[lld] r297357 - Fix wrong assertion failure.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 20:47:33 PST 2017


Author: ruiu
Date: Wed Mar  8 22:47:33 2017
New Revision: 297357

URL: http://llvm.org/viewvc/llvm-project?rev=297357&view=rev
Log:
Fix wrong assertion failure.

Previously, if you have foo=bar in a definition file, this assertion
could fire because when symbols are read from file they could be mangled.
It seems that due to historical reasons underscore mangling scheme is
really ad-hoc, and I cannot find a clean way to handle this. I had
to just de-mangle symbols to search again.

Modified:
    lld/trunk/COFF/Librarian.cpp
    lld/trunk/test/COFF/export32.test

Modified: lld/trunk/COFF/Librarian.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Librarian.cpp?rev=297357&r1=297356&r2=297357&view=diff
==============================================================================
--- lld/trunk/COFF/Librarian.cpp (original)
+++ lld/trunk/COFF/Librarian.cpp Wed Mar  8 22:47:33 2017
@@ -104,6 +104,14 @@ static ImportNameType getNameType(String
 
 static std::string replace(StringRef S, StringRef From, StringRef To) {
   size_t Pos = S.find(From);
+
+  // From and To may be mangled, but substrings in S may not.
+  if (Pos == StringRef::npos && From.startswith("_") && To.startswith("_")) {
+    From = From.substr(1);
+    To = To.substr(1);
+    Pos = S.find(From);
+  }
+
   if (Pos == StringRef::npos) {
     error(S + ": replacing '" + From + "' with '" + To + "' failed");
     return "";

Modified: lld/trunk/test/COFF/export32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/export32.test?rev=297357&r1=297356&r2=297357&view=diff
==============================================================================
--- lld/trunk/test/COFF/export32.test (original)
+++ lld/trunk/test/COFF/export32.test Wed Mar  8 22:47:33 2017
@@ -73,6 +73,16 @@
 # CHECK6:     duplicate /export option: _exportfn2
 # CHECK6-NOT: duplicate /export option: _exportfn1
 
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:foo=mangled
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK7 %s
+
+# CHECK7:      Export Table:
+# CHECK7:      DLL name: export32.test.tmp.dll
+# CHECK7:      Ordinal      RVA  Name
+# CHECK7-NEXT:       0        0
+# CHECK7-NEXT:       1        0
+# CHECK7-NEXT:       2   0x1010  foo
+
 --- !COFF
 header:
   Machine:         IMAGE_FILE_MACHINE_I386




More information about the llvm-commits mailing list