Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tromey@adacore.com>
Cc: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/3] Consistently use BFD's time
Date: Sat, 20 Jun 2020 00:05:53 +0100	[thread overview]
Message-ID: <07179329-a5ac-6947-7303-c0d7b919aa39@redhat.com> (raw)
In-Reply-To: <87k102vm5y.fsf@tromey.com>

On 6/19/20 9:24 PM, Tom Tromey wrote:
> Tom> I rebased the stat branch and I'll integrate my patches into it today.
> 
> I couldn't make this work.  The previous patch worked because, at the
> time, common-defs.h could include bfd.h relatively early.  That's no
> longer the case, and after trying a number of things I found that
> perhaps this double inclusion interferes with some system headers
> somehow. 

> I'm not sure what to do.  Maybe I can try namespacing just sys/stat.h?

Can you clarify what do you see not work?  I tried rebasing it
here, and it seems to work.  It builds cleanly on GNU/Linux and
mingw32-w64 (both -m64 and -m32).  I've pasted the resulting patch below.

I've also added an #error in case something pulls in sys/stat.h before
we get to defs.h.  I think that if that happens due to some include
in common-defs.h pulling sys/stat.h (say, libiberty.h ever exports some
API using struct stat), then it would likely be exposing a problem
similar to the bfd.h one, in that we should be calling such an API
with the stat that libiberty was built against.  Hopefully that won't
happen -- external interfaces using "struct stat" are a really bad idea,
as this whole thread shows...

I think I'd still like to try to understand why the --avoid=largefile
solution doesn't work though.

From fd8d185820e572dcff6fbfe2e65cd5b79cef86f3 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Fri, 19 Jun 2020 23:09:10 +0100
Subject: [PATCH] Handle different "struct stat" between GDB and BFD

---
 gdb/defs.h    | 19 +++++++++++++++++++
 gdb/gdb_bfd.c | 45 +++++++++++++++++++++++++++++++++++++++++----
 gdb/gdb_bfd.h |  2 +-
 gdb/jit.c     |  4 ++--
 gdb/symfile.c |  2 +-
 5 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/gdb/defs.h b/gdb/defs.h
index a75511158a4..b8723dccd12 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -34,8 +34,27 @@
 #undef PACKAGE_TARNAME
 
 #include <config.h>
+
+/* Gnulib may replace struct stat with its own version.  Bfd does not
+   use gnulib, so when we call into bfd, we must use the system struct
+   stat.  */
+
+#ifdef _GL_SYS_STAT_H
+# error "gnulib's <sys/stat.h> included too early"
+#endif
+
+#define __need_system_sys_stat_h 1
+
+#include <sys/stat.h>
+
 #include "bfd.h"
 
+typedef struct stat sys_stat;
+
+#undef __need_system_sys_stat_h
+
+#include <sys/stat.h>
+
 #include <sys/types.h>
 #include <limits.h>
 
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 25e0178a8b8..6026a6b7dbe 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -66,7 +66,7 @@ struct gdb_bfd_data
       needs_relocations (0),
       crc_computed (0)
   {
-    struct stat buf;
+    sys_stat buf;
 
     if (bfd_stat (abfd, &buf) == 0)
       {
@@ -361,24 +361,61 @@ gdb_bfd_iovec_fileio_close (struct bfd *abfd, void *stream)
   return 0;
 }
 
+/* Convert between a struct stat (potentially a gnulib replacement)
+   and a sys_stat (the system's struct stat).  */
+
+static sys_stat
+to_sys_stat (struct stat *st)
+{
+  sys_stat sst {};
+
+#define COPY(FIELD) \
+  sst.FIELD = st->FIELD
+
+  COPY (st_dev);
+  COPY (st_ino);
+  COPY (st_mode);
+  COPY (st_nlink);
+  COPY (st_uid);
+  COPY (st_gid);
+  COPY (st_rdev);
+
+  /* Check for overflow?  */
+  COPY (st_size);
+
+  // Should probably check _GL_WINDOWS_STAT_TIMESPEC and refer to
+  // st_atim, etc. instead.
+  COPY (st_atime);
+  COPY (st_mtime);
+  COPY (st_ctime);
+
+#undef COPY
+
+  return sst;
+}
+
 /* Wrapper for target_fileio_fstat suitable for passing as the
    STAT_FUNC argument to gdb_bfd_openr_iovec.  */
 
 static int
 gdb_bfd_iovec_fileio_fstat (struct bfd *abfd, void *stream,
-			    struct stat *sb)
+			    sys_stat *sb)
 {
   int fd = *(int *) stream;
   int target_errno;
   int result;
 
-  result = target_fileio_fstat (fd, sb, &target_errno);
+  struct stat st;
+
+  result = target_fileio_fstat (fd, &st, &target_errno);
   if (result == -1)
     {
       errno = fileio_errno_to_host (target_errno);
       bfd_set_error (bfd_error_system_call);
     }
 
+  *sb = to_sys_stat (&st);
+
   return result;
 }
 
