This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Linkerscript - do not emit multiple relocation sections when using --emit-relocs.
AbandonedPublic

Authored by grimar on Jun 1 2017, 7:56 AM.

Details

Reviewers
ruiu
rafael
Summary

I tried to link head linux kernel and faced with fact that objcopy
refuses to proccess one of LLD linked binaries:

RELOCS  arch/x86/realmode/rm/realmode.relocs
OBJCOPY arch/x86/realmode/rm/realmode.bin

objcopy:arch/x86/realmode/rm/realmode.elf: Bad value

That happens because using script LLD produces 2 relocation sections
that point to the same output section. For example without this patch
output for testcase would be:

[ 1] .foo              PROGBITS         0000000000000000  00001000
     000000000000000a  0000000000000000  AX       0     0     1
[ 3] .rela.foo         RELA             0000000000000000  00001010
     0000000000000018  0000000000000018   I       6     1     8
[ 4] .rela.bar         RELA             0000000000000000  00001028
     0000000000000018  0000000000000018   I       6     1     8

(both .rela.foo and .rela.bar points to .foo).

And implementation of objcopy does not like that. AFAIK
generally tools does not support that. We already workaround this
for non-script case (see PR31986), so looks reasonable to do the same for script too,
since at least kernel uses it.

Diff Detail