[lld] [lld][WebAssembly] Convert pic-static test to assembly. NFC (PR #178321)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 27 15:55:10 PST 2026


https://github.com/sbc100 updated https://github.com/llvm/llvm-project/pull/178321

>From f6627e283cf493468576cbb3a4e0d4f341a357b8 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Tue, 27 Jan 2026 15:49:17 -0800
Subject: [PATCH] [lld][WebAssembly] Convert pic-static test to assembly. NFC

---
 lld/test/wasm/pic-static.ll | 121 ---------------------------
 lld/test/wasm/pic-static.s  | 159 ++++++++++++++++++++++++++++++++++++
 2 files changed, 159 insertions(+), 121 deletions(-)
 delete mode 100644 lld/test/wasm/pic-static.ll
 create mode 100644 lld/test/wasm/pic-static.s

diff --git a/lld/test/wasm/pic-static.ll b/lld/test/wasm/pic-static.ll
deleted file mode 100644
index 12ac4c3a5544e..0000000000000
--- 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)
- at global_float = global float 1.0
- at hidden_float = hidden global float 2.0
- at missing_float = extern_weak global float
-
- at 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:           65536
-
-; 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:           65536
-
-; 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:           65544
-
-; __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 0000000000000..d1404280e61ba
--- /dev/null
+++ b/lld/test/wasm/pic-static.s
@@ -0,0 +1,159 @@
+# 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 at GOT
+  end_function
+
+.globl getaddr_missing_function
+getaddr_missing_function:
+  .functype getaddr_missing_function () -> (i32)
+  global.get missing_function at GOT
+  end_function
+
+.globl getaddr_hidden
+getaddr_hidden:
+  .functype getaddr_hidden () -> (i32)
+  global.get  __table_base
+  i32.const hidden_func at TBREL
+  i32.add
+  end_function
+
+.globl getaddr_missing_float
+getaddr_missing_float:
+  .functype getaddr_missing_float () -> (i32)
+  global.get missing_float at 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 at GOT
+  f32.load  0
+  global.get  ret32_ptr at 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 at 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
+
+# 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:           65536
+
+# 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:           65544
+
+# __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



More information about the llvm-commits mailing list