NetBSD Problem Report #55731

From paul@whooppee.com  Sun Oct 18 13:43:01 2020
Return-Path: <paul@whooppee.com>
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" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 82B141A921F
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 18 Oct 2020 13:43:01 +0000 (UTC)
Message-Id: <20201018134227.0767030F2C4@speedy.whooppee.com>
Date: Sun, 18 Oct 2020 06:42:27 -0700 (PDT)
From: paul@whooppee.com
Reply-To: paul@whooppee.com
To: gnats-bugs@NetBSD.org
Subject: (custom) kernel build failure with ``no options PTRACE''
X-Send-Pr-Version: 3.95

>Number:         55731
>Category:       kern
>Synopsis:       (custom) kernel fails when certain options are removed
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 18 13:45:00 +0000 2020
>Last-Modified:  Tue Oct 20 20:50:01 +0000 2020
>Originator:     Paul Goyette
>Release:        NetBSD 9.99.73
>Organization:
+--------------------+--------------------------+-----------------------+
| Paul Goyette       | PGP Key fingerprint:     | E-mail addresses:     |
| (Retired)          | FA29 0E3B 35AF E8AE 6651 | paul@whooppee.com     |
| Software Developer | 0786 F758 55DE 53BA 7731 | pgoyette@netbsd.org   |
+--------------------+--------------------------+-----------------------+
>Environment:


