[PATCH] D39348: Implement --just-symbols.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 07:31:02 PST 2018


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

> Index: lld/ELF/InputFiles.cpp
> ===================================================================
> --- lld/ELF/InputFiles.cpp
> +++ lld/ELF/InputFiles.cpp
> @@ -1159,6 +1159,42 @@
>    }
>  }
>  
> +// This is for --just-symbols.
> +//
> +// This option allows you to link your output against other existing
> +// program, so that if you load both your program and the other program
> +// into memory, your output can use program's symbols.
> +//
> +// 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);

Please make sure we reject .o files.

How does this support having the just symbol file be the only one? The
function that read the just symbols file is already templated.

> +  // Handle the --just-symbols option. This may add absolute symbols
> +  // to the symbol table.
> +  for (auto *Arg : Args.filtered(OPT_just_symbols))
> +    if (Optional<MemoryBufferRef> MB = readFile(Arg->getValue()))
> +      readJustSymbolsFile<ELFT>(*MB);

Don't we have to handle it in the correct position in the command line?

Cheers,
Rafael


More information about the llvm-commits mailing list