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

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 28 11:04:32 PST 2017


George Rimar via Phabricator <reviews at reviews.llvm.org> writes:

> grimar created this revision.
> Herald added a subscriber: emaste.
>
> This is "Bug 35067 - support --just-symbols (-R)" (https://bugs.llvm.org//show_bug.cgi?id=35067)
>
> Description of feature:
> --just-symbols=filename
> Read symbol names and their addresses from filename, but do not relocate it or include it in the output.
> This allows your output file to refer symbolically to absolute locations of memory defined in other programs.
> You may use this option more than once. 
> (ftp://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html)
>
> Patch implements --just-symbols flag. Behavior is to read symbols from file and
> add all of them as absolute symbols except undefined symbols, which are kept as undefined.
>
> 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?

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

> +# RUN: echo "_start:" > %t.s

Does a local _start change anything?

> +// Used for --just-symbol=filename implementation, here we scan
> +// and add symbols from object file.
> +template <class ELFT> void ObjFile<ELFT>::parseJustSymbols() {
> +  ArrayRef<Elf_Shdr> ObjSections =
> +      check(this->getObj().sections(), toString(this));
> +
> +  // Initialize symbol and string tables.
> +  for (const Elf_Shdr &Hdr : ObjSections) {
> +    if (Hdr.sh_type != SHT_SYMTAB)
> +      continue;
> +    this->initSymtab(ObjSections, &Hdr);
> +    break;
> +  }
> +
> +  // Scan over all symbols.
> +  for (const Elf_Sym &Sym : this->ELFSyms) {
> +    // Skip all local symbols.
> +    if (Sym.getBinding() == STB_LOCAL)
> +      continue;
> +
> +    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?

Cheers,
Rafael


More information about the llvm-commits mailing list