[llvm] [dwarf] make dwarf fission compatible with RISCV relaxations 1/2 (PR #166597)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 7 10:52:29 PST 2025


dlav-sc wrote:

> Perhaps the absoluteSymbolDiff function can be improved to cover this case (walking multiple fragments, so long as each has an absolute/fixed size, etc)

I attempted to handle multiple fragment cases in `absoluteSymbolDiff`, but I now believe this won't work. The main reason is that we can't calculate the difference between two labels in different fragments before layout (see `MCAssembler::layout()`), since `MCFragment` doesn't know its final position within the section before layout.

Moreover even if it were possible, I don't think `absoluteSymbolDiff` provides what I need. From my understanding, `absoluteSymbolDiff` returns a difference only when the offset between labels remains constant **both at assembly time and at link time**. What I actually need is to check whether the linker might change the offset between labels, therefore I need to ensure the offset remains constant only **at link time**. This is a much less restrictive condition than what `absoluteSymbolDiff` implies.

If we can't compute the label difference with `absoluteSymbolDiff`, but have a guarantee that the linker won't affect the difference, we could simply emit  an appropriate assembly directive (e.g. `.uleb128 Hi-Lo`) and use the addr+offset DWARF format anyway. This approach works in most cases, see `MCObjectStreamer::emitAbsoluteSymbolDiffAsULEB128`. When that function can't obtain the difference between labels with `absoluteSymbolDiff`, it emits the appropriate assembly directive.

`isRangeRelaxable` simply checks that the fragments' sizes between labels won't change at link time. It's acceptable if they change at assembly time (e.g., during fixup resolution by assembler), because we have the `.uleb128` directive in that case.

Therefore, I believe `absoluteSymbolDiff` and `isRangeRelaxable` serve different purposes. The former aims to eliminate redundant `.uleb128` directives (i.e. primarily for optimization), while the latter determines whether a dwarf form should be handled by the linker.

I might be mistaken about something, so please feel free to share any concerns you have.

https://github.com/llvm/llvm-project/pull/166597


More information about the llvm-commits mailing list