diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index cd768db8a7ffcf1b04be33e2cac6d7e32418a787..2c85d4c066f386ff2dbef70548e6a3a2be58fafb 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -403,9 +403,6 @@ struct Ctx { // A tuple of (reference, extractedFile, sym). Used by --why-extract=. SmallVector, 0> whyExtractRecords; - // Store duplicate symbols (only defined). - typedef llvm::DenseMap eSymsCntMap; - llvm::DenseSet eSymsHist; // A mapping from a symbol to an InputFile referencing it backward. Used by // --warn-backrefs. llvm::DenseMap> gotPltInfo; // sym, soFile->orderIdx array; + // Store duplicate symbols (only defined). + llvm::DenseSet duplicatedSymNames; } adlt; // OHOS_LOCAL end }; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index af62fa7cca0b4021b7474904b24bbea999d53937..a4ee33280065e9912b777d51a5368dc4f84d90e7 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2568,14 +2568,14 @@ void LinkerDriver::link(opt::InputArgList &args) { for (StringRef name : config->undefined) addUnusedUndefined(name)->referenced = true; - // Fill eSymsHist for defined syms. This will help to find duplicates. + // Fill duplicatedSymNames for defined syms. This will help to find duplicates. if (config->adlt) { - Ctx::eSymsCntMap eSymsHist; + ESymsCntMap eSymsHist; for (auto *file : files) buildSymsHist(file, eSymsHist); for (auto eSym : eSymsHist) if (eSym.second > 1) - ctx->eSymsHist.insert(eSym.first); + ctx->adlt.duplicatedSymNames.insert(eSym.first); eSymsHist.clear(); } diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 23d9512dfb1d300b28943a40514d7425b5487261..0b6ac03faff1887c20e05a72826db4cc320a1910 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -159,14 +159,14 @@ static bool isCompatible(InputFile *file) { } template -static void doBuildSymsHist(InputFile *file, Ctx::eSymsCntMap &eSymsHist) { +static void doBuildSymsHist(InputFile *file, ESymsCntMap &eSymsHist) { if (!isCompatible(file)) return; if (auto *f = dyn_cast>(file)) f->buildSymsHist(eSymsHist); } -void elf::buildSymsHist(InputFile *file, Ctx::eSymsCntMap &eSymsHist) { +void elf::buildSymsHist(InputFile *file, ESymsCntMap &eSymsHist) { invokeELFT(doBuildSymsHist, file, eSymsHist); } @@ -1049,7 +1049,7 @@ InputSectionBase *ObjFile::createInputSection(uint32_t idx, } template -void ObjFile::buildSymsHist(Ctx::eSymsCntMap &eSymsHist) { +void ObjFile::buildSymsHist(ESymsCntMap &eSymsHist) { ArrayRef eSyms = this->getELFSyms(); for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i) { if (!eSyms[i].isDefined()) @@ -1073,7 +1073,7 @@ void ObjFile::initializeSymbols(const object::ELFFile &obj) { if (!symbols[i]) { StringRef name = CHECK(eSyms[i].getName(stringTable), this); if (config->adlt && eSyms[i].isDefined() && - ctx->eSymsHist.count(CachedHashStringRef(name)) != 0) { + ctx->adlt.duplicatedSymNames.count(CachedHashStringRef(name)) != 0) { ctx->adlt.withCfi = ctx->adlt.withCfi || name == "__cfi_check"; name = this->getUniqueName(name); } @@ -2038,6 +2038,11 @@ template void SharedFileExtended::parseDynamics() { // is stored to sh_info. If a local symbol appears after some non-local // symbol, that's a violation of the spec. StringRef name = CHECK(sym.getName(this->stringTable), this); + // Add postfix for defined duplicates. + if (config->adlt && sym.isDefined() && + ctx->adlt.duplicatedSymNames.count(CachedHashStringRef(name)) != 0) + name = this->getUniqueName(name); + if (sym.getBinding() == STB_LOCAL) { warn("found local symbol '" + name + "' in global part of symbol table in file " + toString(this)); diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 65152c33727952018484e56c456d731edfe508f5..b8d47779488d74177d74d89e94925c5d05d3b7d1 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -47,7 +47,8 @@ extern std::unique_ptr tar; llvm::Optional readFile(StringRef path); // Add symbols in File to the symbol table. -void buildSymsHist(InputFile *file, Ctx::eSymsCntMap &eSymsHist); +typedef llvm::DenseMap ESymsCntMap; +void buildSymsHist(InputFile *file, ESymsCntMap &eSymsHist); void parseFile(InputFile *file); // The root class of input files. @@ -293,7 +294,7 @@ public: // Get cached DWARF information. DWARFCache *getDwarf(); - void buildSymsHist(Ctx::eSymsCntMap &eSymsHist); + void buildSymsHist(ESymsCntMap &eSymsHist); void initializeLocalSymbols(); void postParse();