Mon Oct 25 07:54:44 2021 UTC ()
In some arch, _mcount() would be called recursively when built with COPTS=-O0.

Normally, functions called from mcount.c are expected to be expanded inline,
so _mcount() will never be called recursively. But when build with COPTS=-O0,
`static inline' functions aren't inlined, and _mcount() will be called
recursively.

Even if _mcount() has `__attribute__((__no_ instrument_function__))',
it has no effect on the calling external (no-inlined) function.

To avoid this, PROF.<fn> is added can be set the profiling flag of any file.
"PROF.mcount.c" is set to blank by default, mcount.c itself is compiled
without -pg.


(ryo)
diff -r1.419 -r1.420 src/share/mk/bsd.README
diff -r1.385 -r1.386 src/share/mk/bsd.lib.mk
diff -r1.282 -r1.283 src/sys/conf/Makefile.kern.inc
diff -r1.51 -r1.52 src/sys/lib/libkern/Makefile.libkern

cvs diff -r1.419 -r1.420 src/share/mk/bsd.README (expand / switch to unified diff)

--- src/share/mk/bsd.README 2021/10/14 11:45:46 1.419
+++ src/share/mk/bsd.README 2021/10/25 07:54:44 1.420
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: bsd.README,v 1.419 2021/10/14 11:45:46 nia Exp $ 1# $NetBSD: bsd.README,v 1.420 2021/10/25 07:54:44 ryo Exp $
2# @(#)bsd.README 8.2 (Berkeley) 4/2/94 2# @(#)bsd.README 8.2 (Berkeley) 4/2/94
3 3
4This is the README file for the make "include" files for the NetBSD 4This is the README file for the make "include" files for the NetBSD
5source tree. The files are installed in /usr/share/mk, and are, 5source tree. The files are installed in /usr/share/mk, and are,
6by convention, named with the suffix ".mk". 6by convention, named with the suffix ".mk".
7 7
8Note, this file is not intended to replace reading through the .mk 8Note, this file is not intended to replace reading through the .mk
9files for anything tricky. 9files for anything tricky.
10 10
11=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 11=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
12 12
13RANDOM THINGS WORTH KNOWING: 13RANDOM THINGS WORTH KNOWING:
14 14
@@ -1620,26 +1620,30 @@ LDADD Additional loader objects. Usual @@ -1620,26 +1620,30 @@ LDADD Additional loader objects. Usual
1620 1620
1621 LDADD+=-lutil -lcompat 1621 LDADD+=-lutil -lcompat
1622 1622
1623LDFLAGS Additional linker flags (passed to ${CC} during link). 1623LDFLAGS Additional linker flags (passed to ${CC} during link).
1624 1624
1625LINKS See <bsd.links.mk> 1625LINKS See <bsd.links.mk>
1626 1626
1627OBJCOPTS Additional flags to the compiler when creating ObjC objects. 1627OBJCOPTS Additional flags to the compiler when creating ObjC objects.
1628 1628
1629OBJCOPTS.<fn> Additional flags to the compiler when creating the 1629OBJCOPTS.<fn> Additional flags to the compiler when creating the
1630 ObjC objects for <fn>. 1630 ObjC objects for <fn>.
1631 For <fn>.[ly], "<fn>.c" must be used. 1631 For <fn>.[ly], "<fn>.c" must be used.
1632 1632
 1633PROF.<fn> Alternative flag instead of "-pg" to pass to the compiler
 1634 when profiling <fn>. For <fn>.[ly], "<fn>.c" must be used.
 1635 Usually used to exclude a particular file from profiling.
 1636
1633SYMLINKS See <bsd.links.mk> 1637SYMLINKS See <bsd.links.mk>
1634 1638
1635MAN Manual pages (should end in .1 - .9). If no MAN variable is 1639MAN Manual pages (should end in .1 - .9). If no MAN variable is
1636 defined, "MAN=${PROG}.1" is assumed. 1640 defined, "MAN=${PROG}.1" is assumed.
1637 1641
1638PAXCTL_FLAGS If defined, run paxctl(1) on the program binary after link 1642PAXCTL_FLAGS If defined, run paxctl(1) on the program binary after link
1639 time, with the value of this variable as args to paxctl(1). 1643 time, with the value of this variable as args to paxctl(1).
1640 1644
1641PAXCTL_FLAGS.${PROG} Custom override for PAXCTL_FLAGS. 1645PAXCTL_FLAGS.${PROG} Custom override for PAXCTL_FLAGS.
1642 1646
1643PROG The name of the program to build. If not supplied, nothing 1647PROG The name of the program to build. If not supplied, nothing
1644 is built. 1648 is built.
1645 1649

cvs diff -r1.385 -r1.386 src/share/mk/bsd.lib.mk (expand / switch to unified diff)

