NetBSD Problem Report #59326

From www@netbsd.org  Sat Apr 19 05:20:18 2025
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 8FC851A9239
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 19 Apr 2025 05:20:18 +0000 (UTC)
Message-Id: <20250419052017.2FF7F1A923D@mollari.NetBSD.org>
Date: Sat, 19 Apr 2025 05:20:17 +0000 (UTC)
From: rokuyama.rk@gmail.com
Reply-To: rokuyama.rk@gmail.com
To: gnats-bugs@NetBSD.org
Subject: pointer to global function in same object file points PLT entry
X-Send-Pr-Version: www-1.0

>Number:         59326
>Category:       port-vax
>Synopsis:       pointer to global function in same object file points PLT entry
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-vax-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 19 05:25:00 +0000 2025
>Last-Modified:  Sat Sep 06 09:35:02 +0000 2025
>Originator:     Rin Okuyama
>Release:        10.99.12 (and netbsd-9 at least)
>Organization:
Internet Initiative Japan Inc.
>Environment:
NetBSD  10.99.12 NetBSD 10.99.12 (GENERIC) #1: Sun Apr 13 19:38:40 JST 2025  rin@sakaizumii.local:/home/rin/src/sys/arch/vax/compile/obj.vax-vax/GENERIC vax
>Description:
Many rump-based ATF cases do not work on vax. For example,
if_bridge:bridge_ipv4 fails as:

```
tc-so:Executing command [ /sbin/brconfig bridge0 add shmif0 ]
tc-se:Fail: incorrect exit status: 1, expected: 0
tc-se:stdout:
tc-se:
tc-se:stderr:
tc-se:brconfig: add shmif0: Invalid argument
tc-se:
```

This EINVAL comes from if_bridge.c:bridge_ioctl_add():

```
	if (ifs->_if_input != ether_input) {
		error = EINVAL;
		goto out;
	}
```

This is strange since _if_input for shmif(4) should be
initialized to ether_input() in if_ethersubr.c::ether_ifattach():

```
	ifp->_if_input = ether_input;
```

Inserting debug printf's for ether_input value, I observed:

```
[   4.7600050] ether_ifattach: ether_input: 0x7f045918
[   8.1500050] bridge_ioctl_add: ether_input: 0x7f0b67f0
```

(Here, I used RUMP_STDOUT environment variable to obtain this log.)

This is not a recent regression; similar ATF failures also happen
at least for netbsd-9.

This inconsistency is because pointers for ether_ifattach point
(1) PLT entry for ether_ifattach(), and (2) GOT entry for
bridge_ioctl_add(), respectively.

This, of course, cannot be worked around even by LD_BIND_NOW.
>How-To-Repeat:
As a minimal reproducer, callee() pointers behave similarly for
callee.c and caller.c below:

callee.c:
```
#include <stdio.h>

void
callee(void)
{
}

static void
print_callee(void)
{

	printf("%s: %p\n", callee);
}
```

caller.c:
```
#include <stdio.h>

void callee(void);

void
caller(void)
{

	callee();
	printf("%s: %p\n", callee);
}
```

Then, I got:

```
% cc -fPIC -c callee.c
% readelf -a callee.o
...
Relocation section '.rela.text' at offset 0x1a0 contains 3 entries:
 Offset     Info    Type            Sym.Value  Sym. Name + Addend
...
0000000f  0000090d R_VAX_PLT32       00000000   callee + 0
...
% readelf -a callee.o
```

and

```
% cc -fPIC -c caller.c
% readelf -a caller.o
...
Relocation section '.rela.text' at offset 0x180 contains 4 entries:
 Offset     Info    Type            Sym.Value  Sym. Name + Addend
...
00000008  0000090d R_VAX_PLT32       00000000   callee + 0
0000000e  00000907 R_VAX_GOT32       00000000   callee + 0
...
```

You can see function pointer local to callee.o as well as function
call for caller.o point PLT entry, whereas function pointer in
callee.o points GOT entry.

For amd64, e.g., function pointer in callee.o points GOT entry,
not PLT, in a similar manner to caller.o.
>Fix:
For upstream, this behavior seems to be introduced by this commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=7b6021f1972

With this patch:
https://gist.github.com/rokuyama/181d7208bd099899a24cb6a70a809616

function pointers always point to GOT entries, even if functions are
local to object files.

With the patch applied, I've confirmed:

(1) full distribution (with MKX11) can be cross-built,
(2) **most** rump-based ATF cases become working fine,
(3) no new regression for full ATF runs, and
(4) perl-5.38.2 can be built natively.

