This is an archive of the discontinued LLVM Phabricator instance.

[ELF] --emit-relocs: fix missing STT_SECTION when the first input section is synthetic
ClosedPublic

Authored by MaskRay on Mar 24 2022, 11:35 PM.

Details

Summary

addSectionSymbols suppresses the STT_SECTION symbol if the first input section
is non-SHF_MERGE synthetic. This is incorrect when the first input section is synthetic
while a non-synthetic input section exists:

  • .bss : { *(COMMON) *(.bss) } (abc388ed3cf0ef7e617ebe243d3b0b32d29e69a5 regressed the case because COMMON symbols precede .bss in the absence of a linker script)
  • Place a synthetic section in another section: .data : { *(.got) *(.data) }

For %t/a1 in the new test emit-relocs-synthetic.s, ld.lld produces incorrect
relocations with symbol index 0.

0000000000000000 <_start>:
       0: 8b 05 33 00 00 00             movl    51(%rip), %eax          # 0x39 <bss>
                0000000000000002:  R_X86_64_PC32        *ABS*+0xd
       6: 8b 05 1c 00 00 00             movl    28(%rip), %eax          # 0x28 <common>
                0000000000000008:  R_X86_64_PC32        common-0x4
       c: 8b 05 06 00 00 00             movl    6(%rip), %eax           # 0x18
                000000000000000e:  R_X86_64_GOTPCRELX   *ABS*+0x4

Fix the issue by checking every input section.

Diff Detail

Event Timeline

MaskRay created this revision.Mar 24 2022, 11:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2022, 11:35 PM
MaskRay requested review of this revision.Mar 24 2022, 11:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2022, 11:35 PM
MaskRay edited the summary of this revision. (Show Details)Mar 24 2022, 11:36 PM
MaskRay updated this revision to Diff 418138.Mar 24 2022, 11:38 PM

fix a test comment

MaskRay updated this revision to Diff 418139.Mar 24 2022, 11:39 PM

fix comment header

This revision is now accepted and ready to land.Mar 29 2022, 12:06 AM