From a253ca3ac09df29254718e4bc88e7f532becf4aa Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel Date: Fri, 17 Jan 2025 14:18:56 -0300 Subject: [PATCH] Debug extra symbols --- lld/ELF/Arch/SBF.cpp | 2 +- lld/ELF/SyntheticSections.cpp | 4 +--- lld/ELF/SyntheticSections.h | 1 + lld/ELF/Writer.cpp | 28 +++++++++++++++++++--------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lld/ELF/Arch/SBF.cpp b/lld/ELF/Arch/SBF.cpp index 77c9a76d55c44f..ac53727fac4f6d 100644 --- a/lld/ELF/Arch/SBF.cpp +++ b/lld/ELF/Arch/SBF.cpp @@ -41,7 +41,7 @@ SBF::SBF() { symbolicRel = R_SBF_64_64; defaultCommonPageSize = 8; defaultMaxPageSize = 8; - defaultImageBase = 8; + defaultImageBase = 0; } RelExpr SBF::getRelExpr(RelType type, const Symbol &s, diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 6b90f7cd45bb0e..c4035d309d8093 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -272,8 +272,6 @@ Defined *elf::addSyntheticLocal(StringRef name, uint8_t type, uint64_t value, Defined *s = makeDefined(section.file, name, STB_LOCAL, STV_DEFAULT, type, value, size, §ion); if (in.symTab) { - std::ofstream out("/Users/lucasste/Documents/solana-test/program/addsyn.txt", std::ios::app); - out << s->getName().str() << std::endl; in.symTab->addSymbol(s); } @@ -2178,7 +2176,7 @@ void SymbolTableBaseSection::addSymbol(Symbol *b) { (config->emachine == EM_SBF && config->eflags == 0x3)); unsigned Offset; - if (strTabSec.name == ".dynstr" && b->isLocal()) { + if (this->type == SHT_DYNSYM && b->isLocal()) { const static unsigned LocalOffset = strTabSec.addString("hidden_func", false); Offset = LocalOffset; } else { diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index eaf1b6ea112b90..b6fc035eedcc67 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -31,6 +31,7 @@ #include "llvm/Support/Endian.h" #include "llvm/Support/Parallel.h" #include "llvm/Support/Threading.h" +#include namespace lld::elf { class Defined; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 95be552c3fd6b3..d25b68ea2f637a 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -786,12 +786,11 @@ static void demoteAndCopyLocalSymbols() { if (isSbfV3() && includeInSymtab(*b) && shouldKeepInSymtab(*dr) && - (b->used || (!config->gcSections && (!config->copyRelocs || config->discard == DiscardPolicy::None)))) { - if ((b->type & STT_FUNC) != 0) { + (b->used || (!config->gcSections && (!config->copyRelocs || config->discard == DiscardPolicy::None))) && + b->type == STT_FUNC) { // std::ofstream out("/Users/lucasste/Documents/solana-test/program/demote.txt", std::ios::app); // out << "Adding sym: " << b->getName().str() << std::endl; - partitions[b->partition - 1].dynSymTab->addSymbol(b); - } + partitions[b->partition - 1].dynSymTab->addSymbol(b); } } } @@ -1712,6 +1711,7 @@ template void Writer::finalizeAddressDependentContent() { AArch64Err843419Patcher a64p; ARMErr657417Patcher a32p; script->assignAddresses(); + bool SbfDuplicateRemoval = false; // .ARM.exidx and SHF_LINK_ORDER do not require precise addresses, but they // do require the relative addresses of OutputSections because linker scripts // can assign Virtual Addresses to OutputSections that are not monotonically @@ -1762,6 +1762,15 @@ template void Writer::finalizeAddressDependentContent() { } const Defined *changedSym = script->assignAddresses(); + + if (!SbfDuplicateRemoval && isSbfV3()) { + for (Partition &part: partitions) { + part.dynSymTab->sortSymbolsByValue(); + } + SbfDuplicateRemoval = true; + changed = true; + } + if (!changed) { // Some symbols may be dependent on section addresses. When we break the // loop, the symbol values are finalized because a previous @@ -2104,7 +2113,7 @@ template void Writer::finalizeSections() { addVerneed(sym); } else if (isSbfV3() && (sym->used || (!config->gcSections && (!config->copyRelocs || config->discard == DiscardPolicy::None))) && - (sym->type & STT_FUNC) != 0) { + sym->type == STT_FUNC) { partitions[sym->partition - 1].dynSymTab->addSymbol(sym); } } @@ -2300,11 +2309,12 @@ template void Writer::finalizeSections() { if (config->emachine == EM_ARM && !config->isLE && config->armBe8) { addArmInputSectionMappingSymbols(); sortArmMappingSymbols(); - } else if (isSbfV3()) { - for (Partition &part: partitions) { - part.dynSymTab->sortSymbolsByValue(); - } } +// else if (isSbfV3()) { +// for (Partition &part: partitions) { +// part.dynSymTab->sortSymbolsByValue(); +// } +// } } // Ensure data sections are not mixed with executable sections when