Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -12,6 +12,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/ELF.h" #include @@ -59,6 +60,7 @@ llvm::StringRef OutputFile; llvm::StringRef SoName; llvm::StringRef Sysroot; + llvm::StringSet<> TraceSymbol; std::string RPath; std::vector SymbolVersions; std::vector DynamicList; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -417,6 +417,9 @@ if (Optional Buffer = readFile(Arg->getValue())) parseVersionScript(*Buffer); } + + for (auto *Arg : Args.filtered(OPT_trace_symbol)) + Config->TraceSymbol.insert(Arg->getValue()); } void LinkerDriver::createFiles(opt::InputArgList &Args) { @@ -499,6 +502,7 @@ Symtab.scanShlibUndefined(); Symtab.scanDynamicList(); Symtab.scanVersionScript(); + Symtab.traceDefined(); Symtab.addCombinedLtoObject(); if (HasError) Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ ELF/InputFiles.h @@ -140,6 +140,8 @@ const Elf_Shdr *getSymbolTable() const { return this->Symtab; }; + void traceUndefined(StringRef Name); + // Get MIPS GP0 value defined by this file. This value represents the gp value // used to create the relocatable object and required to support // R_MIPS_GPREL16 / R_MIPS_GPREL32 relocations. Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -313,6 +313,14 @@ return new (IAlloc.Allocate()) InputSection(this, &Sec); } +// Print the module names which reference the notified +// symbols provided through -y or --trace-symbol option. +template +void elf::ObjectFile::traceUndefined(StringRef Name) { + if (!Config->TraceSymbol.empty() && Config->TraceSymbol.count(Name)) + outs() << getFilename(this) << ": reference to " << Name << "\n"; +} + template void elf::ObjectFile::initializeSymbols() { this->initStringTable(); Elf_Sym_Range Syms = this->getElfSymbols(false); @@ -350,6 +358,7 @@ switch (Sym->st_shndx) { case SHN_UNDEF: + traceUndefined(Name); return elf::Symtab::X ->addUndefined(Name, Binding, Sym->st_other, Sym->getType(), /*CanOmitFromDynSym*/ false, this) Index: ELF/Options.td =================================================================== --- ELF/Options.td +++ ELF/Options.td @@ -164,6 +164,8 @@ def z: JS<"z">, MetaVarName<"