[v2,gdb/build] Fix build breaker on mingw-w64

Message ID 20241203091352.8465-1-tdevries@suse.de
State Superseded
Headers
Series [v2,gdb/build] Fix build breaker on mingw-w64 |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Tom de Vries Dec. 3, 2024, 9:13 a.m. UTC
  From: Simon Marchi <simark@simark.ca>

The mingw-w64 build breaks currently:
...
    In file included from gdb/cli/cli-cmds.c:58:
    gdbsupport/eintr.h: In function ‘pid_t gdb::waitpid(pid_t, int*, int)’:
    gdbsupport/eintr.h:77:35: error: ‘::waitpid’ has not been declared; \
                                     did you mean ‘gdb::waitpid’?
       77 |   return gdb::handle_eintr (-1, ::waitpid, pid, wstatus, options);
          |                                   ^~~~~~~
          |                                   gdb::waitpid
    gdbsupport/eintr.h:75:1: note: ‘gdb::waitpid’ declared here
       75 | waitpid (pid_t pid, int *wstatus, int options)
          | ^~~~~~~
...

This is a regression since commit 658a03e9e85 ("[gdbsupport] Add
gdb::{waitpid,read,write,close}"), which moved the use of ::waitpid from
run_under_shell, where it was used conditionally:
...
 #if defined(CANT_FORK) || \
       (!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK))
   ...
   ...
       int ret = gdb::handle_eintr (-1, ::waitpid, pid, &status, 0);
...
to gdb::waitpid, where it's used unconditionally:
...
inline pid_t
waitpid (pid_t pid, int *wstatus, int options)
{
  return gdb::handle_eintr (-1, ::waitpid, pid, wstatus, options);
}
...

Likewise for ::wait.

Guard these uses with HAVE_WAITPID and HAVE_WAIT.

Reproduced and tested by doing a mingw-w64 cross-build on x86_64-linux.
---
 gdb/config.in        | 3 +++
 gdb/configure        | 3 ++-
 gdb/configure.ac     | 1 -
 gdbserver/config.in  | 6 ++++++
 gdbserver/configure  | 2 ++
 gdbsupport/common.m4 | 2 ++
 gdbsupport/config.in | 6 ++++++
 gdbsupport/configure | 2 ++
 gdbsupport/eintr.h   | 4 ++++
 9 files changed, 27 insertions(+), 2 deletions(-)


base-commit: 98439a80cce3ba652ef4bd4cc69c0b7a04c2c60e
  

Comments

Tom Tromey Dec. 3, 2024, 5:47 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> Guard these uses with HAVE_WAITPID and HAVE_WAIT.

Tom> Reproduced and tested by doing a mingw-w64 cross-build on x86_64-linux.

Looks good to me.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Tom de Vries Dec. 4, 2024, 1:30 p.m. UTC | #2
On 12/3/24 18:47, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> Guard these uses with HAVE_WAITPID and HAVE_WAIT.
> 
> Tom> Reproduced and tested by doing a mingw-w64 cross-build on x86_64-linux.
> 
> Looks good to me.
> Approved-By: Tom Tromey <tom@tromey.com>

Hi Tom,

thanks for the review.

