From: Dominique Martinet <asmadeus@codewreck.org>
To: linux-api@vger.kernel.org, libc-alpha@sourceware.org
Cc: Quentin Bouget <quentin.bouget@cea.fr>,
Jeff Layton <jlayton@kernel.org>,
David Howells <dhowells@redhat.com>,
Florian Weimer <fweimer@redhat.com>
Subject: statx struct's stx_size pointer compatibility with uint64_t/size_t
Date: Tue, 17 Dec 2019 16:21:54 +0100 [thread overview]
Message-ID: <20191217152154.GB25518@nautica> (raw)
In-Reply-To: <87r213aykv.fsf@oldenburg2.str.redhat.com>
I originally asked this on libc-help@, Florian redirected me to
linux-api@ and libc-alpha@; resending my first mail and quoting his
reply at the end.
A coworker ran into an incompatible-pointer-type compiler warning when
trying to pass &statxbuf.stx_size to a function expecting a size_t *,
which boils down to this:
-------------
#define _GNU_SOURCE
#include <stdint.h>
#include <sys/stat.h>
static void test(uint64_t *size) {
(void)size;
}
int main() {
struct statx statxbuf;
test(&statxbuf.stx_size);
return 0;
}
-------------
Giving this warning:
-------------
t.c: In function ‘main’:
t.c:12:10: warning: passing argument 1 of ‘test’ from incompatible
pointer type [-Wincompatible-pointer-types]
12 | test(&statxbuf.stx_size);
| ^~~~~~~~~~~~~~~~~~
| |
| __u64 * {aka long long unsigned int *}
t.c:5:28: note: expected ‘uint64_t *’ {aka ‘long unsigned int *’} but
argument is of type ‘__u64 *’ {aka ‘long long unsigned int *’}
5 | static void test(uint64_t *size) {
| ~~~~~~~~~~^~~~
-------------
(same happens with size_t)
The final warning is probably some standard defining long and long long
cannot be treated as compatible even on archs where it is, but it's a
bit of a shame that manipulating __u64 and uint64_t yield such errors
when passing pointers around -- the types pretty much guarantee they
have to be compatible and it is just an arbitrary choice that made one
be long and the other long long on x86_64 unless I misunderstood
something?
I'm a bit at loss of what to advise here.
We need to pass the value as a pointer because it can be updated, our
use case is that the symlink size can be wrong in /proc/x/fd/ and we
will want the correct value back in a statx struct here[1].
What would be the "recommended" way of doing this?
Any chance the field could change to be uint64_t-compatible in the
future? Not sure what that implies regarding e.g. backwards
compatibility though...
[1] https://github.com/cea-hpc/robinhood/blob/1ed74893c088d78783acd2e25e8009a483510ff7/src/backends/posix.c#L248
Florian Weimer wrote on Tue, Dec 17, 2019:
> * Dominique Martinet:
> > What would be the "recommended" way of doing this?
> > Any chance the field could change to be uint64_t-compatible in the
> > future? Not sure what that implies regarding e.g. backwards
> > compatibility though...
>
> This is a tricky subject. We already have a copy of the type with
> uint64_t fields in the installed glibc headers, but this is only used
> if the kernel definition is not available.
>
> We do not want to duplicate kernel headers too much because it causes
> problems if both glibc headers and kernel headers are included in the
> same translation unit. That in turn makes it difficult to use new
> kernel features by only updating the kernel headers.
>
> I do not know why the kernel definition of __u64 does not follow that
> of uint64_t in <stdint.h> (or why we even have that __u64 type), and
> whether the kernel definition can be changed at this point. We can
> fix this issue with preprocessor magic, but I am not entirely sure if
> this is a good idea.
Thanks,
--
Dominique
next parent reply other threads:[~2019-12-17 15:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87r213aykv.fsf@oldenburg2.str.redhat.com>
2019-12-17 15:21 ` Dominique Martinet [this message]
2019-12-17 16:53 ` statx struct's stx_size pointer compatibility with uint64_t/size_t Dominique Martinet
2019-12-18 11:51 ` Florian Weimer
2019-12-17 18:17 ` David Howells
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=20191217152154.GB25518@nautica \
--to=asmadeus@codewreck.org \
--cc=dhowells@redhat.com \
--cc=fweimer@redhat.com \
--cc=jlayton@kernel.org \
--cc=libc-alpha@sourceware.org \
--cc=linux-api@vger.kernel.org \
--cc=quentin.bouget@cea.fr \
/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 NNTP newsgroup(s).