--- src/share/mk/bsd.lib.mk 2021/08/21 11:55:24 1.385
+++ src/share/mk/bsd.lib.mk 2021/10/25 07:54:44 1.386
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: bsd.lib.mk,v 1.385 2021/08/21 11:55:24 andvar Exp $ 1# $NetBSD: bsd.lib.mk,v 1.386 2021/10/25 07:54:44 ryo Exp $
2# @(#)bsd.lib.mk 8.3 (Berkeley) 4/22/94 2# @(#)bsd.lib.mk 8.3 (Berkeley) 4/22/94
3 3
4.include <bsd.init.mk> 4.include <bsd.init.mk>
5.include <bsd.shlib.mk> 5.include <bsd.shlib.mk>
6.include <bsd.gcc.mk> 6.include <bsd.gcc.mk>
7.include <bsd.sanitizer.mk> 7.include <bsd.sanitizer.mk>
8 8
9# Pull in <bsd.sys.mk> here so we can override its .c.o rule 9# Pull in <bsd.sys.mk> here so we can override its .c.o rule
10.include <bsd.sys.mk> 10.include <bsd.sys.mk>
11 11
12LIBISMODULE?= no 12LIBISMODULE?= no
13LIBISPRIVATE?= no 13LIBISPRIVATE?= no
14LIBISCXX?= no 14LIBISCXX?= no
@@ -41,27 +41,28 @@ MKPROFILE:= no @@ -41,27 +41,28 @@ MKPROFILE:= no
41realinstall: checkver libinstall 41realinstall: checkver libinstall
42 42
43##### LIB specific flags. 43##### LIB specific flags.
44# XXX: This is needed for programs that link with .a libraries 44# XXX: This is needed for programs that link with .a libraries
45# Perhaps a more correct solution is to always generate _pic.a 45# Perhaps a more correct solution is to always generate _pic.a
46# files or always have a shared library. 46# files or always have a shared library.
47# Another fix is to provide rcrt0.o like OpenBSD does and 47# Another fix is to provide rcrt0.o like OpenBSD does and
48# do relocations for static PIE. 48# do relocations for static PIE.
49.if defined(MKPIE) && (${MKPIE} != "no") && !defined(NOPIE) 49.if defined(MKPIE) && (${MKPIE} != "no") && !defined(NOPIE)
50CFLAGS+= ${PIE_CFLAGS} 50CFLAGS+= ${PIE_CFLAGS}
51AFLAGS+= ${PIE_AFLAGS} 51AFLAGS+= ${PIE_AFLAGS}
52.endif 52.endif
53 53
54PGFLAGS+= -pg 54PROF?= -pg
 55PGFLAGS+= ${PROF.${.IMPSRC:T}:U${PROF}}
55.if ${MKPIC} != "no" 56.if ${MKPIC} != "no"
56PGFLAGS+= -fPIC 57PGFLAGS+= -fPIC
57.endif 58.endif
58 59
59##### Libraries that this may depend upon. 60##### Libraries that this may depend upon.
60.if defined(LIBDPLIBS) && ${MKPIC} != "no" # { 61.if defined(LIBDPLIBS) && ${MKPIC} != "no" # {
61.for _lib _dir in ${LIBDPLIBS} 62.for _lib _dir in ${LIBDPLIBS}
62.if !defined(LIBDO.${_lib}) 63.if !defined(LIBDO.${_lib})
63LIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR} 64LIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR}
64.MAKEOVERRIDES+=LIBDO.${_lib} 65.MAKEOVERRIDES+=LIBDO.${_lib}
65.endif 66.endif
66.if ${LIBDO.${_lib}} == "_external" 67.if ${LIBDO.${_lib}} == "_external"
67LDADD+= -l${_lib} 68LDADD+= -l${_lib}

cvs diff -r1.282 -r1.283 src/sys/conf/Makefile.kern.inc (expand / switch to unified diff)

