public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Alexander Kanavin <alex.kanavin@gmail.com>
To: Mark Wielaard <mark@klomp.org>
Cc: elfutils-devel@sourceware.org, Khem Raj <raj.khem@gmail.com>
Subject: Re: [PATCH] debuginfod/debuginfod-client.c: correct string format on 32bit arches with 64bit time_t
Date: Sun, 5 Dec 2021 21:45:31 +0100	[thread overview]
Message-ID: <CANNYZj_60XCnxScjkni33oKHXF8hs0Lm0X8XW4j=u1oFB75U5A@mail.gmail.com> (raw)
In-Reply-To: <Ya0hj3HSrSI0Ff49@wildebeest.org>

I'm not sure; the point of this patch is simply to ensure debuginfod builds
everywhere without errors. Making the types consistent is perhaps better
done as a followup?

Alex

On Sun, 5 Dec 2021 at 21:31, Mark Wielaard <mark@klomp.org> wrote:

> Hi,
>
> On Sun, Nov 21, 2021 at 11:14:11PM +0100, Alexander Kanavin via
> Elfutils-devel wrote:
> > From: Alexander Kanavin <alex.kanavin@gmail.com>
> >
> > Use intmax_t to print time_t
> >
> > time_t is platform dependent and some of architectures e.g.
> > x32, riscv32, arc use 64bit time_t even while they are 32bit
> > architectures, therefore directly using integer printf formats will not
> > work portably, use intmax_t to typecast time_t into printf family of
> > functions.
>
> OK, so there were some questions about whether using intmax_t and %jd
> are portable enough, but I think it is clear that everything these
> days support that. So that is good.
>
> > musl 1.2.0 and above uses time64 on all platforms; glibc 2.34 has added
> support for
> > time64 (which might be enabled by distro-wide CFLAGS), with possibly
> > 2.35 or 2.36 making it enabled by default.
> >
> > Use a plain int for scanning cache_config, as that's what the function
> > returns.
>
> So I think you are correct that printing/scanning/casting the time_t
> around is somewhat unfortunate because the size of time_t is not
> stable across architectures. Thanks for looking into this. I had no
> idea time_t was such a problematic data type.
>
> What makes it even more curious is that debuginfod_config_cache takes
> a long, not a time_t, while it is always called with a time_t
> argument. And then it returns an int... The result is interpreted as a
> negative errno number or is cast back to a time_t if it is positive.
>
> With this patch we write out the interval values "as big as possible"
> (intmax_t), but read it back in "as small as possible" (int). Would it
> make sense to also try to read it back in as intmax_t and then cast
> down to int? Or simply always cast down to int before writing it out,
> so reading and writing use the same data type?
>
> We seem to not expect these intervals to be much bigger than a week,
> so an int should always be big enough (even when stretched up to a
> whole year).
>
> Thanks,
>
> Mark
>

  reply	other threads:[~2021-12-05 20:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-21 22:14 Alexander Kanavin
2021-11-25 17:51 ` Frank Ch. Eigler
2021-11-25 18:50   ` Alexander Kanavin
2021-11-25 19:24     ` Frank Ch. Eigler
2021-12-05 20:31 ` Mark Wielaard
2021-12-05 20:45   ` Alexander Kanavin [this message]
2021-12-08 15:31     ` Mark Wielaard
2021-12-09  9:52       ` Alexander Kanavin
2021-12-09  0:56   ` Frank Ch. Eigler
  -- strict thread matches above, loose matches on Subject: below --
2021-11-19 18:15 Alexander Kanavin
2021-11-20  3:57 ` Érico Nogueira
2021-11-20  8:11   ` Alexander Kanavin
2021-11-20 14:41     ` Khem Raj

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='CANNYZj_60XCnxScjkni33oKHXF8hs0Lm0X8XW4j=u1oFB75U5A@mail.gmail.com' \
    --to=alex.kanavin@gmail.com \
    --cc=elfutils-devel@sourceware.org \
    --cc=mark@klomp.org \
    --cc=raj.khem@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).