Module Name: src Committed By: rillig Date: Sun Jan 19 10:57:10 UTC 2025
Modified Files: src/usr.bin/make: Makefile compat.c job.c main.c make.h Log Message: make: fix code coverage counts See tests/usr.bin/gcov/t_gcov.sh. To generate a diff of this commit: cvs rdiff -u -r1.127 -r1.128 src/usr.bin/make/Makefile cvs rdiff -u -r1.261 -r1.262 src/usr.bin/make/compat.c cvs rdiff -u -r1.484 -r1.485 src/usr.bin/make/job.c cvs rdiff -u -r1.636 -r1.637 src/usr.bin/make/main.c cvs rdiff -u -r1.348 -r1.349 src/usr.bin/make/make.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/Makefile diff -u src/usr.bin/make/Makefile:1.127 src/usr.bin/make/Makefile:1.128 --- src/usr.bin/make/Makefile:1.127 Tue Dec 19 20:08:27 2023 +++ src/usr.bin/make/Makefile Sun Jan 19 10:57:10 2025 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.127 2023/12/19 20:08:27 rillig Exp $ +# $NetBSD: Makefile,v 1.128 2025/01/19 10:57:10 rillig Exp $ # @(#)Makefile 5.2 (Berkeley) 12/28/90 PROG= make @@ -28,6 +28,7 @@ WARNS= 6 USE_COVERAGE?= no # works only with gcc; clang9 fails to link .if ${USE_COVERAGE} == "yes" GCOV?= gcov +CPPFLAGS+= -DFORK_FUNCTION=fork COPTS+= --coverage -O0 -ggdb GCOV_PERL= if (/^File '(?:.*\/)?(\S+)'/) { GCOV_PERL+= $$file = $$1; $$func = ""; Index: src/usr.bin/make/compat.c diff -u src/usr.bin/make/compat.c:1.261 src/usr.bin/make/compat.c:1.262 --- src/usr.bin/make/compat.c:1.261 Sat Jul 20 11:05:11 2024 +++ src/usr.bin/make/compat.c Sun Jan 19 10:57:10 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.261 2024/07/20 11:05:11 rillig Exp $ */ +/* $NetBSD: compat.c,v 1.262 2025/01/19 10:57:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -91,7 +91,7 @@ #include "pathnames.h" /* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: compat.c,v 1.261 2024/07/20 11:05:11 rillig Exp $"); +MAKE_RCSID("$NetBSD: compat.c,v 1.262 2025/01/19 10:57:10 rillig Exp $"); static GNode *curTarg = NULL; static pid_t compatChild; @@ -203,7 +203,7 @@ UseShell(const char *cmd MAKE_ATTR_UNUSE static int Compat_Spawn(const char **av) { - int pid = vfork(); + int pid = FORK_FUNCTION(); if (pid < 0) Fatal("Could not fork"); Index: src/usr.bin/make/job.c diff -u src/usr.bin/make/job.c:1.484 src/usr.bin/make/job.c:1.485 --- src/usr.bin/make/job.c:1.484 Fri Jan 3 04:51:42 2025 +++ src/usr.bin/make/job.c Sun Jan 19 10:57:10 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.484 2025/01/03 04:51:42 rillig Exp $ */ +/* $NetBSD: job.c,v 1.485 2025/01/19 10:57:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -141,7 +141,7 @@ #include "trace.h" /* "@(#)job.c 8.2 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: job.c,v 1.484 2025/01/03 04:51:42 rillig Exp $"); +MAKE_RCSID("$NetBSD: job.c,v 1.485 2025/01/19 10:57:10 rillig Exp $"); /* * A shell defines how the commands are run. All commands for a target are @@ -1416,9 +1416,9 @@ JobExec(Job *job, char **argv) Var_ReexportVars(job->node); - cpid = vfork(); + cpid = FORK_FUNCTION(); if (cpid == -1) - Punt("Cannot vfork: %s", strerror(errno)); + Punt("Cannot fork: %s", strerror(errno)); if (cpid == 0) { /* Child */ Index: src/usr.bin/make/main.c diff -u src/usr.bin/make/main.c:1.636 src/usr.bin/make/main.c:1.637 --- src/usr.bin/make/main.c:1.636 Sat Nov 23 22:59:51 2024 +++ src/usr.bin/make/main.c Sun Jan 19 10:57:10 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.636 2024/11/23 22:59:51 rillig Exp $ */ +/* $NetBSD: main.c,v 1.637 2025/01/19 10:57:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -111,7 +111,7 @@ #include "trace.h" /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: main.c,v 1.636 2024/11/23 22:59:51 rillig Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.637 2025/01/19 10:57:10 rillig Exp $"); #if defined(MAKE_NATIVE) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -1780,7 +1780,7 @@ Cmd_Exec(const char *cmd, char **error) Var_ReexportVars(SCOPE_GLOBAL); - switch (cpid = vfork()) { + switch (cpid = FORK_FUNCTION()) { case 0: (void)close(pipefds[0]); (void)dup2(pipefds[1], STDOUT_FILENO); Index: src/usr.bin/make/make.h diff -u src/usr.bin/make/make.h:1.348 src/usr.bin/make/make.h:1.349 --- src/usr.bin/make/make.h:1.348 Sat Jan 11 21:21:33 2025 +++ src/usr.bin/make/make.h Sun Jan 19 10:57:10 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.348 2025/01/11 21:21:33 rillig Exp $ */ +/* $NetBSD: make.h,v 1.349 2025/01/19 10:57:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -178,6 +178,15 @@ typedef unsigned char bool; #define false 0 #endif +/* + * In code coverage mode with gcc>=12, calling vfork/exec does not mark any + * further code from the parent process as covered. gcc-10.5.0 is fine, as + * are fork/exec calls, as well as posix_spawn. + */ +#ifndef FORK_FUNCTION +#define FORK_FUNCTION vfork +#endif + #include "lst.h" #include "make_malloc.h" #include "str.h"