svn commit: r321778 - in projects/runtime-coverage: . share/mk
Ngie Cooper
ngie at FreeBSD.org
Mon Jul 31 09:54:06 UTC 2017
Author: ngie
Date: Mon Jul 31 09:54:04 2017
New Revision: 321778
URL: https://svnweb.freebsd.org/changeset/base/321778
Log:
Take a different approach to building with --coverage (WiP)
The .covo binaries didn't really make sense after reviewing some stackoverflow posts
and other related documentation -- in particular, it would complicate matters by having
"coverage-enabled binaries" link to "coverage-enabled libraries" (aka "covo" libraries).
It's best to install the full binaries/libraries to /usr/lib/cov instead.
In order to enable this (and make sure that libprofile_rt is built properly),
libprofile_rt must be built with cross-tools.
Also, don't explicitly disable MK_COVERAGE in _libraries -- coverage support needs to
be baked in to the libraries in order for it to be effective.
Pass through --coverage in the linking phase for shared libraries -- it's necessary
to ensure that libprofile_rt is resolved properly in the _libraries phase with 2nd
order libraries, like libcom_err.so.*.
This change reverses all of r320396 and partially reverses r321758. The first commit
was the WiP approach that was proven to incorrect with the reasoning given in the first
paragraph. The second commit reverses the MK_DEBUG_FILES change because I'll probably
run into friction when trying to merge it back in to head if I leave it in (despite
the fact that I find this behavior completely unnecessary).
TODO: see if libprofile_rt's symbols should be stripped out of debug files; they are
currently duplicated between the fat binaries installed to /usr/lib/cov and the debug
files installed to /usr/lib/debug .
Modified:
projects/runtime-coverage/Makefile.inc1
projects/runtime-coverage/share/mk/bsd.lib.mk
projects/runtime-coverage/share/mk/bsd.prog.mk
projects/runtime-coverage/share/mk/sys.mk
Modified: projects/runtime-coverage/Makefile.inc1
==============================================================================
--- projects/runtime-coverage/Makefile.inc1 Mon Jul 31 09:50:47 2017 (r321777)
+++ projects/runtime-coverage/Makefile.inc1 Mon Jul 31 09:54:04 2017 (r321778)
@@ -546,7 +546,7 @@ TMAKE= MAKEOBJDIRPREFIX=${OBJTREE} \
-DNO_LINT \
-DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
- MK_COVERAGE=no MK_DEBUG_FLAGS=no \
+ MK_COVERAGE=no \
MK_LLDB=no MK_TESTS=no
# cross-tools stage
@@ -934,7 +934,7 @@ _libraries:
@echo ">>> stage 4.2: building libraries"
@echo "--------------------------------------------------------------"
${_+_}cd ${.CURDIR}; \
- ${WMAKE} -DNO_FSCHG MK_COVERAGE=no MK_HTML=no -DNO_LINT MK_MAN=no \
+ ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS} libraries
everything: .PHONY
@echo
@@ -2047,6 +2047,12 @@ _lld= usr.bin/clang/lld
.if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_LLD_BOOTSTRAP} != "no"
_clang_libs= lib/clang
.endif
+.if ${MK_COVERAGE} != "no"
+.if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no"
+_coverage_libs= lib/libclang_rt/profile
+.endif
+.endif
+
.if ${MK_GCC_BOOTSTRAP} != "no"
_gcc= gnu/usr.bin/cc
.endif
@@ -2058,6 +2064,7 @@ cross-tools: .MAKE .PHONY
.for _tool in \
${LOCAL_XTOOL_DIRS} \
${_clang_libs} \
+ ${_coverage_libs} \
${_clang} \
${_lld} \
${_binutils} \
Modified: projects/runtime-coverage/share/mk/bsd.lib.mk
==============================================================================
--- projects/runtime-coverage/share/mk/bsd.lib.mk Mon Jul 31 09:50:47 2017 (r321777)
+++ projects/runtime-coverage/share/mk/bsd.lib.mk Mon Jul 31 09:54:04 2017 (r321778)
@@ -73,12 +73,19 @@ SHARED_CFLAGS+= -g
SHARED_CXXFLAGS+= -g
CTFFLAGS+= -g
.endif
+.if defined(SHLIB_NAME) && ${MK_COVERAGE} != "no" && \
+ (!empty(DEBUG_FLAGS:M-g*) || !empty(SHARED_CFLAGS:M-g*) || \
+ !empty(SHARED_CXXFLAGS:M-g*))
+_COV_FLAG= --coverage
+SHARED_CFLAGS+= ${_COV_FLAG}
+SHARED_CXXFLAGS+= ${_COV_FLAG}
+.endif
.include <bsd.libnames.mk>
-# prefer .s to a .c, add .covo and .po, remove stuff not used in the BSD libraries
+# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
# .pico used for PIC object files
-.SUFFIXES: .out .o .bc .covo .ll .po .pico .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
+.SUFFIXES: .out .o .bc .ll .po .pico .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
.if !defined(PICFLAG)
.if ${MACHINE_CPUARCH} == "sparc64"
@@ -88,14 +95,8 @@ PICFLAG=-fpic
.endif
.endif
-COV_FLAG=--coverage -g
-
PO_FLAG=-pg
-.c.covo:
- ${CC} ${COV_FLAG} ${STATIC_CFLAGS} ${COV_CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
- ${CTFCONVERT_CMD}
-
.c.po:
${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
${CTFCONVERT_CMD}
@@ -104,9 +105,6 @@ PO_FLAG=-pg
${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
${CTFCONVERT_CMD}
-.cc.covo .C.covo .cpp.covo .cxx.covo:
- ${CXX} ${COV_FLAG} ${STATIC_CXXFLAGS} ${COV_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
-
.cc.po .C.po .cpp.po .cxx.po:
${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@@ -121,15 +119,10 @@ PO_FLAG=-pg
${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
${CTFCONVERT_CMD}
-.s.covo .s.po .s.pico:
+.s.po .s.pico:
${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
${CTFCONVERT_CMD}
-.asm.covo:
- ${CC:N${CCACHE_BIN}} -x assembler-with-cpp -DCOV ${COV_CFLAGS} \
- ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
- ${CTFCONVERT_CMD}
-
.asm.po:
${CC:N${CCACHE_BIN}} -x assembler-with-cpp -DPROF ${PO_CFLAGS} \
${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@@ -140,11 +133,6 @@ PO_FLAG=-pg
${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
${CTFCONVERT_CMD}
-.S.covo:
- ${CC:N${CCACHE_BIN}} -DCOV ${COV_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
- -o ${.TARGET}
- ${CTFCONVERT_CMD}
-
.S.po:
${CC:N${CCACHE_BIN}} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
-o ${.TARGET}
@@ -161,6 +149,12 @@ _SHLIBDIR:=${SHLIBDIR}
.if defined(SHLIB_NAME)
.if ${MK_DEBUG_FILES} != "no"
SHLIB_NAME_FULL=${SHLIB_NAME}.full
+.if ${MK_COVERAGE} != "no"
+COVERAGEFILEDIR=${COVERAGEDIR}${_SHLIBDIR}
+.if !exists(${DESTDIR}${COVERAGEFILEDIR})
+COVERAGEMKDIR=
+.endif
+.endif
# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
.if ${_SHLIBDIR} == "/boot" ||\
${SHLIBDIR:C%/lib(/.*)?$%/lib%} == "/lib" ||\
@@ -204,22 +198,6 @@ lib${LIB_PRIVATE}${LIB}.a: ${OBJS} ${STATICOBJS}
.if !defined(INTERNALLIB)
-.if ${MK_COVERAGE} != "no" && defined(LIB) && !empty(LIB)
-_LIBS+= lib${LIB_PRIVATE}${LIB}_c.a
-COV_OBJS+= ${OBJS:.o=.covo} ${STATICOBJS:.o=.covo}
-DEPENDOBJS+= ${COV_OBJS}
-CLEANFILES+= ${COV_OBJS}
-# XXX (ngie): tighten this down
-CLEANFILES+= *.gcda *.gcno
-
-lib${LIB_PRIVATE}${LIB}_c.a: ${COV_OBJS}
- @${ECHO} building coverage instrumented ${LIB} library
- @rm -f ${.TARGET}
- ${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' NMFLAGS='${NMFLAGS}' \
- ${LORDER} ${COV_OBJS} | ${TSORT} ${TSORTFLAGS}` ${ARADD}
- ${RANLIB} ${RANLIBFLAGS} ${.TARGET}
-.endif
-
.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
_LIBS+= lib${LIB_PRIVATE}${LIB}_p.a
POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
@@ -256,6 +234,9 @@ CLEANFILES+= ${SOBJS}
.if defined(SHLIB_NAME)
_LIBS+= ${SHLIB_NAME}
+.if !empty(_COV_FLAG)
+SOLINKOPTS+= ${_COV_FLAG}
+.endif
SOLINKOPTS+= -shared -Wl,-x
.if defined(LD_FATAL_WARNINGS) && ${LD_FATAL_WARNINGS} == "no"
SOLINKOPTS+= -Wl,--no-fatal-warnings
@@ -390,6 +371,14 @@ _libinstall:
${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
${SHLIB_NAME} ${DESTDIR}${_SHLIBDIR}/
.if ${MK_DEBUG_FILES} != "no"
+.if ${MK_COVERAGE} != "no"
+.if defined(COVERAGEMKDIR)
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},coverage} -d ${DESTDIR}${COVERAGEFILEDIR}/
+.endif
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},coverage} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${_INSTALLFLAGS} \
+ ${SHLIB_NAME}.full ${DESTDIR}${COVERAGEFILEDIR}/${SHLIB_NAME}
+.endif
.if defined(DEBUGMKDIR)
${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -d ${DESTDIR}${DEBUGFILEDIR}/
.endif
@@ -441,6 +430,9 @@ _libinstall:
.if !defined(LIBRARIES_ONLY)
.include <bsd.nls.mk>
+.if defined(_COV_FLAG)
+.include <bsd.cov.mk>
+.endif
.include <bsd.files.mk>
.include <bsd.incs.mk>
.include <bsd.confs.mk>
Modified: projects/runtime-coverage/share/mk/bsd.prog.mk
==============================================================================
--- projects/runtime-coverage/share/mk/bsd.prog.mk Mon Jul 31 09:50:47 2017 (r321777)
+++ projects/runtime-coverage/share/mk/bsd.prog.mk Mon Jul 31 09:54:04 2017 (r321778)
@@ -40,9 +40,15 @@ CFLAGS+=${CRUNCH_CFLAGS}
.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
empty(DEBUG_FLAGS:M-gdwarf-*)
CFLAGS+= -g
+CXXFLAGS+= -g
CTFFLAGS+= -g
.endif
+.if ${MK_COVERAGE} != "no" && ${CFLAGS:M-g*} != ""
+_COV_FLAG= --coverage
+CFLAGS+= ${_COV_FLAG}
+CXXFLAGS+= ${_COV_FLAG}
.endif
+.endif
.if !defined(DEBUG_FLAGS)
STRIP?= -s
@@ -73,6 +79,12 @@ DEBUGFILEDIR= ${DEBUGDIR}${BINDIR}
.else
DEBUGFILEDIR?= ${BINDIR}/.debug
.endif
+.if ${MK_COVERAGE} != "no"
+COVERAGEDIR= ${COVDIR}${BINDIR}
+.if !exists(${DESTDIR}${COVERAGEDIR})
+COVERAGEMKDIR=
+.endif
+.endif
.if !exists(${DESTDIR}${DEBUGFILEDIR})
DEBUGMKDIR=
.endif
@@ -233,6 +245,13 @@ _proginstall:
${INSTALL} ${TAG_ARGS} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
.if ${MK_DEBUG_FILES} != "no"
+.if ${MK_COVERAGE} != "no"
+.if defined(COVERAGEMKDIR)
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},coverage} -d ${DESTDIR}${COVERAGEDIR}/
+.endif
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},coverage} -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
+ ${PROGNAME}.full ${DESTDIR}${COVERAGEDIR}/${PROGNAME}
+.endif
.if defined(DEBUGMKDIR)
${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -d ${DESTDIR}${DEBUGFILEDIR}/
.endif
@@ -279,6 +298,9 @@ NLSNAME?= ${PROG}
.include <bsd.nls.mk>
.include <bsd.confs.mk>
+.if defined(_COV_FLAG)
+.include <bsd.cov.mk>
+.endif
.include <bsd.files.mk>
.include <bsd.incs.mk>
.include <bsd.links.mk>
Modified: projects/runtime-coverage/share/mk/sys.mk
==============================================================================
--- projects/runtime-coverage/share/mk/sys.mk Mon Jul 31 09:50:47 2017 (r321777)
+++ projects/runtime-coverage/share/mk/sys.mk Mon Jul 31 09:54:04 2017 (r321778)
@@ -163,7 +163,6 @@ CFLAGS += -fno-strict-aliasing
.endif
.endif
IR_CFLAGS ?= ${STATIC_CFLAGS:N-O*} ${CFLAGS:N-O*}
-COV_CFLAGS ?= ${CFLAGS}
PO_CFLAGS ?= ${CFLAGS}
# cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
@@ -185,7 +184,6 @@ CTFFLAGS += -g
CXX ?= c++
CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
IR_CXXFLAGS ?= ${STATIC_CXXFLAGS:N-O*} ${CXXFLAGS:N-O*}
-COV_CXXFLAGS ?= ${CXXFLAGS}
PO_CXXFLAGS ?= ${CXXFLAGS}
DTRACE ?= dtrace
More information about the svn-src-projects
mailing list