[lld] r320118 - [WebAssembly] Add check to ensure symbol VA is only set once. NFC.

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 16:13:14 PST 2017


Author: sbc
Date: Thu Dec  7 16:13:14 2017
New Revision: 320118

URL: http://llvm.org/viewvc/llvm-project?rev=320118&view=rev
Log:
[WebAssembly] Add check to ensure symbol VA is only set once. NFC.

Also remove resulting unneeded function.

Differential Revision: https://reviews.llvm.org/D40990

Modified:
    lld/trunk/wasm/Driver.cpp
    lld/trunk/wasm/Symbols.cpp

Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=320118&r1=320117&r2=320118&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Thu Dec  7 16:13:14 2017
@@ -134,17 +134,6 @@ static Optional<std::string> findFile(St
   return None;
 }
 
-// Inject a new wasm global into the output binary with the given value.
-// Wasm global are used in relocatable object files to model symbol imports
-// and exports.  In the final executable the only use of wasm globals is
-// for the exlicit stack pointer (__stack_pointer).
-static Symbol* addSyntheticGlobal(StringRef Name, int32_t Value) {
-  log("injecting global: " + Name);
-  Symbol *S = Symtab->addDefinedGlobal(Name);
-  S->setVirtualAddress(Value);
-  return S;
-}
-
 // Inject a new undefined symbol into the link.  This will cause the link to
 // fail unless this symbol can be found.
 static void addSyntheticUndefinedFunction(StringRef Name,
@@ -285,7 +274,7 @@ void LinkerDriver::link(ArrayRef<const c
     for (StringRef S : args::getStrings(Args, OPT_undefined))
       addSyntheticUndefinedFunction(S, nullptr);
 
-    Config->StackPointerSymbol = addSyntheticGlobal("__stack_pointer", 0);
+    Config->StackPointerSymbol = Symtab->addDefinedGlobal("__stack_pointer");
   }
 
   createFiles(Args);

Modified: lld/trunk/wasm/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.cpp?rev=320118&r1=320117&r2=320118&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.cpp (original)
+++ lld/trunk/wasm/Symbols.cpp Thu Dec  7 16:13:14 2017
@@ -61,6 +61,7 @@ uint32_t Symbol::getOutputIndex() const
 
 void Symbol::setVirtualAddress(uint32_t Value) {
   DEBUG(dbgs() << "setVirtualAddress " << Name << " -> " << Value << "\n");
+  assert(!VirtualAddress.hasValue());
   VirtualAddress = Value;
 }
 




More information about the llvm-commits mailing list