From: Eli Zaretskii <eliz@gnu.org>
To: Pedro Alves <palves@redhat.com>
Cc: tromey@adacore.com, cbiesinger@google.com, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/3] Consistently use BFD's time
Date: Tue, 21 Jan 2020 17:56:00 -0000 [thread overview]
Message-ID: <83wo9kvhlu.fsf@gnu.org> (raw)
In-Reply-To: <40fa6532-4440-d47b-63db-9485828c791f@redhat.com> (message from Pedro Alves on Mon, 20 Jan 2020 20:50:17 +0000)
> Cc: tromey@adacore.com, cbiesinger@google.com, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Mon, 20 Jan 2020 20:50:17 +0000
>
> >> I'm not sure about that solution -- won't --avoid=stat mean that
> >> we disable any stat gnulib fix for all platforms, instead of just
> >> for Windows?
> >
> > It would, but do we have any known problems with stat and fstat on
> > other platforms?
>
> There's the list of known problems in the gnulib pages:
>
> https://www.gnu.org/software/gnulib/manual/html_node/fstat.html
This one is only about Solaris problems with st_mtime etc. (MSVC
problems are of no concern to us.)
> https://www.gnu.org/software/gnulib/manual/html_node/stat.html
Is the trailing slash issue important for GDB?
> https://www.gnu.org/software/gnulib/manual/html_node/lstat.html
Likewise.
All in all, the gain sounds small to me, if at all.
> >> We only have one lstat call, but we also use fstat, for example, and
> >> I assume that these *stat modules in gnulib are all intertwined.
> >> Also, we may only have one lstat call nowadays, but who knows about
> >> the future.
> >
> > Even having a gdb_lstat for that purpose will be simpler and more
> > future-proof than the whole Gnulib stat module, I think.
>
> I think one could use that argument for any piece of gnulib in
> isolation.
I wouldn't say "any piece", there are some functions there with very
non-trivial guts. But yes, the impact of Gnulib IME is mostly
important where it provides missing functions, not where it replaces
existing ones.
> But fighting against use of some particular modules ends up creating
> a larger burden over time IMO. I'd rather avoid doing that if
> possible.
Sure, this goes without saying. I was just considering this as one
alternative, since we don't seem to have a much better one. Or do we?
> extern int bfd_stat (bfd *, struct rpl_stat *);
>
> This is incorrect, because that bfd function was not defined
> that way. It is instead written as:
>
> extern int bfd_stat (bfd *, struct stat *);
>
> Given the stat replacement, we pass it a rpl_stat pointer, when it
> is in reality expecting a "struct stat" one (or whatever that expands
> in the system headers). So we get undefined behavior at run time.
>
> By defining __need_system_sys_stat_h just before bfd.h is included,
> we're sure that bfd's bfd_stat is declared with the system's
> stat, just like when bfd itself was compiled.
>
> extern int bfd_stat (bfd *, struct stat *);
>
> We undef __need_system_sys_stat_h again just after including
> "bfd.h", so that the gdb uses the gnulib struct stat. But we
> also create the sys_stat typedef so that we can refer to the
> system's stat type after __need_system_sys_stat_h is undefined
> and gnulib's stat replacement is visible.
>
> So the *stat functions will be shadowed by the gnulib ones
> within gdb, yes. But we also get a compile error if we
> call bfd_stat with a masked struct stat:
OK, I see. This would work, of course, but IME solutions based on
specific order of inclusion of header files are fragile, and break
easily, because header files tend to include other header files and
break the order you carefully observed. But if there's no better
alternative, perhaps this is the way to go.
> > Also, aren't some of the problems on platforms other than MinGW
> > resolved by the Gnulib sys/stat.h header, as opposed to the
> > replacement implementation of the functions themselves?
>
> Some yes, but not all. But it's the sys/stat.h header replacement
> that redefines struct stat, so I don't see the point you're making.
And you are sure that including first the system's stat.h and then the
Gnulib's version of it will never cause any compilation problems?
Also, if GDB uses values based on what bfd_stat retrieves, then these
values might be different from what the Gnulib replacement stat
retrieves in GDB's own code for the same file (due to size of the
fields), right? Are we sure we never compare those expecting them to
match for the same file?
> So perhaps what we need is to enable largefile support by
> default on bfd for mingw, to force use of the 64-bit stat?
> Does the original issue go away if you configure
> with --enable-largefile? Maybe we need a mingw-specific
> tweak in gdb's src/config/largefile.m4?
>
> Looking my mingw-w64's stat.h, I see:
>
> #if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
> #ifdef _USE_32BIT_TIME_T
> #define stat _stat32i64
> #define fstat _fstat32i64
> #else
> #define stat _stat64
> #define fstat _fstat64
> #endif
> #endif
>
> So if BFD is compiled with _FILE_OFFSET_BITS == 64 and
> _USE_32BIT_TIME_T is not defined, the mismatch ends up going
> away? Is there a reason we _wouldn't_ want to enable largefile
> support in bfd?
That's a non-starter for me, as I will explain in response to your
further message.
next prev parent reply other threads:[~2020-01-21 17:34 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 [this message]
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
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=83wo9kvhlu.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=cbiesinger@google.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--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