mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-23 22:23:00 +00:00
MachObjectWriter: optimize the string table for common suffices
This is a follow-up to r207670 (ELF) and r218636 (COFF). Differential Revision: http://reviews.llvm.org/D5622 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219126 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
+24
-43
@@ -525,15 +525,10 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) {
|
||||
}
|
||||
|
||||
/// ComputeSymbolTable - Compute the symbol table data
|
||||
///
|
||||
/// \param StringTable [out] - The string table data.
|
||||
/// \param StringIndexMap [out] - Map from symbol names to offsets in the
|
||||
/// string table.
|
||||
void MachObjectWriter::
|
||||
ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
|
||||
std::vector<MachSymbolData> &LocalSymbolData,
|
||||
std::vector<MachSymbolData> &ExternalSymbolData,
|
||||
std::vector<MachSymbolData> &UndefinedSymbolData) {
|
||||
void MachObjectWriter::ComputeSymbolTable(
|
||||
MCAssembler &Asm, std::vector<MachSymbolData> &LocalSymbolData,
|
||||
std::vector<MachSymbolData> &ExternalSymbolData,
|
||||
std::vector<MachSymbolData> &UndefinedSymbolData) {
|
||||
// Build section lookup table.
|
||||
DenseMap<const MCSection*, uint8_t> SectionIndexMap;
|
||||
unsigned Index = 1;
|
||||
@@ -542,37 +537,34 @@ ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
|
||||
SectionIndexMap[&it->getSection()] = Index;
|
||||
assert(Index <= 256 && "Too many sections!");
|
||||
|
||||
// Index 0 is always the empty string.
|
||||
StringMap<uint64_t> StringIndexMap;
|
||||
StringTable += '\x00';
|
||||
// Build the string table.
|
||||
for (MCSymbolData &SD : Asm.symbols()) {
|
||||
const MCSymbol &Symbol = SD.getSymbol();
|
||||
if (!Asm.isSymbolLinkerVisible(Symbol))
|
||||
continue;
|
||||
|
||||
// Build the symbol arrays and the string table, but only for non-local
|
||||
// symbols.
|
||||
StringTable.add(Symbol.getName());
|
||||
}
|
||||
StringTable.finalize(StringTableBuilder::MachO);
|
||||
|
||||
// Build the symbol arrays but only for non-local symbols.
|
||||
//
|
||||
// The particular order that we collect the symbols and create the string
|
||||
// table, then sort the symbols is chosen to match 'as'. Even though it
|
||||
// doesn't matter for correctness, this is important for letting us diff .o
|
||||
// files.
|
||||
// The particular order that we collect and then sort the symbols is chosen to
|
||||
// match 'as'. Even though it doesn't matter for correctness, this is
|
||||
// important for letting us diff .o files.
|
||||
for (MCSymbolData &SD : Asm.symbols()) {
|
||||
const MCSymbol &Symbol = SD.getSymbol();
|
||||
|
||||
// Ignore non-linker visible symbols.
|
||||
if (!Asm.isSymbolLinkerVisible(SD.getSymbol()))
|
||||
if (!Asm.isSymbolLinkerVisible(Symbol))
|
||||
continue;
|
||||
|
||||
if (!SD.isExternal() && !Symbol.isUndefined())
|
||||
continue;
|
||||
|
||||
uint64_t &Entry = StringIndexMap[Symbol.getName()];
|
||||
if (!Entry) {
|
||||
Entry = StringTable.size();
|
||||
StringTable += Symbol.getName();
|
||||
StringTable += '\x00';
|
||||
}
|
||||
|
||||
MachSymbolData MSD;
|
||||
MSD.SymbolData = &SD;
|
||||
MSD.StringIndex = Entry;
|
||||
MSD.StringIndex = StringTable.getOffset(Symbol.getName());
|
||||
|
||||
if (Symbol.isUndefined()) {
|
||||
MSD.SectionIndex = 0;
|
||||
@@ -592,22 +584,15 @@ ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
|
||||
const MCSymbol &Symbol = SD.getSymbol();
|
||||
|
||||
// Ignore non-linker visible symbols.
|
||||
if (!Asm.isSymbolLinkerVisible(SD.getSymbol()))
|
||||
if (!Asm.isSymbolLinkerVisible(Symbol))
|
||||
continue;
|
||||
|
||||
if (SD.isExternal() || Symbol.isUndefined())
|
||||
continue;
|
||||
|
||||
uint64_t &Entry = StringIndexMap[Symbol.getName()];
|
||||
if (!Entry) {
|
||||
Entry = StringTable.size();
|
||||
StringTable += Symbol.getName();
|
||||
StringTable += '\x00';
|
||||
}
|
||||
|
||||
MachSymbolData MSD;
|
||||
MSD.SymbolData = &SD;
|
||||
MSD.StringIndex = Entry;
|
||||
MSD.StringIndex = StringTable.getOffset(Symbol.getName());
|
||||
|
||||
if (Symbol.isAbsolute()) {
|
||||
MSD.SectionIndex = 0;
|
||||
@@ -631,10 +616,6 @@ ComputeSymbolTable(MCAssembler &Asm, SmallString<256> &StringTable,
|
||||
ExternalSymbolData[i].SymbolData->setIndex(Index++);
|
||||
for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
|
||||
UndefinedSymbolData[i].SymbolData->setIndex(Index++);
|
||||
|
||||
// The string table is padded to a multiple of 4.
|
||||
while (StringTable.size() % 4)
|
||||
StringTable += '\x00';
|
||||
}
|
||||
|
||||
void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm,
|
||||
@@ -683,7 +664,7 @@ void MachObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
|
||||
markAbsoluteVariableSymbols(Asm, Layout);
|
||||
|
||||
// Compute symbol table information and bind symbol indices.
|
||||
ComputeSymbolTable(Asm, StringTable, LocalSymbolData, ExternalSymbolData,
|
||||
ComputeSymbolTable(Asm, LocalSymbolData, ExternalSymbolData,
|
||||
UndefinedSymbolData);
|
||||
}
|
||||
|
||||
@@ -922,7 +903,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
sizeof(MachO::nlist_64) :
|
||||
sizeof(MachO::nlist));
|
||||
WriteSymtabLoadCommand(SymbolTableOffset, NumSymTabSymbols,
|
||||
StringTableOffset, StringTable.size());
|
||||
StringTableOffset, StringTable.data().size());
|
||||
|
||||
WriteDysymtabLoadCommand(FirstLocalSymbol, NumLocalSymbols,
|
||||
FirstExternalSymbol, NumExternalSymbols,
|
||||
@@ -1028,7 +1009,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
WriteNlist(UndefinedSymbolData[i], Layout);
|
||||
|
||||
// Write the string table.
|
||||
OS << StringTable.str();
|
||||
OS << StringTable.data();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user