This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Mention section name for STT_SECTION in reportRangeError()
ClosedPublic

Authored by MaskRay on Mar 2 2023, 3:07 PM.

Details

Summary

D73518 mentioned non-STT_SECTION symbol names. This patch extends the code to
handle STT_SECTION symbols, where we report the section name.
This change helps at least the following cases with very little code.

  • Whether a out-of-range relocation is due to code or data.
  • For a relocation in .debug_info, which referenced .debug_* section (due to DWARF32 limitation) causes the problem.

Diff Detail

Event Timeline

MaskRay created this revision.Mar 2 2023, 3:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2023, 3:07 PM
MaskRay requested review of this revision.Mar 2 2023, 3:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2023, 3:07 PM

So this:

(.text+0x3): relocation R_X86_64_PC32 out of range: 2147483648 is not in [-2147483648, 2147483647]; references .bss+0

Says that we're trying to write into .text+0x3 (3 bytes into the .text section) the value 2147483648 as an offset, relative to .bss+0? (are there cases where the offset would be non-zero and the +N on the second part (the .bss+0) would be non-zero as well?)

The +0 on the .bss is the bit I find surprising/not sure I understand - I'd have thought it'd just be .bss & the +N is in the "N is not in [...];"?

So this:

(.text+0x3): relocation R_X86_64_PC32 out of range: 2147483648 is not in [-2147483648, 2147483647]; references .bss+0

Says that we're trying to write into .text+0x3 (3 bytes into the .text section) the value 2147483648 as an offset, relative to .bss+0? (are there cases where the offset would be non-zero and the +N on the second part (the .bss+0) would be non-zero as well?)

Yes.

The +0 on the .bss is the bit I find surprising/not sure I understand - I'd have thought it'd just be .bss & the +N is in the "N is not in [...];"?

A non-zero offset is possible. For example an C/C++ internal linkage function may have a non-zero offset relative to its section. A reference against the local symbol will be converted to a relocation against the section symbol.

peter.smith accepted this revision.Mar 3 2023, 1:33 AM

Looks like a good improvement, one small suggestion on the text, but no strong opinion on it if you prefer the original.

lld/ELF/Relocations.cpp
106

One small suggestion, could use `"; references section " as that makes the +0 form a bit less surprising. I guess for cases like .text, .data etc. it will be obvious that it is a section symbol, but for some user defined names it might be less obvious.

This revision is now accepted and ready to land.Mar 3 2023, 1:33 AM
MaskRay updated this revision to Diff 502219.Mar 3 2023, 12:33 PM
MaskRay edited the summary of this revision. (Show Details)

remove offset (since it's always zero for the STT_SECTION symbol)

MaskRay marked an inline comment as done.Mar 3 2023, 12:33 PM
MaskRay retitled this revision from [ELF] Mention section name and offset for STT_SECTION in reportRangeError() to [ELF] Mention section name for STT_SECTION in reportRangeError().
This revision was landed with ongoing or failed builds.Mar 3 2023, 12:35 PM
This revision was automatically updated to reflect the committed changes.

remove offset (since it's always zero for the STT_SECTION symbol)

Oh, nice!