mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-15 07:18:33 +00:00
[ELF] Optimize replaceCommonSymbols
This decreases the 0.2% time (no debug info) to nearly no.
This commit is contained in:
parent
745420d3f4
commit
40fae4d8fc
@ -1821,17 +1821,21 @@ static void writeDependencyFile() {
|
||||
// symbols of type CommonSymbol.
|
||||
static void replaceCommonSymbols() {
|
||||
llvm::TimeTraceScope timeScope("Replace common symbols");
|
||||
for (Symbol *sym : symtab->symbols()) {
|
||||
auto *s = dyn_cast<CommonSymbol>(sym);
|
||||
if (!s)
|
||||
for (ELFFileBase *file : objectFiles) {
|
||||
if (!file->hasCommonSyms)
|
||||
continue;
|
||||
for (Symbol *sym : file->getGlobalSymbols()) {
|
||||
auto *s = dyn_cast<CommonSymbol>(sym);
|
||||
if (!s)
|
||||
continue;
|
||||
|
||||
auto *bss = make<BssSection>("COMMON", s->size, s->alignment);
|
||||
bss->file = s->file;
|
||||
bss->markDead();
|
||||
inputSections.push_back(bss);
|
||||
s->replace(Defined{s->file, s->getName(), s->binding, s->stOther, s->type,
|
||||
/*value=*/0, s->size, bss});
|
||||
auto *bss = make<BssSection>("COMMON", s->size, s->alignment);
|
||||
bss->file = s->file;
|
||||
bss->markDead();
|
||||
inputSections.push_back(bss);
|
||||
s->replace(Defined{s->file, s->getName(), s->binding, s->stOther, s->type,
|
||||
/*value=*/0, s->size, bss});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1123,6 +1123,7 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
|
||||
if (value == 0 || value >= UINT32_MAX)
|
||||
fatal(toString(this) + ": common symbol '" + name +
|
||||
"' has invalid alignment: " + Twine(value));
|
||||
hasCommonSyms = true;
|
||||
sym->resolve(
|
||||
CommonSymbol{this, name, binding, stOther, type, value, size});
|
||||
continue;
|
||||
|
@ -205,12 +205,15 @@ protected:
|
||||
// Initializes this class's member variables.
|
||||
template <typename ELFT> void init();
|
||||
|
||||
StringRef stringTable;
|
||||
const void *elfShdrs = nullptr;
|
||||
const void *elfSyms = nullptr;
|
||||
uint32_t numELFShdrs = 0;
|
||||
uint32_t numELFSyms = 0;
|
||||
uint32_t firstGlobal = 0;
|
||||
StringRef stringTable;
|
||||
|
||||
public:
|
||||
bool hasCommonSyms = false;
|
||||
};
|
||||
|
||||
// .o file.
|
||||
|
Loading…
x
Reference in New Issue
Block a user