[compiler-rt] [RISCV][compiler-rt] Asm funcs should be hidden (PR #226633)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 20:48:29 PDT 2026


https://github.com/lenary created https://github.com/llvm/llvm-project/pull/226633

The C builtins are built with `-fvisibility=hidden` when that option is available, as the builtins are expected to be statically linked and not called across shared library boundaries.

Before this change, the assembly-written builtin implementations were declared with STV_DEFAULT visibility, meaning they would be visible across shared library boundaries. This change moves them to being declared as STV_HIDDEN to fix this issue.

In particular, the save/restore routines are not normal functions and cannot be called via a PLT, so this fixes a bug there, and also applies it to the assembly multiply routine.

>From ac6842ae5f88df07db3acc56e26273b0485b9472 Mon Sep 17 00:00:00 2001
From: Sam Elliott <aelliott at qti.qualcomm.com>
Date: Fri, 25 Sep 2026 16:08:40 -0700
Subject: [PATCH] [RISCV][compiler-rt] Asm funcs should be hidden

The C builtins are built with `-fvisibility=hidden` when that option is
available, as the builtins are expected to be statically linked and not
called across shared library boundaries.

Before this change, the assembly-written builtin implementations were
declared with STV_DEFAULT visibility, meaning they would be visible
across shared library boundaries. This change moves them to being
declared as STV_HIDDEN to fix this issue.

In particular, the save/restore routines are not normal functions and
cannot be called via a PLT, so this fixes a bug there, and also applies
it to the assembly multiply routine.
---
 .../lib/builtins/riscv/int_mul_impl.inc       |  1 +
 compiler-rt/lib/builtins/riscv/restore.S      | 32 +++++++++++++++++++
 compiler-rt/lib/builtins/riscv/save.S         | 32 +++++++++++++++++++
 3 files changed, 65 insertions(+)

diff --git a/compiler-rt/lib/builtins/riscv/int_mul_impl.inc b/compiler-rt/lib/builtins/riscv/int_mul_impl.inc
index 53699b356f6a89..43f046ec42fee8 100644
--- a/compiler-rt/lib/builtins/riscv/int_mul_impl.inc
+++ b/compiler-rt/lib/builtins/riscv/int_mul_impl.inc
@@ -18,6 +18,7 @@
 	.align 2
 
 	.globl __mulxi3
+	.hidden __mulxi3
 	.type  __mulxi3, @function
 __mulxi3:
 	mv     a2, a0
diff --git a/compiler-rt/lib/builtins/riscv/restore.S b/compiler-rt/lib/builtins/riscv/restore.S
index 7816f74ed497ea..e709abf4c57bdf 100644
--- a/compiler-rt/lib/builtins/riscv/restore.S
+++ b/compiler-rt/lib/builtins/riscv/restore.S
@@ -28,6 +28,7 @@
 #ifndef __riscv_abi_rve
 
   .globl  __riscv_restore_12
+  .hidden __riscv_restore_12
   .type   __riscv_restore_12, at function
 __riscv_restore_12:
   lw      s11, 12(sp)
@@ -35,12 +36,16 @@ __riscv_restore_12:
   // fallthrough into __riscv_restore_11/10/9/8
 
   .globl  __riscv_restore_11
+  .hidden __riscv_restore_11
   .type   __riscv_restore_11, at function
   .globl  __riscv_restore_10
+  .hidden __riscv_restore_10
   .type   __riscv_restore_10, at function
   .globl  __riscv_restore_9
+  .hidden __riscv_restore_9
   .type   __riscv_restore_9, at function
   .globl  __riscv_restore_8
+  .hidden __riscv_restore_8
   .type   __riscv_restore_8, at function
 __riscv_restore_11:
 __riscv_restore_10:
@@ -54,12 +59,16 @@ __riscv_restore_8:
   // fallthrough into __riscv_restore_7/6/5/4
 
   .globl  __riscv_restore_7
+  .hidden __riscv_restore_7
   .type   __riscv_restore_7, at function
   .globl  __riscv_restore_6
+  .hidden __riscv_restore_6
   .type   __riscv_restore_6, at function
   .globl  __riscv_restore_5
+  .hidden __riscv_restore_5
   .type   __riscv_restore_5, at function
   .globl  __riscv_restore_4
+  .hidden __riscv_restore_4
   .type   __riscv_restore_4, at function
 __riscv_restore_7:
 __riscv_restore_6:
@@ -73,12 +82,16 @@ __riscv_restore_4:
   // fallthrough into __riscv_restore_3/2/1/0
 
   .globl  __riscv_restore_3
+  .hidden __riscv_restore_3
   .type   __riscv_restore_3, at function
   .globl  __riscv_restore_2
+  .hidden __riscv_restore_2
   .type   __riscv_restore_2, at function
   .globl  __riscv_restore_1
+  .hidden __riscv_restore_1
   .type   __riscv_restore_1, at function
   .globl  __riscv_restore_0
+  .hidden __riscv_restore_0
   .type   __riscv_restore_0, at function
 __riscv_restore_3:
 __riscv_restore_2:
@@ -94,6 +107,7 @@ __riscv_restore_0:
 #else
 
   .globl  __riscv_restore_2
+  .hidden __riscv_restore_2
   .type   __riscv_restore_2, at function
 __riscv_restore_2:
   lw      s1, 0(sp)
@@ -101,6 +115,7 @@ __riscv_restore_2:
   // fallthrough into __riscv_restore_1/0
 
   .globl  __riscv_restore_1
+  .hidden __riscv_restore_1
   .type   __riscv_restore_1, at function
 __riscv_restore_1:
   lw      s0, 0(sp)
@@ -108,6 +123,7 @@ __riscv_restore_1:
   // fallthrough into __riscv_restore_0
 
   .globl  __riscv_restore_0
+  .hidden __riscv_restore_0
   .type   __riscv_restore_0, at function
 __riscv_restore_0:
   lw      ra, 0(sp)
@@ -121,6 +137,7 @@ __riscv_restore_0:
 #ifndef __riscv_abi_rve
 
   .globl  __riscv_restore_12
+  .hidden __riscv_restore_12
   .type   __riscv_restore_12, at function
 __riscv_restore_12:
   ld      s11, 8(sp)
@@ -128,8 +145,10 @@ __riscv_restore_12:
   // fallthrough into __riscv_restore_11/10
 
   .globl  __riscv_restore_11
+  .hidden __riscv_restore_11
   .type   __riscv_restore_11, at function
   .globl  __riscv_restore_10
+  .hidden __riscv_restore_10
   .type   __riscv_restore_10, at function
 __riscv_restore_11:
 __riscv_restore_10:
@@ -139,8 +158,10 @@ __riscv_restore_10:
   // fallthrough into __riscv_restore_9/8
 
   .globl  __riscv_restore_9
+  .hidden __riscv_restore_9
   .type   __riscv_restore_9, at function
   .globl  __riscv_restore_8
+  .hidden __riscv_restore_8
   .type   __riscv_restore_8, at function
 __riscv_restore_9:
 __riscv_restore_8:
@@ -150,8 +171,10 @@ __riscv_restore_8:
   // fallthrough into __riscv_restore_7/6
 
   .globl  __riscv_restore_7
+  .hidden __riscv_restore_7
   .type   __riscv_restore_7, at function
   .globl  __riscv_restore_6
+  .hidden __riscv_restore_6
   .type   __riscv_restore_6, at function
 __riscv_restore_7:
 __riscv_restore_6:
@@ -161,8 +184,10 @@ __riscv_restore_6:
   // fallthrough into __riscv_restore_5/4
 
   .globl  __riscv_restore_5
+  .hidden __riscv_restore_5
   .type   __riscv_restore_5, at function
   .globl  __riscv_restore_4
+  .hidden __riscv_restore_4
   .type   __riscv_restore_4, at function
 __riscv_restore_5:
 __riscv_restore_4:
@@ -172,8 +197,10 @@ __riscv_restore_4:
   // fallthrough into __riscv_restore_3/2
 
   .globl  __riscv_restore_3
+  .hidden __riscv_restore_3
   .type   __riscv_restore_3, at function
   .globl  __riscv_restore_2
+  .hidden __riscv_restore_2
   .type   __riscv_restore_2, at function
 __riscv_restore_3:
 __riscv_restore_2:
@@ -183,8 +210,10 @@ __riscv_restore_2:
   // fallthrough into __riscv_restore_1/0
 
   .globl  __riscv_restore_1
+  .hidden __riscv_restore_1
   .type   __riscv_restore_1, at function
   .globl  __riscv_restore_0
+  .hidden __riscv_restore_0
   .type   __riscv_restore_0, at function
 __riscv_restore_1:
 __riscv_restore_0:
@@ -196,6 +225,7 @@ __riscv_restore_0:
 #else
 
   .globl  __riscv_restore_2
+  .hidden __riscv_restore_2
   .type   __riscv_restore_2, at function
 __riscv_restore_2:
   ld      s1, 0(sp)
@@ -203,6 +233,7 @@ __riscv_restore_2:
   // fallthrough into __riscv_restore_1/0
 
   .globl  __riscv_restore_1
+  .hidden __riscv_restore_1
   .type   __riscv_restore_1, at function
 __riscv_restore_1:
   ld      s0, 0(sp)
@@ -210,6 +241,7 @@ __riscv_restore_1:
   // fallthrough into __riscv_restore_0
 
   .globl  __riscv_restore_0
+  .hidden __riscv_restore_0
   .type   __riscv_restore_0, at function
 __riscv_restore_0:
   ld      ra, 0(sp)
diff --git a/compiler-rt/lib/builtins/riscv/save.S b/compiler-rt/lib/builtins/riscv/save.S
index 6b50bce0225248..ab7132eaa7b852 100644
--- a/compiler-rt/lib/builtins/riscv/save.S
+++ b/compiler-rt/lib/builtins/riscv/save.S
@@ -21,6 +21,7 @@
 #ifndef __riscv_abi_rve
 
   .globl  __riscv_save_12
+  .hidden __riscv_save_12
   .type   __riscv_save_12, at function
 __riscv_save_12:
   addi   sp, sp, -64
@@ -29,12 +30,16 @@ __riscv_save_12:
   j      .Lriscv_save_11_8
 
   .globl  __riscv_save_11
+  .hidden __riscv_save_11
   .type   __riscv_save_11, at function
   .globl  __riscv_save_10
+  .hidden __riscv_save_10
   .type   __riscv_save_10, at function
   .globl  __riscv_save_9
+  .hidden __riscv_save_9
   .type   __riscv_save_9, at function
   .globl  __riscv_save_8
+  .hidden __riscv_save_8
   .type   __riscv_save_8, at function
 __riscv_save_11:
 __riscv_save_10:
@@ -50,12 +55,16 @@ __riscv_save_8:
   j      .Lriscv_save_7_4
 
   .globl  __riscv_save_7
+  .hidden __riscv_save_7
   .type   __riscv_save_7, at function
   .globl  __riscv_save_6
+  .hidden __riscv_save_6
   .type   __riscv_save_6, at function
   .globl  __riscv_save_5
+  .hidden __riscv_save_5
   .type   __riscv_save_5, at function
   .globl  __riscv_save_4
+  .hidden __riscv_save_4
   .type   __riscv_save_4, at function
 __riscv_save_7:
 __riscv_save_6:
@@ -76,12 +85,16 @@ __riscv_save_4:
   jr     t0
 
   .globl  __riscv_save_3
+  .hidden __riscv_save_3
   .type   __riscv_save_3, at function
   .globl  __riscv_save_2
+  .hidden __riscv_save_2
   .type   __riscv_save_2, at function
   .globl  __riscv_save_1
+  .hidden __riscv_save_1
   .type   __riscv_save_1, at function
   .globl  __riscv_save_0
+  .hidden __riscv_save_0
   .type   __riscv_save_0, at function
 __riscv_save_3:
 __riscv_save_2:
@@ -97,6 +110,7 @@ __riscv_save_0:
 #else
 
   .globl  __riscv_save_2
+  .hidden __riscv_save_2
   .type   __riscv_save_2, at function
 __riscv_save_2:
   addi    sp, sp, -12
@@ -106,6 +120,7 @@ __riscv_save_2:
   jr      t0
 
   .globl  __riscv_save_1
+  .hidden __riscv_save_1
   .type   __riscv_save_1, at function
 __riscv_save_1:
   addi    sp, sp, -8
@@ -114,6 +129,7 @@ __riscv_save_1:
   jr      t0
 
   .globl  __riscv_save_0
+  .hidden __riscv_save_0
   .type   __riscv_save_0, at function
 __riscv_save_0:
   addi    sp, sp, -4
@@ -127,6 +143,7 @@ __riscv_save_0:
 #ifndef __riscv_abi_rve
 
   .globl  __riscv_save_12
+  .hidden __riscv_save_12
   .type   __riscv_save_12, at function
 __riscv_save_12:
   addi   sp, sp, -112
@@ -135,8 +152,10 @@ __riscv_save_12:
   j      .Lriscv_save_11_10
 
   .globl  __riscv_save_11
+  .hidden __riscv_save_11
   .type   __riscv_save_11, at function
   .globl  __riscv_save_10
+  .hidden __riscv_save_10
   .type   __riscv_save_10, at function
 __riscv_save_11:
 __riscv_save_10:
@@ -148,8 +167,10 @@ __riscv_save_10:
   j      .Lriscv_save_9_8
 
   .globl  __riscv_save_9
+  .hidden __riscv_save_9
   .type   __riscv_save_9, at function
   .globl  __riscv_save_8
+  .hidden __riscv_save_8
   .type   __riscv_save_8, at function
 __riscv_save_9:
 __riscv_save_8:
@@ -161,8 +182,10 @@ __riscv_save_8:
   j      .Lriscv_save_7_6
 
   .globl  __riscv_save_7
+  .hidden __riscv_save_7
   .type   __riscv_save_7, at function
   .globl  __riscv_save_6
+  .hidden __riscv_save_6
   .type   __riscv_save_6, at function
 __riscv_save_7:
 __riscv_save_6:
@@ -174,8 +197,10 @@ __riscv_save_6:
   j      .Lriscv_save_5_4
 
   .globl  __riscv_save_5
+  .hidden __riscv_save_5
   .type   __riscv_save_5, at function
   .globl  __riscv_save_4
+  .hidden __riscv_save_4
   .type   __riscv_save_4, at function
 __riscv_save_5:
 __riscv_save_4:
@@ -187,8 +212,10 @@ __riscv_save_4:
   j      .Lriscv_save_3_2
 
   .globl  __riscv_save_3
+  .hidden __riscv_save_3
   .type   __riscv_save_3, at function
   .globl  __riscv_save_2
+  .hidden __riscv_save_2
   .type   __riscv_save_2, at function
 __riscv_save_3:
 __riscv_save_2:
@@ -203,8 +230,10 @@ __riscv_save_2:
   jr     t0
 
   .globl  __riscv_save_1
+  .hidden __riscv_save_1
   .type   __riscv_save_1, at function
   .globl  __riscv_save_0
+  .hidden __riscv_save_0
   .type   __riscv_save_0, at function
 __riscv_save_1:
 __riscv_save_0:
@@ -216,6 +245,7 @@ __riscv_save_0:
 #else
 
   .globl  __riscv_save_2
+  .hidden __riscv_save_2
   .type   __riscv_save_2, at function
 __riscv_save_2:
   addi    sp, sp, -24
@@ -225,6 +255,7 @@ __riscv_save_2:
   jr      t0
 
   .globl  __riscv_save_1
+  .hidden __riscv_save_1
   .type   __riscv_save_1, at function
 __riscv_save_1:
   addi    sp, sp, -16
@@ -233,6 +264,7 @@ __riscv_save_1:
   jr      t0
 
   .globl  __riscv_save_0
+  .hidden __riscv_save_0
   .type   __riscv_save_0, at function
 __riscv_save_0:
   addi    sp, sp, -8



More information about the llvm-commits mailing list