]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: include sys/stat.h for 'struct stat'
authorAndrew Burgess <aburgess@redhat.com>
Mon, 23 Jun 2025 12:45:02 +0000 (13:45 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 23 Jun 2025 13:11:20 +0000 (14:11 +0100)
Tom de Vries reported a build failure on x86_64-w64-mingw32 after
commit:

  commit bd389c9515d240f55b117075b43184efdea41287
  Date:   Wed Jun 11 22:52:16 2025 +0200

      gdb: implement linux namespace support for fileio_lstat and vFile::lstat

The build failure looks like this:

  ../../src/gdbserver/hostio.cc: In function 'void handle_lstat(char*, int*)':
  ../../src/gdbserver/hostio.cc:544:63: error: cannot convert '_stat64*' to 'stat*'
    544 |     ret = the_target->multifs_lstat (hostio_fs_pid, filename, &st);
        |                                                               ^~~
        |                                                               |
        |                                                               _stat64*
  In file included from ./../../src/gdbserver/server.h:58,
                   from <command-line>:
  ./../../src/gdbserver/target.h:448:74: note:   initializing argument 3 of 'virtual int process_stratum_target::multifs_lstat(int, const char*, stat*)'
    448 |   virtual int multifs_lstat (int pid, const char *filename, struct stat *sb);
        |                                                             ~~~~~~~~~~~~~^~

The problem is that in sys/stat.h for mingw, 'stat' is #defined to
_stat64, but target.h doesn't include sys/stat.h, and so doesn't see
this #define.

However, target.h does, by luck, manages to see the actual definition
of 'struct stat', which isn't in sys/stat.h itself, but is in some
other header that just happens to be pulled in by chance.

As a result of all this, the declaration of
process_stratum_target::multifs_lstat in target.h uses 'struct stat'
for its argument type, while the call in hostio.cc, uses 'struct
_stat64' as its argument type, which causes the build error seen
above.

The fix is to include sys/stat.h in target.h so that the declaration's
argument type will change to 'struct _stat64' (via the #define).

gdbserver/target.h

index 4d3f80f736d9d43c6e8b2fffc2e0a7f1fca56c56..66ca72fec17ef16b5aa094c060b617813590b6fd 100644 (file)
@@ -31,6 +31,7 @@
 #include "gdbsupport/btrace-common.h"
 #include <vector>
 #include "gdbsupport/byte-vector.h"
+#include <sys/stat.h>
 
 struct emit_ops;
 struct process_info;