From 8f94cbb2895abfa665374df8a87ca6e6da0f56f4 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Fri, 17 May 2024 08:36:46 -0400 Subject: [PATCH] ADLT: refactor #1. AdltCtx. Change-Id: Ib932ac65fbadc553c8328c5e0cfe972ae5638822 Signed-off-by: Anton Volkov --- lld/ELF/Adlt.h | 73 +++++++++++++++++ lld/ELF/Config.h | 20 ----- lld/ELF/Driver.cpp | 65 ++++++--------- lld/ELF/InputFiles.cpp | 60 +++++++++----- lld/ELF/InputFiles.h | 22 ++++-- lld/ELF/InputSection.cpp | 19 +++-- lld/ELF/InputSection.h | 5 -- lld/ELF/MapFile.cpp | 5 +- lld/ELF/MarkLive.cpp | 3 +- lld/ELF/Relocations.cpp | 144 +++++++++++++++++++--------------- lld/ELF/SyntheticSections.cpp | 29 +++---- lld/ELF/Writer.cpp | 39 ++++----- 12 files changed, 285 insertions(+), 199 deletions(-) create mode 100644 lld/ELF/Adlt.h diff --git a/lld/ELF/Adlt.h b/lld/ELF/Adlt.h new file mode 100644 index 000000000000..61986489702a --- /dev/null +++ b/lld/ELF/Adlt.h @@ -0,0 +1,73 @@ +//===- 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/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; + +template class ObjFile; +template class SharedFileExtended; + +class AdltCtx { +public: + llvm::SmallVector sharedFilesExtended; + // Useful getters + template + const SharedFileExtended *getSoExt(const ObjFile *file); + 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::DenseSet duplicatedSymNames; +}; + +// The only instance of Ctx struct. +extern std::unique_ptr adltCtx; + +template +const SharedFileExtended *AdltCtx::getSoExt(const ObjFile *file) { + assert(file); + return cast>(file); +} + +template +SharedFileExtended *AdltCtx::getSoExt(InputFile *file) { + assert(file); + return cast>(file); +} + +template +SharedFileExtended *AdltCtx::getSoExt(unsigned orderId) { + assert(orderId < sharedFilesExtended.size()); + return getSoExt(sharedFilesExtended[orderId]); +} + +} // namespace elf +} // namespace lld + +// OHOS_LOCAL end +#endif 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 a4ee33280065..0a7c9a1665f8 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); @@ -114,6 +116,8 @@ bool elf::link(ArrayRef args, llvm::raw_ostream &stdoutOS, config = std::make_unique(); elf::ctx = std::make_unique(); + if (config->adlt) + elf::adltCtx = std::make_unique(); driver = std::make_unique(); script = std::make_unique(); symtab = std::make_unique(); @@ -849,7 +853,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 = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (ELFFileBase *file : files) for (Symbol *sym : file->getSymbols()) map[sym->getName()] = sym; @@ -1828,7 +1832,7 @@ static void excludeLibs(opt::InputArgList &args) { sym->versionId = VER_NDX_LOCAL; }; - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (ELFFileBase *file : files) visit(file); @@ -2025,7 +2029,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 = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (ELFFileBase *file : files) { if (!file->hasCommonSyms) continue; @@ -2102,7 +2106,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 = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (InputFile *f : files) { auto *obj = cast>(f); ArrayRef syms = obj->getSymbols(); @@ -2357,7 +2361,7 @@ static void redirectSymbols(ArrayRef wrapped) { return; // Update pointers in input files. - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; parallelForEach(files, [&](ELFFileBase *file) { for (Symbol *&sym : file->getMutableGlobalSymbols()) if (Symbol *s = map.lookup(sym)) @@ -2393,7 +2397,7 @@ static uint32_t getAndFeatures() { return 0; uint32_t ret = -1; - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (ELFFileBase *f : files) { uint32_t features = f->andFeatures; @@ -2477,46 +2481,25 @@ static void postParseObjectFile(ELFFileBase *file) { } } -static void postParseSharedFileForAdlt(ELFFileBase *file) { +static void postParseSharedFileExtended(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(""); } } -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) { @@ -2575,7 +2558,7 @@ void LinkerDriver::link(opt::InputArgList &args) { buildSymsHist(file, eSymsHist); for (auto eSym : eSymsHist) if (eSym.second > 1) - ctx->adlt.duplicatedSymNames.insert(eSym.first); + adltCtx->duplicatedSymNames.insert(eSym.first); eSymsHist.clear(); } @@ -2597,7 +2580,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 +2638,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, postParseSharedFileExtended); parallelForEach(ctx->objectFiles, initializeLocalSymbols); parallelForEach(ctx->objectFiles, postParseObjectFile); @@ -2724,7 +2707,7 @@ 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(); + const size_t numSoBeforeLTO = adltCtx->sharedFilesExtended.size(); invokeELFT(compileBitcodeFiles, skipLinkedOutput); // Symbol resolution finished. Report backward reference problems, @@ -2743,8 +2726,8 @@ void LinkerDriver::link(opt::InputArgList &args) { // more file will be added. if (config->adlt) { auto newSharedFiles = - makeArrayRef(ctx->sharedFilesExtended).slice(numSoBeforeLTO); - parallelForEach(newSharedFiles, postParseSharedFileForAdlt); + makeArrayRef(adltCtx->sharedFilesExtended).slice(numSoBeforeLTO); + parallelForEach(newSharedFiles, postParseObjectFile); } auto newObjectFiles = makeArrayRef(ctx->objectFiles).slice(numObjsBeforeLTO); parallelForEach(newObjectFiles, initializeLocalSymbols); @@ -2770,9 +2753,9 @@ 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 (InputSectionBase *s : it.value()->getSections()) - if (isSectionValidForAdlt(it.index(), s)) + for (auto *it : adltCtx->sharedFilesExtended) + for (InputSectionBase *s : it->getSections()) + if (it->isSectionValid(s)) inputSections.push_back(s); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 0b6ac03faff1..1fae37b85268 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" @@ -162,7 +163,7 @@ template static void doBuildSymsHist(InputFile *file, ESymsCntMap &eSymsHist) { if (!isCompatible(file)) return; - if (auto *f = dyn_cast>(file)) + if (auto *f = adltCtx->getSoExt(file)) f->buildSymsHist(eSymsHist); } @@ -197,10 +198,10 @@ 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->parseForAdlt(); + if (auto *f = adltCtx->getSoExt(file)) { + f->orderIdx = adltCtx->sharedFilesExtended.size(); + adltCtx->sharedFilesExtended.push_back(f); + f->parse(); 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); @@ -1247,7 +1248,7 @@ template void ObjFile::postParse() { continue; std::lock_guard lock(mu); if (config->adlt) { - auto *f = cast>(this); + auto *f = adltCtx->getSoExt(this); bool isDebug = false; if (isDebug) { lld::outs() << "Put to duplicates for: " << archiveName << "\n"; @@ -1622,7 +1623,7 @@ template void SharedFile::parse() { } template -void SharedFileExtended::resolveDuplicatesForAdlt() { +void SharedFileExtended::resolveDuplicates() { auto pred = [&](DuplicateSymbol dup) { auto sym = dup.sym; if (!sym->isDefined()) @@ -1657,8 +1658,9 @@ SharedFileExtended::SharedFileExtended(MemoryBufferRef mb, const_cast(this->fileKind) = InputFile::SharedKind; } -template void SharedFileExtended::parseForAdlt() { - this->parse(); +template +void SharedFileExtended::parse(bool ignoreComdats) { + ObjFile::parse(ignoreComdats); parseDynamics(); parseElfSymTab(); @@ -1702,10 +1704,32 @@ template void SharedFileExtended::parseForAdlt() { lld::outs() << '\n'; } -template void SharedFileExtended::postParseForAdlt() { - this->initializeLocalSymbols(); - this->postParse(); - resolveDuplicatesForAdlt(); +template void SharedFileExtended::postParse() { + ObjFile::initializeLocalSymbols(); + ObjFile::postParse(); + resolveDuplicates(); +} + +template +bool SharedFileExtended::isSectionValid(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; } template @@ -1915,7 +1939,7 @@ Symbol &SharedFileExtended::getDynamicSymbol(uint32_t symbolIndex) const { } template -Symbol &SharedFileExtended::getSymbolADLT(uint32_t symbolIndex, +Symbol &SharedFileExtended::getSymbol(uint32_t symbolIndex, bool fromDynamic) const { Symbol &sym = fromDynamic ? getDynamicSymbol(symbolIndex) : getSymbolFromElfSymTab(symbolIndex); @@ -1925,7 +1949,7 @@ Symbol &SharedFileExtended::getSymbolADLT(uint32_t symbolIndex, return sym; /*if (name.contains("__emutls_v.TLS_data1")) // debug hint - lld::outs() << "debug getSymbolADLT(): " << name << "\n";*/ + lld::outs() << "debug getSymbol(): " << name << "\n";*/ // check SymbolTable auto res = elf::symtab->find(name); @@ -2040,7 +2064,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/InputFiles.h b/lld/ELF/InputFiles.h index b8d47779488d..4413ccc1e1b2 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -199,6 +199,10 @@ public: .slice(firstGlobal); } + // OHOS_LOCAL begins + virtual bool isSectionValid(InputSectionBase *s) { return true; } + // OHOS_LOCAL end + template typename ELFT::ShdrRange getELFShdrs() const { return typename ELFT::ShdrRange( reinterpret_cast(elfShdrs), numELFShdrs); @@ -243,13 +247,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]; @@ -296,7 +300,7 @@ public: void buildSymsHist(ESymsCntMap &eSymsHist); void initializeLocalSymbols(); - void postParse(); + virtual void postParse(); protected: virtual StringRef getUniqueName(StringRef origName) const; @@ -401,8 +405,10 @@ public: return f->kind() == InputFile::SharedKind; } - void parseForAdlt(); - void postParseForAdlt(); + virtual void parse(bool ignoreComdats = false) override; + virtual void postParse() override; + + virtual bool isSectionValid(InputSectionBase *s) override; StringRef addAdltPostfix(StringRef input) const; bool addAdltPostfix(Symbol *s); @@ -423,7 +429,7 @@ public: template Symbol &getRelocTargetSymADLT(const RelT &rel, InputSectionBase &sec) const { uint32_t symIndex = rel.getSymbol(config->isMips64EL); - return getSymbolADLT(symIndex, isDynamicSection(sec)); + return getSymbol(symIndex, isDynamicSection(sec)); } ArrayRef getLocalSymbols() override { @@ -433,7 +439,7 @@ public: } Symbol &getDynamicSymbol(uint32_t symbolIndex) const; - Symbol &getSymbolADLT(uint32_t symbolIndex, bool fromDynamic) const; + Symbol &getSymbol(uint32_t symbolIndex, bool fromDynamic) const; Symbol &getSymbolFromElfSymTab(uint32_t symbolIndex) const { if (symbolIndex >= this->allSymbols.size()) @@ -492,7 +498,7 @@ private: void parseDynamics(); // SharedFile compability void parseElfSymTab(); // ObjectFile compability - void resolveDuplicatesForAdlt(); + void resolveDuplicates(); StringRef getShStrTab(ArrayRef elfSections); diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 0eb2968413bd..78a34afa8fef 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -8,6 +8,7 @@ #include "InputSection.h" #include "Config.h" +#include "Adlt.h" #include "InputFiles.h" #include "OutputSections.h" #include "Relocations.h" @@ -348,10 +349,11 @@ 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(); - Symbol &sym = config->adlt - ? getSharedFile()->getRelocTargetSymADLT(rel, *sec) - : file->getRelocTargetSym(rel); + config->adlt ? adltCtx->getSoExt(file) : getFile(); + Symbol &sym = + config->adlt + ? adltCtx->getSoExt(file)->getRelocTargetSymADLT(rel, *sec) + : file->getRelocTargetSym(rel); auto *p = reinterpret_cast(buf); buf += sizeof(RelTy); @@ -847,9 +849,10 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef rels) { if (!RelTy::IsRela) addend += target.getImplicitAddend(bufLoc, type); - Symbol &sym = config->adlt ? getSharedFile()->getSymbolFromElfSymTab( - rel.getSymbol(config->isMips64EL)) - : getFile()->getRelocTargetSym(rel); + Symbol &sym = config->adlt + ? adltCtx->getSoExt(file)->getSymbolFromElfSymTab( + rel.getSymbol(config->isMips64EL)) + : getFile()->getRelocTargetSym(rel); if (config->adlt) { // TODO improve switch (type) { case R_AARCH64_RELATIVE: @@ -964,7 +967,7 @@ 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) + (config->adlt ? LLVM_UNLIKELY(adltCtx->getSoExt(file)->splitStack) : LLVM_UNLIKELY(getFile()->splitStack))) adjustSplitStackFunctionPrologues(buf, bufEnd); diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index b9f4541e77a9..1d13d1673304 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -137,11 +137,6 @@ public: return cast_or_null>(file); } - template - SharedFileExtended *getSharedFile() const { - return cast_or_null>(file); - } - // Used by --optimize-bb-jumps and RISC-V linker relaxation temporarily to // indicate the number of bytes which is not counted in the size. This should // be reset to zero after uses. diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp index 51353287c90e..f4a3ad98f434 100644 --- a/lld/ELF/MapFile.cpp +++ b/lld/ELF/MapFile.cpp @@ -23,6 +23,7 @@ #include "LinkerScript.h" #include "OutputSections.h" #include "Symbols.h" +#include "Adlt.h" #include "SyntheticSections.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/SetVector.h" @@ -55,7 +56,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 = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (ELFFileBase *file : files) for (Symbol *b : file->getSymbols()) if (auto *dr = dyn_cast(b)) @@ -225,7 +226,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 = config->adlt ? adltCtx->sharedFilesExtended : 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..66974398c92d 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -25,6 +25,7 @@ #include "LinkerScript.h" #include "SymbolTable.h" #include "Symbols.h" +#include "Adlt.h" #include "SyntheticSections.h" #include "Target.h" #include "lld/Common/CommonLinkerContext.h" @@ -345,7 +346,7 @@ 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; + auto files = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (ELFFileBase *file : files) for (Symbol *s : file->getSymbols()) if (auto *d = dyn_cast(s)) diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 798440141025..cd390a01539d 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" @@ -433,6 +434,44 @@ private: size_t i = 0; }; +// OHOS_LOCAL begin +template class AdltRelocationScanner { +public: + explicit AdltRelocationScanner(InputSectionBase &sec) : sec(sec) {} + + SharedFileExtended *getSoExt() { + return adltCtx->getSoExt(sec.file); + } + void process(Relocation *r, bool fromDynamic); + void trackGotPlt(Symbol *sym); + void trackDynReloc(); + + unsigned getDynamicRelocsCount(); + bool isRelr() { return config->adlt && relSecType == SHT_RELR; } + bool toProcessAux = false; + +private: + uint32_t relSecType = SHT_NULL; + InputSectionBase &sec; +}; + +template +void AdltRelocationScanner::trackGotPlt(Symbol *sym) { + adltCtx->gotPltInfo[sym].push_back(getSoExt()->orderIdx); +} + +template void AdltRelocationScanner::trackDynReloc() { + getSoExt()->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 { @@ -458,16 +497,10 @@ 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); - - // ADLT - template - void processForADLT(const RelTy &rel, Relocation *r, bool fromDynamic); - - template - void tracePushRelocADLT(InputSectionBase &isec, Relocation &r) const; }; } // namespace @@ -1036,6 +1069,9 @@ 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 @@ -1304,39 +1340,10 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym, return 0; } -template -static void trackDynRelocAdlt(SharedFileExtended *soFile) { - soFile->dynRelIndexes.insert(mainPart->relaDyn->relocs.size() - 1); -} - -template -static void trackGotPltAdlt(Symbol *sym, SharedFileExtended *soFile) { - ctx->adlt.gotPltInfo[sym].push_back(soFile->orderIdx); -} - -// ADLT BEGIN -template -void RelocationScanner::tracePushRelocADLT(InputSectionBase &isec, - Relocation &r) const { - auto file = sec.getSharedFile(); - 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) { - auto file = sec.getSharedFile(); +// OHOS_LOCAL begin +template +void AdltRelocationScanner::process(Relocation *r, bool fromDynamic) { + auto file = adltCtx->getSoExt(sec.file); bool isDebug = false; /*if (r->offset == 0x21F) // debug hint @@ -1353,9 +1360,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 @@ -1366,20 +1370,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: @@ -1388,10 +1393,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); @@ -1403,7 +1408,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: @@ -1432,13 +1437,13 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, 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: @@ -1457,17 +1462,17 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, break; } } -// ADLT END +// OHOS_LOCAL end template void RelocationScanner::scanOne(RelTy *&i) { const RelTy &rel = *i; uint32_t symIndex = rel.getSymbol(config->isMips64EL); bool fromDynamic = false; if (config->adlt) - fromDynamic = sec.getSharedFile()->isDynamicSection(sec); + fromDynamic = adltCtx->getSoExt(sec.file)->isDynamicSection(sec); Symbol &sym = config->adlt - ? sec.getSharedFile()->getSymbolADLT(symIndex, fromDynamic) + ? adltCtx->getSoExt(sec.file)->getSymbol(symIndex, fromDynamic) : sec.getFile()->getSymbol(symIndex); RelType type; @@ -1501,8 +1506,11 @@ template void RelocationScanner::scanOne(RelTy *&i) { int64_t addend = computeAddend(rel, expr, sym.isLocal()); if (config->adlt) { + AdltRelocationScanner adltScanner(sec); Relocation r = {expr, type, offset, addend, &sym}; - processForADLT(rel, &r, fromDynamic); + adltScanner.process(&r, fromDynamic); + if (adltScanner.toProcessAux) + processAux(r); return; } @@ -1716,6 +1724,7 @@ void RelocationScanner::scan(ArrayRef rels) { template void elf::scanRelocations(InputSectionBase &s) { RelocationScanner scanner(s); + AdltRelocationScanner adltScanner(s); if (config->adlt) { bool isDebug = false; if (isDebug) @@ -1807,15 +1816,24 @@ static bool handleNonPreemptibleIfunc(Symbol &sym) { return true; } -template static void addGotPltIndexAdlt(Symbol *s, bool isPlt) { - auto &vec = ctx->adlt.gotPltInfo[s]; - for (auto &it : vec) { - auto *soFile = cast>(ctx->sharedFilesExtended[it]); +// OHOS_LOCAL begin +namespace lld { +namespace elf { +namespace adlt { +template static void addGotPltIndex(Symbol *s, bool isPlt) { + auto &vec = adltCtx->gotPltInfo[s]; + 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) { @@ -1829,12 +1847,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()) { @@ -1869,7 +1887,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); @@ -1923,7 +1941,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 61d52dc894b5..e2d32416c65b 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,8 +1399,8 @@ DynamicSection::computeContents() { part.dynStrTab->addString(config->rpath)); if (config->adlt) { - for (InputFile *file : ctx->sharedFilesExtended) { - auto *f = cast>(file); + for (InputFile *file : adltCtx->sharedFilesExtended) { + auto *f = adltCtx->getSoExt(file); for (size_t i = 0; i < f->dtNeeded.size(); i++) { auto tag = DT_NEEDED; auto val = part.dynStrTab->addString(f->dtNeeded[i]); @@ -1557,8 +1558,8 @@ DynamicSection::computeContents() { return &osd->osec; return (OutputSection *)nullptr; }; - for (InputFile *file : ctx->sharedFilesExtended) { - auto *f = cast>(file); + for (InputFile *file : adltCtx->sharedFilesExtended) { + auto *f = adltCtx->getSoExt(file); auto initArray = findSection(f->addAdltPostfix(".init_array")); auto finiArray = findSection(f->addAdltPostfix(".fini_array")); if (initArray) { @@ -2276,8 +2277,8 @@ void SymbolTableBaseSection::sortSymTabSymbolsInAdlt(size_t numLocals) { return {-1, file}; }; - for (InputFile* file : ctx->sharedFilesExtended) { - auto* soext = cast>(file); + for (InputFile* file : adltCtx->sharedFilesExtended) { + auto* soext = adltCtx->getSoExt(file); soext->sharedLocalSymbolIndex = llvm::None; soext->sharedGlobalSymbolIndex = llvm::None; } @@ -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 = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; parallelForEach(files, [](ELFFileBase *file) { for (InputSectionBase *sec : file->getSections()) { if (!sec) @@ -4104,9 +4105,9 @@ AdltSection::AdltSection(StringTableSection& strTabSec) template void AdltSection::finalizeContents() { soInputs.clear(); - soInputs.reserve(ctx->sharedFilesExtended.size()); - for (InputFile* file : ctx->sharedFilesExtended) { - auto* soext = cast>(file); + soInputs.reserve(adltCtx->sharedFilesExtended.size()); + for (InputFile* file : adltCtx->sharedFilesExtended) { + auto* soext = adltCtx->getSoExt(file); soInputs.push_back(makeSoData(soext)); } @@ -4199,7 +4200,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 }; } @@ -4348,7 +4349,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); @@ -4382,7 +4383,7 @@ void AdltSection::finalizeOnWrite() { template void AdltSection::finalizeOnWrite(size_t idx, SoData& soData) { - auto* soext = cast>(ctx->sharedFilesExtended[idx]); + auto* soext = adltCtx->getSoExt(idx); // require SymbolTableBaseSection::sortSymTabSymbolsInAdlt for .symtab called soData.sharedLocalIndex = soext->sharedLocalSymbolIndex; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 6743de95cd2f..c04b8f858f9b 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() && @@ -593,11 +594,11 @@ template void AdltWriter::trackPhdr(OutputSection *sec, PhdrEntry *phdr) { auto *isec = getInputSection(sec); if (isec && isec->file) - if (auto *soFile = ctx->adlt.getSoExt(isec->file)) { + if (auto *soFile = adltCtx->getSoExt(isec->file)) { soFile->programHeaders.insert(phdr); return; } - ctx->adlt.commonProgramHeaders.insert(phdr); + adltCtx->commonProgramHeaders.insert(phdr); } template void AdltWriter::traceRelocs() { @@ -621,8 +622,8 @@ template void AdltWriter::traceRelocs() { << " + 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 +660,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() << ")"; @@ -790,7 +791,7 @@ template static void markUsedLocalSymbols() { // See MarkLive::resolveReloc(). if (config->gcSections) return; - auto files = config->adlt ? ctx->sharedFilesExtended : ctx->objectFiles; + auto files = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (ELFFileBase *file : files) { ObjFile *f = cast>(file); for (InputSectionBase *s : f->getSections()) { @@ -862,7 +863,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()"); @@ -1189,7 +1190,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; @@ -1489,7 +1490,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 +1907,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 = config->adlt ? adltCtx->sharedFilesExtended : ctx->objectFiles; for (InputFile *File : files) { parallelForEach(File->getSymbols(), [&](Symbol *Sym) { auto *def = dyn_cast(Sym); @@ -2127,8 +2128,8 @@ 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)) { - auto *soFile = cast>(it.value()); + for (auto *file : adltCtx->sharedFilesExtended) { + auto *soFile = adltCtx->getSoExt(file); auto sections = soFile->getSections(); // scan .rela.dyn (base: SHT_NULL) scanRelocations(*sections[0]); @@ -2520,7 +2521,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