From 36969278468c29919360b47ac9bc6e9a1ddf684f Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 9 Jul 2015 15:13:41 +0000 Subject: [PATCH] Add a helper to printing BE of LE depending on the format. The gnu ar format uses BE numbers. The BSD one uses LE. Add a helper for one or the other. NFC for now, just removes some noise from the following patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241808 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/ArchiveWriter.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Object/ArchiveWriter.cpp b/lib/Object/ArchiveWriter.cpp index 84dc3d6309c..78fada64b64 100644 --- a/lib/Object/ArchiveWriter.cpp +++ b/lib/Object/ArchiveWriter.cpp @@ -91,8 +91,12 @@ static void printWithSpacePadding(raw_fd_ostream &OS, T Data, unsigned Size, } } -static void print32BE(raw_ostream &Out, uint32_t Val) { - support::endian::Writer(Out).write(Val); +static void print32(raw_ostream &Out, object::Archive::Kind Kind, + uint32_t Val) { + if (Kind == object::Archive::K_GNU) + support::endian::Writer(Out).write(Val); + else + support::endian::Writer(Out).write(Val); } static void printRestOfMemberHeader(raw_fd_ostream &Out, @@ -200,7 +204,7 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind, if (!StartOffset) { printGNUSmallMemberHeader(Out, "", sys::TimeValue::now(), 0, 0, 0, 0); StartOffset = Out.tell(); - print32BE(Out, 0); + print32(Out, Kind, 0); } for (const object::BasicSymbolRef &S : Obj.symbols()) { @@ -216,7 +220,7 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind, NameOS << '\0'; ++NumSyms; MemberOffsetRefs.push_back(MemberNum); - print32BE(Out, 0); + print32(Out, Kind, 0); } } Out << NameOS.str(); @@ -231,7 +235,7 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind, Out.seek(StartOffset - 12); printWithSpacePadding(Out, Pos - StartOffset, 10); Out.seek(StartOffset); - print32BE(Out, NumSyms); + print32(Out, Kind, NumSyms); Out.seek(Pos); return StartOffset + 4; } @@ -335,7 +339,7 @@ llvm::writeArchive(StringRef ArcName, if (MemberReferenceOffset) { Out.seek(MemberReferenceOffset); for (unsigned MemberNum : MemberOffsetRefs) - print32BE(Out, MemberOffset[MemberNum]); + print32(Out, Kind, MemberOffset[MemberNum]); } Output.keep(); -- 2.34.1