forked from OSchip/llvm-project
glld/mac] Don't add names of unreferenced symbols to string table
Before this, a hello world program would contain many many unnecessary entries in its string table. No behavior change, just makes the string table in the output smaller and more like ld64's. Differential Revision: https://reviews.llvm.org/D93711
This commit is contained in:
parent
7ec7788ac1
commit
57ffbe020a
|
@ -694,6 +694,11 @@ void SymtabSection::emitStabs() {
|
|||
}
|
||||
|
||||
void SymtabSection::finalizeContents() {
|
||||
auto addSymbol = [&](std::vector<SymtabEntry> &symbols, Symbol *sym) {
|
||||
uint32_t strx = stringTableSection.addString(sym->getName());
|
||||
symbols.push_back({sym, strx});
|
||||
};
|
||||
|
||||
// Local symbols aren't in the SymbolTable, so we walk the list of object
|
||||
// files to gather them.
|
||||
for (InputFile *file : inputFiles) {
|
||||
|
@ -702,10 +707,8 @@ void SymtabSection::finalizeContents() {
|
|||
// TODO: when we implement -dead_strip, we should filter out symbols
|
||||
// that belong to dead sections.
|
||||
if (auto *defined = dyn_cast<Defined>(sym)) {
|
||||
if (!defined->isExternal()) {
|
||||
uint32_t strx = stringTableSection.addString(sym->getName());
|
||||
localSymbols.push_back({sym, strx});
|
||||
}
|
||||
if (!defined->isExternal())
|
||||
addSymbol(localSymbols, sym);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -713,19 +716,16 @@ void SymtabSection::finalizeContents() {
|
|||
|
||||
// __dyld_private is a local symbol too. It's linker-created and doesn't
|
||||
// exist in any object file.
|
||||
if (Defined* dyldPrivate = in.stubHelper->dyldPrivate) {
|
||||
uint32_t strx = stringTableSection.addString(dyldPrivate->getName());
|
||||
localSymbols.push_back({dyldPrivate, strx});
|
||||
}
|
||||
if (Defined* dyldPrivate = in.stubHelper->dyldPrivate)
|
||||
addSymbol(localSymbols, dyldPrivate);
|
||||
|
||||
for (Symbol *sym : symtab->getSymbols()) {
|
||||
uint32_t strx = stringTableSection.addString(sym->getName());
|
||||
if (auto *defined = dyn_cast<Defined>(sym)) {
|
||||
assert(defined->isExternal());
|
||||
externalSymbols.push_back({sym, strx});
|
||||
addSymbol(externalSymbols, sym);
|
||||
} else if (auto *dysym = dyn_cast<DylibSymbol>(sym)) {
|
||||
if (dysym->isReferenced())
|
||||
undefinedSymbols.push_back({sym, strx});
|
||||
addSymbol(undefinedSymbols, sym);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,17 +86,19 @@
|
|||
# CHECK-NEXT: iundefsym: 5
|
||||
# CHECK-NEXT: nundefsym: 2
|
||||
|
||||
## Verify that the first entry in the StringTable is a space.
|
||||
## Verify that the first entry in the StringTable is a space, and that
|
||||
## unreferenced symbols aren't emitted.
|
||||
# RUN: obj2yaml %t/test | FileCheck %s --check-prefix=YAML
|
||||
# YAML: StringTable:
|
||||
# YAML-NEXT: ' '
|
||||
# YAML-NOT: _unreferenced
|
||||
|
||||
#--- libfoo.s
|
||||
.globl _dynamic
|
||||
_dynamic:
|
||||
|
||||
#--- test.s
|
||||
.globl _main, _external, _external_weak
|
||||
.globl _main, _external, _external_weak, _unreferenced
|
||||
|
||||
.data
|
||||
_external:
|
||||
|
|
Loading…
Reference in New Issue