NetBSD Problem Report #59391

From www@netbsd.org  Sat May  3 13:38:00 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) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 656D21A923C
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  3 May 2025 13:38:00 +0000 (UTC)
Message-Id: <20250503133759.0EEFE1A923E@mollari.NetBSD.org>
Date: Sat,  3 May 2025 13:37:59 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: unnecessary __PIC__ conditionals clutter .S files
X-Send-Pr-Version: www-1.0

>Number:         59391
>Category:       lib
>Synopsis:       unnecessary __PIC__ conditionals clutter .S files
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat May 03 13:40:00 +0000 2025
>Last-Modified:  Thu May 08 01:15:01 +0000 2025
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
Piccy Eaters Anonymous
>Environment:
>Description:
Example:

     81 #ifdef __PIC__
     82 	call	PIC_PLT(_C_LABEL(__sigprocmask14))
     83 #else
     84 	call	_C_LABEL(__sigprocmask14)
     85 #endif

https://nxr.netbsd.org/xref/src/lib/libc/arch/i386/gen/setjmp.S?r=1.18#81

This is unnecessary because PIC_PLT(x) is already defined to expand to
x@PLT if __PIC__, and x if !__PIC__.

We have various cases of this in-tree.  Sometimes entire files are
conditionalized on __PIC__, such as:

https://nxr.netbsd.org/xref/src/lib/libc/arch/sparc/gen/sigsetjmp.S?r=1.7

It would be nice if had fewer of these conditionals in .S files to
make the .S files easier to read and audit with less duplication of
logic.
>How-To-Repeat:
code inspection
>Fix:
Yes, please!

In some cases we can just eliminate the #ifdef __PIC__.  In other
cases like the sparc files it may require some judicious
#ifdef __PIC__ macros like this:

https://nxr.netbsd.org/xref/src/tests/kernel/arch/sparc/execsp.S?r=1.1#35

Maybe that's too much abstraction, but I think it's easier to read the
slightly abstracted code than to juggle two whole copies of the
definitions.

>Release-Note:

>Audit-Trail:

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/59391: unnecessary __PIC__ conditionals clutter .S files
Date: Sat, 3 May 2025 17:07:24 +0300

 > Sometimes entire files are conditionalized on __PIC__, such as:
 >
 > https://nxr.netbsd.org/xref/src/lib/libc/arch/sparc/gen/sigsetjmp.S?r=1.7

 Which, in this particular case, is, IMHO, the best way to write it.
 It has two slight problems.  First, when last time I touched this, I
 was lazy and didn't comment the static version the same way I did for
 dynamic.  Second, unfortunately the preprocessor symbol is PIC, so
 instead of more natural:

   #if static
   ...
   // more simple static version
   ...
   #else // PIC
   ...
   // jump through pic hoops that obscure the logic a bit
   ...
   #endif

 you either get ungly inverted "if !PIC" condition preceding static
 part or get the more obscure dynamic "if PIC" version firts, like here
 and in most of the rest of the code in the tree.

 But trying to cram this into one text for static and PIC with macro
 magic will be a bad idea.

 -uwe

From: Taylor R Campbell <riastradh@NetBSD.org>
To: Valery Ushakov <uwe@stderr.spb.ru>
Cc: gnats-bugs@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: lib/59391: unnecessary __PIC__ conditionals clutter .S files
Date: Sat, 3 May 2025 14:58:48 +0000

 > Date: Sat, 3 May 2025 17:07:24 +0300
 > From: Valery Ushakov <uwe@stderr.spb.ru>
 >=20
 > > Sometimes entire files are conditionalized on __PIC__, such as:
 > >
 > > https://nxr.netbsd.org/xref/src/lib/libc/arch/sparc/gen/sigsetjmp.S?r=
 =3D1.7
 >=20
 > Which, in this particular case, is, IMHO, the best way to write it.
 > [...]
 > But trying to cram this into one text for static and PIC with macro
 > magic will be a bad idea.

 So I see, the control flow is nontrivially different, I guess because
 there's no PLT here (and no conditional branch to register)?  Fair
 enough!  (Though why not use PLT here?)

 But the x86 ones are just silly: we already have a macro PIC_PLT to
 conditionally expand to x@PLT or x depending on __PIC__, so

 #ifdef __PIC__
 	call PIC_PLT(x)
 #else
 	call x
 #endif

 redundantly makes this PIC code an ATM machine.

