[lld] [llvm] [ICF] Add a NOP after branch in ICF thunk to improve debugability (PR #154986)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 27 13:03:30 PDT 2025
dwblaikie wrote:
> Thanks for pointing that out!
>
> But if you have three consecutive one-instruction functions (which would be a common case if you enable ICF safe thunks), they will be concat into one sequence: https://godbolt.org/z/GhrYP8njv
>
> ```
> 0x0000000000000000 1 12 1 0 0 0 is_stmt prologue_end
> 0x0000000000000010 2 12 1 0 0 0 is_stmt prologue_end
> 0x0000000000000020 3 12 1 0 0 0 is_stmt prologue_end
> 0x0000000000000021 3 12 1 0 0 0 is_stmt end_sequence
> ```
>
> The problem we have here is, for ICF thunks to be probably symbolicated, each function needs to be its own sequence when we enable `-mllvm -emit-func-debug-line-table-offsets`: https://godbolt.org/z/qbndoGWbM
>
> ```
> 0x0000000000000000 1 12 1 0 0 0 is_stmt prologue_end
> 0x0000000000000000 1 12 1 0 0 0 is_stmt end_sequence
> 0x0000000000000010 2 12 1 0 0 0 is_stmt prologue_end
> 0x0000000000000010 2 12 1 0 0 0 is_stmt end_sequence
> 0x0000000000000020 3 12 1 0 0 0 is_stmt prologue_end
> 0x0000000000000021 3 12 1 0 0 0 is_stmt end_sequence
> ```
>
> In this case, we can just advance PC, as the PC will go into other thunks.
I'm pretty sure this table is incorrect/buggy - it contains duplicate entries for the same offset.
It describes zero-length, not one-length sequences.
3 single-instruction functions with separate sequences should be emitted like this:
```
0x0000000000000000 1 12 0 0 0 0 is_stmt prologue_end
0x0000000000000001 1 12 0 0 0 0 is_stmt end_sequence
0x0000000000000001 2 12 0 0 0 0 is_stmt prologue_end
0x0000000000000002 2 12 0 0 0 0 is_stmt end_sequence
0x0000000000000002 3 13 0 0 0 0 is_stmt prologue_end
0x0000000000000003 3 13 0 0 0 0 is_stmt end_sequence
```
https://github.com/llvm/llvm-project/pull/154986
More information about the llvm-commits
mailing list