From: Andrew Deason Date: Thu, 6 Sep 2018 18:42:11 +0000 (-0500) Subject: Run ctfconvert/ctfmerge for all objects X-Git-Tag: openafs-devel-1_9_0~429 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=c1d39153da00d5525b2f7874b2d214a7f1b1bb86 Run ctfconvert/ctfmerge for all objects Commit 88cb536f (autoconf: detect ctf-tools and add ctf to libafs) introduced running ctfconvert and ctfmerge for libafs on Solaris, but didn't add any CTF data for userspace code. This commit causes the same commands to be run for every binary that we build (if the ctf tools are available). To accomplish this, also refactor how we run ctfconvert and ctfmerge. The approach in commit 88cb536f would require us to modify the makefile rule for every executable to run RUN_CTFCONVERT and RUN_CTFMERGE, which is somewhat impractical. So instead in this commit, we modify all of our *_CCRULE and *_LDRULE variables to wrap the compiler invocation with the new CC_WRAPPER script. This means our *RULE variables change from something like this: FOO_CCRULE = $(RUN_CC) $(CC) $(XXX_FLAGS) -o $@ to something like this: FOO_CCRULE = $(RUN_CC) $(CC_WRAPPER) $(CC) $(XXX_FLAGS) -o $@ CC_WRAPPER expands to the script src/config/cc-wrapper, which just runs ctfconvert or ctfmerge on the relevant files after the compiler/linker runs. If the CTF tools are not configured, CC_WRAPPER expands to nothing, to limit our impact on other platforms. This commit was developed in collaboration with mbarbosa@sinenomine.net. Change-Id: Id19ba9d739edc68f01c2db7d5caa20758ec8144a Reviewed-on: https://gerrit.openafs.org/13308 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- diff --git a/configure.ac b/configure.ac index ed47861..3fa4038 100644 --- a/configure.ac +++ b/configure.ac @@ -88,6 +88,7 @@ AC_CONFIG_FILES([ src/config/Makefile.pthread src/config/Makefile.version-CML src/config/Makefile.version-NOCML + src/config/cc-wrapper src/config/shlib-build src/config/shlib-install src/crypto/hcrypto/Makefile @@ -201,7 +202,8 @@ AC_CONFIG_FILES([ tests/util/Makefile tests/volser/Makefile]) AC_CONFIG_COMMANDS([default],[chmod a+x src/config/shlib-build - chmod a+x src/config/shlib-install],[]) + chmod a+x src/config/shlib-install + chmod a+x src/config/cc-wrapper],[]) AC_OUTPUT # print a final summary diff --git a/src/cf/ctf-tools.m4 b/src/cf/ctf-tools.m4 index 3410214..955078a 100644 --- a/src/cf/ctf-tools.m4 +++ b/src/cf/ctf-tools.m4 @@ -25,6 +25,14 @@ AS_CASE([$CTF_TOOLS], AS_IF([test "x$CTFMERGE" = "x"], [AC_MSG_ERROR("ctfmerge not found")])] ) +CC_WRAPPER= +LD_WRAPPER= +AS_IF([test x"$CTFCONVERT" != x && test x"$CTFMERGE" != x], + [CC_WRAPPER="$TOP_SRCDIR/config/cc-wrapper cc" + LD_WRAPPER="$TOP_SRCDIR/config/cc-wrapper ld"]) +AC_SUBST([CC_WRAPPER]) +AC_SUBST([LD_WRAPPER]) + AC_ARG_VAR([CTFCONVERT], [Path to ctfconvert]) AC_ARG_VAR([CTFMERGE], [Path to ctfmerge]) ]) diff --git a/src/config/.gitignore b/src/config/.gitignore index 62ebae6..9a3d953 100644 --- a/src/config/.gitignore +++ b/src/config/.gitignore @@ -14,6 +14,7 @@ /Makefile.version-CML /afsconfig.h /afsconfig.h.in +/cc-wrapper /config /mkvers /param.h.new diff --git a/src/config/Makefile.config.in b/src/config/Makefile.config.in index 87bf73d..f29d64d 100644 --- a/src/config/Makefile.config.in +++ b/src/config/Makefile.config.in @@ -152,6 +152,8 @@ KERNELDIR = ../libafs # # Build helper apps # +CC_WRAPPER = @CC_WRAPPER@ +LD_WRAPPER = @LD_WRAPPER@ COMPILE_ET = @COMPILE_ET_PATH@ CONFIGTOOL = @CONFIGTOOL_PATH@ RXGEN = @RXGEN_PATH@ @@ -229,24 +231,24 @@ COMMON_LDFLAGS=$(LDFLAGS) $(LDFLAGS_hcrypto) $(LDFLAGS_roken) $(DBG) $(OPTMZ) # LWP Flags LWP_CFLAGS=$(MODULE_CFLAGS) $(COMMON_CFLAGS) LWP_LDFLAGS=$(MODULE_LDFLAGS) $(COMMON_LDFLAGS) $(XLDFLAGS) $(ARCHFLAGS) -LWP_CCRULE =$(RUN_CC) $(CCOBJ) $(CPPFLAGS_$(@)) $(LWP_CFLAGS) $(CFLAGS_$(@)) -o $@ -c -LWP_CCRULE_NOQ=$(RUN_CC_NOQ) $(CCOBJ) $(CPPFLAGS_$(@)) $(LWP_CFLAGS) $(CFLAGS_$(@)) -o $@ -c +LWP_CCRULE =$(RUN_CC) $(CC_WRAPPER) $(CCOBJ) $(CPPFLAGS_$(@)) $(LWP_CFLAGS) $(CFLAGS_$(@)) -o $@ -c +LWP_CCRULE_NOQ=$(RUN_CC_NOQ) $(CC_WRAPPER) $(CCOBJ) $(CPPFLAGS_$(@)) $(LWP_CFLAGS) $(CFLAGS_$(@)) -o $@ -c # Pthreaded PTH_CFLAGS=$(MODULE_CFLAGS) $(COMMON_CFLAGS) $(MT_CFLAGS) PTH_LDFLAGS=$(MODULE_LDFLAGS) $(COMMON_LDFLAGS) $(MT_LDFLAGS) -PTH_CCRULE =$(RUN_CC) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c -PTH_CCRULE_NOQ=$(RUN_CC_NOQ) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c +PTH_CCRULE =$(RUN_CC) $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c +PTH_CCRULE_NOQ=$(RUN_CC_NOQ) $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c # Shared SHD_CFLAGS=$(MODULE_CFLAGS) $(COMMON_CFLAGS) $(MT_CFLAGS) $(SHLIB_CFLAGS) SHD_LDFLAGS=$(MODULE_LDFLAGS) $(COMMON_LDFLAGS) $(SHLIB_LDFLAGS) -SHD_CCRULE =$(RUN_CC) $(MT_CC) $(CPPFLAGS_$(@)) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c -SHD_CCRULE_NOQ=$(RUN_CC_NOQ) $(MT_CC) $(CPPFLAGS_$(@)) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c +SHD_CCRULE =$(RUN_CC) $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c +SHD_CCRULE_NOQ=$(RUN_CC_NOQ) $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c # Libtool - for objects that are part of pthread-only libraries LT_CCRULE=$(RUN_CC) $(LIBTOOL) --quiet --mode=compile --tag=CC \ - $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c + $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c LT_current=0 LT_revision=0 @@ -254,7 +256,7 @@ LT_age=0 # Basic rule to link a shared library. LT_LDLIB_shlib_common=$(LIBTOOL) --quiet --mode=link --tag=CC \ - $(MT_CC) -rpath $(libdir) \ + $(LD_WRAPPER) $(MT_CC) -rpath $(libdir) \ $(PTH_LDFLAGS) $(PTH_CFLAGS) $(LDFLAGS_$(@)) \ -o $@ \ -version-info $(LT_current):$(LT_revision):$(LT_age) @@ -267,18 +269,18 @@ LT_LDLIB_shlib_missing=$(LT_LDLIB_shlib_common) -export-symbols-regex \ # Link a static convenience library (contains no PIC code) LT_LDLIB_static=$(LIBTOOL) --quiet --mode=link --tag=CC \ - $(MT_CC) -static $(LDFLAGS) $(DBG) $(OPTMZ) \ + $(LD_WRAPPER) $(MT_CC) -static $(LDFLAGS) $(DBG) $(OPTMZ) \ $(LDFLAGS_$(@)) -o $@ # Link a convenience library for use in other libs (contains PIC code) LT_LDLIB_pic= $(LIBTOOL) --quiet --mode=link --tag=CC \ - $(MT_CC) $(LDFLAGS) $(DBG) $(OPTMZ) \ + $(LD_WRAPPER) $(MT_CC) $(LDFLAGS) $(DBG) $(OPTMZ) \ $(LDFLAGS_$(@)) -o $@ # Libtool - for objects that are built for both pthread and lwp libraries LTLWP_CCRULE=$(RUN_CC) $(LWPTOOL) --mode compile \ - --lwpcc "$(CCOBJ)" \ - --mtcc "$(LIBTOOL) --quiet --mode=compile --tag=CC $(MT_CC) $(MT_CFLAGS)" \ + --lwpcc "$(CC_WRAPPER) $(CCOBJ)" \ + --mtcc "$(LIBTOOL) --quiet --mode=compile --tag=CC $(CC_WRAPPER) $(MT_CC) $(MT_CFLAGS)" \ -o $@ \ -- \ $(CPPFLAGS_$(@)) $(MODULE_CFLAGS) $(COMMON_CFLAGS) $(CFLAGS_$(@)) \ @@ -298,15 +300,15 @@ LT_LDLIB_lwp_NOQ=$(RUN_LD_NOQ) $(LWPTOOL) --mode link \ # Use this to link an executable with one or more libtool libraries LT_LDRULE = $(RUN_LD) $(LIBTOOL) --quiet --mode=link --tag=CC \ - $(MT_CC) $(PTH_LDFLAGS) $(PTH_CFLAGS) \ + $(LD_WRAPPER) $(MT_CC) $(PTH_LDFLAGS) $(PTH_CFLAGS) \ $(LDFLAGS_$(@)) -o $@ LT_LDRULE_static = $(RUN_LD) $(LIBTOOL) --quiet --mode=link --tag=CC \ - $(MT_CC) -static $(PTH_LDFLAGS) $(PTH_CFLAGS) \ + $(LD_WRAPPER) $(MT_CC) -static $(PTH_LDFLAGS) $(PTH_CFLAGS) \ $(LDFLAGS_$(@)) -o $@ LT_LDRULE_static_NOQ = $(RUN_LD_NOQ) $(LIBTOOL) --quiet --mode=link --tag=CC \ - $(MT_CC) -static $(PTH_LDFLAGS) $(PTH_CFLAGS) \ + $(LD_WRAPPER) $(MT_CC) -static $(PTH_LDFLAGS) $(PTH_CFLAGS) \ $(LDFLAGS_$(@)) -o $@ LT_INSTALL_DATA=$(LIBTOOL) --quiet --mode=install $(INSTALL_DATA) @@ -317,36 +319,5 @@ LT_CLEAN=$(RM) -rf .lwp .libs *.la *.lo # Default rules. These will be overriden if the module Makefile specifically # includes a particular type (lwp, pthread, or shared) -AFS_LDRULE =$(RUN_LD) $(CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@ -AFS_LDRULE_NOQ =$(RUN_LD_NOQ) $(CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@ - -RUN_CTFCONVERT=@RUN_CTFCONVERT() { \ - CTFLABEL=$$1 ; \ - CTFDBG=$$2 ; \ - shift ; shift ; \ - if test "x$${CTFDBG}" = "x" ; then exit 0; fi; \ - if test "x${CTFCONVERT}" = "x" ; then exit 0; fi; \ - if test "x${CTFMERGE}" = "x" ; then \ - echo "refusing to run ctfconvert; missing ctfmerge"; \ - exit 1; \ - fi; \ - for t in $$@ ; do \ - echo "${CTFCONVERT} -g -l $${CTFLABEL} $$t"; \ - ${CTFCONVERT} -g -l $${CTFLABEL} $$t; \ - done ; \ -} ; RUN_CTFCONVERT - -RUN_CTFMERGE=@RUN_CTFMERGE () { \ - CTFLABEL=$$1 ; \ - CTFDBG=$$2 ; \ - shift ; shift ; \ - if test "x$${CTFDBG}" = "x" ; then exit 0; fi; \ - if test "x${CTFMERGE}" = "x" ; then exit 0; fi; \ - if test "x${CTFCONVERT}" = "x" ; then \ - echo "refusing to run ctfmerge; missing ctfconvert"; \ - exit 1; \ - fi; \ - echo "$(CTFMERGE) -g -l $${CTFLABEL} -o $$@"; \ - $(CTFMERGE) -g -l $${CTFLABEL} -o $$@; \ -} ; RUN_CTFMERGE - +AFS_LDRULE =$(RUN_LD) $(LD_WRAPPER) $(CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@ +AFS_LDRULE_NOQ =$(RUN_LD_NOQ) $(LD_WRAPPER) $(CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@ diff --git a/src/config/Makefile.pthread.in b/src/config/Makefile.pthread.in index f4af720..e95936a 100644 --- a/src/config/Makefile.pthread.in +++ b/src/config/Makefile.pthread.in @@ -3,8 +3,8 @@ AFS_LDFLAGS=$(PTH_LDFLAGS) AFS_CCRULE=$(PTH_CCRULE) AFS_CCRULE_NOQ=$(PTH_CCRULE_NOQ) -AFS_LDRULE=$(RUN_LD) $(MT_CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@ -AFS_LDRULE_NOQ=$(RUN_LD_NOQ) $(MT_CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@ +AFS_LDRULE=$(RUN_LD) $(LD_WRAPPER) $(MT_CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@ +AFS_LDRULE_NOQ=$(RUN_LD_NOQ) $(LD_WRAPPER) $(MT_CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@)) -o $@ .c.o: $(AFS_CCRULE) $< diff --git a/src/config/cc-wrapper.in b/src/config/cc-wrapper.in new file mode 100644 index 0000000..8ef305f --- /dev/null +++ b/src/config/cc-wrapper.in @@ -0,0 +1,112 @@ +#!/bin/sh +# +# usage: +# cc-wrapper cc /path/to/cc -c -o foo.o foo.c +# cc-wrapper ld /path/to/ld -o foo foo.o +# +# This wraps running the compiler or linker, so we can tweak the files +# generated. Currently, this just involves running ctfconvert or ctfmerge on +# the relevant files, if available. + +set -e + +CTFCONVERT=@CTFCONVERT@ +CTFMERGE=@CTFMERGE@ +ctf_label=openafs + +mode="$1" +shift + +# First, run the command that we're wrapping. +"$@" + +# If we've reached here, the compiler/linker finished successfully, so now we +# can run ctfconvert/ctfmerge, if we're configured to. If we're not going to +# process ctf stuff, we can just exit immediately. +if [ x"$CTFCONVERT" = x ] || [ x"$CTFMERGE" = x ] ; then + exit 0 +fi + +# Look for our target file (indicated by '-o target'), and if debugging is +# turned on (indicated by '-g') +target= +target_next= +debug= +for arg in "$@" ; do + if [ x"$target_next" = x1 ] ; then + target="$arg" + target_next= + continue + fi + + case "$arg" in + -o) target_next=1 + ;; + -g) debug=1 + ;; + esac +done + +if [ x"$OPENAFS_CC_WRAPPER_DEBUG_FLAG" != x ] ; then + # Normally we try to determine if debugging is turned on by searching $@ + # for "-g". But sometimes we link something with debugging info and don't + # pass -g (the Solaris kernel module, for example). In this case, the + # caller can specify whether that debugging is turned on by setting the env + # var OPENAFS_CC_WRAPPER_DEBUG_FLAG to a nonempty string. + debug=1 +fi + +if [ x"$debug" = x ] ; then + # Don't run ctfconvert/ctfmerge if debugging isn't turned on. + exit 0 +fi + +if [ x"$target" = x ] ; then + echo "$0: error: cannot extract target from args" >&2 + exit 1 +fi + +echo_run() { + if [ x"$V" != x0 ] ; then + echo "$@" + fi + "$@" +} + +case "$mode" in +cc) + # It looks like we compiled a single object. For that, we just need to run + # 'ctfconvert' against the target .o. + echo_run "$CTFCONVERT" -g -l $ctf_label "$target" + ;; + +ld) + # It looks like we're linking an executable. For that, we need to give + # 'ctfmerge' every .o and .a that we're linking against. + + merge_objs= + for arg in "$@" ; do + case "$arg" in + *.[oa]) + merge_objs="$merge_objs $arg" + ;; + esac + done + + if [ x"$merge_objs" = x ] ; then + # If we can't find any .o or .a files that we're linking into the + # target executable, our caller is probably compiling/linking directly + # from foo.c into foo (skipping foo.o). For that, we just need to run + # ctfconvert/ctfmerge on the executable itself. + echo_run "$CTFCONVERT" -g -l $ctf_label "$target" + merge_objs="$target" + fi + + echo_run "$CTFMERGE" -g -l $ctf_label -o "$target" $merge_objs + ;; + +*) + echo "$0: Unknown mode '$mode'" >&2 + exit 1 + ;; +esac diff --git a/src/libafs/Makefile.common.in b/src/libafs/Makefile.common.in index 775a3d1..e585660 100644 --- a/src/libafs/Makefile.common.in +++ b/src/libafs/Makefile.common.in @@ -43,9 +43,9 @@ COMMON_INCLUDE = -I. -I.. -I../nfs \ # Build rules - CC and CFLAGS are defined in system specific MakefileProtos. .c.o: - $(RUN_CC) $(CC) $(COMMON_INCLUDE) $(CFLAGS) $(CFLAGS-$(@)) $(KERN_DBG) -c $< -CRULE_NOOPT= $(RUN_CC) $(CC) $(COMMON_INCLUDE) $(KERN_DBG) $(CFLAGS) $(CFLAGS-$(@)) -o $@ -c -CRULE_OPT= $(RUN_CC) $(CC) $(COMMON_INCLUDE) $(KERN_DBG) $(KERN_OPTMZ) $(CFLAGS) $(CFLAGS-$(@)) -o $@ -c + $(RUN_CC) $(CC_WRAPPER) $(CC) $(COMMON_INCLUDE) $(CFLAGS) $(CFLAGS-$(@)) $(KERN_DBG) -c $< +CRULE_NOOPT= $(RUN_CC) $(CC_WRAPPER) $(CC) $(COMMON_INCLUDE) $(KERN_DBG) $(CFLAGS) $(CFLAGS-$(@)) -o $@ -c +CRULE_OPT= $(RUN_CC) $(CC_WRAPPER) $(CC) $(COMMON_INCLUDE) $(KERN_DBG) $(KERN_OPTMZ) $(CFLAGS) $(CFLAGS-$(@)) -o $@ -c system: all diff --git a/src/libafs/MakefileProto.SOLARIS.in b/src/libafs/MakefileProto.SOLARIS.in index 0c8e41f..f04ceef 100644 --- a/src/libafs/MakefileProto.SOLARIS.in +++ b/src/libafs/MakefileProto.SOLARIS.in @@ -149,15 +149,13 @@ dest_libafs: $(LIBAFS) $(LIBAFSNONFS) ${INSTALL} -m 644 $(LIBAFS) $(DEST_LIBAFS) ${INSTALL} -m 644 $(LIBAFSNONFS) $(DEST_LIBAFSNONFS) +# See $TOP_SRCDIR/config/cc-wrapper for an explanation/usage of +# OPENAFS_CC_WRAPPER_DEBUG_FLAG + ${LIBAFS}: $(AFSAOBJS) $(AFSNFSOBJS) $(RM) -f $@ - $(RUN_CTFCONVERT) libafs "${KERN_DBG}" ${AFSAOBJS} ${AFSNFSOBJS} - $(LD) $(LDFLAGS) -o $@ $(AFSAOBJS) ${AFSNFSOBJS} - $(RUN_CTFMERGE) libafs "${KERN_DBG}" $@ $(AFSAOBJS) ${AFSNFSOBJS} + OPENAFS_CC_WRAPPER_DEBUG_FLAG="$(KERN_DBG)" $(LD_WRAPPER) $(LD) $(LDFLAGS) -o $@ $(AFSAOBJS) ${AFSNFSOBJS} ${LIBAFSNONFS}: $(AFSAOBJS) $(AFSNONFSOBJS) $(RM) -f $@ - $(RUN_CTFCONVERT) libafs "${KERN_DBG}" ${AFSAOBJS} ${AFSNONFSOBJS} - $(LD) $(LDFLAGS) -o $@ $(AFSAOBJS) ${AFSNONFSOBJS} - $(RUN_CTFMERGE) libafs "${KERN_DBG}" $@ $(AFSAOBJS) ${AFSNONFSOBJS} - + OPENAFS_CC_WRAPPER_DEBUG_FLAG="$(KERN_DBG)" $(LD_WRAPPER) $(LD) $(LDFLAGS) -o $@ $(AFSAOBJS) ${AFSNONFSOBJS} diff --git a/src/tsalvaged/Makefile.in b/src/tsalvaged/Makefile.in index c0c337c..cd69b86 100644 --- a/src/tsalvaged/Makefile.in +++ b/src/tsalvaged/Makefile.in @@ -20,7 +20,7 @@ MODULE_CFLAGS = -DRXDEBUG -DFSSYNC_BUILD_CLIENT \ SCFLAGS=$(COMMON_CFLAGS) -I.. -DRXDEBUG -DFSSYNC_BUILD_CLIENT \ -DAFS_DEMAND_ATTACH_FS $(PTH_CFLAGS) -SCCRULE=$(RUN_CC) ${MT_CC} ${SCFLAGS} -c $? -o $@ +SCCRULE=$(RUN_CC) $(CC_WRAPPER) ${MT_CC} ${SCFLAGS} -c $? -o $@ DIR=$(srcdir)/../dir VOL=$(srcdir)/../vol