mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
Start adding thin archive support.
This is just sufficient for 'ar t' to work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224307 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c981753745
commit
96b7967f83
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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 *Parent, const char *Start)
|
||||
|
||||
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 *Parent, const char *Start)
|
||||
}
|
||||
}
|
||||
|
||||
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>> Archive::create(MemoryBufferRef Source) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
BIN
test/Object/Inputs/thin.a
Normal file
BIN
test/Object/Inputs/thin.a
Normal file
Binary file not shown.
@ -26,3 +26,11 @@ CHECK: rw-r--r-- 1002/102 8 2004-11-19 03:24:02.000000000 evenlen
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user