[llvm] 9f049e9 - [lld][WebAssemby] Allow import module names to be empty strings.

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 31 15:30:55 PDT 2022


Author: Dan Gohman
Date: 2022-08-31T15:30:15-07:00
New Revision: 9f049e999308c43360fbe1513a772b818745addb

URL: https://github.com/llvm/llvm-project/commit/9f049e999308c43360fbe1513a772b818745addb
DIFF: https://github.com/llvm/llvm-project/commit/9f049e999308c43360fbe1513a772b818745addb.diff

LOG: [lld][WebAssemby] Allow import module names to be empty strings.

The component-model [canonical ABI] is currently using import names with
empty strings. Remove the special cases for empty strings from
WasmObjectFile.cpp so that they can pass through as-is.

[canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md

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

Added: 
    

Modified: 
    lld/test/wasm/import-module.ll
    lld/test/wasm/import-name.ll
    llvm/lib/Object/WasmObjectFile.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/wasm/import-module.ll b/lld/test/wasm/import-module.ll
index 9a473194ce2c3..5045e6df6d540 100644
--- a/lld/test/wasm/import-module.ll
+++ b/lld/test/wasm/import-module.ll
@@ -6,12 +6,15 @@ target triple = "wasm32-unknown-unknown-wasm"
 
 define void @_start() {
   call void @foo();
+  call void @qux();
   ret void
 }
 
 declare void @foo() #0
+declare void @qux() #1
 
 attributes #0 = { "wasm-import-module"="bar" }
+attributes #1 = { "wasm-import-module"="" }
 
 ; CHECK:        - Type:            IMPORT
 ; CHECK-NEXT:     Imports:         
@@ -19,3 +22,7 @@ attributes #0 = { "wasm-import-module"="bar" }
 ; CHECK-NEXT:         Field:           foo
 ; CHECK-NEXT:         Kind:            FUNCTION
 ; CHECK-NEXT:         SigIndex:        0
+; CHECK-NEXT:       - Module:          ''
+; CHECK-NEXT:         Field:           qux
+; CHECK-NEXT:         Kind:            FUNCTION
+; CHECK-NEXT:         SigIndex:        0

diff  --git a/lld/test/wasm/import-name.ll b/lld/test/wasm/import-name.ll
index fdcbe115df6fa..cf2803117ec6a 100644
--- a/lld/test/wasm/import-name.ll
+++ b/lld/test/wasm/import-name.ll
@@ -5,13 +5,16 @@
 target triple = "wasm32-unknown-unknown"
 
 declare void @f0() #0
+declare void @f1() #1
 
 define void @_start() {
     call void @f0()
+    call void @f1()
     ret void
 }
 
 attributes #0 = { "wasm-import-module"="somewhere" "wasm-import-name"="something" }
+attributes #1 = { "wasm-import-module"="otherwhere" "wasm-import-name"="" }
 
 ; CHECK:        - Type:            IMPORT
 ; CHECK-NEXT:     Imports:
@@ -19,9 +22,15 @@ attributes #0 = { "wasm-import-module"="somewhere" "wasm-import-name"="something
 ; CHECK-NEXT:         Field:           something
 ; CHECK-NEXT:         Kind:            FUNCTION
 ; CHECK-NEXT:         SigIndex:        0
+; CHECK-NEXT:       - Module:          otherwhere
+; CHECK-NEXT:         Field:           ''
+; CHECK-NEXT:         Kind:            FUNCTION
+; CHECK-NEXT:         SigIndex:        0
 
 ; CHECK:        - Type:            CUSTOM
 ; CHECK-NEXT:     Name:            name
 ; CHECK-NEXT:     FunctionNames:
 ; CHECK-NEXT:       - Index:           0
 ; CHECK-NEXT:         Name:            f0
+; CHECK-NEXT:       - Index:           1
+; CHECK-NEXT:         Name:            f1

diff  --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index d00359c6deef6..0e24ac94bf70c 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -640,9 +640,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
           Info.Name = Import.Field;
         }
         Signature = &Signatures[Import.SigIndex];
-        if (!Import.Module.empty()) {
-          Info.ImportModule = Import.Module;
-        }
+        Info.ImportModule = Import.Module;
       }
       break;
 
@@ -672,9 +670,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
           Info.Name = Import.Field;
         }
         GlobalType = &Import.Global;
-        if (!Import.Module.empty()) {
-          Info.ImportModule = Import.Module;
-        }
+        Info.ImportModule = Import.Module;
       }
       break;
 
@@ -704,9 +700,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
           Info.Name = Import.Field;
         }
         TableType = &Import.Table;
-        if (!Import.Module.empty()) {
-          Info.ImportModule = Import.Module;
-        }
+        Info.ImportModule = Import.Module;
       }
       break;
 
@@ -769,9 +763,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
           Info.Name = Import.Field;
         }
         Signature = &Signatures[Import.SigIndex];
-        if (!Import.Module.empty()) {
-          Info.ImportModule = Import.Module;
-        }
+        Info.ImportModule = Import.Module;
       }
       break;
     }


        


More information about the llvm-commits mailing list