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.

llvm-svn: 297357
This commit is contained in:
Rui Ueyama 2017-03-09 04:47:33 +00:00
parent 6dcb0eb301
commit 7d271ae21d
2 changed files with 18 additions and 0 deletions

View File

@ -104,6 +104,14 @@ static ImportNameType getNameType(StringRef Sym, StringRef ExtName) {
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 "";

View File

@ -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