[Object/COFF] Fix Windows .lib name handling.
authorRui Ueyama <ruiu@google.com>
Mon, 3 Jun 2013 00:27:03 +0000 (00:27 +0000)
committerRui Ueyama <ruiu@google.com>
Mon, 3 Jun 2013 00:27:03 +0000 (00:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183091 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/Archive.cpp
test/Object/Inputs/coff_archive.lib [changed mode: 0755->0644]
test/Object/Inputs/coff_archive_short.lib [new file with mode: 0644]
test/Object/coff-archive-short.test [new file with mode: 0644]

index 0e13d0540fa60f6a265ab6bcbfb91a6cfac8a306..be359240626fef2dedf80dbe56b9839270ac4581 100644 (file)
@@ -132,8 +132,11 @@ Archive::Archive(MemoryBuffer *source, error_code &ec)
   // COFF archive format
   //  First member : /
   //  Second member : / (provides a directory of symbols)
-  //  Third member : // contains the string table, this is present even if the
-  //                    string table is empty
+  //  Third member : // (may exist, if it exists, contains the string table)
+  //  Note: Microsoft PE/COFF Spec 8.3 says that the third member is present
+  //  even if the string table is empty. However, lib.exe does not in fact
+  //  seem to create the third member if there's no member whose filename
+  //  exceeds 15 characters. So the third member is optional.
   if (name == "/") {
     SymbolTable = i;
     StringTable = e;
@@ -150,14 +153,17 @@ Archive::Archive(MemoryBuffer *source, error_code &ec)
       Format = K_GNU;
       StringTable = i;
       ++i;
-    } else  { 
+    } else {
       Format = K_COFF;
       if (i != e) {
         SymbolTable = i;
         ++i;
       }
       if (i != e) {
-        StringTable = i;
+        if ((ec = i->getName(name)))
+          return;
+        if (name == "//")
+          StringTable = i;
       }
     }
   } else if (name == "__.SYMDEF") {
old mode 100755 (executable)
new mode 100644 (file)
diff --git a/test/Object/Inputs/coff_archive_short.lib b/test/Object/Inputs/coff_archive_short.lib
new file mode 100644 (file)
index 0000000..41cb1c2
Binary files /dev/null and b/test/Object/Inputs/coff_archive_short.lib differ
diff --git a/test/Object/coff-archive-short.test b/test/Object/coff-archive-short.test
new file mode 100644 (file)
index 0000000..fa531b3
--- /dev/null
@@ -0,0 +1,26 @@
+#
+# Check if the index is appearing properly in the output file
+#
+# coff_archive_short.lib does not have member whose name is longer
+# than 15 characters, thus, unlike coff_archive.lib, it has no string
+# table as the third member.
+#
+RUN: llvm-nm --numeric-sort -s %p/Inputs/coff_archive_short.lib | FileCheck -check-prefix=CHECKIDX %s
+
+CHECKIDX: Archive map
+CHECKIDX: _shortfn1 in short1.obj
+CHECKIDX: _shortfn2 in short2.obj
+CHECKIDX: short1.obj:
+CHECKIDX: 00000000 N .debug$S
+CHECKIDX: 00000000 i .drectve
+CHECKIDX: 00000000 t .text
+CHECKIDX: 00000000 T _shortfn1
+CHECKIDX: 00000001 a @feat.00
+CHECKIDX: 00aa9d1b a @comp.id
+CHECKIDX: short2.obj:
+CHECKIDX: 00000000 N .debug$S
+CHECKIDX: 00000000 i .drectve
+CHECKIDX: 00000000 t .text
+CHECKIDX: 00000000 T _shortfn2
+CHECKIDX: 00000001 a @feat.00
+CHECKIDX: 00aa9d1b a @comp.id