[llvm] r241842 - llvm-ar: Pad the symbol table to 4 bytes.

Rafael Espindola rafael.espindola at gmail.com
Thu Jul 9 12:48:06 PDT 2015


Author: rafael
Date: Thu Jul  9 14:48:06 2015
New Revision: 241842

URL: http://llvm.org/viewvc/llvm-project?rev=241842&view=rev
Log:
llvm-ar: Pad the symbol table to 4 bytes.

It looks like ld64 requires it. With this we seem to be able to bootstrap using
llvm-ar+/usr/bin/true instead of ar+ranlib (currently on stage2).

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=241842&r1=241841&r2=241842&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ArchiveWriter.cpp (original)
+++ llvm/trunk/lib/Object/ArchiveWriter.cpp Thu Jul  9 14:48:06 2015
@@ -237,8 +237,11 @@ writeSymbolTable(raw_fd_ostream &Out, ob
     print32(Out, Kind, StringTable.size()); // byte count of the string table
   Out << StringTable;
 
-  if (Out.tell() % 2)
-    Out << '\0';
+  // ld64 requires the next member header to start at an offset that is
+  // 4 bytes aligned.
+  unsigned Pad = OffsetToAlignment(Out.tell(), 4);
+  while (Pad--)
+    Out.write(uint8_t(0));
 
   // Patch up the size of the symbol table now that we know how big it is.
   unsigned Pos = Out.tell();

Modified: llvm/trunk/test/Object/archive-symtab.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/archive-symtab.test?rev=241842&r1=241841&r2=241842&view=diff
==============================================================================
--- llvm/trunk/test/Object/archive-symtab.test (original)
+++ llvm/trunk/test/Object/archive-symtab.test Thu Jul  9 14:48:06 2015
@@ -87,3 +87,11 @@ MACHO: trivial-object-test2.macho-x86-64
 MACHO-NEXT: 0000000000000000 t _bar
 MACHO-NEXT: 0000000000000001 T _foo
 MACHO-NEXT: 0000000000000002 T _main
+
+Test that we pad the symbol table so that it ends in a multiple of 4 bytes:
+8 + 60 + 36 == 104
+RUN: rm -f %t.a
+RUN: llvm-ar --format=bsd rcs %t.a %p/Inputs/trivial-object-test.macho-x86-64
+RUN: FileCheck --check-prefix=MACHO-SYMTAB-ALIGN %s < %t.a
+MACHO-SYMTAB-ALIGN: !<arch>
+MACHO-SYMTAB-ALIGN-NEXT: #1/12           {{..........}}  0     0     0       36        `





More information about the llvm-commits mailing list