Module Name:    src
Committed By:   rin
Date:           Wed Jul 26 03:39:56 UTC 2023

Modified Files:
        src/sys/arch/aarch64/conf: Makefile.aarch64
        src/sys/arch/arm/conf: Makefile.arm
        src/sys/conf: Makefile.kern.inc

Log Message:
Fix kernel size inflation for arm and aarch64 (PR toolchain/57146)

For some conditions, SYSTEM_LD_TAIL is set for arm and aarch64.
Then, ctfmerge(1) in default SYSTEM_LD_TAIL is unintentionally
skipped, which results in the catastrophic kernel size inflation,
as reported in the PR.

Also, introduce and use OBJCOPY_STRIPFLAGS variable instead of
STRIPFLAGS, as strip(1) is replaced by objcopy(1) during MI
kernel build procedure.

XXX
For Makefile.{arm,aarch64}, weird logic is used to determine how
to handle debug symbols; MKDEBUG{,KERNEL} are taken into account
later in sys/conf/Makefile.kern.inc.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/aarch64/conf/Makefile.aarch64
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/arm/conf/Makefile.arm
cvs rdiff -u -r1.297 -r1.298 src/sys/conf/Makefile.kern.inc

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

Modified files:

Index: src/sys/arch/aarch64/conf/Makefile.aarch64
diff -u src/sys/arch/aarch64/conf/Makefile.aarch64:1.23 src/sys/arch/aarch64/conf/Makefile.aarch64:1.24
--- src/sys/arch/aarch64/conf/Makefile.aarch64:1.23	Thu May 27 06:19:38 2021
+++ src/sys/arch/aarch64/conf/Makefile.aarch64	Wed Jul 26 03:39:55 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.aarch64,v 1.23 2021/05/27 06:19:38 ryo Exp $
+#	$NetBSD: Makefile.aarch64,v 1.24 2023/07/26 03:39:55 rin Exp $
 
 # Makefile for NetBSD
 #
@@ -95,13 +95,14 @@ LOADADDRESS?=	0xffffc00000000000
 LINKFLAGS_NORMAL=	-X
 
 # Strip AArch64 mapping symbols from the kernel image, as they interfere
-# with ddb. Do it differently if 'makeoptions DEBUG="-g"' was specified.
-.if !defined(DEBUG) || empty(DEBUG:M-g*)
-SYSTEM_LD_TAIL?=	${OBJCOPY} -w --strip-symbol='[$$][dx]'	\
-				   --strip-symbol='[$$][dx]\.*' $@ ;\
-			${SIZE} $@; chmod 755 $@
+# with ddb, but don't strip them in netbsd.gdb.
+AA64_STRIP_SYMBOLS=	--strip-symbol='[$$][dx]' \
+			--strip-symbol='[$$][dx]\.*'
+.if (defined(DEBUG) && !empty(DEBUG:M-g*)) || (!defined(DEBUG) && \
+	(${MKDEBUGKERNEL:Uno} == "yes" || ${MKDEBUG:Uno} == "yes"))
+OBJCOPY_STRIPFLAGS=	-g -w ${AA64_STRIP_SYMBOLS}
 .else
-STRIPFLAGS=-g --strip-symbol='$$x' --strip-symbol='$$d'
+SYSTEM_LD_TAIL=		@${OBJCOPY} -w ${AA64_STRIP_SYMBOLS} $@
 .endif
 
 ##

Index: src/sys/arch/arm/conf/Makefile.arm
diff -u src/sys/arch/arm/conf/Makefile.arm:1.55 src/sys/arch/arm/conf/Makefile.arm:1.56
--- src/sys/arch/arm/conf/Makefile.arm:1.55	Fri Jul 10 12:25:09 2020
+++ src/sys/arch/arm/conf/Makefile.arm	Wed Jul 26 03:39:55 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.arm,v 1.55 2020/07/10 12:25:09 skrll Exp $
+#	$NetBSD: Makefile.arm,v 1.56 2023/07/26 03:39:55 rin Exp $
 
 # Makefile for NetBSD
 #
