From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
To: Willy Tarreau <w@1wt.eu>
Cc: "Charles Mirabile" <cmirabil@redhat.com>,
linux-kernel@vger.kernel.org,
"Thomas Weißschuh" <linux@weissschuh.net>
Subject: Re: [PATCH] nolibc/stdlib: Improve `getauxval(3)` implementation
Date: Wed, 17 Jan 2024 02:23:53 +0700 [thread overview]
Message-ID: <ZabXyRMECEnMUizk@biznet-home.integral.gnuweeb.org> (raw)
In-Reply-To: <ZabUyZG3C3LUax6f@biznet-home.integral.gnuweeb.org>
On Wed, Jan 17, 2024 at 02:11:12AM +0700, Ammar Faizi wrote:
> On Tue, Jan 16, 2024 at 07:59:39PM +0100, Willy Tarreau wrote:
> > On Tue, Jan 16, 2024 at 07:58:09PM +0100, Willy Tarreau wrote:
> > > On Wed, Jan 17, 2024 at 01:52:06AM +0700, Ammar Faizi wrote:
> > > > What do you think about other architectures? Will it potentially be
> > > > misinterpreted?
> > >
> > > Indeed, it would fail on a 64-bit big endian architecture. Let's
> > > just declare the local variable the same way as it is in the spec,
> > > it will be much cleaner and more reliable.
> >
> > With that said, if previous code used to work on such architectures,
> > maybe the definition above is only for x86_64 and differs on other
> > archs. Maybe it's really defined as two longs ?
>
> I just took a look at the kernel source code:
> https://github.com/torvalds/linux/blob/v6.7/fs/binfmt_elf.c#L226-L261
>
> The auxv is stored in `elf_info` variable, the type is `elf_addr_t`. Not
> sure what kind of typedef is that. I'll check.
>
> Each auxv entry is added using this macro:
>
> #define NEW_AUX_ENT(id, val) \
> do { \
> *elf_info++ = id; \
> *elf_info++ = val; \
> } while (0)
>
> where `id` is the type. That clearly implies `type` and `val` have the
> same size on the Linux kernel.
So here is the result:
1. 'elf_addr_t' defintion ( https://github.com/torvalds/linux/blob/v6.7/include/linux/elf.h#L38-L62 ):
(simplified)
#if ELF_CLASS == ELFCLASS32
#define elf_addr_t Elf32_Off
#else
#define elf_addr_t Elf64_Off
#endif
2. 'Elf32_Off' and 'Elf64_Off' typedefs ( https://github.com/torvalds/linux/blob/v6.7/include/uapi/linux/elf.h#L8-L23 )
typedef __u32 Elf32_Off;
typedef __u64 Elf64_Off;
Assuming 'ELFCLASS32' is for 32-bit architectures, then it's two __u64
on 64-bit arch, and two __u32 on 32-bit arch. That is identical to
'unsigned long' for both cases (on Linux). So it's fine to have
'unsigned long' for both 'type' and 'value'.
--
Ammar Faizi
next prev parent reply other threads:[~2024-01-16 19:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 18:11 [PATCH] nolibc/stdlib: Improve `getauxval(3)` implementation Charles Mirabile
2024-01-16 18:52 ` Ammar Faizi
2024-01-16 18:58 ` Willy Tarreau
2024-01-16 18:59 ` Willy Tarreau
2024-01-16 19:11 ` Ammar Faizi
2024-01-16 19:23 ` Ammar Faizi [this message]
2024-01-16 19:46 ` Willy Tarreau
2024-01-16 19:51 ` Ammar Faizi
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=ZabXyRMECEnMUizk@biznet-home.integral.gnuweeb.org \
--to=ammarfaizi2@gnuweeb.org \
--cc=cmirabil@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=w@1wt.eu \
/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