From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 13 16:08:48 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 274D810C for ; Thu, 13 Dec 2012 16:08:48 +0000 (UTC) (envelope-from emaste@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 0180F8FC18 for ; Thu, 13 Dec 2012 16:08:48 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id qBDG8l3A078469 for ; Thu, 13 Dec 2012 16:08:47 GMT (envelope-from emaste@freebsd.org) Received: (from emaste@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id qBDG8l5K078468 for freebsd-hackers@freebsd.org; Thu, 13 Dec 2012 16:08:47 GMT (envelope-from emaste@freebsd.org) X-Authentication-Warning: freefall.freebsd.org: emaste set sender to emaste@freebsd.org using -f Date: Thu, 13 Dec 2012 16:08:47 +0000 From: Ed Maste To: freebsd-hackers@freebsd.org Subject: [PATCH] Shared library debug .symbols files Message-ID: <20121213160847.GA78448@sandvine.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Dec 2012 16:08:48 -0000 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