Module Name:    src
Committed By:   mrg
Date:           Mon May  6 08:43:37 UTC 2024

Modified Files:
        src/share/mk: bsd.kmodule.mk bsd.lib.mk bsd.prog.mk
        src/sys/conf: Makefile.kern.inc

Log Message:
use objcopy's --compress-debug-sections when creating debug files.

this reduces the size of the installed files by over half in most cases,
though the debug set size doesn't really change much (which looks like
close to 1GB of space on amd64 with xdebug installed, similar on arm64,
and about 600MB without xdebug.)

tested by running GDB on a few things, seems just as functional, on amd64,
arm64, and slightly on riscv64.

(first attempt for this feature used "gcc -gz=zlib", but that ends up
making CTF unhappy, but fortunately this works in binutils to create
the .debug files separate to any ctf usage of the main file.)


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/share/mk/bsd.kmodule.mk
cvs rdiff -u -r1.402 -r1.403 src/share/mk/bsd.lib.mk
cvs rdiff -u -r1.348 -r1.349 src/share/mk/bsd.prog.mk
cvs rdiff -u -r1.300 -r1.301 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/share/mk/bsd.kmodule.mk
diff -u src/share/mk/bsd.kmodule.mk:1.84 src/share/mk/bsd.kmodule.mk:1.85
--- src/share/mk/bsd.kmodule.mk:1.84	Sat Jun  3 21:26:28 2023
+++ src/share/mk/bsd.kmodule.mk	Mon May  6 08:43:37 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.kmodule.mk,v 1.84 2023/06/03 21:26:28 lukem Exp $
+#	$NetBSD: bsd.kmodule.mk,v 1.85 2024/05/06 08:43:37 mrg Exp $
 
 # We are not building this with PIE
 MKPIE=no
@@ -191,7 +191,8 @@ ${PROG}: ${OBJS} ${DPADD} ${KMODSCRIPT}
 .if defined(PROGDEBUG)
 ${PROGDEBUG}: ${PROG}
 	${_MKTARGET_CREATE}
-	(  ${OBJCOPY} --only-keep-debug ${PROG} ${PROGDEBUG} \
+	( ${OBJCOPY} --only-keep-debug --compress-debug-sections \
+	    ${PROG} ${PROGDEBUG} \
 	&& ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
 		--add-gnu-debuglink=${PROGDEBUG} ${PROG} \
 	) || (rm -f ${PROGDEBUG}; false)

Index: src/share/mk/bsd.lib.mk
diff -u src/share/mk/bsd.lib.mk:1.402 src/share/mk/bsd.lib.mk:1.403
--- src/share/mk/bsd.lib.mk:1.402	Thu Apr 11 19:12:11 2024
+++ src/share/mk/bsd.lib.mk	Mon May  6 08:43:37 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.lib.mk,v 1.402 2024/04/11 19:12:11 christos Exp $
+#	$NetBSD: bsd.lib.mk,v 1.403 2024/05/06 08:43:37 mrg Exp $
 #	@(#)bsd.lib.mk	8.3 (Berkeley) 4/22/94
 
 .include <bsd.init.mk>
@@ -621,15 +621,15 @@ _MAINLIBDEPS=	${SOLIB} ${DPADD} ${DPLIBC
 .if defined(_LIB.so.debug)
 ${_LIB.so.debug}: ${_LIB.so.link}
 	${_MKTARGET_CREATE}
-	(  ${OBJCOPY} --only-keep-debug \
-		${_LIB.so.link} ${_LIB.so.debug} \
+	( ${OBJCOPY} --only-keep-debug --compress-debug-sections \
+	    ${_LIB.so.link} ${_LIB.so.debug} \
 	) || (rm -f ${.TARGET}; false)
 ${_LIB.so.full}: ${_LIB.so.link} ${_LIB.so.debug}
 	${_MKTARGET_CREATE}
 	(  ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
-		--add-gnu-debuglink=${_LIB.so.debug} \
-		${_LIB.so.link} ${_LIB.so.full}.tmp && \
-		${MV} ${_LIB.so.full}.tmp ${_LIB.so.full} \
+	    --add-gnu-debuglink=${_LIB.so.debug} \
+	    ${_LIB.so.link} ${_LIB.so.full}.tmp && \
+	    ${MV} ${_LIB.so.full}.tmp ${_LIB.so.full} \
 	) || (rm -f ${.TARGET}; false)
 ${_LIB.so.link}: ${_MAINLIBDEPS}
 .else # aka no MKDEBUG

Index: src/share/mk/bsd.prog.mk
diff -u src/share/mk/bsd.prog.mk:1.348 src/share/mk/bsd.prog.mk:1.349
--- src/share/mk/bsd.prog.mk:1.348	Mon Feb 19 20:39:38 2024
+++ src/share/mk/bsd.prog.mk	Mon May  6 08:43:37 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.prog.mk,v 1.348 2024/02/19 20:39:38 christos Exp $
+#	$NetBSD: bsd.prog.mk,v 1.349 2024/05/06 08:43:37 mrg Exp $
 #	@(#)bsd.prog.mk	8.2 (Berkeley) 4/2/94
 
 .ifndef HOSTPROG
@@ -506,8 +506,9 @@ ${_P}.ro: ${OBJS.${_P}} ${_DPADD.${_P}}
 .if defined(_PROGDEBUG.${_P})
 ${_PROGDEBUG.${_P}}: ${_P}
 	${_MKTARGET_CREATE}
-	(  ${OBJCOPY} --only-keep-debug ${_P} ${_PROGDEBUG.${_P}} \
-	&& ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
+	( ${OBJCOPY} --only-keep-debug --compress-debug-sections \
+	    ${_P} ${_PROGDEBUG.${_P}} && \
+	  ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
 		--add-gnu-debuglink=${_PROGDEBUG.${_P}} ${_P} \
 	) || (rm -f ${_PROGDEBUG.${_P}}; false)
 .endif

Index: src/sys/conf/Makefile.kern.inc
diff -u src/sys/conf/Makefile.kern.inc:1.300 src/sys/conf/Makefile.kern.inc:1.301
--- src/sys/conf/Makefile.kern.inc:1.300	Sun Jan 14 00:39:10 2024
+++ src/sys/conf/Makefile.kern.inc	Mon May  6 08:43:36 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.kern.inc,v 1.300 2024/01/14 00:39:10 gutteridge Exp $
+#	$NetBSD: Makefile.kern.inc,v 1.301 2024/05/06 08:43:36 mrg Exp $
 #
 # This file contains common `MI' targets and definitions and it is included
 # at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}.
@@ -264,7 +264,8 @@ SYSTEM_LD_TAIL+= && ${TOOL_SED} \
 
 SYSTEM_LD_TAIL_DEBUG?=&& \
 	runit mv -f $@ $@.gdb && \
-	runit ${OBJCOPY} --only-keep-debug $@.gdb $@-${KERNEL_CONFIG}.debug && \
+	runit ${OBJCOPY} --only-keep-debug --compress-debug-sections \
+	    $@.gdb $@-${KERNEL_CONFIG}.debug && \
 	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