[PATCH] D38239: [ELF] - Define linkerscript symbols early.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 10:56:28 PST 2018


George Rimar <grimar at accesssoftek.com> writes:

> Yeah, my concerns are about -defsym still. 
> LLD handles it just like script symbols. 
> We are very different from GNU linkers. Difference blowing my mind sometimes.
>
> To summarize:
> 1) If we have test.s with
> .global foo
> foo = 0x123
>
> Then LLD can overload it with defsym:
> ld.lld -defsym=foo=0x99 test.o -o test
> (1: 0000000000000099     0 NOTYPE  GLOBAL DEFAULT  ABS foo)
> and bfd can not:
> ld.bfd  -defsym=foo=0x99 test.o -o test
> multiple definition of `foo'
>
> In that case ld.bfd behaves exactly like "-defsym makes foo to be symbol from .o". Which is very straightforward.
> And we are breaking it. We already discussed it and came to conclusion it is fine.

It is a mater of convenience. It seems so far that handling defsym as a
mini linker script makes things simpler. If that is not the case, it can
be changed. Since we do have to handle actual linker scripts, I don't
see how changing defsym would make things simpler.

> Though probably if we would follow bfd logic for -defsym then I guess
> thinLTO logic would be fine.

Yes, since we would be in an error path and not try to use it. But it
seems reasonable to expect ThinLTO to not provide us with a symbol if it
is not prevailing, no?

> 2) If we use both script and -defsym (one or multiple for the same symbol):
> test.script:            
>  foo = 0x26;             
>
> and change order of -defsym and script in invocation:
> linker -defsym=foo=0x77 -defsym=foo=0x99 --script test.script test.o -o test
> linker  --script test.script -defsym=foo=0x77 -defsym=foo=0x99 test.o -o test
>
> Then LLD always produce the same value, 0x99. Its because we always handle -defsym after script.
> ld.bfd produces either 0x26 or 0x99 depending on order.
>
> Technically I guess the last option should override others as it usually happens,
> in that case LLD do wrong thing currently. It also atm breaks assumption that -defsym are just regular
> linker script assignments, as we always handle them out of order.

If it is simple I would not be opposed to handling defsym in the correct
position in the command line.

Cheers,
Rafael


More information about the llvm-commits mailing list