--- src/sys/conf/Makefile.kern.inc 2021/09/11 20:28:05 1.282
+++ src/sys/conf/Makefile.kern.inc 2021/10/25 07:54:44 1.283
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile.kern.inc,v 1.282 2021/09/11 20:28:05 andvar Exp $ 1# $NetBSD: Makefile.kern.inc,v 1.283 2021/10/25 07:54:44 ryo Exp $
2# 2#
3# This file contains common `MI' targets and definitions and it is included 3# This file contains common `MI' targets and definitions and it is included
4# at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}. 4# at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}.
5# 5#
6# Each target in this file should be protected with `if !target(target)' 6# Each target in this file should be protected with `if !target(target)'
7# or `if !commands(target)' and each variable should only be conditionally 7# or `if !commands(target)' and each variable should only be conditionally
8# assigned `VAR ?= VALUE', so that everything can be overridden. 8# assigned `VAR ?= VALUE', so that everything can be overridden.
9# 9#
10# DEBUG is set to -g if debugging. 10# DEBUG is set to -g if debugging.
11# PROF is set to -pg if profiling. 11# PROF is set to -pg if profiling.
12# 12#
13# To specify debugging, add the config line: makeoptions DEBUG="-g" 13# To specify debugging, add the config line: makeoptions DEBUG="-g"
14# A better way is to specify -g only for a few files. 14# A better way is to specify -g only for a few files.
@@ -140,28 +140,28 @@ COMPILE_CTFCONVERT= ${_MKSHECHO}\ @@ -140,28 +140,28 @@ COMPILE_CTFCONVERT= ${_MKSHECHO}\
140 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} && \ 140 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} && \
141 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 141 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
142.else 142.else
143COMPILE_CTFCONVERT= ${_MKSHNOECHO} 143COMPILE_CTFCONVERT= ${_MKSHNOECHO}
144.endif 144.endif
145 145
146KCOMPILE.c= ${CC} ${COPTS.${<:T}} ${CFLAGS} ${CPPFLAGS} -c $< -o $@ 146KCOMPILE.c= ${CC} ${COPTS.${<:T}} ${CFLAGS} ${CPPFLAGS} -c $< -o $@
147KCOMPILE.s= ${CC} ${AFLAGS} ${AFLAGS.${<:T}} ${CPPFLAGS} -c $< -o $@ 147KCOMPILE.s= ${CC} ${AFLAGS} ${AFLAGS.${<:T}} ${CPPFLAGS} -c $< -o $@
148KLINK.o= ${LD} -r ${LINKFORMAT} -Map=${.TARGET}.map -o ${.TARGET} ${.ALLSRC} 148KLINK.o= ${LD} -r ${LINKFORMAT} -Map=${.TARGET}.map -o ${.TARGET} ${.ALLSRC}
149 149
150# compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or 150# compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
151# NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file). 151# NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
152NORMAL_C?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}" && \ 152NORMAL_C?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}" && \
153 ${_MKSHECHO} ${KCOMPILE.c} ${PROF} && \ 153 ${_MKSHECHO} ${KCOMPILE.c} ${PROF.${.IMPSRC:T}:U${PROF}} && \
154 ${KCOMPILE.c} ${PROF} && \ 154 ${KCOMPILE.c} ${PROF.${.IMPSRC:T}:U${PROF}} && \
155 ${COMPILE_CTFCONVERT} 155 ${COMPILE_CTFCONVERT}
156NOPROF_C?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}" && \ 156NOPROF_C?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}" && \
157 ${_MKSHECHO} ${KCOMPILE.c} && \ 157 ${_MKSHECHO} ${KCOMPILE.c} && \
158 ${KCOMPILE.c} && \ 158 ${KCOMPILE.c} && \
159 ${COMPILE_CTFCONVERT} 159 ${COMPILE_CTFCONVERT}
160NORMAL_S?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}" && \ 160NORMAL_S?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}" && \
161 ${_MKSHECHO} ${KCOMPILE.s} && \ 161 ${_MKSHECHO} ${KCOMPILE.s} && \
162 ${KCOMPILE.s} 162 ${KCOMPILE.s}
163  163
164# link rules:  164# link rules:
165LINK_O?= @${_MKSHMSG} " link ${.CURDIR:T}/${.TARGET}" && \ 165LINK_O?= @${_MKSHMSG} " link ${.CURDIR:T}/${.TARGET}" && \
166 ${_MKSHECHO} ${KLINK.o} && \ 166 ${_MKSHECHO} ${KLINK.o} && \
167 ${KLINK.o} 167 ${KLINK.o}

cvs diff -r1.51 -r1.52 src/sys/lib/libkern/Makefile.libkern (expand / switch to unified diff)

