llvm.org GIT mirror llvm / 2825a23
Simplify handling of archive Symbol tables. We only need to store a StringRef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251748 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
3 changed file(s) with 18 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
207207 child_iterator findSym(StringRef name) const;
208208
209209 bool hasSymbolTable() const;
210 child_iterator getSymbolTableChild() const { return SymbolTable; }
211 StringRef getSymbolTable() const {
212 // We know that the symbol table is not an external file,
213 // so we just assert there is no error.
214 return *SymbolTable->getBuffer();
215 }
210 StringRef getSymbolTable() const { return SymbolTable; }
216211 uint32_t getNumberOfSymbols() const;
217212
218213 private:
219 child_iterator SymbolTable;
214 StringRef SymbolTable;
220215 StringRef StringTable;
221216 child_iterator FirstRegular;
222217 unsigned Format : 2;
232232 }
233233
234234 Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
235 : Binary(Binary::ID_Archive, Source), SymbolTable(child_end()),
236 FirstRegular(child_end()) {
235 : Binary(Binary::ID_Archive, Source), FirstRegular(child_end()) {
237236 StringRef Buffer = Data.getBuffer();
238237 // Check for sufficient magic.
239238 if (Buffer.startswith(ThinMagic)) {
277276
278277 if (Name == "__.SYMDEF") {
279278 Format = K_BSD;
280 SymbolTable = i;
279 // We know that the symbol table is not an external file, so we just assert
280 // there is no error.
281 SymbolTable = *i->getBuffer();
281282 ++i;
282283 FirstRegular = i;
283284 ec = std::error_code();
293294 return;
294295 Name = NameOrErr.get();
295296 if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
296 SymbolTable = i;
297 // We know that the symbol table is not an external file, so we just
298 // assert there is no error.
299 SymbolTable = *i->getBuffer();
297300 ++i;
298301 }
299302 FirstRegular = i;
307310
308311 bool has64SymTable = false;
309312 if (Name == "/" || Name == "/SYM64/") {
310 SymbolTable = i;
313 // We know that the symbol table is not an external file, so we just assert
314 // there is no error.
315 SymbolTable = *i->getBuffer();
311316 if (Name == "/SYM64/")
312317 has64SymTable = true;
313318
343348 }
344349
345350 Format = K_COFF;
346 SymbolTable = i;
351 // We know that the symbol table is not an external file, so we just assert
352 // there is no error.
353 SymbolTable = *i->getBuffer();
347354
348355 ++i;
349356 if (i == e) {
550557 return child_end();
551558 }
552559
553 bool Archive::hasSymbolTable() const {
554 return SymbolTable != child_end();
555 }
560 bool Archive::hasSymbolTable() const { return !SymbolTable.empty(); }
14511451 }
14521452
14531453 static void printArchiveHeaders(Archive *A, bool verbose, bool print_offset) {
1454 if (A->hasSymbolTable()) {
1455 Archive::child_iterator S = A->getSymbolTableChild();
1456 Archive::Child C = *S;
1457 printArchiveChild(C, verbose, print_offset);
1458 }
1459 for (Archive::child_iterator I = A->child_begin(), E = A->child_end(); I != E;
1460 ++I) {
1454 for (Archive::child_iterator I = A->child_begin(false), E = A->child_end();
1455 I != E; ++I) {
14611456 Archive::Child C = *I;
14621457 printArchiveChild(C, verbose, print_offset);
14631458 }