No subject

Rin Okuyama rin@netbsd.org
Mon May 5 05:43:23 GMT 2025


>From 51fcee395af03b828aa0d5f90f102b0daffb787b Mon Sep 17 00:00:00 2001
From: Rin Okuyama <rokuyama.rk@gmail.com>
Date: Mon, 5 May 2025 14:39:21 +0900
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

Consider the following C source, main.c:

```

void func(void) {
}

int main(void) {
        printf("%s: %p\n", func);
        return 0;
}
```

Before this patch applied, `func` argument for printf(3) points PLT:

```
% /somewhere/vax--netbsdelf-gcc -S -fPIC -O2 main.c
% /usr/local/vax--netbsdelf/bin/as -pic main.s -o main.o
% readelf -r main.o

Relocation section '.rela.text.startup' at offset 0x14c contains 3 entries:
 Offset     Info    Type            Sym.Value  Sym. Name + Addend
0000000d  00000504 R_VAX_PC32        00000000   .rodata.str1.1 + 0
00000007  0000080d R_VAX_PLT32       00000000   func + 0
00000014  00000a0d R_VAX_PLT32       00000000   printf + 0
```

After this patch applied, it points GOT as done for other platforms:

```
% /usr/local/vax--netbsdelf/bin/as -pic main.s -o main.o
% readelf -r main.o

Relocation section '.rela.text.startup' at offset 0x14c contains 3 entries:
 Offset     Info    Type            Sym.Value  Sym. Name + Addend
0000000d  00000504 R_VAX_PC32        00000000   .rodata.str1.1 + 0
00000007  00000807 R_VAX_GOT32       00000000   func + 0
00000014  00000a0d R_VAX_PLT32       00000000   printf + 0
```
---
 gas/config/tc-vax.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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;
-- 
2.46.1



More information about the Binutils mailing list