--- src/sys/lib/libkern/Makefile.libkern 2021/05/17 08:50:36 1.51
+++ src/sys/lib/libkern/Makefile.libkern 2021/10/25 07:54:44 1.52
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile.libkern,v 1.51 2021/05/17 08:50:36 mrg Exp $ 1# $NetBSD: Makefile.libkern,v 1.52 2021/10/25 07:54:44 ryo Exp $
2 2
3# 3#
4# Variable definitions for libkern. 4# Variable definitions for libkern.
5# 5#
6# Before including this, you _must_ set 6# Before including this, you _must_ set
7# KERNDIR: location of sys/lib/libkern 7# KERNDIR: location of sys/lib/libkern
8# 8#
9# You *may* set: 9# You *may* set:
10# LIBKERN_ARCH: architecture subdir to be used 10# LIBKERN_ARCH: architecture subdir to be used
11# KERNCPPFLAGS: see Makefile.inc 11# KERNCPPFLAGS: see Makefile.inc
12# KERNMISCCPPFLAGS: see Makefile.inc 12# KERNMISCCPPFLAGS: see Makefile.inc
13# 13#
14 14
@@ -45,27 +45,27 @@ CPPFLAGS+= -I${KERNDIR}/../../../common/ @@ -45,27 +45,27 @@ CPPFLAGS+= -I${KERNDIR}/../../../common/
45.endif 45.endif
46 46
47.if !defined(RUMPKERNEL) 47.if !defined(RUMPKERNEL)
48.include "${.PARSEDIR}/Makefile.compiler-rt" 48.include "${.PARSEDIR}/Makefile.compiler-rt"
49.endif 49.endif
50 50
51# Other stuff 51# Other stuff
52SRCS+= kern_assert.c __main.c 52SRCS+= kern_assert.c __main.c
53SRCS+= cpuset.c inet_addr.c intoa.c 53SRCS+= cpuset.c inet_addr.c intoa.c
54.if empty(SRCS:Mbyte_swap_8.*) 54.if empty(SRCS:Mbyte_swap_8.*)
55SRCS+= bswap64.c 55SRCS+= bswap64.c
56.endif 56.endif
57SRCS+= md4c.c md5c.c rmd160.c sha1.c sha2.c sha3.c keccak.c murmurhash.c 57SRCS+= md4c.c md5c.c rmd160.c sha1.c sha2.c sha3.c keccak.c murmurhash.c
58SRCS+= pmatch.c mcount.c crc32.c 58SRCS+= pmatch.c crc32.c
59SRCS+= strlist.c 59SRCS+= strlist.c
60 60
61SRCS+= ppath_kmem_alloc.c 61SRCS+= ppath_kmem_alloc.c
62 62
63SRCS+= copystr.c 63SRCS+= copystr.c
64SRCS+= strsep.c strstr.c 64SRCS+= strsep.c strstr.c
65SRCS+= strlcpy.c strlcat.c 65SRCS+= strlcpy.c strlcat.c
66 66
67SRCS+= imax.c imin.c lmax.c lmin.c uimax.c uimin.c ulmax.c ulmin.c 67SRCS+= imax.c imin.c lmax.c lmin.c uimax.c uimin.c ulmax.c ulmin.c
68SRCS+= memmove.c 68SRCS+= memmove.c
69SRCS+= strchr.c strrchr.c 69SRCS+= strchr.c strrchr.c
70SRCS+= memcmp.c memmem.c 70SRCS+= memcmp.c memmem.c
71 71
@@ -92,26 +92,30 @@ SRCS+= xlat_mbr_fstype.c @@ -92,26 +92,30 @@ SRCS+= xlat_mbr_fstype.c
92 92
93SRCS+= heapsort.c ptree.c radixtree.c rb.c rpst.c 93SRCS+= heapsort.c ptree.c radixtree.c rb.c rpst.c
94 94
95SRCS+= hexdump.c 95SRCS+= hexdump.c
96 96
97# for crypto 97# for crypto
98SRCS+= explicit_memset.c consttime_memequal.c 98SRCS+= explicit_memset.c consttime_memequal.c
99 99
100SRCS+= entpool.c 100SRCS+= entpool.c
101 101
102SRCS+= dkcksum.c 102SRCS+= dkcksum.c
103SRCS+= disklabel_swap.c 103SRCS+= disklabel_swap.c
104 104
 105# for profiling
 106SRCS+= mcount.c
 107PROF.mcount.c= # mcount.c itself is never a profiling target
 108
105.PATH: ${NETBSDSRCDIR}/common/lib/libc/cdb 109.PATH: ${NETBSDSRCDIR}/common/lib/libc/cdb
106SRCS+= cdbr.c 110SRCS+= cdbr.c
107SRCS+= mi_vector_hash.c 111SRCS+= mi_vector_hash.c
108 112
109# Files to clean up 113# Files to clean up
110CLEANFILES+= lib${LIB}.o lib${LIB}.po 114CLEANFILES+= lib${LIB}.o lib${LIB}.po
111 115
112# Remove from SRCS the .c files for any .S files added by the MD makefiles, 116# Remove from SRCS the .c files for any .S files added by the MD makefiles,
113# also remove from SRCS the .c files for the .c files in NO_SRCS. 117# also remove from SRCS the .c files for the .c files in NO_SRCS.
114# (Unlike libc, we don't worry about lint) 118# (Unlike libc, we don't worry about lint)
115 119
116.for check_file in ${SRCS:M*.S} ${NO_SRCS} 120.for check_file in ${SRCS:M*.S} ${NO_SRCS}
117unwanted_file := ${SRCS:M${check_file:.S=.c}} 121unwanted_file := ${SRCS:M${check_file:.S=.c}}