NetBSD Problem Report #52427

From martin@duskware.de  Tue Jul 25 07:48:07 2017
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 72EA07A16F
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 25 Jul 2017 07:48:07 +0000 (UTC)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: VAX text relocations
X-Send-Pr-Version: 3.95

>Number:         52427
>Category:       toolchain
>Synopsis:       VAX text relocations
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 25 07:50:00 +0000 2017
>Last-Modified:  Tue Aug 01 02:05:01 +0000 2023
>Originator:     Martin Husemann
>Release:        NetBSD 8.99.1
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD dead-to-the-world.duskware.de 8.99.1 NetBSD 8.99.1 (DEAD) #7: Sun Jul 23 12:04:50 CEST 2017 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/vax/compile/DEAD vax
Architecture: vax
Machine: vax
>Description:

After my recent fixes to compiler_rt, perl is buildable on VAX again.
But:

 > perl -e 'print "hello\n";'
/usr/pkg/lib/perl5/5.26.0/vax-netbsd-thread-multi/CORE/libperl.so: text relocations
hello


Looking at the relocations show they are all of the form:

	R_VAX_RELATIVE   *ABS*+0x6967c

and seem to be part of big switch/case things. The first looks like this:

   5ca00:       31 de db        brw 5a5e1 <Perl_yylex+0x2e6f>
   5ca03:       cf 50 00 0a     casel r0,$0x0,$0xa
   5ca07:       27 11 38 45     divp $0x11,$0x38,$0x14[r5],*0xffffd214(r2),*0x46
(r0),*0x46(r0)
   5ca0b:       14 d2 14 d2 
   5ca0f:       b0 46 b0 46 
   5ca13:       95 12           tstb $0x12
   5ca15:       95 12           tstb $0x12
   5ca17:       19 00           blss 5ca19 <Perl_yylex+0x52a7>
   5ca19:       14 d2           bgtr 5c9ed <Perl_yylex+0x527b>
   5ca1b:       38 45 31 06     editpc $0x31[r5],$0x6,$0x0,$0x17
   5ca1f:       00 17 
   5ca21:       9f cf 76 06     pushab 5d09b <Perl_yylex+0x5929>
                        5ca22: R_VAX_RELATIVE   *ABS*+0x676cf
   5ca25:       00              halt
   5ca26:       dd 5a           pushl r10
   5ca28:       fb 01 ff bd     calls $0x1,*1a60ec <_GLOBAL_OFFSET_TABLE_+0xea0>
   5ca2c:       96 14 00 


All others look like a jump table:

   5cdd1:       17 9f 30 6c     jmp *0x66c30
   5cdd5:       06 00 
                        5cdd3: R_VAX_RELATIVE   *ABS*+0x66c30
   5cdd7:       17 9f 7c 96     jmp *0x6967c
   5cddb:       06 00 
                        5cdd9: R_VAX_RELATIVE   *ABS*+0x6967c
   5cddd:       17 9f a8 71     jmp *0x671a8
   5cde1:       06 00 


Is this a binutils or gcc issue? Is it avoidable? If not, should we make
ld.elf_so quiet about it on VAX?

>How-To-Repeat:
Build perl on vax and use it.

>Fix:
n/a