@@ -826,7 +863,7 @@ gdb_bfd_openr_iovec (const char *filename, const char *target,
 					void *stream),
 		     int (*stat_func) (struct bfd *abfd,
 				       void *stream,
-				       struct stat *sb))
+				       sys_stat *sb))
 {
   bfd *result = bfd_openr_iovec (filename, target,
 				 open_func, open_closure,
diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
index a941b79fe73..8eb44f5ea20 100644
--- a/gdb/gdb_bfd.h
+++ b/gdb/gdb_bfd.h
@@ -158,7 +158,7 @@ gdb_bfd_ref_ptr gdb_bfd_openr_iovec (const char *filename, const char *target,
 							void *stream),
 				     int (*stat_func) (struct bfd *abfd,
 						       void *stream,
-						       struct stat *sb));
+						       sys_stat *sb));
 
 /* A wrapper for bfd_openr_next_archived_file that initializes the
    gdb-specific reference count.  */
diff --git a/gdb/jit.c b/gdb/jit.c
index 1b5ef46469e..bb59dafb126 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -124,11 +124,11 @@ mem_bfd_iovec_pread (struct bfd *abfd, void *stream, void *buf,
 /* For statting the file, we only support the st_size attribute.  */
 
 static int
-mem_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb)
+mem_bfd_iovec_stat (struct bfd *abfd, void *stream, sys_stat *sb)
 {
   struct target_buffer *buffer = (struct target_buffer*) stream;
 
-  memset (sb, 0, sizeof (struct stat));
+  memset (sb, 0, sizeof (sys_stat));
   sb->st_size = buffer->size;
   return 0;
 }
diff --git a/gdb/symfile.c b/gdb/symfile.c
index b29f864b373..a00f04697ad 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1257,7 +1257,7 @@ separate_debug_file_exists (const std::string &name, unsigned long crc,
 {
   unsigned long file_crc;
   int file_crc_p;
-  struct stat parent_stat, abfd_stat;
+  sys_stat parent_stat, abfd_stat;
   int verified_as_different;
 
   /* Find a separate debug info file as if symbols would be present in

base-commit: 87f83f20023bf366c14ec4e0fd307948d96caaee
-- 
2.14.5



  reply	other threads:[~2020-06-19 23:05 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-14 21:10 [PATCH 0/3] Fix gdb's BFD cache Tom Tromey
2020-01-14 21:10 ` [PATCH 2/3] Consistently use BFD's time Tom Tromey
2020-01-14 23:17   ` Christian Biesinger via gdb-patches
2020-01-15 17:51   ` Eli Zaretskii
2020-01-16 20:47     ` Pedro Alves
2020-01-16 21:58       ` Christian Biesinger via gdb-patches
2020-01-16 22:31         ` Pedro Alves
2020-01-17  8:48         ` Eli Zaretskii
2020-01-17 18:32           ` Tom Tromey
2020-01-17 21:03             ` Tom Tromey
2020-01-18 11:07               ` Eli Zaretskii
2020-01-20 15:52                 ` Pedro Alves
2020-01-20 15:53                   ` Pedro Alves
2020-01-20 20:50                   ` Eli Zaretskii
2020-01-20 20:58                     ` Pedro Alves
2020-01-21 15:50                       ` Pedro Alves
2020-01-21 19:38                         ` Eli Zaretskii
2020-01-21 17:56                       ` Eli Zaretskii
2020-01-23 22:05                   ` Tom Tromey
2020-06-19 17:51                   ` Tom Tromey
2020-04-01 20:20       ` Tom Tromey
2020-06-18 14:14     ` Tom Tromey
2020-06-18 15:04       ` Eli Zaretskii
2020-06-18 16:00         ` Tom Tromey
2020-06-18 17:27           ` Eli Zaretskii
2020-06-18 17:32             ` Pedro Alves
2020-06-18 17:54               ` Eli Zaretskii
2020-06-19 12:02                 ` Pedro Alves
2020-06-19 12:13                   ` Eli Zaretskii
2020-06-19 17:09                   ` Tom Tromey
2020-06-19 20:24                     ` Tom Tromey
2020-06-19 23:05                       ` Pedro Alves [this message]
2020-07-21 19:39                         ` Tom Tromey
2020-07-28 19:31                         ` Tom Tromey
2020-08-13 12:15                           ` Tom de Vries
2020-08-14 23:40                             ` Joel Brobecker
2020-08-23 16:09                               ` Joel Brobecker
2020-08-23 23:32                                 ` Pedro Alves
2020-08-24 20:04                                   ` Joel Brobecker
2020-09-02 14:45                                     ` Tom Tromey
2020-09-02 14:59                                       ` Joel Brobecker
2020-06-18 17:57               ` Tom Tromey
2020-01-14 21:10 ` [PATCH 1/3] Avoid hash table corruption in gdb_bfd.c Tom Tromey
2020-01-14 22:26   ` Christian Biesinger via gdb-patches
2020-01-14 22:13 ` [PATCH 3/3] Further simplify gdb BFD caching Tom Tromey
2020-01-23 22:30   ` Tom Tromey
2020-09-02 18:45     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=07179329-a5ac-6947-7303-c0d7b919aa39@redhat.com \
    --to=palves@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox