[llvm] r242926 - Fix fetching the symbol table of a thin archive.
Rafael Espindola
rafael.espindola at gmail.com
Wed Jul 22 12:34:26 PDT 2015
Author: rafael
Date: Wed Jul 22 14:34:26 2015
New Revision: 242926
URL: http://llvm.org/viewvc/llvm-project?rev=242926&view=rev
Log:
Fix fetching the symbol table of a thin archive.
We were trying to read it as an external file.
Modified:
llvm/trunk/include/llvm/Object/Archive.h
llvm/trunk/lib/Object/Archive.cpp
llvm/trunk/test/Object/archive-symtab.test
Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=242926&r1=242925&r2=242926&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Wed Jul 22 14:34:26 2015
@@ -62,6 +62,8 @@ public:
return reinterpret_cast<const ArchiveMemberHeader *>(Data.data());
}
+ bool isThinMember() const;
+
public:
Child(const Archive *Parent, const char *Start);
Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=242926&r1=242925&r2=242926&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Wed Jul 22 14:34:26 2015
@@ -87,17 +87,17 @@ Archive::Child::Child(const Archive *Par
if (!Start)
return;
- const ArchiveMemberHeader *Header =
- reinterpret_cast<const ArchiveMemberHeader *>(Start);
uint64_t Size = sizeof(ArchiveMemberHeader);
- if (!Parent->IsThin || Header->getName() == "/" || Header->getName() == "//")
- Size += Header->getSize();
Data = StringRef(Start, Size);
+ if (!isThinMember()) {
+ Size += getRawSize();
+ Data = StringRef(Start, Size);
+ }
// Setup StartOfFile and PaddingBytes.
StartOfFile = sizeof(ArchiveMemberHeader);
// Don't include attached name.
- StringRef Name = Header->getName();
+ StringRef Name = getRawName();
if (Name.startswith("#1/")) {
uint64_t NameSize;
if (Name.substr(3).rtrim(" ").getAsInteger(10, NameSize))
@@ -116,8 +116,13 @@ uint64_t Archive::Child::getRawSize() co
return getHeader()->getSize();
}
+bool Archive::Child::isThinMember() const {
+ StringRef Name = getHeader()->getName();
+ return Parent->IsThin && Name != "/" && Name != "//";
+}
+
ErrorOr<StringRef> Archive::Child::getBuffer() const {
- if (!Parent->IsThin)
+ if (!isThinMember())
return StringRef(Data.data() + StartOfFile, getSize());
ErrorOr<StringRef> Name = getName();
if (std::error_code EC = Name.getError())
Modified: llvm/trunk/test/Object/archive-symtab.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/archive-symtab.test?rev=242926&r1=242925&r2=242926&view=diff
==============================================================================
--- llvm/trunk/test/Object/archive-symtab.test (original)
+++ llvm/trunk/test/Object/archive-symtab.test Wed Jul 22 14:34:26 2015
@@ -8,6 +8,17 @@ CHECK-NEXT: foo in trivial-object-test2.
CHECK-NEXT: main in trivial-object-test2.elf-x86-64
CHECK-NOT: bar
+
+RUN: rm -f %t.a
+RUN: llvm-ar rcT %t.a %p/Inputs/trivial-object-test.elf-x86-64 %p/Inputs/trivial-object-test2.elf-x86-64
+RUN: llvm-nm -M %t.a | FileCheck --check-prefix=THIN %s
+
+THIN: Archive map
+THIN-NEXT: main in {{.*}}/Inputs/trivial-object-test.elf-x86-64
+THIN-NEXT: foo in {{.*}}/Inputs/trivial-object-test2.elf-x86-64
+THIN-NEXT: main in {{.*}}/Inputs/trivial-object-test2.elf-x86-64
+
+
CHECK: trivial-object-test.elf-x86-64:
CHECK-NEXT: U SomeOtherFunction
CHECK-NEXT: 0000000000000000 T main
More information about the llvm-commits
mailing list