From 2a9e60bc7f9e6c2b31dbc8d9f5d876c0ce0a9991 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Tue, 27 Jun 2017 06:02:50 +0000 Subject: [PATCH] Stash work for adding runtime coverage support to bsd.lib.mk The initial work uses static libraries instead of dynamic libraries, for parity with pico-style libraries. I suspect this approach is slightly flawed, but I wanted to stash the WiP, just in case. --- share/mk/bsd.lib.mk | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk index 67a5630996be..cde1868d1b54 100644 --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -76,9 +76,9 @@ CTFFLAGS+= -g .include -# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries +# prefer .s to a .c, add .covo and .po, remove stuff not used in the BSD libraries # .pico used for PIC object files -.SUFFIXES: .out .o .bc .ll .po .pico .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln +.SUFFIXES: .out .o .bc .covo .ll .po .pico .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln .if !defined(PICFLAG) .if ${MACHINE_CPUARCH} == "sparc64" @@ -88,8 +88,14 @@ 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} @@ -98,6 +104,9 @@ 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} @@ -112,10 +121,15 @@ PO_FLAG=-pg ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} ${CTFCONVERT_CMD} -.s.po .s.pico: +.s.covo .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} @@ -126,6 +140,11 @@ 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} @@ -185,6 +204,22 @@ 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}