From: Taylor R Campbell <riastradh@NetBSD.org>
To: Valery Ushakov <uwe@stderr.spb.ru>
Cc: gnats-bugs@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: lib/59391: unnecessary __PIC__ conditionals clutter .S files
Date: Sat, 3 May 2025 15:56:33 +0000

 > Date: Sat, 3 May 2025 14:58:48 +0000
 > From: Taylor R Campbell <riastradh@NetBSD.org>
 >=20
 > > Date: Sat, 3 May 2025 17:07:24 +0300
 > > From: Valery Ushakov <uwe@stderr.spb.ru>
 > >=20
 > > > Sometimes entire files are conditionalized on __PIC__, such as:
 > > >
 > > > https://nxr.netbsd.org/xref/src/lib/libc/arch/sparc/gen/sigsetjmp.S?r=
 =3D1.7
 > >=20
 > > Which, in this particular case, is, IMHO, the best way to write it.
 > > [...]
 > > But trying to cram this into one text for static and PIC with macro
 > > magic will be a bad idea.
 >=20
 > So I see, the control flow is nontrivially different, I guess because
 > there's no PLT here (and no conditional branch to register)?  Fair
 > enough!  (Though why not use PLT here?)

 Answering my own question about PLT: even if we went through the PLT
 here, it wouldn't help because there's only R_SPARC_WPLT30 for CALL
 instructions, no R_SPARC_WPLT22 for conditional branches, so the
 control flow would still be substantively different for the PIC and
 non-PIC cases.

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/59391: unnecessary __PIC__ conditionals clutter .S files
Date: Sat, 3 May 2025 21:05:10 +0300

 > But the x86 ones are just silly [...]

 They very well can be, but you can't legislate common sense.

 Sometimes it's easy and natural to have common asm text with a bit of
 macro pixie dust that gives you both static and pic code and I
 generally tried to do that for sh3 for example, where, yes, you can
 perhaps schedule instructions a bit better in each version if you
 wrote them separately, but you are not really doing any contortions to
 merge the two versions.

 OTOH sometimes it's easier (including in terms of cognitive load on
 the reader) to have two separate versions, like in that sparc example.

 -uwe

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59391 CVS commit: src/lib/libc
Date: Sat, 3 May 2025 19:55:33 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat May  3 19:55:33 UTC 2025

 Modified Files:
 	src/lib/libc/arch/i386/gen: resumecontext.S setjmp.S sigsetjmp.S
 	    swapcontext.S
 	src/lib/libc/arch/i386/sys: __clone.S cerror.S ptrace.S
 	src/lib/libc/compat/arch/i386/gen: compat_setjmp.S compat_sigsetjmp.S

 Log Message:
 libc/i386: Omit needless __PIC__ conditionals.

 No binary change.

 PR lib/59391: unnecessary __PIC__ conditionals clutter .S files


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 src/lib/libc/arch/i386/gen/resumecontext.S \
     src/lib/libc/arch/i386/gen/swapcontext.S
 cvs rdiff -u -r1.18 -r1.19 src/lib/libc/arch/i386/gen/setjmp.S
 cvs rdiff -u -r1.19 -r1.20 src/lib/libc/arch/i386/gen/sigsetjmp.S
 cvs rdiff -u -r1.6 -r1.7 src/lib/libc/arch/i386/sys/__clone.S
 cvs rdiff -u -r1.18 -r1.19 src/lib/libc/arch/i386/sys/cerror.S
 cvs rdiff -u -r1.19 -r1.20 src/lib/libc/arch/i386/sys/ptrace.S
 cvs rdiff -u -r1.3 -r1.4 src/lib/libc/compat/arch/i386/gen/compat_setjmp.S \
     src/lib/libc/compat/arch/i386/gen/compat_sigsetjmp.S

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

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59391 CVS commit: src/lib/libc/arch/x86_64
Date: Sat, 3 May 2025 19:56:21 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat May  3 19:56:21 UTC 2025

 Modified Files:
 	src/lib/libc/arch/x86_64/gen: __setjmp14.S __sigsetjmp14.S
 	    resumecontext.S swapcontext.S
 	src/lib/libc/arch/x86_64/sys: __clone.S cerror.S ptrace.S

 Log Message:
 libc/x86_64: Omit needless __PIC__ conditionals.

 PR lib/59391: unnecessary __PIC__ conditionals clutter .S files


 To generate a diff of this commit:
 cvs rdiff -u -r1.4 -r1.5 src/lib/libc/arch/x86_64/gen/__setjmp14.S \
     src/lib/libc/arch/x86_64/gen/__sigsetjmp14.S
 cvs rdiff -u -r1.6 -r1.7 src/lib/libc/arch/x86_64/gen/resumecontext.S \
     src/lib/libc/arch/x86_64/gen/swapcontext.S
 cvs rdiff -u -r1.5 -r1.6 src/lib/libc/arch/x86_64/sys/__clone.S
 cvs rdiff -u -r1.7 -r1.8 src/lib/libc/arch/x86_64/sys/cerror.S \
     src/lib/libc/arch/x86_64/sys/ptrace.S

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

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59391 CVS commit: src
Date: Sat, 3 May 2025 19:57:13 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat May  3 19:57:13 UTC 2025

 Modified Files:
 	src/lib/libc/arch/arm/gen: _setjmp.S setjmp.S
 	src/lib/libc/arch/arm/sys: cerror.S ptrace.S sbrk.S
 	src/sys/arch/arm/include: asm.h

 Log Message:
 arm: Nix most __PIC__ conditionals in .S files.

 New macros PCREL_GET(rN,label,pclabel) and PCREL_SYM(label,pclabel)
 to enable this by the pattern:

 	ldr	rN, label
 #ifdef __PIC__
 pclabel:
 	add	rN, rN, pc
 #endif
 ...
 label:
 #ifdef __PIC__
 	.word	(label - (pclabel + 2*sizeof(instruction)))
 #else
 	.word	label
 #endif

 (sizeof(instruction) = 2 for thumb, 4 for non-thumb.)

 No binary change in libc with MKPIE=no (i.e., testing both for
 changes to the PIC build and changes to the non-PIC build).

 In principle, assembly routines could improve instruction scheduling
 by splitting up the ldr and add instructions.  But in practice, the
 maintenance and auditing burden likely makes this worthwhile by
 improving legibility vs a tangle of in-line #ifdefs.

 brk.S does things a little differently making it harder to unify.
 Could redo it but I don't want to make changes without testing them
 first.

 PR lib/59391: unnecessary __PIC__ conditionals clutter .S files


 To generate a diff of this commit:
 cvs rdiff -u -r1.17 -r1.18 src/lib/libc/arch/arm/gen/_setjmp.S
 cvs rdiff -u -r1.19 -r1.20 src/lib/libc/arch/arm/gen/setjmp.S
 cvs rdiff -u -r1.13 -r1.14 src/lib/libc/arch/arm/sys/cerror.S
 cvs rdiff -u -r1.12 -r1.13 src/lib/libc/arch/arm/sys/ptrace.S \
     src/lib/libc/arch/arm/sys/sbrk.S
 cvs rdiff -u -r1.35 -r1.36 src/sys/arch/arm/include/asm.h

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

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/59391: unnecessary __PIC__ conditionals clutter .S files
Date: Sun, 4 May 2025 14:12:57 +0300

 > New macros PCREL_GET(rN,label,pclabel) and PCREL_SYM(label,pclabel)

 Speaking from sh3 experience (where similar macros have been around
 for 20 years), there are two things in this that kinda feel awkward.

 The "pclabel" in PCREL_GET(a, label, pclabel) should be hoisted out
 ouf the macro, and instead of

           PCREL_GET(rN, .Lsym, .LPC0)

 one can write just

   0:      PCREL_GET(rN, .Lsym)

 with the natural asm syntax for labels.  The label doesn't need to be
 hidden inside the macro (unlike, say, "gotsym" in GOT_INITSYM, where
 preceding .align gets in the way).  I think this lessens the cognitive
 burden on the reader.  Also, with the label in its natural position
 you can also use local labels, b/c in the label position that number
 is obviously a local label, while in

           PCREL_GET(rN, .Lsym, 0)

 that zero is extra confusing.

 Second, "PCREL" in the names is a confusing, b/c the end result is to
 set rN to the _ABSOLUTE_ address, not to the pc relative offset.

 The sbrk.S example

     /* get address or offset to __curbrk */
     PCREL_GET(r2, .Lcurbrk, .LPIC0)

 is the perfect storm - the comment used to refer to the "ldr"
 instruction that is now inside the macro.  The macro always gets the
 address, so the comment is now wrong and (with "PCREL" in the macro
 name) doubly confusing.

 -uwe

