Object: Add Archive::getNumberOfSymbols().
authorRui Ueyama <ruiu@google.com>
Tue, 26 May 2015 16:20:40 +0000 (16:20 +0000)
committerRui Ueyama <ruiu@google.com>
Tue, 26 May 2015 16:20:40 +0000 (16:20 +0000)
Add a function that returns number of symbols in archive headers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238213 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/Archive.h
lib/Object/Archive.cpp

index d40dc9db9f5bfb5795efeb64ef70ece6443eefe0..8da6919a46555cf515e8ab379c87f2bf47fcf9a1 100644 (file)
@@ -207,6 +207,7 @@ public:
 
   bool hasSymbolTable() const;
   child_iterator getSymbolTableChild() const { return SymbolTable; }
+  uint32_t getNumberOfSymbols() const;
 
 private:
   child_iterator SymbolTable;
index 7d43daaf0f4b890e1152d28a7a099ce58a024568..fb91eed2909745170830a6ed461a14d073cff235 100644 (file)
@@ -487,22 +487,21 @@ Archive::symbol_iterator Archive::symbol_begin() const {
 Archive::symbol_iterator Archive::symbol_end() const {
   if (!hasSymbolTable())
     return symbol_iterator(Symbol(this, 0, 0));
+  return symbol_iterator(Symbol(this, getNumberOfSymbols(), 0));
+}
 
+uint32_t Archive::getNumberOfSymbols() const {
   const char *buf = SymbolTable->getBuffer().begin();
-  uint32_t symbol_count = 0;
-  if (kind() == K_GNU) {
-    symbol_count = read32be(buf);
-  } else if (kind() == K_MIPS64) {
-    symbol_count = read64be(buf);
-  } else if (kind() == K_BSD) {
-    symbol_count = read32le(buf) / 8;
-  } else {
-    uint32_t member_count = 0;
-    member_count = read32le(buf);
-    buf += 4 + (member_count * 4); // Skip offsets.
-    symbol_count = read32le(buf);
-  }
-  return symbol_iterator(Symbol(this, symbol_count, 0));
+  if (kind() == K_GNU)
+    return read32be(buf);
+  if (kind() == K_MIPS64)
+    return read64be(buf);
+  if (kind() == K_BSD)
+    return read32le(buf) / 8;
+  uint32_t member_count = 0;
+  member_count = read32le(buf);
+  buf += 4 + (member_count * 4); // Skip offsets.
+  return read32le(buf);
 }
 
 Archive::child_iterator Archive::findSym(StringRef name) const {