System: NetBSD speedy.whooppee.com 9.99.73 NetBSD 9.99.73 (SPEEDY 2020-09-19 19:15:42 UTC) #0: Sat Sep 19 21:45:32 UTC 2020 paul@speedy.whooppee.com:/build/netbsd-local/obj/amd64/sys/arch/amd64/compile/SPEEDY amd64
Architecture: x86_64
Machine: amd64
>Description:
	Recent changes in 9.99.74 have broken the build for kernels which
	do not include the PTRACE, COREDUMP, EXEC_ELF32, and EXEC_ELF64
	options.  (Note that the exec_elf32 and exec_elf64 modules are
	expected to be autoloaded as needed;  kernels prior to 2020-10-16
	at 13:18:24 UTC work fine with the same set of kernel options and
	modules.)  The build fails with the folllowing errors:
	#      link  SPEEDY/netbsd
	/build/netbsd-local/tools/x86_64/amd64/bin/x86_64--netbsd-ld -Map netbsd.map --cref -T netbsd.ldscript -Ttext 0xffffffff80200000 -e start -z max-page-size=0x200000 -X -o netbsd ${SYSTEM_OBJ:[@]:Nswapnetbsd.o} ${EXTRA_OBJ} vers.o swapnetbsd.o
	/build/netbsd-local/tools/x86_64/amd64/bin/x86_64--netbsd-ld: process_machdep.o: in function `ptrace_machdep_dorequest':
	/build/netbsd-local/src/sys/arch/amd64/amd64/process_machdep.c:329: undefined reference to `ptrace_update_lwp'
	/build/netbsd-local/tools/x86_64/amd64/bin/x86_64--netbsd-ld: /build/netbsd-local/src/sys/arch/amd64/amd64/process_machdep.c:372: undefined reference to `ptrace_update_lwp'
	*** [netbsd] Error code 1

	Christos offered an initial patch in [1].  With this patch, the
	build fails while building modules:

	#   compile  coredump/kern_core.o
	/build/netbsd-local/tools/x86_64/amd64/bin/x86_64--netbsd-gcc -O2 -g   -std=gnu99    -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-sign-compare  -Wsystem-headers   -Wno-traditional   -Wa,--fatal-warnings  -Wreturn-type -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter -Wno-sign-compare -Werror  -Wno-error=address-of-packed-member   -ffreestanding  -fno-strict-aliasing -Wno-pointer-sign -mno-red-zone -mno-mmx -mno-sse -mno-avx -msoft-float -mcmodel=kernel -fno-omit-frame-pointer   -I/build/netbsd-local/src/common/include -DDIAGNOSTIC --sysroot=/build/netbsd-local/dest/amd64 -I/build/netbsd-local/src/common/include -DDIAGNOSTIC  -nostdinc -I. -I/build/netbsd-local/src/sys/modules/coredump -isystem /build/netbsd-local/src/sys -isystem /build/netbsd-local/src/sys/arch -isystem /build/netbsd-local/src/sys/../common/include -D_KERNEL -D_MODULE -DSYSCTL_INCLUDE_DESCR -c  -Wno-cast-function-type    /build/netbsd-local/src/sys/kern/kern
 _core.c
	In file included from /build/netbsd-local/src/sys/sys/compat_stub.h:35,
	                 from /build/netbsd-local/src/sys/kern/kern_core.c:53:
	/build/netbsd-local/src/sys/kern/kern_core.c: In function 'coredump_modcmd':
	/build/netbsd-local/src/sys/kern/kern_core.c:80:40: error: 'real_coredump_elf32' undeclared (first use in this function); did you mean 'real_coredump_netbsd'?
	   80 |   MODULE_HOOK_SET(coredump_elf32_hook, real_coredump_elf32);
	      |                                        ^~~~~~~~~~~~~~~~~~~
	/build/netbsd-local/src/sys/kern/kern_core.c:80:40: note: each undeclared identifier is reported only once for each function it appears in
	/build/netbsd-local/src/sys/kern/kern_core.c:81:40: error: 'real_coredump_elf64' undeclared (first use in this function); did you mean 'real_coredump_netbsd'?
	   81 |   MODULE_HOOK_SET(coredump_elf64_hook, real_coredump_elf64);
	      |                                        ^~~~~~~~~~~~~~~~~~~
	*** [kern_core.o] Error code 1


	christos@ suggested adding the missing symbols to header file
	sys/sys/exec_elf.h but that breaks compilation of kern/kern_core.c

	...
	#   compile  coredump/kern_core.o
	... (gcc command line elided)
	In file included from /build/netbsd-local/src_ro/sys/sys/compat_stub.h:35,
	                 from /build/netbsd-local/src_ro/sys/kern/kern_core.c:53:
	/build/netbsd-local/src_ro/sys/kern/kern_core.c: In function 'coredump_modcmd':
	/build/netbsd-local/src_ro/sys/kern/kern_core.c:80:40: error: 'real_coredump_elf32' undeclared (first use in this function); did you mean 'real_coredump_netbsd'?
	   80 |   MODULE_HOOK_SET(coredump_elf32_hook, real_coredump_elf32);
	      |                                        ^~~~~~~~~~~~~~~~~~~
	/build/netbsd-local/src_ro/sys/kern/kern_core.c:80:40: note: each undeclared identifier is reported only once for each function it appears in
	/build/netbsd-local/src_ro/sys/kern/kern_core.c:81:40: error: 'real_coredump_elf64' undeclared (first use in this function); did you mean 'real_coredump_netbsd'?
	   81 |   MODULE_HOOK_SET(coredump_elf64_hook, real_coredump_elf64);
	      |                                        ^~~~~~~~~~~~~~~~~~~


	On my own initiative, I tried to #include <sys/exec_elf.h> in
	kern/kern_core.c but that results in a different compile error
	or kern/kern/core_elf32.c

	#   compile  coredump/core_elf32.o
	/build/netbsd-local/tools/x86_64/amd64/bin/x86_64--netbsd-gcc -O2 -g   -std=gnu99    -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-sign-compare  -Wsystem-headers   -Wno-traditional   -Wa,--fatal-warnings  -Wreturn-type -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter -Wno-sign-compare -Werror  -Wno-error=address-of-packed-member   -ffreestanding  -fno-strict-aliasing -Wno-pointer-sign -mno-red-zone -mno-mmx -mno-sse -mno-avx -msoft-float -mcmodel=kernel -fno-omit-frame-pointer   -I/build/netbsd-local/src_ro/common/include -DDIAGNOSTIC --sysroot=/build/netbsd-local/dest/amd64 -I/build/netbsd-local/src_ro/common/include -DDIAGNOSTIC  -nostdinc -I. -I/build/netbsd-local/src_ro/sys/modules/coredump -isystem /build/netbsd-local/src_ro/sys -isystem /build/netbsd-local/src_ro/sys/arch -isystem /build/netbsd-local/src_ro/sys/../common/include -D_KERNEL -D_MODULE -DSYSCTL_INCLUDE_DESCR -c    /build/netbsd-local/src_ro/sys/kern/core_elf
 32.c
	In file included from /build/netbsd-local/src_ro/sys/kern/core_elf32.c:42:
	/build/netbsd-local/src_ro/sys/kern/core_elf32.c: In function 'coredump_note_procinfo':
	/build/netbsd-local/src_ro/sys/kern/core_elf32.c:424:13: error: implicit declaration of function 'coredump_savenote_elf32'; did you mean 'coredump_note_elf32'? [-Werror=implicit-function-declaration]
	  424 |  ELFNAMEEND(coredump_savenote)(ns, ELF_NOTE_NETBSD_CORE_PROCINFO,
	      |             ^~~~~~~~~~~~~~~~~
	/build/netbsd-local/src_ro/sys/kern/core_elf32.c: In function 'coredump_note_elf32':
	/build/netbsd-local/src_ro/sys/kern/core_elf32.c:541:2: error: 'PT32_GETXSTATE' undeclared (first use in this function); did you mean 'PT64_GETXSTATE'?
	  541 |  COREDUMP_MACHDEP_LWP_NOTES(l, ns, d->name);
	      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~
	/build/netbsd-local/src_ro/sys/kern/core_elf32.c:541:2: note: each undeclared identifier is reported only once for each function it appears in
	/build/netbsd-local/src_ro/sys/kern/core_elf32.c: At top level:
	/build/netbsd-local/src_ro/sys/kern/core_elf32.c:583:12: error: no previous prototype for 'coredump_savenote_elf32' [-Werror=missing-prototypes]
	  583 | ELFNAMEEND(coredump_savenote)(struct note_state *ns, unsigned int type,
	      |            ^~~~~~~~~~~~~~~~~
	/build/netbsd-local/src_ro/sys/kern/core_elf32.c:583:12: error: conflicting types for 'coredump_savenote_elf32' [-Werror]
	/build/netbsd-local/src_ro/sys/kern/core_elf32.c:424:13: note: previous implicit declaration of 'coredump_savenote_elf32' was here
	  424 |  ELFNAMEEND(coredump_savenote)(ns, ELF_NOTE_NETBSD_CORE_PROCINFO,
	      |             ^~~~~~~~~~~~~~~~~
	cc1: all warnings being treated as errors
	*** [core_elf32.o] Error code 1



	[1] https://mail-index.netbsd.org/current-users/2020/10/17/msg039701.html

>How-To-Repeat:
	see above - build a kernel and modules with

		no options PTRACE
		no options COREDUMP
		no options EXEC_ELF32
		no options EXEC_ELF64
>Fix:
	unknown

>Audit-Trail:
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/55731 - (custom) kernel build failure with ``no options
 PTRACE''
Date: Tue, 20 Oct 2020 13:30:28 -0700 (PDT)

 ---------- Forwarded message ----------
 Date: Tue, 20 Oct 2020 10:39:27 -0700 (PDT)
 From: Paul Goyette <paul@whooppee.com>
 To: gnats@netbsd.org
 Subject: Re: kern/55731 - (custom) kernel build failure with ``no options
      PTRACE''

 (Log commit message to PR audit trail)


 Module Name:	src
 Committed By:	christos
 Date:		Mon Oct 19 19:33:02 UTC 2020

 Modified Files:
  	src/sys/arch/amd64/conf: MODULAR files.amd64
  	src/sys/kern: compat_stub.c core_elf32.c files.kern kern_core.c
  	    kern_sig.c
  	src/sys/modules/coredump: Makefile
  	src/sys/modules/exec_elf32: Makefile
  	src/sys/modules/exec_elf64: Makefile
  	src/sys/modules/ptrace_common: Makefile
  	src/sys/sys: compat_stub.h exec_elf.h
 Added Files:
  	src/sys/modules/ptrace_common: machdep.mk

 Log Message:
 Arrange so that no options COREDUMP and no options PTRACE work together.
 Thanks to Paul Goyette for testing.


 To generate a diff of this commit:
 cvs rdiff -u -r1.17 -r1.18 src/sys/arch/amd64/conf/MODULAR
 cvs rdiff -u -r1.117 -r1.118 src/sys/arch/amd64/conf/files.amd64
 cvs rdiff -u -r1.19 -r1.20 src/sys/kern/compat_stub.c
 cvs rdiff -u -r1.65 -r1.66 src/sys/kern/core_elf32.c
 cvs rdiff -u -r1.52 -r1.53 src/sys/kern/files.kern
 cvs rdiff -u -r1.30 -r1.31 src/sys/kern/kern_core.c
 cvs rdiff -u -r1.390 -r1.391 src/sys/kern/kern_sig.c
 cvs rdiff -u -r1.6 -r1.7 src/sys/modules/coredump/Makefile
 cvs rdiff -u -r1.5 -r1.6 src/sys/modules/exec_elf32/Makefile
 cvs rdiff -u -r1.4 -r1.5 src/sys/modules/exec_elf64/Makefile
 cvs rdiff -u -r1.3 -r1.4 src/sys/modules/ptrace_common/Makefile
 cvs rdiff -u -r0 -r1.1 src/sys/modules/ptrace_common/machdep.mk
 cvs rdiff -u -r1.23 -r1.24 src/sys/sys/compat_stub.h
 cvs rdiff -u -r1.167 -r1.168 src/sys/sys/exec_elf.h

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


 !DSPAM:5f8dea32273387311682910!

From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/55731 - (custom) kernel build failure with ``no options
 PTRACE''
Date: Tue, 20 Oct 2020 13:30:53 -0700 (PDT)

 ---------- Forwarded message ----------
 Date: Tue, 20 Oct 2020 10:40:59 -0700 (PDT)
 From: Paul Goyette <paul@whooppee.com>
 To: gnats@netbsd.org
 Subject: Re: kern/55731 - (custom) kernel build failure with ``no options
      PTRACE''

 (Log new failure info to PR audit trail)


 This still isn't quite correct.

 For i386, a custom kernel build fails.  Here's the diff between GENERIC
 and the custom config (this mirrors the config I used on amd64 to file
 the original PR kern/55731):

 --- GENERIC	2020-09-27 22:28:13.468056102 -0700
 +++ TEST	2020-10-20 07:41:41.302325022 -0700
 @@ -22,6 +22,17 @@

   options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary

 +# Remove standard options, as they are provided by modules
 +
 +no options 	EXEC_SCRIPT
 +no options 	EXEC_ELF32
 +no options 	COREDUMP
 +no options 	AIO
 +no options 	MQUEUE
 +no options 	SEMAPHORE
 +no options 	PTRACE
 +
 +
   #ident		"GENERIC-$Revision: 1.1233 $"

   maxusers	64		# estimated number of users
 @@ -120,7 +131,7 @@
   # Diagnostic/debugging support options
   options 	DIAGNOSTIC	# inexpensive kernel consistency checks
   				# XXX to be commented out on release branch
 -#options 	DEBUG		# expensive debugging checks/support
 +options 	DEBUG		# expensive debugging checks/support
   #options 	LOCKDEBUG	# expensive locking checks/support
   options 	DDB		# in-kernel debugger
   #options 	DDB_ONPANIC=1	# see also sysctl(7): `ddb.onpanic'


 Here's the build failure (with sources updated Tue Oct 20 14:02:24 UTC)

 ...
 #      link  TEST/netbsd
 /build/netbsd-compat/tools/x86_64/i386/bin/i486--netbsdelf-ld -Map netbsd.map 
 --cref -T netbsd.ldscript -Ttext c0100000 -e start -X -o netbsd 
 ${SYSTEM_OBJ:[@]:Nswapnetbsd.o} ${EXTRA_OBJ} vers.o swapnetbsd.o
 /build/netbsd-compat/tools/x86_64/i386/bin/i486--netbsdelf-ld: 
 process_machdep.o: in function `ptrace_machdep_dorequest':
 /build/netbsd-compat/src/sys/arch/i386/i386/process_machdep.c:298: undefined 
 reference to `ptrace_update_lwp'
 /build/netbsd-compat/tools/x86_64/i386/bin/i486--netbsdelf-ld: 
 /build/netbsd-compat/src/sys/arch/i386/i386/process_machdep.c:324: undefined 
 reference to `ptrace_update_lwp'
 /build/netbsd-compat/tools/x86_64/i386/bin/i486--netbsdelf-ld: procfs_fpregs.o: 
 in function `procfs_dofpregs':
 /build/netbsd-compat/src/sys/miscfs/procfs/procfs_fpregs.c:96: undefined 
 reference to `process_dofpregs'
 /build/netbsd-compat/tools/x86_64/i386/bin/i486--netbsdelf-ld: procfs_fpregs.o: 
 in function `procfs_validfpregs':
 /build/netbsd-compat/src/sys/miscfs/procfs/procfs_fpregs.c:103: undefined 
 reference to `process_validfpregs'
 /build/netbsd-compat/tools/x86_64/i386/bin/i486--netbsdelf-ld: procfs_regs.o: 
 in function `procfs_doregs':
 /build/netbsd-compat/src/sys/miscfs/procfs/procfs_regs.c:93: undefined 
 reference to `process_doregs'
 /build/netbsd-compat/tools/x86_64/i386/bin/i486--netbsdelf-ld: procfs_regs.o: 
 in function `procfs_validregs':
 /build/netbsd-compat/src/sys/miscfs/procfs/procfs_regs.c:100: undefined 
 reference to `process_validregs'
 *** [netbsd] Error code 1

 nbmake: stopped in /build/netbsd-compat/obj/i386/sys/arch/i386/compile/TEST
 1 error



 On Mon, 19 Oct 2020, Christos Zoulas wrote:

 > Module Name:	src
 > Committed By:	christos
 > Date:		Mon Oct 19 19:33:02 UTC 2020
 > 
 > Modified Files:
 > 	src/sys/arch/amd64/conf: MODULAR files.amd64
 > 	src/sys/kern: compat_stub.c core_elf32.c files.kern kern_core.c
 > 	    kern_sig.c
 > 	src/sys/modules/coredump: Makefile
 > 	src/sys/modules/exec_elf32: Makefile
 > 	src/sys/modules/exec_elf64: Makefile
 > 	src/sys/modules/ptrace_common: Makefile
 > 	src/sys/sys: compat_stub.h exec_elf.h
 > Added Files:
 > 	src/sys/modules/ptrace_common: machdep.mk
 > 
 > Log Message:
 > Arrange so that no options COREDUMP and no options PTRACE work together.
 > Thanks to Paul Goyette for testing.
 > 
 > 
 > To generate a diff of this commit:
 > cvs rdiff -u -r1.17 -r1.18 src/sys/arch/amd64/conf/MODULAR
 > cvs rdiff -u -r1.117 -r1.118 src/sys/arch/amd64/conf/files.amd64
 > cvs rdiff -u -r1.19 -r1.20 src/sys/kern/compat_stub.c
 > cvs rdiff -u -r1.65 -r1.66 src/sys/kern/core_elf32.c
 > cvs rdiff -u -r1.52 -r1.53 src/sys/kern/files.kern
 > cvs rdiff -u -r1.30 -r1.31 src/sys/kern/kern_core.c
 > cvs rdiff -u -r1.390 -r1.391 src/sys/kern/kern_sig.c
 > cvs rdiff -u -r1.6 -r1.7 src/sys/modules/coredump/Makefile
 > cvs rdiff -u -r1.5 -r1.6 src/sys/modules/exec_elf32/Makefile
 > cvs rdiff -u -r1.4 -r1.5 src/sys/modules/exec_elf64/Makefile
 > cvs rdiff -u -r1.3 -r1.4 src/sys/modules/ptrace_common/Makefile
 > cvs rdiff -u -r0 -r1.1 src/sys/modules/ptrace_common/machdep.mk
 > cvs rdiff -u -r1.23 -r1.24 src/sys/sys/compat_stub.h
 > cvs rdiff -u -r1.167 -r1.168 src/sys/sys/exec_elf.h
 > 
 > Please note that diffs are not public domain; they are subject to the
 > copyright notices on the relevant files.
 > 
 > 
 > 
 > 
 >

 +--------------------+--------------------------+-----------------------+
 | Paul Goyette       | PGP Key fingerprint:     | E-mail addresses:     |
 | (Retired)          | FA29 0E3B 35AF E8AE 6651 | paul@whooppee.com     |
 | Software Developer | 0786 F758 55DE 53BA 7731 | pgoyette@netbsd.org   |
 +--------------------+--------------------------+-----------------------+

 !DSPAM:5f8f17ea132927979820306!

From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/55731 - (custom) kernel build failure with ``no options  
   PTRACE''
Date: Tue, 20 Oct 2020 13:34:11 -0700 (PDT)

 Log commit to PR audit trail

 ---------- Forwarded message ----------
 Date: Tue, 20 Oct 2020 16:28:55 -0400
 From: Christos Zoulas <christos@netbsd.org>
 Reply-To: source-changes-d@NetBSD.org
 To: source-changes@NetBSD.org
 Subject: CVS commit: src/sys

 Module Name:	src
 Committed By:	christos
 Date:		Tue Oct 20 20:28:55 UTC 2020

 Modified Files:
  	src/sys/kern: sys_process_lwpstatus.c sys_ptrace_common.c
  	src/sys/sys: ptrace.h

 Log Message:
 Basic register read/write functionality and lwp setting are always provided
 by the kernel because they are needed by multiple things
 (ptrace/procfs/coredump), so move them to sys_process_lwpstatus (this file
 should be renamed to sys_process_common.c?)


 To generate a diff of this commit:
 cvs rdiff -u -r1.1 -r1.2 src/sys/kern/sys_process_lwpstatus.c
 cvs rdiff -u -r1.86 -r1.87 src/sys/kern/sys_ptrace_common.c
 cvs rdiff -u -r1.71 -r1.72 src/sys/sys/ptrace.h

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


 !DSPAM:5f8f48cd39541419215376!

From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/55731 - (custom) kernel build failure with ``no options
 PTRACE''
Date: Tue, 20 Oct 2020 13:45:28 -0700 (PDT)

 On Tue, 20 Oct 2020, Christos Zoulas wrote:

 > I fixed the ptrace part, but I think that the best way to fix the 
 > coredump_netbsd32 is to put it in its own module?

 Yeah, I think you're right.  I'll have a look at it sometime soon (and
 after I verify the latest commit).



 +--------------------+--------------------------+-----------------------+
 | Paul Goyette       | PGP Key fingerprint:     | E-mail addresses:     |
 | (Retired)          | FA29 0E3B 35AF E8AE 6651 | paul@whooppee.com     |
 | Software Developer | 0786 F758 55DE 53BA 7731 | pgoyette@netbsd.org   |
 +--------------------+--------------------------+-----------------------+

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.