Simplify handling of archive Symbol tables.

We only need to store a StringRef.

llvm-svn: 251748
This commit is contained in:
Rafael Espindola 2015-10-31 21:03:29 +00:00
parent 7f253aa63c
commit 4a782fbfe6
3 changed files with 18 additions and 23 deletions

View File

@ -208,16 +208,11 @@ public:
child_iterator findSym(StringRef name) const;
bool hasSymbolTable() const;
child_iterator getSymbolTableChild() const { return SymbolTable; }
StringRef getSymbolTable() const {
// We know that the symbol table is not an external file,
// so we just assert there is no error.
return *SymbolTable->getBuffer();
}
StringRef getSymbolTable() const { return SymbolTable; }
uint32_t getNumberOfSymbols() const;
private:
child_iterator SymbolTable;
StringRef SymbolTable;
StringRef StringTable;
child_iterator FirstRegular;
unsigned Format : 2;

View File

@ -233,8 +233,7 @@ ErrorOr<std::unique_ptr<Archive>> Archive::create(MemoryBufferRef Source) {
}
Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
: Binary(Binary::ID_Archive, Source), SymbolTable(child_end()),
FirstRegular(child_end()) {
: Binary(Binary::ID_Archive, Source), FirstRegular(child_end()) {
StringRef Buffer = Data.getBuffer();
// Check for sufficient magic.
if (Buffer.startswith(ThinMagic)) {
@ -278,7 +277,9 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
if (Name == "__.SYMDEF") {
Format = K_BSD;
SymbolTable = i;
// We know that the symbol table is not an external file, so we just assert
// there is no error.
SymbolTable = *i->getBuffer();
++i;
FirstRegular = i;
ec = std::error_code();
@ -294,7 +295,9 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
return;
Name = NameOrErr.get();
if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
SymbolTable = i;
// We know that the symbol table is not an external file, so we just
// assert there is no error.
SymbolTable = *i->getBuffer();
++i;
}
FirstRegular = i;
@ -308,7 +311,9 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
bool has64SymTable = false;
if (Name == "/" || Name == "/SYM64/") {
SymbolTable = i;
// We know that the symbol table is not an external file, so we just assert
// there is no error.
SymbolTable = *i->getBuffer();
if (Name == "/SYM64/")
has64SymTable = true;
@ -344,7 +349,9 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
}
Format = K_COFF;
SymbolTable = i;
// We know that the symbol table is not an external file, so we just assert
// there is no error.
SymbolTable = *i->getBuffer();
++i;
if (i == e) {
@ -551,6 +558,4 @@ Archive::child_iterator Archive::findSym(StringRef name) const {
return child_end();
}
bool Archive::hasSymbolTable() const {
return SymbolTable != child_end();
}
bool Archive::hasSymbolTable() const { return !SymbolTable.empty(); }

View File

@ -1452,13 +1452,8 @@ static void printArchiveChild(Archive::Child &C, bool verbose,
}
static void printArchiveHeaders(Archive *A, bool verbose, bool print_offset) {
if (A->hasSymbolTable()) {
Archive::child_iterator S = A->getSymbolTableChild();
Archive::Child C = *S;
printArchiveChild(C, verbose, print_offset);
}
for (Archive::child_iterator I = A->child_begin(), E = A->child_end(); I != E;
++I) {
for (Archive::child_iterator I = A->child_begin(false), E = A->child_end();
I != E; ++I) {
Archive::Child C = *I;
printArchiveChild(C, verbose, print_offset);
}