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 <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
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
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
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])
])
/Makefile.version-CML
/afsconfig.h
/afsconfig.h.in
+/cc-wrapper
/config
/mkvers
/param.h.new
#
# Build helper apps
#
+CC_WRAPPER = @CC_WRAPPER@
+LD_WRAPPER = @LD_WRAPPER@
COMPILE_ET = @COMPILE_ET_PATH@
CONFIGTOOL = @CONFIGTOOL_PATH@
RXGEN = @RXGEN_PATH@
# 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
# 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)
# 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_$(@)) \
# 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)
# 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 $@
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) $<
--- /dev/null
+#!/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
# 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
${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}
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