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.)
pull/37/head
mrg 2024-05-06 08:43:36 +00:00
parent 465b033192
commit b1d1e928c0
4 changed files with 16 additions and 13 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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