From b2e73f8e14d0e0d46197a2f75cdfe282a913bc5a Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Thu, 23 May 2024 10:16:57 -0400 Subject: [PATCH 1/7] Drop unused actions as objfile Change-Id: Ic88e38269d663acc81d06bc129eb663753033d4b Signed-off-by: Anton Volkov --- lld/ELF/Driver.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index a4ee33280065..c901197ed3bd 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -849,7 +849,7 @@ static std::pair getPackDynRelocs(opt::InputArgList &args) { static void readCallGraph(MemoryBufferRef mb) { // Build a map from symbol name to section DenseMap map; - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (ELFFileBase *file : files) for (Symbol *sym : file->getSymbols()) map[sym->getName()] = sym; @@ -1828,7 +1828,7 @@ static void excludeLibs(opt::InputArgList &args) { sym->versionId = VER_NDX_LOCAL; }; - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (ELFFileBase *file : files) visit(file); @@ -2025,7 +2025,7 @@ static void writeDependencyFile() { // symbols of type CommonSymbol. static void replaceCommonSymbols() { llvm::TimeTraceScope timeScope("Replace common symbols"); - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (ELFFileBase *file : files) { if (!file->hasCommonSyms) continue; @@ -2102,7 +2102,7 @@ static void findKeepUniqueSections(opt::InputArgList &args) { // Visit the address-significance table in each object file and mark each // referenced symbol as address-significant. - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (InputFile *f : files) { auto *obj = cast>(f); ArrayRef syms = obj->getSymbols(); @@ -2357,7 +2357,7 @@ static void redirectSymbols(ArrayRef wrapped) { return; // Update pointers in input files. - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; parallelForEach(files, [&](ELFFileBase *file) { for (Symbol *&sym : file->getMutableGlobalSymbols()) if (Symbol *s = map.lookup(sym)) @@ -2393,7 +2393,7 @@ static uint32_t getAndFeatures() { return 0; uint32_t ret = -1; - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (ELFFileBase *f : files) { uint32_t features = f->andFeatures; -- Gitee From 98ac76a9310deeaab1717665d516f097ee742fb1 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Fri, 24 May 2024 03:17:26 -0400 Subject: [PATCH 2/7] Drop unused actions as objfile #2 Change-Id: I1766e0c2fa6bd4752a39ff7373fcbe3b40a6e2b5 Signed-off-by: Anton Volkov --- lld/ELF/Driver.cpp | 8 +------- lld/ELF/InputSection.cpp | 5 ++--- lld/ELF/MapFile.cpp | 4 ++-- lld/ELF/MarkLive.cpp | 15 ++++++++------- lld/ELF/SyntheticSections.cpp | 7 ++++--- lld/ELF/Writer.cpp | 17 +++++++++-------- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index c901197ed3bd..ce6bed6b6776 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2508,7 +2508,7 @@ static bool isSectionValidForAdlt(int fileIdx, InputSectionBase *s) { bool isNeededProgBits = type == SHT_PROGBITS && !(name.startswith(".got.plt") || name.startswith(".plt") || name.startswith(".got") || - name.startswith(".eh_frame_hdr"));// || name.startswith(".debug_")); + name.startswith(".eh_frame_hdr") || name.startswith(".debug_")); bool ret = isBaseType || isNeededProgBits; bool isDebug = false; @@ -2724,7 +2724,6 @@ void LinkerDriver::link(opt::InputArgList &args) { // With this the symbol table should be complete. After this, no new names // except a few linker-synthesized ones will be added to the symbol table. const size_t numObjsBeforeLTO = ctx->objectFiles.size(); - const size_t numSoBeforeLTO = ctx->sharedFilesExtended.size(); invokeELFT(compileBitcodeFiles, skipLinkedOutput); // Symbol resolution finished. Report backward reference problems, @@ -2741,11 +2740,6 @@ void LinkerDriver::link(opt::InputArgList &args) { // compileBitcodeFiles may have produced lto.tmp object files. After this, no // more file will be added. - if (config->adlt) { - auto newSharedFiles = - makeArrayRef(ctx->sharedFilesExtended).slice(numSoBeforeLTO); - parallelForEach(newSharedFiles, postParseSharedFileForAdlt); - } auto newObjectFiles = makeArrayRef(ctx->objectFiles).slice(numObjsBeforeLTO); parallelForEach(newObjectFiles, initializeLocalSymbols); parallelForEach(newObjectFiles, postParseObjectFile); diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 0eb2968413bd..7dc198d7b1a9 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -963,9 +963,8 @@ static void relocateNonAllocForRelocatable(InputSection *sec, uint8_t *buf) { template void InputSectionBase::relocate(uint8_t *buf, uint8_t *bufEnd) { - if (flags & SHF_EXECINSTR && - (config->adlt ? LLVM_UNLIKELY(getSharedFile()->splitStack) - : LLVM_UNLIKELY(getFile()->splitStack))) + if (!config->adlt && flags & SHF_EXECINSTR && + LLVM_UNLIKELY(getFile()->splitStack)) adjustSplitStackFunctionPrologues(buf, bufEnd); if (flags & SHF_ALLOC) { diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp index 51353287c90e..5c1d109ef73b 100644 --- a/lld/ELF/MapFile.cpp +++ b/lld/ELF/MapFile.cpp @@ -55,7 +55,7 @@ static void writeHeader(raw_ostream &os, uint64_t vma, uint64_t lma, // Returns a list of all symbols that we want to print out. static std::vector getSymbols() { std::vector v; - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (ELFFileBase *file : files) for (Symbol *b : file->getSymbols()) if (auto *dr = dyn_cast(b)) @@ -225,7 +225,7 @@ static void writeMapFile(raw_fd_ostream &os) { static void writeCref(raw_fd_ostream &os) { // Collect symbols and files. MapVector> map; - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (ELFFileBase *file : files) { for (Symbol *sym : file->getSymbols()) { if (isa(sym)) diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 61be1e13287f..f4fa5b90e265 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -345,13 +345,14 @@ template void MarkLive::mark() { // to from __start_/__stop_ symbols because there will only be one set of // symbols for the whole program. template void MarkLive::moveToMain() { - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; - for (ELFFileBase *file : files) - for (Symbol *s : file->getSymbols()) - if (auto *d = dyn_cast(s)) - if ((d->type == STT_GNU_IFUNC || d->type == STT_TLS) && d->section && - d->section->isLive()) - markSymbol(s); + auto files = ctx->objectFiles; + if (!config->adlt) + for (ELFFileBase *file : files) + for (Symbol *s : file->getSymbols()) + if (auto *d = dyn_cast(s)) + if ((d->type == STT_GNU_IFUNC || d->type == STT_TLS) && d->section && + d->section->isLive()) + markSymbol(s); for (InputSectionBase *sec : inputSections) { if (!sec->isLive() || !isValidCIdentifier(sec->name)) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 61d52dc894b5..e317d45b9162 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1531,7 +1531,8 @@ DynamicSection::computeContents() { } if (config->emachine == EM_AARCH64) { - if (config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) + if (!config->adlt && + config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) addInt(DT_AARCH64_BTI_PLT, 0); if (config->zPacPlt) addInt(DT_AARCH64_PAC_PLT, 0); @@ -2293,7 +2294,7 @@ void SymbolTableBaseSection::sortSymTabSymbolsInAdlt(size_t numLocals) { [makeKey](const SymbolTableEntry& lhs, const SymbolTableEntry& rhs) { return makeKey(lhs) <= makeKey(rhs); }); - + // extract file boundaries for local symbols for (auto iter = symbols.begin(); iter != localEnd; ++iter) if (auto* soext = dyn_cast_or_null>(iter->sym->file)) @@ -3495,7 +3496,7 @@ template void elf::splitSections() { llvm::TimeTraceScope timeScope("Split sections"); // splitIntoPieces needs to be called on each MergeInputSection // before calling finalizeContents(). - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; parallelForEach(files, [](ELFFileBase *file) { for (InputSectionBase *sec : file->getSections()) { if (!sec) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 6743de95cd2f..3b4d2c9e513d 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -526,7 +526,7 @@ template void elf::createSyntheticSections() { in.iplt = std::make_unique(); add(*in.iplt); - if (config->andFeatures) + if (!config->adlt && config->andFeatures) add(*make()); // .note.GNU-stack is always added when we are creating a re-linkable @@ -790,7 +790,7 @@ template static void markUsedLocalSymbols() { // See MarkLive::resolveReloc(). if (config->gcSections) return; - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (ELFFileBase *file : files) { ObjFile *f = cast>(file); for (InputSectionBase *s : f->getSections()) { @@ -862,7 +862,7 @@ template void Writer::copyLocalSymbols() { llvm::TimeTraceScope timeScope("Add local symbols"); if (config->copyRelocs && config->discard != DiscardPolicy::None) markUsedLocalSymbols(); - auto files = /*config->adlt ? ctx->sharedFilesExtended :*/ ctx->objectFiles; + auto files = ctx->objectFiles; for (ELFFileBase *file : files) { for (Symbol *b : file->getLocalSymbols()) { assert(b->isLocal() && "should have been caught in initializeSymbols()"); @@ -1489,7 +1489,7 @@ static DenseMap buildSectionOrder() { for (Symbol *sym : symtab->symbols()) addSym(*sym); - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (ELFFileBase *file : files) for (Symbol *sym : file->getLocalSymbols()) addSym(*sym); @@ -1906,7 +1906,7 @@ template void Writer::finalizeAddressDependentContent() { // block sections, input sections can shrink when the jump instructions at // the end of the section are relaxed. static void fixSymbolsAfterShrinking() { - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = ctx->objectFiles; for (InputFile *File : files) { parallelForEach(File->getSymbols(), [&](Symbol *Sym) { auto *def = dyn_cast(Sym); @@ -2207,9 +2207,10 @@ template void Writer::finalizeSections() { if (sym->includeInDynsym()) { partitions[sym->partition - 1].dynSymTab->addSymbol(sym); - if (auto *file = dyn_cast_or_null(sym->file)) - if (file->isNeeded && !sym->isUndefined()) - addVerneed(sym); + if (!config->adlt) // ADLT support ver syms + if (auto *file = dyn_cast_or_null(sym->file)) + if (file->isNeeded && !sym->isUndefined()) + addVerneed(sym); } } -- Gitee From d4081a2655121fb278912fbb8fa004fee0a96130 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Fri, 24 May 2024 05:30:25 -0400 Subject: [PATCH 3/7] Adlt ctx init Change-Id: If84f5d4f2d2ec09736a6929a1ed412b69ed9ad26 Signed-off-by: Anton Volkov --- lld/ELF/Adlt.cpp | 50 ++++++++++++++++++++++++++++ lld/ELF/Adlt.h | 62 +++++++++++++++++++++++++++++++++++ lld/ELF/CMakeLists.txt | 1 + lld/ELF/Config.h | 20 ----------- lld/ELF/Driver.cpp | 11 ++++--- lld/ELF/InputFiles.cpp | 11 ++++--- lld/ELF/InputSection.cpp | 6 ++-- lld/ELF/InputSection.h | 5 +-- lld/ELF/Relocations.cpp | 22 ++++++------- lld/ELF/SyntheticSections.cpp | 23 ++++++------- lld/ELF/Writer.cpp | 46 +++++++++++++++----------- 11 files changed, 182 insertions(+), 75 deletions(-) create mode 100644 lld/ELF/Adlt.cpp create mode 100644 lld/ELF/Adlt.h diff --git a/lld/ELF/Adlt.cpp b/lld/ELF/Adlt.cpp new file mode 100644 index 000000000000..e6258cf5249a --- /dev/null +++ b/lld/ELF/Adlt.cpp @@ -0,0 +1,50 @@ +//===- Adlt.cpp -------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// OHOS_LOCAL begin +#include "Adlt.h" +#include "llvm/Support/Casting.h" + +#include "InputFiles.h" + +using namespace llvm; + +using namespace lld; +using namespace lld::elf; +using namespace llvm::object; + +template +SharedFileExtended *AdltCtx::getSoExt(InputFile *file) { + assert(file); + return cast>(file); +} + +template +SharedFileExtended *AdltCtx::getSoExt(unsigned orderId) { + assert(orderId < sharedFilesExtended.size()); + return sharedFilesExtended[orderId]; +} + +void AdltCtx::checkDuplicatedSymbols() { + assert(!symNamesHist.empty()); + for (auto entry : symNamesHist) + if (entry.second > 1) + duplicatedSymNames.insert(entry.first); + symNamesHist.clear(); +} + +template SharedFileExtended * +AdltCtx::getSoExt(InputFile *file); +template SharedFileExtended * +AdltCtx::getSoExt(InputFile *file); +template SharedFileExtended * +AdltCtx::getSoExt(InputFile *file); +template SharedFileExtended * +AdltCtx::getSoExt(InputFile *file); + +// OHOS_LOCAL end diff --git a/lld/ELF/Adlt.h b/lld/ELF/Adlt.h new file mode 100644 index 000000000000..a1a87df03e46 --- /dev/null +++ b/lld/ELF/Adlt.h @@ -0,0 +1,62 @@ +//===- Adlt.h -------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// OHOS_LOCAL begin +#ifndef LLD_ELF_ADLT_H +#define LLD_ELF_ADLT_H + +#include "llvm/ADT/CachedHashString.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/BinaryFormat/ELF.h" +#include "llvm/Support/Endian.h" +#include + +namespace lld { +namespace elf { + +class ELFFileBase; +class InputFile; +class Symbol; +struct PhdrEntry; + +// class SharedFileExtended; // TODO: inherit from SharedFile +template class SharedFileExtended; +struct PhdrEntry; + +class AdltCtx { +public: + // TODO: inherit from SharedFile + // llvm::SmallVector sharedFilesExtended; + llvm::SmallVector sharedFilesExtended; + + void checkDuplicatedSymbols(); + + template SharedFileExtended *getSoExt(InputFile *file); + template SharedFileExtended *getSoExt(unsigned orderId); + + llvm::SetVector commonProgramHeaders; + bool withCfi = false; + // From input .rela.dyn, .rela.plt: + // Keep input library indexes that are needed for got/plt symbol + llvm::DenseMap> + gotPltInfo; // sym, soFile->orderIdx array; + + // Store duplicate symbols (only defined). + llvm::DenseMap + symNamesHist; // hash, count usages + llvm::DenseSet duplicatedSymNames; +}; + +// The only instance of Ctx struct. +extern std::unique_ptr adltCtx; + +} // namespace elf +} // namespace lld + +#endif // LLD_ELF_ADLT_H +// OHOS_LOCAL end diff --git a/lld/ELF/CMakeLists.txt b/lld/ELF/CMakeLists.txt index b37035d3e742..de8b3bf51d58 100644 --- a/lld/ELF/CMakeLists.txt +++ b/lld/ELF/CMakeLists.txt @@ -45,6 +45,7 @@ add_lld_library(lldELF Target.cpp Thunks.cpp Writer.cpp + Adlt.cpp LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 0d220c6afdf3..001f714454bc 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -34,8 +34,6 @@ class BinaryFile; class BitcodeFile; class ELFFileBase; class SharedFile; -template class SharedFileExtended; -struct PhdrEntry; // OHOS_LOCAL class InputSectionBase; class Symbol; @@ -390,7 +388,6 @@ struct Ctx { SmallVector> memoryBuffers; SmallVector objectFiles; SmallVector sharedFiles; - SmallVector sharedFilesExtended; SmallVector binaryFiles; SmallVector bitcodeFiles; SmallVector lazyBitcodeFiles; @@ -409,23 +406,6 @@ struct Ctx { llvm::DenseMap> backwardReferences; - - // OHOS_LOCAL begin - struct AdltCtx { - template SharedFileExtended *getSoExt(InputFile *file) { - return cast>(file); - } - - llvm::SetVector commonProgramHeaders; - bool withCfi = false; - // From input .rela.dyn, .rela.plt: - // Keep input library indexes that are needed for got/plt symbol - llvm::DenseMap> - gotPltInfo; // sym, soFile->orderIdx array; - // Store duplicate symbols (only defined). - llvm::DenseSet duplicatedSymNames; - } adlt; - // OHOS_LOCAL end }; // The only instance of Ctx struct. diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index ce6bed6b6776..c3a8a3ba4121 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -24,6 +24,7 @@ #include "Driver.h" #include "Config.h" +#include "Adlt.h" #include "ICF.h" #include "InputFiles.h" #include "InputSection.h" @@ -76,6 +77,7 @@ using namespace lld::elf; std::unique_ptr elf::config; std::unique_ptr elf::ctx; +std::unique_ptr elf::adltCtx; // OHOS_LOCAL std::unique_ptr elf::driver; static void setConfigs(opt::InputArgList &args); @@ -2570,12 +2572,13 @@ void LinkerDriver::link(opt::InputArgList &args) { // Fill duplicatedSymNames for defined syms. This will help to find duplicates. if (config->adlt) { + elf::adltCtx = std::make_unique(); ESymsCntMap eSymsHist; for (auto *file : files) buildSymsHist(file, eSymsHist); for (auto eSym : eSymsHist) if (eSym.second > 1) - ctx->adlt.duplicatedSymNames.insert(eSym.first); + adltCtx->duplicatedSymNames.insert(CachedHashStringRef(eSym.first)); eSymsHist.clear(); } @@ -2597,7 +2600,7 @@ void LinkerDriver::link(opt::InputArgList &args) { // producing a shared library. // We also need one if any shared libraries are used and for pie executables // (probably because the dynamic linker needs it). - config->hasDynSymTab = (config->adlt ? !ctx->sharedFilesExtended.empty() + config->hasDynSymTab = (config->adlt ? !adltCtx->sharedFilesExtended.empty() : !ctx->sharedFiles.empty()) || config->isPic || config->exportDynamic; @@ -2655,7 +2658,7 @@ void LinkerDriver::link(opt::InputArgList &args) { // No more lazy bitcode can be extracted at this point. Do post parse work // like checking duplicate symbols. if (config->adlt) - parallelForEach(ctx->sharedFilesExtended, postParseSharedFileForAdlt); + parallelForEach(adltCtx->sharedFilesExtended, postParseSharedFileForAdlt); parallelForEach(ctx->objectFiles, initializeLocalSymbols); parallelForEach(ctx->objectFiles, postParseObjectFile); @@ -2764,7 +2767,7 @@ void LinkerDriver::link(opt::InputArgList &args) { // Beyond this point, no new files are added. // Aggregate all input sections into one place. if (config->adlt) - for (auto it : llvm::enumerate(ctx->sharedFilesExtended)) + for (auto it : llvm::enumerate(adltCtx->sharedFilesExtended)) for (InputSectionBase *s : it.value()->getSections()) if (isSectionValidForAdlt(it.index(), s)) inputSections.push_back(s); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 0b6ac03faff1..d4b0519a11a1 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -8,6 +8,7 @@ #include "InputFiles.h" #include "Config.h" +#include "Adlt.h" #include "DWARF.h" #include "Driver.h" #include "InputSection.h" @@ -198,8 +199,8 @@ template static void doParseFile(InputFile *file) { // .so file if (config->adlt) if (auto *f = dyn_cast>(file)) { - f->orderIdx = ctx->sharedFilesExtended.size(); - ctx->sharedFilesExtended.push_back(cast(file)); + f->orderIdx = adltCtx->sharedFilesExtended.size(); + adltCtx->sharedFilesExtended.push_back(cast(file)); f->parseForAdlt(); return; } @@ -1073,8 +1074,8 @@ 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->adlt.duplicatedSymNames.count(CachedHashStringRef(name)) != 0) { - ctx->adlt.withCfi = ctx->adlt.withCfi || name == "__cfi_check"; + adltCtx->duplicatedSymNames.count(CachedHashStringRef(name)) != 0) { + adltCtx->withCfi = adltCtx->withCfi || name == "__cfi_check"; name = this->getUniqueName(name); } symbols[i] = symtab.insert(name); @@ -2040,7 +2041,7 @@ template void SharedFileExtended::parseDynamics() { 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) + adltCtx->duplicatedSymNames.count(CachedHashStringRef(name)) != 0) name = this->getUniqueName(name); if (sym.getBinding() == STB_LOCAL) { diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 7dc198d7b1a9..275f5a2202be 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -348,9 +348,9 @@ void InputSection::copyRelocations(uint8_t *buf, ArrayRef rels) { for (const RelTy &rel : rels) { RelType type = rel.getType(config->isMips64EL); const ObjFile *file = - config->adlt ? getSharedFile() : getFile(); + config->adlt ? getSoExt() : getFile(); Symbol &sym = config->adlt - ? getSharedFile()->getRelocTargetSymADLT(rel, *sec) + ? getSoExt()->getRelocTargetSymADLT(rel, *sec) : file->getRelocTargetSym(rel); auto *p = reinterpret_cast(buf); @@ -847,7 +847,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef rels) { if (!RelTy::IsRela) addend += target.getImplicitAddend(bufLoc, type); - Symbol &sym = config->adlt ? getSharedFile()->getSymbolFromElfSymTab( + Symbol &sym = config->adlt ? getSoExt()->getSymbolFromElfSymTab( rel.getSymbol(config->isMips64EL)) : getFile()->getRelocTargetSym(rel); if (config->adlt) { // TODO improve diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index b9f4541e77a9..1bcf8b4eca20 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -17,6 +17,7 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/TinyPtrVector.h" #include "llvm/Object/ELF.h" +#include "Adlt.h" namespace lld { namespace elf { @@ -138,8 +139,8 @@ public: } template - SharedFileExtended *getSharedFile() const { - return cast_or_null>(file); + SharedFileExtended *getSoExt() const { + return adltCtx->getSoExt(file); } // Used by --optimize-bb-jumps and RISC-V linker relaxation temporarily to diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 798440141025..590ff31b1bcf 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -42,6 +42,7 @@ #include "Relocations.h" #include "Config.h" +#include "Adlt.h" #include "InputFiles.h" #include "LinkerScript.h" #include "OutputSections.h" @@ -1311,14 +1312,14 @@ static void trackDynRelocAdlt(SharedFileExtended *soFile) { template static void trackGotPltAdlt(Symbol *sym, SharedFileExtended *soFile) { - ctx->adlt.gotPltInfo[sym].push_back(soFile->orderIdx); + adltCtx->gotPltInfo[sym].push_back(soFile->orderIdx); } // ADLT BEGIN template void RelocationScanner::tracePushRelocADLT(InputSectionBase &isec, Relocation &r) const { - auto file = sec.getSharedFile(); + auto file = sec.getSoExt(); auto fullOffset = isec.address + r.offset; lld::outs() << "[ADLT] Before push: [0x" + utohexstr(fullOffset) + "] type: " + toString(r.type) + @@ -1336,7 +1337,7 @@ void RelocationScanner::tracePushRelocADLT(InputSectionBase &isec, template void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, bool fromDynamic) { - auto file = sec.getSharedFile(); + auto file = sec.getSoExt(); bool isDebug = false; /*if (r->offset == 0x21F) // debug hint @@ -1464,11 +1465,10 @@ template void RelocationScanner::scanOne(RelTy *&i) { uint32_t symIndex = rel.getSymbol(config->isMips64EL); bool fromDynamic = false; if (config->adlt) - fromDynamic = sec.getSharedFile()->isDynamicSection(sec); - Symbol &sym = - config->adlt - ? sec.getSharedFile()->getSymbolADLT(symIndex, fromDynamic) - : sec.getFile()->getSymbol(symIndex); + fromDynamic = sec.getSoExt()->isDynamicSection(sec); + Symbol &sym = config->adlt + ? sec.getSoExt()->getSymbolADLT(symIndex, fromDynamic) + : sec.getFile()->getSymbol(symIndex); RelType type; // Deal with MIPS oddity. @@ -1808,9 +1808,9 @@ static bool handleNonPreemptibleIfunc(Symbol &sym) { } template static void addGotPltIndexAdlt(Symbol *s, bool isPlt) { - auto &vec = ctx->adlt.gotPltInfo[s]; + auto &vec = adltCtx->gotPltInfo[s]; for (auto &it : vec) { - auto *soFile = cast>(ctx->sharedFilesExtended[it]); + auto *soFile = cast>(adltCtx->sharedFilesExtended[it]); auto &entries = isPlt ? in.relaPlt->relocs : mainPart->relaDyn->relocs; auto &output = isPlt ? soFile->pltRelIndexes : soFile->dynRelIndexes; output.insert(entries.size() - 1); @@ -1923,7 +1923,7 @@ void elf::postScanRelocations() { // Local symbols may need the aforementioned non-preemptible ifunc and GOT // handling. They don't need regular PLT. - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (ELFFileBase *file : files) for (Symbol *sym : file->getLocalSymbols()) fn(*sym); diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index e317d45b9162..4120a2e00dd1 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -15,6 +15,7 @@ #include "SyntheticSections.h" #include "Config.h" +#include "Adlt.h" #include "DWARF.h" #include "EhFrame.h" #include "InputFiles.h" @@ -1398,11 +1399,11 @@ DynamicSection::computeContents() { part.dynStrTab->addString(config->rpath)); if (config->adlt) { - for (InputFile *file : ctx->sharedFilesExtended) { - auto *f = cast>(file); - for (size_t i = 0; i < f->dtNeeded.size(); i++) { + for (InputFile *file : adltCtx->sharedFilesExtended) { + auto *soExt = adltCtx->getSoExt(file); + for (size_t i = 0; i < soExt->dtNeeded.size(); i++) { auto tag = DT_NEEDED; - auto val = part.dynStrTab->addString(f->dtNeeded[i]); + auto val = part.dynStrTab->addString(soExt->dtNeeded[i]); if (llvm::find(entries, std::pair{tag, val}) == entries.end()) addInt(tag, val); @@ -1558,7 +1559,7 @@ DynamicSection::computeContents() { return &osd->osec; return (OutputSection *)nullptr; }; - for (InputFile *file : ctx->sharedFilesExtended) { + for (InputFile *file : adltCtx->sharedFilesExtended) { auto *f = cast>(file); auto initArray = findSection(f->addAdltPostfix(".init_array")); auto finiArray = findSection(f->addAdltPostfix(".fini_array")); @@ -2277,7 +2278,7 @@ void SymbolTableBaseSection::sortSymTabSymbolsInAdlt(size_t numLocals) { return {-1, file}; }; - for (InputFile* file : ctx->sharedFilesExtended) { + for (InputFile* file : adltCtx->sharedFilesExtended) { auto* soext = cast>(file); soext->sharedLocalSymbolIndex = llvm::None; soext->sharedGlobalSymbolIndex = llvm::None; @@ -4105,8 +4106,8 @@ AdltSection::AdltSection(StringTableSection& strTabSec) template void AdltSection::finalizeContents() { soInputs.clear(); - soInputs.reserve(ctx->sharedFilesExtended.size()); - for (InputFile* file : ctx->sharedFilesExtended) { + soInputs.reserve(adltCtx->sharedFilesExtended.size()); + for (InputFile* file : adltCtx->sharedFilesExtended) { auto* soext = cast>(file); soInputs.push_back(makeSoData(soext)); } @@ -4200,7 +4201,7 @@ typename AdltSection::CommonData AdltSection::makeCommonData() { return CommonData { UINT32_MAX, // .symtabSecIndex, filled in writeTo - ctx->adlt.commonProgramHeaders.size(), // .programHeadersAllocated + adltCtx->commonProgramHeaders.size(), // .programHeadersAllocated {}, // .phIndexes filled in writeTo }; } @@ -4349,7 +4350,7 @@ void AdltSection::extractProgramHeaderIndexes() { phdrsIndexes[it.value()] = static_cast(it.index()); }; - for (const PhdrEntry* phentry : ctx->adlt.commonProgramHeaders) { + for (const PhdrEntry* phentry : adltCtx->commonProgramHeaders) { auto it = phdrsIndexes.find(phentry); if (it != phdrsIndexes.end()) { common.phIndexes.push_back(it->second); @@ -4383,7 +4384,7 @@ void AdltSection::finalizeOnWrite() { template void AdltSection::finalizeOnWrite(size_t idx, SoData& soData) { - auto* soext = cast>(ctx->sharedFilesExtended[idx]); + auto* soext = cast>(adltCtx->sharedFilesExtended[idx]); // require SymbolTableBaseSection::sortSymTabSymbolsInAdlt for .symtab called soData.sharedLocalIndex = soext->sharedLocalSymbolIndex; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 3b4d2c9e513d..2c36a542a244 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -11,6 +11,7 @@ #include "ARMErrataFix.h" #include "CallGraphSort.h" #include "Config.h" +#include "Adlt.h" #include "InputFiles.h" #include "LinkerScript.h" #include "MapFile.h" @@ -570,8 +571,8 @@ InputSection *AdltWriter::getInputSection(OutputSection *sec) { } template void AdltWriter::checkPhdrs() { - for (auto *file : ctx->sharedFilesExtended) - if (auto *soFile = ctx->adlt.getSoExt(file)) + for (auto *file : adltCtx->sharedFilesExtended) + if (auto *soFile = adltCtx->getSoExt(file)) assert(!soFile->programHeaders.empty() && "ADLT: PHdr indexes can't be empty!"); } @@ -580,8 +581,8 @@ template void AdltWriter::checkRelocs() { assert(!mainPart->relaDyn->relocs.empty() && "ADLT: relaDyn can't be empty!"); assert(!in.relaPlt->relocs.empty() && "ADLT: relaPlt can't be empty!"); - for (auto *file : ctx->sharedFilesExtended) - if (auto *soFile = ctx->adlt.getSoExt(file)) { + for (auto *file : adltCtx->sharedFilesExtended) + if (auto *soFile = adltCtx->getSoExt(file)) { assert(!soFile->dynRelIndexes.empty() && "ADLT: relaDyn indexes can't be empty!"); assert(!soFile->pltRelIndexes.empty() && @@ -592,12 +593,11 @@ template void AdltWriter::checkRelocs() { template void AdltWriter::trackPhdr(OutputSection *sec, PhdrEntry *phdr) { auto *isec = getInputSection(sec); - if (isec && isec->file) - if (auto *soFile = ctx->adlt.getSoExt(isec->file)) { - soFile->programHeaders.insert(phdr); - return; - } - ctx->adlt.commonProgramHeaders.insert(phdr); + if (isec && isec->file) { + isec->getSoExt()->programHeaders.insert(phdr); + return; + } + adltCtx->commonProgramHeaders.insert(phdr); } template void AdltWriter::traceRelocs() { @@ -612,17 +612,25 @@ template void AdltWriter::traceRelocs() { lld::outs() << "\n"; }; + auto printSym = [&](Symbol *sym) { + if (sym->getName().empty() && sym->isSection()) { + Defined *d = cast(sym); + return d->section->name; + } + return sym->getName(); + }; + auto printRelocTable = [&](auto *relSec, auto &outIndexes) { for (auto &it : outIndexes) // print relocs if (DynamicReloc *rel = &relSec->relocs[it]) lld::outs() << it << ":\t" << rel->inputSec->name << " + 0x" << utohexstr(rel->offsetInSec) << "\t" - << toString(rel->type) << "\t" << rel->sym->getName() + << toString(rel->type) << "\t" << printSym(rel->sym) << " + 0x" << utohexstr(rel->addend) << '\n'; }; - for (auto *file : ctx->sharedFilesExtended) - if (auto *soFile = ctx->adlt.getSoExt(file)) { + for (auto *file : adltCtx->sharedFilesExtended) + if (auto *soFile = adltCtx->getSoExt(file)) { lld::outs() << soFile->soName << ":\n"; lld::outs() << "Dyn relocs (" << soFile->dynRelIndexes.size() << ")"; printIndexes(soFile->dynRelIndexes); @@ -659,13 +667,13 @@ template void AdltWriter::tracePhdrs() { << "\t" << p->firstSec->name << '\n'; }; - auto &common = ctx->adlt.commonProgramHeaders; + auto &common = adltCtx->commonProgramHeaders; lld::outs() << "Common Program Headers (" << common.size() << ")"; printIndexes(common); printPhTable(common); - for (auto *file : ctx->sharedFilesExtended) - if (auto *soFile = ctx->adlt.getSoExt(file)) { + for (auto *file : adltCtx->sharedFilesExtended) + if (auto *soFile = adltCtx->getSoExt(file)) { auto &headers = soFile->programHeaders; lld::outs() << soFile->soName << "\n"; lld::outs() << "Program headers (" << headers.size() << ")"; @@ -1189,7 +1197,7 @@ void PhdrEntry::add(OutputSection *sec) { // OHOS_LOCAL begin if (config->adlt) { - if (ctx->adlt.withCfi && p_type == PT_LOAD) { + if (adltCtx->withCfi && p_type == PT_LOAD) { // check cfi.h: LIBRARY_ALIGNMENT and _BITS constexpr uint32_t kCFILibraryAlignment = 1UL << 18; firstSec->alignment = kCFILibraryAlignment; @@ -2127,7 +2135,7 @@ template void Writer::finalizeSections() { // copy relocations, etc. Note that relocations for non-alloc sections are // directly processed by InputSection::relocateNonAlloc. if (config->adlt) - for (auto &it : llvm::enumerate(ctx->sharedFilesExtended)) { + for (auto &it : llvm::enumerate(adltCtx->sharedFilesExtended)) { auto *soFile = cast>(it.value()); auto sections = soFile->getSections(); // scan .rela.dyn (base: SHT_NULL) @@ -2521,7 +2529,7 @@ SmallVector Writer::createPhdrs(Partition &part) { auto file = adltWriter.getInputSection(sec)->file; if (!file) return llvm::None; - return cast>(file)->orderIdx; + return adltCtx->getSoExt(file)->orderIdx; }; // OHOS_LOCAL end -- Gitee From ffb574f5308b65065551ced37bac3cfbeecb2810 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Fri, 24 May 2024 07:48:22 -0400 Subject: [PATCH 4/7] Adlt build hist. Remove old trace. Change-Id: Iee134ed4d135f5e5ff6968d107577711973eea1f Signed-off-by: Anton Volkov --- lld/ELF/Adlt.cpp | 16 +++- lld/ELF/Adlt.h | 2 + lld/ELF/Driver.cpp | 41 ++-------- lld/ELF/InputFiles.cpp | 160 ++++++++-------------------------------- lld/ELF/InputFiles.h | 27 +++---- lld/ELF/Relocations.cpp | 24 ------ 6 files changed, 64 insertions(+), 206 deletions(-) diff --git a/lld/ELF/Adlt.cpp b/lld/ELF/Adlt.cpp index e6258cf5249a..b5e68b4c2e08 100644 --- a/lld/ELF/Adlt.cpp +++ b/lld/ELF/Adlt.cpp @@ -30,14 +30,23 @@ SharedFileExtended *AdltCtx::getSoExt(unsigned orderId) { return sharedFilesExtended[orderId]; } +template +void AdltCtx::buildSymbolsHist(std::vector &files) { + for (auto *file : files) + if (auto *soExt = getSoExt(file)) + soExt->buildSymbolsHist(); + assert(!symNamesHist.empty()); +} + void AdltCtx::checkDuplicatedSymbols() { assert(!symNamesHist.empty()); for (auto entry : symNamesHist) if (entry.second > 1) - duplicatedSymNames.insert(entry.first); + duplicatedSymNames.insert(CachedHashStringRef(entry.first)); symNamesHist.clear(); } +// TODO: inherit from SharedFile template SharedFileExtended * AdltCtx::getSoExt(InputFile *file); template SharedFileExtended * @@ -47,4 +56,9 @@ AdltCtx::getSoExt(InputFile *file); template SharedFileExtended * AdltCtx::getSoExt(InputFile *file); +template void AdltCtx::buildSymbolsHist(std::vector &); +template void AdltCtx::buildSymbolsHist(std::vector &); +template void AdltCtx::buildSymbolsHist(std::vector &); +template void AdltCtx::buildSymbolsHist(std::vector &); + // OHOS_LOCAL end diff --git a/lld/ELF/Adlt.h b/lld/ELF/Adlt.h index a1a87df03e46..4fefb1ca036a 100644 --- a/lld/ELF/Adlt.h +++ b/lld/ELF/Adlt.h @@ -36,6 +36,8 @@ public: void checkDuplicatedSymbols(); + template void buildSymbolsHist(std::vector &files); + template SharedFileExtended *getSoExt(InputFile *file); template SharedFileExtended *getSoExt(unsigned orderId); diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index c3a8a3ba4121..fa2afc8e6a6d 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2498,27 +2498,6 @@ static void postParseSharedFileForAdlt(ELFFileBase *file) { } } -static bool isSectionValidForAdlt(int fileIdx, InputSectionBase *s) { - if (!s || s == &InputSection::discarded) - return false; - uint32_t type = s->type; - StringRef name = s->name; - - bool isBaseType = type == SHT_NOBITS || type == SHT_NOTE || - type == SHT_INIT_ARRAY || type == SHT_FINI_ARRAY; - // TODO: fix .debug_info relocation - bool isNeededProgBits = - type == SHT_PROGBITS && - !(name.startswith(".got.plt") || name.startswith(".plt") || name.startswith(".got") || - name.startswith(".eh_frame_hdr") || name.startswith(".debug_")); - bool ret = isBaseType || isNeededProgBits; - - bool isDebug = false; - if (ret && isDebug) - lld::outs() << "[isSectionValidForAdlt]: " << name << "\n"; - return ret; -} - // Do actual linking. Note that when this function is called, // all linker scripts have already been parsed. void LinkerDriver::link(opt::InputArgList &args) { @@ -2565,6 +2544,9 @@ void LinkerDriver::link(opt::InputArgList &args) { for (auto *arg : args.filtered(OPT_trace_symbol)) symtab->insert(arg->getValue())->traced = true; + if (config->adlt) // Init ADLT context + elf::adltCtx = std::make_unique(); + // Handle -u/--undefined before input files. If both a.a and b.so define foo, // -u foo a.a b.so will extract a.a. for (StringRef name : config->undefined) @@ -2572,14 +2554,8 @@ void LinkerDriver::link(opt::InputArgList &args) { // Fill duplicatedSymNames for defined syms. This will help to find duplicates. if (config->adlt) { - elf::adltCtx = std::make_unique(); - ESymsCntMap eSymsHist; - for (auto *file : files) - buildSymsHist(file, eSymsHist); - for (auto eSym : eSymsHist) - if (eSym.second > 1) - adltCtx->duplicatedSymNames.insert(CachedHashStringRef(eSym.first)); - eSymsHist.clear(); + invokeELFT(adltCtx->buildSymbolsHist, files); + adltCtx->checkDuplicatedSymbols(); } // Add all files to the symbol table. This will add almost all @@ -2767,12 +2743,11 @@ void LinkerDriver::link(opt::InputArgList &args) { // Beyond this point, no new files are added. // Aggregate all input sections into one place. if (config->adlt) - for (auto it : llvm::enumerate(adltCtx->sharedFilesExtended)) - for (InputSectionBase *s : it.value()->getSections()) - if (isSectionValidForAdlt(it.index(), s)) + for (auto *file : adltCtx->sharedFilesExtended) + for (InputSectionBase *s : file->getSections()) + if (file->isValidSection(s)) inputSections.push_back(s); - for (InputFile *f : ctx->objectFiles) for (InputSectionBase *s : f->getSections()) if (s && s != &InputSection::discarded) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index d4b0519a11a1..7db5dcb675ae 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -159,18 +159,6 @@ static bool isCompatible(InputFile *file) { return false; } -template -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, ESymsCntMap &eSymsHist) { - invokeELFT(doBuildSymsHist, file, eSymsHist); -} - template static void doParseFile(InputFile *file) { if (!isCompatible(file)) return; @@ -1048,18 +1036,6 @@ InputSectionBase *ObjFile::createInputSection(uint32_t idx, return make(*this, sec, name); } - -template -void ObjFile::buildSymsHist(ESymsCntMap &eSymsHist) { - ArrayRef eSyms = this->getELFSyms(); - for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i) { - if (!eSyms[i].isDefined()) - continue; - StringRef name = CHECK(eSyms[i].getName(stringTable), this); - eSymsHist[CachedHashStringRef(name)]++; - } -} - // Initialize this->Symbols. this->Symbols is a parallel array as // its corresponding ELF symbol table. template @@ -1247,14 +1223,6 @@ template void ObjFile::postParse() { if (sym.binding == STB_WEAK || binding == STB_WEAK) continue; std::lock_guard lock(mu); - if (config->adlt) { - auto *f = cast>(this); - bool isDebug = false; - if (isDebug) { - lld::outs() << "Put to duplicates for: " << archiveName << "\n"; - f->traceSymbol(sym); - } - } ctx->duplicates.push_back({&sym, this, sec, eSym.st_value}); } } @@ -1658,49 +1626,39 @@ SharedFileExtended::SharedFileExtended(MemoryBufferRef mb, const_cast(this->fileKind) = InputFile::SharedKind; } +template void SharedFileExtended::buildSymbolsHist() { + ArrayRef eSyms = this->template getELFSyms(); + for (size_t i = this->firstGlobal, end = eSyms.size(); i != end; ++i) { + if (!eSyms[i].isDefined()) + continue; + StringRef name = CHECK(eSyms[i].getName(this->stringTable), this); + adltCtx->symNamesHist[CachedHashStringRef(name)]++; + } +} + +template +bool SharedFileExtended::isValidSection(InputSectionBase *s) { + if (!s || s == &InputSection::discarded) + return false; + uint32_t type = s->type; + StringRef name = s->name; + + bool isBaseType = type == SHT_NOBITS || type == SHT_NOTE || + type == SHT_INIT_ARRAY || type == SHT_FINI_ARRAY; + // TODO: fix .debug-* sections relocation + bool isNeededProgBits = + type == SHT_PROGBITS && + !(name.startswith(".got.plt") || name.startswith(".plt") || + name.startswith(".got") || name.startswith(".eh_frame_hdr") || + name.startswith(".debug_")); + bool ret = isBaseType || isNeededProgBits; + return ret; +} + template void SharedFileExtended::parseForAdlt() { this->parse(); parseDynamics(); parseElfSymTab(); - - bool isDebug = false; // debug hint - if (!isDebug) - return; - - const ELFFile obj = this->getObj(); - ArrayRef objSections = this->template getELFShdrs(); - - lld::outs() << "Parse symbols from .symtab:\n"; - auto p = obj.getSection(symTabSecIdx); - if (p.takeError()) { - fatal("getSection failed: " + llvm::toString(p.takeError())); - } - const Elf_Shdr *elfSymTab = *p; - StringRef strTable = *obj.getStringTableForSymtab(*elfSymTab); - - auto eSyms = *obj.symbols(elfSymTab); - this->symbols.resize(this->symbols.size() + eSyms.size()); - for (const Elf_Sym &sym : eSyms) { - if (!sym.isDefined()) - continue; - - auto rawSec = obj.getSection(sym.st_shndx); - if (rawSec.takeError()) - continue; - if (isDebug) - traceElfSymbol(sym, strTable); - } - if (isDebug) - lld::outs() << '\n'; - - lld::outs() << "Parse offsets of some sections:\n"; - for (const Elf_Shdr &sec : objSections) { - auto name = check(obj.getSectionName(sec)); - if (name == ".init_array" || name == ".fini_array" || name == ".data" || - name == ".data.rel.ro" || name == ".bss.rel.ro" || name == ".bss") - traceElfSection(sec); - } - lld::outs() << '\n'; } template void SharedFileExtended::postParseForAdlt() { @@ -1773,8 +1731,6 @@ Defined *SharedFileExtended::findSectionSymbol(uint64_t offset) const { }); auto d = *candidates.begin(); - if (isDebug) - traceSymbol(*d, "found section sym: "); return d; } @@ -1821,7 +1777,6 @@ bool SharedFileExtended::isDynamicSection(InputSectionBase &sec) const { template Defined *SharedFileExtended::findDefinedSymbol( uint64_t offset, llvm::function_ref extraCond) const { - bool isDebug = false; /*if (offset == 0x7738) // debug hint isDebug = true;*/ auto predRange = [=](Symbol *sym) { @@ -1841,15 +1796,9 @@ Defined *SharedFileExtended::findDefinedSymbol( auto ret = std::find_if(i, e, predRange); if (ret != e) { // item was found Defined *d = cast(*ret); - if (isDebug) - traceSymbol(*d, d->isSection() ? "found section sym: " - : "found defined sym: "); return d; } - auto *sectionSym = findSectionSymbol(offset); - if (isDebug && sectionSym) - traceSymbol(*sectionSym, "found section sym: "); return sectionSym; } @@ -1859,57 +1808,6 @@ SharedFileExtended::getShStrTab(ArrayRef elfSections) { return CHECK(this->getObj().getSectionStringTable(elfSections), this); } -template -void SharedFileExtended::traceElfSymbol(const Elf_Sym &sym, - StringRef strTable) const { - const ELFFile obj = this->getObj(); - auto rawSec = obj.getSection(sym.st_shndx); - auto parsedSec = - !rawSec.takeError() ? *obj.getSection(sym.st_shndx) : nullptr; - lld::outs() << "File: " << soName << " symName: " << *sym.getName(strTable) - << " val: 0x" << utohexstr(sym.st_value) << " sec of sym: " - << (parsedSec ? *obj.getSectionName(*parsedSec) : "unknown!") - << " sym type: 0x" << utohexstr(sym.getType()) - << " sym binding: 0x" << utohexstr(sym.getBinding()) << '\n'; -} - -template -void SharedFileExtended::traceElfSection(const Elf_Shdr &sec) const { - const ELFFile obj = this->getObj(); - - auto secName = *obj.getSectionName(sec); - lld::outs() << "File: " << soName << " sec: " << secName << " sec addr: 0x" - << utohexstr(sec.sh_addr) << " sec offs: 0x" - << utohexstr(sec.sh_offset) << " sec ent size: 0x" - << utohexstr(sec.sh_entsize) << '\n'; -} - -template -void SharedFileExtended::traceSymbol(const Symbol &sym, - StringRef title) const { - lld::outs() << "File: " << soName << ": " + title - << " symName: " << sym.getName() << " exportDynamic: 0x" - << utohexstr(sym.exportDynamic); - if (!sym.isDefined()) { - lld::outs() << '\n'; - return; - } - auto &d = cast(sym); - lld::outs() << " val: 0x" << utohexstr(d.value) - << " sec of sym: " << (d.section ? d.section->name : "unknown!") - << " sym type: 0x" << utohexstr(d.type) << " sym binding: 0x" - << utohexstr(d.binding) << '\n'; -} - -template -void SharedFileExtended::traceSection(const SectionBase &sec, - StringRef title) const { - lld::outs() << "File: " << soName << ": " + title << " sec: " << sec.name - << " sec addr: 0x" << utohexstr(sec.address) << " sec offs: 0x" - << utohexstr(sec.getOffset(0)) << " sec ent size: 0x" - << utohexstr(sec.entsize) << '\n'; -} - template Symbol &SharedFileExtended::getDynamicSymbol(uint32_t symbolIndex) const { return *this->symbols[symbolIndex]; diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index b8d47779488d..42db1858130e 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -47,8 +47,6 @@ extern std::unique_ptr tar; llvm::Optional readFile(StringRef path); // Add symbols in File to the symbol table. -typedef llvm::DenseMap ESymsCntMap; -void buildSymsHist(InputFile *file, ESymsCntMap &eSymsHist); void parseFile(InputFile *file); // The root class of input files. @@ -96,14 +94,6 @@ public: fileKind == BitcodeKind); return symbols; } - - // ADLT beg - ArrayRef getAllSymbols() const { return allSymbols; } - - SmallVector allSymbols; - // ADLT end - - // Get filename to use for linker script processing. StringRef getNameForScript() const; @@ -211,6 +201,11 @@ public: return getELFSyms().slice(firstGlobal); } + // OHOS_LOCAL begin + virtual void buildSymbolsHist() {} + virtual bool isValidSection(InputSectionBase *s) { return true; } + // OHOS_LOCAL end + protected: // Initializes this class's member variables. template void init(); @@ -294,7 +289,6 @@ public: // Get cached DWARF information. DWARFCache *getDwarf(); - void buildSymsHist(ESymsCntMap &eSymsHist); void initializeLocalSymbols(); void postParse(); @@ -401,6 +395,9 @@ public: return f->kind() == InputFile::SharedKind; } + void buildSymbolsHist() override; + bool isValidSection(InputSectionBase *s) override; + void parseForAdlt(); void postParseForAdlt(); @@ -441,12 +438,6 @@ public: return *this->allSymbols[symbolIndex]; } - void traceElfSymbol(const Elf_Sym &sym, StringRef strTable) const; - void traceElfSection(const Elf_Shdr &sec) const; - - void traceSymbol(const Symbol &sym, StringRef title = "") const; - void traceSection(const SectionBase &sec, StringRef title = "") const; - public: // the input order of the file as it presented in ADLT image size_t orderIdx; @@ -489,6 +480,8 @@ protected: virtual StringRef getUniqueName(StringRef origName) const override; private: + SmallVector allSymbols; + void parseDynamics(); // SharedFile compability void parseElfSymTab(); // ObjectFile compability diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 590ff31b1bcf..fa1884c6d14c 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -466,9 +466,6 @@ private: // ADLT template void processForADLT(const RelTy &rel, Relocation *r, bool fromDynamic); - - template - void tracePushRelocADLT(InputSectionBase &isec, Relocation &r) const; }; } // namespace @@ -1316,24 +1313,6 @@ static void trackGotPltAdlt(Symbol *sym, SharedFileExtended *soFile) { } // ADLT BEGIN -template -void RelocationScanner::tracePushRelocADLT(InputSectionBase &isec, - Relocation &r) const { - auto file = sec.getSoExt(); - auto fullOffset = isec.address + r.offset; - lld::outs() << "[ADLT] Before push: [0x" + utohexstr(fullOffset) + - "] type: " + toString(r.type) + - " expr: " + std::to_string(r.expr) + " offset: 0x" + - utohexstr(r.offset) + " addend: 0x" + utohexstr(r.addend) + - ".\n"; - lld::outs() << "section where: "; - file->traceSection(isec); - - lld::outs() << "r->sym: "; - file->traceSymbol(*r.sym); - lld::outs() << "\n"; -} - template void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, bool fromDynamic) { @@ -1354,9 +1333,6 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, r->offset -= fromDynamic ? secWhere->address : sec.address; assert(r->type); - if (isDebug) - tracePushRelocADLT(*secWhere, *r); - // resolve relocs switch (r->type) { // dyn relocs -- Gitee From 597b2afe88456584684189eb2ed177b696fd59f5 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Fri, 24 May 2024 11:03:35 -0400 Subject: [PATCH 5/7] Adlt cleanup SharedFileExtended Change-Id: I99a1ec2696f000fd9dd7284cc896f5678e05635f Signed-off-by: Anton Volkov --- lld/ELF/Adlt.cpp | 12 +- lld/ELF/Driver.cpp | 12 +- lld/ELF/InputFiles.cpp | 240 ++++++++++------------------------ lld/ELF/InputFiles.h | 67 ++++------ lld/ELF/InputSection.cpp | 8 +- lld/ELF/Relocations.cpp | 16 +-- lld/ELF/SyntheticSections.cpp | 10 +- 7 files changed, 121 insertions(+), 244 deletions(-) diff --git a/lld/ELF/Adlt.cpp b/lld/ELF/Adlt.cpp index b5e68b4c2e08..277d24154024 100644 --- a/lld/ELF/Adlt.cpp +++ b/lld/ELF/Adlt.cpp @@ -47,14 +47,10 @@ void AdltCtx::checkDuplicatedSymbols() { } // TODO: inherit from SharedFile -template SharedFileExtended * -AdltCtx::getSoExt(InputFile *file); -template SharedFileExtended * -AdltCtx::getSoExt(InputFile *file); -template SharedFileExtended * -AdltCtx::getSoExt(InputFile *file); -template SharedFileExtended * -AdltCtx::getSoExt(InputFile *file); +template SharedFileExtended *AdltCtx::getSoExt(InputFile *); +template SharedFileExtended *AdltCtx::getSoExt(InputFile *); +template SharedFileExtended *AdltCtx::getSoExt(InputFile *); +template SharedFileExtended *AdltCtx::getSoExt(InputFile *); template void AdltCtx::buildSymbolsHist(std::vector &); template void AdltCtx::buildSymbolsHist(std::vector &); diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index fa2afc8e6a6d..3f3726f2644e 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2479,19 +2479,19 @@ static void postParseObjectFile(ELFFileBase *file) { } } -static void postParseSharedFileForAdlt(ELFFileBase *file) { +static void postParseSharedFile(ELFFileBase *file) { switch (config->ekind) { case ELF32LEKind: - cast>(file)->postParseForAdlt(); + adltCtx->getSoExt(file)->postParse(); break; case ELF32BEKind: - cast>(file)->postParseForAdlt(); + adltCtx->getSoExt(file)->postParse(); break; case ELF64LEKind: - cast>(file)->postParseForAdlt(); + adltCtx->getSoExt(file)->postParse(); break; case ELF64BEKind: - cast>(file)->postParseForAdlt(); + adltCtx->getSoExt(file)->postParse(); break; default: llvm_unreachable(""); @@ -2634,7 +2634,7 @@ void LinkerDriver::link(opt::InputArgList &args) { // No more lazy bitcode can be extracted at this point. Do post parse work // like checking duplicate symbols. if (config->adlt) - parallelForEach(adltCtx->sharedFilesExtended, postParseSharedFileForAdlt); + parallelForEach(adltCtx->sharedFilesExtended, postParseSharedFile); parallelForEach(ctx->objectFiles, initializeLocalSymbols); parallelForEach(ctx->objectFiles, postParseObjectFile); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 7db5dcb675ae..3514782dd7c8 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -188,8 +188,8 @@ template static void doParseFile(InputFile *file) { if (config->adlt) if (auto *f = dyn_cast>(file)) { f->orderIdx = adltCtx->sharedFilesExtended.size(); - adltCtx->sharedFilesExtended.push_back(cast(file)); - f->parseForAdlt(); + adltCtx->sharedFilesExtended.push_back(f); + f->parse(); return; } @@ -327,6 +327,8 @@ ELFFileBase::ELFFileBase(Kind k, MemoryBufferRef mb) : InputFile(k, mb) { } } +// namespace +// { template static const Elf_Shdr *findSection(ArrayRef sections, uint32_t type) { for (const Elf_Shdr &sec : sections) @@ -334,6 +336,9 @@ static const Elf_Shdr *findSection(ArrayRef sections, uint32_t type) { return &sec; return nullptr; } +// } // namespace + + template void ELFFileBase::init() { using Elf_Shdr = typename ELFT::Shdr; @@ -573,6 +578,7 @@ void ObjFile::initializeSections(bool ignoreComdats, this->sections[i] = createInputSection(i, sec, name); this->sections[i]->address = sec.sh_addr; this->sections[i]->size = sec.sh_size; + sectionsMap[sec.sh_addr] = i; } switch (sec.sh_type) { @@ -1590,39 +1596,10 @@ template void SharedFile::parse() { } } -template -void SharedFileExtended::resolveDuplicatesForAdlt() { - auto pred = [&](DuplicateSymbol dup) { - auto sym = dup.sym; - if (!sym->isDefined()) - return true; - - auto d = cast(sym); - return !d->section && !d->getOutputSection(); - }; - static std::mutex mu; - { - std::lock_guard lock(mu); - llvm::erase_if(ctx->duplicates, pred); - } - - if (ctx->duplicates.empty()) - return; - - { - std::lock_guard lock(mu); - for (DuplicateSymbol &dup : ctx->duplicates) - warn("duplicate: " + dup.file->getName() + ": " + dup.section->name + - ": " + dup.sym->getName()); - ctx->duplicates.clear(); - } -} - template SharedFileExtended::SharedFileExtended(MemoryBufferRef mb, StringRef soName) - : ObjFile(mb, soName), soName(soName), - simpleSoName(path::stem(soName)) { + : ObjFile(mb, soName), soName(soName) { const_cast(this->fileKind) = InputFile::SharedKind; } @@ -1655,177 +1632,103 @@ bool SharedFileExtended::isValidSection(InputSectionBase *s) { return ret; } -template void SharedFileExtended::parseForAdlt() { - this->parse(); +template +bool SharedFileExtended::isDynamicSection(InputSectionBase *s) const { + return s->type == llvm::ELF::SHT_NULL || s->name.startswith(".got.plt"); +} + +template void SharedFileExtended::parse(bool ignoreComdats) { + ObjFile::parse(ignoreComdats); parseDynamics(); parseElfSymTab(); } -template void SharedFileExtended::postParseForAdlt() { - this->initializeLocalSymbols(); - this->postParse(); - resolveDuplicatesForAdlt(); +template void SharedFileExtended::postParse() { + ObjFile::initializeLocalSymbols(); + ObjFile::postParse(); } template -StringRef SharedFileExtended::addAdltPostfix(StringRef input) const { +StringRef SharedFileExtended::getUniqueName(StringRef input) const { if (input.empty()) return input; auto suffix = Twine("__") + Twine::utohexstr(this->orderIdx); return saver().save(input + suffix); } template -bool SharedFileExtended::addAdltPostfix(Symbol *s) { - StringRef newName = addAdltPostfix(s->getName()); - if (s->getName() == newName) - return false; - s->setName(newName); - return true; -} - -template -StringRef SharedFileExtended::getUniqueName(StringRef origName) const { - return addAdltPostfix(origName); +Defined &SharedFileExtended::getDefinedLocalSym(unsigned offset) { + auto getSym = [&](unsigned offs) { + return localSymbols[this->definedSymbolsMap[offs]]; + }; + auto *s = getSym(offset); + if (!s || s == localSymbols[0]) { + auto sec = findSection(offset); + s = getSym(sec->address); + } + assert(s && s->isDefined()); + return cast(*s); } -// TODO: optimize 2 lookups template -bool SharedFileExtended::saveSymbol(const Defined& d) const { - auto found = elf::symtab->find(d.getName()); - if (found) - return false; - in.symTab->addSymbol(elf::symtab->addSymbol(d)); - return true; +InputSectionBase &SharedFileExtended::getSection(unsigned offset) { + auto *sec = this->sections[this->sectionsMap[offset]]; + if (offset && sec->type == SHT_NULL) + sec = findSection(offset); + return *sec; } template -Defined *SharedFileExtended::findSectionSymbol(uint64_t offset) const { - bool isDebug = false; - /*if (offset == 0x7738) // debug hint - isDebug = true;*/ - llvm::SmallVector candidates; - for (auto *sym : this->allSymbols) { - if (!sym || !sym->isSection()) - continue; - assert(sym->isDefined()); - Defined *d = cast(sym); - uint64_t low = d->section->address; - uint64_t high = low + d->section->size; - - if (isDebug) - lld::outs() << "offset: 0x" + utohexstr(offset) + - " sect name: " + d->section->name + "low 0x" + - utohexstr(low) + " high: 0x" + utohexstr(high) + "\n"; - bool isGood = (offset >= low) && (offset < high); - if (!isGood) - continue; - candidates.push_back(d); - } - if (candidates.empty()) // no suitable items found - return nullptr; - - llvm::sort(candidates, [offset](Defined *d1, Defined *d2) { - auto a1 = d1->section->address; - auto a2 = d2->section->address; - return (offset - a1 < offset - a2); - }); - - auto d = *candidates.begin(); - return d; -} - -template -InputSectionBase * -SharedFileExtended::findInputSection(StringRef name) const { - for (InputSectionBase *sec : this->sections) - if (sec && sec->name == name) - return sec; - return nullptr; +InputSectionBase &SharedFileExtended::getSectionByOrder(unsigned idx) { + auto *sec = this->sections[idx]; + if (!sec) + sec = &InputSection::discarded; + return *sec; } template -InputSectionBase * -SharedFileExtended::findInputSection(uint64_t offset) const { +InputSectionBase *SharedFileExtended::findSection(unsigned offset) { llvm::SmallVector candidates; for (InputSectionBase *sec : this->sections) { if (!sec) continue; - if (sec->address == offset) - return sec; - uint64_t low = sec->address; - uint64_t high = low + sec->size; - bool isGood = (offset >= low) && (offset < high); - if (!isGood) - continue; - candidates.push_back(sec); + auto low = sec->address, high = low + sec->size; + if (offset >= low && offset < high) + candidates.push_back(sec); } if (candidates.empty()) // no suitable items found return nullptr; - - auto lessAddr = [&](auto *s1, auto *s2) { return s1->address < s2->address; }; - auto i = candidates.begin(); - auto e = candidates.end(); - auto ret = std::min_element(i, e, lessAddr); - return *ret; -} - -template -bool SharedFileExtended::isDynamicSection(InputSectionBase &sec) const { - return sec.type == llvm::ELF::SHT_NULL || sec.name.startswith(".got.plt"); -} - -template -Defined *SharedFileExtended::findDefinedSymbol( - uint64_t offset, llvm::function_ref extraCond) const { - /*if (offset == 0x7738) // debug hint - isDebug = true;*/ - auto predRange = [=](Symbol *sym) { - if (!sym || sym->isUndefined()) - return false; - - Defined *d = cast(sym); - if (d->file != this) - return false; - - bool goodVal = d->section->address + d->value == offset; - return goodVal && extraCond(d); - }; - - auto i = this->allSymbols.begin(); - auto e = this->allSymbols.end(); - auto ret = std::find_if(i, e, predRange); - if (ret != e) { // item was found - Defined *d = cast(*ret); - return d; - } - auto *sectionSym = findSectionSymbol(offset); - return sectionSym; -} - -template -StringRef -SharedFileExtended::getShStrTab(ArrayRef elfSections) { - return CHECK(this->getObj().getSectionStringTable(elfSections), this); + llvm::sort(candidates, [offset](InputSectionBase *a, InputSectionBase *b) { + return (offset - a->address < offset - b->address); + }); + return *candidates.begin(); } template Symbol &SharedFileExtended::getDynamicSymbol(uint32_t symbolIndex) const { return *this->symbols[symbolIndex]; } +template +Symbol &SharedFileExtended::getLocalSymbol(uint32_t symbolIndex) const{ + assert(symbolIndex && (symbolIndex < localSymbols.size())); + return *localSymbols[symbolIndex]; +} template -Symbol &SharedFileExtended::getSymbolADLT(uint32_t symbolIndex, - bool fromDynamic) const { - Symbol &sym = fromDynamic ? getDynamicSymbol(symbolIndex) - : getSymbolFromElfSymTab(symbolIndex); +Symbol &SharedFileExtended::getSymbol(uint32_t symbolIndex, + bool fromDynamic) { + if (!symbolIndex) + return *localSymbols[0]; + /* TODO + if (symbolIndex > static_cast(symTabFirstGlobal)) + return getDynamicSymbol(symbolIndex - (symTabFirstGlobal + 1)); + return fromDynamic ? getDynamicSymbol(symbolIndex) + : getLocalSymbol(symbolIndex); */ + Symbol &sym = fromDynamic ? getDynamicSymbol(symbolIndex) + : getLocalSymbol(symbolIndex); StringRef name = sym.getName(); if (name.empty()) return sym; - - /*if (name.contains("__emutls_v.TLS_data1")) // debug hint - lld::outs() << "debug getSymbolADLT(): " << name << "\n";*/ - // check SymbolTable auto res = elf::symtab->find(name); if (res && (res->exportDynamic || res->versionId)) @@ -2018,16 +1921,16 @@ template void SharedFileExtended::parseElfSymTab() { ArrayRef eSections = this->template getELFShdrs(); // Find a symbol table. - const Elf_Shdr *eSymtabSec = findSection(eSections, SHT_SYMTAB); + const Elf_Shdr *eSymtabSec = ::findSection(eSections, SHT_SYMTAB); if (!eSymtabSec) return; - eFirstGlobal = eSymtabSec->sh_info; + symTabFirstGlobal = eSymtabSec->sh_info; ArrayRef eSyms = CHECK(obj.symbols(eSymtabSec), this); auto numESyms = uint32_t(eSyms.size()); auto eStringTable = CHECK(obj.getStringTableForSymtab(*eSymtabSec, eSections), this); - this->allSymbols.resize(numESyms); + this->localSymbols.resize(numESyms); for (size_t i = 0; i < numESyms; i++) { const Elf_Sym &eSym = eSyms[i]; @@ -2056,13 +1959,14 @@ template void SharedFileExtended::parseElfSymTab() { }); bool isInDynSym = dynSym != this->symbols.end(); if (!isInDynSym) - name = addAdltPostfix(name); + name = getUniqueName(name); /*if (name == "TLS_data1") // debug hint lld::outs() << name << '\n'; */ - this->allSymbols[i] = + this->localSymbols[i] = make(this, name, bind, other, type, val, eSym.st_size, sec); + this->definedSymbolsMap[eSym.st_value] = i; } else { - this->allSymbols[i] = make(this, name, bind, other, type, + this->localSymbols[i] = make(this, name, bind, other, type, /*discardedSecIdx=*/i); } } diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 42db1858130e..3167372e42eb 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -238,13 +238,13 @@ public: } virtual ~ObjFile() {} - void parse(bool ignoreComdats = false); + virtual void parse(bool ignoreComdats = false); void parseLazy(); StringRef getShtGroupSignature(ArrayRef sections, const Elf_Shdr &sec); - virtual Symbol &getSymbol(uint32_t symbolIndex) const { + Symbol &getSymbol(uint32_t symbolIndex) const { if (symbolIndex >= this->symbols.size()) fatal(toString(this) + ": invalid symbol index"); return *this->symbols[symbolIndex]; @@ -290,11 +290,16 @@ public: DWARFCache *getDwarf(); void initializeLocalSymbols(); - void postParse(); + virtual void postParse(); -protected: + // OHOS_LOCAL virtual StringRef getUniqueName(StringRef origName) const; +protected: + // OHOS_LOCAL + llvm::DenseMap sectionsMap; // offset, orderIdx + llvm::DenseMap definedSymbolsMap; // abs offset, orderIdx + private: void initializeSections(bool ignoreComdats, const llvm::object::ELFFile &obj); @@ -394,49 +399,28 @@ public: static bool classof(const InputFile *f) { return f->kind() == InputFile::SharedKind; } - void buildSymbolsHist() override; bool isValidSection(InputSectionBase *s) override; + bool isDynamicSection(InputSectionBase *s) const; - void parseForAdlt(); - void postParseForAdlt(); - - StringRef addAdltPostfix(StringRef input) const; - bool addAdltPostfix(Symbol *s); + void parse(bool ignoreComdats = false) override; + void postParse() override; - bool saveSymbol(const Defined& d) const; + Defined &getDefinedLocalSym(unsigned offset); - Defined *findSectionSymbol(uint64_t offset) const; - Defined *findDefinedSymbol( - uint64_t offset, - llvm::function_ref extraCond = [](Defined *) { - return true; - }) const; + InputSectionBase &getSection(unsigned offset); + InputSectionBase &getSectionByOrder(unsigned idx); + InputSectionBase *findSection(unsigned offset); - InputSectionBase *findInputSection(StringRef name) const; - InputSectionBase *findInputSection(uint64_t offset) const; - bool isDynamicSection(InputSectionBase &sec) const; - - template - Symbol &getRelocTargetSymADLT(const RelT &rel, InputSectionBase &sec) const { + template Symbol &getRelocTargetSym(const RelT &rel) { uint32_t symIndex = rel.getSymbol(config->isMips64EL); - return getSymbolADLT(symIndex, isDynamicSection(sec)); - } - - ArrayRef getLocalSymbols() override { - if (this->allSymbols.empty()) - return {}; - return llvm::makeArrayRef(this->allSymbols).slice(1, eFirstGlobal - 1); + return getSymbol(symIndex, false); } Symbol &getDynamicSymbol(uint32_t symbolIndex) const; - Symbol &getSymbolADLT(uint32_t symbolIndex, bool fromDynamic) const; + Symbol &getLocalSymbol(uint32_t symbolIndex) const; + Symbol &getSymbol(uint32_t symbolIndex, bool fromDynamic); - Symbol &getSymbolFromElfSymTab(uint32_t symbolIndex) const { - if (symbolIndex >= this->allSymbols.size()) - fatal(toString(this) + ": invalid symbol index"); - return *this->allSymbols[symbolIndex]; - } public: // the input order of the file as it presented in ADLT image @@ -444,7 +428,7 @@ public: int dynSymSecIdx = 0; int symTabSecIdx = 0; int symTabShndxSecIdx = 0; - int eFirstGlobal = 0; + int symTabFirstGlobal = 0; int gotPltSecIdx = 0; // .symtab's start of local symbols owned by library @@ -476,19 +460,14 @@ public: // parsed. Only filled for `--no-allow-shlib-undefined`. SmallVector requiredSymbols; -protected: - virtual StringRef getUniqueName(StringRef origName) const override; + StringRef getUniqueName(StringRef origName) const override; private: - SmallVector allSymbols; + SmallVector localSymbols; void parseDynamics(); // SharedFile compability void parseElfSymTab(); // ObjectFile compability - void resolveDuplicatesForAdlt(); - - StringRef getShStrTab(ArrayRef elfSections); - std::vector parseVerneed(const llvm::object::ELFFile &obj, const typename ELFT::Shdr *sec); }; diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 275f5a2202be..bf2b1d7c5521 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -347,10 +347,9 @@ void InputSection::copyRelocations(uint8_t *buf, ArrayRef rels) { for (const RelTy &rel : rels) { RelType type = rel.getType(config->isMips64EL); - const ObjFile *file = - config->adlt ? getSoExt() : getFile(); + const ObjFile *file = getFile(); Symbol &sym = config->adlt - ? getSoExt()->getRelocTargetSymADLT(rel, *sec) + ? getSoExt()->getRelocTargetSym(rel) : file->getRelocTargetSym(rel); auto *p = reinterpret_cast(buf); @@ -847,8 +846,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef rels) { if (!RelTy::IsRela) addend += target.getImplicitAddend(bufLoc, type); - Symbol &sym = config->adlt ? getSoExt()->getSymbolFromElfSymTab( - rel.getSymbol(config->isMips64EL)) + Symbol &sym = config->adlt ? getSoExt()->getRelocTargetSym(rel) : getFile()->getRelocTargetSym(rel); if (config->adlt) { // TODO improve switch (type) { diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index fa1884c6d14c..ea1acb552c81 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1326,22 +1326,22 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, isDebug = true;*/ // parse offset (where) - InputSectionBase *secWhere = file->findInputSection(r->offset); - assert(secWhere && "not found!"); + InputSectionBase &secWhere = + (sec.type != SHT_NULL) ? sec : file->getSection(r->offset); // process offset - r->offset -= fromDynamic ? secWhere->address : sec.address; + r->offset -= fromDynamic ? secWhere.address : sec.address; assert(r->type); // resolve relocs switch (r->type) { // dyn relocs case R_AARCH64_RELATIVE: { - Defined *d = file->findDefinedSymbol(r->addend); + Defined *d = &file->getDefinedLocalSym(r->addend); assert(d && "R_AARCH64_RELATIVE: r->sym not found by addend!"); r->sym = d; r->addend -= d->section->address + d->value; - addRelativeReloc(*secWhere, r->offset, *r->sym, r->addend, r->expr, + addRelativeReloc(secWhere, r->offset, *r->sym, r->addend, r->expr, r->type); trackDynRelocAdlt(file); return; @@ -1365,7 +1365,7 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, case R_AARCH64_ABS64: if (fromDynamic) { assert(r->sym->exportDynamic); - sec.getPartition().relaDyn->addSymbolReloc(target.symbolicRel, *secWhere, + sec.getPartition().relaDyn->addSymbolReloc(target.symbolicRel, secWhere, r->offset, *r->sym, r->addend, r->type); trackDynRelocAdlt(file); @@ -1441,9 +1441,9 @@ template void RelocationScanner::scanOne(RelTy *&i) { uint32_t symIndex = rel.getSymbol(config->isMips64EL); bool fromDynamic = false; if (config->adlt) - fromDynamic = sec.getSoExt()->isDynamicSection(sec); + fromDynamic = sec.getSoExt()->isDynamicSection(&sec); Symbol &sym = config->adlt - ? sec.getSoExt()->getSymbolADLT(symIndex, fromDynamic) + ? sec.getSoExt()->getSymbol(symIndex, fromDynamic) : sec.getFile()->getSymbol(symIndex); RelType type; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 4120a2e00dd1..5a4abd964dbf 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1560,9 +1560,9 @@ DynamicSection::computeContents() { return (OutputSection *)nullptr; }; for (InputFile *file : adltCtx->sharedFilesExtended) { - auto *f = cast>(file); - auto initArray = findSection(f->addAdltPostfix(".init_array")); - auto finiArray = findSection(f->addAdltPostfix(".fini_array")); + auto *f = adltCtx->getSoExt(file); + auto initArray = findSection(f->getUniqueName(".init_array")); + auto finiArray = findSection(f->getUniqueName(".fini_array")); if (initArray) { addInt(DT_INIT_ARRAY, initArray->addr); addInt(DT_INIT_ARRAYSZ, initArray->size); @@ -4221,8 +4221,8 @@ AdltSection::makeSoData(const SharedFileExtended* soext) { }); } - data.initArrayName = soext->addAdltPostfix(".init_array"); - data.finiArrayName = soext->addAdltPostfix(".fini_array"); + data.initArrayName = soext->getUniqueName(".init_array"); + data.finiArrayName = soext->getUniqueName(".fini_array"); data.relaDynIndx = soext->dynRelIndexes.getArrayRef(); data.relaPltIndx = soext->pltRelIndexes.getArrayRef(); -- Gitee From 78b2947ff4330a862da3461a648abf4609a900bf Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Fri, 24 May 2024 11:21:28 -0400 Subject: [PATCH 6/7] Adlt cleanup RelocationScanner Change-Id: Idd74f5fc81f4cc4213430ec412ab43ee6ef6e499 Signed-off-by: Anton Volkov --- lld/ELF/Adlt.cpp | 7 ++- lld/ELF/Relocations.cpp | 126 +++++++++++++++++++++++++++------------- 2 files changed, 92 insertions(+), 41 deletions(-) diff --git a/lld/ELF/Adlt.cpp b/lld/ELF/Adlt.cpp index 277d24154024..308706eabba8 100644 --- a/lld/ELF/Adlt.cpp +++ b/lld/ELF/Adlt.cpp @@ -27,7 +27,7 @@ SharedFileExtended *AdltCtx::getSoExt(InputFile *file) { template SharedFileExtended *AdltCtx::getSoExt(unsigned orderId) { assert(orderId < sharedFilesExtended.size()); - return sharedFilesExtended[orderId]; + return cast>(sharedFilesExtended[orderId]); } template @@ -52,6 +52,11 @@ template SharedFileExtended *AdltCtx::getSoExt(InputFile *); template SharedFileExtended *AdltCtx::getSoExt(InputFile *); template SharedFileExtended *AdltCtx::getSoExt(InputFile *); +template SharedFileExtended *AdltCtx::getSoExt(unsigned); +template SharedFileExtended *AdltCtx::getSoExt(unsigned); +template SharedFileExtended *AdltCtx::getSoExt(unsigned); +template SharedFileExtended *AdltCtx::getSoExt(unsigned); + template void AdltCtx::buildSymbolsHist(std::vector &); template void AdltCtx::buildSymbolsHist(std::vector &); template void AdltCtx::buildSymbolsHist(std::vector &); diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index ea1acb552c81..f248007b6287 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -434,6 +434,51 @@ private: size_t i = 0; }; + +// OHOS_LOCAL begin +template class AdltRelocationScanner { +public: + AdltRelocationScanner(InputSectionBase &isec) + : file(adltCtx->getSoExt(isec.file)), + fromDynamic(file->isDynamicSection(&isec)), sec(isec) {} + + SharedFileExtended *getSoExt() { return file; } + + Symbol &getSymbol(uint32_t idx) { return file->getSymbol(idx, fromDynamic); } + + void process(Relocation *r); + void trackGotPlt(Symbol *sym); + void trackDynReloc(); + + unsigned getDynamicRelocsCount(); + bool isRelr() { return config->adlt && relSecType == SHT_RELR; } + bool toProcessAux = false; + +private: + SharedFileExtended *file = nullptr; + bool fromDynamic = false; + InputSectionBase &sec; + uint32_t relSecType = SHT_NULL; +}; + +template +void AdltRelocationScanner::trackGotPlt(Symbol *sym) { + adltCtx->gotPltInfo[sym].push_back(file->orderIdx); +} + +template +void AdltRelocationScanner::trackDynReloc() { + file->dynRelIndexes.insert(getDynamicRelocsCount() - 1); +} + +template +unsigned AdltRelocationScanner::getDynamicRelocsCount() { + auto currentSize = isRelr() ? mainPart->relrDyn->relocs.size() + : mainPart->relaDyn->relocs.size(); + return currentSize; +} +// OHOS_LOCAL end + // This class encapsulates states needed to scan relocations for one // InputSectionBase. class RelocationScanner { @@ -459,6 +504,7 @@ private: int64_t computeAddend(const RelTy &rel, RelExpr expr, bool isLocal) const; bool isStaticLinkTimeConstant(RelExpr e, RelType type, const Symbol &sym, uint64_t relOff) const; + void processAux(Relocation &r); // OHOS_LOCAL void processAux(RelExpr expr, RelType type, uint64_t offset, Symbol &sym, int64_t addend) const; template void scanOne(RelTy *&i); @@ -1034,6 +1080,11 @@ bool RelocationScanner::isStaticLinkTimeConstant(RelExpr e, RelType type, // sections. Given that it is ro, we will need an extra PT_LOAD. This // complicates things for the dynamic linker and means we would have to reserve // space for the extra PT_LOAD even if we end up not using it. + +void RelocationScanner::processAux(Relocation &r) { // OHOS_LOCAL + processAux(r.expr, r.type, r.offset, *r.sym, r.addend); +} + void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset, Symbol &sym, int64_t addend) const { // If the relocation is known to be a link-time constant, we know no dynamic @@ -1302,23 +1353,9 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym, return 0; } +// OHOS_LOCAL begin template -static void trackDynRelocAdlt(SharedFileExtended *soFile) { - soFile->dynRelIndexes.insert(mainPart->relaDyn->relocs.size() - 1); -} - -template -static void trackGotPltAdlt(Symbol *sym, SharedFileExtended *soFile) { - adltCtx->gotPltInfo[sym].push_back(soFile->orderIdx); -} - -// ADLT BEGIN -template -void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, - bool fromDynamic) { - auto file = sec.getSoExt(); - bool isDebug = false; - +void AdltRelocationScanner::process(Relocation *r) { /*if (r->offset == 0x21F) // debug hint isDebug = true; /*if (r->type == R_AARCH64_ABS64 && @@ -1330,7 +1367,7 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, (sec.type != SHT_NULL) ? sec : file->getSection(r->offset); // process offset - r->offset -= fromDynamic ? secWhere.address : sec.address; + r->offset -= secWhere.address; assert(r->type); // resolve relocs @@ -1343,20 +1380,21 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, r->addend -= d->section->address + d->value; addRelativeReloc(secWhere, r->offset, *r->sym, r->addend, r->expr, r->type); - trackDynRelocAdlt(file); + assert(getDynamicRelocsCount()); + trackDynReloc(); return; } case R_AARCH64_GLOB_DAT: assert(r->sym->exportDynamic); if (!r->sym->needsGot) r->sym->needsGot = 1; - trackGotPltAdlt(r->sym, file); + trackGotPlt(r->sym); return; case R_AARCH64_JUMP_SLOT: assert(r->sym->exportDynamic); if (r->sym->isUndefined() && !r->sym->needsPlt) r->sym->needsPlt = 1; - trackGotPltAdlt(r->sym, file); + trackGotPlt(r->sym); return; // abs relocs case R_AARCH64_ABS32: @@ -1365,10 +1403,10 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, case R_AARCH64_ABS64: if (fromDynamic) { assert(r->sym->exportDynamic); - sec.getPartition().relaDyn->addSymbolReloc(target.symbolicRel, secWhere, + sec.getPartition().relaDyn->addSymbolReloc(r->type, secWhere, r->offset, *r->sym, r->addend, r->type); - trackDynRelocAdlt(file); + trackDynReloc(); return; } sec.relocations.push_back(*r); @@ -1380,7 +1418,7 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, case R_AARCH64_LDST128_ABS_LO12_NC: case R_AARCH64_PREL32: case R_AARCH64_PREL64: - processAux(r->expr, r->type, r->offset, *r->sym, r->addend); + toProcessAux = true; return; // plt relocs case R_AARCH64_CALL26: @@ -1398,24 +1436,21 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, return; case R_AARCH64_ADR_GOT_PAGE: if (r->sym->isDefined() && !r->sym->needsGot) { - if (isDebug) - lld::outs() << "[ADLT] R_AARCH64_ADR_GOT_PAGE: sym not in GOT! "; - r->expr = R_PC; // prev: R_AARCH64_GOT_PAGE_PC || R_AARCH64_GOT_PAGE || - // R_GOT || R_GOT_PC - // TODO: replace reloc R_AARCH64_ADR_GOT_PAGE + // prev: R_AARCH64_GOT_PAGE_PC || R_AARCH64_GOT_PAGE || R_GOT || R_GOT_PC + r->expr = R_PC; sec.relocations.push_back(*r); return; } LLVM_FALLTHROUGH; case R_AARCH64_LD64_GOT_LO12_NC: case R_AARCH64_LD64_GOTPAGE_LO15: - processAux(r->expr, r->type, r->offset, *r->sym, r->addend); + toProcessAux = true; return; // tls relocs case R_AARCH64_TLSDESC: if (fromDynamic && !r->sym->needsTlsDesc) r->sym->needsTlsDesc = 1; - trackDynRelocAdlt(file); + trackGotPlt(r->sym); return; case R_AARCH64_TLSDESC_CALL: case R_AARCH64_TLS_TPREL64: @@ -1439,11 +1474,11 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, template void RelocationScanner::scanOne(RelTy *&i) { const RelTy &rel = *i; uint32_t symIndex = rel.getSymbol(config->isMips64EL); - bool fromDynamic = false; + std::unique_ptr> adltScanner = nullptr; if (config->adlt) - fromDynamic = sec.getSoExt()->isDynamicSection(&sec); + adltScanner = std::make_unique>(sec); Symbol &sym = config->adlt - ? sec.getSoExt()->getSymbol(symIndex, fromDynamic) + ? adltScanner->getSymbol(symIndex) : sec.getFile()->getSymbol(symIndex); RelType type; @@ -1478,7 +1513,9 @@ template void RelocationScanner::scanOne(RelTy *&i) { if (config->adlt) { Relocation r = {expr, type, offset, addend, &sym}; - processForADLT(rel, &r, fromDynamic); + adltScanner->process(&r); + if (adltScanner->toProcessAux) + processAux(r); return; } @@ -1783,15 +1820,24 @@ static bool handleNonPreemptibleIfunc(Symbol &sym) { return true; } -template static void addGotPltIndexAdlt(Symbol *s, bool isPlt) { +// OHOS_LOCAL begin +namespace lld { +namespace elf { +namespace adlt { +template static void addGotPltIndex(Symbol *s, bool isPlt) { auto &vec = adltCtx->gotPltInfo[s]; - for (auto &it : vec) { - auto *soFile = cast>(adltCtx->sharedFilesExtended[it]); + for (auto &orderId : vec) { + auto *soFile = adltCtx->getSoExt(orderId); auto &entries = isPlt ? in.relaPlt->relocs : mainPart->relaDyn->relocs; auto &output = isPlt ? soFile->pltRelIndexes : soFile->dynRelIndexes; output.insert(entries.size() - 1); } } +} // namespace adlt +} // namespace elf +} // namespace lld + +// OHOS_LOCAL end void elf::postScanRelocations() { auto fn = [](Symbol &sym) { @@ -1805,12 +1851,12 @@ void elf::postScanRelocations() { if (sym.needsGot) { addGotEntry(sym); if (config->adlt) - invokeELFT(addGotPltIndexAdlt, &sym, false); + invokeELFT(adlt::addGotPltIndex, &sym, false); } if (sym.needsPlt) { addPltEntry(*in.plt, *in.gotPlt, *in.relaPlt, target->pltRel, sym); if (config->adlt) - invokeELFT(addGotPltIndexAdlt, &sym, true); + invokeELFT(adlt::addGotPltIndex, &sym, true); } if (sym.needsCopy) { if (sym.isObject()) { @@ -1845,7 +1891,7 @@ void elf::postScanRelocations() { mainPart->relaDyn->addAddendOnlyRelocIfNonPreemptible( target->tlsDescRel, *in.got, in.got->getTlsDescOffset(sym), sym, target->tlsDescRel); - invokeELFT(addGotPltIndexAdlt, &sym, false); + invokeELFT(adlt::addGotPltIndex, &sym, false); } if (sym.needsTlsGd) { in.got->addDynTlsEntry(sym); -- Gitee From f08950f339899831c10b7f002769ee92d136aae7 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 5 Jun 2024 03:53:41 -0400 Subject: [PATCH 7/7] Adlt minor refactoring changes. Change-Id: If97b6604390a24c0ffd77ef849897e2793b5ead4 Signed-off-by: Anton Volkov --- lld/ELF/Adlt.cpp | 12 +++---- lld/ELF/Adlt.h | 12 +++---- lld/ELF/Config.h | 2 +- lld/ELF/Driver.cpp | 2 +- lld/ELF/InputFiles.cpp | 63 +++++++++++++++++++++-------------- lld/ELF/InputFiles.h | 45 +++++++++++++++---------- lld/ELF/Relocations.cpp | 48 ++++++++++---------------- lld/ELF/SyntheticSections.cpp | 49 ++++++++------------------- lld/ELF/Writer.cpp | 24 +++++++------ 9 files changed, 124 insertions(+), 133 deletions(-) diff --git a/lld/ELF/Adlt.cpp b/lld/ELF/Adlt.cpp index 308706eabba8..b3d8f4f56e79 100644 --- a/lld/ELF/Adlt.cpp +++ b/lld/ELF/Adlt.cpp @@ -25,7 +25,7 @@ SharedFileExtended *AdltCtx::getSoExt(InputFile *file) { } template -SharedFileExtended *AdltCtx::getSoExt(unsigned orderId) { +SharedFileExtended *AdltCtx::getSoExt(size_t orderId) { assert(orderId < sharedFilesExtended.size()); return cast>(sharedFilesExtended[orderId]); } @@ -38,7 +38,7 @@ void AdltCtx::buildSymbolsHist(std::vector &files) { assert(!symNamesHist.empty()); } -void AdltCtx::checkDuplicatedSymbols() { +void AdltCtx::scanDuplicatedSymbols() { assert(!symNamesHist.empty()); for (auto entry : symNamesHist) if (entry.second > 1) @@ -52,10 +52,10 @@ template SharedFileExtended *AdltCtx::getSoExt(InputFile *); template SharedFileExtended *AdltCtx::getSoExt(InputFile *); template SharedFileExtended *AdltCtx::getSoExt(InputFile *); -template SharedFileExtended *AdltCtx::getSoExt(unsigned); -template SharedFileExtended *AdltCtx::getSoExt(unsigned); -template SharedFileExtended *AdltCtx::getSoExt(unsigned); -template SharedFileExtended *AdltCtx::getSoExt(unsigned); +template SharedFileExtended *AdltCtx::getSoExt(size_t); +template SharedFileExtended *AdltCtx::getSoExt(size_t); +template SharedFileExtended *AdltCtx::getSoExt(size_t); +template SharedFileExtended *AdltCtx::getSoExt(size_t); template void AdltCtx::buildSymbolsHist(std::vector &); template void AdltCtx::buildSymbolsHist(std::vector &); diff --git a/lld/ELF/Adlt.h b/lld/ELF/Adlt.h index 4fefb1ca036a..b6751cf54607 100644 --- a/lld/ELF/Adlt.h +++ b/lld/ELF/Adlt.h @@ -24,31 +24,29 @@ class InputFile; class Symbol; struct PhdrEntry; -// class SharedFileExtended; // TODO: inherit from SharedFile template class SharedFileExtended; struct PhdrEntry; class AdltCtx { public: - // TODO: inherit from SharedFile - // llvm::SmallVector sharedFilesExtended; - llvm::SmallVector sharedFilesExtended; + llvm::SmallVector sharedFilesExtended; - void checkDuplicatedSymbols(); + void scanDuplicatedSymbols(); template void buildSymbolsHist(std::vector &files); template SharedFileExtended *getSoExt(InputFile *file); - template SharedFileExtended *getSoExt(unsigned orderId); + template SharedFileExtended *getSoExt(size_t orderId); llvm::SetVector commonProgramHeaders; + bool withCfi = false; + // From input .rela.dyn, .rela.plt: // Keep input library indexes that are needed for got/plt symbol llvm::DenseMap> gotPltInfo; // sym, soFile->orderIdx array; - // Store duplicate symbols (only defined). llvm::DenseMap symNamesHist; // hash, count usages llvm::DenseSet duplicatedSymNames; diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 001f714454bc..2eaee71cca74 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -386,7 +386,7 @@ struct DuplicateSymbol { struct Ctx { SmallVector> memoryBuffers; - SmallVector objectFiles; + SmallVector objectFiles; SmallVector sharedFiles; SmallVector binaryFiles; SmallVector bitcodeFiles; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 3f3726f2644e..88ef20d59014 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2555,7 +2555,7 @@ void LinkerDriver::link(opt::InputArgList &args) { // Fill duplicatedSymNames for defined syms. This will help to find duplicates. if (config->adlt) { invokeELFT(adltCtx->buildSymbolsHist, files); - adltCtx->checkDuplicatedSymbols(); + adltCtx->scanDuplicatedSymbols(); } // Add all files to the symbol table. This will add almost all diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 3514782dd7c8..df9355f3b625 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -327,8 +327,6 @@ ELFFileBase::ELFFileBase(Kind k, MemoryBufferRef mb) : InputFile(k, mb) { } } -// namespace -// { template static const Elf_Shdr *findSection(ArrayRef sections, uint32_t type) { for (const Elf_Shdr &sec : sections) @@ -336,9 +334,11 @@ static const Elf_Shdr *findSection(ArrayRef sections, uint32_t type) { return &sec; return nullptr; } -// } // namespace - +// OHOS_LOCAL begin +void ELFFileBase::buildSymbolsHist() {} +bool ELFFileBase::isValidSection(InputSectionBase *s) const { return true; } +// OHOS_LOCAL end template void ELFFileBase::init() { using Elf_Shdr = typename ELFT::Shdr; @@ -574,6 +574,7 @@ void ObjFile::initializeSections(bool ignoreComdats, } auto secName = check(obj.getSectionName(sec, shstrtab)); if (config->adlt && sec.sh_type == SHT_NULL) { + // TODO: add unique for output only auto name = getUniqueName(secName); this->sections[i] = createInputSection(i, sec, name); this->sections[i]->address = sec.sh_addr; @@ -602,6 +603,7 @@ void ObjFile::initializeSections(bool ignoreComdats, .second; if (keepGroup) { if (config->relocatable) { + // TODO: add unique for output only auto name = config->adlt ? getUniqueName(secName) : secName; this->sections[i] = createInputSection(i, sec, name); if (config->adlt) { @@ -635,6 +637,7 @@ void ObjFile::initializeSections(bool ignoreComdats, ctx->hasSympart.store(true, std::memory_order_relaxed); LLVM_FALLTHROUGH; default: + // TODO: add unique for output only auto name = config->adlt ? getUniqueName(secName) : secName; this->sections[i] = createInputSection(i, sec, name); if (config->adlt) { @@ -1057,7 +1060,12 @@ void ObjFile::initializeSymbols(const object::ELFFile &obj) { StringRef name = CHECK(eSyms[i].getName(stringTable), this); if (config->adlt && eSyms[i].isDefined() && adltCtx->duplicatedSymNames.count(CachedHashStringRef(name)) != 0) { - adltCtx->withCfi = adltCtx->withCfi || name == "__cfi_check"; + if (name == "__cfi_check" && !adltCtx->withCfi) { + adltCtx->withCfi = true; + if (config->adltTrace) + lld::outs() << "[ADLT] Cfi mode is ON\n"; + } + // TODO: add unique for output only name = this->getUniqueName(name); } symbols[i] = symtab.insert(name); @@ -1599,9 +1607,7 @@ template void SharedFile::parse() { template SharedFileExtended::SharedFileExtended(MemoryBufferRef mb, StringRef soName) - : ObjFile(mb, soName), soName(soName) { - const_cast(this->fileKind) = InputFile::SharedKind; -} + : ObjFile(InputFile::SharedKind, mb, soName), soName(soName) {} template void SharedFileExtended::buildSymbolsHist() { ArrayRef eSyms = this->template getELFSyms(); @@ -1614,7 +1620,7 @@ template void SharedFileExtended::buildSymbolsHist() { } template -bool SharedFileExtended::isValidSection(InputSectionBase *s) { +bool SharedFileExtended::isValidSection(InputSectionBase *s) const { if (!s || s == &InputSection::discarded) return false; uint32_t type = s->type; @@ -1623,17 +1629,18 @@ bool SharedFileExtended::isValidSection(InputSectionBase *s) { bool isBaseType = type == SHT_NOBITS || type == SHT_NOTE || type == SHT_INIT_ARRAY || type == SHT_FINI_ARRAY; // TODO: fix .debug-* sections relocation + // TODO: rename sections at outputStage. bool isNeededProgBits = type == SHT_PROGBITS && - !(name.startswith(".got.plt") || name.startswith(".plt") || - name.startswith(".got") || name.startswith(".eh_frame_hdr") || - name.startswith(".debug_")); + !(name.startswith(".got") || name.startswith(".plt") || + name.startswith(".eh_frame_hdr") || name.startswith(".debug_")); bool ret = isBaseType || isNeededProgBits; return ret; } template bool SharedFileExtended::isDynamicSection(InputSectionBase *s) const { + // TODO: rename sections at outputStage. return s->type == llvm::ELF::SHT_NULL || s->name.startswith(".got.plt"); } @@ -1656,7 +1663,7 @@ StringRef SharedFileExtended::getUniqueName(StringRef input) const { } template -Defined &SharedFileExtended::getDefinedLocalSym(unsigned offset) { +Defined &SharedFileExtended::getDefinedLocalSym(uint64_t offset) { auto getSym = [&](unsigned offs) { return localSymbols[this->definedSymbolsMap[offs]]; }; @@ -1670,7 +1677,7 @@ Defined &SharedFileExtended::getDefinedLocalSym(unsigned offset) { } template -InputSectionBase &SharedFileExtended::getSection(unsigned offset) { +InputSectionBase &SharedFileExtended::getSection(uint64_t offset) { auto *sec = this->sections[this->sectionsMap[offset]]; if (offset && sec->type == SHT_NULL) sec = findSection(offset); @@ -1678,7 +1685,7 @@ InputSectionBase &SharedFileExtended::getSection(unsigned offset) { } template -InputSectionBase &SharedFileExtended::getSectionByOrder(unsigned idx) { +InputSectionBase &SharedFileExtended::getSectionByOrder(size_t idx) { auto *sec = this->sections[idx]; if (!sec) sec = &InputSection::discarded; @@ -1686,35 +1693,35 @@ InputSectionBase &SharedFileExtended::getSectionByOrder(unsigned idx) { } template -InputSectionBase *SharedFileExtended::findSection(unsigned offset) { +InputSectionBase *SharedFileExtended::findSection(uint64_t offset) { llvm::SmallVector candidates; for (InputSectionBase *sec : this->sections) { if (!sec) continue; - auto low = sec->address, high = low + sec->size; + auto low = sec->address; + auto high = low + sec->size; if (offset >= low && offset < high) candidates.push_back(sec); } if (candidates.empty()) // no suitable items found return nullptr; - llvm::sort(candidates, [offset](InputSectionBase *a, InputSectionBase *b) { - return (offset - a->address < offset - b->address); - }); + llvm::sort(candidates, + [](auto *a, auto *b) { return a->address < b->address; }); return *candidates.begin(); } template -Symbol &SharedFileExtended::getDynamicSymbol(uint32_t symbolIndex) const { +Symbol &SharedFileExtended::getDynamicSymbol(size_t symbolIndex) const { return *this->symbols[symbolIndex]; } template -Symbol &SharedFileExtended::getLocalSymbol(uint32_t symbolIndex) const{ +Symbol &SharedFileExtended::getLocalSymbol(size_t symbolIndex) const{ assert(symbolIndex && (symbolIndex < localSymbols.size())); return *localSymbols[symbolIndex]; } template -Symbol &SharedFileExtended::getSymbol(uint32_t symbolIndex, +Symbol &SharedFileExtended::getSymbol(size_t symbolIndex, bool fromDynamic) { if (!symbolIndex) return *localSymbols[0]; @@ -1745,6 +1752,12 @@ Symbol &SharedFileExtended::getSymbol(uint32_t symbolIndex, return sym; } +template +ArrayRef SharedFileExtended::getLocalSymbols() { + assert(!localSymbols.empty()); + return llvm::makeArrayRef(localSymbols).slice(0, symTabFirstGlobal); +} + template void SharedFileExtended::parseDynamics() { const ELFFile obj = this->getObj(); ArrayRef sections = this->template getELFShdrs(); @@ -1843,7 +1856,7 @@ template void SharedFileExtended::parseDynamics() { // Add postfix for defined duplicates. if (config->adlt && sym.isDefined() && adltCtx->duplicatedSymNames.count(CachedHashStringRef(name)) != 0) - name = this->getUniqueName(name); + name = getUniqueName(name); // TODO: add unique for output only if (sym.getBinding() == STB_LOCAL) { warn("found local symbol '" + name + @@ -1959,7 +1972,7 @@ template void SharedFileExtended::parseElfSymTab() { }); bool isInDynSym = dynSym != this->symbols.end(); if (!isInDynSym) - name = getUniqueName(name); + name = getUniqueName(name); // TODO: add unique for output only /*if (name == "TLS_data1") // debug hint lld::outs() << name << '\n'; */ this->localSymbols[i] = diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 3167372e42eb..41f1561bb545 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -202,8 +202,8 @@ public: } // OHOS_LOCAL begin - virtual void buildSymbolsHist() {} - virtual bool isValidSection(InputSectionBase *s) { return true; } + virtual void buildSymbolsHist(); + virtual bool isValidSection(InputSectionBase *s) const; // OHOS_LOCAL end protected: @@ -236,6 +236,10 @@ public: ObjFile(MemoryBufferRef m, StringRef archiveName) : ELFFileBase(ObjKind, m) { this->archiveName = archiveName; } + ObjFile(Kind k, MemoryBufferRef m, StringRef archiveName) // OHOS_LOCAL + : ELFFileBase(k, m) { + this->archiveName = archiveName; + } virtual ~ObjFile() {} virtual void parse(bool ignoreComdats = false); @@ -292,13 +296,15 @@ public: void initializeLocalSymbols(); virtual void postParse(); - // OHOS_LOCAL + // OHOS_LOCAL begin + // TODO: move to SharedFileExtended virtual StringRef getUniqueName(StringRef origName) const; protected: - // OHOS_LOCAL - llvm::DenseMap sectionsMap; // offset, orderIdx - llvm::DenseMap definedSymbolsMap; // abs offset, orderIdx + // TODO: move to SharedFileExtended + llvm::DenseMap sectionsMap; // offset, orderIdx + llvm::DenseMap definedSymbolsMap; // abs offset, orderIdx + // OHOS_LOCAL end private: void initializeSections(bool ignoreComdats, @@ -400,31 +406,33 @@ public: return f->kind() == InputFile::SharedKind; } void buildSymbolsHist() override; - bool isValidSection(InputSectionBase *s) override; + bool isValidSection(InputSectionBase *s) const override; bool isDynamicSection(InputSectionBase *s) const; void parse(bool ignoreComdats = false) override; void postParse() override; - Defined &getDefinedLocalSym(unsigned offset); + Defined &getDefinedLocalSym(uint64_t offset); - InputSectionBase &getSection(unsigned offset); - InputSectionBase &getSectionByOrder(unsigned idx); - InputSectionBase *findSection(unsigned offset); + InputSectionBase &getSection(uint64_t offset); + InputSectionBase &getSectionByOrder(size_t idx); + InputSectionBase *findSection(uint64_t offset); template Symbol &getRelocTargetSym(const RelT &rel) { uint32_t symIndex = rel.getSymbol(config->isMips64EL); return getSymbol(symIndex, false); } - Symbol &getDynamicSymbol(uint32_t symbolIndex) const; - Symbol &getLocalSymbol(uint32_t symbolIndex) const; - Symbol &getSymbol(uint32_t symbolIndex, bool fromDynamic); + Symbol &getDynamicSymbol(size_t symbolIndex) const; + Symbol &getLocalSymbol(size_t symbolIndex) const; + Symbol &getSymbol(size_t symbolIndex, bool fromDynamic); + + ArrayRef getLocalSymbols() override; public: // the input order of the file as it presented in ADLT image - size_t orderIdx; + size_t orderIdx = 0; int dynSymSecIdx = 0; int symTabSecIdx = 0; int symTabShndxSecIdx = 0; @@ -440,8 +448,10 @@ public: llvm::SetVector programHeaders; // From input .rela.dyn, .rela.plt: - llvm::SetVector dynRelIndexes; - llvm::SetVector pltRelIndexes; + llvm::SetVector + relaDynIndexes; // If not .relr.dyn exists, contains only Got/Abs/Tls + // relocs. Otherwise contains relative relocs also. + llvm::SetVector relaPltIndexes; // .got.plt relocs // SharedFile compability layer: // This is actually a vector of Elf_Verdef pointers. @@ -460,6 +470,7 @@ public: // parsed. Only filled for `--no-allow-shlib-undefined`. SmallVector requiredSymbols; + // TODO: add unique for output only StringRef getUniqueName(StringRef origName) const override; private: diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index f248007b6287..c67ec01bf27a 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -444,21 +444,19 @@ public: SharedFileExtended *getSoExt() { return file; } - Symbol &getSymbol(uint32_t idx) { return file->getSymbol(idx, fromDynamic); } + Symbol &getSymbol(unsigned idx) { return file->getSymbol(idx, fromDynamic); } void process(Relocation *r); void trackGotPlt(Symbol *sym); - void trackDynReloc(); + void trackRelatives(); + void trackDynamics(); - unsigned getDynamicRelocsCount(); - bool isRelr() { return config->adlt && relSecType == SHT_RELR; } bool toProcessAux = false; private: SharedFileExtended *file = nullptr; bool fromDynamic = false; InputSectionBase &sec; - uint32_t relSecType = SHT_NULL; }; template @@ -466,16 +464,14 @@ void AdltRelocationScanner::trackGotPlt(Symbol *sym) { adltCtx->gotPltInfo[sym].push_back(file->orderIdx); } -template -void AdltRelocationScanner::trackDynReloc() { - file->dynRelIndexes.insert(getDynamicRelocsCount() - 1); +template void AdltRelocationScanner::trackRelatives() { + auto count = mainPart->relaDyn->relocs.size(); + file->relaDynIndexes.insert(count - 1); } -template -unsigned AdltRelocationScanner::getDynamicRelocsCount() { - auto currentSize = isRelr() ? mainPart->relrDyn->relocs.size() - : mainPart->relaDyn->relocs.size(); - return currentSize; +template void AdltRelocationScanner::trackDynamics() { + auto count = mainPart->relaDyn->relocs.size(); + file->relaDynIndexes.insert(count - 1); } // OHOS_LOCAL end @@ -508,10 +504,6 @@ private: void processAux(RelExpr expr, RelType type, uint64_t offset, Symbol &sym, int64_t addend) const; template void scanOne(RelTy *&i); - - // ADLT - template - void processForADLT(const RelTy &rel, Relocation *r, bool fromDynamic); }; } // namespace @@ -1379,9 +1371,8 @@ void AdltRelocationScanner::process(Relocation *r) { r->sym = d; r->addend -= d->section->address + d->value; addRelativeReloc(secWhere, r->offset, *r->sym, r->addend, r->expr, - r->type); - assert(getDynamicRelocsCount()); - trackDynReloc(); + r->type); + trackRelatives(); return; } case R_AARCH64_GLOB_DAT: @@ -1406,7 +1397,7 @@ void AdltRelocationScanner::process(Relocation *r) { sec.getPartition().relaDyn->addSymbolReloc(r->type, secWhere, r->offset, *r->sym, r->addend, r->type); - trackDynReloc(); + trackDynamics(); return; } sec.relocations.push_back(*r); @@ -1473,10 +1464,10 @@ void AdltRelocationScanner::process(Relocation *r) { template void RelocationScanner::scanOne(RelTy *&i) { const RelTy &rel = *i; - uint32_t symIndex = rel.getSymbol(config->isMips64EL); std::unique_ptr> adltScanner = nullptr; if (config->adlt) adltScanner = std::make_unique>(sec); + uint32_t symIndex = rel.getSymbol(config->isMips64EL); Symbol &sym = config->adlt ? adltScanner->getSymbol(symIndex) : sec.getFile()->getSymbol(symIndex); @@ -1729,11 +1720,6 @@ void RelocationScanner::scan(ArrayRef rels) { template void elf::scanRelocations(InputSectionBase &s) { RelocationScanner scanner(s); - if (config->adlt) { - bool isDebug = false; - if (isDebug) - lld::outs() << s.file->getName().str() + ": " + s.name.str() + '\n'; - } const RelsOrRelas rels = s.template relsOrRelas(); if (rels.areRelocsRel()) scanner.template scan(rels.rels); @@ -1829,8 +1815,9 @@ template static void addGotPltIndex(Symbol *s, bool isPlt) { for (auto &orderId : vec) { auto *soFile = adltCtx->getSoExt(orderId); auto &entries = isPlt ? in.relaPlt->relocs : mainPart->relaDyn->relocs; - auto &output = isPlt ? soFile->pltRelIndexes : soFile->dynRelIndexes; - output.insert(entries.size() - 1); + auto &output = isPlt ? soFile->relaPltIndexes : soFile->relaDynIndexes; + auto index = entries.size() - 1; + output.insert(index); } } } // namespace adlt @@ -1891,7 +1878,8 @@ void elf::postScanRelocations() { mainPart->relaDyn->addAddendOnlyRelocIfNonPreemptible( target->tlsDescRel, *in.got, in.got->getTlsDescOffset(sym), sym, target->tlsDescRel); - invokeELFT(adlt::addGotPltIndex, &sym, false); + if (config->adlt) + invokeELFT(adlt::addGotPltIndex, &sym, false); } if (sym.needsTlsGd) { in.got->addDynTlsEntry(sym); diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 5a4abd964dbf..491a61dd15da 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1551,40 +1551,17 @@ DynamicSection::computeContents() { addInSec(DT_HASH, *part.hashTab); if (isMain) { - if (config->adlt) { - auto findSection = [](StringRef name, unsigned partition = 1) { - for (SectionCommand *cmd : script->sectionCommands) - if (auto *osd = dyn_cast(cmd)) - if (osd->osec.name == name && osd->osec.partition == partition) - return &osd->osec; - return (OutputSection *)nullptr; - }; - for (InputFile *file : adltCtx->sharedFilesExtended) { - auto *f = adltCtx->getSoExt(file); - auto initArray = findSection(f->getUniqueName(".init_array")); - auto finiArray = findSection(f->getUniqueName(".fini_array")); - if (initArray) { - addInt(DT_INIT_ARRAY, initArray->addr); - addInt(DT_INIT_ARRAYSZ, initArray->size); - } - if (finiArray) { - addInt(DT_FINI_ARRAY, finiArray->addr); - addInt(DT_FINI_ARRAYSZ, finiArray->size); - } - } - } else { - if (Out::preinitArray) { - addInt(DT_PREINIT_ARRAY, Out::preinitArray->addr); - addInt(DT_PREINIT_ARRAYSZ, Out::preinitArray->size); - } - if (Out::initArray) { - addInt(DT_INIT_ARRAY, Out::initArray->addr); - addInt(DT_INIT_ARRAYSZ, Out::initArray->size); - } - if (Out::finiArray) { - addInt(DT_FINI_ARRAY, Out::finiArray->addr); - addInt(DT_FINI_ARRAYSZ, Out::finiArray->size); - } + if (Out::preinitArray) { + addInt(DT_PREINIT_ARRAY, Out::preinitArray->addr); + addInt(DT_PREINIT_ARRAYSZ, Out::preinitArray->size); + } + if (Out::initArray) { + addInt(DT_INIT_ARRAY, Out::initArray->addr); + addInt(DT_INIT_ARRAYSZ, Out::initArray->size); + } + if (Out::finiArray) { + addInt(DT_FINI_ARRAY, Out::finiArray->addr); + addInt(DT_FINI_ARRAYSZ, Out::finiArray->size); } if (Symbol *b = symtab->find(config->init)) @@ -4224,8 +4201,8 @@ AdltSection::makeSoData(const SharedFileExtended* soext) { data.initArrayName = soext->getUniqueName(".init_array"); data.finiArrayName = soext->getUniqueName(".fini_array"); - data.relaDynIndx = soext->dynRelIndexes.getArrayRef(); - data.relaPltIndx = soext->pltRelIndexes.getArrayRef(); + data.relaDynIndx = soext->relaDynIndexes.getArrayRef(); + data.relaPltIndx = soext->relaPltIndexes.getArrayRef(); data.programHeadersAllocated = soext->programHeaders.size(); data.programHeaders = soext->programHeaders.getArrayRef(); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 2c36a542a244..93fd33ccb2b9 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -315,6 +315,7 @@ template void elf::createSyntheticSections() { } if (config->adlt) { + assert(adltCtx && "ADLT: ctx not initialized!"); in.adltStrTab = std::make_unique(".adlt.strtab", false); in.adltData = std::make_unique>(*in.adltStrTab); add(*in.adltStrTab); @@ -571,6 +572,8 @@ InputSection *AdltWriter::getInputSection(OutputSection *sec) { } template void AdltWriter::checkPhdrs() { + assert(!adltCtx->commonProgramHeaders.empty() && + "Common headers can't be empty!"); for (auto *file : adltCtx->sharedFilesExtended) if (auto *soFile = adltCtx->getSoExt(file)) assert(!soFile->programHeaders.empty() && @@ -583,9 +586,9 @@ template void AdltWriter::checkRelocs() { for (auto *file : adltCtx->sharedFilesExtended) if (auto *soFile = adltCtx->getSoExt(file)) { - assert(!soFile->dynRelIndexes.empty() && + assert(!soFile->relaDynIndexes.empty() && "ADLT: relaDyn indexes can't be empty!"); - assert(!soFile->pltRelIndexes.empty() && + assert(!soFile->relaPltIndexes.empty() && "ADLT: relaPlt indexes can't be empty!"); } } @@ -602,7 +605,8 @@ void AdltWriter::trackPhdr(OutputSection *sec, PhdrEntry *phdr) { template void AdltWriter::traceRelocs() { lld::outs() << "[ADLT]\n"; - lld::outs() << "Dyn relocs (" << mainPart->relaDyn->relocs.size() << ")\n"; + auto dynRelsSize = mainPart->relaDyn->relocs.size(); + lld::outs() << "Dyn relocs (" << dynRelsSize << ")\n"; lld::outs() << "Plt relocs (" << in.relaPlt->relocs.size() << ")\n"; auto printIndexes = [&](auto &vec) { @@ -620,7 +624,7 @@ template void AdltWriter::traceRelocs() { return sym->getName(); }; - auto printRelocTable = [&](auto *relSec, auto &outIndexes) { + auto printRelaTable = [&](auto *relSec, auto &outIndexes) { for (auto &it : outIndexes) // print relocs if (DynamicReloc *rel = &relSec->relocs[it]) lld::outs() << it << ":\t" << rel->inputSec->name << " + 0x" @@ -632,13 +636,13 @@ template void AdltWriter::traceRelocs() { for (auto *file : adltCtx->sharedFilesExtended) if (auto *soFile = adltCtx->getSoExt(file)) { lld::outs() << soFile->soName << ":\n"; - lld::outs() << "Dyn relocs (" << soFile->dynRelIndexes.size() << ")"; - printIndexes(soFile->dynRelIndexes); - printRelocTable(mainPart->relaDyn.get(), soFile->dynRelIndexes); + lld::outs() << ".rela.dyn relocs (" << soFile->relaDynIndexes.size() << ")"; + printIndexes(soFile->relaDynIndexes); + printRelaTable(mainPart->relaDyn.get(), soFile->relaDynIndexes); - lld::outs() << "Plt relocs (" << soFile->pltRelIndexes.size() << ")"; - printIndexes(soFile->pltRelIndexes); - printRelocTable(in.relaPlt.get(), soFile->pltRelIndexes); + lld::outs() << ".rela.plt relocs (" << soFile->relaPltIndexes.size() << ")"; + printIndexes(soFile->relaPltIndexes); + printRelaTable(in.relaPlt.get(), soFile->relaPltIndexes); } } -- Gitee