Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Archives require a symbol table on Solaris, even if empty. #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Object/ArchiveWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind,
if (Kind == object::Archive::K_BSD)
print32(Out, Kind, StringTable.size()); // byte count of the string table
Out << StringTable;
// If there are no symbols, emit an empty symbol table, to satisfy Solaris
// tools, older versions of which expect a symbol table in a non-empty
// archive, regardless of whether there are any symbols in it.
if (StringTable.size() == 0)
print32(Out, Kind, 0);

// ld64 requires the next member header to start at an offset that is
// 4 bytes aligned.
Expand Down
7 changes: 7 additions & 0 deletions test/Object/Inputs/solaris-nosymbols.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
...
12 changes: 12 additions & 0 deletions test/Object/archive-format.test
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ THIN-PATH-NEXT: /65 0 0 0 644 4 `

RUN: not llvm-ar --format=bsd rcT bad.a 0123456789abcde 0123456789abcdef 2>&1 | FileCheck --check-prefix=BSD-THIN %s
BSD-THIN: Only the gnu format has a thin mode.

If an archive has an object with no symbols, the linker and some other
tools on some versions of Solaris will abort operations if there is no
symbol table. Create such an object, put it into an archive, and check to
see that there is an empty symbol table.
RUN: mkdir -p %t
RUN: yaml2obj %S/Inputs/solaris-nosymbols.yaml > %t/foo.o
RUN: llvm-ar rs %t/foo.a %t/foo.o
RUN: cat -v %t/foo.a | FileCheck -strict-whitespace --check-prefix=SOLARIS %s
SOLARIS: !<arch>
SOLARIS-NEXT: / 0 0 0 0 8 `
SOLARIS-NEXT: ^@^@^@^@^@^@^@^@foo.o/