diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp index 7274232d1469f99ac6a0cb54e30fa0e3aeb001c1..4c3e5aff9ef2656b2e5380a08fce64d656ac40df 100644 --- a/lld/ELF/Arch/AArch64.cpp +++ b/lld/ELF/Arch/AArch64.cpp @@ -455,6 +455,8 @@ void AArch64::relocate(uint8_t *loc, const Relocation &rel, checkInt(loc, val, 33, rel); LLVM_FALLTHROUGH; case R_AARCH64_ADR_PREL_PG_HI21_NC: + if (config->adlt && *(uint32_t*)loc == 0xd503201f) // ignore nop + break; write32AArch64Addr(loc, val >> 12); break; case R_AARCH64_ADR_PREL_LO21: diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index ffd2511d0b1c7320ae314dae11912e7726a779df..f4f8b81b018f12f302c71c7260a7de526d0c4e01 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -1667,7 +1667,8 @@ template void SharedFileExtended::parseForAdlt() { lld::outs() << "Parse offsets of some sections:\n"; for (const Elf_Shdr &sec : objSections) { auto name = check(obj.getSectionName(sec, shstrtab)); - if (name == ".init_array" || name == ".fini_array" || name == ".data") + if (name == ".init_array" || name == ".fini_array" || name == ".data" || + name == ".data.rel.ro" || name == ".bss.rel.ro" || name == ".bss") traceElfSection(sec); } lld::outs() << '\n'; @@ -1680,12 +1681,12 @@ template void SharedFileExtended::postParseForAdlt() { } template -StringRef SharedFileExtended::addAdltPrefix(StringRef input) { +StringRef SharedFileExtended::addAdltPostfix(StringRef input) { return markItemForAdlt(input, soName); } template -bool SharedFileExtended::addAdltPrefix(Symbol *s) { +bool SharedFileExtended::addAdltPostfix(Symbol *s) { StringRef newName = markItemForAdlt(s->getName(), soName); if (s->getName() == newName) return false; @@ -2007,6 +2008,8 @@ template void SharedFileExtended::parseElfSymTab() { const Elf_Shdr *eSec = *p; InputSectionBase *sec = this->sections[secIdx]; auto val = eSym.st_value - eSec->sh_addr; + if (name.startswith("__")) + name = addAdltPostfix(name); this->allSymbols[i] = make(this, name, bind, other, type, val, eSym.st_size, sec); } else { diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 5207ef34344cb8357e1866acfd5611c5b15abc85..821e5f369db30c0e0230e19473a952cdc301e56c 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -399,8 +399,8 @@ public: void parseForAdlt(); void postParseForAdlt(); - StringRef addAdltPrefix(StringRef input); - bool addAdltPrefix(Symbol *s); + StringRef addAdltPostfix(StringRef input); + bool addAdltPostfix(Symbol *s); Defined *findSectionSymbol(uint64_t offset) const; Defined *findDefinedSymbol( diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 51c505d159d53a811172e360a0a2065ea49a5c25..68729e4ebc4bfc88515e33cfd1f49e3a2a6fc1d2 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -104,7 +104,9 @@ static StringRef getOutputSectionName(const InputSectionBase *s) { {".data.rel.ro", ".data", ".rodata", ".bss.rel.ro", ".bss", ".gcc_except_table", ".init_array", ".fini_array", ".tbss", ".tdata", ".ARM.exidx", ".ARM.extab", ".ctors", ".dtors", ".ohos.randomdata"}) // OHOS_LOCAL - if (isSectionPrefix(v, s->name)) + if (config->adlt && s->name.startswith(v)) + return s->name; + else if (isSectionPrefix(v, s->name)) return v; return s->name; diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 278c4927bccffcbb7c3ace44aadf065ecaebe0ac..de31d8cc2af4ad6cf9b6c5f3d89ca2df2797f511 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1427,13 +1427,19 @@ template void RelocationScanner::scanOne(RelTy *&i) { Symbol *s = &sym; if (!(expr == R_PLT || expr == R_PLT_PC || expr == R_GOT || expr == R_GOT_PC)) - if (Symbol *tmp = &file->getSymbolFromElfSymTab(symIndex)) - if (tmp->getName() != s->getName()) - s = tmp; + if (Symbol *tmp = &file->getSymbolFromElfSymTab(symIndex)) { + if (isDebug) + traceSym(debugTitle + "changed to tmp: ", *tmp); + s = tmp; + } s = sym.getName().size() ? elf::symtab->find(sym.getName()) : &sym; - if (!s) // if symbol was not found in elf::symtab + if (!s) { // if symbol was not found in elf::symtab s = &sym; + in.symTab->addSymbol(s); + } + if (isDebug) + traceSym(debugTitle + "before push: ", *s); if (s->isUndefined()) { if (expr == R_PLT || expr == R_PLT_PC) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 8a7208698c6d18466fcae13d56683759795304a0..29135ddb16d79ecc5fdafb0355797abb3f9a5b24 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1560,8 +1560,8 @@ DynamicSection::computeContents() { }; for (InputFile *file : ctx->sharedFilesExtended) { auto *f = cast>(file); - auto initArray = findSection(f->addAdltPrefix(".init_array")); - auto finiArray = findSection(f->addAdltPrefix(".fini_array")); + auto initArray = findSection(f->addAdltPostfix(".init_array")); + auto finiArray = findSection(f->addAdltPostfix(".fini_array")); if (initArray) { addInt(DT_INIT_ARRAY, initArray->addr); addInt(DT_INIT_ARRAYSZ, initArray->size); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index a3db65a4732cdfc3c42015ff5324b415fa7dd076..de16dec8e6098c52d90dce222ea2b6bd438acc57 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -273,7 +273,9 @@ void elf::addReservedSymbols() { static OutputSection *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) + if ((config->adlt ? osd->osec.name.startswith(name) + : osd->osec.name == name) && + osd->osec.partition == partition) return &osd->osec; return nullptr; } @@ -831,6 +833,12 @@ static bool isRelroSection(const OutputSection *sec) { // ELF in spirit. But in reality many linker features depend on // magic section names. StringRef s = sec->name; + if (config->adlt) + return s.startswith(".data.rel.ro") || s.startswith(".bss.rel.ro") || + s.startswith(".ctors") || s.startswith(".dtors") || + s.startswith(".eh_frame") || s.startswith(".fini_array") || + s.startswith(".init_array") || s.startswith(".preinit_array"); + return s == ".data.rel.ro" || s == ".bss.rel.ro" || s == ".ctors" || s == ".dtors" || s == ".jcr" || s == ".eh_frame" || s == ".fini_array" || s == ".init_array" ||