From: Andrey Melnikov <temnota.am@gmail.com>
To: Rich Felker <dalias@aerifal.cx>
Cc: musl@lists.openwall.com
Subject: [musl] Re: move __BYTE_ORDER definition to alltypes.h
Date: Wed, 27 Jan 2021 00:29:05 +0300 [thread overview]
Message-ID: <CA+PODjoggTkhXneT=FjArxnbNCx3p0Pct7mgtbR=gQudVhy_eA@mail.gmail.com> (raw)
In-Reply-To: <20210126172330.GB23432@brightrain.aerifal.cx>
вт, 26 янв. 2021 г. в 20:23, Rich Felker <dalias@aerifal.cx>:
>
> On Tue, Jan 26, 2021 at 02:55:09PM +0300, Andrey Melnikov wrote:
> > Hi.
> >
> > Your commit 97d35a552ec5b6ddf7923dd2f9a8eb973526acea leads to
> > miscompile programs which rely on one of defines __LITTLE_ENDIAN or
> > __BIG_ENDIAN.
> > Now, both unconditionally defined when included stdarg.h and programs
> > which define __(BIG|LITTE)_ENDIAN itself - miscompiled. linux kernel
> > for example - it internally uses #if defined __BIG_ENDIAN and defines
> > it only for BIGENDAIN arches.
> >
> > Any ideas?
>
> The conditionally-defined macros that on some archs tell you the
> endianness are __BIG_ENDIAN__ and __LITTLE_ENDIAN__ (note the final
Yes, defined by compiller.
> __) or other arch-specific macros. __BIG_ENDIAN and __LITTLE_ENDIAN
> (without the final __) have always been the possible values for
> __BYTE_ORDER from endian.h.
From <endian.h> - its correct headers for this, not from <stdarg.h>.
<stdarg.h> is for va_* macros.
> In any case, all of these are in the
> reserved namespace and should not be defined by applications or
> inspected in any way other than a manner documented by the
> implementation.
Where is it reserved?
> How did this come up with the Linux kernel? AFAIK it uses -nostdinc
> and should not see the libc headers at all. But if that #ifdef is
> present in Linux it's probably a bug since it's contrary to all
> historical use of __BIG_ENDIAN...
Easy. Build an out-of-tree module that includes <linux/kernel.h> which
is include <stdarg.h> which is define all variant _ENDIAN macros,
later it include <asm/byteorder.h> which is include
<linux/byteorder/little_endian.h> in my case,
in <linux/byteorder/little_endian.h> (read
uapi/linux/byteorder/little_endian.h) we have defines:
#ifndef __LITTLE_ENDIAN
#define __LITTLE_ENDIAN 1234
#endif
#ifndef __LITTLE_ENDIAN_BITFIELD
#define __LITTLE_ENDIAN_BITFIELD
#endif
and later, include <linux/etherdevice.h> in module for
is_multicast_ether_addr() function:
static inline bool is_multicast_ether_addr(const u8 *addr)
{
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
u32 a = *(const u32 *)addr;
#else
u16 a = *(const u16 *)addr;
#endif
#ifdef __BIG_ENDIAN
return 0x01 & (a >> ((sizeof(a) * 8) - 8));
#else
return 0x01 & a;
#endif1234
}
And now, we have defined __LITTLE_ENDIAN 1234 (from kernel headers),
__BIG_ENDIAN 4321 (from stdarg header) - and code for BIG endian
compiled for LITTLE endian machide. Doh.
Please, return (BIG|LITTLE|PDP)_ENDIAN defines back to <endian.h>.
next prev parent reply other threads:[~2021-01-26 21:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CA+PODjoUKSfu1Z+b2PukoVOKOCrfzhLAkDa2VOjvNQYnd9Hc1A@mail.gmail.com>
2021-01-26 17:23 ` Rich Felker
2021-01-26 21:29 ` Andrey Melnikov [this message]
2021-01-26 21:40 ` Rich Felker
2021-01-27 8:12 ` Andrey Melnikov
2021-01-27 15:45 ` Rich Felker
2021-01-28 12:45 ` Andrey Melnikov
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='CA+PODjoggTkhXneT=FjArxnbNCx3p0Pct7mgtbR=gQudVhy_eA@mail.gmail.com' \
--to=temnota.am@gmail.com \
--cc=dalias@aerifal.cx \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).