[PATCH 3/3] LoongArch: Reword message for unresolvable PC-relative relocs
Xi Ruoyao
xry111@xry111.site
Fri Dec 13 05:53:52 GMT 2024
If we hit such a bad reloc, it means the programmer has somehow wrongly
instructed the compiler to generate PC-relative relocs against external
symbols. "Recompiling with -fPIC" (or -fPIE) is just misleading.
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
bfd/elfnn-loongarch.c | 4 ++++
ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d | 2 +-
ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d | 2 +-
ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d | 2 +-
ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d | 2 +-
ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d | 2 +-
ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d | 2 +-
7 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 5d252bcccb9..93368275b46 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -894,6 +894,10 @@ bad_static_reloc (struct bfd_link_info *info,
pic = _("; recompile with -fPIE");
}
+ if (r_type == R_LARCH_PCREL20_S2 || r_type == R_LARCH_PCALA_HI20)
+ pic = _("; recompile with -mno-direct-extern-access and check the "
+ "symbol visibility");
+
(*_bfd_error_handler)
(_("%pB:(%pA+%#lx): relocation %s against `%s` can not be used when making "
"%s%s"),
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d
index 6ecefd1d48a..fac02d036ba 100644
--- a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d
@@ -2,4 +2,4 @@
#source: bad_pcala_hi20_global.s
#target: [check_shared_lib_support]
#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20
-#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -fPIC
+#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -mno-direct-extern-access and check the symbol visibility
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d
index 5dc2f7c4e4b..a5cd359ac63 100644
--- a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d
@@ -1,4 +1,4 @@
#name: PC-relative relocation making executable
#source: bad_pcala_hi20_global_pie.s
#ld: -pie -z undefs --defsym _start=0
-#error: .*: relocation R_LARCH_PCALA_HI20 against `sym` can not be used when making a PIE object; recompile with -fPIE
+#error: .*: relocation R_LARCH_PCALA_HI20 against `sym` can not be used when making a PIE object; recompile with -mno-direct-extern-access and check the symbol visibility
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d
index cefc42cf89f..fa6cff370be 100644
--- a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d
@@ -2,4 +2,4 @@
#source: bad_pcala_hi20_weak.s
#target: [check_shared_lib_support]
#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20
-#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -fPIC
+#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -mno-direct-extern-access and check the symbol visibility
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d
index 5515f257191..62a3d8dae25 100644
--- a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d
@@ -1,4 +1,4 @@
#name: PC-relative relocation making executable
#source: bad_pcala_hi20_weak_pie.s
#ld: -pie --defsym _start=0
-#error: .*: relocation R_LARCH_PCALA_HI20 against `sym` can not be used when making a PIE object; recompile with -fPIE
+#error: .*: relocation R_LARCH_PCALA_HI20 against `sym` can not be used when making a PIE object; recompile with -mno-direct-extern-access and check the symbol visibility
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d
index 8e063dfb0ec..b517f22c20c 100644
--- a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d
@@ -2,4 +2,4 @@
#source: bad_pcrel20_s2_global.s
#target: [check_shared_lib_support]
#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20
-#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -fPIC
+#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -mno-direct-extern-access and check the symbol visibility
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d
index 605df24988a..bf551ef6db2 100644
--- a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d
@@ -2,4 +2,4 @@
#source: bad_pcrel20_s2_weak.s
#target: [check_shared_lib_support]
#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20
-#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -fPIC
+#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -mno-direct-extern-access and check the symbol visibility
--
2.47.1
More information about the Binutils
mailing list