llvm-ar: Darwin archive format fixes.

* Support writing the DARWIN64 symbol table format.

* In darwin archives, emit a symbol table whenever requested, even
  when there are no members, as the apple linker will abort if given
  an archive without a symbol table.

Added tests for same, and also simplified and moved the GNU 64-bit
symbol table test into archive-symtab.test.

llvm-svn: 344183
diff --git a/llvm/test/Object/archive-GNU64-write.test b/llvm/test/Object/archive-GNU64-write.test
deleted file mode 100644
index 0bfb7c8..0000000
--- a/llvm/test/Object/archive-GNU64-write.test
+++ /dev/null
@@ -1,40 +0,0 @@
-# REQUIRES: llvm-64-bits
-# REQUIRES: system-linux
-# REQUIRES: shell
-
-# RUN: yaml2obj %s > %t
-# RUN: dd if=%t of=%t bs=1 count=0 seek=1M
-# RUN: rm -f %t.lib
-# RUN: cp %t %t2
-# RUN: SYM64_THRESHOLD=19 llvm-ar cr %t.lib %t %t2 %p/Inputs/trivial-object-test.elf-x86-64
-# RUN: llvm-nm --print-armap %t.lib | FileCheck %s
-# RUN: grep SYM64 %t.lib
-
-# Delete temp files. They are too large.
-# RUN: rm -f %t %t2 %t.lib
-
-!ELF
-FileHeader:
-  Class:           ELFCLASS64
-  Data:            ELFDATA2LSB
-  Type:            ET_EXEC
-  Machine:         EM_X86_64
-Sections:
-  - Name:            .data
-    Type:            SHT_PROGBITS
-    Flags:           [ SHF_ALLOC ]
-    AddressAlign:    0x0000000000000001
-    Content:         "00"
-    Size:            32
-
-# CHECK:      Archive map
-# CHECK-NEXT: main in trivial-object-test.elf-x86-64
-
-# CHECK:    archive-GNU64-write.test.tmp:
-
-# CHECK:    archive-GNU64-write.test.tmp2:
-
-# CHECK:    trivial-object-test.elf-x86-64:
-# CHECK-NEXT:                     U SomeOtherFunction
-# CHECK-NEXT:    0000000000000000 T main
-# CHECK-NEXT:                     U puts
diff --git a/llvm/test/Object/archive-format.test b/llvm/test/Object/archive-format.test
index 219fc7f..b1ae411 100644
--- a/llvm/test/Object/archive-format.test
+++ b/llvm/test/Object/archive-format.test
@@ -38,7 +38,7 @@
 BSD-NEXT: 0123456789abcdefzed.
 
 RUN: rm -f %t.a
-RUN: llvm-ar --format=darwin rc %t.a 0123456789abcde 0123456789abcdef
+RUN: llvm-ar --format=darwin rcS %t.a 0123456789abcde 0123456789abcdef
 RUN: cat %t.a | FileCheck -strict-whitespace --check-prefix=DARWIN %s
 
 DARWIN:      !<arch>
diff --git a/llvm/test/Object/archive-symtab.test b/llvm/test/Object/archive-symtab.test
index 2979707..96f4813 100644
--- a/llvm/test/Object/archive-symtab.test
+++ b/llvm/test/Object/archive-symtab.test
@@ -2,6 +2,11 @@
 RUN: llvm-ar rcsU %t.a %p/Inputs/trivial-object-test.elf-x86-64 %p/Inputs/trivial-object-test2.elf-x86-64
 RUN: llvm-nm -M %t.a | FileCheck %s
 
+RUN: rm -f %t.a
+RUN: env SYM64_THRESHOLD=1 llvm-ar rcsU %t.a %p/Inputs/trivial-object-test.elf-x86-64 %p/Inputs/trivial-object-test2.elf-x86-64
+RUN: llvm-nm -M %t.a | FileCheck %s
+RUXX: grep SYM64 %t.a
+
 CHECK: Archive map
 CHECK-NEXT: main in trivial-object-test.elf-x86-64
 CHECK-NEXT: foo in trivial-object-test2.elf-x86-64
@@ -82,6 +87,11 @@
 RUN: llvm-ar --format=bsd rcsU %t.a %p/Inputs/trivial-object-test.macho-x86-64 %p/Inputs/trivial-object-test2.macho-x86-64
 RUN: llvm-nm -M %t.a | FileCheck --check-prefix=MACHO %s
 
+RUN: rm -f %t.a
+RUN: env SYM64_THRESHOLD=1 llvm-ar --format=darwin rcsU %t.a %p/Inputs/trivial-object-test.macho-x86-64 %p/Inputs/trivial-object-test2.macho-x86-64
+RUN: llvm-nm -M %t.a | FileCheck --check-prefix=MACHO %s
+RUN: grep '__\.SYMDEF_64' %t.a
+
 MACHO: Archive map
 MACHO-NEXT: _main in trivial-object-test.macho-x86-64
 MACHO-NEXT: _foo in trivial-object-test2.macho-x86-64
@@ -138,3 +148,21 @@
 RUN: FileCheck --check-prefix=GNU-SYMTAB-ALIGN %s < %t.a
 GNU-SYMTAB-ALIGN: !<arch>
 GNU-SYMTAB-ALIGN-NEXT: /               0           0     0     0       14        `
+
+
+** Test the behavior of an empty archive:
+
+No symbol table emitted for GNU archives
+RUN: rm -f %t.a
+RUN: llvm-ar rcs --format=gnu %t.a
+RUN: not grep -q '/               ' %t.a
+
+No symbol table for BSD archives
+RUN: rm -f %t.a
+RUN: llvm-ar rcs --format=bsd %t.a
+RUN: not grep -q '__\.SYMDEF' %t.a
+
+And we do emit a symbol table for DARWIN archives
+RUN: rm -f %t.a
+RUN: llvm-ar rcs --format=darwin %t.a
+RUN: grep -q '__\.SYMDEF' %t.a