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

Commit 22bd70f

Browse files
committed
Archives require a symbol table on Solaris, even if empty.
On Solaris ld (and some other tools that use the underlying utility libraries, such as elfdump) chokes on an archive library that has no symbol table. The Solaris tools always create one, even if it's empty. That bug has been fixed in the latest development line, and can probably be backported to a supported release, but it would be nice if LLVM's archiver could emit the empty symbol table, too. Patch by Danek Duvall! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297773 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c67a9ef commit 22bd70f

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/Object/ArchiveWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind,
341341
if (isBSDLike(Kind))
342342
print32(Out, Kind, StringTable.size()); // byte count of the string table
343343
Out << StringTable;
344+
// If there are no symbols, emit an empty symbol table, to satisfy Solaris
345+
// tools, older versions of which expect a symbol table in a non-empty
346+
// archive, regardless of whether there are any symbols in it.
347+
if (StringTable.size() == 0)
348+
print32(Out, Kind, 0);
344349

345350
// ld64 requires the next member header to start at an offset that is
346351
// 4 bytes aligned.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_REL
6+
Machine: EM_X86_64
7+
...

test/Object/archive-format.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,15 @@ THIN-PATH-NEXT: /65 0 0 0 644 4 `
7878

7979
RUN: not llvm-ar --format=bsd rcT bad.a 0123456789abcde 0123456789abcdef 2>&1 | FileCheck --check-prefix=BSD-THIN %s
8080
BSD-THIN: Only the gnu format has a thin mode.
81+
82+
If an archive has an object with no symbols, the linker and some other
83+
tools on some versions of Solaris will abort operations if there is no
84+
symbol table. Create such an object, put it into an archive, and check to
85+
see that there is an empty symbol table.
86+
RUN: mkdir -p %t
87+
RUN: yaml2obj %S/Inputs/solaris-nosymbols.yaml > %t/foo.o
88+
RUN: llvm-ar rs %t/foo.a %t/foo.o
89+
RUN: cat -v %t/foo.a | FileCheck -strict-whitespace --check-prefix=SOLARIS %s
90+
SOLARIS: !<arch>
91+
SOLARIS-NEXT: / 0 0 0 0 8 `
92+
SOLARIS-NEXT: ^@^@^@^@^@^@^@^@foo.o/

0 commit comments

Comments
 (0)