From 23a76be5adcaa768ba538f8a4514a7afccf61988 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 21 Feb 2017 20:40:54 +0000 Subject: Don't modify archive members unless really needed. For whatever reason ld64 requires that member headers (not the member themselves) should be aligned. The only way to do that is to edit the previous member so that it ends at an aligned boundary. Since modifying data put in an archive is an undesirable property, llvm-ar should only do it when it is absolutely necessary. llvm-svn: 295765 --- llvm/tools/llvm-ar/llvm-ar.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'llvm/tools/llvm-ar/llvm-ar.cpp') diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index b99a396da62..6d7c1c1c546 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -87,13 +87,14 @@ static cl::opt MRI("M", cl::desc("")); static cl::opt Plugin("plugin", cl::desc("plugin (ignored for compatibility")); namespace { -enum Format { Default, GNU, BSD }; +enum Format { Default, GNU, BSD, DARWIN }; } static cl::opt FormatOpt("format", cl::desc("Archive format to create"), cl::values(clEnumValN(Default, "default", "default"), clEnumValN(GNU, "gnu", "gnu"), + clEnumValN(DARWIN, "darwin", "darwin"), clEnumValN(BSD, "bsd", "bsd"))); static std::string Options; @@ -623,8 +624,9 @@ computeNewArchiveMembers(ArchiveOperation Operation, } static object::Archive::Kind getDefaultForHost() { - return Triple(sys::getProcessTriple()).isOSDarwin() ? object::Archive::K_BSD - : object::Archive::K_GNU; + return Triple(sys::getProcessTriple()).isOSDarwin() + ? object::Archive::K_DARWIN + : object::Archive::K_GNU; } static object::Archive::Kind getKindFromMember(const NewArchiveMember &Member) { @@ -633,7 +635,7 @@ static object::Archive::Kind getKindFromMember(const NewArchiveMember &Member) { if (OptionalObject) return isa(**OptionalObject) - ? object::Archive::K_BSD + ? object::Archive::K_DARWIN : object::Archive::K_GNU; // squelch the error in case we had a non-object file @@ -672,6 +674,11 @@ performWriteOperation(ArchiveOperation Operation, fail("Only the gnu format has a thin mode"); Kind = object::Archive::K_BSD; break; + case DARWIN: + if (Thin) + fail("Only the gnu format has a thin mode"); + Kind = object::Archive::K_DARWIN; + break; } std::pair Result = -- cgit v1.2.3