summaryrefslogtreecommitdiff
path: root/test/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'test/wasm')
-rw-r--r--test/wasm/Inputs/event-section1.ll9
-rw-r--r--test/wasm/Inputs/event-section2.ll9
-rw-r--r--test/wasm/Inputs/globals.yaml2
-rw-r--r--test/wasm/Inputs/undefined-globals.yaml2
-rw-r--r--test/wasm/alias.ll4
-rw-r--r--test/wasm/archive-export.ll50
-rw-r--r--test/wasm/archive.ll1
-rw-r--r--test/wasm/call-indirect.ll10
-rw-r--r--test/wasm/comdats.ll2
-rw-r--r--test/wasm/compress-relocs.ll10
-rw-r--r--test/wasm/cxx-mangling.ll20
-rw-r--r--test/wasm/data-layout.ll10
-rw-r--r--test/wasm/data-segment-merging.ll51
-rw-r--r--test/wasm/debug-removed-fn.ll44
-rw-r--r--test/wasm/debuginfo.test4
-rw-r--r--test/wasm/demangle.ll14
-rw-r--r--test/wasm/event-section.ll34
-rw-r--r--test/wasm/export-all.ll2
-rw-r--r--test/wasm/export-table.test2
-rw-r--r--test/wasm/export.ll6
-rw-r--r--test/wasm/import-memory.test17
-rw-r--r--test/wasm/import-table.test4
-rw-r--r--test/wasm/load-undefined.test14
-rw-r--r--test/wasm/local-symbols.ll5
-rw-r--r--test/wasm/locals-duplicate.test14
-rw-r--r--test/wasm/lto/archive.ll2
-rw-r--r--test/wasm/lto/cache.ll8
-rw-r--r--test/wasm/lto/export.ll6
-rw-r--r--test/wasm/lto/signature-mismatch.ll19
-rw-r--r--test/wasm/many-functions.ll6
-rw-r--r--test/wasm/relocatable.ll16
-rw-r--r--test/wasm/shared.ll82
-rw-r--r--test/wasm/signature-mismatch-weak.ll4
-rw-r--r--test/wasm/signature-mismatch.ll8
-rw-r--r--test/wasm/stack-pointer.ll4
-rw-r--r--test/wasm/strip-all.test10
-rw-r--r--test/wasm/strip-debug.test4
-rw-r--r--test/wasm/undefined-entry.test8
-rw-r--r--test/wasm/undefined-weak-call.ll4
-rw-r--r--test/wasm/undefined.ll4
-rw-r--r--test/wasm/visibility-hidden.ll36
-rw-r--r--test/wasm/weak-alias-overide.ll10
-rw-r--r--test/wasm/weak-alias.ll8
-rw-r--r--test/wasm/weak-symbols.ll17
-rw-r--r--test/wasm/weak-undefined.ll13
45 files changed, 452 insertions, 157 deletions
diff --git a/test/wasm/Inputs/event-section1.ll b/test/wasm/Inputs/event-section1.ll
new file mode 100644
index 0000000000000..89d9e87162f5a
--- /dev/null
+++ b/test/wasm/Inputs/event-section1.ll
@@ -0,0 +1,9 @@
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+declare void @llvm.wasm.throw(i32, i8*)
+
+define void @foo(i8* %p) {
+ call void @llvm.wasm.throw(i32 0, i8* %p)
+ ret void
+}
diff --git a/test/wasm/Inputs/event-section2.ll b/test/wasm/Inputs/event-section2.ll
new file mode 100644
index 0000000000000..3499db9298afa
--- /dev/null
+++ b/test/wasm/Inputs/event-section2.ll
@@ -0,0 +1,9 @@
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+declare void @llvm.wasm.throw(i32, i8*)
+
+define void @bar(i8* %p) {
+ call void @llvm.wasm.throw(i32 0, i8* %p)
+ ret void
+}
diff --git a/test/wasm/Inputs/globals.yaml b/test/wasm/Inputs/globals.yaml
index c08a3044ec950..a2c4602294efa 100644
--- a/test/wasm/Inputs/globals.yaml
+++ b/test/wasm/Inputs/globals.yaml
@@ -34,7 +34,7 @@ Sections:
Offset: 0x00000004
- Type: CUSTOM
Name: linking
- Version: 1
+ Version: 2
SymbolTable:
- Index: 0
Kind: GLOBAL
diff --git a/test/wasm/Inputs/undefined-globals.yaml b/test/wasm/Inputs/undefined-globals.yaml
index 440a538d6587c..49cf8811f8129 100644
--- a/test/wasm/Inputs/undefined-globals.yaml
+++ b/test/wasm/Inputs/undefined-globals.yaml
@@ -32,7 +32,7 @@ Sections:
Offset: 0x00000004
- Type: CUSTOM
Name: linking
- Version: 1
+ Version: 2
SymbolTable:
- Index: 0
Kind: GLOBAL
diff --git a/test/wasm/alias.ll b/test/wasm/alias.ll
index f88452e538c45..358582ea1520e 100644
--- a/test/wasm/alias.ll
+++ b/test/wasm/alias.ll
@@ -1,5 +1,5 @@
; RUN: llc -filetype=obj -o %t.o %s
-; RUN: wasm-ld %t.o -o %t.wasm
+; RUN: wasm-ld --export=start_alias %t.o -o %t.wasm
; RUN: obj2yaml %t.wasm | FileCheck %s
target triple = "wasm32-unknown-unknown"
@@ -25,7 +25,7 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 0 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000001
diff --git a/test/wasm/archive-export.ll b/test/wasm/archive-export.ll
new file mode 100644
index 0000000000000..37256ce37244b
--- /dev/null
+++ b/test/wasm/archive-export.ll
@@ -0,0 +1,50 @@
+Test that --export will also fetch lazy symbols from archives
+
+RUN: llc -filetype=obj %S/Inputs/start.ll -o %t.o
+RUN: llc -filetype=obj %S/Inputs/archive1.ll -o %t.a1.o
+RUN: llc -filetype=obj %S/Inputs/archive2.ll -o %t.a2.o
+RUN: rm -f %t.a
+RUN: llvm-ar rcs %t.a %t.a1.o %t.a2.o
+RUN: wasm-ld --export-dynamic --export=archive2_symbol -o %t.wasm %t.a %t.o
+RUN: obj2yaml %t.wasm | FileCheck %s
+RUN: wasm-ld --export-dynamic -o %t.wasm %t.a %t.o
+RUN: obj2yaml %t.wasm | FileCheck %s -check-prefix=NOEXPORT
+
+CHECK: Exports:
+CHECK-NEXT: - Name: memory
+CHECK-NEXT: Kind: MEMORY
+CHECK-NEXT: Index: 0
+CHECK-NEXT: - Name: __heap_base
+CHECK-NEXT: Kind: GLOBAL
+CHECK-NEXT: Index: 1
+CHECK-NEXT: - Name: __data_end
+CHECK-NEXT: Kind: GLOBAL
+CHECK-NEXT: Index: 2
+CHECK-NEXT: - Name: foo
+CHECK-NEXT: Kind: FUNCTION
+CHECK-NEXT: Index: 2
+CHECK-NEXT: - Name: bar
+CHECK-NEXT: Kind: FUNCTION
+CHECK-NEXT: Index: 3
+CHECK-NEXT: - Name: archive2_symbol
+CHECK-NEXT: Kind: FUNCTION
+CHECK-NEXT: Index: 4
+CHECK-NEXT: - Name: _start
+CHECK-NEXT: Kind: FUNCTION
+CHECK-NEXT: Index: 1
+CHECK-NEXT: - Type: CODE
+
+NOEXPORT: Exports:
+NOEXPORT-NEXT: - Name: memory
+NOEXPORT-NEXT: Kind: MEMORY
+NOEXPORT-NEXT: Index: 0
+NOEXPORT-NEXT: - Name: __heap_base
+NOEXPORT-NEXT: Kind: GLOBAL
+NOEXPORT-NEXT: Index: 1
+NOEXPORT-NEXT: - Name: __data_end
+NOEXPORT-NEXT: Kind: GLOBAL
+NOEXPORT-NEXT: Index: 2
+NOEXPORT-NEXT: - Name: _start
+NOEXPORT-NEXT: Kind: FUNCTION
+NOEXPORT-NEXT: Index: 1
+NOEXPORT-NEXT: - Type: CODE
diff --git a/test/wasm/archive.ll b/test/wasm/archive.ll
index 50f72d6273860..beea2725cff97 100644
--- a/test/wasm/archive.ll
+++ b/test/wasm/archive.ll
@@ -3,6 +3,7 @@
; RUN: llc -filetype=obj %S/Inputs/archive2.ll -o %t.a2.o
; RUN: llc -filetype=obj %S/Inputs/archive3.ll -o %t.a3.o
; RUN: llc -filetype=obj %S/Inputs/hello.ll -o %t.hello.o
+; RUN: rm -f %t.a
; RUN: llvm-ar rcs %t.a %t.a1.o %t.a2.o %t.a3.o %t.hello.o
; RUN: rm -f %t.imports
; RUN: not wasm-ld %t.a %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-UNDEFINED %s
diff --git a/test/wasm/call-indirect.ll b/test/wasm/call-indirect.ll
index 63a6def873822..7f8fe474f414d 100644
--- a/test/wasm/call-indirect.ll
+++ b/test/wasm/call-indirect.ll
@@ -1,6 +1,6 @@
; RUN: llc -filetype=obj %p/Inputs/call-indirect.ll -o %t2.o
; RUN: llc -filetype=obj %s -o %t.o
-; RUN: wasm-ld -o %t.wasm %t2.o %t.o
+; RUN: wasm-ld --export-dynamic -o %t.wasm %t2.o %t.o
; RUN: obj2yaml %t.wasm | FileCheck %s
; bitcode generated from the following C code:
@@ -60,7 +60,7 @@ define void @call_ptr(i64 (i64)* %arg) {
; CHECK-NEXT: FunctionTypes: [ 3, 0, 3, 1, 3, 4 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000003
@@ -105,9 +105,6 @@ define void @call_ptr(i64 (i64)* %arg) {
; CHECK-NEXT: - Name: __data_end
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 2
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 4
; CHECK-NEXT: - Name: bar
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
@@ -117,6 +114,9 @@ define void @call_ptr(i64 (i64)* %arg) {
; CHECK-NEXT: - Name: foo
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 3
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 4
; CHECK-NEXT: - Name: indirect_func
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 3
diff --git a/test/wasm/comdats.ll b/test/wasm/comdats.ll
index d0bec4cda1465..9baea22050efb 100644
--- a/test/wasm/comdats.ll
+++ b/test/wasm/comdats.ll
@@ -1,7 +1,7 @@
; RUN: llc -filetype=obj -mtriple=wasm32-unknown-uknown-wasm %p/Inputs/comdat1.ll -o %t1.o
; RUN: llc -filetype=obj -mtriple=wasm32-unknown-uknown-wasm %p/Inputs/comdat2.ll -o %t2.o
; RUN: llc -filetype=obj -mtriple=wasm32-unknown-uknown-wasm %s -o %t.o
-; RUN: wasm-ld -o %t.wasm %t.o %t1.o %t2.o
+; RUN: wasm-ld --export-dynamic -o %t.wasm %t.o %t1.o %t2.o
; RUN: obj2yaml %t.wasm | FileCheck %s
target triple = "wasm32-unknown-unknown"
diff --git a/test/wasm/compress-relocs.ll b/test/wasm/compress-relocs.ll
index b137d5abd43e3..d14ea26a4c334 100644
--- a/test/wasm/compress-relocs.ll
+++ b/test/wasm/compress-relocs.ll
@@ -1,9 +1,11 @@
; RUN: llc -filetype=obj %p/Inputs/call-indirect.ll -o %t2.o
; RUN: llc -filetype=obj %s -o %t.o
-; RUN: wasm-ld -o %t.wasm %t2.o %t.o
+; RUN: wasm-ld --export-dynamic -o %t.wasm %t2.o %t.o
; RUN: obj2yaml %t.wasm | FileCheck %s
-
-; RUN: wasm-ld -O2 -o %t-compressed.wasm %t2.o %t.o
+; RUN: wasm-ld --export-dynamic -O2 -o %t-opt.wasm %t2.o %t.o
+; RUN: obj2yaml %t-opt.wasm | FileCheck %s
+; RUN: not wasm-ld --compress-relocations -o %t-compressed.wasm %t2.o %t.o 2>&1 | FileCheck %s -check-prefix=ERROR
+; RUN: wasm-ld --export-dynamic --strip-debug --compress-relocations -o %t-compressed.wasm %t2.o %t.o
; RUN: obj2yaml %t-compressed.wasm | FileCheck %s -check-prefix=COMPRESS
target triple = "wasm32-unknown-unknown-wasm"
@@ -18,5 +20,7 @@ entry:
ret void
}
+; ERROR: wasm-ld: error: --compress-relocations is incompatible with output debug information. Please pass --strip-debug or --strip-all
+
; CHECK: Body: 4100280284888080002100410028028088808000118080808000001A2000118180808000001A0B
; COMPRESS: Body: 41002802840821004100280280081100001A20001101001A0B
diff --git a/test/wasm/cxx-mangling.ll b/test/wasm/cxx-mangling.ll
index 67f3594e8166a..e1f4ea4950a64 100644
--- a/test/wasm/cxx-mangling.ll
+++ b/test/wasm/cxx-mangling.ll
@@ -1,8 +1,8 @@
; RUN: llc -filetype=obj %s -o %t.o
-; RUN: wasm-ld --demangle -o %t_demangle.wasm %t.o
-; RUN: obj2yaml %t_demangle.wasm | FileCheck %s
-; RUN: wasm-ld --no-demangle -o %t_nodemangle.wasm %t.o
-; RUN: obj2yaml %t_nodemangle.wasm | FileCheck %s
+; RUN: wasm-ld --export=_Z3fooi --demangle -o %t_demangle.wasm %t.o
+; RUN: obj2yaml %t_demangle.wasm | FileCheck --check-prefixes=CHECK,DEMANGLE %s
+; RUN: wasm-ld --export=_Z3fooi --no-demangle -o %t_nodemangle.wasm %t.o
+; RUN: obj2yaml %t_nodemangle.wasm | FileCheck --check-prefixes=CHECK,MANGLE %s
target triple = "wasm32-unknown-unknown"
@@ -32,12 +32,12 @@ define void @_start() {
; CHECK-NEXT: - Name: __data_end
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 2
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 3
; CHECK-NEXT: - Name: _Z3fooi
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 2
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 3
; CHECK-NEXT: - Type: CODE
; CHECK-NEXT: Functions:
; CHECK-NEXT: - Index: 0
@@ -58,9 +58,11 @@ define void @_start() {
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Name: __wasm_call_ctors
; CHECK-NEXT: - Index: 1
-; CHECK-NEXT: Name: 'undefined function bar(int)'
+; DEMANGLE-NEXT: Name: 'undefined function bar(int)'
+; MANGLE-NEXT: Name: undefined function _Z3bari
; CHECK-NEXT: - Index: 2
-; CHECK-NEXT: Name: 'foo(int)'
+; DEMANGLE-NEXT: Name: 'foo(int)'
+; MANGLE-NEXT: Name: _Z3fooi
; CHECK-NEXT: - Index: 3
; CHECK-NEXT: Name: _start
; CHECK-NEXT: ...
diff --git a/test/wasm/data-layout.ll b/test/wasm/data-layout.ll
index 5fd3f2d7791cf..b01c13ac9b82a 100644
--- a/test/wasm/data-layout.ll
+++ b/test/wasm/data-layout.ll
@@ -68,6 +68,16 @@ target triple = "wasm32-unknown-unknown"
; CHECK-MAX-NEXT: Initial: 0x00000002
; CHECK-MAX-NEXT: Maximum: 0x00000002
+; RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry --shared-memory \
+; RUN: --initial-memory=131072 --max-memory=131072 -o %t_max.wasm %t.o \
+; RUN: %t.hello.o
+; RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-SHARED
+
+; CHECK-SHARED: - Type: MEMORY
+; CHECK-SHARED-NEXT: Memories:
+; CHECK-SHARED-NEXT: - Flags: [ HAS_MAX, IS_SHARED ]
+; CHECK-SHARED-NEXT: Initial: 0x00000002
+; CHECK-SHARED-NEXT: Maximum: 0x00000002
; RUN: wasm-ld --relocatable -o %t_reloc.wasm %t.o %t.hello.o
; RUN: obj2yaml %t_reloc.wasm | FileCheck %s -check-prefix=RELOC
diff --git a/test/wasm/data-segment-merging.ll b/test/wasm/data-segment-merging.ll
index d0df84d0fc237..2a48b2db6e37e 100644
--- a/test/wasm/data-segment-merging.ll
+++ b/test/wasm/data-segment-merging.ll
@@ -5,44 +5,27 @@ target triple = "wasm32-unknown-unknown"
@c = hidden global [9 x i8] c"whatever\00", align 1
@d = hidden global i32 42, align 4
+@e = private constant [9 x i8] c"constant\00", align 1
+@f = private constant i8 43, align 4
+
; RUN: llc -filetype=obj %s -o %t.data-segment-merging.o
; RUN: wasm-ld -no-gc-sections --no-entry -o %t.merged.wasm %t.data-segment-merging.o
; RUN: obj2yaml %t.merged.wasm | FileCheck %s --check-prefix=MERGE
-; MERGE: - Type: DATA
-; MERGE-NEXT: Segments:
-; MERGE-NEXT: - SectionOffset: 7
-; MERGE-NEXT: MemoryIndex: 0
-; MERGE-NEXT: Offset:
-; MERGE-NEXT: Opcode: I32_CONST
-; MERGE-NEXT: Value: 1024
-; MERGE-NEXT: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000
+; MERGE: - Type: DATA
+; MERGE: Segments:
+; MERGE: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000
+; MERGE: Content: 636F6E7374616E74000000002B
+; MERGE-NOT: Content:
; RUN: wasm-ld -no-gc-sections --no-entry --no-merge-data-segments -o %t.separate.wasm %t.data-segment-merging.o
; RUN: obj2yaml %t.separate.wasm | FileCheck %s --check-prefix=SEPARATE
-; SEPARATE: - Type: DATA
-; SEPARATE-NEXT: Segments:
-; SEPARATE-NEXT: - SectionOffset: 7
-; SEPARATE-NEXT: MemoryIndex: 0
-; SEPARATE-NEXT: Offset:
-; SEPARATE-NEXT: Opcode: I32_CONST
-; SEPARATE-NEXT: Value: 1024
-; SEPARATE-NEXT: Content: 68656C6C6F00
-; SEPARATE-NEXT: - SectionOffset: 19
-; SEPARATE-NEXT: MemoryIndex: 0
-; SEPARATE-NEXT: Offset:
-; SEPARATE-NEXT: Opcode: I32_CONST
-; SEPARATE-NEXT: Value: 1030
-; SEPARATE-NEXT: Content: 676F6F6462796500
-; SEPARATE-NEXT: - SectionOffset: 33
-; SEPARATE-NEXT: MemoryIndex: 0
-; SEPARATE-NEXT: Offset:
-; SEPARATE-NEXT: Opcode: I32_CONST
-; SEPARATE-NEXT: Value: 1038
-; SEPARATE-NEXT: Content: '776861746576657200'
-; SEPARATE-NEXT: - SectionOffset: 48
-; SEPARATE-NEXT: MemoryIndex: 0
-; SEPARATE-NEXT: Offset:
-; SEPARATE-NEXT: Opcode: I32_CONST
-; SEPARATE-NEXT: Value: 1048
-; SEPARATE-NEXT: Content: 2A000000
+; SEPARATE: - Type: DATA
+; SEPARATE: Segments:
+; SEPARATE: Content: 68656C6C6F00
+; SEPARATE: Content: 676F6F6462796500
+; SEPARATE: Content: '776861746576657200'
+; SEPARATE: Content: 2A000000
+; SEPARATE: Content: 636F6E7374616E7400
+; SEPARATE: Content: 2B
+; SEPARATE-NOT: Content:
diff --git a/test/wasm/debug-removed-fn.ll b/test/wasm/debug-removed-fn.ll
new file mode 100644
index 0000000000000..8f5f6507f3da7
--- /dev/null
+++ b/test/wasm/debug-removed-fn.ll
@@ -0,0 +1,44 @@
+; RUN: llc -filetype=obj < %s -o %t.o
+; RUN: wasm-ld %t.o --no-entry --export=foo -o %t.wasm
+; RUN: llvm-dwarfdump -debug-line %t.wasm | FileCheck %s
+
+; CHECK: Address
+; CHECK: 0x0000000000000005
+; CHECK: 0x0000000000000000
+
+; ModuleID = 't.bc'
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown-wasm"
+
+; Function Attrs: noinline nounwind optnone
+define hidden i32 @foo() #0 !dbg !7 {
+entry:
+ ret i32 42, !dbg !11
+}
+
+; Function Attrs: noinline nounwind optnone
+define hidden i32 @bar() #0 !dbg !12 {
+entry:
+ ret i32 6, !dbg !13
+}
+
+attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (trunk 337293)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "t.c", directory: "/d/y")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 7.0.0 (trunk 337293)"}
+!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DILocation(line: 2, column: 3, scope: !7)
+!12 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, isLocal: false, isDefinition: true, scopeLine: 5, isOptimized: false, unit: !0, retainedNodes: !2)
+!13 = !DILocation(line: 6, column: 3, scope: !12)
diff --git a/test/wasm/debuginfo.test b/test/wasm/debuginfo.test
index ce68a03bcbcec..3e07ad960842e 100644
--- a/test/wasm/debuginfo.test
+++ b/test/wasm/debuginfo.test
@@ -43,7 +43,7 @@ CHECK-NEXT: DW_AT_name ("hi_foo.c")
CHECK: DW_TAG_variable
CHECK-NEXT: DW_AT_name ("y")
-CHECK-NEXT: DW_AT_type (0x00000097 "int[]")
+CHECK-NEXT: DW_AT_type (0x00000097 "int[2]")
CHECK-NEXT: DW_AT_external (true)
CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
CHECK-NEXT: DW_AT_decl_line (1)
@@ -65,7 +65,7 @@ CHECK-NEXT: DW_AT_encoding (DW_ATE_unsigned)
CHECK: DW_TAG_variable
CHECK-NEXT: DW_AT_name ("z")
-CHECK-NEXT: DW_AT_type (0x00000097 "int[]")
+CHECK-NEXT: DW_AT_type (0x00000097 "int[2]")
CHECK-NEXT: DW_AT_external (true)
CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
CHECK-NEXT: DW_AT_decl_line (8)
diff --git a/test/wasm/demangle.ll b/test/wasm/demangle.ll
index f0416bb6b32f9..64fa46ae4dce4 100644
--- a/test/wasm/demangle.ll
+++ b/test/wasm/demangle.ll
@@ -1,17 +1,19 @@
; RUN: llc -filetype=obj %s -o %t.o
-; RUN: not wasm-ld --undefined _Z3fooi \
-; RUN: -o %t.wasm %t.o 2>&1 | FileCheck %s
+; RUN: not wasm-ld -o %t.wasm %t.o 2>&1 | FileCheck %s
-; CHECK: error: undefined symbol: foo(int)
+; CHECK: error: {{.*}}.o: undefined symbol: foo(int)
-; RUN: not wasm-ld --no-demangle --undefined _Z3fooi \
-; RUN: -o %t.wasm %t.o 2>&1 | FileCheck -check-prefix=CHECK-NODEMANGLE %s
+; RUN: not wasm-ld --no-demangle \
+; RUN: -o %t.wasm %t.o 2>&1 | FileCheck -check-prefix=CHECK-NODEMANGLE %s
-; CHECK-NODEMANGLE: error: undefined symbol: _Z3fooi
+; CHECK-NODEMANGLE: error: {{.*}}.o: undefined symbol: _Z3fooi
target triple = "wasm32-unknown-unknown"
+declare void @_Z3fooi(i32);
+
define hidden void @_start() local_unnamed_addr {
entry:
+ call void @_Z3fooi(i32 1)
ret void
}
diff --git a/test/wasm/event-section.ll b/test/wasm/event-section.ll
new file mode 100644
index 0000000000000..1610287b4a3bf
--- /dev/null
+++ b/test/wasm/event-section.ll
@@ -0,0 +1,34 @@
+; RUN: llc -filetype=obj -exception-model=wasm -mattr=+exception-handling %p/Inputs/event-section1.ll -o %t1.o
+; RUN: llc -filetype=obj -exception-model=wasm -mattr=+exception-handling %p/Inputs/event-section2.ll -o %t2.o
+; RUN: llc -filetype=obj -exception-model=wasm -mattr=+exception-handling %s -o %t.o
+; RUN: wasm-ld -o %t.wasm %t.o %t1.o %t2.o
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+declare void @foo(i8*)
+declare void @bar(i8*)
+
+define void @_start() {
+ call void @foo(i8* null)
+ call void @bar(i8* null)
+ ret void
+}
+
+; CHECK: Sections:
+; CHECK-NEXT: - Type: TYPE
+; CHECK-NEXT: Signatures:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: ReturnType: NORESULT
+; CHECK-NEXT: ParamTypes: []
+; CHECK-NEXT: - Index: 1
+; CHECK-NEXT: ReturnType: NORESULT
+; CHECK-NEXT: ParamTypes:
+; CHECK-NEXT: - I32
+
+; CHECK: - Type: EVENT
+; CHECK-NEXT: Events:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: Attribute: 0
+; CHECK-NEXT: SigIndex: 1
diff --git a/test/wasm/export-all.ll b/test/wasm/export-all.ll
index 34797aac76f71..f903df9160d37 100644
--- a/test/wasm/export-all.ll
+++ b/test/wasm/export-all.ll
@@ -42,7 +42,7 @@ entry:
; CHECK-NOT: - Name: internal_func
; EXPORT: - Type: EXPORT
-; EXPORT: - Name: _start
; EXPORT: - Name: bar
; EXPORT: - Name: foo
+; EXPORT: - Name: _start
; EXPORT-NOT: - Name: internal_func
diff --git a/test/wasm/export-table.test b/test/wasm/export-table.test
index 58775b928f7fa..e2d05f00d5a7b 100644
--- a/test/wasm/export-table.test
+++ b/test/wasm/export-table.test
@@ -6,7 +6,7 @@
# CHECK: - Type: TABLE
# CHECK-NEXT: Tables:
-# CHECK-NEXT: - ElemType: ANYFUNC
+# CHECK-NEXT: - ElemType: FUNCREF
# CHECK-NEXT: Limits:
# CHECK-NEXT: Flags: [ HAS_MAX ]
# CHECK-NEXT: Initial: 0x00000001
diff --git a/test/wasm/export.ll b/test/wasm/export.ll
index 16b2b6ca57cc0..519aafebbe232 100644
--- a/test/wasm/export.ll
+++ b/test/wasm/export.ll
@@ -28,10 +28,10 @@ entry:
; CHECK-NEXT: - Name: __data_end
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 2
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Name: hidden_function
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Type: CODE
diff --git a/test/wasm/import-memory.test b/test/wasm/import-memory.test
index 49bf06b748322..0a64afd6ce201 100644
--- a/test/wasm/import-memory.test
+++ b/test/wasm/import-memory.test
@@ -31,3 +31,20 @@
# CHECK-MAX-NEXT: Initial: 0x00000004
# CHECK-MAX-NEXT: Maximum: 0x00000005
# CHECK-MAX-NEXT: - Type:
+
+# RUN: wasm-ld --import-memory --shared-memory --initial-memory=262144 \
+# RUN: --max-memory=327680 -o %t.max.wasm %t.start.o
+# RUN: obj2yaml %t.max.wasm | FileCheck -check-prefix=CHECK-SHARED %s
+
+# Verify the --shared-memory flag works with imports
+
+# CHECK-SHARED: - Type: IMPORT
+# CHECK-SHARED-NEXT: Imports:
+# CHECK-SHARED-NEXT: - Module: env
+# CHECK-SHARED-NEXT: Field: memory
+# CHECK-SHARED-NEXT: Kind: MEMORY
+# CHECK-SHARED-NEXT: Memory:
+# CHECK-SHARED-NEXT: Flags: [ HAS_MAX, IS_SHARED ]
+# CHECK-SHARED-NEXT: Initial: 0x00000004
+# CHECK-SHARED-NEXT: Maximum: 0x00000005
+# CHECK-SHARED-NEXT: - Type:
diff --git a/test/wasm/import-table.test b/test/wasm/import-table.test
index eb767090292ac..440509b3483c4 100644
--- a/test/wasm/import-table.test
+++ b/test/wasm/import-table.test
@@ -10,9 +10,7 @@
# CHECK-NEXT: Field: __indirect_function_table
# CHECK-NEXT: Kind: TABLE
# CHECK-NEXT: Table:
-# CHECK-NEXT: ElemType: ANYFUNC
+# CHECK-NEXT: ElemType: FUNCREF
# CHECK-NEXT: Limits:
-# CHECK-NEXT: Flags: [ HAS_MAX ]
# CHECK-NEXT: Initial: 0x00000001
-# CHECK-NEXT: Maximum: 0x00000001
diff --git a/test/wasm/load-undefined.test b/test/wasm/load-undefined.test
index 160cb485ac34b..1b8d259d5b8dd 100644
--- a/test/wasm/load-undefined.test
+++ b/test/wasm/load-undefined.test
@@ -4,6 +4,7 @@
; RUN: llc -filetype=obj %S/Inputs/ret64.ll -o %t.o
; RUN: llc -filetype=obj %S/Inputs/ret32.ll -o %t2.o
; RUN: llc -filetype=obj %S/Inputs/start.ll -o %t.start.o
+; RUN: rm -f %t2.a
; RUN: llvm-ar rcs %t2.a %t2.o
; RUN: wasm-ld %t.start.o --no-gc-sections %t2.a %t.o -o %t.wasm -u ret32 --undefined ret64
; RUN: obj2yaml %t.wasm | FileCheck %s
@@ -17,9 +18,9 @@
; CHECK-NEXT: - Index: 1
; CHECK-NEXT: Name: _start
; CHECK-NEXT: - Index: 2
-; CHECK-NEXT: Name: ret32
-; CHECK-NEXT: - Index: 3
; CHECK-NEXT: Name: ret64
+; CHECK-NEXT: - Index: 3
+; CHECK-NEXT: Name: ret32
; CHECK-NEXT: ...
; NO-LOAD: Name: name
@@ -32,9 +33,6 @@
; NO-LOAD-NEXT: Name: ret64
; NO-LOAD-NEXT: ...
-; Verify that referencing a symbol that doesn't exist won't work
-; RUN: not wasm-ld %t.start.o -o %t.wasm -u symboldoesnotexist 2>&1 | FileCheck -check-prefix=CHECK-UNDEFINED1 %s
-; CHECK-UNDEFINED1: error: undefined symbol: symboldoesnotexist
-
-; RUN: not wasm-ld %t.start.o -o %t.wasm --undefined symboldoesnotexist --allow-undefined 2>&1 | FileCheck -check-prefix=CHECK-UNDEFINED2 %s
-; CHECK-UNDEFINED2: symbol forced with --undefined not found: symboldoesnotexist
+; Verify that referencing a symbol that is not found doesn't result in a link
+; failure. This matches the behaviour of the ELF linker.
+; RUN: wasm-ld %t.start.o -o %t.wasm -u symboldoesnotexist
diff --git a/test/wasm/local-symbols.ll b/test/wasm/local-symbols.ll
index 5471466eb076b..dd92b4ec9bc5d 100644
--- a/test/wasm/local-symbols.ll
+++ b/test/wasm/local-symbols.ll
@@ -1,5 +1,6 @@
+; Test that internal symbols can still be GC'd when with --export-dynamic.
; RUN: llc -filetype=obj %s -o %t.o
-; RUN: wasm-ld -o %t.wasm %t.o
+; RUN: wasm-ld --export-dynamic -o %t.wasm %t.o
; RUN: obj2yaml %t.wasm | FileCheck %s
target triple = "wasm32-unknown-unknown"
@@ -35,7 +36,7 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 1, 0 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000001
diff --git a/test/wasm/locals-duplicate.test b/test/wasm/locals-duplicate.test
index 3c67cdd8cfa47..2d6bd0df5314c 100644
--- a/test/wasm/locals-duplicate.test
+++ b/test/wasm/locals-duplicate.test
@@ -1,6 +1,6 @@
; RUN: llc -filetype=obj %p/Inputs/locals-duplicate1.ll -o %t1.o
; RUN: llc -filetype=obj %p/Inputs/locals-duplicate2.ll -o %t2.o
-; RUN: wasm-ld --no-entry -o %t.wasm %t1.o %t2.o
+; RUN: wasm-ld --export-dynamic --no-entry -o %t.wasm %t1.o %t2.o
; RUN: obj2yaml %t.wasm | FileCheck %s
; CHECK: --- !WASM
@@ -20,7 +20,7 @@
; CHECK-NEXT: 1, 1, 1 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000007
@@ -253,7 +253,7 @@
; RELOC-NEXT: 0, 0 ]
; RELOC-NEXT: - Type: TABLE
; RELOC-NEXT: Tables:
-; RELOC-NEXT: - ElemType: ANYFUNC
+; RELOC-NEXT: - ElemType: FUNCREF
; RELOC-NEXT: Limits:
; RELOC-NEXT: Flags: [ HAS_MAX ]
; RELOC-NEXT: Initial: 0x00000007
@@ -382,7 +382,7 @@
; RELOC-NEXT: Content: '0000000000000000'
; RELOC-NEXT: - Type: CUSTOM
; RELOC-NEXT: Name: linking
-; RELOC-NEXT: Version: 1
+; RELOC-NEXT: Version: 2
; RELOC-NEXT: SymbolTable:
; RELOC-NEXT: - Index: 0
; RELOC-NEXT: Kind: FUNCTION
@@ -516,15 +516,15 @@
; RELOC-NEXT: SegmentInfo:
; RELOC-NEXT: - Index: 0
; RELOC-NEXT: Name: .bss.colliding_global1
-; RELOC-NEXT: Alignment: 4
+; RELOC-NEXT: Alignment: 2
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: - Index: 1
; RELOC-NEXT: Name: .bss.colliding_global2
-; RELOC-NEXT: Alignment: 4
+; RELOC-NEXT: Alignment: 2
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: - Index: 2
; RELOC-NEXT: Name: .bss.colliding_global3
-; RELOC-NEXT: Alignment: 4
+; RELOC-NEXT: Alignment: 2
; RELOC-NEXT: Flags: [ ]
; RELOC-NEXT: - Type: CUSTOM
; RELOC-NEXT: Name: name
diff --git a/test/wasm/lto/archive.ll b/test/wasm/lto/archive.ll
index 89fa840cdec57..ab067d8cdce46 100644
--- a/test/wasm/lto/archive.ll
+++ b/test/wasm/lto/archive.ll
@@ -2,7 +2,7 @@
; RUN: rm -f %t.a
; RUN: llvm-ar rcs %t.a %t1.o
; RUN: llvm-as %s -o %t2.o
-; RUN: wasm-ld %t2.o %t.a -o %t3
+; RUN: wasm-ld --export-dynamic %t2.o %t.a -o %t3
; RUN: obj2yaml %t3 | FileCheck %s
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
diff --git a/test/wasm/lto/cache.ll b/test/wasm/lto/cache.ll
index b0a7820c1e19a..6d52b973f0fad 100644
--- a/test/wasm/lto/cache.ll
+++ b/test/wasm/lto/cache.ll
@@ -1,5 +1,7 @@
; RUN: opt -module-hash -module-summary %s -o %t.o
; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.o
+; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
+; UNSUPPORTED: system-netbsd
; RUN: rm -Rf %t.cache && mkdir %t.cache
; Create two files that would be removed by cache pruning due to age.
@@ -11,12 +13,16 @@
; RUN: ls %t.cache | count 4
; Create a file of size 64KB.
-; RUN: "%python" -c "print(' ' * 65536)" > %t.cache/llvmcache-foo
+; RUN: %python -c "print(' ' * 65536)" > %t.cache/llvmcache-foo
; This should leave the file in place.
; RUN: wasm-ld --thinlto-cache-dir=%t.cache --thinlto-cache-policy cache_size_bytes=128k:prune_interval=0s -o %t.wasm %t2.o %t.o
; RUN: ls %t.cache | count 5
+; Increase the age of llvmcache-foo, which will give it the oldest time stamp
+; so that it is processed and removed first.
+; RUN: %python -c 'import os,sys,time; t=time.time()-120; os.utime(sys.argv[1],(t,t))' %t.cache/llvmcache-foo
+
; This should remove it.
; RUN: wasm-ld --thinlto-cache-dir=%t.cache --thinlto-cache-policy cache_size_bytes=32k:prune_interval=0s -o %t.wasm %t2.o %t.o
; RUN: ls %t.cache | count 4
diff --git a/test/wasm/lto/export.ll b/test/wasm/lto/export.ll
index 44ded6f147f6b..0ff0be504eda6 100644
--- a/test/wasm/lto/export.ll
+++ b/test/wasm/lto/export.ll
@@ -29,10 +29,10 @@ entry:
; CHECK-NEXT: - Name: __data_end
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 2
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Name: hidden_function
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Type: CODE
diff --git a/test/wasm/lto/signature-mismatch.ll b/test/wasm/lto/signature-mismatch.ll
new file mode 100644
index 0000000000000..e48bb39cd8d97
--- /dev/null
+++ b/test/wasm/lto/signature-mismatch.ll
@@ -0,0 +1,19 @@
+; RUN: llc -filetype=obj -o %t.o %s
+; RUN: llvm-as %S/Inputs/archive.ll -o %t1.o
+; RUN: not wasm-ld --fatal-warnings %t.o %t1.o -o %t.wasm 2>&1 | FileCheck %s
+
+; Test that functions defined in bitcode correctly report signature
+; mistmaches with existing undefined sybmols in normal objects.
+
+target triple = "wasm32-unknown-unknown"
+
+; f is defined to take no argument in archive.ll which is compiled to bitcode
+declare void @f(i32);
+
+define void @_start() {
+ call void @f(i32 0)
+ ret void
+}
+
+; CHECK: >>> defined as (i32) -> void in {{.*}}signature-mismatch.ll.tmp1.o
+; CHECK: >>> defined as () -> void in lto.tmp
diff --git a/test/wasm/many-functions.ll b/test/wasm/many-functions.ll
index 02ad9aab51a0e..e2191bed9ed60 100644
--- a/test/wasm/many-functions.ll
+++ b/test/wasm/many-functions.ll
@@ -815,7 +815,7 @@ entry:
; CHECK-NEXT: Content: '01000000'
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: linking
-; CHECK-NEXT: Version: 1
+; CHECK-NEXT: Version: 2
; CHECK-NEXT: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: FUNCTION
@@ -1482,9 +1482,9 @@ entry:
; CHECK-NEXT: SegmentInfo:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Name: .data.g0
-; CHECK-NEXT: Alignment: 4
+; CHECK-NEXT: Alignment: 2
; CHECK-NEXT: Flags: [ ]
; CHECK-NEXT: - Index: 1
; CHECK-NEXT: Name: .data.foo
-; CHECK-NEXT: Alignment: 4
+; CHECK-NEXT: Alignment: 2
; CHECK-NEXT: Flags: [ ]
diff --git a/test/wasm/relocatable.ll b/test/wasm/relocatable.ll
index 4e8a887f31d87..c503afa812324 100644
--- a/test/wasm/relocatable.ll
+++ b/test/wasm/relocatable.ll
@@ -63,7 +63,7 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 2, 1, 1 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000004
@@ -157,7 +157,7 @@ entry:
; CHECK-NEXT: Content: '616263'
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: linking
-; CHECK-NEXT: Version: 1
+; CHECK-NEXT: Version: 2
; CHECK-NEXT: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: FUNCTION
@@ -232,27 +232,27 @@ entry:
; CHECK-NEXT: SegmentInfo:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Name: .rodata.hello_str
-; CHECK-NEXT: Alignment: 1
+; CHECK-NEXT: Alignment: 0
; CHECK-NEXT: Flags: [ ]
; CHECK-NEXT: - Index: 1
; CHECK-NEXT: Name: .data.func_addr1
-; CHECK-NEXT: Alignment: 4
+; CHECK-NEXT: Alignment: 2
; CHECK-NEXT: Flags: [ ]
; CHECK-NEXT: - Index: 2
; CHECK-NEXT: Name: .data.func_addr2
-; CHECK-NEXT: Alignment: 4
+; CHECK-NEXT: Alignment: 2
; CHECK-NEXT: Flags: [ ]
; CHECK-NEXT: - Index: 3
; CHECK-NEXT: Name: .data.func_addr3
-; CHECK-NEXT: Alignment: 4
+; CHECK-NEXT: Alignment: 2
; CHECK-NEXT: Flags: [ ]
; CHECK-NEXT: - Index: 4
; CHECK-NEXT: Name: .data.data_addr1
-; CHECK-NEXT: Alignment: 8
+; CHECK-NEXT: Alignment: 3
; CHECK-NEXT: Flags: [ ]
; CHECK-NEXT: - Index: 5
; CHECK-NEXT: Name: .rodata.data_comdat
-; CHECK-NEXT: Alignment: 1
+; CHECK-NEXT: Alignment: 0
; CHECK-NEXT: Flags: [ ]
; CHECK-NEXT: Comdats:
; CHECK-NEXT: - Name: func_comdat
diff --git a/test/wasm/shared.ll b/test/wasm/shared.ll
new file mode 100644
index 0000000000000..f3abd11727783
--- /dev/null
+++ b/test/wasm/shared.ll
@@ -0,0 +1,82 @@
+; RUN: llc -O0 -filetype=obj %s -o %t.o
+; RUN: wasm-ld -shared -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+target triple = "wasm32-unknown-unknown"
+
+@data = hidden global i32 2, align 4
+@indirect_func = local_unnamed_addr global void ()* @foo, align 4
+@indirect_func_external = local_unnamed_addr global void ()* @func_external, align 4
+
+define default void @foo() {
+entry:
+ ; To ensure we use __stack_pointer
+ %ptr = alloca i32
+ %0 = load i32, i32* @data, align 4
+ %1 = load i32, i32* @data_external, align 4
+ %2 = load void ()*, void ()** @indirect_func, align 4
+ call void %2()
+ ret void
+}
+
+declare void @func_external()
+
+@data_external = external global i32
+
+
+; check for dylink section at start
+
+; CHECK: Sections:
+; CHECK-NEXT: - Type: CUSTOM
+; CHECK-NEXT: Name: dylink
+; CHECK-NEXT: MemorySize: 8
+; CHECK-NEXT: MemoryAlignment: 2
+; CHECK-NEXT: TableSize: 2
+; CHECK-NEXT: TableAlignment: 0
+
+; check for import of __table_base and __memory_base globals
+
+; CHECK: - Type: IMPORT
+; CHECK-NEXT: Imports:
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __indirect_function_table
+; CHECK-NEXT: Kind: TABLE
+; CHECK-NEXT: Table:
+; CHECK-NEXT: ElemType: FUNCREF
+; CHECK-NEXT: Limits:
+; CHECK-NEXT: Initial: 0x00000002
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __stack_pointer
+; CHECK-NEXT: Kind: GLOBAL
+; CHECK-NEXT: GlobalType: I32
+; CHECK-NEXT: GlobalMutable: true
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __memory_base
+; CHECK-NEXT: Kind: GLOBAL
+; CHECK-NEXT: GlobalType: I32
+; CHECK-NEXT: GlobalMutable: false
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __table_base
+; CHECK-NEXT: Kind: GLOBAL
+; CHECK-NEXT: GlobalType: I32
+; CHECK-NEXT: GlobalMutable: false
+
+; check for elem segment initialized with __table_base global as offset
+
+; CHECK: - Type: ELEM
+; CHECK-NEXT: Segments:
+; CHECK-NEXT: - Offset:
+; CHECK-NEXT: Opcode: GLOBAL_GET
+; CHECK-NEXT: Index: 2
+; CHECK-NEXT: Functions: [ 2, 0 ]
+
+; check the data segment initialized with __memory_base global as offset
+
+; CHECK: - Type: DATA
+; CHECK-NEXT: Segments:
+; CHECK-NEXT: - SectionOffset: 6
+; CHECK-NEXT: MemoryIndex: 0
+; CHECK-NEXT: Offset:
+; CHECK-NEXT: Opcode: GLOBAL_GET
+; CHECK-NEXT: Index: 1
+; CHECK-NEXT: Content: '0000000001000000'
diff --git a/test/wasm/signature-mismatch-weak.ll b/test/wasm/signature-mismatch-weak.ll
index dbf73d1aa46e8..4d2b02cc9ed33 100644
--- a/test/wasm/signature-mismatch-weak.ll
+++ b/test/wasm/signature-mismatch-weak.ll
@@ -14,5 +14,5 @@ entry:
}
; CHECK: warning: function signature mismatch: weakFn
-; CHECK-NEXT: >>> defined as () -> I32 in {{.*}}signature-mismatch-weak.ll.tmp.o
-; CHECK-NEXT: >>> defined as () -> I64 in {{.*}}signature-mismatch-weak.ll.tmp.strong.o
+; CHECK-NEXT: >>> defined as () -> i32 in {{.*}}signature-mismatch-weak.ll.tmp.o
+; CHECK-NEXT: >>> defined as () -> i64 in {{.*}}signature-mismatch-weak.ll.tmp.strong.o
diff --git a/test/wasm/signature-mismatch.ll b/test/wasm/signature-mismatch.ll
index d750d4f6b359e..8f13d644a7ce5 100644
--- a/test/wasm/signature-mismatch.ll
+++ b/test/wasm/signature-mismatch.ll
@@ -18,9 +18,9 @@ entry:
declare i32 @ret32(i32, i64, i32) local_unnamed_addr #1
; CHECK: error: function signature mismatch: ret32
-; CHECK-NEXT: >>> defined as (I32, I64, I32) -> I32 in {{.*}}.main.o
-; CHECK-NEXT: >>> defined as (F32) -> I32 in {{.*}}.ret32.o
+; CHECK-NEXT: >>> defined as (i32, i64, i32) -> i32 in {{.*}}.main.o
+; CHECK-NEXT: >>> defined as (f32) -> i32 in {{.*}}.ret32.o
; REVERSE: error: function signature mismatch: ret32
-; REVERSE-NEXT: >>> defined as (F32) -> I32 in {{.*}}.ret32.o
-; REVERSE-NEXT: >>> defined as (I32, I64, I32) -> I32 in {{.*}}.main.o
+; REVERSE-NEXT: >>> defined as (f32) -> i32 in {{.*}}.ret32.o
+; REVERSE-NEXT: >>> defined as (i32, i64, i32) -> i32 in {{.*}}.main.o
diff --git a/test/wasm/stack-pointer.ll b/test/wasm/stack-pointer.ll
index 888c938881de8..6851214fe91a3 100644
--- a/test/wasm/stack-pointer.ll
+++ b/test/wasm/stack-pointer.ll
@@ -31,7 +31,7 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000001
@@ -50,7 +50,7 @@ entry:
; CHECK-NEXT: Body: 23808080800041106B1A41000B
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: linking
-; CHECK-NEXT: Version: 1
+; CHECK-NEXT: Version: 2
; CHECK-NEXT: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: FUNCTION
diff --git a/test/wasm/strip-all.test b/test/wasm/strip-all.test
new file mode 100644
index 0000000000000..7b7c25963bc75
--- /dev/null
+++ b/test/wasm/strip-all.test
@@ -0,0 +1,10 @@
+RUN: llc -filetype=obj %p/Inputs/start.ll -o %t.start.o
+RUN: wasm-ld --strip-all -o %t.wasm %t.start.o
+RUN: obj2yaml %t.wasm | FileCheck %s
+
+# Test alias -s
+RUN: wasm-ld -s -o %t.wasm %t.start.o
+RUN: obj2yaml %t.wasm | FileCheck %s
+
+# Check that there is no name section
+CHECK-NOT: Name: name
diff --git a/test/wasm/strip-debug.test b/test/wasm/strip-debug.test
index be5ba700e2582..6ee27f8c8a776 100644
--- a/test/wasm/strip-debug.test
+++ b/test/wasm/strip-debug.test
@@ -2,5 +2,9 @@ RUN: llc -filetype=obj %p/Inputs/start.ll -o %t.start.o
RUN: wasm-ld --strip-debug -o %t.wasm %t.start.o
RUN: obj2yaml %t.wasm | FileCheck %s
+# Test alias -S
+RUN: wasm-ld -S -o %t.wasm %t.start.o
+RUN: obj2yaml %t.wasm | FileCheck %s
+
# Check that there is no name section
CHECK-NOT: Name: name
diff --git a/test/wasm/undefined-entry.test b/test/wasm/undefined-entry.test
index ffa079ca638bb..a36212f2c9e3c 100644
--- a/test/wasm/undefined-entry.test
+++ b/test/wasm/undefined-entry.test
@@ -1,11 +1,9 @@
RUN: llc -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o
RUN: not wasm-ld -o %t.wasm %t.ret32.o 2>&1 | FileCheck %s
+RUN: not wasm-ld --allow-undefined -o %t.wasm %t.ret32.o 2>&1 | FileCheck %s
RUN: not wasm-ld -entry=foo -o %t.wasm %t.ret32.o 2>&1 | FileCheck %s -check-prefix=CHECK-CUSTOM
-RUN: not wasm-ld --allow-undefined -o %t.wasm %t.ret32.o 2>&1 | FileCheck %s -check-prefix=CHECK-ALLOW
-CHECK: error: undefined symbol: _start
-CHECK-CUSTOM: error: undefined symbol: foo
-CHECK-ALLOW: error: entry symbol not defined (pass --no-entry to supress):
-_start
+CHECK: error: entry symbol not defined (pass --no-entry to supress): _start
+CHECK-CUSTOM: error: entry symbol not defined (pass --no-entry to supress): foo
RUN: wasm-ld --no-entry -o %t.wasm %t.ret32.o
diff --git a/test/wasm/undefined-weak-call.ll b/test/wasm/undefined-weak-call.ll
index c13f5c1ae3f16..0b7d0c769d475 100644
--- a/test/wasm/undefined-weak-call.ll
+++ b/test/wasm/undefined-weak-call.ll
@@ -1,5 +1,5 @@
; RUN: llc -filetype=obj %s -o %t.o
-; RUN: wasm-ld --no-entry --print-gc-sections %t.o \
+; RUN: wasm-ld --entry=callWeakFuncs --print-gc-sections %t.o \
; RUN: -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-GC %s
; RUN: obj2yaml %t.wasm | FileCheck %s
@@ -45,7 +45,7 @@ define i32 @callWeakFuncs() {
; CHECK-NEXT: FunctionTypes: [ 0, 0, 0, 1, 2 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000001
diff --git a/test/wasm/undefined.ll b/test/wasm/undefined.ll
index 7d2161d2bcc60..1da979fc07648 100644
--- a/test/wasm/undefined.ll
+++ b/test/wasm/undefined.ll
@@ -1,10 +1,10 @@
; RUN: llc -filetype=obj %s -o %t.o
; RUN: wasm-ld --allow-undefined -o %t.wasm %t.o
-; Fails due to undefined 'foo' and also 'baz'
+; Fails due to undefined 'foo'
; RUN: not wasm-ld --undefined=baz -o %t.wasm %t.o 2>&1 | FileCheck %s
; CHECK: error: {{.*}}.o: undefined symbol: foo
-; CHECK: error: undefined symbol: baz
+; CHECK-NOT: undefined symbol: baz
; Succeeds if we pass a file containing 'foo' as --allow-undefined-file.
; RUN: echo 'foo' > %t.txt
diff --git a/test/wasm/visibility-hidden.ll b/test/wasm/visibility-hidden.ll
index af973df0751aa..b4fe0b53ba21a 100644
--- a/test/wasm/visibility-hidden.ll
+++ b/test/wasm/visibility-hidden.ll
@@ -1,11 +1,18 @@
; RUN: llc -filetype=obj -o %t.o %s
; RUN: llc -filetype=obj %S/Inputs/hidden.ll -o %t2.o
+; RUN: rm -f %t2.a
; RUN: llvm-ar rcs %t2.a %t2.o
-; RUN: wasm-ld %t.o %t2.a -o %t.wasm
+
+; Test that symbols with hidden visitiblity are not export, even with
+; --export-dynamic
+; RUN: wasm-ld --export-dynamic %t.o %t2.a -o %t.wasm
; RUN: obj2yaml %t.wasm | FileCheck %s
-; Test that hidden symbols are not exported, whether pulled in from an archive
-; or directly.
+; Test that symbols with default visitiblity are not exported without
+; --export-dynamic
+; RUN: wasm-ld %t.o %t2.a -o %t.nodef.wasm
+; RUN: obj2yaml %t.nodef.wasm | FileCheck %s -check-prefix=NO-DEFAULT
+
target triple = "wasm32-unknown-unknown"
@@ -42,13 +49,30 @@ entry:
; CHECK-NEXT: - Name: __data_end
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 2
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 3
; CHECK-NEXT: - Name: objectDefault
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 2
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 3
; CHECK-NEXT: - Name: archiveDefault
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 5
; CHECK-NEXT: - Type:
+
+
+; NO-DEFAULT: - Type: EXPORT
+; NO-DEFAULT-NEXT: Exports:
+; NO-DEFAULT-NEXT: - Name: memory
+; NO-DEFAULT-NEXT: Kind: MEMORY
+; NO-DEFAULT-NEXT: Index: 0
+; NO-DEFAULT-NEXT: - Name: __heap_base
+; NO-DEFAULT-NEXT: Kind: GLOBAL
+; NO-DEFAULT-NEXT: Index: 1
+; NO-DEFAULT-NEXT: - Name: __data_end
+; NO-DEFAULT-NEXT: Kind: GLOBAL
+; NO-DEFAULT-NEXT: Index: 2
+; NO-DEFAULT-NEXT: - Name: _start
+; NO-DEFAULT-NEXT: Kind: FUNCTION
+; NO-DEFAULT-NEXT: Index: 3
+; NO-DEFAULT-NEXT: - Type:
diff --git a/test/wasm/weak-alias-overide.ll b/test/wasm/weak-alias-overide.ll
index 8b98f3347a1c6..7fefad0fb04a0 100644
--- a/test/wasm/weak-alias-overide.ll
+++ b/test/wasm/weak-alias-overide.ll
@@ -1,6 +1,6 @@
; RUN: llc -filetype=obj -o %t.o %s
; RUN: llc -filetype=obj %S/Inputs/weak-alias.ll -o %t2.o
-; RUN: wasm-ld %t.o %t2.o -o %t.wasm
+; RUN: wasm-ld --export-dynamic %t.o %t2.o -o %t.wasm
; RUN: obj2yaml %t.wasm | FileCheck %s
; Test that the strongly defined alias_fn from this file is used both here
@@ -35,7 +35,7 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 1, 0, 1, 1, 1, 1, 1 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000003
@@ -74,12 +74,12 @@ entry:
; CHECK-NEXT: - Name: __data_end
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 2
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Name: alias_fn
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Name: direct_fn
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 3
diff --git a/test/wasm/weak-alias.ll b/test/wasm/weak-alias.ll
index 227906a555043..0c856e1eafa09 100644
--- a/test/wasm/weak-alias.ll
+++ b/test/wasm/weak-alias.ll
@@ -1,6 +1,6 @@
; RUN: llc -filetype=obj -o %t.o %s
; RUN: llc -filetype=obj %S/Inputs/weak-alias.ll -o %t2.o
-; RUN: wasm-ld %t.o %t2.o -o %t.wasm
+; RUN: wasm-ld --export-dynamic %t.o %t2.o -o %t.wasm
; RUN: obj2yaml %t.wasm | FileCheck %s
; Test that weak aliases (alias_fn is a weak alias of direct_fn) are linked correctly
@@ -32,7 +32,7 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 0, 1, 1, 1, 1, 1 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000002
@@ -170,7 +170,7 @@ entry:
; RELOC-NEXT: FunctionTypes: [ 0, 1, 1, 1, 1, 1 ]
; RELOC-NEXT: - Type: TABLE
; RELOC-NEXT: Tables:
-; RELOC-NEXT: - ElemType: ANYFUNC
+; RELOC-NEXT: - ElemType: FUNCREF
; RELOC-NEXT: Limits:
; RELOC-NEXT: Flags: [ HAS_MAX ]
; RELOC-NEXT: Initial: 0x00000002
@@ -250,7 +250,7 @@ entry:
; RELOC-NEXT: Body: 23808080800041106B220024808080800020004181808080003602081081808080002101200041106A24808080800020010B
; RELOC-NEXT: - Type: CUSTOM
; RELOC-NEXT: Name: linking
-; RELOC-NEXT: Version: 1
+; RELOC-NEXT: Version: 2
; RELOC-NEXT: SymbolTable:
; RELOC-NEXT: - Index: 0
; RELOC-NEXT: Kind: FUNCTION
diff --git a/test/wasm/weak-symbols.ll b/test/wasm/weak-symbols.ll
index bd45de39ca357..41ade7c1aa0ea 100644
--- a/test/wasm/weak-symbols.ll
+++ b/test/wasm/weak-symbols.ll
@@ -1,7 +1,7 @@
; RUN: llc -filetype=obj %p/Inputs/weak-symbol1.ll -o %t1.o
; RUN: llc -filetype=obj %p/Inputs/weak-symbol2.ll -o %t2.o
; RUN: llc -filetype=obj %s -o %t.o
-; RUN: wasm-ld -no-gc-sections -o %t.wasm %t.o %t1.o %t2.o
+; RUN: wasm-ld --export-dynamic -o %t.wasm %t.o %t1.o %t2.o
; RUN: obj2yaml %t.wasm | FileCheck %s
target triple = "wasm32-unknown-unknown"
@@ -29,10 +29,10 @@ entry:
; CHECK-NEXT: ReturnType: I32
; CHECK-NEXT: ParamTypes:
; CHECK-NEXT: - Type: FUNCTION
-; CHECK-NEXT: FunctionTypes: [ 0, 0, 1, 1, 1, 1 ]
+; CHECK-NEXT: FunctionTypes: [ 0, 0, 1, 1, 1 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000002
@@ -59,7 +59,7 @@ entry:
; CHECK-NEXT: Mutable: false
; CHECK-NEXT: InitExpr:
; CHECK-NEXT: Opcode: I32_CONST
-; CHECK-NEXT: Value: 1032
+; CHECK-NEXT: Value: 1028
; CHECK-NEXT: - Index: 3
; CHECK-NEXT: Type: I32
; CHECK-NEXT: Mutable: false
@@ -91,7 +91,7 @@ entry:
; CHECK-NEXT: Index: 3
; CHECK-NEXT: - Name: exportWeak2
; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 5
+; CHECK-NEXT: Index: 4
; CHECK-NEXT: - Type: ELEM
; CHECK-NEXT: Segments:
; CHECK-NEXT: - Offset:
@@ -114,9 +114,6 @@ entry:
; CHECK-NEXT: Body: 4181808080000B
; CHECK-NEXT: - Index: 4
; CHECK-NEXT: Locals:
-; CHECK-NEXT: Body: 41020B
-; CHECK-NEXT: - Index: 5
-; CHECK-NEXT: Locals:
; CHECK-NEXT: Body: 4181808080000B
; CHECK-NEXT: - Type: DATA
; CHECK-NEXT: Segments:
@@ -125,7 +122,7 @@ entry:
; CHECK-NEXT: Offset:
; CHECK-NEXT: Opcode: I32_CONST
; CHECK-NEXT: Value: 1024
-; CHECK-NEXT: Content: '0100000002000000'
+; CHECK-NEXT: Content: '01000000'
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: name
; CHECK-NEXT: FunctionNames:
@@ -138,7 +135,5 @@ entry:
; CHECK-NEXT: - Index: 3
; CHECK-NEXT: Name: exportWeak1
; CHECK-NEXT: - Index: 4
-; CHECK-NEXT: Name: weakFn
-; CHECK-NEXT: - Index: 5
; CHECK-NEXT: Name: exportWeak2
; CHECK-NEXT: ...
diff --git a/test/wasm/weak-undefined.ll b/test/wasm/weak-undefined.ll
index 53b38bc32c3e2..41e992e5ea472 100644
--- a/test/wasm/weak-undefined.ll
+++ b/test/wasm/weak-undefined.ll
@@ -22,7 +22,8 @@ define i32* @get_address_of_global_var() #0 {
define void @_start() #0 {
entry:
- %call = call i32* @get_address_of_global_var()
+ %call1 = call i32* @get_address_of_global_var()
+ %call2 = call i8* @get_address_of_foo()
ret void
}
@@ -42,7 +43,7 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 1, 1, 0 ]
; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables:
-; CHECK-NEXT: - ElemType: ANYFUNC
+; CHECK-NEXT: - ElemType: FUNCREF
; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000001
@@ -84,12 +85,6 @@ entry:
; CHECK-NEXT: - Name: _start
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 3
-; CHECK-NEXT: - Name: get_address_of_foo
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 1
-; CHECK-NEXT: - Name: get_address_of_global_var
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Type: CODE
; CHECK-NEXT: Functions:
; CHECK-NEXT: - Index: 0
@@ -103,5 +98,5 @@ entry:
; CHECK-NEXT: Body: 4180808080000B
; CHECK-NEXT: - Index: 3
; CHECK-NEXT: Locals:
-; CHECK-NEXT: Body: 1082808080001A0B
+; CHECK-NEXT: Body: 1082808080001A1081808080001A0B
; CHECK-NEXT: ...