Skip to content

Commit

Permalink
Debug extra symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Jan 17, 2025
1 parent fd0028d commit a253ca3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lld/ELF/Arch/SBF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, &section);
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);
}

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions lld/ELF/SyntheticSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "llvm/Support/Endian.h"
#include "llvm/Support/Parallel.h"
#include "llvm/Support/Threading.h"
#include <unordered_set>

namespace lld::elf {
class Defined;
Expand Down
28 changes: 19 additions & 9 deletions lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -1712,6 +1711,7 @@ template <class ELFT> void Writer<ELFT>::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
Expand Down Expand Up @@ -1762,6 +1762,15 @@ template <class ELFT> void Writer<ELFT>::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
Expand Down Expand Up @@ -2104,7 +2113,7 @@ template <class ELFT> void Writer<ELFT>::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);
}
}
Expand Down Expand Up @@ -2300,11 +2309,12 @@ template <class ELFT> void Writer<ELFT>::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
Expand Down

0 comments on commit a253ca3

Please sign in to comment.