[lld] 2c12b05 - [lld][WebAssembly] Allow globals imports via import_name/import_module

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 20:35:22 PDT 2020


Author: Sam Clegg
Date: 2020-09-14T20:35:03-07:00
New Revision: 2c12b056bececd3fce3d5a3b731b4ff8fa6dfbbb

URL: https://github.com/llvm/llvm-project/commit/2c12b056bececd3fce3d5a3b731b4ff8fa6dfbbb
DIFF: https://github.com/llvm/llvm-project/commit/2c12b056bececd3fce3d5a3b731b4ff8fa6dfbbb.diff

LOG: [lld][WebAssembly] Allow globals imports via import_name/import_module

This feature already exists but was limited to function
symbols.

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

Added: 
    

Modified: 
    lld/test/wasm/mutable-globals.s
    lld/wasm/Relocations.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/wasm/mutable-globals.s b/lld/test/wasm/mutable-globals.s
index 98f216e1bebc..ea856e511289 100644
--- a/lld/test/wasm/mutable-globals.s
+++ b/lld/test/wasm/mutable-globals.s
@@ -9,5 +9,7 @@ _start:
   end_function
 
 .globaltype foo, i32
+.import_module foo, env
+.import_name foo, foo
 
 # CHECK: error: mutable global imported but 'mutable-globals' feature not present in inputs: `foo`. Use --no-check-features to suppress.

diff  --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp
index 2559e0f869cc..0a364d1a53ac 100644
--- a/lld/wasm/Relocations.cpp
+++ b/lld/wasm/Relocations.cpp
@@ -21,10 +21,13 @@ static bool requiresGOTAccess(const Symbol *sym) {
 }
 
 static bool allowUndefined(const Symbol* sym) {
-  // Undefined functions with explicit import name are allowed to be undefined
-  // at link time.
-  if (auto *F = dyn_cast<UndefinedFunction>(sym))
-    if (F->importName)
+  // Undefined functions and globals with explicit import name are allowed to be
+  // undefined at link time.
+  if (auto *f = dyn_cast<UndefinedFunction>(sym))
+    if (f->importName)
+      return true;
+  if (auto *g = dyn_cast<UndefinedGlobal>(sym))
+    if (g->importName)
       return true;
   return (config->allowUndefined ||
           config->allowUndefinedSymbols.count(sym->getName()) != 0);


        


More information about the llvm-commits mailing list