diff options
| -rw-r--r-- | llvm/lib/Object/ArchiveWriter.cpp | 7 | ||||
| -rw-r--r-- | llvm/test/Object/archive-symtab.test | 8 |
2 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp index c485b34a081..1148c847549 100644 --- a/llvm/lib/Object/ArchiveWriter.cpp +++ b/llvm/lib/Object/ArchiveWriter.cpp @@ -237,8 +237,11 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind, 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(); diff --git a/llvm/test/Object/archive-symtab.test b/llvm/test/Object/archive-symtab.test index 5de2f2b5e1d..5f648ebc109 100644 --- a/llvm/test/Object/archive-symtab.test +++ b/llvm/test/Object/archive-symtab.test @@ -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 ` |

