Simon Atanasyan via llvm-dev
2016-Apr-04 14:52 UTC
[llvm-dev] [LLD][ELF] Dynamic relocations list depends on the input files order
Hi, For MIPS it is possible that output executable file contains both GOT entry and R_MIPS_COPY or R_MIPS_REL32 relocation for the same target symbol. If LLD processes the relocation requires GOT entry before the relocation requires COPY dynamic relocation, it generates the correct output. If the order is reversed, LLD emits COPY dynamic relocation only and does not generate a GOT entry (or shows an error in case of x86 target). It looks like the same problem affects other targets too, so I show a reproduction script for x86 target. % cat data.s .data .global foo .type foo, at object foo: .word 0 % cat r-got.s .text .global _start _start: movl foo at GOT, %eax % cat r-32.s .text ref: movl $foo, (%esp) % as --32 r-got.s -o r-got.o % as --32 r-32.s -o r-32.o % as --32 data.s -o data.o % lld -flavor gnu data.o -shared -o libdata.so % lld -flavor gnu r-32.o r-got.o libdata.so -o a.out relocation R_386_GOT32 out of range % lld -flavor gnu r-got.o r-32.o libdata.so -o a.out % readelf -Sr a.out ... [ 7] .got PROGBITS 00012058 002058 000004 00 WA 0 0 4 ... Relocation section '.rel.dyn' at offset 0x15c contains 2 entries: Offset Info Type Sym.Value Sym. Name 00012058 00000106 R_386_GLOB_DAT 00013000 foo 00013000 00000105 R_386_COPY 00013000 foo BTW the D18711 patch changes the LLD behavior. With this patch the following command completes successfully, but does not produce .got section. % lld -flavor gnu r-32.o r-got.o libdata.so -o a.out I planned to fix this problem but while D18711 is active I think it does not have a sense to change the same code in parallel. -- Simon Atanasyan
Rafael EspĂndola via llvm-dev
2016-Apr-07 18:16 UTC
[llvm-dev] [LLD][ELF] Dynamic relocations list depends on the input files order
Interesting issues. Would you mind reporting a bug? As for D1871, really sorry for the delay. Taking a look at the missing issues found some yaks. I think the last one is properly shaved with r265682 and I should be able to upload a new version of D1871 today. Thanks, Rafael On 4 April 2016 at 10:52, Simon Atanasyan <simon at atanasyan.com> wrote:> Hi, > > For MIPS it is possible that output executable file contains both GOT > entry and R_MIPS_COPY or R_MIPS_REL32 relocation for the same target > symbol. If LLD processes the relocation requires GOT entry before the > relocation requires COPY dynamic relocation, it generates the correct > output. If the order is reversed, LLD emits COPY dynamic relocation > only and does not generate a GOT entry (or shows an error in case of > x86 target). > > It looks like the same problem affects other targets too, so I show a > reproduction script for x86 target. > > % cat data.s > .data > .global foo > .type foo, at object > foo: > .word 0 > > % cat r-got.s > .text > .global _start > _start: > movl foo at GOT, %eax > > % cat r-32.s > .text > ref: > movl $foo, (%esp) > > % as --32 r-got.s -o r-got.o > % as --32 r-32.s -o r-32.o > % as --32 data.s -o data.o > % lld -flavor gnu data.o -shared -o libdata.so > > % lld -flavor gnu r-32.o r-got.o libdata.so -o a.out > relocation R_386_GOT32 out of range > > % lld -flavor gnu r-got.o r-32.o libdata.so -o a.out > % readelf -Sr a.out > ... > [ 7] .got PROGBITS 00012058 002058 000004 00 WA 0 0 4 > ... > Relocation section '.rel.dyn' at offset 0x15c contains 2 entries: > Offset Info Type Sym.Value Sym. Name > 00012058 00000106 R_386_GLOB_DAT 00013000 foo > 00013000 00000105 R_386_COPY 00013000 foo > > BTW the D18711 patch changes the LLD behavior. With this patch the > following command completes successfully, but does not produce .got > section. > > % lld -flavor gnu r-32.o r-got.o libdata.so -o a.out > > I planned to fix this problem but while D18711 is active I think it > does not have a sense to change the same code in parallel. > > -- > Simon Atanasyan
Simon Atanasyan via llvm-dev
2016-Apr-08 16:57 UTC
[llvm-dev] [LLD][ELF] Dynamic relocations list depends on the input files order
Hi, I have created D18862 to solve this problem. But if you see light at the end of the tunnel with the D18711 I will wait result of your work. It is not a problem. Anyway I will not forget about this issue. Regards, Simon On Thu, Apr 7, 2016 at 9:16 PM, Rafael EspĂndola <rafael.espindola at gmail.com> wrote:> Interesting issues. Would you mind reporting a bug? > > As for D1871, really sorry for the delay. Taking a look at the missing > issues found some yaks. I think the last one is properly shaved with > r265682 and I should be able to upload a new version of D1871 today. > > Thanks, > Rafael > > On 4 April 2016 at 10:52, Simon Atanasyan <simon at atanasyan.com> wrote: >> Hi, >> >> For MIPS it is possible that output executable file contains both GOT >> entry and R_MIPS_COPY or R_MIPS_REL32 relocation for the same target >> symbol. If LLD processes the relocation requires GOT entry before the >> relocation requires COPY dynamic relocation, it generates the correct >> output. If the order is reversed, LLD emits COPY dynamic relocation >> only and does not generate a GOT entry (or shows an error in case of >> x86 target). >> >> It looks like the same problem affects other targets too, so I show a >> reproduction script for x86 target.