[PATCH] VAX: PIC: Use GOT for pointer for global function
Jan-Benedict Glaw
jbglaw@lug-owl.de
Sun Nov 15 13:18:58 GMT 2026
Hi!
On Mon, 2025-05-05 05:45:46 +0000, Rin Okuyama <rin@netbsd.org> wrote:
> Subject: [PATCH] VAX: PIC: Use GOT for pointer for global function
>
> in same file, instead of PLT
>
> This fixes the problem reported as Bug 32941:
> https://sourceware.org/bugzilla/show_bug.cgi?id=32941
[...]
> diff --git a/gas/config/tc-vax.c b/gas/config/tc-vax.c
> index 0b39d98f44a..529b25b9d57 100644
> --- a/gas/config/tc-vax.c
> +++ b/gas/config/tc-vax.c
> @@ -409,8 +409,7 @@ md_estimate_size_before_relax (fragS *fragP, segT segment)
> else if (((unsigned char *) fragP->fr_opcode)[0] == VAX_CALLS
> || ((unsigned char *) fragP->fr_opcode)[0] == VAX_CALLG
> || ((unsigned char *) fragP->fr_opcode)[0] == VAX_JSB
> - || ((unsigned char *) fragP->fr_opcode)[0] == VAX_JMP
> - || S_IS_FUNCTION (fragP->fr_symbol))
> + || ((unsigned char *) fragP->fr_opcode)[0] == VAX_JMP)
> reloc_type = BFD_RELOC_32_PLT_PCREL;
> else
> reloc_type = BFD_RELOC_32_GOT_PCREL;
I intend to commit the following patch, containing your fix and adding
a testcase for it:
diff --git a/gas/config/tc-vax.c b/gas/config/tc-vax.c
index 3d21796..614cc8d 100644
--- a/gas/config/tc-vax.c
+++ b/gas/config/tc-vax.c
@@ -399,7 +399,13 @@ md_estimate_size_before_relax (fragS *fragP, segT segment)
|| S_IS_EXTERNAL (fragP->fr_symbol)))
{
/* Indirect references cannot go through the GOT or PLT,
- let's hope they'll become local in the final link. */
+ let's hope they'll become local in the final link.
+ Only calls and jumps may go through the PLT. Any other
+ reference wants the address of the symbol and must use the
+ GOT, also for a function: a PLT reference is turned into an
+ indirect one through the function's .got.plt slot, which
+ holds the PLT entry until the lazy binding has happened, so
+ the same function would have different addresses. */
if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragP->fr_symbol))
!= STV_DEFAULT)
|| (p[0] & 0x10))
@@ -407,8 +413,7 @@ md_estimate_size_before_relax (fragS *fragP, segT segment)
else if (((unsigned char *) fragP->fr_opcode)[0] == VAX_CALLS
|| ((unsigned char *) fragP->fr_opcode)[0] == VAX_CALLG
|| ((unsigned char *) fragP->fr_opcode)[0] == VAX_JSB
- || ((unsigned char *) fragP->fr_opcode)[0] == VAX_JMP
- || S_IS_FUNCTION (fragP->fr_symbol))
+ || ((unsigned char *) fragP->fr_opcode)[0] == VAX_JMP)
reloc_type = BFD_RELOC_32_PLT_PCREL;
else
reloc_type = BFD_RELOC_32_GOT_PCREL;
diff --git a/gas/testsuite/gas/vax/elf-got-func.d b/gas/testsuite/gas/vax/elf-got-func.d
new file mode 100644
index 0000000..f3d66d5
--- /dev/null
+++ b/gas/testsuite/gas/vax/elf-got-func.d
@@ -0,0 +1,14 @@
+#as: -k
+#objdump: -r
+#name: VAX ELF PIC address of a function uses the GOT
+
+.*: file format elf32-vax
+
+RELOCATION RECORDS FOR \[\.text\]:
+OFFSET +TYPE +VALUE
+00000004 R_VAX_GOT32 fn
+0000000b R_VAX_GOT32 fn
+00000012 R_VAX_PLT32 fn
+00000019 R_VAX_PLT32 fn
+0000001f R_VAX_PLT32 fn
+00000025 R_VAX_PLT32 fn
diff --git a/gas/testsuite/gas/vax/elf-got-func.s b/gas/testsuite/gas/vax/elf-got-func.s
new file mode 100644
index 0000000..c3fc335
--- /dev/null
+++ b/gas/testsuite/gas/vax/elf-got-func.s
@@ -0,0 +1,16 @@
+# Taking the address of a global function in PIC code must go through
+# the GOT even if the function is defined in this file; only calls and
+# jumps may use the PLT.
+ .text
+ .globl fn
+ .type fn, @function
+fn:
+ .word 0
+ movab fn, %r0
+ pushab fn
+ calls $0, fn
+ callg (%ap), fn
+ jsb fn
+ jmp fn
+ ret
+ .size fn, . - fn
diff --git a/gas/testsuite/gas/vax/vax.exp b/gas/testsuite/gas/vax/vax.exp
index 0c27be0..b521066 100644
--- a/gas/testsuite/gas/vax/vax.exp
+++ b/gas/testsuite/gas/vax/vax.exp
@@ -53,4 +53,5 @@ run_dump_test broken_word
if { [istarget vax-*-*elf*] || [istarget vax-*-linux-*] } then {
run_dump_test elf-rel
+ run_dump_test elf-got-func
}
Sorry for the long delay!
MfG, JBG
--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20261115/5f376b8f/attachment.sig>
More information about the Binutils
mailing list