[all-commits] [llvm/llvm-project] 7370a4: [ELF] --emit-relocs: fix missing STT_SECTION when ...

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue Mar 29 08:56:34 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7370a489b1005e424b23bd0009af2365aef4db53
      https://github.com/llvm/llvm-project/commit/7370a489b1005e424b23bd0009af2365aef4db53
  Author: Fangrui Song <i at maskray.me>
  Date:   2022-03-29 (Tue, 29 Mar 2022)

  Changed paths:
    M lld/ELF/Writer.cpp
    A lld/test/ELF/emit-relocs-synthetic.s

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

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.

Reviewed By: ikudrin

Differential Revision: https://reviews.llvm.org/D122463




More information about the All-commits mailing list