diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 6abd581ce33f8b93a7ba30ccf43ef86a8b0b4d20..2a0ee3b04dc523a1c9525221316721eec153ab7f 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -1652,15 +1652,7 @@ SharedFileExtended::SharedFileExtended(MemoryBufferRef mb, template void SharedFileExtended::parseForAdlt() { this->parse(); parseDynamics(); - parseElfSymTab(); - // add additional section symbols - for (InputSectionBase *sec : this->sections) - for (StringRef prefix : {".got", ".got.plt"}) - if (sec && sec->name.startswith(prefix)) { - auto *d = make(this, "", ELF::STB_LOCAL, 0, ELF::STT_SECTION, 0, 0, sec); - this->allSymbols.push_back(cast(d)); - } bool isDebug = false; // debug hint if (!isDebug) @@ -1779,10 +1771,27 @@ SharedFileExtended::findInputSection(StringRef name) const { template InputSectionBase * SharedFileExtended::findInputSection(uint64_t offset) const { - for (InputSectionBase *sec : this->sections) - if (sec && sec->address == offset) + llvm::SmallVector candidates; + for (InputSectionBase *sec : this->sections) { + if (!sec) + continue; + if (sec->address == offset) return sec; - return nullptr; + uint64_t low = sec->address; + uint64_t high = low + sec->size; + bool isGood = (offset >= low) && (offset < high); + if (!isGood) + continue; + 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 diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 1e953665722ce2dd08fe281568487d2caa585dec..eb21da94ce628b599794885bff4807aba2366dee 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1337,7 +1337,6 @@ template void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, bool fromDynamic) { auto file = sec.getSharedFile(); - uint32_t symIndex = rel.getSymbol(config->isMips64EL); bool isDebug = false; /*if (r->offset == 0x21F) // debug hint @@ -1347,10 +1346,7 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, isDebug = true;*/ // parse offset (where) - InputSectionBase *secWhere = cast( - fromDynamic - ? file->findDefinedSymbol(r->offset)->section - : (r->sym->isDefined() ? cast(r->sym)->section : &sec)); + InputSectionBase *secWhere = file->findInputSection(r->offset); assert(secWhere && "not found!"); // process offset @@ -1400,8 +1396,6 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, } sec.relocations.push_back(*r); return; - case R_AARCH64_ADD_ABS_LO12_NC: - case R_AARCH64_ADR_PREL_PG_HI21: case R_AARCH64_LDST8_ABS_LO12_NC: case R_AARCH64_LDST16_ABS_LO12_NC: case R_AARCH64_LDST32_ABS_LO12_NC: @@ -1421,6 +1415,10 @@ void RelocationScanner::processForADLT(const RelTy &rel, Relocation *r, sec.relocations.push_back(*r); return; // got relocs + case R_AARCH64_ADD_ABS_LO12_NC: + case R_AARCH64_ADR_PREL_PG_HI21: + sec.relocations.push_back(*r); // TODO: optimize GOT + return; case R_AARCH64_ADR_GOT_PAGE: if (r->sym->isDefined() && !r->sym->needsGot) { if (isDebug)