Given your comment in the v1 thread about common-defs.h including 
gdbsupport/config.h, I've written a more minimal version that adds 
HAVE_WAITPID and HAVE_WAIT only in gdbsupport, and submitted as v3 ( 
https://sourceware.org/pipermail/gdb-patches/2024-December/213783.html ).

Thanks,
- Tom
  

Patch

diff --git a/gdb/config.in b/gdb/config.in
index 187b42ca29b..1b517f035f7 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -586,6 +586,9 @@ 
 /* Define to 1 if you have the <vfork.h> header file. */
 #undef HAVE_VFORK_H
 
+/* Define to 1 if you have the `wait' function. */
+#undef HAVE_WAIT
+
 /* Define to 1 if you have the `waitpid' function. */
 #undef HAVE_WAITPID
 
diff --git a/gdb/configure b/gdb/configure
index 138c2a153b7..7fd52844d7e 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -20065,6 +20065,8 @@  fi
     sigprocmask \
     sigtimedwait \
     socketpair \
+    wait \
+    waitpid \
 
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
@@ -29924,7 +29926,6 @@  for ac_func in  \
   sigsetmask \
   ttrace \
   use_default_colors \
-  waitpid \
   wresize \
 
 do :
diff --git a/gdb/configure.ac b/gdb/configure.ac
index d638b8f3c8e..230c0be79c7 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1389,7 +1389,6 @@  AC_CHECK_FUNCS([ \
   sigsetmask \
   ttrace \
   use_default_colors \
-  waitpid \
   wresize \
 ])
 
diff --git a/gdbserver/config.in b/gdbserver/config.in
index 65f9ff6e647..53aecf4afc4 100644
--- a/gdbserver/config.in
+++ b/gdbserver/config.in
@@ -393,6 +393,12 @@ 
 /* Define to 1 if you have the <vfork.h> header file. */
 #undef HAVE_VFORK_H
 
+/* Define to 1 if you have the `wait' function. */
+#undef HAVE_WAIT
+
+/* Define to 1 if you have the `waitpid' function. */
+#undef HAVE_WAITPID
+
 /* Define to 1 if you have the <wait.h> header file. */
 #undef HAVE_WAIT_H
 
diff --git a/gdbserver/configure b/gdbserver/configure
index 32980e5017e..48cbaccc4eb 100755
--- a/gdbserver/configure
+++ b/gdbserver/configure
@@ -8772,6 +8772,8 @@  fi
     sigprocmask \
     sigtimedwait \
     socketpair \
+    wait \
+    waitpid \
 
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
diff --git a/gdbsupport/common.m4 b/gdbsupport/common.m4
index 54290cc85e7..4d4060322bf 100644
--- a/gdbsupport/common.m4
+++ b/gdbsupport/common.m4
@@ -82,6 +82,8 @@  AC_CHECK_HEADERS([ \
     sigprocmask \
     sigtimedwait \
     socketpair \
+    wait \
+    waitpid \
   ])
 
   # This is needed for RHEL 5 and uclibc-ng < 1.0.39.
diff --git a/gdbsupport/config.in b/gdbsupport/config.in
index 8467072752a..0beacf22c05 100644
--- a/gdbsupport/config.in
+++ b/gdbsupport/config.in
@@ -319,6 +319,12 @@ 
 /* Define to 1 if you have the <vfork.h> header file. */
 #undef HAVE_VFORK_H
 
+/* Define to 1 if you have the `wait' function. */
+#undef HAVE_WAIT
+
+/* Define to 1 if you have the `waitpid' function. */
+#undef HAVE_WAITPID
+
 /* Define to 1 if you have the <wait.h> header file. */
 #undef HAVE_WAIT_H
 
diff --git a/gdbsupport/configure b/gdbsupport/configure
index 87980f6870f..0d994933b7d 100755
--- a/gdbsupport/configure
+++ b/gdbsupport/configure
@@ -11546,6 +11546,8 @@  fi
     sigprocmask \
     sigtimedwait \
     socketpair \
+    wait \
+    waitpid \
 
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
diff --git a/gdbsupport/eintr.h b/gdbsupport/eintr.h
index 3980e3f5ac1..4cab8f9d48d 100644
--- a/gdbsupport/eintr.h
+++ b/gdbsupport/eintr.h
@@ -71,11 +71,13 @@  handle_eintr (ErrorValType errval, const Fun &f, const Args &... args)
   return ret;
 }
 
+#ifdef HAVE_WAITPID
 inline pid_t
 waitpid (pid_t pid, int *wstatus, int options)
 {
   return gdb::handle_eintr (-1, ::waitpid, pid, wstatus, options);
 }
+#endif /* HAVE_WAITPID */
 
 inline int
 open (const char *pathname, int flags)
@@ -83,11 +85,13 @@  open (const char *pathname, int flags)
   return gdb::handle_eintr (-1, ::open, pathname, flags);
 }
 
+#ifdef HAVE_WAIT
 inline pid_t
 wait (int *wstatus)
 {
   return gdb::handle_eintr (-1, ::wait, wstatus);
 }
+#endif /* HAVE_WAIT */
 
 inline int
 close (int fd)