From: "Valery Ushakov" <uwe@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59391 CVS commit: src
Date: Tue, 6 May 2025 20:21:34 +0000

 Module Name:	src
 Committed By:	uwe
 Date:		Tue May  6 20:21:34 UTC 2025

 Modified Files:
 	src/lib/libc/arch/arm/gen: _setjmp.S setjmp.S
 	src/lib/libc/arch/arm/sys: cerror.S ptrace.S sbrk.S
 	src/sys/arch/arm/include: asm.h

 Log Message:
 arm/asm.h: revert PCREL_GET &c in previous (ok riastradh)

 This change needs to be redone and re-verified.  I have detailed some
 issues in the PR, and it also turns out that some of the changes were
 in the !_REENTRANT branch of #ifdef and thus not checked at all.
 riastradh asked to back out the changes for now.

 PR lib/59391: unnecessary __PIC__ conditionals clutter .S files


 To generate a diff of this commit:
 cvs rdiff -u -r1.18 -r1.19 src/lib/libc/arch/arm/gen/_setjmp.S
 cvs rdiff -u -r1.20 -r1.21 src/lib/libc/arch/arm/gen/setjmp.S
 cvs rdiff -u -r1.14 -r1.15 src/lib/libc/arch/arm/sys/cerror.S
 cvs rdiff -u -r1.13 -r1.14 src/lib/libc/arch/arm/sys/ptrace.S \
     src/lib/libc/arch/arm/sys/sbrk.S
 cvs rdiff -u -r1.36 -r1.37 src/sys/arch/arm/include/asm.h

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

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59391 CVS commit: src/lib/libc/rpc
Date: Tue, 6 May 2025 23:18:38 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue May  6 23:18:38 UTC 2025

 Modified Files:
 	src/lib/libc/rpc: svc_fdset.c

 Log Message:
 libc: Fix _REENTRANT build.

 This svc_fdset.c has some pretty heinous abuse of thread_key_t, but
 I'll pretend I didn't see that for now so I don't have to wade
 further into the sunrpc business.

 Prompted by:

 PR lib/59401: libc: thr_sigsetmask definition is incoherent
 PR lib/59391: unnecessary __PIC__ conditionals clutter .S files


 To generate a diff of this commit:
 cvs rdiff -u -r1.16 -r1.17 src/lib/libc/rpc/svc_fdset.c

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

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/59391: unnecessary __PIC__ conditionals clutter .S files
Date: Thu, 8 May 2025 04:09:51 +0300

 The patch below allows one to write something like the following.  For
 static version it will expand to direct absolute accesses.  For PIC
 version it will do GOT or PC-relative respectively.  Same object code
 is generated modulo one s/mov/movs/ in cerror.S to make it compilable
 as thumb (to verify the same code is generated for thumb as well).


 0:	PIC_GOT_INIT(r3, .Lgot)
 	...
 	MOV_GLOBAL(r4, r3, .Lgvar)
 	str	r0, [r4]
 	...
 1:	MOV_PROTECTED(r4, .Llvar)
 	str	r1, [r4]

 	// and in the data after the function
 	.p2align 2
 .Lgot:
 	PIC_GOT_INITREF(0b)

 .Lgvar: // gvar has default visibility
 	.word GLOBAL_SYMREF(gvar)

 .Llvar: // lvar has protected or hidden visibility
 	.word PROTECTED_SYMREF(lvar)


 Index: sys/arch/arm/include/asm.h
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/arm/include/asm.h,v
 retrieving revision 1.39
 diff -u -p -c -r1.39 asm.h
 *** sys/arch/arm/include/asm.h	7 May 2025 16:26:47 -0000	1.39
 --- sys/arch/arm/include/asm.h	8 May 2025 00:32:21 -0000
 ***************
 *** 189,217 ****

   #define	ASMSTR		.asciz

 - #ifdef __PIC__
 - #define	REL_SYM(a, b)	((a) - (b))
 - #define	PLT_SYM(x)	x
 - #define	GOT_SYM(x)	PIC_SYM(x, GOT)
 - #define	GOT_GET(x,got,sym)	\
 - 	ldr	x, sym;		\
 - 	ldr	x, [x, got]

   /*
 !  * Load _GLOBAL_OFFSET_TABLE_ address into register:
    *
 !  * 0:	GOT_INIT(rX, .Lgot)
    *	...
    *
    *      // and in the data after the function
 !  *	GOT_INITSYM(.Lgot, 0b)
    */
 ! #define	GOT_INIT(Rgot, gotsym)	  \
 ! 	ldr	Rgot, gotsym	; \
 ! 	add	Rgot, Rgot, pc
 ! #define	GOT_INITSYM(gotsym, initlabel)	\
 ! 	.align 0;		\
 ! 	gotsym:	.word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (initlabel+(1+2)*_INSN_SIZE)

   #ifdef __STDC__
   #define	PIC_SYM(x,y)	x(y)
 --- 189,243 ----

   #define	ASMSTR		.asciz


   /*
 !  * Hide the gory details of PIC accesses vs. normal accesses.  Use as
 !  * in the following example.  For static version it will expand to
 !  * direct absolute accesses.  For PIC version it will do GOT or
 !  * PC-relative respectively.
    *
 !  * 0:	PIC_GOT_INIT(r3, .Lgot)
    *	...
 +  *	MOV_GLOBAL(r4, r3, .Lgvar)
 +  *	str	r0, [r4]
 +  *	...
 +  * 1:	MOV_PROTECTED(r4, .Llvar)
 +  *	str	r1, [r4]
    *
    *      // and in the data after the function
 !  *	.p2align 2
 !  * .Lgot:
 !  *	PIC_GOT_INITREF(0b)
 !  *
 !  * .Lgvar: // gvar has default visibility
 !  *	.word GLOBAL_SYMREF(gvar)
 !  *
 !  * .Llvar: // lvar has protected or hidden visibility
 !  *	.word PROTECTED_SYMREF(lvar)
    */
 ! #ifdef __PIC__
 ! #define	REL_SYM(a, b)	((a) - (b))
 ! #define	PLT_SYM(x)	x
 ! 
 ! #define	PIC_GOT_INIT(Rgot, reflabel) \
 ! 	MOV_PROTECTED(Rgot, reflabel)
 ! 
 ! #define	PIC_GOT_INITREF(initlabel) \
 ! 	.word PROTECTED_SYMREF(_C_LABEL(_GLOBAL_OFFSET_TABLE_), initlabel)
 ! 
 ! #define MOV_GLOBAL(Rdst, Rgot, reflabel)	\
 ! 	ldr	Rdst, reflabel;			\
 ! 	ldr	Rdst, [Rdst, Rgot]
 ! 
 ! #define	GLOBAL_SYMREF(sym) \
 ! 	PIC_SYM(sym, GOT)
 ! 
 ! #define MOV_PROTECTED(Rdst, reflabel)	\
 ! 	ldr	Rdst, reflabel;		\
 ! 	add	Rdst, Rdst, pc
 ! 
 ! #define PROTECTED_SYMREF(sym, movlabel)	\
 ! 	((sym) - ((movlabel) + (1+2)*_INSN_SIZE))

   #ifdef __STDC__
   #define	PIC_SYM(x,y)	x(y)
 ***************
 *** 219,232 ****
   #define	PIC_SYM(x,y)	x/**/(/**/y/**/)
   #endif

 ! #else
   #define	REL_SYM(a, b)	(a)
   #define	PLT_SYM(x)	x
 ! #define	GOT_SYM(x)	x
 ! #define	GOT_GET(x,got,sym)	\
 ! 	ldr	x, sym;
 ! #define	GOT_INIT(Rgot, gotsym)
 ! #define	GOT_INITSYM(gotsym, initlabel)
   #define	PIC_SYM(x,y)	x
   #endif	/* __PIC__ */

 --- 245,267 ----
   #define	PIC_SYM(x,y)	x/**/(/**/y/**/)
   #endif

 ! #else  /* !__PIC__ */
   #define	REL_SYM(a, b)	(a)
   #define	PLT_SYM(x)	x
 ! 
 ! #define	PIC_GOT_INIT(Rgot, reflabel)
 ! #define	PIC_GOT_INITREF(initlabel)
 ! 
 ! #define MOV_GLOBAL(Rdst, Rgot, reflabel) \
 ! 	ldr	Rdst, reflabel	/* Rgot is not used */
 ! 
 ! #define	GLOBAL_SYMREF(sym) (sym)
 ! 
 ! #define MOV_PROTECTED(Rdst, reflabel)	\
 ! 	ldr	Rdst, reflabel
 ! 
 ! #define PROTECTED_SYMREF(sym, movlabel) (sym)
 ! 
   #define	PIC_SYM(x,y)	x
   #endif	/* __PIC__ */

 Index: tests/kernel/arch/arm/contextspfunc.S
 ===================================================================
 RCS file: /cvsroot/src/tests/kernel/arch/arm/contextspfunc.S,v
 retrieving revision 1.2
 diff -u -p -c -r1.2 contextspfunc.S
 *** tests/kernel/arch/arm/contextspfunc.S	7 May 2025 16:26:47 -0000	1.2
 --- tests/kernel/arch/arm/contextspfunc.S	8 May 2025 00:32:22 -0000
 *************** RCSID("$NetBSD: contextspfunc.S,v 1.2 20
 *** 39,51 ****
    *	the global variable contextsp and call contextdone.
    */
   ENTRY(contextspfunc)
 ! 0:	GOT_INIT(r0, .Lgot)
   	mov	r1, sp
 ! 	GOT_GET(r2, r0, .Lcontextsp)
   	str	r1, [r2]
   	b	PLT_SYM(_C_LABEL(contextdone))

 ! 	GOT_INITSYM(.Lgot, 0b)
   .Lcontextsp:
 ! 	.word	GOT_SYM(contextsp)
   END(contextspfunc)
 --- 39,52 ----
    *	the global variable contextsp and call contextdone.
    */
   ENTRY(contextspfunc)
 ! 0:	PIC_GOT_INIT(r0, .Lgot)
   	mov	r1, sp
 ! 	MOV_GLOBAL(r2, r0, .Lcontextsp)
   	str	r1, [r2]
   	b	PLT_SYM(_C_LABEL(contextdone))

 ! 	.p2align 2
 ! .Lgot:	PIC_GOT_INITREF(0b)
   .Lcontextsp:
 ! 	.word	GLOBAL_SYMREF(contextsp)
   END(contextspfunc)
 Index: tests/kernel/arch/arm/execsp.S
 ===================================================================
 RCS file: /cvsroot/src/tests/kernel/arch/arm/execsp.S,v
 retrieving revision 1.4
 diff -u -p -c -r1.4 execsp.S
 *** tests/kernel/arch/arm/execsp.S	7 May 2025 16:26:47 -0000	1.4
 --- tests/kernel/arch/arm/execsp.S	8 May 2025 00:32:22 -0000
 *************** RCSID("$NetBSD: execsp.S,v 1.4 2025/05/0
 *** 40,54 ****
    *	to the usual csu __start routine.
    */
   ENTRY(execsp_start)
 ! 0:	GOT_INIT(r3, .Lgot.execsp_start)
   	mov	r4, sp
 ! 	GOT_GET(r5, r3, .Lstartsp)
   	str	r4, [r5]
   	b	PLT_SYM(_C_LABEL(__start))

 ! 	GOT_INITSYM(.Lgot.execsp_start, 0b)
   .Lstartsp:
 ! 	.word	GOT_SYM(startsp)
   END(execsp_start)

   /*
 --- 40,56 ----
    *	to the usual csu __start routine.
    */
   ENTRY(execsp_start)
 ! 0:	PIC_GOT_INIT(r3, .Lgot.execsp_start)
   	mov	r4, sp
 ! 	MOV_GLOBAL(r5, r3, .Lstartsp)
   	str	r4, [r5]
   	b	PLT_SYM(_C_LABEL(__start))

 ! 	.p2align 2
 ! .Lgot.execsp_start:
 ! 	PIC_GOT_INITREF(0b)
   .Lstartsp:
 ! 	.word	GLOBAL_SYMREF(startsp)
   END(execsp_start)

   /*
 *************** END(execsp_start)
 *** 58,72 ****
    *	returns.
    */
   ENTRY(execsp_ctor)
 ! 0:	GOT_INIT(r0, .Lgot.execsp_ctor)
   	mov	r1, sp
 ! 	GOT_GET(r2, r0, .Lctorsp)
   	str	r1, [r2]
   	RET

 ! 	GOT_INITSYM(.Lgot.execsp_ctor, 0b)
   .Lctorsp:
 ! 	.word	GOT_SYM(ctorsp)
   END(execsp_ctor)

   	/* Make execsp_ctor a constructor. */
 --- 60,76 ----
    *	returns.
    */
   ENTRY(execsp_ctor)
 ! 0:	PIC_GOT_INIT(r0, .Lgot.execsp_ctor)
   	mov	r1, sp
 ! 	MOV_GLOBAL(r2, r0, .Lctorsp)
   	str	r1, [r2]
   	RET

 ! 	.p2align 2
 ! .Lgot.execsp_ctor:
 ! 	PIC_GOT_INITREF(0b)
   .Lctorsp:
 ! 	.word	GLOBAL_SYMREF(ctorsp)
   END(execsp_ctor)

   	/* Make execsp_ctor a constructor. */
 *************** END(execsp_ctor)
 *** 82,97 ****
    *	been initialized.
    */
   ENTRY(main)
 ! 0:	GOT_INIT(r0, .Lgot.main)
   	mov	r1, sp
 ! 	GOT_GET(r2, r0, .Lmainsp)
   	str	r1, [r2]
   	mov	r0, #0
   	RET

 ! 	GOT_INITSYM(.Lgot.main, 0b)
   .Lmainsp:
 ! 	.word	GOT_SYM(mainsp)
   END(main)

   /*
 --- 86,103 ----
    *	been initialized.
    */
   ENTRY(main)
 ! 0:	PIC_GOT_INIT(r0, .Lgot.main)
   	mov	r1, sp
 ! 	MOV_GLOBAL(r2, r0, .Lmainsp)
   	str	r1, [r2]
   	mov	r0, #0
   	RET

 ! 	.p2align 2
 ! .Lgot.main:
 ! 	PIC_GOT_INITREF(0b)
   .Lmainsp:
 ! 	.word	GLOBAL_SYMREF(mainsp)
   END(main)

   /*
 *************** END(main)
 *** 102,116 ****
    *	back to the t_signal_and_sp parent.
    */
   ENTRY(execsp_dtor)
 ! 0:	GOT_INIT(r0, .Lgot.execsp_dtor)
   	mov	r1, sp
 ! 	GOT_GET(r2, r0, .Ldtorsp)
   	str	r1, [r2]
   	b	PLT_SYM(_C_LABEL(execsp_main))

 ! 	GOT_INITSYM(.Lgot.execsp_dtor, 0b)
   .Ldtorsp:
 ! 	.word	GOT_SYM(dtorsp)
   END(execsp_dtor)

   	/* Make execsp_ctor a destructor. */
 --- 108,124 ----
    *	back to the t_signal_and_sp parent.
    */
   ENTRY(execsp_dtor)
 ! 0:	PIC_GOT_INIT(r0, .Lgot.execsp_dtor)
   	mov	r1, sp
 ! 	MOV_GLOBAL(r2, r0, .Ldtorsp)
   	str	r1, [r2]
   	b	PLT_SYM(_C_LABEL(execsp_main))

 ! 	.p2align 2
 ! .Lgot.execsp_dtor:
 ! 	PIC_GOT_INITREF(0b)
   .Ldtorsp:
 ! 	.word	GLOBAL_SYMREF(dtorsp)
   END(execsp_dtor)

   	/* Make execsp_ctor a destructor. */
 Index: tests/kernel/arch/arm/signalsphandler.S
 ===================================================================
 RCS file: /cvsroot/src/tests/kernel/arch/arm/signalsphandler.S,v
 retrieving revision 1.3
 diff -u -p -c -r1.3 signalsphandler.S
 *** tests/kernel/arch/arm/signalsphandler.S	7 May 2025 16:26:47 -0000	1.3
 --- tests/kernel/arch/arm/signalsphandler.S	8 May 2025 00:32:22 -0000
 *************** RCSID("$NetBSD: signalsphandler.S,v 1.3 
 *** 39,51 ****
    *	variable signalsp and return.
    */
   ENTRY(signalsphandler)
 ! 0:	GOT_INIT(r0, .Lgot)
   	mov	r1, sp
 ! 	GOT_GET(r2, r0, .Lsignalsp)
   	str	r1, [r2]
   	RET

 ! 	GOT_INITSYM(.Lgot, 0b)
   .Lsignalsp:
 ! 	.word	GOT_SYM(signalsp)
   END(signalsphandler)
 --- 39,52 ----
    *	variable signalsp and return.
    */
   ENTRY(signalsphandler)
 ! 0:	PIC_GOT_INIT(r0, .Lgot)
   	mov	r1, sp
 ! 	MOV_GLOBAL(r2, r0, .Lsignalsp)
   	str	r1, [r2]
   	RET

 ! 	.p2align 2
 ! .Lgot:	PIC_GOT_INITREF(0b)
   .Lsignalsp:
 ! 	.word	GLOBAL_SYMREF(signalsp)
   END(signalsphandler)
 Index: lib/libc/arch/arm/gen/_setjmp.S
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/arch/arm/gen/_setjmp.S,v
 retrieving revision 1.20
 diff -u -p -c -r1.20 _setjmp.S
 *** lib/libc/arch/arm/gen/_setjmp.S	8 May 2025 00:28:31 -0000	1.20
 --- lib/libc/arch/arm/gen/_setjmp.S	8 May 2025 00:32:22 -0000
 *************** ENTRY(_setjmp)
 *** 60,71 ****
   	ldr	r1, .L_setjmp_magic

   #if defined(__ARM_EABI__) && (!defined(__thumb__) || defined(_ARM_ARCH_T2))
 ! 	ldr	r2, .Lfpu_present
 ! #ifdef __PIC__
 ! 	add	r2, r2, pc	/* pc = &.LPIC0 */
 ! #endif
   	ldr	r2, [r2]
 - .LPIC0:
   #if defined(__thumb__) && defined(_ARM_ARCH_T2)
   	cbz	r2, 1f
   #else
 --- 60,67 ----
   	ldr	r1, .L_setjmp_magic

   #if defined(__ARM_EABI__) && (!defined(__thumb__) || defined(_ARM_ARCH_T2))
 ! 0:	MOV_PROTECTED(r2, .Lfpu_present)
   	ldr	r2, [r2]
   #if defined(__thumb__) && defined(_ARM_ARCH_T2)
   	cbz	r2, 1f
   #else
 *************** ENTRY(_setjmp)
 *** 106,114 ****
   	RET

   #if defined(__ARM_EABI__) && (!defined(__thumb__) || defined(_ARM_ARCH_T2))
 ! 	.align	0
   .Lfpu_present:
 ! 	.word	REL_SYM(_libc_arm_fpu_present, .LPIC0)
   #endif /* __ARM_EABI__ && (_ARM_ARCH_T2 || !__thumb__) */
   END(_setjmp)

 --- 102,110 ----
   	RET

   #if defined(__ARM_EABI__) && (!defined(__thumb__) || defined(_ARM_ARCH_T2))
 ! 	.p2align 2
   .Lfpu_present:
 ! 	.word	PROTECTED_SYMREF(_C_LABEL(_libc_arm_fpu_present), 0b)
   #endif /* __ARM_EABI__ && (_ARM_ARCH_T2 || !__thumb__) */
   END(_setjmp)

 Index: lib/libc/arch/arm/gen/setjmp.S
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/arch/arm/gen/setjmp.S,v
 retrieving revision 1.22
 diff -u -p -c -r1.22 setjmp.S
 *** lib/libc/arch/arm/gen/setjmp.S	8 May 2025 00:28:31 -0000	1.22
 --- lib/libc/arch/arm/gen/setjmp.S	8 May 2025 00:32:22 -0000
 *************** ENTRY(__setjmp14)
 *** 75,86 ****
   	ldr	r1, .Lsetjmp_magic

   #if defined(__ARM_EABI__) && (!defined(__thumb__) || defined(_ARM_ARCH_T2))
 ! 	ldr	r2, .Lfpu_present
 ! #ifdef __PIC__
 ! 	add	r2, r2, pc	/* pc = &.LPIC0 */
 ! #endif
   	ldr	r2, [r2]
 - .LPIC0:
   #if defined(__thumb__) && defined(_ARM_ARCH_T2)
   	cbz	r2, 1f		/* don't save if we don't have a FPU */
   #else
 --- 75,82 ----
   	ldr	r1, .Lsetjmp_magic

   #if defined(__ARM_EABI__) && (!defined(__thumb__) || defined(_ARM_ARCH_T2))
 ! 0:	MOV_PROTECTED(r2, .Lfpu_present)
   	ldr	r2, [r2]
   #if defined(__thumb__) && defined(_ARM_ARCH_T2)
   	cbz	r2, 1f		/* don't save if we don't have a FPU */
   #else
 *************** ENTRY(__setjmp14)
 *** 120,128 ****
   	RET

   #if defined(__ARM_EABI__) && (!defined(__thumb__) || defined(_ARM_ARCH_T2))
 ! 	.align	0
   .Lfpu_present:
 ! 	.word	REL_SYM(_libc_arm_fpu_present, .LPIC0)
   #endif /* __ARM_EABI__ && (!__thumb__ || _ARM_ARCH_T2) */
   END(__setjmp14)

 --- 116,124 ----
   	RET

   #if defined(__ARM_EABI__) && (!defined(__thumb__) || defined(_ARM_ARCH_T2))
 ! 	.p2align 2
   .Lfpu_present:
 ! 	.word	PROTECTED_SYMREF(_C_LABEL(_libc_arm_fpu_present), 0b)
   #endif /* __ARM_EABI__ && (!__thumb__ || _ARM_ARCH_T2) */
   END(__setjmp14)

 Index: lib/libc/arch/arm/sys/cerror.S
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/arch/arm/sys/cerror.S,v
 retrieving revision 1.18
 diff -u -p -c -r1.18 cerror.S
 *** lib/libc/arch/arm/sys/cerror.S	7 May 2025 16:26:47 -0000	1.18
 --- lib/libc/arch/arm/sys/cerror.S	8 May 2025 00:32:22 -0000
 *************** ENTRY_NP(CERROR)
 *** 82,92 ****
   	.fnstart
   	.cfi_startproc
   #endif
 ! 0:	GOT_INIT(r3, .Lgot)
 ! 	ldr	r1, .Lerrno
 ! #ifdef __PIC__
 ! 	ldr	r1, [r3, r1]
 ! #endif /* __PIC__ */
   	str	r0, [r1]
   	MOV_RETVAL_MINUS_1
   	RET
 --- 82,89 ----
   	.fnstart
   	.cfi_startproc
   #endif
 ! 0:	PIC_GOT_INIT(r3, .Lgot)
 ! 	MOV_GLOBAL(r1, r3, .Lerrno)
   	str	r0, [r1]
   	MOV_RETVAL_MINUS_1
   	RET
 *************** ENTRY_NP(CERROR)
 *** 94,102 ****
   	.cfi_endproc
   	.fnend
   #endif
 ! 
 ! 	GOT_INITSYM(.Lgot, 0b)
   .Lerrno:
 ! 	.word	GOT_SYM(_C_LABEL(errno))
   #endif /* _REENTRANT */
   END(CERROR)
 --- 91,99 ----
   	.cfi_endproc
   	.fnend
   #endif
 ! 	.p2align 2
 ! .Lgot:	PIC_GOT_INITREF(0b)
   .Lerrno:
 ! 	.word	GLOBAL_SYMREF(_C_LABEL(errno))
   #endif /* _REENTRANT */
   END(CERROR)
 Index: lib/libc/arch/arm/sys/ptrace.S
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/arch/arm/sys/ptrace.S,v
 retrieving revision 1.14
 diff -u -p -c -r1.14 ptrace.S
 *** lib/libc/arch/arm/sys/ptrace.S	6 May 2025 20:21:33 -0000	1.14
 --- lib/libc/arch/arm/sys/ptrace.S	8 May 2025 00:32:22 -0000
 ***************
 *** 35,40 ****
 --- 35,43 ----

   ENTRY(ptrace)
   #ifdef _REENTRANT
 + 	/* __errno() returns the address of a thread local variable */
 + 	.globl	_C_LABEL(__errno)
 + 
   #if !defined(__thumb__) || defined(_ARM_ARCH_T2)
   	push	{r0-r3, lr}
   #else
 *************** ENTRY(ptrace)
 *** 52,69 ****
   	mov	lr, r4
   	pop	{r0-r4}
   #endif
 ! #else
   	push	{r0, r1}
 ! #ifdef __PIC__
 ! 	/* Setup the GOT */
 ! 	ldr	r0, .Lgot
 ! 	adr	r1, .Lgot
 ! 	add	r0, r0, r1
 ! 	ldr	r1, .Lerrno
 ! 	ldr	r1, [r0, r1]
 ! #else
 ! 	ldr	r1, .Lerrno
 ! #endif /* __PIC__ */
   	movs	r0, #0
   	str	r0, [r1]
   	pop	{r0, r1}
 --- 55,68 ----
   	mov	lr, r4
   	pop	{r0-r4}
   #endif
 ! 
 ! #else /* !_REENTRANT */
 ! 	/* errno is a global variable */
 ! 	.globl	_C_LABEL(errno)
 ! 
   	push	{r0, r1}
 ! 0:	PIC_GOT_INIT(r0, .Lgot)
 ! 	MOV_GLOBAL(r1, r0, .Lerrno)
   	movs	r0, #0
   	str	r0, [r1]
   	pop	{r0, r1}
 *************** ENTRY(ptrace)
 *** 74,86 ****
   	RET

   #ifndef _REENTRANT
 ! #ifdef __PIC__
 ! 	.align	0
 ! .Lgot:
 ! 	.word	_C_LABEL(_GLOBAL_OFFSET_TABLE_) - .Lgot
 ! #endif /* __PIC__ */
 ! 
   .Lerrno:
 ! 	.word	PIC_SYM(_C_LABEL(errno), GOT)
   #endif /* !_REENTRANT */
   END(ptrace)
 --- 73,81 ----
   	RET

   #ifndef _REENTRANT
 ! 	.p2align 2
 ! .Lgot:	PIC_GOT_INITREF(0b)
   .Lerrno:
 ! 	.word	GLOBAL_SYMREF(_C_LABEL(errno))
   #endif /* !_REENTRANT */
   END(ptrace)
 Index: lib/libc/arch/arm/sys/sbrk.S
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/arch/arm/sys/sbrk.S,v
 retrieving revision 1.14
 diff -u -p -c -r1.14 sbrk.S
 *** lib/libc/arch/arm/sys/sbrk.S	6 May 2025 20:21:34 -0000	1.14
 --- lib/libc/arch/arm/sys/sbrk.S	8 May 2025 00:32:22 -0000
 *************** _C_LABEL(__curbrk):
 *** 51,67 ****
    * Change the data segment size
    */
   ENTRY(_sbrk)
 ! 	/* get address or offset to __curbrk */
 ! 	ldr	r2, .Lcurbrk
 ! #ifdef __PIC__
 ! 	add	r2, r2, pc	/* pc = &.LPIC0 */
 ! #endif

   	/* Get the current brk address */
   	ldr	r1, [r2]

   	/* Calculate new value */
 ! .LPIC0:	mov	r3, r0
   	adds	r0, r0, r1
   	SYSTRAP(break)
   	_INVOKE_CERROR()
 --- 51,64 ----
    * Change the data segment size
    */
   ENTRY(_sbrk)
 ! 	/* Get address of __curbrk */
 ! 1:	MOV_PROTECTED(r2, .Lcurbrk)

   	/* Get the current brk address */
   	ldr	r1, [r2]

   	/* Calculate new value */
 ! 	mov	r3, r0
   	adds	r0, r0, r1
   	SYSTRAP(break)
   	_INVOKE_CERROR()
 *************** ENTRY(_sbrk)
 *** 74,80 ****
   	/* Return old curbrk value */
   	RET

 ! 	.align	0
   .Lcurbrk:
 ! 	.word	REL_SYM(_C_LABEL(__curbrk), .LPIC0)
   END(_sbrk)
 --- 71,77 ----
   	/* Return old curbrk value */
   	RET

 ! 	.p2align 2
   .Lcurbrk:
 ! 	.word	PROTECTED_SYMREF(_C_LABEL(__curbrk), 1b)
   END(_sbrk)

 -uwe

>Unformatted:

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.