Simon Atanasyan
2015-Apr-18 11:52 UTC
[LLVMdev] [lld] Linker cannot handle sections with non-unique names
Hi, FYI LLD cannot handle ELF sections with non-unique names. An object file with such sections can be generated by the Clang since r234143. I am not sure that Clang works absolutely correct but bfd linker works fine. Right now I do not have a time to investigate this problem. If nobody take, I will try to solve it later. Here is the reproduction script for x86_64 host: $ cat test.cc template <class T> void foo(T) {} int main() { foo(0); foo(1.0); } $ clang++ -c test.cc -fno-unique-section-names $ lld -flavor gnu -target x86_64 --hash-style=both --build-id \ --eh-frame-hdr -m elf_x86_64 \ -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out \ <bunch of regular linker arguments here> $ ./a.out Illegal instruction $ clang++ -c test.cc -funique-section-names $ lld -flavor gnu -target x86_64 --hash-style=both --build-id \ --eh-frame-hdr -m elf_x86_64 \ -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out \ <bunch of regular linker arguments here> $ ./a.out -- Simon Atanasyan
Shankar Easwaram
2015-Apr-18 12:09 UTC
[LLVMdev] [lld] Linker cannot handle sections with non-unique names
Thanks Simon fir the test. I may be able to get to this issue later too. The bug is mostly in the elf reader where it's skipping real sections with the same name.> On Apr 18, 2015, at 06:52, Simon Atanasyan <simon at atanasyan.com> wrote: > > Hi, > > FYI > > LLD cannot handle ELF sections with non-unique names. An object file > with such sections can be generated by the Clang since r234143. I am > not sure that Clang works absolutely correct but bfd linker works > fine. > > Right now I do not have a time to investigate this problem. If nobody > take, I will try to solve it later. > > Here is the reproduction script for x86_64 host: > > $ cat test.cc > template <class T> > void foo(T) {} > > int main() { > foo(0); > foo(1.0); > } > > $ clang++ -c test.cc -fno-unique-section-names > $ lld -flavor gnu -target x86_64 --hash-style=both --build-id \ > --eh-frame-hdr -m elf_x86_64 \ > -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out \ > <bunch of regular linker arguments here> > $ ./a.out > Illegal instruction > > $ clang++ -c test.cc -funique-section-names > $ lld -flavor gnu -target x86_64 --hash-style=both --build-id \ > --eh-frame-hdr -m elf_x86_64 \ > -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out \ > <bunch of regular linker arguments here> > $ ./a.out > > -- > Simon Atanasyan
Shankar Easwaran
2015-Apr-19 22:44 UTC
[LLVMdev] [lld] Linker cannot handle sections with non-unique names
Attached patch fixes the issue. On Sat, Apr 18, 2015 at 6:52 AM, Simon Atanasyan <simon at atanasyan.com> wrote:> Hi, > > FYI > > LLD cannot handle ELF sections with non-unique names. An object file > with such sections can be generated by the Clang since r234143. I am > not sure that Clang works absolutely correct but bfd linker works > fine. > > Right now I do not have a time to investigate this problem. If nobody > take, I will try to solve it later. > > Here is the reproduction script for x86_64 host: > > $ cat test.cc > template <class T> > void foo(T) {} > > int main() { > foo(0); > foo(1.0); > } > > $ clang++ -c test.cc -fno-unique-section-names > $ lld -flavor gnu -target x86_64 --hash-style=both --build-id \ > --eh-frame-hdr -m elf_x86_64 \ > -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out \ > <bunch of regular linker arguments here> > $ ./a.out > Illegal instruction > > $ clang++ -c test.cc -funique-section-names > $ lld -flavor gnu -target x86_64 --hash-style=both --build-id \ > --eh-frame-hdr -m elf_x86_64 \ > -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out \ > <bunch of regular linker arguments here> > $ ./a.out > > -- > Simon Atanasyan >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150419/b981ca12/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: no-unique-sections.patch Type: text/x-patch Size: 2873 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150419/b981ca12/attachment.bin>
Davide Italiano
2015-Apr-20 01:22 UTC
[LLVMdev] [lld] Linker cannot handle sections with non-unique names
On Sun, Apr 19, 2015 at 3:44 PM, Shankar Easwaran <shankarke at gmail.com> wrote:> Attached patch fixes the issue. >This seems OK to me but please add a testcase.
Simon Atanasyan
2015-Apr-20 08:34 UTC
[LLVMdev] [lld] Linker cannot handle sections with non-unique names
On Mon, Apr 20, 2015 at 1:44 AM, Shankar Easwaran <shankarke at gmail.com> wrote:> Attached patch fixes the issue.Thanks for the quick fix. The patch LGTM if you add a test case. Unfortunately yaml2obj does not support duplicated section names but we can use a binary input file. -- Simon Atanasyan
Reasonably Related Threads
- [LLVMdev] [lld] Linker cannot handle sections with non-unique names
- [LLVMdev] [lld] Linker cannot handle sections with non-unique names
- [LLVMdev] [lld] Representation of lld::Reference with a fake target
- [LLVMdev] [lld] Representation of lld::Reference with a fake target
- [LLVMdev] [lld] Representation of lld::Reference with a fake target