summaryrefslogtreecommitdiff
path: root/lld/test
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2022-12-06 16:49:13 -0800
committerSam Clegg <sbc@chromium.org>2023-03-23 14:26:27 -0700
commit3111784ff7d3d51a9e981b1a0bbc8f6511c34d25 (patch)
tree2e82782b60fd65796c88557bf9fb1bca74c81ff9 /lld/test
parent1c9173365a932a0d289ec86704ec645a138de03e (diff)
downloadllvm-3111784ff7d3d51a9e981b1a0bbc8f6511c34d25.tar.gz
[lld][WebAssembly] Initial support for stub libraries
See the docs in lld/docs/WebAssembly.rst for more on this. This feature unlocks a lot of simplification in the emscripten toolchain since we can represent the JS libraries to wasm-ld as stub libraries. See https://github.com/emscripten-core/emscripten/issues/18875 Differential Revision: https://reviews.llvm.org/D145308
Diffstat (limited to 'lld/test')
-rw-r--r--lld/test/wasm/Inputs/libstub-missing-dep.so2
-rw-r--r--lld/test/wasm/Inputs/libstub-missing-sym.so3
-rw-r--r--lld/test/wasm/Inputs/libstub.so5
-rw-r--r--lld/test/wasm/stub_library.s48
4 files changed, 58 insertions, 0 deletions
diff --git a/lld/test/wasm/Inputs/libstub-missing-dep.so b/lld/test/wasm/Inputs/libstub-missing-dep.so
new file mode 100644
index 000000000000..f2345b766f09
--- /dev/null
+++ b/lld/test/wasm/Inputs/libstub-missing-dep.so
@@ -0,0 +1,2 @@
+#STUB
+foo: missing_dep,missing_dep2
diff --git a/lld/test/wasm/Inputs/libstub-missing-sym.so b/lld/test/wasm/Inputs/libstub-missing-sym.so
new file mode 100644
index 000000000000..2120b948511e
--- /dev/null
+++ b/lld/test/wasm/Inputs/libstub-missing-sym.so
@@ -0,0 +1,3 @@
+#STUB
+# Symbol `foo` is missing from this file which causes stub_object.s to fail
+bar
diff --git a/lld/test/wasm/Inputs/libstub.so b/lld/test/wasm/Inputs/libstub.so
new file mode 100644
index 000000000000..57e61f632b10
--- /dev/null
+++ b/lld/test/wasm/Inputs/libstub.so
@@ -0,0 +1,5 @@
+#STUB
+# This is a comment
+foo: foodep1,foodep2
+# This symbols as no dependencies
+bar
diff --git a/lld/test/wasm/stub_library.s b/lld/test/wasm/stub_library.s
new file mode 100644
index 000000000000..9cbf2505ea9e
--- /dev/null
+++ b/lld/test/wasm/stub_library.s
@@ -0,0 +1,48 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
+# RUN: wasm-ld %t.o %p/Inputs/libstub.so -o %t.wasm
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+# When the dependencies are missing the link fails
+# RUN: not wasm-ld %t.o %p/Inputs/libstub-missing-dep.so -o %t.wasm 2>&1 | FileCheck --check-prefix=MISSING-DEP %s
+
+# When the dependencies are missing the link fails
+# RUN: not wasm-ld %t.o %p/Inputs/libstub-missing-sym.so -o %t.wasm 2>&1 | FileCheck --check-prefix=MISSING-SYM %s
+
+# MISSING-DEP: libstub-missing-dep.so: undefined symbol: missing_dep. Required by foo
+# MISSING-DEP: libstub-missing-dep.so: undefined symbol: missing_dep2. Required by foo
+
+# MISSING-SYM: undefined symbol: foo
+
+# The function foo is defined in libstub.so but depend on foodep1 and foodep2
+.functype foo () -> ()
+
+.globl foodep1
+foodep1:
+ .functype foodep1 () -> ()
+ end_function
+
+.globl foodep2
+foodep2:
+ .functype foodep2 () -> ()
+ end_function
+
+.globl _start
+_start:
+ .functype _start () -> ()
+ call foo
+ end_function
+
+# CHECK: - Type: EXPORT
+# CHECK-NEXT: Exports:
+# CHECK-NEXT: - Name: memory
+# CHECK-NEXT: Kind: MEMORY
+# CHECK-NEXT: Index: 0
+# CHECK-NEXT: - Name: foodep1
+# CHECK-NEXT: Kind: FUNCTION
+# CHECK-NEXT: Index: 1
+# CHECK-NEXT: - Name: foodep2
+# CHECK-NEXT: Kind: FUNCTION
+# CHECK-NEXT: Index: 2
+# CHECK-NEXT: - Name: _start
+# CHECK-NEXT: Kind: FUNCTION
+# CHECK-NEXT: Index: 3