[PATCH] VAX: PIC: Use GOT for pointer for global function

Jan-Benedict Glaw jbglaw@lug-owl.de
Mon Nov 16 18:52:37 GMT 2026


Hi,

On Sun, 2026-11-15 14:18:58 +0100, Jan-Benedict Glaw <jbglaw@lug-owl.de> wrote:
> 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
>  }
> 
> 

Committed unchanged with this commit message:

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.


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/20261116/66571e27/attachment-0001.sig>


More information about the Binutils mailing list