>Audit-Trail:
From: Rin Okuyama <rokuyama.rk@gmail.com>
To: "gnats-bugs@NetBSD.org" <gnats-bugs@NetBSD.org>, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: toolchain/52427 (VAX text relocations)
Date: Tue, 1 Aug 2023 09:50:05 +0900

 -------- Forwarded Message --------
 Subject: [PATCH] 1/2: toolchain/52427: VAX text relocations
 Date: Mon, 31 Jul 2023 14:29:13 +1000
 From: Kalvis Duckmanton <kalvisd@gmail.com>
 To: tech-toolchain@netbsd.org

 Hi all,

 I'd like to submit the following change to the GNU assembler in NetBSD
 10.99.6 for consideration.  This alters the behaviour of
 tc-vax.c:md_create_long_jump() to emit a jump to a offset from the PC
 instead of a jump to an absolute address.

 md_create_long_jump() is used, as far as I can tell, as part of the GNU
 assembler's handling of displacements to branch targets where the
 displacement won't fit in a 16 bit word.

 Using an absolute address works but in a shared library ld.elf_so will
 complain about relocations in the text segment.

 I think that this should address PR toolchain/52427
 (https://mail-index.netbsd.org/netbsd-bugs/2017/07/25/msg052924.html)

 Tested on my machine by compiling Perl for VAX from source and using it.

 many thanks

 kalvis

 ---
   external/gpl3/binutils/dist/gas/config/tc-vax.c | 17 +++++++++--------
   1 file changed, 9 insertions(+), 8 deletions(-)

 diff --git a/external/gpl3/binutils/dist/gas/config/tc-vax.c
 b/external/gpl3/binutils/dist/gas/config/tc-vax.c
 index 88548bf72096..30a12c705fed 100644
 --- a/external/gpl3/binutils/dist/gas/config/tc-vax.c
 +++ b/external/gpl3/binutils/dist/gas/config/tc-vax.c
 @@ -2330,18 +2330,19 @@ md_create_short_jump (char *ptr,

   void
   md_create_long_jump (char *ptr,
 -                    addressT from_addr ATTRIBUTE_UNUSED,
 -                    addressT to_addr,
 -                    fragS *frag,
 -                    symbolS *to_symbol)
 +                     addressT from_addr,
 +                     addressT to_addr,
 +                     fragS *frag ATTRIBUTE_UNUSED,
 +                     symbolS *to_symbol ATTRIBUTE_UNUSED)
   {
     valueT offset;

 -  offset = to_addr - S_GET_VALUE (to_symbol);
 -  *ptr++ = VAX_JMP;            /* Arbitrary jump.  */
 -  *ptr++ = VAX_ABSOLUTE_MODE;
 +  /* account for 1 byte instruction, 1 byte of address specifier and
 +     4 bytes of offset from PC */
 +  offset = to_addr - (from_addr + 1 + 1 + 4);
 +  *ptr++ = VAX_JMP;             /* long jump */
 +  *ptr++ = VAX_PC_RELATIVE_MODE;
     md_number_to_chars (ptr, offset, 4);
 -  fix_new (frag, ptr - frag->fr_literal, 4, to_symbol, (long) 0, 0,
 NO_RELOC);
   }
   ^L
   #ifdef OBJ_VMS
 -- 
 2.20.1


From: Rin Okuyama <rokuyama.rk@gmail.com>
To: "gnats-bugs@NetBSD.org" <gnats-bugs@NetBSD.org>, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: toolchain/52427 (VAX text relocations)
Date: Tue, 1 Aug 2023 09:50:47 +0900

 -------- Forwarded Message --------
 Subject: [PATCH] 2/2: toolchain/52427: VAX text relocations
 Date: Mon, 31 Jul 2023 14:31:00 +1000
 From: Kalvis Duckmanton <kalvisd@gmail.com>
 To: tech-toolchain@netbsd.org

 Hi all,

 This is the second part of the change to address toolchain/52427
 (https://mail-index.netbsd.org/netbsd-bugs/2017/07/25/msg052924.html).
 This change to NetBSD 10.99.6 updates the GNU assembler in binutils.old,
 altering the behaviour of tc-vax.c:md_create_long_jump() to emit a jump
 to an address relative to the PC instead of a jump to an absolute address.

 many thanks

 kalvis


 ---
   .../gpl3/binutils.old/dist/gas/config/tc-vax.c  | 17 +++++++++--------
   1 file changed, 9 insertions(+), 8 deletions(-)

 diff --git a/external/gpl3/binutils.old/dist/gas/config/tc-vax.c
 b/external/gpl3/binutils.old/dist/gas/config/tc-vax.c
 index 6a2ef16b1760..57863a55e882 100644
 --- a/external/gpl3/binutils.old/dist/gas/config/tc-vax.c
 +++ b/external/gpl3/binutils.old/dist/gas/config/tc-vax.c
 @@ -2332,18 +2332,19 @@ md_create_short_jump (char *ptr,

   void
   md_create_long_jump (char *ptr,
 -                    addressT from_addr ATTRIBUTE_UNUSED,
 -                    addressT to_addr,
 -                    fragS *frag,
 -                    symbolS *to_symbol)
 +                     addressT from_addr,
 +                     addressT to_addr,
 +                     fragS *frag ATTRIBUTE_UNUSED,
 +                     symbolS *to_symbol ATTRIBUTE_UNUSED)
   {
     valueT offset;

 -  offset = to_addr - S_GET_VALUE (to_symbol);
 -  *ptr++ = VAX_JMP;            /* Arbitrary jump.  */
 -  *ptr++ = VAX_ABSOLUTE_MODE;
 +  /* account for 1 byte instruction, 1 byte of address specifier and
 +     4 bytes of offset from PC */
 +  offset = to_addr - (from_addr + 1 + 1 + 4);
 +  *ptr++ = VAX_JMP;             /* long jump */
 +  *ptr++ = VAX_PC_RELATIVE_MODE;
     md_number_to_chars (ptr, offset, 4);
 -  fix_new (frag, ptr - frag->fr_literal, 4, to_symbol, (long) 0, 0,
 NO_RELOC);
   }
   ^L
   #ifdef OBJ_VMS
 -- 
 2.20.1


From: Rin Okuyama <rokuyama.rk@gmail.com>
To: "gnats-bugs@NetBSD.org" <gnats-bugs@NetBSD.org>, netbsd-bugs@netbsd.org
Cc: Kalvis Duckmanton <kalvisd@gmail.com>
Subject: Re: toolchain/52427 (Re: [PATCH] 1/2: toolchain/52427: VAX text
 relocations)
Date: Tue, 1 Aug 2023 11:00:44 +0900

 Oops, wrong subject. It should be "Re: toolchain/52427"
 (colon was missing...).

 -------- Forwarded Message --------
 Subject: Re toolchain/52427 (Re: [PATCH] 1/2: toolchain/52427: VAX text relocations)
 Date: Tue, 1 Aug 2023 10:20:08 +0900
 From: Rin Okuyama <rokuyama.rk@gmail.com>
 To: Kalvis Duckmanton <kalvisd@gmail.com>, tech-toolchain@netbsd.org
 CC: gnats-bugs@NetBSD.org <gnats-bugs@NetBSD.org>, netbsd-bugs@netbsd.org

 Hi Kalvis,

 thank you again for great analysis! Some random comments:

 (1) Discussion should be recorded to GNATS, our bug tracking system.
 Please (a) mention PR number in subject, with (b) cc to gnats-bugs@.
 I have forwarded your messages to gnats-bugs@.

 (2) binutils is a 3rd party software for us. Can you please report
 this to upstream?

 https://sourceware.org/binutils/docs/binutils/Bug-Reporting.html

 (3) Now, we are preparing to migrate to GCC 12.3.0. Hopefully,
 vax will switch to 12.3.0 soon. IMO, your patch should be applied
 after the switch. It brings about behavior change for the critical
 toolchain component. I'd like to evaluate its results, separated
 from those by GCC bump.

 Let me thank you again for your work!!

 rin

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-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.