@@ -106,14 +106,14 @@ locore.o: ${ARM}/arm32/locore.S assym.h
 LOADADDRESS?=	0xF0000000
 LINKFLAGS_NORMAL=	-X
 # Strip ARM mapping symbols from the kernel image, as they interfere
-# with ddb. Do it differently if 'makeoptions DEBUG="-g"' was specified.
-.if !defined(DEBUG) || empty(DEBUG:M-g*)
-SYSTEM_LD_TAIL?=	${OBJCOPY} --wildcard --strip-symbol='[$$][atd]' \
-				    --strip-symbol='[$$][atd]\.*' $@;   \
-			${SIZE} $@; chmod 755 $@
+# with ddb, but don't strip them in netbsd.gdb.
+ARM_STRIP_SYMBOLS=	--strip-symbol='[$$][atd]' \
+			--strip-symbol='[$$][atd]\.*'
+.if (defined(DEBUG) && !empty(DEBUG:M-g*)) || (!defined(DEBUG) && \
+	(${MKDEBUGKERNEL:Uno} == "yes" || ${MKDEBUG:Uno} == "yes"))
+OBJCOPY_STRIPFLAGS=	-g -w ${ARM_STRIP_SYMBOLS}
 .else
-STRIPFLAGS=-g --wildcard --strip-symbol='[$$][atd]' \
-	   --strip-symbol='[$$][atd]\.*'
+SYSTEM_LD_TAIL=		@${OBJCOPY} -w ${ARM_STRIP_SYMBOLS} $@
 .endif
 
 ##

Index: src/sys/conf/Makefile.kern.inc
diff -u src/sys/conf/Makefile.kern.inc:1.297 src/sys/conf/Makefile.kern.inc:1.298
--- src/sys/conf/Makefile.kern.inc:1.297	Sat Jun  3 21:26:29 2023
+++ src/sys/conf/Makefile.kern.inc	Wed Jul 26 03:39:55 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.kern.inc,v 1.297 2023/06/03 21:26:29 lukem Exp $
+#	$NetBSD: Makefile.kern.inc,v 1.298 2023/07/26 03:39:55 rin Exp $
 #
 # This file contains common `MI' targets and definitions and it is included
 # at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}.
@@ -245,14 +245,17 @@ LINKFLAGS?=	${LINKFORMAT} ${LINKSCRIPT} 
 LINKFLAGS_DEBUG?=	-X
 KERNEL_CONFIG?=	${KERNEL_BUILD:T}
 
-SYSTEM_LD_TAIL?=@${TOOL_SED} '/const char sccs/!d;s/.*@(.)//;s/" "//;s/\\.*//' vers.c && \
+SYSTEM_LD_TAIL?= @${_MKSHECHO}
+SYSTEM_LD_TAIL+= && ${TOOL_SED} '/const char sccs/!d;s/.*@(.)//;s/" "//;s/\\.*//' vers.c && \
 		${SIZE} $@ && ${SYSTEM_CTFMERGE} && chmod 755 $@
 SYSTEM_LD_TAIL+= && runit() { echo $$@; $$@; }
 
+OBJCOPY_STRIPFLAGS?= -g
+
 SYSTEM_LD_TAIL_DEBUG?=&& \
 	runit mv -f $@ $@.gdb && \
 	runit ${OBJCOPY} --only-keep-debug $@.gdb $@-${KERNEL_CONFIG}.debug && \
-	runit ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
+	runit ${OBJCOPY} ${OBJCOPY_STRIPFLAGS} -p -R .gnu_debuglink \
 	    --add-gnu-debuglink=$@-${KERNEL_CONFIG}.debug $@.gdb $@ && \
 	runit chmod 755 $@ $@.gdb $@-${KERNEL_CONFIG}.debug
 

Reply via email to