diff options
Diffstat (limited to 'lld/ELF/InputFiles.cpp')
-rw-r--r-- | lld/ELF/InputFiles.cpp | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index e8a4188ec775..031a8679db41 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -395,16 +395,6 @@ uint32_t ObjFile<ELFT>::getSectionIndex(const Elf_Sym &sym) const { this); } -template <class ELFT> ArrayRef<Symbol *> ObjFile<ELFT>::getLocalSymbols() { - if (this->symbols.empty()) - return {}; - return makeArrayRef(this->symbols).slice(1, this->firstGlobal - 1); -} - -template <class ELFT> ArrayRef<Symbol *> ObjFile<ELFT>::getGlobalSymbols() { - return makeArrayRef(this->symbols).slice(this->firstGlobal); -} - template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) { // Read a section table. justSymbols is usually false. if (this->justSymbols) @@ -966,7 +956,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx, // `nullptr` for the normal case. However, if -r or --emit-relocs is // specified, we need to copy them to the output. (Some post link analysis // tools specify --emit-relocs to obtain the information.) - if (!config->relocatable && !config->emitRelocs) + if (!config->copyRelocs) return nullptr; InputSection *relocSec = make<InputSection>(*this, sec, name); // If the relocated section is discarded (due to /DISCARD/ or @@ -1035,12 +1025,11 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx, name == ".gnu.linkonce.t.__i686.get_pc_thunk.bx") return &InputSection::discarded; - // If we are creating a new .build-id section, strip existing .build-id - // sections so that the output won't have more than one .build-id. - // This is not usually a problem because input object files normally don't - // have .build-id sections, but you can create such files by - // "ld.{bfd,gold,lld} -r --build-id", and we want to guard against it. - if (name == ".note.gnu.build-id" && config->buildId != BuildIdKind::None) + // Strip existing .note.gnu.build-id sections so that the output won't have + // more than one build-id. This is not usually a problem because input object + // files normally don't have .build-id sections, but you can create such files + // by "ld.{bfd,gold,lld} -r --build-id", and we want to guard against it. + if (name == ".note.gnu.build-id") return &InputSection::discarded; // The linker merges EH (exception handling) frames and creates a @@ -1147,17 +1136,20 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() { if (sec == &InputSection::discarded) { Undefined und{this, name, binding, stOther, type, secIdx}; Symbol *sym = this->symbols[i]; - // !ArchiveFile::parsed or LazyObjFile::fetched means that the file + // !ArchiveFile::parsed or LazyObjFile::extracted means that the file // containing this object has not finished processing, i.e. this symbol is - // a result of a lazy symbol fetch. We should demote the lazy symbol to an - // Undefined so that any relocations outside of the group to it will + // a result of a lazy symbol extract. We should demote the lazy symbol to + // an Undefined so that any relocations outside of the group to it will // trigger a discarded section error. if ((sym->symbolKind == Symbol::LazyArchiveKind && !cast<ArchiveFile>(sym->file)->parsed) || (sym->symbolKind == Symbol::LazyObjectKind && - cast<LazyObjFile>(sym->file)->fetched)) + cast<LazyObjFile>(sym->file)->extracted)) { sym->replace(und); - else + // Prevent LTO from internalizing the symbol in case there is a + // reference to this symbol from this file. + sym->isUsedInRegularObj = true; + } else sym->resolve(und); continue; } @@ -1174,7 +1166,7 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() { } // Undefined symbols (excluding those defined relative to non-prevailing - // sections) can trigger recursive fetch. Process defined symbols first so + // sections) can trigger recursive extract. Process defined symbols first so // that the relative order between a defined symbol and an undefined symbol // does not change the symbol resolution behavior. In addition, a set of // interconnected symbols will all be resolved to the same file, instead of @@ -1202,7 +1194,7 @@ void ArchiveFile::parse() { } // Returns a buffer pointing to a member file containing a given symbol. -void ArchiveFile::fetch(const Archive::Symbol &sym) { +void ArchiveFile::extract(const Archive::Symbol &sym) { Archive::Child c = CHECK(sym.getMember(), toString(this) + ": could not get the member for symbol " + @@ -1291,7 +1283,7 @@ static bool isNonCommonDef(MemoryBufferRef mb, StringRef symName, } } -bool ArchiveFile::shouldFetchForCommon(const Archive::Symbol &sym) { +bool ArchiveFile::shouldExtractForCommon(const Archive::Symbol &sym) { Archive::Child c = CHECK(sym.getMember(), toString(this) + ": could not get the member for symbol " + @@ -1779,10 +1771,10 @@ InputFile *elf::createObjectFile(MemoryBufferRef mb, StringRef archiveName, } } -void LazyObjFile::fetch() { - if (fetched) +void LazyObjFile::extract() { + if (extracted) return; - fetched = true; + extracted = true; InputFile *file = createObjectFile(mb, archiveName, offsetInArchive); file->groupId = groupId; @@ -1835,7 +1827,7 @@ template <class ELFT> void LazyObjFile::parse() { // Replace existing symbols with LazyObject symbols. // - // resolve() may trigger this->fetch() if an existing symbol is an + // resolve() may trigger this->extract() if an existing symbol is an // undefined symbol. If that happens, this LazyObjFile has served // its purpose, and we can exit from the loop early. for (Symbol *sym : this->symbols) { @@ -1843,16 +1835,16 @@ template <class ELFT> void LazyObjFile::parse() { continue; sym->resolve(LazyObject{*this, sym->getName()}); - // If fetched, stop iterating because this->symbols has been transferred + // If extracted, stop iterating because this->symbols has been transferred // to the instantiated ObjFile. - if (fetched) + if (extracted) return; } return; } } -bool LazyObjFile::shouldFetchForCommon(const StringRef &name) { +bool LazyObjFile::shouldExtractForCommon(const StringRef &name) { if (isBitcode(mb)) return isBitcodeNonCommonDef(mb, name, archiveName); |