diff options
Diffstat (limited to 'lld/test/wasm')
69 files changed, 883 insertions, 365 deletions
diff --git a/lld/test/wasm/Inputs/import-attributes.s b/lld/test/wasm/Inputs/import-attributes.s deleted file mode 100644 index 031d472..0000000 --- a/lld/test/wasm/Inputs/import-attributes.s +++ /dev/null @@ -1,9 +0,0 @@ -.functype foo () -> () - - .globl call_foo -call_foo: - .functype call_foo () -> () - call foo - end_function - - .import_module foo, baz diff --git a/lld/test/wasm/alias.s b/lld/test/wasm/alias.s index 0bb035b..83f40a8 100644 --- a/lld/test/wasm/alias.s +++ b/lld/test/wasm/alias.s @@ -24,7 +24,7 @@ _start: # CHECK-NEXT: FunctionTypes: [ 0 ] # CHECK-NEXT: - Type: MEMORY # CHECK-NEXT: Memories: -# CHECK-NEXT: - Minimum: 0x2 +# CHECK-NEXT: - Minimum: 0x1 # CHECK-NEXT: - Type: GLOBAL # CHECK-NEXT: Globals: # CHECK-NEXT: - Index: 0 @@ -32,7 +32,7 @@ _start: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66560 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Type: EXPORT # CHECK-NEXT: Exports: # CHECK-NEXT: - Name: memory diff --git a/lld/test/wasm/bss-only.s b/lld/test/wasm/bss-only.s index 1c0500f..bec7592 100644 --- a/lld/test/wasm/bss-only.s +++ b/lld/test/wasm/bss-only.s @@ -26,13 +26,13 @@ b: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 67568 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Type: I32 # CHECK-NEXT: Mutable: false # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 2028 +# CHECK-NEXT: Value: 66540 # CHECK-NEXT: - Type: EXPORT # CHECK-NEXT: Exports: # CHECK-NEXT: - Name: memory diff --git a/lld/test/wasm/build-id.test b/lld/test/wasm/build-id.test index dd6e223710..5fafd21 100644 --- a/lld/test/wasm/build-id.test +++ b/lld/test/wasm/build-id.test @@ -43,12 +43,12 @@ foo: # DEFAULT: Contents of section build_id: -# DEFAULT-NEXT: 0079 10299168 1e3c845a 3c8f80ae 2f16cc22 .).h.<.Z<.../.." -# DEFAULT-NEXT: 0089 2d +# DEFAULT-NEXT: 0079 103f86e6 3bb81959 2e99ffa9 acfed331 .?..;..Y.......1 +# DEFAULT-NEXT: 0089 3a # SHA1: Contents of section build_id: -# SHA1-NEXT: 0079 145abdda 387a9bc4 e3aed3c3 3319cd37 .Z..8z......3..7 -# SHA1-NEXT: 0089 0212237c e4 ..#|. +# SHA1-NEXT: 0079 1410ade4 e75d1c9d 71023465 03b7572f .....]..q.4e..W/ +# SHA1-NEXT: 0089 c06c5ae0 74 .lZ.t # UUID: Contents of section build_id: # UUID-NEXT: 0079 10 diff --git a/lld/test/wasm/call-indirect.s b/lld/test/wasm/call-indirect.s index 7bf39a9..64eaa59 100644 --- a/lld/test/wasm/call-indirect.s +++ b/lld/test/wasm/call-indirect.s @@ -82,13 +82,13 @@ indirect_func: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66576 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Type: I32 # CHECK-NEXT: Mutable: false # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1032 +# CHECK-NEXT: Value: 65544 # CHECK-NEXT: - Type: EXPORT # CHECK-NEXT: Exports: # CHECK-NEXT: - Name: memory @@ -125,23 +125,23 @@ indirect_func: # CHECK-NEXT: Body: 42010B # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Locals: -# CHECK-NEXT: Body: 410028028088808000118080808000001A410028028488808000118180808000001A0B +# CHECK-NEXT: Body: 410028028080848000118080808000001A410028028480848000118180808000001A0B # CHECK-NEXT: - Index: 2 # CHECK-NEXT: Locals: # CHECK-NEXT: Body: 41020B # CHECK-NEXT: - Index: 3 # CHECK-NEXT: Locals: -# CHECK-NEXT: Body: 410028028888808000118180808000001A0B +# CHECK-NEXT: Body: 410028028880848000118180808000001A0B # CHECK-NEXT: - Index: 4 # CHECK-NEXT: Locals: # CHECK-NEXT: Body: 42012000118280808000001A0B # CHECK-NEXT: - Type: DATA # CHECK-NEXT: Segments: -# CHECK-NEXT: - SectionOffset: 7 +# CHECK-NEXT: - SectionOffset: 8 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: Content: '010000000200000002000000' # CHECK-NEXT: - Type: CUSTOM # CHECK-NEXT: Name: name diff --git a/lld/test/wasm/comdats.ll b/lld/test/wasm/comdats.ll index 2dd687f..1662a98 100644 --- a/lld/test/wasm/comdats.ll +++ b/lld/test/wasm/comdats.ll @@ -23,13 +23,13 @@ entry: ; CHECK-NEXT: Mutable: true ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66576 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: - Type: EXPORT ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: memory @@ -69,7 +69,7 @@ entry: ; CHECK-NEXT: Body: 1080808080001082808080001A0B ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 4180888080000B +; CHECK-NEXT: Body: 4180808480000B ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 0B @@ -81,9 +81,9 @@ entry: ; CHECK-NEXT: Body: 4181808080000B ; CHECK-NEXT: - Type: DATA ; CHECK-NEXT: Segments: -; CHECK-NEXT: - SectionOffset: 7 +; CHECK-NEXT: - SectionOffset: 8 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: Content: '616263' diff --git a/lld/test/wasm/compact-imports.s b/lld/test/wasm/compact-imports.s new file mode 100644 index 0000000..4c6ddc2 --- /dev/null +++ b/lld/test/wasm/compact-imports.s @@ -0,0 +1,27 @@ +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s +# RUN: wasm-ld --experimental-pic --unresolved-symbols=import-dynamic %t.o -o %t.wasm + +.functype foo () -> () +.functype bar () -> () + +.globl _start +_start: + .functype _start () -> () + call foo + call bar + end_function + +.section .custom_section.target_features,"",@ +.int8 1 +.int8 43 +.int8 15 +.ascii "compact-imports" + +# Neither llvm-readobj nor obj2yaml currently report compact imports differently +# so the check here is just for the size of the import section. The Size here +# is larger than 20 bytes without compact imports enabled. + +# RUN: llvm-readobj --sections %t.wasm | FileCheck %s + +# CHECK: Type: IMPORT (0x2) +# CHECK-NEXT: Size: 20 diff --git a/lld/test/wasm/compress-relocs.s b/lld/test/wasm/compress-relocs.s index 41d4ff5..37f1b3b 100644 --- a/lld/test/wasm/compress-relocs.s +++ b/lld/test/wasm/compress-relocs.s @@ -47,16 +47,16 @@ test_memory_and_indirect_call_relocs: end_function # CHECK: test_memory_and_indirect_call_relocs -# CHECK: 41 90 88 80 80 00 i32.const 1040 +# CHECK: 41 90 80 84 80 00 i32.const 65552 # CHECK: 11 80 80 80 80 00 80 80 80 80 00 call_indirect 0 -# CHECK: 28 02 94 88 80 80 00 i32.load 1044 +# CHECK: 28 02 94 80 84 80 00 i32.load 65556 # CHECK: 11 81 80 80 80 00 80 80 80 80 00 call_indirect 1 # CHECK: 41 81 80 80 80 00 i32.const 1 # CHECK: 11 80 80 80 80 00 80 80 80 80 00 call_indirect 0 # COMPRESS: test_memory_and_indirect_call_relocs -# COMPRESS: 41 90 08 i32.const 1040 +# COMPRESS: 41 90 80 04 i32.const 65552 # COMPRESS: 11 00 00 call_indirect 0 -# COMPRESS: 28 02 94 08 i32.load 1044 +# COMPRESS: 28 02 94 80 04 i32.load 65556 # COMPRESS: 11 01 00 call_indirect 1 # COMPRESS: 41 01 i32.const 1 # COMPRESS: 11 00 00 call_indirect 0 @@ -91,11 +91,11 @@ test_relative_relocs: end_function # CHECK: test_relative_relocs -# CHECK: 41 90 88 80 80 00 i32.const 1040 +# CHECK: 41 90 80 84 80 00 i32.const 65552 # CHECK: 41 81 80 80 80 00 i32.const 1 # CHECK: 41 83 80 80 80 00 i32.const 3 # COMPRESS: test_relative_relocs -# COMPRESS: 41 90 08 i32.const 1040 +# COMPRESS: 41 90 80 04 i32.const 65552 # COMPRESS: 41 01 i32.const 1 # COMPRESS: 41 03 i32.const 3 diff --git a/lld/test/wasm/compress-relocs64.s b/lld/test/wasm/compress-relocs64.s index 44e7a08..f3ff646 100644 --- a/lld/test/wasm/compress-relocs64.s +++ b/lld/test/wasm/compress-relocs64.s @@ -36,12 +36,12 @@ test_memory_and_indirect_call_relocs: end_function # CHECK: test_memory_and_indirect_call_relocs -# CHECK: 42 90 88 80 80 80 80 80 80 80 00 i64.const 1040 -# CHECK: 29 03 98 88 80 80 80 80 80 80 80 00 i64.load 1048 +# CHECK: 42 90 80 84 80 80 80 80 80 80 00 i64.const 65552 +# CHECK: 29 03 98 80 84 80 80 80 80 80 80 00 i64.load 65560 # CHECK: 42 81 80 80 80 80 80 80 80 80 00 i64.const 1 # COMPRESS: test_memory_and_indirect_call_relocs -# COMPRESS: 42 90 08 i64.const 1040 -# COMPRESS: 29 03 98 08 i64.load 1048 +# COMPRESS: 42 90 80 04 i64.const 65552 +# COMPRESS: 29 03 98 80 04 i64.load 65560 # COMPRESS: 42 01 i64.const 1 .globl test_relative_relocs @@ -56,11 +56,11 @@ test_relative_relocs: end_function # CHECK: test_relative_relocs -# CHECK: 42 90 88 80 80 80 80 80 80 80 00 i64.const 1040 +# CHECK: 42 90 80 84 80 80 80 80 80 80 00 i64.const 65552 # CHECK: 42 81 80 80 80 80 80 80 80 80 00 i64.const 1 # CHECK: 42 83 80 80 80 80 80 80 80 80 00 i64.const 3 # COMPRESS: test_relative_relocs -# COMPRESS: 42 90 08 i64.const 1040 +# COMPRESS: 42 90 80 04 i64.const 65552 # COMPRESS: 42 01 i64.const 1 # COMPRESS: 42 03 i64.const 3 diff --git a/lld/test/wasm/custom-section-name.ll b/lld/test/wasm/custom-section-name.ll index 8799fbf..89cb72f 100644 --- a/lld/test/wasm/custom-section-name.ll +++ b/lld/test/wasm/custom-section-name.ll @@ -16,29 +16,29 @@ target triple = "wasm32-unknown-unknown" ; CHECK-LABEL: - Type: DATA ; CHECK-NEXT: Segments: -; CHECK-NEXT: - SectionOffset: 7 +; CHECK-NEXT: - SectionOffset: 8 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: Content: '00000000' -; CHECK-NEXT: - SectionOffset: 17 +; CHECK-NEXT: - SectionOffset: 19 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1028 +; CHECK-NEXT: Value: 65540 ; CHECK-NEXT: Content: 2A000000 -; CHECK-NEXT: - SectionOffset: 27 +; CHECK-NEXT: - SectionOffset: 30 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1032 +; CHECK-NEXT: Value: 65544 ; CHECK-NEXT: Content: '07000000' -; BSS-NEXT: - SectionOffset: 37 +; BSS-NEXT: - SectionOffset: 41 ; BSS-NEXT: InitFlags: 0 ; BSS-NEXT: Offset: ; BSS-NEXT: Opcode: I32_CONST -; BSS-NEXT: Value: 1036 +; BSS-NEXT: Value: 65548 ; BSS-NEXT: Content: '00000000' ; NO-BSS-NOT: - SectionOffset: diff --git a/lld/test/wasm/data-layout.s b/lld/test/wasm/data-layout.s index a68bc03..653bec9 100644 --- a/lld/test/wasm/data-layout.s +++ b/lld/test/wasm/data-layout.s @@ -1,11 +1,11 @@ # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/hello.s -o %t.hello32.o # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t32.o -# RUN: wasm-ld -m wasm32 -no-gc-sections --export=__data_end --export=__heap_base --allow-undefined --no-entry -o %t32.wasm %t32.o %t.hello32.o +# RUN: wasm-ld -m wasm32 -no-gc-sections --export=__rodata_start --export=__rodata_end --export=__data_end --export=__heap_base --allow-undefined --no-entry -o %t32.wasm %t32.o %t.hello32.o # RUN: obj2yaml %t32.wasm | FileCheck -DPTR=I32 %s # # RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-unknown %p/Inputs/hello.s -o %t.hello64.o # RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-unknown %s -o %t64.o -# RUN: wasm-ld -m wasm64 -no-gc-sections --export=__data_end --export=__heap_base --allow-undefined --no-entry -o %t64.wasm %t64.o %t.hello64.o +# RUN: wasm-ld -m wasm64 -no-gc-sections --export=__rodata_start --export=__rodata_end --export=__data_end --export=__heap_base --allow-undefined --no-entry -o %t64.wasm %t64.o %t.hello64.o # RUN: obj2yaml %t64.wasm | FileCheck --check-prefixes CHECK,CHK64 -DPTR=I64 %s .section .data.foo,"",@ @@ -25,6 +25,13 @@ aligned_bar: .int32 3 .size aligned_bar, 4 + .section .rodata.baz,"",@ + .globl baz + .hidden baz + .p2align 2 +baz: + .int32 42 + .size baz, 4 .section .data.external_ref,"",@ .globl external_ref @@ -63,33 +70,45 @@ local_struct_internal_ptr: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: [[PTR]]_CONST -# CHECK-NEXT: Value: 66624 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Type: [[PTR]] # CHECK-NEXT: Mutable: false # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: [[PTR]]_CONST -# CHECK-NEXT: Value: 1080 +# CHECK-NEXT: Value: 65592 # CHECK-NEXT: - Index: 2 # CHECK-NEXT: Type: [[PTR]] # CHECK-NEXT: Mutable: false # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: [[PTR]]_CONST -# CHECK-NEXT: Value: 66624 +# CHECK-NEXT: Value: 65536 +# CHECK-NEXT: - Index: 3 +# CHECK-NEXT: Type: [[PTR]] +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: [[PTR]]_CONST +# CHECK-NEXT: Value: 65547 +# CHECK-NEXT: - Index: 4 +# CHECK-NEXT: Type: [[PTR]] +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: [[PTR]]_CONST +# CHECK-NEXT: Value: 65600 # CHECK: - Type: DATA # CHECK-NEXT: Segments: -# CHECK-NEXT: - SectionOffset: 7 +# CHECK-NEXT: - SectionOffset: 8 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: [[PTR]]_CONST -# CHECK-NEXT: Value: 1024 -# CHECK-NEXT: Content: 68656C6C6F0A00 -# CHECK-NEXT: - SectionOffset: 20 +# CHECK-NEXT: Value: 65536 +# CHECK-NEXT: Content: 2A00000068656C6C6F0A00 +# CHECK-NEXT: - SectionOffset: 26 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: [[PTR]]_CONST -# CHECK-NEXT: Value: 1040 +# CHECK-NEXT: Value: 65552 # RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry \ diff --git a/lld/test/wasm/data-segment-merging.ll b/lld/test/wasm/data-segment-merging.ll index e6f3c5e..34c49e8 100644 --- a/lld/test/wasm/data-segment-merging.ll +++ b/lld/test/wasm/data-segment-merging.ll @@ -15,11 +15,11 @@ ; MERGE-LABEL: - Type: DATA ; MERGE-NEXT: Segments: -; MERGE-NEXT: - SectionOffset: 7 +; MERGE-NEXT: - SectionOffset: 8 ; MERGE-NEXT: InitFlags: 0 ; MERGE-NEXT: Offset: ; MERGE: Content: 636F6E7374616E74000000002B -; MERGE-NEXT: - SectionOffset: 26 +; MERGE-NEXT: - SectionOffset: 28 ; MERGE-NEXT: InitFlags: 0 ; MERGE-NEXT: Offset: ; MERGE: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000 @@ -41,27 +41,27 @@ ; SEPARATE-NOT: DATACOUNT ; SEPARATE-LABEL: - Type: DATA ; SEPARATE-NEXT: Segments: -; SEPARATE-NEXT: - SectionOffset: 7 +; SEPARATE-NEXT: - SectionOffset: 8 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: ; SEPARATE: Content: 636F6E7374616E7400 -; SEPARATE-NEXT: - SectionOffset: 22 +; SEPARATE-NEXT: - SectionOffset: 24 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: ; SEPARATE: Content: 2B -; SEPARATE-NEXT: - SectionOffset: 29 +; SEPARATE-NEXT: - SectionOffset: 32 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: ; SEPARATE: Content: 68656C6C6F00 -; SEPARATE-NEXT: - SectionOffset: 41 +; SEPARATE-NEXT: - SectionOffset: 45 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: ; SEPARATE: Content: 676F6F6462796500 -; SEPARATE-NEXT: - SectionOffset: 55 +; SEPARATE-NEXT: - SectionOffset: 60 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: ; SEPARATE: Content: '776861746576657200' -; SEPARATE-NEXT: - SectionOffset: 70 +; SEPARATE-NEXT: - SectionOffset: 76 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: ; SEPARATE: Content: 2A000000 diff --git a/lld/test/wasm/data-segments.ll b/lld/test/wasm/data-segments.ll index 6c401c4..237f428 100644 --- a/lld/test/wasm/data-segments.ll +++ b/lld/test/wasm/data-segments.ll @@ -61,20 +61,20 @@ ; ACTIVE-NEXT: Body: 0B ; ACTIVE-NEXT: - Type: DATA ; ACTIVE-NEXT: Segments: -; ACTIVE-NEXT: - SectionOffset: 7 +; ACTIVE-NEXT: - SectionOffset: 8 ; ACTIVE-NEXT: InitFlags: 0 ; ACTIVE-NEXT: Offset: ; ACTIVE32-NEXT: Opcode: I32_CONST ; ACTIVE64-NEXT: Opcode: I64_CONST -; ACTIVE-NEXT: Value: 1024 +; ACTIVE-NEXT: Value: 65536 ; ACTIVE-NEXT: Content: 636F6E7374616E74000000002B -; ACTIVE-NEXT: - SectionOffset: 26 +; ACTIVE-NEXT: - SectionOffset: 28 ; ACTIVE-NEXT: InitFlags: 0 ; ACTIVE-NEXT: Offset: ; ACTIVE32-NEXT: Opcode: I32_CONST ; ACTIVE64-NEXT: Opcode: I64_CONST -; ACTIVE-NEXT: Value: 1040 -; ACTIVE-NEXT: Content: 68656C6C6F00676F6F646279650000002A000000 +; ACTIVE-NEXT: Value: 65552 +; ACTIVE-NEXT: Content: 68656C6C6F00676F6F646279650000002A00000063000000 ; ACTIVE-NEXT: - Type: CUSTOM ; ACTIVE-NEXT: Name: name ; ACTIVE-NEXT: FunctionNames: @@ -201,7 +201,7 @@ ; DIS-NEXT: block ; DIS-NEXT: block -; NOPIC-DIS-NEXT: [[PTR]].const 11064 +; NOPIC-DIS-NEXT: [[PTR]].const 75576 ; PIC-DIS-NEXT: local.get 0 ; DIS-NEXT: i32.const 0 @@ -211,8 +211,8 @@ ; DIS-NEXT: # 2: down to label0 ; DIS-NEXT: end -; NOPIC-DIS-NEXT: [[PTR]].const 1024 -; NOPIC-DIS-NEXT: [[PTR]].const 1024 +; NOPIC-DIS-NEXT: [[PTR]].const 65536 +; NOPIC-DIS-NEXT: [[PTR]].const 65536 ; NOPIC-DIS-NEXT: global.set 1 ; PIC-DIS-NEXT: [[PTR]].const 0 ; PIC-DIS-NEXT: global.get 1 @@ -224,7 +224,7 @@ ; DIS-NEXT: i32.const 4 ; DIS-NEXT: memory.init 0, 0 -; NOPIC-DIS-NEXT: [[PTR]].const 1028 +; NOPIC-DIS-NEXT: [[PTR]].const 65540 ; PIC-DIS-NEXT: [[PTR]].const 4 ; PIC-DIS-NEXT: global.get 1 ; PIC-DIS-NEXT: [[PTR]].add @@ -233,7 +233,7 @@ ; DIS-NEXT: i32.const 13 ; DIS-NEXT: memory.init 1, 0 -; NOPIC-DIS-NEXT: [[PTR]].const 1044 +; NOPIC-DIS-NEXT: [[PTR]].const 65556 ; PIC-DIS-NEXT: [[PTR]].const 20 ; PIC-DIS-NEXT: global.get 1 ; PIC-DIS-NEXT: [[PTR]].add @@ -241,7 +241,7 @@ ; DIS-NEXT: i32.const 0 ; DIS-NEXT: i32.const 20 ; DIS-NEXT: memory.init 2, 0 -; NOPIC-DIS-NEXT: [[PTR]].const 1064 +; NOPIC-DIS-NEXT: [[PTR]].const 65576 ; PIC-DIS-NEXT: [[PTR]].const 40 ; PIC-DIS-NEXT: global.get 1 ; PIC-DIS-NEXT: [[PTR]].add @@ -249,13 +249,13 @@ ; DIS-NEXT: [[PTR]].const 10000 ; DIS-NEXT: memory.fill 0 -; NOPIC-DIS-NEXT: [[PTR]].const 11064 +; NOPIC-DIS-NEXT: [[PTR]].const 75576 ; PIC-DIS-NEXT: local.get 0 ; DIS-NEXT: i32.const 2 ; DIS-NEXT: i32.atomic.store 0 -; NOPIC-DIS-NEXT: [[PTR]].const 11064 +; NOPIC-DIS-NEXT: [[PTR]].const 75576 ; PIC-DIS-NEXT: local.get 0 ; DIS-NEXT: i32.const -1 @@ -264,7 +264,7 @@ ; DIS-NEXT: br 1 # 1: down to label1 ; DIS-NEXT: end -; NOPIC-DIS-NEXT: [[PTR]].const 11064 +; NOPIC-DIS-NEXT: [[PTR]].const 75576 ; PIC-DIS-NEXT: local.get 0 ; DIS-NEXT: i32.const 1 diff --git a/lld/test/wasm/debug-weak-unused.s b/lld/test/wasm/debug-weak-unused.s new file mode 100644 index 0000000..ccd0c4e --- /dev/null +++ b/lld/test/wasm/debug-weak-unused.s @@ -0,0 +1,36 @@ +# Verify that we can handle R_WASM_FUNCTION_OFFSET relocations against weak +# symbols that were defined in shared libraries. +# Test that the .debug_info is generated without error and contains the +# tombstone value. +# +# Based on debug-undefined-fs.s +# +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t_ret32.o %p/Inputs/ret32.s +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s +# RUN: wasm-ld -shared -o %t_lib.so %t_ret32.o +# RUN: wasm-ld -pie %t_lib.so %t.o -o %t.wasm +# RUN: obj2yaml %t.wasm | FileCheck %s + +# ret32 is weakly defined here, but strongly defined in the shared library. +# So we expect the tombstone to be written for relocations refering to it in +# the debug section. +.globl ret32 +.weak ret32 +ret32: + .functype ret32 (f32) -> (i32) + i32.const 0 + end_function + +.globl _start +_start: + .functype _start () -> () + f32.const 0.0 + call ret32 + drop + end_function + +.section .debug_info,"",@ + .int32 ret32 + +# CHECK: Name: .debug_info +# CHECK-NEXT: Payload: FFFFFFFF diff --git a/lld/test/wasm/debuginfo.test b/lld/test/wasm/debuginfo.test index 9cb1cc3..7e6bd51 100644 --- a/lld/test/wasm/debuginfo.test +++ b/lld/test/wasm/debuginfo.test @@ -50,7 +50,7 @@ CHECK-NEXT: DW_AT_type (0x000000ac "int[2]") CHECK-NEXT: DW_AT_external (true) CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c") CHECK-NEXT: DW_AT_decl_line (1) -CHECK: DW_AT_location (DW_OP_addr 0x400) +CHECK: DW_AT_location (DW_OP_addr 0x10000) CHECK: DW_TAG_array_type diff --git a/lld/test/wasm/dylink-non-pie.s b/lld/test/wasm/dylink-non-pie.s index 3157b8c..fddfddb 100755 --- a/lld/test/wasm/dylink-non-pie.s +++ b/lld/test/wasm/dylink-non-pie.s @@ -32,7 +32,7 @@ f_p: # DIS: <__wasm_apply_data_relocs>: # DIS-EMPTY: -# DIS-NEXT: i32.const 1024 +# DIS-NEXT: i32.const 65536 # DIS-NEXT: global.get 0 # DIS-NEXT: i32.store 0 # DIS-NEXT: end diff --git a/lld/test/wasm/emit-relocs.s b/lld/test/wasm/emit-relocs.s index 385344c..3df345c 100644 --- a/lld/test/wasm/emit-relocs.s +++ b/lld/test/wasm/emit-relocs.s @@ -41,11 +41,11 @@ foo: # CHECK: - Type: DATA # CHECK-NEXT: Segments: -# CHECK-NEXT: - SectionOffset: 7 +# CHECK-NEXT: - SectionOffset: 8 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: Content: '00000000' # There should be a single relocation in this section (just the live symbol) @@ -75,5 +75,5 @@ foo: # CHECK-NEXT: Kind: DATA # CHECK-NEXT: Name: __stack_low # CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN, ABSOLUTE ] -# CHECK-NEXT: Offset: 1040 # CHECK-NEXT: Size: 0 +# CHECK-NEXT: - Index: 3 diff --git a/lld/test/wasm/export-all.s b/lld/test/wasm/export-all.s index 617dcc4..5ae7300 100644 --- a/lld/test/wasm/export-all.s +++ b/lld/test/wasm/export-all.s @@ -30,28 +30,41 @@ foo: # CHECK-NEXT: Index: 1 # CHECK-NEXT: - Name: __dso_handle # CHECK-NEXT: Kind: GLOBAL -# CHECK-NEXT: Index: 1 +# CHECK-NEXT: Index: 4 # CHECK-NEXT: - Name: __data_end # CHECK-NEXT: Kind: GLOBAL -# CHECK-NEXT: Index: 2 +# CHECK-NEXT: Index: 5 +# CHECK-NEXT: - Name: __rodata_start +# CHECK-NEXT: Kind: GLOBAL +# CHECK-NEXT: Index: 6 +# CHECK-NEXT: - Name: __rodata_end +# CHECK-NEXT: Kind: GLOBAL +# CHECK-NEXT: Index: 7 # CHECK-NEXT: - Name: __stack_low # CHECK-NEXT: Kind: GLOBAL -# CHECK-NEXT: Index: 3 +# CHECK-NEXT: Index: 8 # CHECK-NEXT: - Name: __stack_high # CHECK-NEXT: Kind: GLOBAL -# CHECK-NEXT: Index: 4 +# CHECK-NEXT: Index: 9 # CHECK-NEXT: - Name: __global_base # CHECK-NEXT: Kind: GLOBAL -# CHECK-NEXT: Index: 5 +# CHECK-NEXT: Index: 10 # CHECK-NEXT: - Name: __heap_base # CHECK-NEXT: Kind: GLOBAL -# CHECK-NEXT: Index: 6 +# CHECK-NEXT: Index: 11 # CHECK-NEXT: - Name: __heap_end # CHECK-NEXT: Kind: GLOBAL -# CHECK-NEXT: Index: 7 +# CHECK-NEXT: Index: 12 # CHECK-NEXT: - Name: __memory_base # CHECK-NEXT: Kind: GLOBAL -# CHECK-NEXT: Index: 8 +# CHECK-NEXT: Index: 1 # CHECK-NEXT: - Name: __table_base # CHECK-NEXT: Kind: GLOBAL -# CHECK-NEXT: Index: 9 +# CHECK-NEXT: Index: 2 +# CHECK-NEXT: - Name: __wasm_first_page_end +# CHECK-NEXT: Kind: GLOBAL +# CHECK-NEXT: Index: 13 +# CHECK-NEXT: - Name: __tls_base +# CHECK-NEXT: Kind: GLOBAL +# CHECK-NEXT: Index: 3 +# CHECK-NEXT: - Type: CODE diff --git a/lld/test/wasm/externref.s b/lld/test/wasm/externref.s index ffc63a6..1443e5f 100644 --- a/lld/test/wasm/externref.s +++ b/lld/test/wasm/externref.s @@ -35,7 +35,7 @@ _start: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66560 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Type: EXTERNREF # CHECK-NEXT: Mutable: true diff --git a/lld/test/wasm/gc-sections.ll b/lld/test/wasm/gc-sections.ll index e709ab7..69d7ed2 100644 --- a/lld/test/wasm/gc-sections.ll +++ b/lld/test/wasm/gc-sections.ll @@ -57,7 +57,7 @@ entry: ; CHECK-NEXT: Mutable: true ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66576 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Type: I64 ; CHECK-NEXT: Mutable: true @@ -67,11 +67,11 @@ entry: ; CHECK: - Type: DATA ; CHECK-NEXT: Segments: -; CHECK-NEXT: - SectionOffset: 7 +; CHECK-NEXT: - SectionOffset: 8 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: Content: '02000000' ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name @@ -123,7 +123,7 @@ entry: ; NO-GC-NEXT: Mutable: true ; NO-GC-NEXT: InitExpr: ; NO-GC-NEXT: Opcode: I32_CONST -; NO-GC-NEXT: Value: 66576 +; NO-GC-NEXT: Value: 65536 ; NO-GC-NEXT: - Index: 1 ; NO-GC-NEXT: Type: I64 ; NO-GC-NEXT: Mutable: true @@ -139,11 +139,11 @@ entry: ; NO-GC: - Type: DATA ; NO-GC-NEXT: Segments: -; NO-GC-NEXT: - SectionOffset: 7 +; NO-GC-NEXT: - SectionOffset: 8 ; NO-GC-NEXT: InitFlags: 0 ; NO-GC-NEXT: Offset: ; NO-GC-NEXT: Opcode: I32_CONST -; NO-GC-NEXT: Value: 1024 +; NO-GC-NEXT: Value: 65536 ; NO-GC-NEXT: Content: '010000000000000002000000' ; NO-GC-NEXT: - Type: CUSTOM ; NO-GC-NEXT: Name: name diff --git a/lld/test/wasm/global-base.test b/lld/test/wasm/global-base.test index 0e65f0c..e84b8ec 100644 --- a/lld/test/wasm/global-base.test +++ b/lld/test/wasm/global-base.test @@ -19,19 +19,19 @@ CHECK-1024-NEXT: Type: I32 CHECK-1024-NEXT: Mutable: true CHECK-1024-NEXT: InitExpr: CHECK-1024-NEXT: Opcode: I32_CONST -CHECK-1024-NEXT: Value: 66560 +CHECK-1024-NEXT: Value: 65536 CHECK-1024-NEXT: - Index: 1 CHECK-1024-NEXT: Type: I32 CHECK-1024-NEXT: Mutable: false CHECK-1024-NEXT: InitExpr: CHECK-1024-NEXT: Opcode: I32_CONST -CHECK-1024-NEXT: Value: 1024 +CHECK-1024-NEXT: Value: 65536 CHECK-1024-NEXT: - Index: 2 CHECK-1024-NEXT: Type: I32 CHECK-1024-NEXT: Mutable: false CHECK-1024-NEXT: InitExpr: CHECK-1024-NEXT: Opcode: I32_CONST -CHECK-1024-NEXT: Value: 1024 +CHECK-1024-NEXT: Value: 65536 CHECK-1024: - Type: EXPORT CHECK-1024: - Name: __data_end @@ -50,7 +50,7 @@ CHECK-16777216-NEXT: Type: I32 CHECK-16777216-NEXT: Mutable: true CHECK-16777216-NEXT: InitExpr: CHECK-16777216-NEXT: Opcode: I32_CONST -CHECK-16777216-NEXT: Value: 16842752 +CHECK-16777216-NEXT: Value: 65536 CHECK-16777216-NEXT: - Index: 1 CHECK-16777216-NEXT: Type: I32 CHECK-16777216-NEXT: Mutable: false diff --git a/lld/test/wasm/globals.s b/lld/test/wasm/globals.s index 6e049e1..47d9ba8 100644 --- a/lld/test/wasm/globals.s +++ b/lld/test/wasm/globals.s @@ -42,7 +42,7 @@ immutable_global: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66560 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Type: I32 # CHECK-NEXT: Mutable: false diff --git a/lld/test/wasm/import-attribute-mismatch.s b/lld/test/wasm/import-attribute-mismatch.s index 59988dc..81ad8fe 100644 --- a/lld/test/wasm/import-attribute-mismatch.s +++ b/lld/test/wasm/import-attribute-mismatch.s @@ -1,17 +1,58 @@ -# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t1.o %s -# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %S/Inputs/import-attributes.s -o %t2.o -# RUN: not wasm-ld --export call_foo --allow-undefined -o %t.wasm %t1.o %t2.o 2>&1 | FileCheck %s +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -mattr=+reference-types -mattr=+exception-handling -o %t/main.o %t/main.s +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -mattr=+reference-types -mattr=+exception-handling -o %t/other.o %t/other.s +# RUN: not wasm-ld --export call_foo --allow-undefined -o %t.wasm %t/main.o %t/other.o 2>&1 | FileCheck %s + +#--- main.s .functype foo () -> () +.tabletype mytable, funcref +.globaltype myglobal, i32 +.globaltype myglobal, i32 +.tagtype mytag i32 - .globl _start +.globl _start _start: .functype _start () -> () - call foo + i32.const foo + call_indirect mytable, () -> () + global.get myglobal + throw mytag end_function -.import_module foo, bar +#--- other.s + +.functype foo () -> () +.globaltype myglobal, i32 +.tabletype mytable, funcref +.tagtype mytag i32 + +.globl call_foo +call_foo: + .functype call_foo () -> () + i32.const foo + call_indirect mytable, () -> () + global.get myglobal + throw mytag + end_function + +.import_module foo, mod1 +.import_module mytable, mod2 +.import_module myglobal, mod3 +.import_module mytag, mod4 # CHECK: wasm-ld: error: import module mismatch for symbol: foo -# CHECK: >>> defined as bar in {{.*}}1.o -# CHECK: >>> defined as baz in {{.*}}2.o +# CHECK-NEXT: >>> defined as env in {{.*}}main.o +# CHECK-NEXT: >>> defined as mod1 in {{.*}}other.o + +# CHECK: wasm-ld: error: import module mismatch for symbol: mytable +# CHECK-NEXT: >>> defined as env in {{.*}}main.o +# CHECK-NEXT: >>> defined as mod2 in {{.*}}other.o + +# CHECK: wasm-ld: error: import module mismatch for symbol: myglobal +# CHECK-NEXT: >>> defined as env in {{.*}}main.o +# CHECK-NEXT: >>> defined as mod3 in {{.*}}other.o + +# CHECK: wasm-ld: error: import module mismatch for symbol: mytag +# CHECK-NEXT: >>> defined as env in {{.*}}main.o +# CHECK-NEXT: >>> defined as mod4 in {{.*}}other.o diff --git a/lld/test/wasm/import-memory.test b/lld/test/wasm/import-memory.test index dd7066d..9b8148e 100644 --- a/lld/test/wasm/import-memory.test +++ b/lld/test/wasm/import-memory.test @@ -10,7 +10,7 @@ # CHECK-NEXT: Field: memory # CHECK-NEXT: Kind: MEMORY # CHECK-NEXT: Memory: -# CHECK-NEXT: Minimum: 0x2 +# CHECK-NEXT: Minimum: 0x1 # CHECK-NEXT: - Type: diff --git a/lld/test/wasm/init-fini.ll b/lld/test/wasm/init-fini.ll index ef2f41f..7471ebb 100644 --- a/lld/test/wasm/init-fini.ll +++ b/lld/test/wasm/init-fini.ll @@ -78,7 +78,7 @@ entry: ; CHECK-NEXT: Body: 10041005100A100F1012100F10141004100C100F10161002100E0B ; CHECK: - Index: 22 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 02404186808080004100418088808000108080808000450D00000B0B +; CHECK-NEXT: Body: 02404186808080004100418080848000108080808000450D00000B0B ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name ; CHECK-NEXT: FunctionNames: diff --git a/lld/test/wasm/large-debug-section.test b/lld/test/wasm/large-debug-section.test new file mode 100644 index 0000000..5483132 --- /dev/null +++ b/lld/test/wasm/large-debug-section.test @@ -0,0 +1,29 @@ +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/debug1.s -o %t/debug1.o +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/debug2.s -o %t/debug2.o +# --no-gc-sections to prevent the linker from optimizing the chunk away, otherwise it produces a tiny output +# RUN: wasm-ld --no-entry --no-gc-sections %t/debug1.o %t/debug2.o -o %t/combined.wasm +# RUN: llvm-readobj --sections %t/combined.wasm | FileCheck %s + +# Check that the linker doesn't crash with large debug sections that together exceed 2GB. +# CHECK: Type: CUSTOM (0x0) +# Total size: 2214592520 + 134217728 = 2348810248 +# CHECK-NEXT: Size: 2348810248 +# CHECK: Name: .debug_info + +# A 2GB + some extra bytes debug section to make sure we go over 2G +#--- debug1.s +.section .debug_info,"",@ + .int32 0xAAAAAAAA + .int32 0xBBBBBBBB + .zero 2214592504 + .int32 0xCCCCCCCC + .int32 0xDDDDDDDD + +#--- debug2.s +.section .debug_info,"",@ + .int32 0x11111111 + .int32 0x22222222 + .zero 134217712 + .int32 0x44444444 + .int32 0x55555555 diff --git a/lld/test/wasm/large-memory.test b/lld/test/wasm/large-memory.test index 5b737e4..a2888c6 100644 --- a/lld/test/wasm/large-memory.test +++ b/lld/test/wasm/large-memory.test @@ -12,7 +12,7 @@ RUN: obj2yaml %t2.wasm | FileCheck %s --check-prefixes=CHECK,CHECK-4G CHECK: - Type: MEMORY CHECK-NEXT: Memories: CHECK-NEXT: - Flags: [ HAS_MAX ] -CHECK-NEXT: Minimum: 0x2 +CHECK-NEXT: Minimum: 0x1 CHECK-2G-NEXT: Maximum: 0x8000 CHECK-4G-NEXT: Maximum: 0x10000 diff --git a/lld/test/wasm/large-section.test b/lld/test/wasm/large-section.test new file mode 100644 index 0000000..ad3148a2 --- /dev/null +++ b/lld/test/wasm/large-section.test @@ -0,0 +1,35 @@ +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/chunk1.s -o %t/chunk1.o +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/chunk2.s -o %t/chunk2.o +# --no-gc-sections to prevent the linker from optimizing the chunk away, otherwise it produces a tiny output +# RUN: wasm-ld --no-entry --no-gc-sections %t/chunk1.o %t/chunk2.o -o %t/combined.wasm +# RUN: llvm-readobj --sections %t/combined.wasm | FileCheck %s + +# Check that the linker doesn't crash with large data sections that together exceed 2GB. +# CHECK: Type: DATA (0xB) +# CHECK-NEXT: Size: 2348810260 + +# A 2GB + some extra bytes of data to make sure we go over 2G +#--- chunk1.s +.section .data.chunk1,"",@ +.globl chunk1_start +.type chunk1_start,@object +chunk1_start: + .int32 0xAAAAAAAA + .int32 0xBBBBBBBB + .zero 2214592504 + .int32 0xCCCCCCCC + .int32 0xDDDDDDDD +.size chunk1_start, 2214592512 + +#--- chunk2.s +.section .data.chunk2,"",@ +.globl chunk2_start +.type chunk2_start,@object +chunk2_start: + .int32 0x11111111 + .int32 0x22222222 + .zero 134217712 + .int32 0x44444444 + .int32 0x55555555 +.size chunk2_start, 134217728 diff --git a/lld/test/wasm/local-symbols.ll b/lld/test/wasm/local-symbols.ll index 8faee64..6c639a8 100644 --- a/lld/test/wasm/local-symbols.ll +++ b/lld/test/wasm/local-symbols.ll @@ -45,13 +45,13 @@ entry: ; CHECK-NEXT: Mutable: true ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66576 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: - Type: EXPORT ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: memory @@ -67,17 +67,17 @@ entry: ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 4100280284888080000B +; CHECK-NEXT: Body: 4100280284808480000B ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 1080808080001A0B ; CHECK-NEXT: - Type: DATA ; CHECK-NEXT: Segments: -; CHECK-NEXT: - SectionOffset: 7 +; CHECK-NEXT: - SectionOffset: 8 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: Content: '0100000003000000' ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name diff --git a/lld/test/wasm/locals-duplicate.test b/lld/test/wasm/locals-duplicate.test index 5c3135a..88819b2 100644 --- a/lld/test/wasm/locals-duplicate.test +++ b/lld/test/wasm/locals-duplicate.test @@ -26,7 +26,7 @@ ; CHECK-NEXT: Maximum: 0x7 ; CHECK-NEXT: - Type: MEMORY ; CHECK-NEXT: Memories: -; CHECK-NEXT: - Minimum: 0x2 +; CHECK-NEXT: - Minimum: 0x2 ; CHECK-NEXT: - Type: GLOBAL ; CHECK-NEXT: Globals: ; CHECK-NEXT: - Index: 0 @@ -34,19 +34,19 @@ ; CHECK-NEXT: Mutable: true ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66592 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1028 +; CHECK-NEXT: Value: 65540 ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1036 +; CHECK-NEXT: Value: 65548 ; CHECK-NEXT: - Type: EXPORT ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: memory @@ -119,13 +119,13 @@ ; CHECK-NEXT: Body: 41020B ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 4180888080000B +; CHECK-NEXT: Body: 4180808480000B ; CHECK-NEXT: - Index: 4 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 4184888080000B +; CHECK-NEXT: Body: 4184808480000B ; CHECK-NEXT: - Index: 5 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 4188888080000B +; CHECK-NEXT: Body: 4188808480000B ; CHECK-NEXT: - Index: 6 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 4181808080000B @@ -146,13 +146,13 @@ ; CHECK-NEXT: Body: 41020B ; CHECK-NEXT: - Index: 12 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 418C888080000B +; CHECK-NEXT: Body: 418C808480000B ; CHECK-NEXT: - Index: 13 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 4190888080000B +; CHECK-NEXT: Body: 4190808480000B ; CHECK-NEXT: - Index: 14 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 4194888080000B +; CHECK-NEXT: Body: 4194808480000B ; CHECK-NEXT: - Index: 15 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 4184808080000B @@ -164,11 +164,11 @@ ; CHECK-NEXT: Body: 4186808080000B ; CHECK-NEXT: - Type: DATA ; CHECK-NEXT: Segments: -; CHECK-NEXT: - SectionOffset: 7 +; CHECK-NEXT: - SectionOffset: 8 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: Content: '010000000100000001000000010000000100000001000000' ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name diff --git a/lld/test/wasm/lto/Inputs/foo.ll b/lld/test/wasm/lto/Inputs/funcs.ll index f3b54cc..695b552 100644 --- a/lld/test/wasm/lto/Inputs/foo.ll +++ b/lld/test/wasm/lto/Inputs/funcs.ll @@ -1,7 +1,17 @@ target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" target triple = "wasm32-unknown-unknown" -define void @foo() local_unnamed_addr { +define void @foo() { +entry: + ret void +} + +define void @baz() { +entry: + ret void +} + +define void @quux() { entry: ret void } diff --git a/lld/test/wasm/lto/Inputs/stub.so b/lld/test/wasm/lto/Inputs/stub.so index e76c890..c471b81 100644 --- a/lld/test/wasm/lto/Inputs/stub.so +++ b/lld/test/wasm/lto/Inputs/stub.so @@ -1,3 +1,4 @@ #STUB bar: foo memcpy: foo +baz: quux diff --git a/lld/test/wasm/lto/cpu-string.ll b/lld/test/wasm/lto/cpu-string.ll new file mode 100644 index 0000000..7b5a88f --- /dev/null +++ b/lld/test/wasm/lto/cpu-string.ll @@ -0,0 +1,27 @@ +; RUN: llvm-as %s -o %t.o + +; RUN: wasm-ld %t.o -o %t.wasm +; RUN: obj2yaml %t.wasm | FileCheck %s + +; CHECK: bulk-memory +; CHECK-NOT: multimemory + +; RUN: wasm-ld -mllvm -mcpu=mvp %t.o -o %t.mvp.wasm +; RUN: obj2yaml %t.mvp.wasm | FileCheck --check-prefix=CHECK-MVP %s + +; CHECK-MVP-NOT: bulk-memory +; CHECK-MVP-NOT: multimemory + +; RUN: wasm-ld -mllvm -mcpu=bleeding-edge %t.o -o %t.mvp.wasm +; RUN: obj2yaml %t.mvp.wasm | FileCheck --check-prefix=CHECK-BLEEDING-EDGE %s + +; CHECK-BLEEDING-EDGE: bulk-memory +; CHECK-BLEEDING-EDGE: multimemory + +target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" +target triple = "wasm32-unknown-unknown" + +define void @_start() #0 { +entry: + ret void +} diff --git a/lld/test/wasm/lto/relocation-model.ll b/lld/test/wasm/lto/relocation-model.ll index 8fe198d..a042615 100644 --- a/lld/test/wasm/lto/relocation-model.ll +++ b/lld/test/wasm/lto/relocation-model.ll @@ -8,6 +8,11 @@ ; RUN: wasm-ld %t.o -o %t_static.wasm -save-temps -r -mllvm -relocation-model=static ; RUN: llvm-readobj -r %t_static.wasm.lto.o | FileCheck %s --check-prefix=STATIC +;; Linking with --unresolved-symbols=import-dynamic should also generate PIC +;; code for external references. +; RUN: wasm-ld %t.o -o %t_import.wasm -save-temps --experimental-pic --unresolved-symbols=import-dynamic +; RUN: llvm-readobj -r %t_import.wasm.lto.o | FileCheck %s --check-prefix=PIC + ; PIC: R_WASM_GLOBAL_INDEX_LEB foo ; STATIC: R_WASM_MEMORY_ADDR_LEB foo diff --git a/lld/test/wasm/lto/stub-library-libcall.s b/lld/test/wasm/lto/stub-library-libcall.s index 40e1593..af1e5ea 100644 --- a/lld/test/wasm/lto/stub-library-libcall.s +++ b/lld/test/wasm/lto/stub-library-libcall.s @@ -1,15 +1,15 @@ # RUN: split-file %s %t # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t_main.o %t/main.s -# RUN: llvm-as %S/Inputs/foo.ll -o %t_foo.o +# RUN: llvm-as %S/Inputs/funcs.ll -o %t_funcs.o # RUN: llvm-as %S/Inputs/libcall.ll -o %t_libcall.o -# RUN: wasm-ld -mllvm -mattr=-bulk-memory,-bulk-memory-opt %t_main.o %t_libcall.o %t_foo.o %p/Inputs/stub.so -o %t.wasm +# RUN: wasm-ld -mllvm -mattr=-bulk-memory,-bulk-memory-opt %t_main.o %t_libcall.o %t_funcs.o %p/Inputs/stub.so -o %t.wasm # RUN: obj2yaml %t.wasm | FileCheck %s # The function `func_with_libcall` will generate an undefined reference to # `memcpy` at LTO time. `memcpy` itself also declared in stub.so and depends # on `foo` -# If %t_foo.o is not included in the link we get an undefined symbol reported +# If %t_funcs.o is not included in the link we get an undefined symbol reported # to the dependency of memcpy on the foo export: # RUN: not wasm-ld -mllvm -mattr=-bulk-memory,-bulk-memory-opt %t_main.o %t_libcall.o %p/Inputs/stub.so -o %t.wasm 2>&1 | FileCheck --check-prefix=MISSING %s diff --git a/lld/test/wasm/lto/stub-library.s b/lld/test/wasm/lto/stub-library.s index 36d6b7b..f4d1d11 100644 --- a/lld/test/wasm/lto/stub-library.s +++ b/lld/test/wasm/lto/stub-library.s @@ -1,19 +1,23 @@ ## The function `bar` is declared in stub.so and depends on `foo` which is ## defined in an LTO object. We also test the case where the LTO object is ## with an archive file. +## The function `baz` is declared in stub.so and depends on `quux`, and both +## `baz` and `quux` are defined in an LTO object. When `baz` and `quux` are +## DCE'd and become undefined in the LTO process, wasm-ld should not try to +## export the (nonexistent) `quux`. ## This verifies that stub library dependencies (which are required exports) can ## be defined in LTO objects, even when they are within archive files. # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s # RUN: mkdir -p %t -# RUN: llvm-as %S/Inputs/foo.ll -o %t/foo.o -# RUN: wasm-ld %t.o %t/foo.o %p/Inputs/stub.so -o %t.wasm +# RUN: llvm-as %S/Inputs/funcs.ll -o %t/funcs.o +# RUN: wasm-ld %t.o %t/funcs.o %p/Inputs/stub.so -o %t.wasm # RUN: obj2yaml %t.wasm | FileCheck %s -## Run the same test but with foo.o inside of an archive file. -# RUN: rm -f %t/libfoo.a -# RUN: llvm-ar rcs %t/libfoo.a %t/foo.o -# RUN: wasm-ld %t.o %t/libfoo.a %p/Inputs/stub.so -o %t2.wasm +## Run the same test but with funcs.o inside of an archive file. +# RUN: rm -f %t/libfuncs.a +# RUN: llvm-ar rcs %t/libfuncs.a %t/funcs.o +# RUN: wasm-ld %t.o %t/libfuncs.a %p/Inputs/stub.so -o %t2.wasm # RUN: obj2yaml %t2.wasm | FileCheck %s .functype bar () -> () @@ -40,3 +44,5 @@ _start: # CHECK-NEXT: - Name: foo # CHECK-NEXT: Kind: FUNCTION # CHECK-NEXT: Index: 2 + +# CHECK-NOT: - Name: quux diff --git a/lld/test/wasm/lto/tls.ll b/lld/test/wasm/lto/tls.ll index b61edfb..9c1642e 100644 --- a/lld/test/wasm/lto/tls.ll +++ b/lld/test/wasm/lto/tls.ll @@ -30,13 +30,13 @@ attributes #0 = { noinline nounwind optnone "target-features"="+atomics,+bulk-me ; CHECK-NEXT: Mutable: true ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66576 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK: GlobalNames: ; CHECK-NEXT: - Index: 0 diff --git a/lld/test/wasm/lto/used.ll b/lld/test/wasm/lto/used.ll index a185103..dd36259 100644 --- a/lld/test/wasm/lto/used.ll +++ b/lld/test/wasm/lto/used.ll @@ -26,11 +26,11 @@ return: ; CHECK: - Type: DATA ; CHECK-NEXT: Segments: -; CHECK-NEXT: - SectionOffset: 7 +; CHECK-NEXT: - SectionOffset: 8 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: Content: '01000000' ; CHECK: - Type: CUSTOM diff --git a/lld/test/wasm/map-file.s b/lld/test/wasm/map-file.s index 2757f50..380ab57 100644 --- a/lld/test/wasm/map-file.s +++ b/lld/test/wasm/map-file.s @@ -59,15 +59,15 @@ somezeroes: # CHECK-NEXT: - 66 b write_global # CHECK-NEXT: - 71 f {{.*}}{{/|\\}}map-file.s.tmp1.o:(_start) # CHECK-NEXT: - 71 f _start -# CHECK-NEXT: - 82 11 DATA -# CHECK-NEXT: 400 83 8 .data -# CHECK-NEXT: 400 89 8 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.data.somedata) -# CHECK-NEXT: 400 89 8 somedata -# CHECK-NEXT: 408 82 4 .bss -# CHECK-NEXT: 408 0 4 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.bss.somezeroes) -# CHECK-NEXT: 408 0 4 somezeroes -# CHECK-NEXT: - 93 12 CUSTOM(.debug_info) -# CHECK-NEXT: - a5 61 CUSTOM(name) +# CHECK-NEXT: - 82 12 DATA +# CHECK-NEXT: 10000 83 8 .data +# CHECK-NEXT: 10000 8a 8 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.data.somedata) +# CHECK-NEXT: 10000 8a 8 somedata +# CHECK-NEXT: 10008 82 4 .bss +# CHECK-NEXT: 10008 0 4 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.bss.somezeroes) +# CHECK-NEXT: 10008 0 4 somezeroes +# CHECK-NEXT: - 94 12 CUSTOM(.debug_info) +# CHECK-NEXT: - a6 61 CUSTOM(name) # RUN: not wasm-ld %t1.o -o /dev/null -Map=/ 2>&1 \ # RUN: | FileCheck -check-prefix=FAIL %s diff --git a/lld/test/wasm/memory-naming.test b/lld/test/wasm/memory-naming.test index 766d9cd5..66143c3 100644 --- a/lld/test/wasm/memory-naming.test +++ b/lld/test/wasm/memory-naming.test @@ -57,7 +57,7 @@ # CHECK-IMPORT-NEXT: Field: bar # CHECK-IMPORT-NEXT: Kind: MEMORY # CHECK-IMPORT-NEXT: Memory: -# CHECK-IMPORT-NEXT: Minimum: 0x2 +# CHECK-IMPORT-NEXT: Minimum: 0x1 # CHECK-IMPORT: - Type: EXPORT # CHECK-IMPORT-NEXT: Exports: # CHECK-IMPORT-NEXT: - Name: _start @@ -77,7 +77,7 @@ # CHECK-IMPORT-DEFAULT-NEXT: Field: foo # CHECK-IMPORT-DEFAULT-NEXT: Kind: MEMORY # CHECK-IMPORT-DEFAULT-NEXT: Memory: -# CHECK-IMPORT-DEFAULT-NEXT: Minimum: 0x2 +# CHECK-IMPORT-DEFAULT-NEXT: Minimum: 0x1 # CHECK-IMPORT-DEFAULT-NEXT: - Type: # RUN:wasm-ld --import-memory=foo,bar --export-memory=qux -o %t.both.wasm %t.start.o @@ -91,7 +91,7 @@ # CHECK-BOTH-NEXT: Field: bar # CHECK-BOTH-NEXT: Kind: MEMORY # CHECK-BOTH-NEXT: Memory: -# CHECK-BOTH-NEXT: Minimum: 0x2 +# CHECK-BOTH-NEXT: Minimum: 0x1 # CHECK-BOTH: - Type: EXPORT # CHECK-BOTH-NEXT: Exports: # CHECK-BOTH-NEXT: - Name: qux diff --git a/lld/test/wasm/merge-string.s b/lld/test/wasm/merge-string.s index a4b89abf..229f393 100644 --- a/lld/test/wasm/merge-string.s +++ b/lld/test/wasm/merge-string.s @@ -41,21 +41,21 @@ negative_addend: // COMMON-NEXT: Mutable: true // COMMON-NEXT: InitExpr: // COMMON-NEXT: Opcode: I32_CONST -// COMMON-NEXT: Value: 66576 +// COMMON-NEXT: Value: 65536 // COMMON-NEXT: - Index: 1 // COMMON-NEXT: Type: I32 // COMMON-NEXT: Mutable: false // COMMON-NEXT: InitExpr: // COMMON-NEXT: Opcode: I32_CONST -// MERGE-NEXT: Value: 1024 -// NOMERGE-NEXT: Value: 1028 +// MERGE-NEXT: Value: 65536 +// NOMERGE-NEXT: Value: 65540 // COMMON-NEXT: - Index: 2 // COMMON-NEXT: Type: I32 // COMMON-NEXT: Mutable: false // COMMON-NEXT: InitExpr: // COMMON-NEXT: Opcode: I32_CONST -// MERGE-NEXT: Value: 1025 -// NOMERGE-NEXT: Value: 1029 +// MERGE-NEXT: Value: 65537 +// NOMERGE-NEXT: Value: 65541 // COMMON-NEXT: - Type: EXPORT // COMMON-NEXT: Exports: // COMMON-NEXT: - Name: memory @@ -71,11 +71,11 @@ negative_addend: // // COMMON: - Type: DATA // COMMON-NEXT: Segments: -// COMMON-NEXT: - SectionOffset: 7 +// COMMON-NEXT: - SectionOffset: 8 // COMMON-NEXT: InitFlags: 0 // COMMON-NEXT: Offset: // COMMON-NEXT: Opcode: I32_CONST -// COMMON-NEXT: Value: 1024 +// COMMON-NEXT: Value: 65536 // MERGE-NEXT: Content: '61626300' // NOMERGE-NEXT: Content: '6162630061626300626300' diff --git a/lld/test/wasm/merge-undefined-symbols.s b/lld/test/wasm/merge-undefined-symbols.s new file mode 100644 index 0000000..62856d6 --- /dev/null +++ b/lld/test/wasm/merge-undefined-symbols.s @@ -0,0 +1,41 @@ +# Verify that the `no_strip` attribute on undefined symbols is preserved +# as long as one of the undefined references is `no_strip`. +# The indirect function table is created by the linker in the case that +# the __indirect_function_table symbol is live (i.e. marked as no_strip). +# This test verifies that the undefined symbol is NO_STRIP, even if the first +# undefined reference is not NO_STRIP. +# +# RUN: split-file %s %t +# RUN: llvm-mc -mattr=+reference-types -filetype=obj -triple=wasm32-unknown-unknown -o %t/main.o %t/main.s +# RUN: llvm-mc -mattr=+reference-types -filetype=obj -triple=wasm32-unknown-unknown -o %t/other.o %t/other.s +# +# RUN: wasm-ld %t/main.o %t/other.o -o %t.wasm +# RUN: obj2yaml %t.wasm | FileCheck %s +# +# RUN: wasm-ld %t/other.o %t/main.o -o %t2.wasm +# RUN: obj2yaml %t2.wasm | FileCheck %s + +#--- main.s +.globl __indirect_function_table +.tabletype __indirect_function_table, funcref +.no_dead_strip __indirect_function_table + +.globl _start +_start: + .functype _start () -> () + end_function + +#--- other.s +# This file contains a reference to __indirect_function_table that is not +# marked as `.no_dead_strip`. +.globl __indirect_function_table +.tabletype __indirect_function_table, funcref + +# CHECK: - Type: TABLE +# CHECK-NEXT: Tables: +# CHECK-NEXT: - Index: 0 +# CHECK-NEXT: ElemType: FUNCREF +# CHECK-NEXT: Limits: +# CHECK-NEXT: Flags: [ HAS_MAX ] +# CHECK-NEXT: Minimum: 0x1 +# CHECK-NEXT: Maximum: 0x1 diff --git a/lld/test/wasm/multi-table.s b/lld/test/wasm/multi-table.s index afe8dda..31cba9f 100644 --- a/lld/test/wasm/multi-table.s +++ b/lld/test/wasm/multi-table.s @@ -87,7 +87,7 @@ call_indirect_explicit_tables: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66576 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Type: EXPORT # CHECK-NEXT: Exports: # CHECK-NEXT: - Name: memory @@ -127,14 +127,14 @@ call_indirect_explicit_tables: # CHECK-NEXT: Body: 42010B # CHECK-NEXT: - Index: 3 # CHECK-NEXT: Locals: [] -# CHECK-NEXT: Body: 41002802808880800011818080800083808080001A41002802848880800011828080800083808080001A0B +# CHECK-NEXT: Body: 41002802808084800011818080800083808080001A41002802848084800011828080800083808080001A0B # CHECK-NEXT: - Type: DATA # CHECK-NEXT: Segments: -# CHECK-NEXT: - SectionOffset: 7 +# CHECK-NEXT: - SectionOffset: 8 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: Content: '0100000002000000' # CHECK-NEXT: - Type: CUSTOM # CHECK-NEXT: Name: name diff --git a/lld/test/wasm/mutable-global-exports.s b/lld/test/wasm/mutable-global-exports.s index 1c10e92..3cf1ae7 100644 --- a/lld/test/wasm/mutable-global-exports.s +++ b/lld/test/wasm/mutable-global-exports.s @@ -81,40 +81,49 @@ _start: # CHECK-ALL-NEXT: Index: 1 # CHECK-ALL-NEXT: - Name: foo_global # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 1 +# CHECK-ALL-NEXT: Index: 4 # CHECK-ALL-NEXT: - Name: bar_global # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 2 +# CHECK-ALL-NEXT: Index: 5 # CHECK-ALL-NEXT: - Name: __dso_handle # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 3 +# CHECK-ALL-NEXT: Index: 6 # CHECK-ALL-NEXT: - Name: __data_end # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 4 +# CHECK-ALL-NEXT: Index: 7 +# CHECK-ALL-NEXT: - Name: __rodata_start +# CHECK-ALL-NEXT: Kind: GLOBAL +# CHECK-ALL-NEXT: Index: 8 +# CHECK-ALL-NEXT: - Name: __rodata_end +# CHECK-ALL-NEXT: Kind: GLOBAL +# CHECK-ALL-NEXT: Index: 9 # CHECK-ALL-NEXT: - Name: __stack_low # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 5 +# CHECK-ALL-NEXT: Index: 10 # CHECK-ALL-NEXT: - Name: __stack_high # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 6 +# CHECK-ALL-NEXT: Index: 11 # CHECK-ALL-NEXT: - Name: __global_base # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 7 +# CHECK-ALL-NEXT: Index: 12 # CHECK-ALL-NEXT: - Name: __heap_base # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 8 +# CHECK-ALL-NEXT: Index: 13 # CHECK-ALL-NEXT: - Name: __heap_end # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 9 +# CHECK-ALL-NEXT: Index: 14 # CHECK-ALL-NEXT: - Name: __memory_base # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 10 +# CHECK-ALL-NEXT: Index: 1 # CHECK-ALL-NEXT: - Name: __table_base # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 11 +# CHECK-ALL-NEXT: Index: 2 # CHECK-ALL-NEXT: - Name: __wasm_first_page_end # CHECK-ALL-NEXT: Kind: GLOBAL -# CHECK-ALL-NEXT: Index: 12 +# CHECK-ALL-NEXT: Index: 15 +# CHECK-ALL-NEXT: - Name: __tls_base +# CHECK-ALL-NEXT: Kind: GLOBAL +# CHECK-ALL-NEXT: Index: 3 # CHECK-ALL-NEXT: - Type: CODE # CHECK-ALL: Name: target_features diff --git a/lld/test/wasm/no-strip-segment.s b/lld/test/wasm/no-strip-segment.s index e70acae..2b79ed6 100644 --- a/lld/test/wasm/no-strip-segment.s +++ b/lld/test/wasm/no-strip-segment.s @@ -47,16 +47,16 @@ grab_liba: # "greetings" section # CHECK: - Type: DATA # CHECK: Segments: -# CHECK: - SectionOffset: 7 +# CHECK: - SectionOffset: 8 # CHECK: InitFlags: 0 # CHECK: Offset: # CHECK: Opcode: I32_CONST -# CHECK: Value: 1024 +# CHECK: Value: 65536 # CHECK: Content: 68656C6C6F00776F726C6400 # "weahters" section. -# CHECK: - SectionOffset: 25 +# CHECK: - SectionOffset: 27 # CHECK: InitFlags: 0 # CHECK: Offset: # CHECK: Opcode: I32_CONST -# CHECK: Value: 1036 +# CHECK: Value: 65548 # CHECK: Content: 636C6F75647900 diff --git a/lld/test/wasm/no-tls.s b/lld/test/wasm/no-tls.s index c0786c8..c082c1e 100644 --- a/lld/test/wasm/no-tls.s +++ b/lld/test/wasm/no-tls.s @@ -28,7 +28,7 @@ _start: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66560 +# CHECK-NEXT: Value: 65536 # __tls_base # CHECK-NEXT: - Index: 1 diff --git a/lld/test/wasm/page-size.s b/lld/test/wasm/page-size.s index a2bf694..17850b5 100644 --- a/lld/test/wasm/page-size.s +++ b/lld/test/wasm/page-size.s @@ -19,7 +19,7 @@ foo: # CHECK-CUSTOM: - Type: MEMORY # CHECK-CUSTOM-NEXT: Memories: # CHECK-CUSTOM-NEXT: - Flags: [ HAS_PAGE_SIZE ] -# CHECK-CUSTOM-NEXT: Minimum: 0x10410 +# CHECK-CUSTOM-NEXT: Minimum: 0x10004 # CHECK-CUSTOM-NEXT: PageSize: 0x1 # RUN: llvm-objdump --disassemble-symbols=_start %t.custom.wasm | FileCheck %s --check-prefix=CHECK-CUSTOM-DIS @@ -51,7 +51,7 @@ foo: # CHECK-CUSTOM-IMPORT-NEXT: Kind: MEMORY # CHECK-CUSTOM-IMPORT-NEXT: Memory: # CHECK-CUSTOM-IMPORT-NEXT: Flags: [ HAS_PAGE_SIZE ] -# CHECK-CUSTOM-IMPORT-NEXT: Minimum: 0x10410 +# CHECK-CUSTOM-IMPORT-NEXT: Minimum: 0x10004 # CHECK-CUSTOM-IMPORT-NEXT: PageSize: 0x1 # RUN: llvm-objdump --disassemble-symbols=_start %t.custom-import.wasm | FileCheck %s --check-prefix=CHECK-CUSTOM-IMPORT-DIS diff --git a/lld/test/wasm/pic-static-unused.s b/lld/test/wasm/pic-static-unused.s new file mode 100644 index 0000000..eb356d4 --- /dev/null +++ b/lld/test/wasm/pic-static-unused.s @@ -0,0 +1,21 @@ +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o +# RUN: wasm-ld -o %t.wasm %t.o +# RUN: obj2yaml %t.wasm | FileCheck %s + +.globaltype __memory_base, i32, immutable +.globaltype __table_base, i32, immutable + +.globl _start +_start: + .functype _start () -> () + end_function + +.section .debug_info,"",@ + .int32 __memory_base + .int32 __table_base + +## Check that relocations against unused __memory_base and __table_base +## work in non-pic mode. + +# CHECK: Name: .debug_info +# CHECK-NEXT: Payload: FFFFFFFFFFFFFFFF diff --git a/lld/test/wasm/pic-static.ll b/lld/test/wasm/pic-static.ll deleted file mode 100644 index 794b721..0000000 --- a/lld/test/wasm/pic-static.ll +++ /dev/null @@ -1,121 +0,0 @@ -; Test that PIC code can be linked into static binaries. -; In this case the GOT entries will end up as internalized wasm globals with -; fixed values. -; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/ret32.s -o %t.ret32.o -; RUN: llc -relocation-model=pic -filetype=obj %s -o %t.o -; RUN: wasm-ld --allow-undefined --export-all -o %t.wasm %t.o %t.ret32.o -; RUN: obj2yaml %t.wasm | FileCheck %s - -target triple = "wasm32-unknown-emscripten" - -declare i32 @ret32(float) -declare i32 @missing_function(float) -@global_float = global float 1.0 -@hidden_float = hidden global float 2.0 -@missing_float = extern_weak global float - -@ret32_ptr = global ptr @ret32, align 4 - -define ptr @getaddr_external() { - ret ptr @ret32; -} - -define ptr @getaddr_missing_function() { - ret ptr @missing_function; -} - -define ptr @getaddr_hidden() { - ret ptr @hidden_func; -} - -define ptr @getaddr_missing_float() { - ret ptr @missing_float -} - -define hidden i32 @hidden_func() { - ret i32 1 -} - -define void @_start() { -entry: - %f = load float, ptr @hidden_float, align 4 - %addr = load ptr, ptr @ret32_ptr, align 4 - %arg = load float, ptr @global_float, align 4 - call i32 %addr(float %arg) - - %addr2 = call ptr @getaddr_external() - %arg2 = load float, ptr @hidden_float, align 4 - call i32 %addr2(float %arg2) - - %addr3 = call ptr @getaddr_hidden() - call i32 %addr3() - - ret void -} - -; CHECK: - Type: GLOBAL -; CHECK-NEXT: Globals: - -; __stack_pointer -; CHECK-NEXT: - Index: 0 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: true -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66576 - -; GOT.func.ret32 -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1 - -; GOT.func.missing_function -; CHECK-NEXT: - Index: 2 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 2 - -; __table_base -; CHECK-NEXT: - Index: 3 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1 - -; GOT.mem.missing_float -; CHECK-NEXT: - Index: 4 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 0 - -; GOT.mem.global_float -; CHECK-NEXT: - Index: 5 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 - -; GOT.mem.ret32_ptr -; CHECK-NEXT: - Index: 6 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1032 - -; __memory_base -; CHECK-NEXT: - Index: 7 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 0 diff --git a/lld/test/wasm/pic-static.s b/lld/test/wasm/pic-static.s new file mode 100644 index 0000000..c6be02d --- /dev/null +++ b/lld/test/wasm/pic-static.s @@ -0,0 +1,188 @@ +# Test that PIC code can be linked into static binaries. +# In this case the GOT entries will end up as internalized wasm globals with +# fixed values. +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/ret32.s -o %t.ret32.o +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o +# RUN: wasm-ld --allow-undefined --export-all -o %t.wasm %t.o %t.ret32.o +# RUN: obj2yaml %t.wasm | FileCheck %s + +.globaltype __memory_base, i32, immutable +.globaltype __table_base, i32, immutable +.weak missing_float + +.functype ret32 (f32) -> (i32) +.functype missing_function (f32) -> (i32) + +.globl getaddr_external +getaddr_external: +.functype getaddr_external () -> (i32) + global.get ret32@GOT + end_function + +.globl getaddr_missing_function +getaddr_missing_function: + .functype getaddr_missing_function () -> (i32) + global.get missing_function@GOT + end_function + +.globl getaddr_hidden +getaddr_hidden: + .functype getaddr_hidden () -> (i32) + global.get __table_base + i32.const hidden_func@TBREL + i32.add + end_function + +.globl getaddr_missing_float +getaddr_missing_float: + .functype getaddr_missing_float () -> (i32) + global.get missing_float@GOT + end_function + +.hidden hidden_func +.globl hidden_func +hidden_func: + .functype hidden_func () -> (i32) + i32.const 1 + end_function + +.globl _start +_start: + .functype _start () -> () + .local i32, i32 + global.get global_float@GOT + f32.load 0 + global.get ret32_ptr@GOT + i32.load 0 + call_indirect (f32) -> (i32) + drop + global.get __memory_base + local.set 0 + call getaddr_external + local.set 1 + local.get 0 + i32.const hidden_float@MBREL + i32.add + f32.load 0 + local.get 1 + call_indirect (f32) -> (i32) + drop + call getaddr_hidden + call_indirect () -> (i32) + drop + end_function + +.section .data.global_float,"",@ +.globl global_float +global_float: + .int32 0x3f800000 + .size global_float, 4 + +.hidden hidden_float +.section .data.hidden_float,"",@ +.globl hidden_float +hidden_float: + .int32 0x40000000 + .size hidden_float, 4 + +.section .data.ret32_ptr,"",@ +.globl ret32_ptr +ret32_ptr: + .int32 ret32 + .size ret32_ptr, 4 + +# CHECK: - Type: GLOBAL +# CHECK-NEXT: Globals: + +# __stack_pointer +# CHECK-NEXT: - Index: 0 +# CHECK-NEXT: Type: I32 +# CHECK-NEXT: Mutable: true +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 65536 + +# __memory_base +# CHECK-NEXT: - Index: 1 +# CHECK-NEXT: Type: I32 +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 0 + +# __table_base +# CHECK-NEXT: - Index: 2 +# CHECK-NEXT: Type: I32 +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 1 + +# __tls_base +# CHECK-NEXT: - Index: 3 +# CHECK-NEXT: Type: I32 +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 0 + +# GOT.func.internal.ret32 +# CHECK-NEXT: - Index: 4 +# CHECK-NEXT: Type: I32 +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 1 + +# GOT.func.missing_function +# CHECK-NEXT: - Index: 5 +# CHECK-NEXT: Type: I32 +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 2 + +# GOT.mem.missing_float +# CHECK-NEXT: - Index: 6 +# CHECK-NEXT: Type: I32 +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 0 + +# GOT.mem.global_float +# CHECK-NEXT: - Index: 7 +# CHECK-NEXT: Type: I32 +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 65536 + +# GOT.mem.ret32_ptr +# CHECK-NEXT: - Index: 8 +# CHECK-NEXT: Type: I32 +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 65544 + +# CHECK: GlobalNames: +# CHECK-NEXT: - Index: 0 +# CHECK-NEXT: Name: __stack_pointer +# CHECK-NEXT: - Index: 1 +# CHECK-NEXT: Name: __memory_base +# CHECK-NEXT: - Index: 2 +# CHECK-NEXT: Name: __table_base +# CHECK-NEXT: - Index: 3 +# CHECK-NEXT: Name: __tls_base +# CHECK-NEXT: - Index: 4 +# CHECK-NEXT: Name: GOT.func.internal.ret32 +# CHECK-NEXT: - Index: 5 +# CHECK-NEXT: Name: GOT.func.internal.missing_function +# CHECK-NEXT: - Index: 6 +# CHECK-NEXT: Name: GOT.data.internal.missing_float +# CHECK-NEXT: - Index: 7 +# CHECK-NEXT: Name: GOT.data.internal.global_float +# CHECK-NEXT: - Index: 8 +# CHECK-NEXT: Name: GOT.data.internal.ret32_ptr +# CHECK-NEXT: DataSegmentNames: diff --git a/lld/test/wasm/reloc-relative.s b/lld/test/wasm/reloc-relative.s index fde1d1d..5aab061 100644 --- a/lld/test/wasm/reloc-relative.s +++ b/lld/test/wasm/reloc-relative.s @@ -50,40 +50,40 @@ far: # CHECK: - Type: DATA # CHECK-NEXT: Segments: -# CHECK-NEXT: - SectionOffset: 7 +# CHECK-NEXT: - SectionOffset: 8 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: Content: 68656C6C6F0A00 -# CHECK-NEXT: - SectionOffset: 20 +# CHECK-NEXT: - SectionOffset: 22 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1031 +# CHECK-NEXT: Value: 65543 # CHECK-NEXT: Content: 000000002A000000 -# CHECK-NEXT: - SectionOffset: 34 +# CHECK-NEXT: - SectionOffset: 37 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1039 +# CHECK-NEXT: Value: 65551 # CHECK-NEXT: Content: FCFFFFFFFCFFFFFF -# CHECK-NEXT: - SectionOffset: 48 +# CHECK-NEXT: - SectionOffset: 52 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1047 +# CHECK-NEXT: Value: 65559 # CHECK-NEXT: Content: E9FFFFFFE9FFFFFF -# CHECK-NEXT: - SectionOffset: 62 +# CHECK-NEXT: - SectionOffset: 67 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1055 +# CHECK-NEXT: Value: 65567 # CHECK-NEXT: Content: '0800000008000000' -# CHECK-NEXT: - SectionOffset: 76 +# CHECK-NEXT: - SectionOffset: 82 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1063 +# CHECK-NEXT: Value: 65575 # CHECK-NEXT: Content: '15000000' diff --git a/lld/test/wasm/runtime-relocations-himem.s b/lld/test/wasm/runtime-relocations-himem.s new file mode 100644 index 0000000..a12a93a --- /dev/null +++ b/lld/test/wasm/runtime-relocations-himem.s @@ -0,0 +1,60 @@ +## Verifies runtime relocation code for addresses over 2gb works correctly. +## We have had issues with LEB encoding of address over 2gb in i32.const +## instruction leading to invalid binaries. + +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s +# RUN: wasm-ld --global-base=2147483648 --experimental-pic --unresolved-symbols=import-dynamic -no-gc-sections --shared-memory --no-entry -o %t.wasm %t.o +# XUN: obj2yaml %t.wasm | FileCheck %s +# RUN: llvm-objdump -d --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s -- + +.globl tls_sym +.globl data_sym +.globl _start +.globaltype __tls_base, i32 + +_start: + .functype _start () -> () + global.get __tls_base + i32.const tls_sym@TLSREL + i32.add + drop + i32.const data_sym + drop + end_function + +.section tls_sec,"T",@ +.p2align 2 +tls_sym: + .int32 0 + .int32 extern_sym + .size tls_sym, 8 + +.section data_sec,"",@ +.p2align 2 +data_sym: + .int32 0 + .int32 extern_sym + .size data_sym, 8 + +.section .custom_section.target_features,"",@ + .int8 2 + .int8 43 + .int8 7 + .ascii "atomics" + .int8 43 + .int8 11 + .ascii "bulk-memory" + +# CHECK: <__wasm_apply_data_relocs>: +# CHECK-EMPTY: +# CHECK-NEXT: i32.const -2147483636 +# CHECK-NEXT: global.get 0 +# CHECK-NEXT: i32.store 0 +# CHECK-NEXT: end + +# CHECK: <__wasm_apply_tls_relocs>: +# CHECK-EMPTY: +# CHECK-NEXT: i32.const -2147483644 +# CHECK-NEXT: global.get 0 +# CHECK-NEXT: i32.store 0 +# CHECK-NEXT: end diff --git a/lld/test/wasm/section-too-large.test b/lld/test/wasm/section-too-large.test new file mode 100644 index 0000000..a4e6007 --- /dev/null +++ b/lld/test/wasm/section-too-large.test @@ -0,0 +1,21 @@ +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/chunk1.s -o %t/chunk1.o +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/chunk2.s -o %t/chunk2.o +# --no-gc-sections to prevent the linker from optimizing the chunk away, otherwise it produces a tiny output +# RUN: not wasm-ld --no-entry --no-gc-sections %t/chunk1.o %t/chunk2.o -o %t/combined.wasm 2>&1 | FileCheck %s + +# Check that the linker fails gracefully when a section exceeds 4GB. +# CHECK: error: section '.debug_info' too large to encode: + +# Two chunks that together exceed 4GB +#--- chunk1.s +.section .debug_info,"",@ + .int32 0xAAAAAAAA + .zero 2147483640 + .int32 0xBBBBBBBB + +#--- chunk2.s +.section .debug_info,"",@ + .int32 0x11111111 + .zero 2147483640 + .int32 0x22222222 diff --git a/lld/test/wasm/shared-memory-no-atomics.yaml b/lld/test/wasm/shared-memory-no-atomics.yaml index 942c690..62f4ac9 100644 --- a/lld/test/wasm/shared-memory-no-atomics.yaml +++ b/lld/test/wasm/shared-memory-no-atomics.yaml @@ -55,7 +55,7 @@ Sections: # NO-SHARED: - Type: MEMORY # NO-SHARED-NEXT: Memories: -# NO-SHARED-NEXT: - Minimum: 0x2 +# NO-SHARED-NEXT: - Minimum: 0x1 # NO-SHARED-NOT: Maximum: # SHARED: --shared-memory is disallowed by {{.*}}shared-memory-no-atomics.yaml.tmp1.o because it was not compiled with 'atomics' or 'bulk-memory' features. diff --git a/lld/test/wasm/shared-memory.yaml b/lld/test/wasm/shared-memory.yaml index 4cdbb95..b3490c8 100644 --- a/lld/test/wasm/shared-memory.yaml +++ b/lld/test/wasm/shared-memory.yaml @@ -1,16 +1,16 @@ # RUN: yaml2obj %s -o %t1.o -# RUN: wasm-ld --no-entry --shared-memory --features=atomics,bulk-memory %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED +# RUN: wasm-ld --no-entry --no-gc-sections --shared-memory --features=atomics,bulk-memory %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED -# RUN: not wasm-ld --no-entry --shared-memory --max-memory=100000 %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-UNALIGNED +# RUN: not wasm-ld --no-entry --no-gc-sections --shared-memory --max-memory=100000 %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-UNALIGNED -# RUN: not wasm-ld --no-entry --shared-memory --max-memory=131072 --features=bulk-memory %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-NO-ATOMICS +# RUN: not wasm-ld --no-entry --no-gc-sections --shared-memory --max-memory=131072 --features=bulk-memory %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-NO-ATOMICS -# RUN: not wasm-ld --no-entry --shared-memory --max-memory=131072 --features=atomics %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-NO-BULK-MEM +# RUN: not wasm-ld --no-entry --no-gc-sections --shared-memory --max-memory=131072 --features=atomics %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-NO-BULK-MEM # RUN: wasm-ld --relocatable --features=atomics %t1.o -o - | obj2yaml | FileCheck %s --check-prefix ATOMICS-RELOCATABLE -# RUN: wasm-ld --no-entry --shared-memory --max-memory=131072 --features=atomics,bulk-memory %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED +# XUN: wasm-ld --no-entry --no-gc-sections --shared-memory --max-memory=131072 --features=atomics,bulk-memory %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED --- !WASM FileHeader: @@ -22,7 +22,7 @@ Sections: Field: __linear_memory Kind: MEMORY Memory: - Minimum: 0x00000001 + Minimum: 0x00000009 - Module: env Field: __indirect_function_table Kind: TABLE diff --git a/lld/test/wasm/stack-first.test b/lld/test/wasm/stack-first.test index 72e1a00..91f06a4 100644 --- a/lld/test/wasm/stack-first.test +++ b/lld/test/wasm/stack-first.test @@ -5,9 +5,20 @@ ; Also test that __heap_base is still aligned with the --stack-first option. RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/stack-first.s -o %t.o -RUN: wasm-ld -z stack-size=512 --stack-first --export=__data_end --export=__heap_base --export=someByte -o %t.wasm %t.o + +; Check that the default is `--stack-first` +RUN: wasm-ld -z stack-size=512 --export=__data_end --export=__heap_base --export=someByte -o %t.wasm %t.o +RUN: obj2yaml %t.wasm | FileCheck %s + +; Check `--no-stack-first` +RUN: wasm-ld -z stack-size=512 --no-stack-first --export=__data_end --export=__heap_base --export=someByte -o %t.wasm %t.o +RUN: obj2yaml %t.wasm | FileCheck %s --check-prefix=NOT-FIRST + +; Check `--stack-first` +RUN: wasm-ld -z stack-size=512 --no-stack-first --stack-first --export=__data_end --export=__heap_base --export=someByte -o %t.wasm %t.o RUN: obj2yaml %t.wasm | FileCheck %s + CHECK: - Type: GLOBAL CHECK-NEXT: Globals: CHECK-NEXT: - Index: 0 @@ -51,3 +62,19 @@ CHECK-NEXT: Index: 2 CHECK-NEXT: - Name: __heap_base CHECK-NEXT: Kind: GLOBAL CHECK-NEXT: Index: 3 + +NOT-FIRST: - Type: GLOBAL +NOT-FIRST-NEXT: Globals: +NOT-FIRST-NEXT: - Index: 0 +NOT-FIRST-NEXT: Type: I32 +NOT-FIRST-NEXT: Mutable: true +NOT-FIRST-NEXT: InitExpr: +NOT-FIRST-NEXT: Opcode: I32_CONST +NOT-FIRST-NEXT: Value: 1552 +NOT-FIRST-NEXT: - Index: 1 +NOT-FIRST-NEXT: Type: I32 +NOT-FIRST-NEXT: Mutable: false +NOT-FIRST-NEXT: InitExpr: +NOT-FIRST-NEXT: Opcode: I32_CONST +NOT-FIRST-NEXT: Value: 1024 + diff --git a/lld/test/wasm/startstop.ll b/lld/test/wasm/startstop.ll index e7a5c80..c22956f 100644 --- a/lld/test/wasm/startstop.ll +++ b/lld/test/wasm/startstop.ll @@ -27,19 +27,19 @@ entry: ; CHECK: - Type: DATA ; CHECK-NEXT: Segments: -; CHECK-NEXT: - SectionOffset: 7 +; CHECK-NEXT: - SectionOffset: 8 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: Content: 03000000040000002A0000002B000000 -; ASM: 0000006e <get_start>: +; ASM: 00000070 <get_start>: ; ASM-EMPTY: -; ASM-NEXT: 70: i32.const 1024 -; ASM-NEXT: 76: end +; ASM-NEXT: 72: i32.const 65536 +; ASM-NEXT: 78: end -; ASM: 00000077 <get_end>: +; ASM: 00000079 <get_end>: ; ASM-EMPTY: -; ASM-NEXT: 79: i32.const 1040 -; ASM-NEXT: 7f: end +; ASM-NEXT: 7b: i32.const 65552 +; ASM-NEXT: 81: end diff --git a/lld/test/wasm/table-base.s b/lld/test/wasm/table-base.s index 56fff41..92156c4 100644 --- a/lld/test/wasm/table-base.s +++ b/lld/test/wasm/table-base.s @@ -29,7 +29,7 @@ _start: # CHECK-DEFAULT-NEXT: Mutable: true # CHECK-DEFAULT-NEXT: InitExpr: # CHECK-DEFAULT-NEXT: Opcode: I32_CONST -# CHECK-DEFAULT-NEXT: Value: 66560 +# CHECK-DEFAULT-NEXT: Value: 65536 # CHECK-DEFAULT-NEXT: - Index: 1 # CHECK-DEFAULT-NEXT: Type: I32 # CHECK-DEFAULT-NEXT: Mutable: false @@ -58,7 +58,7 @@ _start: # CHECK-100-NEXT: Mutable: true # CHECK-100-NEXT: InitExpr: # CHECK-100-NEXT: Opcode: I32_CONST -# CHECK-100-NEXT: Value: 66560 +# CHECK-100-NEXT: Value: 65536 # CHECK-100-NEXT: - Index: 1 # CHECK-100-NEXT: Type: I32 # CHECK-100-NEXT: Mutable: false diff --git a/lld/test/wasm/tls-align.s b/lld/test/wasm/tls-align.s index 4fd296e..3b51165 100644 --- a/lld/test/wasm/tls-align.s +++ b/lld/test/wasm/tls-align.s @@ -65,7 +65,7 @@ tls2: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66592 +# CHECK-NEXT: Value: 65536 # __tls_base # CHECK-NEXT: - Index: 1 diff --git a/lld/test/wasm/tls-non-shared-memory-basic.s b/lld/test/wasm/tls-non-shared-memory-basic.s index 8ef0173..66ccf8f 100644 --- a/lld/test/wasm/tls-non-shared-memory-basic.s +++ b/lld/test/wasm/tls-non-shared-memory-basic.s @@ -27,11 +27,11 @@ tls1: # CHECK: - Type: DATA # CHECK-NEXT: Segments: -# CHECK-NEXT: - SectionOffset: 7 +# CHECK-NEXT: - SectionOffset: 8 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: Content: 2B000000 # CHECK-NEXT: - Type: CUSTOM # CHECK-NOT: - Type: IMPORT diff --git a/lld/test/wasm/tls-non-shared-memory.s b/lld/test/wasm/tls-non-shared-memory.s index 04fbb62..0d73acb 100644 --- a/lld/test/wasm/tls-non-shared-memory.s +++ b/lld/test/wasm/tls-non-shared-memory.s @@ -63,38 +63,38 @@ tls1: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66576 +# CHECK-NEXT: Value: 65536 # __tls_base # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Type: I32 # CHECK-NEXT: Mutable: false # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # GOT.data.internal.tls1 # CHECK-NEXT: - Index: 2 # CHECK-NEXT: Type: I32 # CHECK-NEXT: Mutable: false # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Type: EXPORT # CHECK: - Type: DATA # .data # CHECK-NEXT: Segments: -# CHECK-NEXT: - SectionOffset: 7 +# CHECK-NEXT: - SectionOffset: 8 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: Content: 2B000000 # .tdata -# CHECK-NEXT: - SectionOffset: 17 +# CHECK-NEXT: - SectionOffset: 19 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1028 +# CHECK-NEXT: Value: 65540 # CHECK-NEXT: Content: 2A000000 # CHECK-NEXT: - Type: CUSTOM diff --git a/lld/test/wasm/tls.s b/lld/test/wasm/tls.s index b1f47f6..21f25f5 100644 --- a/lld/test/wasm/tls.s +++ b/lld/test/wasm/tls.s @@ -98,7 +98,7 @@ tls3: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66592 +# CHECK-NEXT: Value: 65536 # __tls_base # CHECK-NEXT: - Index: 1 diff --git a/lld/test/wasm/undefined-weak-call.s b/lld/test/wasm/undefined-weak-call.s index 7490104..47775c8 100644 --- a/lld/test/wasm/undefined-weak-call.s +++ b/lld/test/wasm/undefined-weak-call.s @@ -61,7 +61,7 @@ callWeakFuncs: # CHECK-NEXT: Maximum: 0x1 # CHECK-NEXT: - Type: MEMORY # CHECK-NEXT: Memories: -# CHECK-NEXT: - Minimum: 0x2 +# CHECK-NEXT: - Minimum: 0x1 # CHECK-NEXT: - Type: GLOBAL # CHECK-NEXT: Globals: # CHECK-NEXT: - Index: 0 @@ -69,7 +69,7 @@ callWeakFuncs: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66560 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Type: EXPORT # CHECK-NEXT: Exports: # CHECK-NEXT: - Name: memory diff --git a/lld/test/wasm/weak-alias-overide.ll b/lld/test/wasm/weak-alias-overide.ll index ca6f4bf..30bf7cf 100644 --- a/lld/test/wasm/weak-alias-overide.ll +++ b/lld/test/wasm/weak-alias-overide.ll @@ -44,7 +44,7 @@ entry: ; CHECK-NEXT: Maximum: 0x3 ; CHECK-NEXT: - Type: MEMORY ; CHECK-NEXT: Memories: -; CHECK-NEXT: - Minimum: 0x2 +; CHECK-NEXT: - Minimum: 0x1 ; CHECK-NEXT: - Type: GLOBAL ; CHECK-NEXT: Globals: ; CHECK-NEXT: - Index: 0 @@ -52,7 +52,7 @@ entry: ; CHECK-NEXT: Mutable: true ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66560 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: - Type: EXPORT ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: memory diff --git a/lld/test/wasm/weak-alias.ll b/lld/test/wasm/weak-alias.ll index 1768b8f..86e42a7 100644 --- a/lld/test/wasm/weak-alias.ll +++ b/lld/test/wasm/weak-alias.ll @@ -41,7 +41,7 @@ entry: ; CHECK-NEXT: Maximum: 0x2 ; CHECK-NEXT: - Type: MEMORY ; CHECK-NEXT: Memories: -; CHECK-NEXT: - Minimum: 0x2 +; CHECK-NEXT: - Minimum: 0x1 ; CHECK-NEXT: - Type: GLOBAL ; CHECK-NEXT: Globals: ; CHECK-NEXT: - Index: 0 @@ -49,7 +49,7 @@ entry: ; CHECK-NEXT: Mutable: true ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66560 +; CHECK-NEXT: Value: 65536 ; CHECK-NEXT: - Type: EXPORT ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: memory diff --git a/lld/test/wasm/weak-symbols.s b/lld/test/wasm/weak-symbols.s index 165ec17..ed85851 100644 --- a/lld/test/wasm/weak-symbols.s +++ b/lld/test/wasm/weak-symbols.s @@ -48,13 +48,13 @@ _start: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66576 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Type: I32 # CHECK-NEXT: Mutable: false # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Type: EXPORT # CHECK-NEXT: Exports: # CHECK-NEXT: - Name: memory @@ -97,11 +97,11 @@ _start: # CHECK-NEXT: Body: 4181808080000B # CHECK-NEXT: - Type: DATA # CHECK-NEXT: Segments: -# CHECK-NEXT: - SectionOffset: 7 +# CHECK-NEXT: - SectionOffset: 8 # CHECK-NEXT: InitFlags: 0 # CHECK-NEXT: Offset: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 1024 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: Content: '01000000' # CHECK-NEXT: - Type: CUSTOM # CHECK-NEXT: Name: name diff --git a/lld/test/wasm/weak-undefined-pic.s b/lld/test/wasm/weak-undefined-pic.s index 5937380..1a3a171 100644 --- a/lld/test/wasm/weak-undefined-pic.s +++ b/lld/test/wasm/weak-undefined-pic.s @@ -45,7 +45,7 @@ _start: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66560 +# CHECK-NEXT: Value: 65536 # Global 'undefined_weak:foo' representing the GOT entry for foo # Unlike other internal GOT entries that need to be mutable this one # is immutable and not updated by `__wasm_apply_global_relocs` diff --git a/lld/test/wasm/weak-undefined.s b/lld/test/wasm/weak-undefined.s index e1f551d..558cac5 100644 --- a/lld/test/wasm/weak-undefined.s +++ b/lld/test/wasm/weak-undefined.s @@ -67,7 +67,7 @@ _start: # CHECK-NEXT: Maximum: 0x1 # CHECK-NEXT: - Type: MEMORY # CHECK-NEXT: Memories: -# CHECK-NEXT: - Minimum: 0x2 +# CHECK-NEXT: - Minimum: 0x1 # CHECK-NEXT: - Type: GLOBAL # CHECK-NEXT: Globals: # CHECK-NEXT: - Index: 0 @@ -75,7 +75,7 @@ _start: # CHECK-NEXT: Mutable: true # CHECK-NEXT: InitExpr: # CHECK-NEXT: Opcode: I32_CONST -# CHECK-NEXT: Value: 66560 +# CHECK-NEXT: Value: 65536 # CHECK-NEXT: - Type: EXPORT # CHECK-NEXT: Exports: # CHECK-NEXT: - Name: memory diff --git a/lld/test/wasm/wrap_import.s b/lld/test/wasm/wrap_import.s new file mode 100644 index 0000000..ce3b6f5 --- /dev/null +++ b/lld/test/wasm/wrap_import.s @@ -0,0 +1,32 @@ +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o +# RUN: wasm-ld -wrap nosuchsym -wrap foo -allow-undefined -o %t.wasm %t.o +# RUN: obj2yaml %t.wasm | FileCheck %s + +.globl foo +.globl _start + +foo: + .functype foo () -> () + end_function + +_start: + .functype _start () -> () + call foo + end_function + +# CHECK: - Type: IMPORT +# CHECK-NEXT: Imports: +# CHECK-NEXT: - Module: env +# CHECK-NEXT: Field: __wrap_foo +# CHECK-NEXT: Kind: FUNCTION +# CHECK-NEXT SigIndex: 0 + +# CHECK: - Type: CODE +# CHECK-NEXT: Functions: +# CHECK-NEXT: Index: 1 + +# CHECK: FunctionNames: +# CHECK-NEXT: - Index: 0 +# CHECK-NEXT: Name: __wrap_foo +# CHECK-NEXT: - Index: 1 +# CHECK-NEXT: Name: _start |
