[PATCH] D54279: wasm32: Respect `--no-mangle` in more locations in LLD

Alex Crichton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 8 15:35:57 PST 2018


alexcrichton created this revision.
alexcrichton added a reviewer: sbc100.
Herald added subscribers: llvm-commits, erik.pilkington, sunfish, aheejin.

This commit updates a few locations that `demangleItanium` is called to all funnel through one location that respects the `--no-mangle` flag passed on the command line for linked wasm binaries. We found recently that `--no-demangle` was still demangling the names section of the binary, and it looks like this may be why!


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D54279

Files:
  wasm/Driver.cpp
  wasm/Symbols.cpp
  wasm/Symbols.h
  wasm/Writer.cpp


Index: wasm/Writer.cpp
===================================================================
--- wasm/Writer.cpp
+++ wasm/Writer.cpp
@@ -554,8 +554,7 @@
   for (const Symbol *S : ImportedSymbols) {
     if (auto *F = dyn_cast<FunctionSymbol>(S)) {
       writeUleb128(Sub.OS, F->getFunctionIndex(), "func index");
-      Optional<std::string> Name = demangleItanium(F->getName());
-      writeStr(Sub.OS, Name ? StringRef(*Name) : F->getName(), "symbol name");
+      writeStr(Sub.OS, toString(*S), "symbol name");
     }
   }
   for (const InputFunction *F : InputFunctions) {
@@ -564,8 +563,7 @@
       if (!F->getDebugName().empty()) {
         writeStr(Sub.OS, F->getDebugName(), "symbol name");
       } else {
-        Optional<std::string> Name = demangleItanium(F->getName());
-        writeStr(Sub.OS, Name ? StringRef(*Name) : F->getName(), "symbol name");
+        writeStr(Sub.OS, maybeDemangleSymbol(F->getName()), "symbol name");
       }
     }
   }
Index: wasm/Symbols.h
===================================================================
--- wasm/Symbols.h
+++ wasm/Symbols.h
@@ -349,6 +349,7 @@
 // Returns a symbol name for an error message.
 std::string toString(const wasm::Symbol &Sym);
 std::string toString(wasm::Symbol::Kind Kind);
+std::string maybeDemangleSymbol(StringRef Name);
 
 } // namespace lld
 
Index: wasm/Symbols.cpp
===================================================================
--- wasm/Symbols.cpp
+++ wasm/Symbols.cpp
@@ -226,10 +226,14 @@
 void LazySymbol::fetch() { cast<ArchiveFile>(File)->addMember(&ArchiveSymbol); }
 
 std::string lld::toString(const wasm::Symbol &Sym) {
+  return lld::maybeDemangleSymbol(Sym.getName());
+}
+
+std::string lld::maybeDemangleSymbol(StringRef Name) {
   if (Config->Demangle)
-    if (Optional<std::string> S = demangleItanium(Sym.getName()))
+    if (Optional<std::string> S = demangleItanium(Name))
       return *S;
-  return Sym.getName();
+  return Name;
 }
 
 std::string lld::toString(wasm::Symbol::Kind Kind) {
Index: wasm/Driver.cpp
===================================================================
--- wasm/Driver.cpp
+++ wasm/Driver.cpp
@@ -310,10 +310,8 @@
 
     // Add a synthetic dummy for weak undefined functions.  These dummies will
     // be GC'd if not used as the target of any "call" instructions.
-    Optional<std::string> SymName = demangleItanium(Sym->getName());
-    StringRef DebugName =
-        Saver.save("undefined function " +
-                   (SymName ? StringRef(*SymName) : Sym->getName()));
+    std::string SymName = toString(*Sym);
+    StringRef DebugName = Saver.save("undefined function " + SymName);
     SyntheticFunction *Func =
         make<SyntheticFunction>(Sig, Sym->getName(), DebugName);
     Func->setBody(UnreachableFn);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54279.173236.patch
Type: text/x-patch
Size: 2766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181108/552d2ed7/attachment.bin>


More information about the llvm-commits mailing list