llvm-project/lld/ELF
Fangrui Song 7370a489b1 [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) }`
  (abc388ed3c 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
2022-03-29 08:56:21 -07:00
..
Arch [AMDGPU][LLD] Adding support for ABI version 5 option 2022-03-23 01:22:37 -07:00
AArch64ErrataFix.cpp [ELF] Don't rely on Symbols.h's transitive inclusion of InputFiles.h. NFC 2022-02-23 20:44:34 -08:00
AArch64ErrataFix.h [ELF] AArch64ErrataFix: replace std::map with DenseMap. NFC 2022-02-07 22:02:25 -08:00
ARMErrataFix.cpp [ELF] Don't rely on Symbols.h's transitive inclusion of InputFiles.h. NFC 2022-02-23 20:44:34 -08:00
ARMErrataFix.h [ELF] Clean up headers. NFC 2022-02-07 21:53:34 -08:00
CMakeLists.txt [ELF] Parallelize --compress-debug-sections=zlib 2022-01-25 10:29:04 -08:00
CallGraphSort.cpp [ELF] Don't rely on Symbols.h's transitive inclusion of InputFiles.h. NFC 2022-02-23 20:44:34 -08:00
CallGraphSort.h
Config.h Reland "[ELF] Enable new passmanager plugin support for LTO" 2022-03-24 16:29:18 +01:00
DWARF.cpp [ELF] Clean up headers. NFC 2022-02-07 21:53:34 -08:00
DWARF.h [ELF] --gdb-index: skip SHF_GROUP .debug_info 2020-08-13 09:11:01 -07:00
Driver.cpp Reland "[ELF] Enable new passmanager plugin support for LTO" 2022-03-24 16:29:18 +01:00
Driver.h [ELF] Change global variable backwardReferences to a LinkerDriver member variable. NFC 2022-02-27 20:33:28 +00:00
DriverUtils.cpp [ELF] Clean up headers. NFC 2022-02-07 21:53:34 -08:00
EhFrame.cpp [ELF] Replace uncompressed InputSectionBase::data() with rawData. NFC 2022-02-21 00:39:26 -08:00
EhFrame.h [ELF] Simplify/optimize EhInputSection::split 2022-01-18 17:03:23 -08:00
ICF.cpp [ELF] Don't use multiple inheritance for OutputSection. NFC 2022-03-08 11:23:42 -08:00
ICF.h
InputFiles.cpp [ELF] Move invalid binding diagnostic from initializeSymbols to postParse 2022-03-16 00:31:29 -07:00
InputFiles.h Reland D119909 [ELF] Parallelize initializeLocalSymbols 2022-03-04 19:00:10 -08:00
InputSection.cpp Revert D122459 "[ELF] --emit-relocs: adjust offsets of .rel[a].eh_frame relocations" 2022-03-28 20:26:21 -07:00
InputSection.h Revert D122459 "[ELF] --emit-relocs: adjust offsets of .rel[a].eh_frame relocations" 2022-03-28 20:26:21 -07:00
LTO.cpp Reland "[ELF] Enable new passmanager plugin support for LTO" 2022-03-24 16:29:18 +01:00
LTO.h [Coding style change] Rename variables so that they start with a lowercase letter 2019-07-10 05:00:37 +00:00
LinkerScript.cpp [ELF] Don't use multiple inheritance for OutputSection. NFC 2022-03-08 11:23:42 -08:00
LinkerScript.h [ELF] Don't use multiple inheritance for OutputSection. NFC 2022-03-08 11:23:42 -08:00
MapFile.cpp [ELF] Don't use multiple inheritance for OutputSection. NFC 2022-03-08 11:23:42 -08:00
MapFile.h [ELF] Move --print-archive-stats= and --why-extract= beside --warn-backrefs report 2022-02-27 20:23:09 +00:00
MarkLive.cpp [ELF] Simplify MergeInputSection::getParentOffset. NFC 2022-03-28 10:02:35 -07:00
MarkLive.h
Options.td Reland "[ELF] Enable new passmanager plugin support for LTO" 2022-03-24 16:29:18 +01:00
OutputSections.cpp [ELF] Don't use multiple inheritance for OutputSection. NFC 2022-03-08 11:23:42 -08:00
OutputSections.h [ELF] Don't use multiple inheritance for OutputSection. NFC 2022-03-08 11:23:42 -08:00
README.md
Relocations.cpp [ELF] Move section assignment from initializeSymbols to postParse 2022-03-15 19:24:41 -07:00
Relocations.h [ELF] Clean up headers. NFC 2022-02-07 21:53:34 -08:00
ScriptLexer.cpp [ELF] Clean up headers. NFC 2022-02-07 21:53:34 -08:00
ScriptLexer.h [ELF] Clean up headers. NFC 2022-02-07 21:53:34 -08:00
ScriptParser.cpp [ELF] Don't use multiple inheritance for OutputSection. NFC 2022-03-08 11:23:42 -08:00
ScriptParser.h [ELF] Clean up headers. NFC 2022-02-07 21:53:34 -08:00
SymbolTable.cpp [ELF] Move isUsedInRegularObj assignment from ctor to call sites. NFC 2022-02-23 21:32:50 -08:00
SymbolTable.h [ELF] Symbols.h: remove #include "InputFiles.h" 2022-02-23 21:36:45 -08:00
Symbols.cpp [ELF] Move section assignment from initializeSymbols to postParse 2022-03-15 19:24:41 -07:00
Symbols.h [ELF] Move section assignment from initializeSymbols to postParse 2022-03-15 19:24:41 -07:00
SyntheticSections.cpp [ELF] Use endianness-aware read32 to avoid dispatch. NFC 2022-03-15 23:51:11 -07:00
SyntheticSections.h [ELF] Fix llvm_unreachable failure when COMMON is placed in SHT_PROGBITS output section 2022-03-28 11:05:52 -07:00
Target.cpp [ELF] De-template getErrorPlace. NFC 2022-01-29 23:05:54 -08:00
Target.h [ELF] Clean up headers. NFC 2022-02-07 21:53:34 -08:00
Thunks.cpp [ELF] Don't rely on Symbols.h's transitive inclusion of InputFiles.h. NFC 2022-02-23 20:44:34 -08:00
Thunks.h [lld] Add missing includes (NFC) 2021-06-03 18:55:18 +02:00
Writer.cpp [ELF] --emit-relocs: fix missing STT_SECTION when the first input section is synthetic 2022-03-29 08:56:21 -07:00
Writer.h [ELF] Clean up headers. NFC 2022-02-07 21:53:34 -08:00

README.md

See docs/NewLLD.rst