[llvm] r314010 - llvm-ar: align the first archive member consistently.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 22 11:36:00 PDT 2017
Author: rafael
Date: Fri Sep 22 11:36:00 2017
New Revision: 314010
URL: http://llvm.org/viewvc/llvm-project?rev=314010&view=rev
Log:
llvm-ar: align the first archive member consistently.
Before we were aligning the member after the symbol table to 4 but
other members to 8.
Modified:
llvm/trunk/lib/Object/ArchiveWriter.cpp
llvm/trunk/test/Object/archive-symtab.test
Modified: llvm/trunk/lib/Object/ArchiveWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ArchiveWriter.cpp?rev=314010&r1=314009&r2=314010&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ArchiveWriter.cpp (original)
+++ llvm/trunk/lib/Object/ArchiveWriter.cpp Fri Sep 22 11:36:00 2017
@@ -349,9 +349,11 @@ writeSymbolTable(raw_fd_ostream &Out, ob
if (StringTable.size() == 0)
print32(Out, Kind, 0);
- // ld64 requires the next member header to start at an offset that is
- // 4 bytes aligned.
- unsigned Alignment = isBSDLike(Kind) ? 4 : 2;
+ // 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.
+ // We do this for all bsd formats because it simplifies aligning members.
+ unsigned Alignment = isBSDLike(Kind) ? 8 : 2;
unsigned Pad = OffsetToAlignment(Out.tell(), Alignment);
while (Pad--)
Out.write(uint8_t(0));
Modified: llvm/trunk/test/Object/archive-symtab.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/archive-symtab.test?rev=314010&r1=314009&r2=314010&view=diff
==============================================================================
--- llvm/trunk/test/Object/archive-symtab.test (original)
+++ llvm/trunk/test/Object/archive-symtab.test Fri Sep 22 11:36:00 2017
@@ -115,7 +115,7 @@ COFF-SHORT-IMPORT-NEXT: _foo in coff-sho
COFF-SHORT-IMPORT-NEXT: __imp__bar in coff-short-import-data
COFF-SHORT-IMPORT-NOT: _bar in coff-short-import-data
-Test that we pad the symbol table so that it ends in a multiple of 4 bytes:
+Test that we pad the symbol table so that it ends in a multiple of 8 bytes:
8 + 60 + 36 == 104
RUN: rm -f %t.a
RUN: llvm-ar --format=bsd rcsU %t.a %p/Inputs/trivial-object-test.macho-x86-64
@@ -123,6 +123,14 @@ RUN: FileCheck --check-prefix=MACHO-SYMT
MACHO-SYMTAB-ALIGN: !<arch>
MACHO-SYMTAB-ALIGN-NEXT: #1/12 {{..........}} 0 0 0 36 `
+Test that we pad the symbol table so that it ends in a multiple of 8 bytes:
+8 + 60 + 52 == 120
+RUN: rm -f %t.a
+RUN: llvm-ar --format=bsd rcsD %t.a %p/Inputs/trivial-object-test.macho-x86-64 %p/Inputs/trivial-object-test.macho-x86-64
+RUN: FileCheck --check-prefix=MACHO-SYMTAB-ALIGN2 %s < %t.a
+MACHO-SYMTAB-ALIGN2: !<arch>
+MACHO-SYMTAB-ALIGN2-NEXT: #1/12 0 0 0 0 52 `
+
With a gnu symbol table we only align to two
8 + 60 + 14 = 82
RUN: rm -f %t.a
More information about the llvm-commits
mailing list