__ehdr_start should be pointing to ELF file headers, not program headers.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
This appears to be broken on Windows for some reason (http://lab.llvm.org:8011/builders/lld-x86_64-win7/builds/5154), so reverting the change.
When comparing the output from gold, ld and lld, one difference I noticed is that gold emits this symbol as SHN_ABS, ld uses index of .text, while lld uses SHN_UNDEF. It's the same for other reserved symbols like _end, _etext, _edata. Is there a particular reason why lld uses SHN_UNDEF or is that a bug?
It's reproducible on my machine. This is an output of llvm-readobj.
D:\b>bin\llvm-readobj -symbols \b\tools\lld\test\ELF\Output\ehdr_start.s.tmp
Error reading file: invalid section index
.
File: \b\tools\lld\test\ELF\Output\ehdr_start.s.tmp
Format: ELF64-x86-64
Arch: x86_64
AddressSize: 64bit
LoadName:
Symbols [
Symbol { Name: (0) Value: 0x0 Size: 0 Binding: Local (0x0) Type: None (0x0) Other: 0 Section: Undefined (0x0) }
These symbols don't really belong to a section, so there's no appropriate section index for them. Nor do they participate in dynamic loading (as they have hidden visibility). A section index of 1 would probably be appropriate (it doesn't matter what value it is, as long as it is not SHN_UNDEF or SHN_ABS).
Anyway, I think the problem is that we do not initialize Out<ELFT>::ElfHeader->SectionIndex, and the fix is to change the code here: http://llvm-cs.pcc.me.uk/tools/lld/ELF/Writer.cpp#1137