From c2c83759541972610fd1dd0764e61b103596f42e Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 20 Oct 2004 23:03:05 +0000 Subject: [PATCH] Change the default handling for kernels built with debugging info (DEBUG=-g). Since GENERIC includes this make option, this applies to most kernels. Previously, installed kernels were stripped of their debug information and installed modules were not. With this commit, the debug info is left intact in the installed kernel and debug information is stripped from all backup copies that are made (kernel.old, modules.old). Developers using DEBUG=-g (which is most) may actually see root disk space go down due to the stripping of kernel.old and modules.old (-~30MB), even though /kernel will be +~13MB larger. Two new makeoptions are available for specification in your kernel config or when you run the buildkernel/nativekernel/installkernel target to make. INSTALLSTRIPPED=1 The installed kernel and modules will be stripped of debug info. This option effectively reverts you to the pre-commit state of things. INSTALLSTRIPPEDMODULES=1 The installed modules will be stripped of debug info. The kernel will be left with debug info intact. What this means is that developres will no longer have to stuff a debug kernel off somewhere to use later instead of a crash, savecore will copy a debuggable kernel into /var/crash instead of a stripped kernel, and snapshot and release CD's will have debug kernels and working crash dumps right out of the box. The memory impact of the debug kernel is zero since the debug info is not loaded, and the run-time impact of this change is also zero. The intention is multi-fold: * To make it easier for inexperienced users to provide meaningful debug info to developers when posting bug reports, especially during release cycles. * To not have to make copies of debug kernels for debugging purposes. Such copies often get out of sync with the actually running kernel and savecore does not know about them. * To make the debugging environment more uniform, less confusing, and easier to use. --- Makefile.inc1 | 28 +++++++++++++++-- sys/conf/Makefile.i386 | 71 +++++++++++++++++++++++++++++------------- sys/conf/kmod.mk | 9 +++++- sys/config/LINT | 10 +++++- sys/i386/conf/LINT | 10 +++++- 5 files changed, 100 insertions(+), 28 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index d3ac280c78..e7a3716331 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -1,6 +1,6 @@ # # $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $ -# $DragonFly: src/Makefile.inc1,v 1.39 2004/09/28 20:56:38 joerg Exp $ +# $DragonFly: src/Makefile.inc1,v 1.40 2004/10/20 23:02:59 dillon Exp $ # # Make command line options: # -DMAKE_KERBEROS5 to build Kerberos5 @@ -465,6 +465,12 @@ redistribute: # for building kernels and only the first of these is designated # as the one being installed. # +# You can specify INSTALLSTRIPPED=1 if you wish the installed +# kernel and modules to be stripped of its debug info (required +# symbols are left intact). You can specify INSTALLSTRIPPEDMODULES +# if you only want to strip the modules of their debug info. These +# only apply if you have DEBUG=-g in your kernel config or make line. +# # Note that we have to use TARGET instead of TARGET_ARCH when # we're in kernel-land. Since only TARGET_ARCH is (expected) to # be set to cross-build, we have to make sure TARGET is set @@ -505,7 +511,18 @@ bk_tools: echo "to build a kernel using native tools, config it manually"; \ echo "or use the nativekernel target if you are in a rush"; \ exit 1; \ - fi + fi + +maybe_bk_tools: +.for _kernel in ${BUILDKERNELS} + @if [ ! -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \ + if [ ! -f ${WORLDDEST}/.libraries_done ]; then \ + echo "The kernel was build using buildworld tools which no" ; \ + echo "longer appear to exist, quickkernel failed!" ; \ + exit 1; \ + fi; \ + fi +.endfor bk_build_list: .if empty(BUILDKERNELS) @@ -606,7 +623,7 @@ nativekernel: bk_build_list bk_kernwarn # nativekernel. Config is rerun but the object hierarchy is not rebuilt, # nor is the make depend step run. # -quickkernel: bk_tools bk_build_list bk_kernwarn +quickkernel: maybe_bk_tools bk_build_list bk_kernwarn .for _kernel in ${BUILDKERNELS} @echo "--------------------------------------------------------------" @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`" @@ -641,8 +658,13 @@ quickkernel: bk_tools bk_build_list bk_kernwarn # Install the kernel defined by INSTALLKERNEL # installkernel reinstallkernel: +.if exists(${KRNLOBJDIR}/${_kernel}/.buildkernel_run) cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \ ${CROSSENV} ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//} +.else + cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \ + ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//} +.endif # # update diff --git a/sys/conf/Makefile.i386 b/sys/conf/Makefile.i386 index 2567bbe046..bf282d1db6 100644 --- a/sys/conf/Makefile.i386 +++ b/sys/conf/Makefile.i386 @@ -2,7 +2,7 @@ # Copyright 1990 W. Jolitz # from: @(#)Makefile.i386 7.1 5/10/91 # $FreeBSD: src/sys/conf/Makefile.i386,v 1.179.2.16 2002/11/18 11:26:49 ru Exp $ -# $DragonFly: src/sys/conf/Attic/Makefile.i386,v 1.16 2004/08/13 17:51:05 dillon Exp $ +# $DragonFly: src/sys/conf/Attic/Makefile.i386,v 1.17 2004/10/20 23:03:02 dillon Exp $ # # Makefile for DragonFly BSD # @@ -16,6 +16,12 @@ # /sys/conf/Makefile.i386 # after which config should be rerun for all machines. # +# Makefile variables: +# -DINSTALLSTRIPPED If debug options are present, install a +# stripped kernel rather then the full debug +# kernel. +# +# -DDESTDIR Where to install, defaults to / # Which version of config(8) is required. %VERSREQ= 400021 @@ -113,22 +119,32 @@ SYSTEM_DEP+= $S/conf/ldscript.$M .PHONY: all modules -all: ${KERNEL} +all: ${KERNEL}.stripped depend: kernel-depend clean: kernel-clean cleandepend: kernel-cleandepend tags: kernel-tags -install install.debug: kernel-install -reinstall reinstall.debug: kernel-reinstall +install: kernel-install +reinstall: kernel-reinstall -.if !defined(DEBUG) -FULLKERNEL= ${KERNEL} -.else +# Normalize output files to make it absolutely crystal clear to +# anyone examining the build directory. +# +.if defined(DEBUG) FULLKERNEL= ${KERNEL}.debug -${KERNEL}: ${FULLKERNEL} - ${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL} +.if defined(INSTALLSTRIPPED) +SELECTEDKERNEL= ${KERNEL}.stripped +.else +SELECTEDKERNEL= ${KERNEL}.debug .endif +.else +FULLKERNEL= ${KERNEL}.nodebug +SELECTEDKERNEL= ${KERNEL}.stripped +.endif + +${KERNEL}.stripped: ${FULLKERNEL} + ${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL}.stripped ${FULLKERNEL}: ${SYSTEM_DEP} vers.o @rm -f ${.TARGET} @@ -147,8 +163,8 @@ ${mfile:T:S/.m$/.h/}: ${mfile} kernel-clean: rm -f *.o *.so *.So *.ko *.s eddep errs \ - ${FULLKERNEL} ${KERNEL} linterrs makelinks \ - setdef[01].c setdefs.h tags \ + ${KERNEL} ${KERNEL}.debug ${KERNEL}.nodebug ${KERNEL}.stripped \ + linterrs makelinks setdef[01].c setdefs.h tags \ vers.c vnode_if.c vnode_if.h \ ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \ ${CLEAN} @@ -211,21 +227,24 @@ kernel-tags: rm -f tags1 sed -e 's, ../, ,' tags > tags1 -kernel-install kernel-install.debug: - @if [ ! -f ${KERNEL}${.TARGET:S/kernel-install//} ] ; then \ +# Note: when moving the existing kernel to .old, make sure it is stripped +# so we do not have two full debug environments sitting in / eating up space. +# +kernel-install: + @if [ ! -f ${SELECTEDKERNEL} ] ; then \ echo "You must build a kernel first." ; \ exit 1 ; \ fi .if exists(${DESTDIR}/${KERNEL}) -chflags noschg ${DESTDIR}/${KERNEL} - mv ${DESTDIR}/${KERNEL} ${DESTDIR}/${KERNEL}.old + ${OBJCOPY} --strip-debug ${DESTDIR}/${KERNEL} ${DESTDIR}/${KERNEL}.old .endif ${INSTALL} -m 555 -o root -g wheel -fschg \ - ${KERNEL}${.TARGET:S/kernel-install//} ${DESTDIR}/${KERNEL} + ${SELECTEDKERNEL} ${DESTDIR}/${KERNEL} -kernel-reinstall kernel-reinstall.debug: +kernel-reinstall: ${INSTALL} -m 555 -o root -g wheel -fschg \ - ${KERNEL}${.TARGET:S/kernel-reinstall//} ${DESTDIR}/${KERNEL} + ${SELECTEDKERNEL} ${DESTDIR}/${KERNEL} .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) all: modules @@ -234,8 +253,8 @@ clean: modules-clean cleandepend: modules-cleandepend cleandir: modules-cleandir tags: modules-tags -install install.debug: modules-install -reinstall reinstall.debug: modules-reinstall +install: modules-install +reinstall: modules-reinstall .endif MKMODULESENV= MAKEOBJDIRPREFIX=${.OBJDIR} @@ -245,6 +264,9 @@ MKMODULESENV+= MODULES_OVERRIDE="${MODULES_OVERRIDE}" .if defined(DEBUG) MKMODULESENV+= DEBUG="${DEBUG}" DEBUG_FLAGS="${DEBUG}" .endif +.if defined(INSTALLSTRIPPED) || defined(INSTALLSTRIPPEDMODULES) +MKMODULESENV+= INSTALLSTRIPPEDMODULES=1 +.endif MKMODULESENV+= MACHINE=i386 modules: @@ -273,16 +295,21 @@ modules-cleandir: modules-tags: cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules tags -modules-install modules-install.debug: +# Note: when moving the existing modules to .old, make sure they are stripped +# so we do not have two full debug environments sitting in / eating up space. +# +modules-install: .if !defined(NO_MODULES_OLD) if [ -d ${DESTDIR}/modules -a -n "`ls ${DESTDIR}/modules`" ]; then \ mkdir -p ${DESTDIR}/modules.old; \ - cp -p ${DESTDIR}/modules/* ${DESTDIR}/modules.old; \ + for file in ${DESTDIR}/modules/*; do \ + ${OBJCOPY} --strip-debug $$file ${DESTDIR}/modules.old/$${file##*/}; \ + done; \ fi; .endif cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install -modules-reinstall modules-reinstall.debug: +modules-reinstall: cd $S ; env ${MKMODULESENV} ${MAKE} -f Makefile.modules install config.o: diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk index 10f4f056bd..985223374f 100644 --- a/sys/conf/kmod.mk +++ b/sys/conf/kmod.mk @@ -1,6 +1,6 @@ # From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 # $FreeBSD: src/sys/conf/kmod.mk,v 1.82.2.15 2003/02/10 13:11:50 nyan Exp $ -# $DragonFly: src/sys/conf/kmod.mk,v 1.16 2004/08/17 18:57:30 dillon Exp $ +# $DragonFly: src/sys/conf/kmod.mk,v 1.17 2004/10/20 23:03:02 dillon Exp $ # # The include file handles installing Kernel Loadable Device # drivers (KLD's). @@ -58,6 +58,7 @@ # bsd.man.mk: maninstall # +OBJCOPY?= objcopy KMODLOAD?= /sbin/kldload KMODUNLOAD?= /sbin/kldunload @@ -185,8 +186,14 @@ _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} realinstall: _kmodinstall .ORDER: beforeinstall _kmodinstall _kmodinstall: +.if defined(INSTALLSTRIPPEDMODULES) ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} + ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG} +.else + ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ + ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} +.endif .endif !target(realinstall) .include diff --git a/sys/config/LINT b/sys/config/LINT index 462dfb06e9..7f1f6fa6b6 100644 --- a/sys/config/LINT +++ b/sys/config/LINT @@ -3,7 +3,7 @@ # as much of the source tree as it can. # # $FreeBSD: src/sys/i386/conf/LINT,v 1.749.2.144 2003/06/04 17:56:59 sam Exp $ -# $DragonFly: src/sys/config/LINT,v 1.39 2004/09/26 01:52:48 dillon Exp $ +# $DragonFly: src/sys/config/LINT,v 1.40 2004/10/20 23:03:05 dillon Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -51,11 +51,19 @@ maxusers 10 # # MODULES_OVERRIDE can be used to limit modules built to a specific list. # +# INSTALLSTRIPPED can be set to cause installkernel to install stripped +# kernels and modules rather than a kernel and modules with debug symbols. +# +# INSTALLSTRIPPEDMODULES can be set to allow a full debug kernel to be +# installed, but to strip the installed modules. +# makeoptions CONF_CFLAGS=-fno-builtin #Don't allow use of memcmp, etc. #makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols #makeoptions KERNEL=foo #Build kernel "foo" and install "/foo" # Only build Linux API modules and plus those parts of the sound system I need. #makeoptions MODULES_OVERRIDE="linux sound/snd sound/pcm sound/driver/maestro3" +#makeoptions INSTALLSTRIPPED=1 +#makeoptions INSTALLSTRIPPEDMODULES=1 # # Certain applications can grow to be larger than the 128M limit diff --git a/sys/i386/conf/LINT b/sys/i386/conf/LINT index bcf6710c8a..cbc471a61f 100644 --- a/sys/i386/conf/LINT +++ b/sys/i386/conf/LINT @@ -3,7 +3,7 @@ # as much of the source tree as it can. # # $FreeBSD: src/sys/i386/conf/LINT,v 1.749.2.144 2003/06/04 17:56:59 sam Exp $ -# $DragonFly: src/sys/i386/conf/Attic/LINT,v 1.39 2004/09/26 01:52:48 dillon Exp $ +# $DragonFly: src/sys/i386/conf/Attic/LINT,v 1.40 2004/10/20 23:03:05 dillon Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -51,11 +51,19 @@ maxusers 10 # # MODULES_OVERRIDE can be used to limit modules built to a specific list. # +# INSTALLSTRIPPED can be set to cause installkernel to install stripped +# kernels and modules rather than a kernel and modules with debug symbols. +# +# INSTALLSTRIPPEDMODULES can be set to allow a full debug kernel to be +# installed, but to strip the installed modules. +# makeoptions CONF_CFLAGS=-fno-builtin #Don't allow use of memcmp, etc. #makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols #makeoptions KERNEL=foo #Build kernel "foo" and install "/foo" # Only build Linux API modules and plus those parts of the sound system I need. #makeoptions MODULES_OVERRIDE="linux sound/snd sound/pcm sound/driver/maestro3" +#makeoptions INSTALLSTRIPPED=1 +#makeoptions INSTALLSTRIPPEDMODULES=1 # # Certain applications can grow to be larger than the 128M limit -- 2.41.0