Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Dec 2012 16:08:47 +0000
From:      Ed Maste <emaste@freebsd.org>
To:        freebsd-hackers@freebsd.org
Subject:   [PATCH] Shared library debug .symbols files
Message-ID:  <20121213160847.GA78448@sandvine.com>

next in thread | raw e-mail | index | archive | help
I've been working generating userland debugging symbols, with the goal
that we'll build them for each release.  The user could install them
along with the system, or later on when needed for debugging.  The
symbols files will also be useful for profiling and tools such as
Valgrind, without needing to build and install world first.

This patch enables .symbols files for shared libraries when DEBUG_FLAGS
is set.  Future changes will be needed to address static libraries and
base system binaries, and the release build bits.

This is a different approach to the patches Mark Johnston posted to 
-hackers about two years ago.  I've followed the example of kmod.mk in
generating a .debug file which is split into the two components with
objcopy at build time.  (Mark's patch overloaded strip to do it at
install time.)

Note that I used --strip-all and not --strip-debug, as the latter
results in duplication in the symtab and strtab between the shared lib
and its .symbols file.

diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
index 2c96df1..6a1b476 100644
--- a/share/mk/bsd.lib.mk
+++ b/share/mk/bsd.lib.mk
@@ -34,14 +34,13 @@ NO_WERROR=
 .endif
 
 .if defined(DEBUG_FLAGS)
+OBJCOPY?=	objcopy
 CFLAGS+= ${DEBUG_FLAGS}
 
 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
 CTFFLAGS+= -g
 .endif
-.endif
-
-.if !defined(DEBUG_FLAGS)
+.else
 STRIP?=	-s
 .endif
 
@@ -173,14 +172,17 @@ SOLINKOPTS+=	-Wl,--fatal-warnings -Wl,--warn-shared-textrel
 .endif
 
 .if target(beforelinking)
-${SHLIB_NAME}: ${SOBJS} beforelinking
+${SHLIB_NAME}: beforelinking
+.endif
+.if defined(DEBUG_FLAGS)
+${SHLIB_NAME}.debug: ${SOBJS}
 .else
 ${SHLIB_NAME}: ${SOBJS}
 .endif
 	@${ECHO} building shared library ${SHLIB_NAME}
-	@rm -f ${.TARGET} ${SHLIB_LINK}
+	@rm -f ${.SHLIB_NAME} ${SHLIB_LINK}
 .if defined(SHLIB_LINK)
-	@ln -fs ${.TARGET} ${SHLIB_LINK}
+	@ln -fs ${.SHLIB_NAME} ${SHLIB_LINK}
 .endif
 .if !defined(NM)
 	@${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
@@ -194,6 +196,15 @@ ${SHLIB_NAME}: ${SOBJS}
 .if ${MK_CTF} != "no"
 	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
 .endif
+
+.if defined(DEBUG_FLAGS)
+${SHLIB_NAME}: ${SHLIB_NAME}.debug ${SHLIB_NAME}.symbols
+	${OBJCOPY} --strip-all --add-gnu-debuglink=${SHLIB_NAME}.symbols\
+	    ${SHLIB_NAME}.debug ${.TARGET}
+
+${SHLIB_NAME}.symbols:
+	${OBJCOPY} --only-keep-debug ${SHLIB_NAME}.debug ${.TARGET}
+.endif
 .endif
 
 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
@@ -270,6 +281,11 @@ _libinstall:
 	${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
 	    ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
 	    ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
+.if defined(DEBUG_FLAGS)
+	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+	    ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
+	    ${SHLIB_NAME}.symbols ${DESTDIR}${SHLIBDIR}
+.endif
 .if defined(SHLIB_LINK)
 # ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building
 # and when building 32 bits library shims.  ${_SHLIBDIRPREFIX} is the directory



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20121213160847.GA78448>