diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-12 20:21:39 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-12 20:21:39 +0000 |
commit | 34ac52d9377b104c83f80184f284199d68732f07 (patch) | |
tree | 90a9245e96c8cc8e429b785d6e13fef59f35c779 /lib | |
parent | 795740b591331a0caf342edc4d572ec348415b40 (diff) | |
download | external_llvm-34ac52d9377b104c83f80184f284199d68732f07.zip external_llvm-34ac52d9377b104c83f80184f284199d68732f07.tar.gz external_llvm-34ac52d9377b104c83f80184f284199d68732f07.tar.bz2 |
Change llvm-ar to use lib/Object.
This fixes two bugs is lib/Object that the use in llvm-ar found:
* In OS X created archives, the name can be padded with nulls. Strip them.
* In the constructor, remember the first non special member and use that in
begin_children. This makes sure we skip all special members, not just the
first one.
The change to llvm-ar itself consist of
* Using lib/Object for reading archives instead of ArchiveReader.cpp.
* Writing the modified archive directly, instead of creating an in memory
representation.
The old Archive library was way more general than what is needed, as can
be seen by the diffstat of this patch.
Having llvm-ar using lib/Object now opens the way for creating regular symbol
tables for both native objects and bitcode files so that we can use those
archives for LTO.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186197 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Object/Archive.cpp | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index 7579a9a..719d104 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -23,20 +23,6 @@ using namespace object; static const char *Magic = "!<arch>\n"; -static bool isInternalMember(const ArchiveMemberHeader &amh) { - static const char *const internals[] = { - "/", - "//" - }; - - StringRef name = amh.getName(); - for (std::size_t i = 0; i < sizeof(internals) / sizeof(*internals); ++i) { - if (name == internals[i]) - return true; - } - return false; -} - void Archive::anchor() { } StringRef ArchiveMemberHeader::getName() const { @@ -93,16 +79,13 @@ unsigned ArchiveMemberHeader::getGID() const { return Ret; } -static const ArchiveMemberHeader *toHeader(const char *base) { - return reinterpret_cast<const ArchiveMemberHeader *>(base); -} - Archive::Child::Child(const Archive *Parent, const char *Start) : Parent(Parent) { if (!Start) return; - const ArchiveMemberHeader *Header = toHeader(Start); + const ArchiveMemberHeader *Header = + reinterpret_cast<const ArchiveMemberHeader *>(Start); Data = StringRef(Start, sizeof(ArchiveMemberHeader) + Header->getSize()); // Setup StartOfFile and PaddingBytes. @@ -173,7 +156,8 @@ error_code Archive::Child::getName(StringRef &Result) const { uint64_t name_size; if (name.substr(3).rtrim(" ").getAsInteger(10, name_size)) llvm_unreachable("Long name length is not an ingeter"); - Result = Data.substr(sizeof(ArchiveMemberHeader), name_size); + Result = Data.substr(sizeof(ArchiveMemberHeader), name_size) + .rtrim(StringRef("\0", 1)); return object_error::success; } // It's a simple name. @@ -252,6 +236,8 @@ Archive::Archive(MemoryBuffer *source, error_code &ec) if (Name == "__.SYMDEF") { Format = K_BSD; SymbolTable = i; + ++i; + FirstRegular = i; ec = object_error::success; return; } @@ -262,8 +248,11 @@ Archive::Archive(MemoryBuffer *source, error_code &ec) ec = i->getName(Name); if (ec) return; - if (Name == StringRef("__.SYMDEF SORTED\0\0\0", 20)) + if (Name == "__.SYMDEF SORTED") { SymbolTable = i; + ++i; + } + FirstRegular = i; return; } @@ -281,12 +270,15 @@ Archive::Archive(MemoryBuffer *source, error_code &ec) if (Name == "//") { Format = K_GNU; StringTable = i; + ++i; + FirstRegular = i; ec = object_error::success; return; } if (Name[0] != '/') { Format = K_GNU; + FirstRegular = i; ec = object_error::success; return; } @@ -301,26 +293,31 @@ Archive::Archive(MemoryBuffer *source, error_code &ec) ++i; if (i == e) { + FirstRegular = i; ec = object_error::success; return; } Name = i->getRawName(); - if (Name == "//") + if (Name == "//") { StringTable = i; + ++i; + } + FirstRegular = i; ec = object_error::success; } -Archive::child_iterator Archive::begin_children(bool skip_internal) const { +Archive::child_iterator Archive::begin_children(bool SkipInternal) const { if (Data->getBufferSize() == 8) // empty archive. return end_children(); + + if (SkipInternal) + return FirstRegular; + const char *Loc = Data->getBufferStart() + strlen(Magic); Child c(this, Loc); - // Skip internals at the beginning of an archive. - if (skip_internal && isInternalMember(*toHeader(Loc))) - return c.getNext(); return c; } |