[binutils-gdb] [gdb/build] Silence Wdeprecated-declarations for vfork
Tom de Vries
vries@sourceware.org
Tue Dec 1 21:10:23 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8deb68c863929741c1c887453c18573e1eb6cfea
commit 8deb68c863929741c1c887453c18573e1eb6cfea
Author: Tom de Vries <tdevries@suse.de>
Date: Tue Dec 1 22:10:19 2026 +0100
[gdb/build] Silence Wdeprecated-declarations for vfork
On macOS I ran into:
...
src/gdb/cli/cli-cmds.c:914:20: warning: 'pid_t vfork()' is deprecated: \
Use posix_spawn or fork [-Wdeprecated-declarations]
src/gdb/ser-pipe.c:83:15: warning: 'pid_t vfork()' is deprecated: \
Use posix_spawn or fork [-Wdeprecated-declarations]
...
due to vfork being deprecated. This breaks the build unless I build with
--disable-werror.
Also on Solaris, vfork is deprecated, and because of it we have this in
gdbsupport/warning.m4:
...
case "${host}" in
*-*-solaris*)
...
# Solaris 11 <unistd.h> marks vfork deprecated.
build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
...
The problems with this solution are that:
- it not just disables Wdeprecated-declarations for vfork, it does so for all
deprecated declarations.
- it needs per-host enabling
Fix this by:
- disabling Wdeprecated-declarations just for vfork, and
- for all hosts.
I considered using a statement expression in a macro gdb_vfork:
...
#define gdb_vfork() ({ \
DIAGNOSTIC_PUSH \
DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
pid_t gdb_vfork_result_ = vfork (); \
DIAGNOSTIC_POP \
gdb_vfork_result_;})
...
but there's no precedent in the gdb sources other than in gnu-nat.c.
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34982
Diff:
---
gdb/cli/cli-cmds.c | 9 ++++++++-
gdb/nat/fork-inferior.c | 10 +++++++++-
gdb/ser-pipe.c | 8 +++++++-
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 9ed0b8b4ffe..dfc41b45b7d 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -60,6 +60,7 @@
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/eintr.h"
#include "gdbsupport/scoped_ignore_signal.h"
+#include "diagnostics.h"
#ifdef TUI
#include "tui/tui.h"
@@ -911,7 +912,13 @@ run_under_shell (const char *arg, int from_tty)
#else /* Can fork. */
int status, pid;
- if ((pid = vfork ()) == 0)
+ /* On some hosts (like macOS and Solaris) vfork is deprecated, so ignore the
+ corresponding Wdeprecated-declarations. */
+ DIAGNOSTIC_PUSH
+ DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
+ pid = vfork ();
+ DIAGNOSTIC_POP
+ if (pid == 0)
{
const char *p, *user_shell = get_shell ();
diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c
index 1c125881496..c31b0a80644 100644
--- a/gdb/nat/fork-inferior.c
+++ b/gdb/nat/fork-inferior.c
@@ -29,6 +29,7 @@
#include "gdbsupport/gdb_signals.h"
#include "gdbsupport/buildargv.h"
#include "gdbsupport/gdb_argv_vec.h"
+#include "diagnostics.h"
#include <vector>
extern char **environ;
@@ -305,7 +306,14 @@ fork_inferior (const char *exec_file, const std::string &allargs, char **env,
pid = fork ();
else
#endif
- pid = vfork ();
+ {
+ /* On some hosts (like macOS and Solaris) vfork is deprecated, so ignore
+ the corresponding Wdeprecated-declarations. */
+ DIAGNOSTIC_PUSH
+ DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
+ pid = vfork ();
+ DIAGNOSTIC_POP
+ }
if (pid < 0)
perror_with_name (("vfork"));
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index 3b755a84860..a0741854a02 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -30,6 +30,7 @@
#include <fcntl.h>
#include "gdbsupport/filestuff.h"
#include "gdbsupport/pathstuff.h"
+#include "diagnostics.h"
#include <signal.h>
@@ -79,8 +80,13 @@ pipe_open (struct serial *scb, const char *name)
/* Create the child process to run the command in. Note that the
apparent call to vfork() below *might* actually be a call to
fork() due to the fact that autoconf will ``#define vfork fork''
- on certain platforms. */
+ on certain platforms.
+ On some hosts (like macOS and Solaris) vfork is deprecated, so ignore the
+ corresponding Wdeprecated-declarations. */
+ DIAGNOSTIC_PUSH
+ DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
pid = vfork ();
+ DIAGNOSTIC_POP
/* Error. */
if (pid == -1)
More information about the Gdb-cvs
mailing list