Module Name:    src
Committed By:   ryo
Date:           Mon Oct 25 07:54:44 UTC 2021

Modified Files:
        src/share/mk: bsd.README bsd.lib.mk
        src/sys/conf: Makefile.kern.inc
        src/sys/lib/libkern: Makefile.libkern

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.419 -r1.420 src/share/mk/bsd.README
cvs rdiff -u -r1.385 -r1.386 src/share/mk/bsd.lib.mk
cvs rdiff -u -r1.282 -r1.283 src/sys/conf/Makefile.kern.inc
cvs rdiff -u -r1.51 -r1.52 src/sys/lib/libkern/Makefile.libkern

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/mk/bsd.README
diff -u src/share/mk/bsd.README:1.419 src/share/mk/bsd.README:1.420
--- src/share/mk/bsd.README:1.419	Thu Oct 14 11:45:46 2021
+++ src/share/mk/bsd.README	Mon Oct 25 07:54:44 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.README,v 1.419 2021/10/14 11:45:46 nia Exp $
+#	$NetBSD: bsd.README,v 1.420 2021/10/25 07:54:44 ryo Exp $
 #	@(#)bsd.README	8.2 (Berkeley) 4/2/94
 
 This is the README file for the make "include" files for the NetBSD
@@ -1630,6 +1630,10 @@ OBJCOPTS.<fn>	Additional flags to the co
 		ObjC objects for <fn>.
 		For <fn>.[ly], "<fn>.c" must be used.
 
+PROF.<fn>	Alternative flag instead of "-pg" to pass to the compiler
+		when profiling <fn>. For <fn>.[ly], "<fn>.c" must be used.
+		Usually used to exclude a particular file from profiling.
+
 SYMLINKS	See <bsd.links.mk>
 
 MAN		Manual pages (should end in .1 - .9).  If no MAN variable is

Index: src/share/mk/bsd.lib.mk
diff -u src/share/mk/bsd.lib.mk:1.385 src/share/mk/bsd.lib.mk:1.386
--- src/share/mk/bsd.lib.mk:1.385	Sat Aug 21 11:55:24 2021
+++ src/share/mk/bsd.lib.mk	Mon Oct 25 07:54:44 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.lib.mk,v 1.385 2021/08/21 11:55:24 andvar Exp $
+#	$NetBSD: bsd.lib.mk,v 1.386 2021/10/25 07:54:44 ryo Exp $
 #	@(#)bsd.lib.mk	8.3 (Berkeley) 4/22/94
 
 .include <bsd.init.mk>
@@ -51,7 +51,8 @@ CFLAGS+=        ${PIE_CFLAGS}
 AFLAGS+=        ${PIE_AFLAGS}
 .endif
 
-PGFLAGS+=	-pg
+PROF?=		-pg
+PGFLAGS+=	${PROF.${.IMPSRC:T}:U${PROF}}
 .if ${MKPIC} != "no"
 PGFLAGS+=	-fPIC
 .endif

Index: src/sys/conf/Makefile.kern.inc
diff -u src/sys/conf/Makefile.kern.inc:1.282 src/sys/conf/Makefile.kern.inc:1.283
--- src/sys/conf/Makefile.kern.inc:1.282	Sat Sep 11 20:28:05 2021
+++ src/sys/conf/Makefile.kern.inc	Mon Oct 25 07:54:44 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.kern.inc,v 1.282 2021/09/11 20:28:05 andvar Exp $
+#	$NetBSD: Makefile.kern.inc,v 1.283 2021/10/25 07:54:44 ryo Exp $
 #
 # This file contains common `MI' targets and definitions and it is included
 # at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}.
@@ -150,8 +150,8 @@ KLINK.o=	${LD} -r ${LINKFORMAT} -Map=${.
 # compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
 # NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
 NORMAL_C?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}" && \
-		${_MKSHECHO} ${KCOMPILE.c} ${PROF} && \
-		${KCOMPILE.c} ${PROF} && \
+		${_MKSHECHO} ${KCOMPILE.c} ${PROF.${.IMPSRC:T}:U${PROF}} && \
+		${KCOMPILE.c} ${PROF.${.IMPSRC:T}:U${PROF}} && \
 		${COMPILE_CTFCONVERT}
 NOPROF_C?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}" && \
 		${_MKSHECHO} ${KCOMPILE.c} && \

Index: src/sys/lib/libkern/Makefile.libkern
diff -u src/sys/lib/libkern/Makefile.libkern:1.51 src/sys/lib/libkern/Makefile.libkern:1.52
--- src/sys/lib/libkern/Makefile.libkern:1.51	Mon May 17 08:50:36 2021
+++ src/sys/lib/libkern/Makefile.libkern	Mon Oct 25 07:54:44 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.libkern,v 1.51 2021/05/17 08:50:36 mrg Exp $
+#	$NetBSD: Makefile.libkern,v 1.52 2021/10/25 07:54:44 ryo Exp $
 
 #
 # Variable definitions for libkern.
@@ -55,7 +55,7 @@ SRCS+=	cpuset.c inet_addr.c intoa.c
 SRCS+=	bswap64.c
 .endif
 SRCS+=	md4c.c md5c.c rmd160.c sha1.c sha2.c sha3.c keccak.c murmurhash.c
-SRCS+=	pmatch.c mcount.c crc32.c
+SRCS+=	pmatch.c crc32.c
 SRCS+=	strlist.c
 
 SRCS+=	ppath_kmem_alloc.c
@@ -102,6 +102,10 @@ SRCS+=	entpool.c
 SRCS+=	dkcksum.c
 SRCS+=	disklabel_swap.c
 
+# for profiling
+SRCS+=	mcount.c
+PROF.mcount.c=			# mcount.c itself is never a profiling target
+
 .PATH:	${NETBSDSRCDIR}/common/lib/libc/cdb
 SRCS+=	cdbr.c
 SRCS+=	mi_vector_hash.c

Reply via email to