[PATCH] D40549: [ELF] - Add support for --just-symbols flag.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 00:18:49 PST 2017


>> Only executable and relocatable files are supported as arguments. Both gnu linkers does not support
>> adding DSO files. Behavior of GNU linkers restricting DSO inputs is probably reasonable, though that looks
>> like artifical limitation. I can imagine DSO with absolute symbols and see no problems to extract
>> and use such symbols. This implementation follows GNU linkers behavior mostly for simplicity and consistency
>> of our implementation.
>
>Do you know what is the use case for .o files? What is the value used,
>the offset in a section?
>

Yes, it's an offset. Not sure how offsets can be used, but
I thought about why GNU linkers support .o and was able to imagine next use case.
If we have params_base.o which has some absolute symbols for example and few undefined symbols:
.global undef1
undef1 = 0x123
.global undef2
.global undef3

we can have derived_params1.o, derived_params2.o objects which are linked with --just-symbols=params_base.o
and define those symbols differently. Then final aplication can link with derived_params1/derived_params2
and use symbols values.

>If the original request is not for .o files I would suggest rejecting
>them for now.

That is also fine I think.

>> +# RUN: echo "_start:" > %t.s
>
>Does a local _start change anything?

No, it could be empty file.

>> +    StringRef Name = check(Sym.getName(this->StringTable), toString(this));
>> +    // We do not want to automatically resolve undefined symbols here, so
>> +    // leaving them as is, assuming they must be defined somewhere else.
>> +    if (Sym.st_shndx == SHN_UNDEF) {
>> +      this->Symbols.push_back(Symtab->addUndefined<ELFT>(
>> +          Name, Sym.getBinding(), Sym.st_other, Sym.getType(),
>> +          /*CanOmitFromDynSym=*/false, this));
>> +      continue;
>> +    }
>
>bfd seems to ignore undefined symbols, no?

No, if you have symbols.o with undefined symbol:
.globl test
test:
  callq undef at PLT

and link it using --just-symbols=symbols.o with stub main.o:
_start:
 nop

Symbol will remain undefined:
ld.bfd main.o --just-symbols=symbols.o -o out
readelf -a out

Symbol table '.symtab' contains 10 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
....
     6: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND undef

Cheers,
Rafael


More information about the llvm-commits mailing list