>Audit-Trail:
From: matthew green <mrg@eterna23.net>
To: gnats-bugs@netbsd.org, rin@netbsd.org
Cc: port-vax-maintainer@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: re: port-vax/59326: pointer to global function in same object file points PLT entry
Date: Mon, 21 Apr 2025 08:58:10 +1000

 > With this patch:
 > https://gist.github.com/rokuyama/181d7208bd099899a24cb6a70a809616

 a later comment here says:

 > There's no information for gas(1) to determine that symbol callee is fun=
 ction.

 but that seems incorrect?  the quoted file has:

         .type   caller, @function

 in it, which seems like it should be enough?

 ...unless i'm missing something.


 .mrg.

From: Rin Okuyama <rokuyama.rk@gmail.com>
To: matthew green <mrg@NetBSD.org>, gnats-bugs@netbsd.org
Cc: port-vax-maintainer@netbsd.org, gnats-admin@netbsd.org,
 netbsd-bugs@netbsd.org
Subject: Re: port-vax/59326: pointer to global function in same object file
 points PLT entry
Date: Mon, 21 Apr 2025 10:51:14 +0900

 On 2025/04/21 7:58, matthew green wrote:
 >> With this patch:
 >> https://gist.github.com/rokuyama/181d7208bd099899a24cb6a70a809616
 > 
 > a later comment here says:
 > 
 >> There's no information for gas(1) to determine that symbol callee is function.
 > 
 > but that seems incorrect?  the quoted file has:
 > 
 >          .type   caller, @function
 > 
 > in it, which seems like it should be enough?
 > 
 > ...unless i'm missing something.

 This indicates that calle**r** is function, not calle**e**.

 Apparently, I made a bad choice for function naming!!

 Thanks,
 rin

From: Rin Okuyama <rokuyama.rk@gmail.com>
To: gnats-bugs@NetBSD.org, netbsd-bugs@NetBSD.org
Cc: 
Subject: Re: port-vax/59326 pointer to global function in same object file
 points PLT entry
Date: Mon, 5 May 2025 07:51:29 +0900

 I can reproduce the problem with vanilla binutils-2.44.
 I've registered a bug report to upstream:

 https://sourceware.org/bugzilla/show_bug.cgi?id=32941

 Thanks,
 rin

From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59326 CVS commit: src/external/gpl3/binutils/dist/gas/config
Date: Sat, 6 Sep 2025 06:06:52 +0000

 Module Name:	src
 Committed By:	rin
 Date:		Sat Sep  6 06:06:52 UTC 2025

 Modified Files:
 	src/external/gpl3/binutils/dist/gas/config: tc-vax.c

 Log Message:
 gas: vax: PIC: Use GOT for pointer for global function

 in same file, instead of PLT

 This fixes function-pointer comparison for shared libraries,
 encountered in, e.g., many rump-based ATF cases. See
 PR port-vax/59326 for more details.

 Reported to upstream as:
 https://sourceware.org/bugzilla/show_bug.cgi?id=32941


 To generate a diff of this commit:
 cvs rdiff -u -r1.21 -r1.22 \
     src/external/gpl3/binutils/dist/gas/config/tc-vax.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59326 CVS commit: [netbsd-11] src/external/gpl3/binutils/dist/gas/config
Date: Sat, 6 Sep 2025 09:32:09 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sat Sep  6 09:32:09 UTC 2025

 Modified Files:
 	src/external/gpl3/binutils/dist/gas/config [netbsd-11]: tc-vax.c

 Log Message:
 Pull up following revision(s) (requested by rin in ticket #26):

 	external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.22

 gas: vax: PIC: Use GOT for pointer for global function
 in same file, instead of PLT

 This fixes function-pointer comparison for shared libraries,
 encountered in, e.g., many rump-based ATF cases. See

 PR port-vax/59326 for more details.

 Reported to upstream as:
 https://sourceware.org/bugzilla/show_bug.cgi?id=32941


 To generate a diff of this commit:
 cvs rdiff -u -r1.19 -r1.19.2.1 \
     src/external/gpl3/binutils/dist/gas/config/tc-vax.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59326 CVS commit: [netbsd-10] src/external/gpl3/binutils/dist/gas/config
Date: Sat, 6 Sep 2025 09:33:35 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sat Sep  6 09:33:35 UTC 2025

 Modified Files:
 	src/external/gpl3/binutils/dist/gas/config [netbsd-10]: tc-vax.c

 Log Message:
 Pull up following revision(s) (requested by rin in ticket #1157):

 	external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.22

 gas: vax: PIC: Use GOT for pointer for global function
 in same file, instead of PLT

 This fixes function-pointer comparison for shared libraries,
 encountered in, e.g., many rump-based ATF cases. See

 PR port-vax/59326 for more details.

 Reported to upstream as:
 https://sourceware.org/bugzilla/show_bug.cgi?id=32941


 To generate a diff of this commit:
 cvs rdiff -u -r1.13.6.1 -r1.13.6.2 \
     src/external/gpl3/binutils/dist/gas/config/tc-vax.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.