[lld] [lld][WebAssembly] Report undefined symbols by default -shared/-pie builds (PR #75242)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 20 12:19:49 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld
Author: Sam Clegg (sbc100)
<details>
<summary>Changes</summary>
Previously we would ignore/import all undefined symbols when using
`-shared` or `-pie`. With this change we now track symbol in shared
libraries and report undefined symbols by default.
The old behaviour is still possible via the
`--unresolved-symbols=import-dynamic flag.
The rationale here is that changing the semantics like this is
reasonable since `-pie` and `-shared` are both still experimental will
warn as such unless `--experimental-pic` is passed.
Depends on (and currently includes)
https://github.com/llvm/llvm-project/pull/75238
---
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:
- (modified) lld/test/wasm/Inputs/ret32.s (-1)
- (added) lld/test/wasm/dylink.s (+30)
- (modified) lld/test/wasm/emit-relocs.s (+1-1)
- (modified) lld/test/wasm/libsearch.s (+31-31)
- (modified) lld/test/wasm/pie.s (+3-3)
- (modified) lld/test/wasm/shared-needed.s (+20-10)
- (modified) lld/test/wasm/shared.s (+3-3)
- (modified) lld/test/wasm/shared64.s (+1-1)
- (modified) lld/test/wasm/signature-mismatch.s (+1-1)
- (modified) lld/test/wasm/tag-section.ll (+1-1)
- (added) lld/test/wasm/undef-shared.s (+12)
- (modified) lld/test/wasm/undefined-data.s (+1-1)
- (modified) lld/test/wasm/unresolved-symbols.s (+1-1)
- (modified) lld/wasm/InputFiles.cpp (+39-4)
- (modified) lld/wasm/InputFiles.h (+20-9)
- (modified) lld/wasm/MarkLive.cpp (+3-2)
- (modified) lld/wasm/Relocations.cpp (+9-4)
- (modified) lld/wasm/SymbolTable.cpp (+76)
- (modified) lld/wasm/SymbolTable.h (+3)
- (modified) lld/wasm/Symbols.cpp (+6-1)
- (modified) lld/wasm/Symbols.h (+25-1)
- (modified) lld/wasm/SyntheticSections.cpp (+2-2)
- (modified) lld/wasm/Writer.cpp (+6-2)
``````````diff
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 at 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]
``````````
</details>
https://github.com/llvm/llvm-project/pull/75242
More information about the llvm-commits
mailing list