[llvm-dev] [LLD][ELF] Dynamic relocations list depends on the input files order

Rafael EspĂ­ndola via llvm-dev llvm-dev at lists.llvm.org
Thu Apr 7 11:16:16 PDT 2016


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


More information about the llvm-dev mailing list