Skip to content

Commit 1827005

Browse files
committed
[WebAssembly] Add support for named globals in the object format.
Differential Revision: https://reviews.llvm.org/D91769
1 parent ea7ab5a commit 1827005

34 files changed

+233
-59
lines changed

lld/test/wasm/alias.s

+3
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ _start:
6262
# CHECK-NEXT: FunctionNames:
6363
# CHECK-NEXT: - Index: 0
6464
# CHECK-NEXT: Name: _start
65+
# CHECK-NEXT: GlobalNames:
66+
# CHECK-NEXT: - Index: 0
67+
# CHECK-NEXT: Name: __stack_pointer
6568
# CHECK-NEXT: ...

lld/test/wasm/call-indirect.ll

+3
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,7 @@ define void @call_ptr(i64 (i64)* %arg) {
153153
; CHECK-NEXT: Name: _start
154154
; CHECK-NEXT: - Index: 4
155155
; CHECK-NEXT: Name: call_ptr
156+
; CHECK-NEXT: GlobalNames:
157+
; CHECK-NEXT: - Index: 0
158+
; CHECK-NEXT: Name: __stack_pointer
156159
; CHECK-NEXT: ...

lld/test/wasm/ctor_return_value.s

+3
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ _start:
4343
# CHECK-NEXT: Name: myctor
4444
# CHECK-NEXT: - Index: 2
4545
# CHECK-NEXT: Name: _start
46+
# CHECK-NEXT: GlobalNames:
47+
# CHECK-NEXT: - Index: 0
48+
# CHECK-NEXT: Name: __stack_pointer
4649
# CHECK-NEXT: ...

lld/test/wasm/cxx-mangling.ll

+3
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ define void @_start() {
5454
; MANGLE-NEXT: Name: _Z3fooi
5555
; CHECK-NEXT: - Index: 2
5656
; CHECK-NEXT: Name: _start
57+
; CHECK-NEXT: GlobalNames:
58+
; CHECK-NEXT: - Index: 0
59+
; CHECK-NEXT: Name: __stack_pointer
5760
; CHECK-NEXT: ...

lld/test/wasm/data-segment-merging.ll

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ target triple = "wasm32-unknown-unknown"
2929
; MERGE-NEXT: FunctionNames:
3030
; MERGE-NEXT: - Index: 0
3131
; MERGE-NEXT: Name: __wasm_call_ctors
32+
; MERGE-NEXT: GlobalNames:
33+
; MERGE-NEXT: - Index: 0
34+
; MERGE-NEXT: Name: __stack_pointer
3235
; MERGE-NOT: - Index:
3336

3437
; RUN: wasm-ld -no-gc-sections --no-entry --no-merge-data-segments -o %t.separate.wasm %t.o
@@ -66,6 +69,9 @@ target triple = "wasm32-unknown-unknown"
6669
; SEPARATE-NEXT: FunctionNames:
6770
; SEPARATE-NEXT: - Index: 0
6871
; SEPARATE-NEXT: Name: __wasm_call_ctors
72+
; SEPARATE-NEXT: GlobalNames:
73+
; SEPARATE-NEXT: - Index: 0
74+
; SEPARATE-NEXT: Name: __stack_pointer
6975
; SEPARATE-NOT: - Index:
7076

7177
; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 -o %t.merged.passive.wasm %t.passive.o

lld/test/wasm/function-imports-first.ll

+3
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ declare i32 @ret32(float) local_unnamed_addr #1
4141
; CHECK-NEXT: Name: _start
4242
; CHECK-NEXT: - Index: 1
4343
; CHECK-NEXT: Name: ret32
44+
; CHECK-NEXT: GlobalNames:
45+
; CHECK-NEXT: - Index: 0
46+
; CHECK-NEXT: Name: __stack_pointer
4447
; CHECK-NEXT: ...

lld/test/wasm/function-imports.ll

+3
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ declare i32 @ret32(float) local_unnamed_addr #1
3737
; CHECK-NEXT: Name: ret32
3838
; CHECK-NEXT: - Index: 1
3939
; CHECK-NEXT: Name: _start
40+
; CHECK-NEXT: GlobalNames:
41+
; CHECK-NEXT: - Index: 0
42+
; CHECK-NEXT: Name: __stack_pointer
4043
; CHECK-NEXT: ...

lld/test/wasm/gc-imports.s

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ _start:
4242
# CHECK-NEXT: Name: _start
4343
# CHECK-NEXT: - Index: 2
4444
# CHECK-NEXT: Name: use_undef_global
45+
# CHECK-NEXT: GlobalNames:
46+
# CHECK-NEXT: - Index: 0
47+
# CHECK-NEXT: Name: used_undef_global
48+
# CHECK-NEXT: - Index: 1
49+
# CHECK-NEXT: Name: __stack_pointer
4550
# CHECK-NEXT: ...
4651

4752
# RUN: wasm-ld --no-gc-sections --allow-undefined \
@@ -84,4 +89,11 @@ _start:
8489
# NO-GC-NEXT: Name: _start
8590
# NO-GC-NEXT: - Index: 5
8691
# NO-GC-NEXT: Name: use_undef_global
92+
# NO-GC-NEXT: GlobalNames:
93+
# NO-GC-NEXT: - Index: 0
94+
# NO-GC-NEXT: Name: unused_undef_global
95+
# NO-GC-NEXT: - Index: 1
96+
# NO-GC-NEXT: Name: used_undef_global
97+
# NO-GC-NEXT: - Index: 2
98+
# NO-GC-NEXT: Name: __stack_pointer
8799
# NO-GC-NEXT: ...

lld/test/wasm/gc-sections.ll

+12
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ entry:
8282
; CHECK-NEXT: Name: _start
8383
; CHECK-NEXT: - Index: 2
8484
; CHECK-NEXT: Name: use_global
85+
; CHECK-NEXT: GlobalNames:
86+
; CHECK-NEXT: - Index: 0
87+
; CHECK-NEXT: Name: __stack_pointer
88+
; CHECK-NEXT: - Index: 1
89+
; CHECK-NEXT: Name: used_global
8590
; CHECK-NEXT: ...
8691

8792
; RUN: wasm-ld -print-gc-sections --no-gc-sections -o %t1.no-gc.wasm \
@@ -150,6 +155,13 @@ entry:
150155
; NO-GC-NEXT: Name: _start
151156
; NO-GC-NEXT: - Index: 4
152157
; NO-GC-NEXT: Name: use_global
158+
; NO-GC-NEXT: GlobalNames:
159+
; NO-GC-NEXT: - Index: 0
160+
; NO-GC-NEXT: Name: __stack_pointer
161+
; NO-GC-NEXT: - Index: 1
162+
; NO-GC-NEXT: Name: unused_global
163+
; NO-GC-NEXT: - Index: 2
164+
; NO-GC-NEXT: Name: used_global
153165
; NO-GC-NEXT: ...
154166

155167
; RUN: not wasm-ld --gc-sections --relocatable -o %t1.no-gc.wasm %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR

lld/test/wasm/init-fini.ll

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ entry:
127127
; CHECK-NEXT: Name: .Lcall_dtors.2002
128128
; CHECK-NEXT: - Index: 22
129129
; CHECK-NEXT: Name: .Lregister_call_dtors.2002
130+
; CHECK-NEXT: GlobalNames:
131+
; CHECK-NEXT: - Index: 0
132+
; CHECK-NEXT: Name: __stack_pointer
130133
; CHECK-NEXT: ...
131134

132135
; RUN: wasm-ld -r %t.o %t.global-ctor-dtor.o -o %t.reloc.wasm

lld/test/wasm/load-undefined.test

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
; CHECK-NEXT: Name: ret64
2222
; CHECK-NEXT: - Index: 3
2323
; CHECK-NEXT: Name: ret32
24+
; CHECK-NEXT: GlobalNames:
25+
; CHECK-NEXT: - Index: 0
26+
; CHECK-NEXT: Name: __stack_pointer
2427
; CHECK-NEXT: ...
2528

2629
; NO-LOAD: Name: name
@@ -31,6 +34,9 @@
3134
; NO-LOAD-NEXT: Name: _start
3235
; NO-LOAD-NEXT: - Index: 2
3336
; NO-LOAD-NEXT: Name: ret64
37+
; NO-LOAD-NEXT: GlobalNames:
38+
; NO-LOAD-NEXT: - Index: 0
39+
; NO-LOAD-NEXT: Name: __stack_pointer
3440
; NO-LOAD-NEXT: ...
3541

3642
; Verify that referencing a symbol that is not found doesn't result in a link

lld/test/wasm/local-symbols.ll

+3
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,7 @@ entry:
9494
; CHECK-NEXT: Name: baz
9595
; CHECK-NEXT: - Index: 1
9696
; CHECK-NEXT: Name: _start
97+
; CHECK-NEXT: GlobalNames:
98+
; CHECK-NEXT: - Index: 0
99+
; CHECK-NEXT: Name: __stack_pointer
97100
; CHECK-NEXT: ...

lld/test/wasm/locals-duplicate.test

+3
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@
209209
; CHECK-NEXT: Name: get_func2B
210210
; CHECK-NEXT: - Index: 17
211211
; CHECK-NEXT: Name: get_func3B
212+
; CHECK-NEXT: GlobalNames:
213+
; CHECK-NEXT: - Index: 0
214+
; CHECK-NEXT: Name: __stack_pointer
212215
; CHECK-NEXT: ...
213216

214217

lld/test/wasm/map-file.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ somedata:
4040
# CHECK-NEXT: 400 5a 4 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.data.somedata)
4141
# CHECK-NEXT: 400 5a 4 somedata
4242
# CHECK-NEXT: - 60 12 CUSTOM(.debug_info)
43-
# CHECK-NEXT: - 72 17 CUSTOM(name)
43+
# CHECK-NEXT: - 72 2b CUSTOM(name)
4444

4545
# RUN: not wasm-ld %t1.o -o /dev/null -Map=/ 2>&1 \
4646
# RUN: | FileCheck -check-prefix=FAIL %s

lld/test/wasm/signature-mismatch-export.ll

+3
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ entry:
2727
; CHECK-NEXT: Name: _start
2828
; CHECK-NEXT: - Index: 2
2929
; CHECK-NEXT: Name: ret32
30+
; CHECK-NEXT: GlobalNames:
31+
; CHECK-NEXT: - Index: 0
32+
; CHECK-NEXT: Name: __stack_pointer
3033
; CHECK-NEXT: ...

lld/test/wasm/signature-mismatch.ll

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ declare i32 @ret32(i32, i64, i32) local_unnamed_addr
5252
; YAML-NEXT: Name: ret32
5353
; YAML-NEXT: - Index: 3
5454
; YAML-NEXT: Name: call_ret32
55+
; YAML-NEXT: GlobalNames:
56+
; YAML-NEXT: - Index: 0
57+
; YAML-NEXT: Name: __stack_pointer
5558
; YAML-NEXT: ...
5659

5760
; RELOC: Name: linking

lld/test/wasm/stack-pointer.ll

+3
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@ entry:
6969
; CHECK-NEXT: FunctionNames:
7070
; CHECK-NEXT: - Index: 0
7171
; CHECK-NEXT: Name: _start
72+
; CHECK-NEXT: GlobalNames:
73+
; CHECK-NEXT: - Index: 0
74+
; CHECK-NEXT: Name: __stack_pointer
7275
; CHECK-NEXT: ...

lld/test/wasm/target-feature-disallowed.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Sections:
3636
...
3737

3838
# SPECIFIED: - Type: CUSTOM
39-
# SPECIFIED-NEXT: Name: target_features
39+
# SPECIFIED: Name: target_features
4040
# SPECIFIED-NEXT: Features:
4141
# SPECIFIED-NEXT: - Prefix: USED
4242
# SPECIFIED-NEXT: Name: bar
@@ -47,7 +47,7 @@ Sections:
4747
# SPECIFIED-NEXT: ...
4848

4949
# UNSPECIFIED: - Type: CUSTOM
50-
# UNSPECIFIED-NEXT: Name: target_features
50+
# UNSPECIFIED: Name: target_features
5151
# UNSPECIFIED-NEXT: Features:
5252
# UNSPECIFIED-NEXT: - Prefix: USED
5353
# UNSPECIFIED-NEXT: Name: bar
@@ -58,14 +58,14 @@ Sections:
5858
# UNSPECIFIED-NEXT: ...
5959

6060
# DISALLOWED: - Type: CUSTOM
61-
# DISALLOWED-NEXT: Name: target_features
61+
# DISALLOWED: Name: target_features
6262
# DISALLOWED-NEXT: Features:
6363
# DISALLOWED-NEXT: - Prefix: USED
6464
# DISALLOWED-NEXT: Name: bar
6565
# DISALLOWED-NEXT: ...
6666

6767
# NONE: - Type: CUSTOM
68-
# NONE-NEXT: Name: target_features
68+
# NONE: Name: target_features
6969
# NONE-NEXT: Features:
7070
# NONE-NEXT: - Prefix: USED
7171
# NONE-NEXT: Name: bar

lld/test/wasm/target-feature-none.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Sections:
2222
# EMPTY-NOT: target_features
2323

2424
# SPECIFIED: - Type: CUSTOM
25-
# SPECIFIED-NEXT: Name: target_features
25+
# SPECIFIED: Name: target_features
2626
# SPECIFIED-NEXT: Features:
2727
# SPECIFIED-NEXT: - Prefix: USED
2828
# SPECIFIED-NEXT: Name: bar

lld/test/wasm/target-feature-required.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Sections:
4141
...
4242

4343
# SPECIFIED: - Type: CUSTOM
44-
# SPECIFIED-NEXT: Name: target_features
44+
# SPECIFIED: Name: target_features
4545
# SPECIFIED-NEXT: Features:
4646
# SPECIFIED-NEXT: - Prefix: USED
4747
# SPECIFIED-NEXT: Name: bar
@@ -54,7 +54,7 @@ Sections:
5454
# UNSPECIFIED: Target feature 'foo' used by {{.*}}target-feature-required.yaml.tmp1.o is not allowed.{{$}}
5555

5656
# UNSPECIFIED-NOCHECK: - Type: CUSTOM
57-
# UNSPECIFIED-NOCHECK-NEXT: Name: target_features
57+
# UNSPECIFIED-NOCHECK: Name: target_features
5858
# UNSPECIFIED-NOCHECK-NEXT: Features:
5959
# UNSPECIFIED-NOCHECK-NEXT: - Prefix: USED
6060
# UNSPECIFIED-NOCHECK-NEXT: Name: bar
@@ -65,7 +65,7 @@ Sections:
6565
# UNSPECIFIED-NOCHECK-NEXT: ...
6666

6767
# REQUIRED: - Type: CUSTOM
68-
# REQUIRED-NEXT: Name: target_features
68+
# REQUIRED: Name: target_features
6969
# REQUIRED-NEXT: Features:
7070
# REQUIRED-NEXT: - Prefix: USED
7171
# REQUIRED-NEXT: Name: foo
@@ -74,7 +74,7 @@ Sections:
7474
# DISALLOWED: Target feature 'foo' used in {{.*}}target-feature-required.yaml.tmp1.o is disallowed by {{.*}}target-feature-required.yaml.tmp.disallowed.o. Use --no-check-features to suppress.{{$}}
7575

7676
# DISALLOWED-NOCHECK: - Type: CUSTOM
77-
# DISALLOWED-NOCHECK-NEXT: Name: target_features
77+
# DISALLOWED-NOCHECK: Name: target_features
7878
# DISALLOWED-NOCHECK-NEXT: Features:
7979
# DISALLOWED-NOCHECK-NEXT: - Prefix: USED
8080
# DISALLOWED-NOCHECK-NEXT: Name: foo
@@ -83,7 +83,7 @@ Sections:
8383
# NONE: Missing target feature 'foo' in {{.*}}target-feature-required.yaml.tmp.none.o, required by {{.*}}target-feature-required.yaml.tmp1.o. Use --no-check-features to suppress.{{$}}
8484

8585
# NONE-NOCHECK: - Type: CUSTOM
86-
# NONE-NOCHECK-NEXT: Name: target_features
86+
# NONE-NOCHECK: Name: target_features
8787
# NONE-NOCHECK-NEXT: Features:
8888
# NONE-NOCHECK-NEXT: - Prefix: USED
8989
# NONE-NOCHECK-NEXT: Name: foo

lld/test/wasm/target-feature-used.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Sections:
4343
...
4444

4545
# SPECIFIED: - Type: CUSTOM
46-
# SPECIFIED-NEXT: Name: target_features
46+
# SPECIFIED: Name: target_features
4747
# SPECIFIED-NEXT: Features:
4848
# SPECIFIED-NEXT: - Prefix: USED
4949
# SPECIFIED-NEXT: Name: bar
@@ -56,7 +56,7 @@ Sections:
5656
# UNSPECIFIED: Target feature 'foo' used by {{.*}}target-feature-used.yaml.tmp1.o is not allowed.{{$}}
5757

5858
# UNSPECIFIED-NOCHECK: - Type: CUSTOM
59-
# UNSPECIFIED-NOCHECK-NEXT: Name: target_features
59+
# UNSPECIFIED-NOCHECK: Name: target_features
6060
# UNSPECIFIED-NOCHECK-NEXT: Features:
6161
# UNSPECIFIED-NOCHECK-NEXT: - Prefix: USED
6262
# UNSPECIFIED-NOCHECK-NEXT: Name: bar
@@ -67,14 +67,14 @@ Sections:
6767
# UNSPECIFIED-NOCHECK-NEXT: ...
6868

6969
# USED: - Type: CUSTOM
70-
# USED-NEXT: Name: target_features
70+
# USED: Name: target_features
7171
# USED-NEXT: Features:
7272
# USED-NEXT: - Prefix: USED
7373
# USED-NEXT: Name: foo
7474
# USED-NEXT: ...
7575

7676
# REQUIRED: - Type: CUSTOM
77-
# REQUIRED-NEXT: Name: target_features
77+
# REQUIRED: Name: target_features
7878
# REQUIRED-NEXT: Features:
7979
# REQUIRED-NEXT: - Prefix: USED
8080
# REQUIRED-NEXT: Name: foo
@@ -83,14 +83,14 @@ Sections:
8383
# DISALLOWED: Target feature 'foo' used in {{.*}}target-feature-used.yaml.tmp1.o is disallowed by {{.*}}target-feature-used.yaml.tmp.disallowed.o. Use --no-check-features to suppress.{{$}}
8484

8585
# DISALLOWED-NOCHECK: - Type: CUSTOM
86-
# DISALLOWED-NOCHECK-NEXT: Name: target_features
86+
# DISALLOWED-NOCHECK: Name: target_features
8787
# DISALLOWED-NOCHECK-NEXT: Features:
8888
# DISALLOWED-NOCHECK-NEXT: - Prefix: USED
8989
# DISALLOWED-NOCHECK-NEXT: Name: foo
9090
# DISALLOWED-NOCHECK-NEXT: ...
9191

9292
# NONE: - Type: CUSTOM
93-
# NONE-NEXT: Name: target_features
93+
# NONE: Name: target_features
9494
# NONE-NEXT: Features:
9595
# NONE-NEXT: - Prefix: USED
9696
# NONE-NEXT: Name: foo

lld/test/wasm/undefined-weak-call.ll

+3
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,7 @@ define i32 @callWeakFuncs() {
9696
; CHECK-NEXT: Name: 'undefined_weak:weakFunc3'
9797
; CHECK-NEXT: - Index: 3
9898
; CHECK-NEXT: Name: callWeakFuncs
99+
; CHECK-NEXT: GlobalNames:
100+
; CHECK-NEXT: - Index: 0
101+
; CHECK-NEXT: Name: __stack_pointer
99102
; CHECK-NEXT: ...

lld/test/wasm/weak-alias-overide.ll

+3
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,7 @@ entry:
129129
; CHECK-NEXT: Name: call_alias_ptr
130130
; CHECK-NEXT: - Index: 6
131131
; CHECK-NEXT: Name: call_direct_ptr
132+
; CHECK-NEXT: GlobalNames:
133+
; CHECK-NEXT: - Index: 0
134+
; CHECK-NEXT: Name: __stack_pointer
132135
; CHECK-NEXT: ...

lld/test/wasm/weak-alias.ll

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ entry:
121121
; CHECK-NEXT: Name: call_alias_ptr
122122
; CHECK-NEXT: - Index: 5
123123
; CHECK-NEXT: Name: call_direct_ptr
124+
; CHECK-NEXT: GlobalNames:
125+
; CHECK-NEXT: - Index: 0
126+
; CHECK-NEXT: Name: __stack_pointer
124127
; CHECK-NEXT: ...
125128

126129
; RUN: wasm-ld --relocatable %t.o %t2.o -o %t.reloc.o
@@ -288,4 +291,7 @@ entry:
288291
; RELOC-NEXT: Name: call_alias_ptr
289292
; RELOC-NEXT: - Index: 5
290293
; RELOC-NEXT: Name: call_direct_ptr
294+
; RELOC-NEXT: GlobalNames:
295+
; RELOC-NEXT: - Index: 0
296+
; RELOC-NEXT: Name: __stack_pointer
291297
; RELOC-NEXT: ...

lld/test/wasm/weak-symbols.ll

+3
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,7 @@ entry:
115115
; CHECK-NEXT: Name: exportWeak1
116116
; CHECK-NEXT: - Index: 3
117117
; CHECK-NEXT: Name: exportWeak2
118+
; CHECK-NEXT: GlobalNames:
119+
; CHECK-NEXT: - Index: 0
120+
; CHECK-NEXT: Name: __stack_pointer
118121
; CHECK-NEXT: ...

0 commit comments

Comments
 (0)