summaryrefslogtreecommitdiff
path: root/COFF/Librarian.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-04-16 16:03:39 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-04-16 16:03:39 +0000
commitd2d3ebb81992e107edf95c1c136d7a342d9b1418 (patch)
treebb1af8fff2b1400cf240e3b2532a1e5d22a121da /COFF/Librarian.cpp
parent16787c9ce0b96aaa669d7fab3a495916b35ce758 (diff)
Notes
Diffstat (limited to 'COFF/Librarian.cpp')
-rw-r--r--COFF/Librarian.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/COFF/Librarian.cpp b/COFF/Librarian.cpp
index 4c597fad73455..3ce72822180b0 100644
--- a/COFF/Librarian.cpp
+++ b/COFF/Librarian.cpp
@@ -104,7 +104,18 @@ static ImportNameType getNameType(StringRef Sym, StringRef ExtName) {
static std::string replace(StringRef S, StringRef From, StringRef To) {
size_t Pos = S.find(From);
- assert(Pos != StringRef::npos);
+
+ // 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 "";
+ }
return (Twine(S.substr(0, Pos)) + To + S.substr(Pos + From.size())).str();
}