libtool/0006-RISC-V-doesn-t-allow-linking-non-PIC-into-shared-obj.patch
Andrea Bolognani c8edf81e6f Fix riscv64 build
Resolves: RHEL-149798

Thanks: Marcin Juszkiewicz <mjuszkiewicz@redhat.com>
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2026-02-16 00:50:09 +01:00

48 lines
2.0 KiB
Diff

From 710874215f449c23b86eb1ce3ddcd6b8116e55d9 Mon Sep 17 00:00:00 2001
From: Palmer Dabbelt <palmer@rivosinc.com>
Date: Thu, 1 Feb 2024 12:34:14 -0800
Subject: [PATCH] RISC-V doesn't allow linking non-PIC into shared objects
I'm not sure exactly why, but it looks like this has started failing on
the latest Fedora rebuilds (with a bump to GCC-14 prereleases) with
errors along the lines of
/usr/bin/ld: .libs/libhello_la-hello.o: relocation R_RISCV_HI20 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: .libs/libhello_la-foo.o: relocation R_RISCV_HI20 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: unresolvable R_RISCV_CALL_PLT relocation against symbol `puts@@GLIBC_2.27'
/usr/bin/ld: unresolvable R_RISCV_CALL_PLT relocation against symbol `__printf_chk@@GLIBC_2.27'
As far as I can tell this always should have failed on RISC-V, as
non-PIC objects have never worked correctly in shared libraries. We
have added some stricter linker error checking over the last few months
so it's possible this is a newly reported error, but I'd guess that the
resulting binaries have always been invalid.
Regardless of exactly why it's getting noticed now, R_RISCV_HI20 is very
much an absolute relocation (it maps to LUI, which just loads up a
constant address) and thus won't work for shared libraries. Given that
other ports skip this test that seems like the way to go for RISC-V
as well.
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
---
tests/demo.at | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/demo.at b/tests/demo.at
index 28b2d1f0..b82684a1 100644
--- a/tests/demo.at
+++ b/tests/demo.at
@@ -511,7 +511,7 @@ AT_CLEANUP
AT_SETUP([force non-PIC objects])
AT_CHECK([case $host in
-hppa*|x86_64*|s390*|arm*)
+hppa*|x86_64*|s390*|arm*|riscv*)
# These hosts cannot use non-PIC shared libs
exit 77 ;;
*-solaris*|*-sunos*)
--
2.49.0