[llvm] r224307 - Start adding thin archive support.
Rafael Espindola
rafael.espindola at gmail.com
Mon Dec 15 17:43:42 PST 2014
Author: rafael
Date: Mon Dec 15 19:43:41 2014
New Revision: 224307
URL: http://llvm.org/viewvc/llvm-project?rev=224307&view=rev
Log:
Start adding thin archive support.
This is just sufficient for 'ar t' to work.
Added:
llvm/trunk/test/Object/Inputs/thin.a
Modified:
llvm/trunk/include/llvm/Object/Archive.h
llvm/trunk/lib/Object/Archive.cpp
llvm/trunk/test/Object/archive-toc.test
Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=224307&r1=224306&r2=224307&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Mon Dec 15 19:43:41 2014
@@ -84,7 +84,7 @@ public:
return getHeader()->getAccessMode();
}
/// \return the size of the archive member without the header or padding.
- uint64_t getSize() const { return Data.size() - StartOfFile; }
+ uint64_t getSize() const;
StringRef getBuffer() const {
return StringRef(Data.data() + StartOfFile, getSize());
@@ -173,9 +173,7 @@ public:
K_COFF
};
- Kind kind() const {
- return Format;
- }
+ Kind kind() const { return (Kind)Format; }
child_iterator child_begin(bool SkipInternal = true) const;
child_iterator child_end() const;
@@ -201,7 +199,8 @@ private:
child_iterator SymbolTable;
child_iterator StringTable;
child_iterator FirstRegular;
- Kind Format;
+ unsigned Format : 2;
+ unsigned IsThin : 1;
};
}
Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=224307&r1=224306&r2=224307&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Mon Dec 15 19:43:41 2014
@@ -22,6 +22,7 @@ using namespace llvm;
using namespace object;
static const char *const Magic = "!<arch>\n";
+static const char *const ThinMagic = "!<thin>\n";
void Archive::anchor() { }
@@ -86,7 +87,10 @@ Archive::Child::Child(const Archive *Par
const ArchiveMemberHeader *Header =
reinterpret_cast<const ArchiveMemberHeader *>(Start);
- Data = StringRef(Start, sizeof(ArchiveMemberHeader) + Header->getSize());
+ uint64_t Size = sizeof(ArchiveMemberHeader);
+ if (!Parent->IsThin || Header->getName() == "/" || Header->getName() == "//")
+ Size += Header->getSize();
+ Data = StringRef(Start, Size);
// Setup StartOfFile and PaddingBytes.
StartOfFile = sizeof(ArchiveMemberHeader);
@@ -100,6 +104,12 @@ Archive::Child::Child(const Archive *Par
}
}
+uint64_t Archive::Child::getSize() const {
+ if (Parent->IsThin)
+ return getHeader()->getSize();
+ return Data.size() - StartOfFile;
+}
+
Archive::Child Archive::Child::getNext() const {
size_t SpaceToSkip = Data.size();
// If it's odd, add 1 to make it even.
@@ -186,9 +196,13 @@ ErrorOr<std::unique_ptr<Archive>> Archiv
Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
: Binary(Binary::ID_Archive, Source), SymbolTable(child_end()) {
+ StringRef Buffer = Data.getBuffer();
// Check for sufficient magic.
- if (Data.getBufferSize() < 8 ||
- StringRef(Data.getBufferStart(), 8) != Magic) {
+ if (Buffer.startswith(ThinMagic)) {
+ IsThin = true;
+ } else if (Buffer.startswith(Magic)) {
+ IsThin = false;
+ } else {
ec = object_error::invalid_file_type;
return;
}
Added: llvm/trunk/test/Object/Inputs/thin.a
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/thin.a?rev=224307&view=auto
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/thin.a (added) and llvm/trunk/test/Object/Inputs/thin.a Mon Dec 15 19:43:41 2014 differ
Modified: llvm/trunk/test/Object/archive-toc.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/archive-toc.test?rev=224307&r1=224306&r2=224307&view=diff
==============================================================================
--- llvm/trunk/test/Object/archive-toc.test (original)
+++ llvm/trunk/test/Object/archive-toc.test Mon Dec 15 19:43:41 2014
@@ -26,3 +26,11 @@ CHECK: rw-r--r-- 1002/102 8 20
CHECK-NEXT: rw-r--r-- 1002/102 7 2004-11-19 03:24:02.000000000 oddlen
CHECK-NEXT: rwxr-xr-x 1002/102 1465 2004-11-19 03:24:02.000000000 very_long_bytecode_file_name.bc
CHECK-NEXT: rw-r--r-- 1002/102 2280 2004-11-19 03:24:02.000000000 IsNAN.o
+
+Test reading a thin archive created by gnu ar
+RUN: env TZ=GMT llvm-ar tv %p/Inputs/thin.a | FileCheck %s --check-prefix=THIN -strict-whitespace
+
+THIN: rw-r--r-- 1000/1000 8 2014-12-16 00:56:27.000000000 evenlen
+THIN-NEXT: rw-r--r-- 1000/1000 7 2014-12-16 00:56:27.000000000 oddlen
+THIN-NEXT: rwxr-xr-x 1000/1000 1465 2014-12-16 00:56:27.000000000 very_long_bytecode_file_name.bc
+THIN-NEXT: rw-r--r-- 1000/1000 2280 2014-12-16 00:56:27.000000000 IsNAN.o
More information about the llvm-commits
mailing list