-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lld][WebAssembly] Report undefined symbols in -shared/-pie builds #75242
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
77e038c
to
edca2f9
Compare
@llvm/pr-subscribers-llvm-binary-utilities @llvm/pr-subscribers-lld-wasm Author: Sam Clegg (sbc100) ChangesPreviously we would ignore/import all undefined symbols when using The old behaviour is still possible via the The rationale here is that changing the semantics like this is Depends on (and currently includes) Patch is 34.18 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/75242.diff 23 Files Affected:
diff --git a/lld/test/wasm/Inputs/ret32.s b/lld/test/wasm/Inputs/ret32.s
index 5233455917e670..009f28c8cc9b88 100644
--- a/lld/test/wasm/Inputs/ret32.s
+++ b/lld/test/wasm/Inputs/ret32.s
@@ -1,4 +1,3 @@
- .hidden ret32
.globl ret32
ret32:
.functype ret32 (f32) -> (i32)
diff --git a/lld/test/wasm/dylink.s b/lld/test/wasm/dylink.s
new file mode 100644
index 00000000000000..5326025edee018
--- /dev/null
+++ b/lld/test/wasm/dylink.s
@@ -0,0 +1,30 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten -o %t.o %s
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten %p/Inputs/ret32.s -o %t.ret32.o
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten %p/Inputs/libsearch-dyn.s -o %t.dyn.o
+# RUN: wasm-ld --experimental-pic -shared %t.ret32.o %t.dyn.o -o %t.lib.so
+# RUN: not wasm-ld --experimental-pic -pie -o %t.wasm %t.o 2>&1 | FileCheck --check-prefix=ERROR %s
+# RUN: wasm-ld --experimental-pic -pie -o %t.wasm %t.o %t.lib.so
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+# ERROR: error: {{.*}}: undefined symbol: ret32
+.functype ret32 (f32) -> (i32)
+
+.globl _start
+_start:
+ .functype _start () -> ()
+ f32.const 0.0
+ call ret32
+ drop
+ i32.const _dynamic@GOT
+ drop
+ end_function
+
+# CHECK: Sections:
+# CHECK-NEXT: - Type: CUSTOM
+# CHECK-NEXT: Name: dylink.0
+# CHECK-NEXT: MemorySize: 0
+# CHECK-NEXT: MemoryAlignment: 0
+# CHECK-NEXT: TableSize: 0
+# CHECK-NEXT: TableAlignment: 0
+# CHECK-NEXT: Needed:
+# CHECK-NEXT: - {{.*}}.lib.so
diff --git a/lld/test/wasm/emit-relocs.s b/lld/test/wasm/emit-relocs.s
index 91de6116164f72..bd136ba810b5ef 100644
--- a/lld/test/wasm/emit-relocs.s
+++ b/lld/test/wasm/emit-relocs.s
@@ -54,7 +54,7 @@ foo:
# CHECK-NEXT: - Index: 1
# CHECK-NEXT: Kind: FUNCTION
# CHECK-NEXT: Name: ret32
-# CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ]
+# CHECK-NEXT: Flags: [ ]
# CHECK-NEXT: Function: 1
# CHECK-NEXT: - Index: 2
# CHECK-NEXT: Kind: DATA
diff --git a/lld/test/wasm/libsearch.s b/lld/test/wasm/libsearch.s
index 23336510748ce8..f321b859a8a179 100644
--- a/lld/test/wasm/libsearch.s
+++ b/lld/test/wasm/libsearch.s
@@ -32,66 +32,66 @@
// Should use explicitly specified static library
// Also ensure that we accept -L <arg>
-// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o -L %t.dir -l:libls.a
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t4 %t.o -L %t.dir -l:libls.a
+// RUN: llvm-readobj --symbols %t4 | FileCheck --check-prefix=STATIC %s
// STATIC: Symbols [
// STATIC: Name: _static
// Should use explicitly specified dynamic library
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -l:libls.so
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t5 %t.o -L%t.dir -l:libls.so
+// RUN: llvm-readobj --symbols %t5 | FileCheck --check-prefix=DYNAMIC %s
// DYNAMIC: Symbols [
// DYNAMIC-NOT: Name: _static
// Should prefer static to dynamic when linking regular executable.
-// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t6 %t.o -L%t.dir -lls
+// RUN: llvm-readobj --symbols %t6 | FileCheck --check-prefix=STATIC %s
// Should prefer dynamic when linking PIE.
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t7 %t.o -L%t.dir -lls
+// RUN: llvm-readobj --symbols %t7 | FileCheck --check-prefix=DYNAMIC %s
// Check for library search order
// RUN: mkdir -p %t.dir2
// RUN: cp %t.dir/libls.a %t.dir2
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir2 -L%t.dir -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t8 %t.o -L%t.dir2 -L%t.dir -lls
+// RUN: llvm-readobj --symbols %t8 | FileCheck --check-prefix=STATIC %s
// -L can be placed after -l
-// RUN: wasm-ld -o %t3 %t.o -lls -L%t.dir
+// RUN: wasm-ld -o %t8 %t.o -lls -L%t.dir
// Check long forms as well
-// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o --library-path=%t.dir --library=ls
-// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o --library-path %t.dir --library ls
+// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t8 %t.o --library-path=%t.dir --library=ls
+// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t8 %t.o --library-path %t.dir --library ls
// Should not search for dynamic libraries if -Bstatic is specified
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t10 %t.o -L%t.dir -Bstatic -lls
+// RUN: llvm-readobj --symbols %t10 | FileCheck --check-prefix=STATIC %s
// RUN: not wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o /dev/null %t.o -L%t.dir -Bstatic -lls2 2>&1 \
// RUN: | FileCheck --check-prefix=NOLIB2 %s
// NOLIB2: unable to find library -lls2
// -Bdynamic should restore default behaviour
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -Bdynamic -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t11 %t.o -L%t.dir -Bstatic -Bdynamic -lls
+// RUN: llvm-readobj --symbols %t11 | FileCheck --check-prefix=DYNAMIC %s
// -Bstatic and -Bdynamic should affect only libraries which follow them
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls -Bstatic -Bdynamic
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -lls -Bdynamic
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t12 %t.o -L%t.dir -lls -Bstatic -Bdynamic
+// RUN: llvm-readobj --symbols %t12 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t13 %t.o -L%t.dir -Bstatic -lls -Bdynamic
+// RUN: llvm-readobj --symbols %t13 | FileCheck --check-prefix=STATIC %s
// Check aliases as well
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -dn -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -non_shared -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -static -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -dy -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -call_shared -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t13 %t.o -L%t.dir -dn -lls
+// RUN: llvm-readobj --symbols %t13 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t14 %t.o -L%t.dir -non_shared -lls
+// RUN: llvm-readobj --symbols %t14 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t15 %t.o -L%t.dir -static -lls
+// RUN: llvm-readobj --symbols %t15 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t16 %t.o -L%t.dir -Bstatic -dy -lls
+// RUN: llvm-readobj --symbols %t16 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t17 %t.o -L%t.dir -Bstatic -call_shared -lls
+// RUN: llvm-readobj --symbols %t17 | FileCheck --check-prefix=DYNAMIC %s
.globl _start, _bar
_start:
diff --git a/lld/test/wasm/pie.s b/lld/test/wasm/pie.s
index 887377043e555c..21eac792073187 100644
--- a/lld/test/wasm/pie.s
+++ b/lld/test/wasm/pie.s
@@ -1,6 +1,6 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten -o %t.o %s
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten %S/Inputs/internal_func.s -o %t.internal_func.o
-# RUN: wasm-ld --no-gc-sections --experimental-pic -pie -o %t.wasm %t.o %t.internal_func.o
+# RUN: wasm-ld --no-gc-sections --experimental-pic -pie --unresolved-symbols=import-dynamic -o %t.wasm %t.o %t.internal_func.o
# RUN: obj2yaml %t.wasm | FileCheck %s
# RUN: llvm-objdump --disassemble-symbols=__wasm_call_ctors,__wasm_apply_data_relocs --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DISASSEM
@@ -150,7 +150,7 @@ _start:
# instruction in the InitExpr. We also, therefore, do not need these globals
# to be mutable.
-# RUN: wasm-ld --no-gc-sections --experimental-pic -pie --extra-features=extended-const -o %t.extended.wasm %t.o %t.internal_func.o
+# RUN: wasm-ld --no-gc-sections --experimental-pic -pie --unresolved-symbols=import-dynamic --extra-features=extended-const -o %t.extended.wasm %t.o %t.internal_func.o
# RUN: obj2yaml %t.extended.wasm | FileCheck %s --check-prefix=EXTENDED-CONST
# EXTENDED-CONST-NOT: __wasm_apply_global_relocs
@@ -207,7 +207,7 @@ _start:
# to be generated along with __wasm_start as the start
# function.
-# RUN: wasm-ld --no-gc-sections --shared-memory --experimental-pic -pie -o %t.shmem.wasm %t.o %t.internal_func.o
+# RUN: wasm-ld --no-gc-sections --shared-memory --experimental-pic -pie --unresolved-symbols=import-dynamic -o %t.shmem.wasm %t.o %t.internal_func.o
# RUN: obj2yaml %t.shmem.wasm | FileCheck %s --check-prefix=SHMEM
# RUN: llvm-objdump --disassemble-symbols=__wasm_start --no-show-raw-insn --no-leading-addr %t.shmem.wasm | FileCheck %s --check-prefix DISASSEM-SHMEM
diff --git a/lld/test/wasm/shared-needed.s b/lld/test/wasm/shared-needed.s
index 12c4597190a3b5..0176da832d2b19 100644
--- a/lld/test/wasm/shared-needed.s
+++ b/lld/test/wasm/shared-needed.s
@@ -1,17 +1,27 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/ret32.s -o %t.ret32.o
-# RUN: wasm-ld -shared --experimental-pic -o %t1.so %t.o
-# RUN: obj2yaml %t1.so | FileCheck %s -check-prefix=SO1
+# RUN: wasm-ld -shared --experimental-pic -o %t.ret32.so %t.ret32.o
+# RUN: obj2yaml %t.ret32.so | FileCheck %s -check-prefix=SO1
+
+# With linking against the ret32.so shared object we expect and undefined
+# symbol error
+# RUN: not wasm-ld -shared --experimental-pic -o %t.so %t.o 2>&1 | FileCheck %s --check-prefix=ERROR
+# ERROR: undefined symbol: ret32
+
+# RUN: wasm-ld -shared --experimental-pic -o %t.so %t.o %t.ret32.so
+# RUN: obj2yaml %t.so | FileCheck %s -check-prefix=SO2
-# RUN: wasm-ld -shared --experimental-pic -o %t2.so %t1.so %t.ret32.o
-# RUN: obj2yaml %t2.so | FileCheck %s -check-prefix=SO2
.globl foo
.globl data
+.functype ret32 (f32) -> (i32)
+
foo:
- .functype foo () -> ()
+ .functype foo (f32) -> (i32)
+ local.get 0
+ call ret32
end_function
.section .data,"",@
@@ -24,8 +34,8 @@ data:
# SO1: Sections:
# SO1-NEXT: - Type: CUSTOM
# SO1-NEXT: Name: dylink.0
-# SO1-NEXT: MemorySize: 4
-# SO1-NEXT: MemoryAlignment: 2
+# SO1-NEXT: MemorySize: 0
+# SO1-NEXT: MemoryAlignment: 0
# SO1-NEXT: TableSize: 0
# SO1-NEXT: TableAlignment: 0
# SO1-NEXT: Needed: []
@@ -34,10 +44,10 @@ data:
# SO2: Sections:
# SO2-NEXT: - Type: CUSTOM
# SO2-NEXT: Name: dylink.0
-# SO2-NEXT: MemorySize: 0
-# SO2-NEXT: MemoryAlignment: 0
+# SO2-NEXT: MemorySize: 4
+# SO2-NEXT: MemoryAlignment: 2
# SO2-NEXT: TableSize: 0
# SO2-NEXT: TableAlignment: 0
# SO2-NEXT: Needed:
-# SO2-NEXT: - shared-needed.s.tmp1.so
+# SO2-NEXT: - shared-needed.s.tmp.ret32.so
# SO2-NEXT: - Type: TYPE
diff --git a/lld/test/wasm/shared.s b/lld/test/wasm/shared.s
index a26f00163fea70..5b40d4ebee7abc 100644
--- a/lld/test/wasm/shared.s
+++ b/lld/test/wasm/shared.s
@@ -1,5 +1,5 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
-# RUN: wasm-ld --experimental-pic -shared -o %t.wasm %t.o
+# RUN: wasm-ld --experimental-pic --unresolved-symbols=import-dynamic -shared -o %t.wasm %t.o
# RUN: obj2yaml %t.wasm | FileCheck %s
# RUN: llvm-objdump --disassemble-symbols=__wasm_call_ctors,__wasm_apply_data_relocs --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS
@@ -7,8 +7,8 @@
# Linker-synthesized globals
.globaltype __stack_pointer, i32
-.globaltype __table_base, i32, immutable
-.globaltype __memory_base, i32, immutable
+.globaltype __table_base, i32, immutable
+.globaltype __memory_base, i32, immutable
.section .data.data,"",@
data:
diff --git a/lld/test/wasm/shared64.s b/lld/test/wasm/shared64.s
index 3401faed8610c1..fba73f187679a6 100644
--- a/lld/test/wasm/shared64.s
+++ b/lld/test/wasm/shared64.s
@@ -1,5 +1,5 @@
# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-unknown -o %t.o %s
-# RUN: wasm-ld -mwasm64 --experimental-pic -shared -o %t.wasm %t.o
+# RUN: wasm-ld -mwasm64 --experimental-pic --unresolved-symbols=import-dynamic -shared -o %t.wasm %t.o
# RUN: obj2yaml %t.wasm | FileCheck %s
# RUN: llvm-objdump --disassemble-symbols=__wasm_call_ctors,__wasm_apply_data_relocs --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS
diff --git a/lld/test/wasm/signature-mismatch.s b/lld/test/wasm/signature-mismatch.s
index 5d305efca24649..e9da3073dde87c 100644
--- a/lld/test/wasm/signature-mismatch.s
+++ b/lld/test/wasm/signature-mismatch.s
@@ -84,7 +84,7 @@ ret32_address_main:
# RELOC-NEXT: - Index: 1
# RELOC-NEXT: Kind: FUNCTION
# RELOC-NEXT: Name: ret32
-# RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
+# RELOC-NEXT: Flags: [ ]
# RELOC-NEXT: Function: 2
# RELOC-NEXT: - Index: 2
# RELOC-NEXT: Kind: DATA
diff --git a/lld/test/wasm/tag-section.ll b/lld/test/wasm/tag-section.ll
index 4decdb58f952a9..20823c72c65116 100644
--- a/lld/test/wasm/tag-section.ll
+++ b/lld/test/wasm/tag-section.ll
@@ -11,7 +11,7 @@
; RUN: llc -filetype=obj -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling -relocation-model=pic %p/Inputs/tag-section1.ll -o %t1.o
; RUN: llc -filetype=obj -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling -relocation-model=pic %p/Inputs/tag-section2.ll -o %t2.o
; RUN: llc -filetype=obj -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling -relocation-model=pic %s -o %t.o
-; RUN: wasm-ld --import-undefined --experimental-pic -pie -o %t.wasm %t.o %t1.o %t2.o
+; RUN: wasm-ld --import-undefined --experimental-pic --unresolved-symbols=import-dynamic -pie -o %t.wasm %t.o %t1.o %t2.o
; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefix=PIC
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
diff --git a/lld/test/wasm/undef-shared.s b/lld/test/wasm/undef-shared.s
new file mode 100644
index 00000000000000..4c270880ef531d
--- /dev/null
+++ b/lld/test/wasm/undef-shared.s
@@ -0,0 +1,12 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
+# RUN: not wasm-ld --experimental-pic %t.o -o /dev/null -shared 2>&1 | FileCheck %s
+
+# CHECK: error: {{.*}}: undefined symbol: hidden
+.global hidden
+.hidden hidden
+
+.global foo
+.section .data,"",@
+foo:
+ .int32 hidden
+ .size foo,4
diff --git a/lld/test/wasm/undefined-data.s b/lld/test/wasm/undefined-data.s
index d63b667c4ea38b..5e2a41606612ab 100644
--- a/lld/test/wasm/undefined-data.s
+++ b/lld/test/wasm/undefined-data.s
@@ -1,7 +1,7 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: not wasm-ld -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=UNDEF
# RUN: wasm-ld --allow-undefined -o %t.wasm %t.o
-# RUN: not wasm-ld --shared -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=SHARED
+# RUN: not wasm-ld --experimental-pic -shared --unresolved-symbols=import-dynamic -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=SHARED
.globl _start
_start:
diff --git a/lld/test/wasm/unresolved-symbols.s b/lld/test/wasm/unresolved-symbols.s
index 5de54d76c6de81..ebb5acc6876c9d 100644
--- a/lld/test/wasm/unresolved-symbols.s
+++ b/lld/test/wasm/unresolved-symbols.s
@@ -80,7 +80,7 @@
.functype get_func_addr () -> (i32)
## import-dynamic should fail due to incompatible relocations.
-# RUN: not wasm-ld %t1.o -o %t5.wasm --unresolved-symbols=import-dynamic 2>&1 | FileCheck -check-prefix=ERRNOPIC %s
+# RUN: not wasm-ld %t1.o -o %t5.wasm --experimental-pic --unresolved-symbols=import-dynamic 2>&1 | FileCheck -check-prefix=ERRNOPIC %s
# ERRNOPIC: relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `undef_data`; recompile with -fPIC
# ERRNOPIC: relocation R_WASM_TABLE_INDEX_SLEB cannot be used against symbol `undef_func`; recompile with -fPIC
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 96ac1e1610dd3b..6ef4769beed695 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -178,7 +178,7 @@ uint64_t ObjFile::calcNewValue(const WasmRelocation &reloc, uint64_t tombstone,
case R_WASM_MEMORY_ADDR_TLS_SLEB:
case R_WASM_MEMORY_ADDR_TLS_SLEB64:
case R_WASM_MEMORY_ADDR_LOCREL_I32: {
- if (isa<UndefinedData>(sym) || sym->isUndefWeak())
+ if (isa<UndefinedData>(sym) || sym->isShared() || sym->isUndefWeak())
return 0;
auto D = cast<DefinedData>(sym);
uint64_t value = D->getVA() + reloc.Addend;
@@ -391,7 +391,36 @@ static bool shouldMerge(const WasmSegment &seg) {
return true;
}
-void ObjFile::parse(bool ignoreComdats) {
+void SharedFile::parse() {
+ WasmFileBase::parse();
+ assert(wasmObj->isSharedObject());
+
+ for (const SymbolRef &sym : wasmObj->symbols()) {
+ const WasmSymbol &wasmSym = wasmObj->getWasmSymbol(sym.getRawDataRefImpl());
+ if (wasmSym.isDefined()) {
+ StringRef name = wasmSym.Info.Name;
+ uint32_t flags = wasmSym.Info.Flags;
+ Symbol *s;
+ LLVM_DEBUG(dbgs() << "shared symbol: " << name << "\n");
+ switch (wasmSym.Info.Kind) {
+ case WASM_SYMBOL_TYPE_FUNCTION:
+ if (name == "__wasm_apply_data_relocs" || name == "__wasm_call_ctors") {
+ continue;
+ }
+ s = symtab->addSharedFunction(name, flags, this, wasmSym.Signature);
+ break;
+ case WASM_SYMBOL_TYPE_DATA:
+ s = symtab->addSharedData(name, flags, this);
+ break;
+ default:
+ continue;
+ }
+ symbols.push_back(s);
+ }
+ }
+}
+
+void WasmFileBase::parse() {
// Parse a memory buffer as a wasm file.
LLVM_DEBUG(dbgs() << "Parsing object: " << toString(this) << "\n");
std::unique_ptr<Binary> bin = CHECK(createBinary(mb), toString(this));
@@ -399,13 +428,18 @@ void ObjFile::parse(bool ignoreComdats) {
auto *obj = dyn_cast<WasmObjectFile>(bin.get());
if (!obj)
fatal(toString(this) + ": not a wasm file");
- if (!obj->isRelocatableObject())
- fatal(toString(this) + ": not a relocatable wasm file");
bin.release();
wasmObj.reset(obj);
checkArch(obj->getArch());
+}
+
+void ObjFile::parse(bool ignoreComdats) {
+ WasmFileBase::parse();
+
+ if (!wasmObj->isRelocatableObject())
+ fatal(toString(this) + ": not a relocatable wasm file");
// Build...
[truncated]
|
@llvm/pr-subscribers-lld Author: Sam Clegg (sbc100) ChangesPreviously we would ignore/import all undefined symbols when using The old behaviour is still possible via the The rationale here is that changing the semantics like this is Depends on (and currently includes) Patch is 34.18 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/75242.diff 23 Files Affected:
diff --git a/lld/test/wasm/Inputs/ret32.s b/lld/test/wasm/Inputs/ret32.s
index 5233455917e670..009f28c8cc9b88 100644
--- a/lld/test/wasm/Inputs/ret32.s
+++ b/lld/test/wasm/Inputs/ret32.s
@@ -1,4 +1,3 @@
- .hidden ret32
.globl ret32
ret32:
.functype ret32 (f32) -> (i32)
diff --git a/lld/test/wasm/dylink.s b/lld/test/wasm/dylink.s
new file mode 100644
index 00000000000000..5326025edee018
--- /dev/null
+++ b/lld/test/wasm/dylink.s
@@ -0,0 +1,30 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten -o %t.o %s
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten %p/Inputs/ret32.s -o %t.ret32.o
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten %p/Inputs/libsearch-dyn.s -o %t.dyn.o
+# RUN: wasm-ld --experimental-pic -shared %t.ret32.o %t.dyn.o -o %t.lib.so
+# RUN: not wasm-ld --experimental-pic -pie -o %t.wasm %t.o 2>&1 | FileCheck --check-prefix=ERROR %s
+# RUN: wasm-ld --experimental-pic -pie -o %t.wasm %t.o %t.lib.so
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+# ERROR: error: {{.*}}: undefined symbol: ret32
+.functype ret32 (f32) -> (i32)
+
+.globl _start
+_start:
+ .functype _start () -> ()
+ f32.const 0.0
+ call ret32
+ drop
+ i32.const _dynamic@GOT
+ drop
+ end_function
+
+# CHECK: Sections:
+# CHECK-NEXT: - Type: CUSTOM
+# CHECK-NEXT: Name: dylink.0
+# CHECK-NEXT: MemorySize: 0
+# CHECK-NEXT: MemoryAlignment: 0
+# CHECK-NEXT: TableSize: 0
+# CHECK-NEXT: TableAlignment: 0
+# CHECK-NEXT: Needed:
+# CHECK-NEXT: - {{.*}}.lib.so
diff --git a/lld/test/wasm/emit-relocs.s b/lld/test/wasm/emit-relocs.s
index 91de6116164f72..bd136ba810b5ef 100644
--- a/lld/test/wasm/emit-relocs.s
+++ b/lld/test/wasm/emit-relocs.s
@@ -54,7 +54,7 @@ foo:
# CHECK-NEXT: - Index: 1
# CHECK-NEXT: Kind: FUNCTION
# CHECK-NEXT: Name: ret32
-# CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ]
+# CHECK-NEXT: Flags: [ ]
# CHECK-NEXT: Function: 1
# CHECK-NEXT: - Index: 2
# CHECK-NEXT: Kind: DATA
diff --git a/lld/test/wasm/libsearch.s b/lld/test/wasm/libsearch.s
index 23336510748ce8..f321b859a8a179 100644
--- a/lld/test/wasm/libsearch.s
+++ b/lld/test/wasm/libsearch.s
@@ -32,66 +32,66 @@
// Should use explicitly specified static library
// Also ensure that we accept -L <arg>
-// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o -L %t.dir -l:libls.a
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t4 %t.o -L %t.dir -l:libls.a
+// RUN: llvm-readobj --symbols %t4 | FileCheck --check-prefix=STATIC %s
// STATIC: Symbols [
// STATIC: Name: _static
// Should use explicitly specified dynamic library
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -l:libls.so
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t5 %t.o -L%t.dir -l:libls.so
+// RUN: llvm-readobj --symbols %t5 | FileCheck --check-prefix=DYNAMIC %s
// DYNAMIC: Symbols [
// DYNAMIC-NOT: Name: _static
// Should prefer static to dynamic when linking regular executable.
-// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t6 %t.o -L%t.dir -lls
+// RUN: llvm-readobj --symbols %t6 | FileCheck --check-prefix=STATIC %s
// Should prefer dynamic when linking PIE.
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t7 %t.o -L%t.dir -lls
+// RUN: llvm-readobj --symbols %t7 | FileCheck --check-prefix=DYNAMIC %s
// Check for library search order
// RUN: mkdir -p %t.dir2
// RUN: cp %t.dir/libls.a %t.dir2
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir2 -L%t.dir -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t8 %t.o -L%t.dir2 -L%t.dir -lls
+// RUN: llvm-readobj --symbols %t8 | FileCheck --check-prefix=STATIC %s
// -L can be placed after -l
-// RUN: wasm-ld -o %t3 %t.o -lls -L%t.dir
+// RUN: wasm-ld -o %t8 %t.o -lls -L%t.dir
// Check long forms as well
-// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o --library-path=%t.dir --library=ls
-// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o --library-path %t.dir --library ls
+// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t8 %t.o --library-path=%t.dir --library=ls
+// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t8 %t.o --library-path %t.dir --library ls
// Should not search for dynamic libraries if -Bstatic is specified
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t10 %t.o -L%t.dir -Bstatic -lls
+// RUN: llvm-readobj --symbols %t10 | FileCheck --check-prefix=STATIC %s
// RUN: not wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o /dev/null %t.o -L%t.dir -Bstatic -lls2 2>&1 \
// RUN: | FileCheck --check-prefix=NOLIB2 %s
// NOLIB2: unable to find library -lls2
// -Bdynamic should restore default behaviour
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -Bdynamic -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t11 %t.o -L%t.dir -Bstatic -Bdynamic -lls
+// RUN: llvm-readobj --symbols %t11 | FileCheck --check-prefix=DYNAMIC %s
// -Bstatic and -Bdynamic should affect only libraries which follow them
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls -Bstatic -Bdynamic
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -lls -Bdynamic
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t12 %t.o -L%t.dir -lls -Bstatic -Bdynamic
+// RUN: llvm-readobj --symbols %t12 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t13 %t.o -L%t.dir -Bstatic -lls -Bdynamic
+// RUN: llvm-readobj --symbols %t13 | FileCheck --check-prefix=STATIC %s
// Check aliases as well
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -dn -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -non_shared -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -static -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -dy -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
-// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -call_shared -lls
-// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t13 %t.o -L%t.dir -dn -lls
+// RUN: llvm-readobj --symbols %t13 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t14 %t.o -L%t.dir -non_shared -lls
+// RUN: llvm-readobj --symbols %t14 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t15 %t.o -L%t.dir -static -lls
+// RUN: llvm-readobj --symbols %t15 | FileCheck --check-prefix=STATIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t16 %t.o -L%t.dir -Bstatic -dy -lls
+// RUN: llvm-readobj --symbols %t16 | FileCheck --check-prefix=DYNAMIC %s
+// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t17 %t.o -L%t.dir -Bstatic -call_shared -lls
+// RUN: llvm-readobj --symbols %t17 | FileCheck --check-prefix=DYNAMIC %s
.globl _start, _bar
_start:
diff --git a/lld/test/wasm/pie.s b/lld/test/wasm/pie.s
index 887377043e555c..21eac792073187 100644
--- a/lld/test/wasm/pie.s
+++ b/lld/test/wasm/pie.s
@@ -1,6 +1,6 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten -o %t.o %s
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten %S/Inputs/internal_func.s -o %t.internal_func.o
-# RUN: wasm-ld --no-gc-sections --experimental-pic -pie -o %t.wasm %t.o %t.internal_func.o
+# RUN: wasm-ld --no-gc-sections --experimental-pic -pie --unresolved-symbols=import-dynamic -o %t.wasm %t.o %t.internal_func.o
# RUN: obj2yaml %t.wasm | FileCheck %s
# RUN: llvm-objdump --disassemble-symbols=__wasm_call_ctors,__wasm_apply_data_relocs --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DISASSEM
@@ -150,7 +150,7 @@ _start:
# instruction in the InitExpr. We also, therefore, do not need these globals
# to be mutable.
-# RUN: wasm-ld --no-gc-sections --experimental-pic -pie --extra-features=extended-const -o %t.extended.wasm %t.o %t.internal_func.o
+# RUN: wasm-ld --no-gc-sections --experimental-pic -pie --unresolved-symbols=import-dynamic --extra-features=extended-const -o %t.extended.wasm %t.o %t.internal_func.o
# RUN: obj2yaml %t.extended.wasm | FileCheck %s --check-prefix=EXTENDED-CONST
# EXTENDED-CONST-NOT: __wasm_apply_global_relocs
@@ -207,7 +207,7 @@ _start:
# to be generated along with __wasm_start as the start
# function.
-# RUN: wasm-ld --no-gc-sections --shared-memory --experimental-pic -pie -o %t.shmem.wasm %t.o %t.internal_func.o
+# RUN: wasm-ld --no-gc-sections --shared-memory --experimental-pic -pie --unresolved-symbols=import-dynamic -o %t.shmem.wasm %t.o %t.internal_func.o
# RUN: obj2yaml %t.shmem.wasm | FileCheck %s --check-prefix=SHMEM
# RUN: llvm-objdump --disassemble-symbols=__wasm_start --no-show-raw-insn --no-leading-addr %t.shmem.wasm | FileCheck %s --check-prefix DISASSEM-SHMEM
diff --git a/lld/test/wasm/shared-needed.s b/lld/test/wasm/shared-needed.s
index 12c4597190a3b5..0176da832d2b19 100644
--- a/lld/test/wasm/shared-needed.s
+++ b/lld/test/wasm/shared-needed.s
@@ -1,17 +1,27 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/ret32.s -o %t.ret32.o
-# RUN: wasm-ld -shared --experimental-pic -o %t1.so %t.o
-# RUN: obj2yaml %t1.so | FileCheck %s -check-prefix=SO1
+# RUN: wasm-ld -shared --experimental-pic -o %t.ret32.so %t.ret32.o
+# RUN: obj2yaml %t.ret32.so | FileCheck %s -check-prefix=SO1
+
+# With linking against the ret32.so shared object we expect and undefined
+# symbol error
+# RUN: not wasm-ld -shared --experimental-pic -o %t.so %t.o 2>&1 | FileCheck %s --check-prefix=ERROR
+# ERROR: undefined symbol: ret32
+
+# RUN: wasm-ld -shared --experimental-pic -o %t.so %t.o %t.ret32.so
+# RUN: obj2yaml %t.so | FileCheck %s -check-prefix=SO2
-# RUN: wasm-ld -shared --experimental-pic -o %t2.so %t1.so %t.ret32.o
-# RUN: obj2yaml %t2.so | FileCheck %s -check-prefix=SO2
.globl foo
.globl data
+.functype ret32 (f32) -> (i32)
+
foo:
- .functype foo () -> ()
+ .functype foo (f32) -> (i32)
+ local.get 0
+ call ret32
end_function
.section .data,"",@
@@ -24,8 +34,8 @@ data:
# SO1: Sections:
# SO1-NEXT: - Type: CUSTOM
# SO1-NEXT: Name: dylink.0
-# SO1-NEXT: MemorySize: 4
-# SO1-NEXT: MemoryAlignment: 2
+# SO1-NEXT: MemorySize: 0
+# SO1-NEXT: MemoryAlignment: 0
# SO1-NEXT: TableSize: 0
# SO1-NEXT: TableAlignment: 0
# SO1-NEXT: Needed: []
@@ -34,10 +44,10 @@ data:
# SO2: Sections:
# SO2-NEXT: - Type: CUSTOM
# SO2-NEXT: Name: dylink.0
-# SO2-NEXT: MemorySize: 0
-# SO2-NEXT: MemoryAlignment: 0
+# SO2-NEXT: MemorySize: 4
+# SO2-NEXT: MemoryAlignment: 2
# SO2-NEXT: TableSize: 0
# SO2-NEXT: TableAlignment: 0
# SO2-NEXT: Needed:
-# SO2-NEXT: - shared-needed.s.tmp1.so
+# SO2-NEXT: - shared-needed.s.tmp.ret32.so
# SO2-NEXT: - Type: TYPE
diff --git a/lld/test/wasm/shared.s b/lld/test/wasm/shared.s
index a26f00163fea70..5b40d4ebee7abc 100644
--- a/lld/test/wasm/shared.s
+++ b/lld/test/wasm/shared.s
@@ -1,5 +1,5 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
-# RUN: wasm-ld --experimental-pic -shared -o %t.wasm %t.o
+# RUN: wasm-ld --experimental-pic --unresolved-symbols=import-dynamic -shared -o %t.wasm %t.o
# RUN: obj2yaml %t.wasm | FileCheck %s
# RUN: llvm-objdump --disassemble-symbols=__wasm_call_ctors,__wasm_apply_data_relocs --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS
@@ -7,8 +7,8 @@
# Linker-synthesized globals
.globaltype __stack_pointer, i32
-.globaltype __table_base, i32, immutable
-.globaltype __memory_base, i32, immutable
+.globaltype __table_base, i32, immutable
+.globaltype __memory_base, i32, immutable
.section .data.data,"",@
data:
diff --git a/lld/test/wasm/shared64.s b/lld/test/wasm/shared64.s
index 3401faed8610c1..fba73f187679a6 100644
--- a/lld/test/wasm/shared64.s
+++ b/lld/test/wasm/shared64.s
@@ -1,5 +1,5 @@
# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-unknown -o %t.o %s
-# RUN: wasm-ld -mwasm64 --experimental-pic -shared -o %t.wasm %t.o
+# RUN: wasm-ld -mwasm64 --experimental-pic --unresolved-symbols=import-dynamic -shared -o %t.wasm %t.o
# RUN: obj2yaml %t.wasm | FileCheck %s
# RUN: llvm-objdump --disassemble-symbols=__wasm_call_ctors,__wasm_apply_data_relocs --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS
diff --git a/lld/test/wasm/signature-mismatch.s b/lld/test/wasm/signature-mismatch.s
index 5d305efca24649..e9da3073dde87c 100644
--- a/lld/test/wasm/signature-mismatch.s
+++ b/lld/test/wasm/signature-mismatch.s
@@ -84,7 +84,7 @@ ret32_address_main:
# RELOC-NEXT: - Index: 1
# RELOC-NEXT: Kind: FUNCTION
# RELOC-NEXT: Name: ret32
-# RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
+# RELOC-NEXT: Flags: [ ]
# RELOC-NEXT: Function: 2
# RELOC-NEXT: - Index: 2
# RELOC-NEXT: Kind: DATA
diff --git a/lld/test/wasm/tag-section.ll b/lld/test/wasm/tag-section.ll
index 4decdb58f952a9..20823c72c65116 100644
--- a/lld/test/wasm/tag-section.ll
+++ b/lld/test/wasm/tag-section.ll
@@ -11,7 +11,7 @@
; RUN: llc -filetype=obj -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling -relocation-model=pic %p/Inputs/tag-section1.ll -o %t1.o
; RUN: llc -filetype=obj -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling -relocation-model=pic %p/Inputs/tag-section2.ll -o %t2.o
; RUN: llc -filetype=obj -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling -relocation-model=pic %s -o %t.o
-; RUN: wasm-ld --import-undefined --experimental-pic -pie -o %t.wasm %t.o %t1.o %t2.o
+; RUN: wasm-ld --import-undefined --experimental-pic --unresolved-symbols=import-dynamic -pie -o %t.wasm %t.o %t1.o %t2.o
; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefix=PIC
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
diff --git a/lld/test/wasm/undef-shared.s b/lld/test/wasm/undef-shared.s
new file mode 100644
index 00000000000000..4c270880ef531d
--- /dev/null
+++ b/lld/test/wasm/undef-shared.s
@@ -0,0 +1,12 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
+# RUN: not wasm-ld --experimental-pic %t.o -o /dev/null -shared 2>&1 | FileCheck %s
+
+# CHECK: error: {{.*}}: undefined symbol: hidden
+.global hidden
+.hidden hidden
+
+.global foo
+.section .data,"",@
+foo:
+ .int32 hidden
+ .size foo,4
diff --git a/lld/test/wasm/undefined-data.s b/lld/test/wasm/undefined-data.s
index d63b667c4ea38b..5e2a41606612ab 100644
--- a/lld/test/wasm/undefined-data.s
+++ b/lld/test/wasm/undefined-data.s
@@ -1,7 +1,7 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: not wasm-ld -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=UNDEF
# RUN: wasm-ld --allow-undefined -o %t.wasm %t.o
-# RUN: not wasm-ld --shared -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=SHARED
+# RUN: not wasm-ld --experimental-pic -shared --unresolved-symbols=import-dynamic -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=SHARED
.globl _start
_start:
diff --git a/lld/test/wasm/unresolved-symbols.s b/lld/test/wasm/unresolved-symbols.s
index 5de54d76c6de81..ebb5acc6876c9d 100644
--- a/lld/test/wasm/unresolved-symbols.s
+++ b/lld/test/wasm/unresolved-symbols.s
@@ -80,7 +80,7 @@
.functype get_func_addr () -> (i32)
## import-dynamic should fail due to incompatible relocations.
-# RUN: not wasm-ld %t1.o -o %t5.wasm --unresolved-symbols=import-dynamic 2>&1 | FileCheck -check-prefix=ERRNOPIC %s
+# RUN: not wasm-ld %t1.o -o %t5.wasm --experimental-pic --unresolved-symbols=import-dynamic 2>&1 | FileCheck -check-prefix=ERRNOPIC %s
# ERRNOPIC: relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `undef_data`; recompile with -fPIC
# ERRNOPIC: relocation R_WASM_TABLE_INDEX_SLEB cannot be used against symbol `undef_func`; recompile with -fPIC
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 96ac1e1610dd3b..6ef4769beed695 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -178,7 +178,7 @@ uint64_t ObjFile::calcNewValue(const WasmRelocation &reloc, uint64_t tombstone,
case R_WASM_MEMORY_ADDR_TLS_SLEB:
case R_WASM_MEMORY_ADDR_TLS_SLEB64:
case R_WASM_MEMORY_ADDR_LOCREL_I32: {
- if (isa<UndefinedData>(sym) || sym->isUndefWeak())
+ if (isa<UndefinedData>(sym) || sym->isShared() || sym->isUndefWeak())
return 0;
auto D = cast<DefinedData>(sym);
uint64_t value = D->getVA() + reloc.Addend;
@@ -391,7 +391,36 @@ static bool shouldMerge(const WasmSegment &seg) {
return true;
}
-void ObjFile::parse(bool ignoreComdats) {
+void SharedFile::parse() {
+ WasmFileBase::parse();
+ assert(wasmObj->isSharedObject());
+
+ for (const SymbolRef &sym : wasmObj->symbols()) {
+ const WasmSymbol &wasmSym = wasmObj->getWasmSymbol(sym.getRawDataRefImpl());
+ if (wasmSym.isDefined()) {
+ StringRef name = wasmSym.Info.Name;
+ uint32_t flags = wasmSym.Info.Flags;
+ Symbol *s;
+ LLVM_DEBUG(dbgs() << "shared symbol: " << name << "\n");
+ switch (wasmSym.Info.Kind) {
+ case WASM_SYMBOL_TYPE_FUNCTION:
+ if (name == "__wasm_apply_data_relocs" || name == "__wasm_call_ctors") {
+ continue;
+ }
+ s = symtab->addSharedFunction(name, flags, this, wasmSym.Signature);
+ break;
+ case WASM_SYMBOL_TYPE_DATA:
+ s = symtab->addSharedData(name, flags, this);
+ break;
+ default:
+ continue;
+ }
+ symbols.push_back(s);
+ }
+ }
+}
+
+void WasmFileBase::parse() {
// Parse a memory buffer as a wasm file.
LLVM_DEBUG(dbgs() << "Parsing object: " << toString(this) << "\n");
std::unique_ptr<Binary> bin = CHECK(createBinary(mb), toString(this));
@@ -399,13 +428,18 @@ void ObjFile::parse(bool ignoreComdats) {
auto *obj = dyn_cast<WasmObjectFile>(bin.get());
if (!obj)
fatal(toString(this) + ": not a wasm file");
- if (!obj->isRelocatableObject())
- fatal(toString(this) + ": not a relocatable wasm file");
bin.release();
wasmObj.reset(obj);
checkArch(obj->getArch());
+}
+
+void ObjFile::parse(bool ignoreComdats) {
+ WasmFileBase::parse();
+
+ if (!wasmObj->isRelocatableObject())
+ fatal(toString(this) + ": not a relocatable wasm file");
// Build...
[truncated]
|
0a14bef
to
9b5bbe6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The biggest part of this change is the addition of the new symbol kind. Can you add to the commit message describing that (maybe it even needs to be the commit title? not sure). And can you also add a tool-conventions change to document?
9b5bbe6
to
d35a345
Compare
d35a345
to
68803c1
Compare
68803c1
to
38ff861
Compare
I've updated the PR description to give more detail. This change doesn't actually add a new symbol kind anywhere except internally within the linker. All we are doing is making use of existing information which was previously being ignored by the linker. |
38ff861
to
3e5b127
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any tests for -no-shlib-sigcheck?
6cf72c9
to
8d62e57
Compare
…uilds Previously we would ignore all undefined symbols when using `-shared` or `-pie`. All undefined symbols would be treated as imports regardless of whether those symbols we defined in any shared library. With this change we now track symbol in shared libraries and report undefined symbols in the main program by default. The old behavior is still available via the `--unresolved-symbols=import-dynamic` command line flag. This rationale for allowing this type of breaking change is that `-pie` and `-shared` are both still experimental will warn as such, unless `--experimental-pic` is passed. As part of this change the linker now models shared library symbols via new SharedFunctionSymbol and SharedDataSymbol types. I've also added a new `--no-shlib-sigcheck` option that bypassed the checking of functions signature in shared libraries. This is specifically required by emscripten the case where the imports/exports of shared libraries have been modified by via JS type legalization (this is only needed when targeting old JS engines where bigint is not yet available See emscripten-core/emscripten#18198
8d62e57
to
000519d
Compare
Test added. |
PTAL |
@@ -323,6 +330,12 @@ class DefinedData : public DataSymbol { | |||
uint64_t size = 0; | |||
}; | |||
|
|||
class SharedData : public DataSymbol { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this class be called SharedDataSymbol
for consistency with functions and with the base class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it looks like the larger symbol class hierarchy is fairly inconsistent here. so changing just this class wouldn't really fix that.
This allows llvm/llvm-project#75242 to roll in.
This allows llvm/llvm-project#75242 to roll in. Also rename MIN_INT53 in library_int53.js to avoid conflicts with runtime_debug.js (this is needed because I enabled WASM_BIGINT in these tests which pulls in library_int53.js in more tests).
This allows llvm/llvm-project#75242 to roll in. Also, rename MIN_INT53 in library_int53.js to avoid conflicts with runtime_debug.js (this is needed because I enabled WASM_BIGINT in these tests which pulls in library_int53.js in more tests).
This allows llvm/llvm-project#75242 to roll in. Also rename MIN_INT53 in library_int53.js to avoid conflicts with runtime_debug.js (this is needed because I enabled WASM_BIGINT in these tests which pulls in library_int53.js in more tests).
Followup to #22231 to allow the llvm roller to succeed. See llvm/llvm-project#75242.
The llvm change that includes `--no-shlib-sigcheck` has now langed (llvm/llvm-project#75242) so we can use that instead.
See llvm/llvm-project#98778 This issue only started showing up after the recent llvm change where shared libraries are actually processed by the linker: llvm/llvm-project#75242
See llvm/llvm-project#98778 This issue only started showing up after the recent llvm change where shared libraries are actually processed by the linker: llvm/llvm-project#75242
See llvm/llvm-project#98778 This issue only started showing up after the recent llvm change where shared libraries are actually processed by the linker: llvm/llvm-project#75242
…2240) See llvm/llvm-project#98778 This issue only started showing up after the recent llvm change where shared libraries are actually processed by the linker: llvm/llvm-project#75242
The llvm change that includes `--no-shlib-sigcheck` has now langed (llvm/llvm-project#75242) so we can use that instead.
The llvm change that includes `--no-shlib-sigcheck` has now langed (llvm/llvm-project#75242) so we can use that instead.
…lvm#75242) Previously we would ignore all undefined symbols when using `-shared` or `-pie`. All undefined symbols would be treated as imports regardless of whether those symbols we defined in any shared library. With this change we now track symbol in shared libraries and report undefined symbols in the main program by default. The old behavior is still available via the `--unresolved-symbols=import-dynamic` command line flag. This rationale for allowing this type of breaking change is that `-pie` and `-shared` are both still experimental will warn as such, unless `--experimental-pic` is passed. As part of this change the linker now models shared library symbols via new SharedFunctionSymbol and SharedDataSymbol types. I've also added a new `--no-shlib-sigcheck` option that bypassed the checking of functions signature in shared libraries. This is specifically required by emscripten the case where the imports/exports of shared libraries have been modified by via JS type legalization (this is only needed when targeting old JS engines where bigint is not yet available See emscripten-core/emscripten#18198
The llvm change that includes `--no-shlib-sigcheck` has now langed (llvm/llvm-project#75242) so we can use that instead.
This allows llvm/llvm-project#75242 to roll in. Also, rename MIN_INT53 in library_int53.js to avoid conflicts with runtime_debug.js (this is needed because I enabled WASM_BIGINT in these tests which pulls in library_int53.js in more tests).
Followup to emscripten-core#22231 to allow the llvm roller to succeed. See llvm/llvm-project#75242.
…scripten-core#22240) See llvm/llvm-project#98778 This issue only started showing up after the recent llvm change where shared libraries are actually processed by the linker: llvm/llvm-project#75242
…ten-core#22238) The llvm change that includes `--no-shlib-sigcheck` has now langed (llvm/llvm-project#75242) so we can use that instead.
Previously we would ignore all undefined symbols when using
-shared
or-pie
. All undefined symbols would be treated as importsregardless of whether those symbols we defined in any shared library.
With this change we now track symbol in shared libraries and report
undefined symbols in the main program by default.
The old behavior is still available via the
--unresolved-symbols=import-dynamic
command line flag.This rationale for allowing this type of breaking change is that
-pie
and
-shared
are both still experimental will warn as such, unless--experimental-pic
is passed.As part of this change the linker now models shared library symbols
via new SharedFunctionSymbol and SharedDataSymbol types.
I've also added a new
--no-shlib-sigcheck
option that bypassed thechecking of functions signature in shared libraries. This is
specifically required by emscripten the case where the imports/exports
of shared libraries have been modified by via JS type legalization (this
is only needed when targeting old JS engines where bigint is not yet
available
See emscripten-core/emscripten#18198