From f4d0a8c13f7fdd8f87747067dc17af1cae03b118 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 3 Jun 2013 00:27:03 +0000 Subject: [PATCH] [Object/COFF] Fix Windows .lib name handling. llvm-svn: 183091 --- llvm/lib/Object/Archive.cpp | 14 +++++++--- llvm/test/Object/Inputs/coff_archive.lib | Bin .../test/Object/Inputs/coff_archive_short.lib | Bin 0 -> 1336 bytes llvm/test/Object/coff-archive-short.test | 26 ++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) mode change 100755 => 100644 llvm/test/Object/Inputs/coff_archive.lib create mode 100644 llvm/test/Object/Inputs/coff_archive_short.lib create mode 100644 llvm/test/Object/coff-archive-short.test diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp index 0e13d0540fa6..be359240626f 100644 --- a/llvm/lib/Object/Archive.cpp +++ b/llvm/lib/Object/Archive.cpp @@ -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") { diff --git a/llvm/test/Object/Inputs/coff_archive.lib b/llvm/test/Object/Inputs/coff_archive.lib old mode 100755 new mode 100644 diff --git a/llvm/test/Object/Inputs/coff_archive_short.lib b/llvm/test/Object/Inputs/coff_archive_short.lib new file mode 100644 index 0000000000000000000000000000000000000000..41cb1c25d1ef8fb1c1561a2a9f539467fcdd7356 GIT binary patch literal 1336 zcmd^7!A`XB{QhcM*ONgn z@4l*{=(n{JnOO=fqPW`5fS8CacxIKU*t z@RQlT5bQ;2xlYHaGqO-wB&BmkTlAW?8zk?v&gq%$a*e&4_vGWjQ`SOGrYE!gdl(G( zZ_C#0BPJ^ff2_xZz2&SZaCf5!`^slP6u7fdggwRaz%$%cj+fr&otN>ITf!j%!ReXC YEU*iP25A3&ZnVG5&Cs@gIX4=70l~uZFaQ7m literal 0 HcmV?d00001 diff --git a/llvm/test/Object/coff-archive-short.test b/llvm/test/Object/coff-archive-short.test new file mode 100644 index 000000000000..fa531b3b6314 --- /dev/null +++ b/llvm/test/Object/coff-archive-short.test @@ -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