[binutils-gdb] VAX: In PIC code, use GOT for function pointers

Jan-Benedict Glaw jbglaw@sourceware.org
Mon Nov 16 18:48:17 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2722595890ab408ccce30ec93ae92db49c3b88a9

commit 2722595890ab408ccce30ec93ae92db49c3b88a9
Author: Jan-Benedict Glaw <jbglaw@getslash.de>
Date:   Sun Nov 15 18:36:27 2026 +0100

    VAX: In PIC code, use GOT for function pointers
    
    Use GOT references for function pointers in PIC code. Actual fix by
    Rin Okuyama, initially reported for NetBSD in https://gnats.netbsd.org/59326 .
    
    PR gas/32941
    
    gas/
            * config/tc-vax.c (md_estimate_size_before_relax): Use GOT instead of PLT.
            * testsuite/gas/vax/elf-got-func.s,
            * testsuite/gas/vax/elf-got-func.d: New test.
            * testsuite/gas/vax/vax.exp: Run it.

Diff:
---
 gas/config/tc-vax.c                  | 11 ++++++++---
 gas/testsuite/gas/vax/elf-got-func.d | 14 ++++++++++++++
 gas/testsuite/gas/vax/elf-got-func.s | 16 ++++++++++++++++
 gas/testsuite/gas/vax/vax.exp        |  1 +
 4 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/gas/config/tc-vax.c b/gas/config/tc-vax.c
index 3d21796851a..614cc8db475 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 00000000000..f3d66d5823f
--- /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 00000000000..c3fc3358843
--- /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 0c27be0b03e..b521066fa87 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
 }


More information about the Binutils-cvs mailing list