[lld] r326835 - Implement --just-symbols.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 6 18:45:24 PST 2018


Rui Ueyama via llvm-commits <llvm-commits at lists.llvm.org> writes:


> +// What we are doing here is to read defined symbols from a given ELF
> +// file and add them as absolute symbols.
> +template <class ELFT> void elf::readJustSymbolsFile(MemoryBufferRef MB) {
> +  typedef typename ELFT::Shdr Elf_Shdr;
> +  typedef typename ELFT::Sym Elf_Sym;
> +  typedef typename ELFT::SymRange Elf_Sym_Range;
> +
> +  StringRef ObjName = MB.getBufferIdentifier();
> +  ELFFile<ELFT> Obj = check(ELFFile<ELFT>::create(MB.getBuffer()));
> +  ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), ObjName);
> +
> +  for (const Elf_Shdr &Sec : Sections) {
> +    if (Sec.sh_type != SHT_SYMTAB)
> +      continue;
> +
> +    Elf_Sym_Range Syms = CHECK(Obj.symbols(&Sec), ObjName);
> +    uint32_t FirstNonLocal = Sec.sh_info;

There are now 3 places in this file that use the fact that sh_info is
the first non-local symbol. I wonder if we could move that to a helper
function.

I still think we should error if someone uses --just-symbols foo.o. In
object files st_value is an offset, not an address.

Cheers,
Rafael


More information about the llvm-commits mailing list