Skip to content

Commit 670dac9

Browse files
alexcrichtonTimNN
authored andcommitted
Merge pull request rust-lang#65 from dhduvall/rust-llvm-2016-10-29
Archives require a symbol table on Solaris, even if empty.
2 parents 20acd70 + 0a1298b commit 670dac9

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/Object/ArchiveWriter.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind,
320320
if (Kind == object::Archive::K_BSD)
321321
print32(Out, Kind, StringTable.size()); // byte count of the string table
322322
Out << StringTable;
323+
// If there are no symbols, emit an empty symbol table, to satisfy Solaris
324+
// tools, older versions of which expect a symbol table in a non-empty
325+
// archive, regardless of whether there are any symbols in it.
326+
if (StringTable.size() == 0)
327+
print32(Out, Kind, 0);
323328

324329
// ld64 requires the next member header to start at an offset that is
325330
// 4 bytes aligned.
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

+12
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,15 @@ THIN-PATH-NEXT: /65 0 0 0 644 4 `
6565

6666
RUN: not llvm-ar --format=bsd rcT bad.a 0123456789abcde 0123456789abcdef 2>&1 | FileCheck --check-prefix=BSD-THIN %s
6767
BSD-THIN: Only the gnu format has a thin mode.
68+
69+
If an archive has an object with no symbols, the linker and some other
70+
tools on some versions of Solaris will abort operations if there is no
71+
symbol table. Create such an object, put it into an archive, and check to
72+
see that there is an empty symbol table.
73+
RUN: mkdir -p %t
74+
RUN: yaml2obj %S/Inputs/solaris-nosymbols.yaml > %t/foo.o
75+
RUN: llvm-ar rs %t/foo.a %t/foo.o
76+
RUN: cat -v %t/foo.a | FileCheck -strict-whitespace --check-prefix=SOLARIS %s
77+
SOLARIS: !<arch>
78+
SOLARIS-NEXT: / 0 0 0 0 8 `
79+
SOLARIS-NEXT: ^@^@^@^@^@^@^@^@foo.o/

0 commit comments

Comments
 (0)