From: Rafael Espindola Date: Thu, 9 Jul 2015 14:54:12 +0000 (+0000) Subject: Extract printBSDMemberHeader. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=56240eaf733a5df404738f317c19b2d9b79da133;p=oota-llvm.git Extract printBSDMemberHeader. It will get another use in the following patch. Also rename the other helper to printGNUSmallMemberHeader for consistency. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241805 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Object/ArchiveWriter.cpp b/lib/Object/ArchiveWriter.cpp index b904a1ec877..84dc3d6309c 100644 --- a/lib/Object/ArchiveWriter.cpp +++ b/lib/Object/ArchiveWriter.cpp @@ -107,37 +107,40 @@ static void printRestOfMemberHeader(raw_fd_ostream &Out, Out << "`\n"; } -static void printMemberHeader(raw_fd_ostream &Out, StringRef Name, - const sys::TimeValue &ModTime, unsigned UID, - unsigned GID, unsigned Perms, unsigned Size) { +static void printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name, + const sys::TimeValue &ModTime, + unsigned UID, unsigned GID, + unsigned Perms, unsigned Size) { printWithSpacePadding(Out, Twine(Name) + "/", 16); printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, Size); } +static void printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name, + const sys::TimeValue &ModTime, unsigned UID, + unsigned GID, unsigned Perms, unsigned Size) { + uint64_t PosAfterHeader = Out.tell() + 60 + Name.size(); + // Pad so that even 64 bit object files are aligned. + unsigned Pad = OffsetToAlignment(PosAfterHeader, 8); + unsigned NameWithPadding = Name.size() + Pad; + printWithSpacePadding(Out, Twine("#1/") + Twine(NameWithPadding), 16); + printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, + NameWithPadding + Size); + Out << Name; + assert(PosAfterHeader == Out.tell()); + while (Pad--) + Out.write(uint8_t(0)); +} + static void printMemberHeader(raw_fd_ostream &Out, object::Archive::Kind Kind, StringRef Name, std::vector::iterator &StringMapIndexIter, const sys::TimeValue &ModTime, unsigned UID, unsigned GID, unsigned Perms, unsigned Size) { - if (Kind == object::Archive::K_BSD) { - uint64_t PosAfterHeader = Out.tell() + 60 + Name.size(); - // Pad so that even 64 bit object files are aligned. - unsigned Pad = OffsetToAlignment(PosAfterHeader, 8); - unsigned NameWithPadding = Name.size() + Pad; - printWithSpacePadding(Out, Twine("#1/") + Twine(NameWithPadding), 16); - printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, - NameWithPadding + Size); - Out << Name; - assert(PosAfterHeader == Out.tell()); - while (Pad--) - Out.write(uint8_t(0)); - return; - } - if (Name.size() < 16) { - printMemberHeader(Out, Name, ModTime, UID, GID, Perms, Size); - return; - } + if (Kind == object::Archive::K_BSD) + return printBSDMemberHeader(Out, Name, ModTime, UID, GID, Perms, Size); + if (Name.size() < 16) + return printGNUSmallMemberHeader(Out, Name, ModTime, UID, GID, Perms, Size); Out << '/'; printWithSpacePadding(Out, *StringMapIndexIter++, 15); printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, Size); @@ -195,7 +198,7 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind, object::SymbolicFile &Obj = *ObjOrErr.get(); if (!StartOffset) { - printMemberHeader(Out, "", sys::TimeValue::now(), 0, 0, 0, 0); + printGNUSmallMemberHeader(Out, "", sys::TimeValue::now(), 0, 0, 0, 0); StartOffset = Out.tell(); print32BE(Out, 0); }