[llvm] r297773 - Archives require a symbol table on Solaris, even if empty.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 14 12:57:13 PDT 2017


Author: rafael
Date: Tue Mar 14 14:57:13 2017
New Revision: 297773

URL: http://llvm.org/viewvc/llvm-project?rev=297773&view=rev
Log:
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!

Added:
    llvm/trunk/test/Object/Inputs/solaris-nosymbols.yaml
Modified:
    llvm/trunk/lib/Object/ArchiveWriter.cpp
    llvm/trunk/test/Object/archive-format.test

Modified: llvm/trunk/lib/Object/ArchiveWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ArchiveWriter.cpp?rev=297773&r1=297772&r2=297773&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ArchiveWriter.cpp (original)
+++ llvm/trunk/lib/Object/ArchiveWriter.cpp Tue Mar 14 14:57:13 2017
@@ -341,6 +341,11 @@ writeSymbolTable(raw_fd_ostream &Out, ob
   if (isBSDLike(Kind))
     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.

Added: llvm/trunk/test/Object/Inputs/solaris-nosymbols.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/solaris-nosymbols.yaml?rev=297773&view=auto
==============================================================================
--- llvm/trunk/test/Object/Inputs/solaris-nosymbols.yaml (added)
+++ llvm/trunk/test/Object/Inputs/solaris-nosymbols.yaml Tue Mar 14 14:57:13 2017
@@ -0,0 +1,7 @@
+--- !ELF
+FileHeader:      
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+...

Modified: llvm/trunk/test/Object/archive-format.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/archive-format.test?rev=297773&r1=297772&r2=297773&view=diff
==============================================================================
--- llvm/trunk/test/Object/archive-format.test (original)
+++ llvm/trunk/test/Object/archive-format.test Tue Mar 14 14:57:13 2017
@@ -78,3 +78,15 @@ THIN-PATH-NEXT: /65             0
 
 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/




More information about the llvm-commits mailing list