[llvm] r294615 - Object: pad out BSD archive members to 8-bytes

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 12:53:53 PST 2017


Since I got no reply in over a week I fixed the regression myself:
r295765.

Cheers,
Rafael

Rafael Avila de Espindola <rafael.espindola at gmail.com> writes:

> Ping. Are you working on this? I really don't think we should have
> llvm-ar modifying the files stored in .a in cases it doesn't have to
> work around a ld64 bug.
>
> Cheers,
> Rafael
>
> Rafael Avila de Espindola <rafael.espindola at gmail.com> writes:
>
>> I am pretty sure this is working around a bug in ld64.
>>
>> We were already aligning the objects themselves. There is no point in
>> requiring the member header to be aligned.
>>
>> Also, this has the *very* bad property that the file you put in the .a
>> is not the file you get out: it might have '\n' added to the end.
>>
>> If we absolutely must do this, we should add a new archive format
>> (K_APPLE?). We already check if we are adding macho files to the
>> archive, so we could use that.
>>
>> Cheers,
>> Rafael
>>
>>
>> Saleem Abdulrasool via llvm-commits <llvm-commits at lists.llvm.org>
>> writes:
>>
>>> Author: compnerd
>>> Date: Thu Feb  9 13:29:35 2017
>>> New Revision: 294615
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=294615&view=rev
>>> Log:
>>> Object: pad out BSD archive members to 8-bytes
>>>
>>> ld64 requires its archive members to be 8-byte aligned for 64-bit
>>> content and 4-byte aligned for 32-bit content.  Opt for the larger
>>> alignment requirement.  This ensures that ld64 can consume archives
>>> generated by llvm-ar.
>>>
>>> Thanks to Kevin Enderby for the hint about the ld64/cctools behaviours!
>>>
>>> Resolves PR28361!
>>>
>>> Modified:
>>>     llvm/trunk/lib/Object/ArchiveWriter.cpp
>>>     llvm/trunk/test/Object/archive-format.test
>>>
>>> Modified: llvm/trunk/lib/Object/ArchiveWriter.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ArchiveWriter.cpp?rev=294615&r1=294614&r2=294615&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/lib/Object/ArchiveWriter.cpp (original)
>>> +++ llvm/trunk/lib/Object/ArchiveWriter.cpp Thu Feb  9 13:29:35 2017
>>> @@ -395,18 +395,28 @@ llvm::writeArchive(StringRef ArcName,
>>>    std::vector<unsigned> MemberOffset;
>>>    for (const NewArchiveMember &M : NewMembers) {
>>>      MemoryBufferRef File = M.Buf->getMemBufferRef();
>>> +    unsigned Padding = 0;
>>>  
>>>      unsigned Pos = Out.tell();
>>>      MemberOffset.push_back(Pos);
>>>  
>>> +    // ld64 expects the members to be 8-byte aligned for 64-bit content and at
>>> +    // least 4-byte aligned for 32-bit content.  Opt for the larger encoding
>>> +    // uniformly.  This matches the behaviour with cctools and ensures that ld64
>>> +    // is happy with archives that we generate.
>>> +    if (Kind == object::Archive::K_BSD)
>>> +      Padding = OffsetToAlignment(M.Buf->getBufferSize(), 8);
>>> +
>>>      printMemberHeader(Out, Kind, Thin,
>>>                        sys::path::filename(M.Buf->getBufferIdentifier()),
>>>                        StringMapIndexIter, M.ModTime, M.UID, M.GID, M.Perms,
>>> -                      M.Buf->getBufferSize());
>>> +                      M.Buf->getBufferSize() + Padding);
>>>  
>>>      if (!Thin)
>>>        Out << File.getBuffer();
>>>  
>>> +    while (Padding--)
>>> +      Out << '\n';
>>>      if (Out.tell() % 2)
>>>        Out << '\n';
>>>    }
>>>
>>> Modified: llvm/trunk/test/Object/archive-format.test
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/archive-format.test?rev=294615&r1=294614&r2=294615&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/test/Object/archive-format.test (original)
>>> +++ llvm/trunk/test/Object/archive-format.test Thu Feb  9 13:29:35 2017
>>> @@ -32,10 +32,12 @@ RUN: llvm-ar --format=bsd rc %t.a 012345
>>>  RUN: cat %t.a | FileCheck -strict-whitespace --check-prefix=BSD %s
>>>  
>>>  BSD:      !<arch>
>>> -BSD-NEXT: #1/20           0           0     0     644     24        `
>>> -BSD-NEXT: 0123456789abcde{{.....}}bar.
>>> -BSD-SAME: #1/16           0           0     0     644     20        `
>>> -BSD-NEXT: 0123456789abcdefzed.
>>> +BSD-NEXT: #1/20           0           0     0     644     28        `
>>> +Each [[:space:]] matches a newline.  We explicitly match 3 newlines, as the
>>> +fourth newline is implicitly consumed by FileCheck and cannot be matched.
>>> +BSD-NEXT: 0123456789abcde{{.....}}bar.{{[[:space:]][[:space:]][[:space:]]}}
>>> +BSD-NEXT: #1/20           0           0     0     644     28        `
>>> +BSD-NEXT: 0123456789abcdef{{....}}zed.
>>>  
>>>  RUN: rm -f test.a
>>>  RUN: llvm-ar --format=gnu rcT test.a 0123456789abcde 0123456789abcdef
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list