Iain Hibbert | 7 Feb 2010 20:08

host endianness

Hi,

(think this might be toolchain related, flame away if not :)

In the native build of pcc(1), we use a pre-generated config.h which
contains HOST_(BIG|LITTLE)_ENDIAN and TARGET_(BIG|LITTLE)_ENDIAN
definitions which should really be provided at build time. I found
<bsd.endian.mk> which supplies TARGET_ENDIANNESS but nothing about the
host.

Is it ok to add the test below so I can supply the HOST_*_ENDIAN symbol to
the pcc build as appropriate? Its basically a copy of the
MACHINE_ARCH/TARGET_ENDIANNESS test already there..

regards,
iain

--- bsd.endian.mk	9 Jan 2008 11:26:14 -0000	1.15
+++ bsd.endian.mk	7 Feb 2010 18:57:17 -0000
 <at>  <at>  -24,4 +24,23  <at>  <at> 
 TARGET_ENDIANNESS=	4321
 .endif

+.if ${HOST_ARCH} == "alpha" || \
+    ${HOST_ARCH} == "arm" || \
+    ${HOST_ARCH} == "i386" || \
+    ${HOST_ARCH} == "ia64" || \
+    ${HOST_ARCH} == "vax" || \
+    ${HOST_ARCH} == "x86_64" || \
+    ${HOST_ARCH:C/^.*el$/el/} == "el"
(Continue reading)

Iain Hibbert | 7 Feb 2010 20:39

Re: host endianness

On Sun, 7 Feb 2010, Iain Hibbert wrote:

> Hi,
>
> (think this might be toolchain related, flame away if not :)
>
> In the native build of pcc(1), we use a pre-generated config.h which
> contains HOST_(BIG|LITTLE)_ENDIAN and TARGET_(BIG|LITTLE)_ENDIAN
> definitions which should really be provided at build time. I found
> <bsd.endian.mk> which supplies TARGET_ENDIANNESS but nothing about the
> host.
>
> Is it ok to add the test below so I can supply the HOST_*_ENDIAN symbol to
> the pcc build as appropriate? Its basically a copy of the
> MACHINE_ARCH/TARGET_ENDIANNESS test already there..

Hm, except that test doesn't actually work.. seems that HOST_ARCH is
actually _HOST_ARCH and it's not always set.

any other suggestions to get the host endianness at build time?

iain

Christos Zoulas | 8 Feb 2010 07:08

Re: host endianness

In article <1265571540.101109.17086.nullmailer <at> galant.ukfsn.org>,
Iain Hibbert  <plunky <at> rya-online.net> wrote:
>On Sun, 7 Feb 2010, Iain Hibbert wrote:
>
>> Hi,
>>
>> (think this might be toolchain related, flame away if not :)
>>
>> In the native build of pcc(1), we use a pre-generated config.h which
>> contains HOST_(BIG|LITTLE)_ENDIAN and TARGET_(BIG|LITTLE)_ENDIAN
>> definitions which should really be provided at build time. I found
>> <bsd.endian.mk> which supplies TARGET_ENDIANNESS but nothing about the
>> host.
>>
>> Is it ok to add the test below so I can supply the HOST_*_ENDIAN symbol to
>> the pcc build as appropriate? Its basically a copy of the
>> MACHINE_ARCH/TARGET_ENDIANNESS test already there..
>
>Hm, except that test doesn't actually work.. seems that HOST_ARCH is
>actually _HOST_ARCH and it's not always set.
>
>any other suggestions to get the host endianness at build time?

compile and run:

#include <stdio.h>
union {
	int x;
	char c[4];
} z = {
(Continue reading)

David Laight | 8 Feb 2010 08:03
Picon

Re: host endianness

On Mon, Feb 08, 2010 at 06:08:32AM +0000, Christos Zoulas wrote:
> >
> >any other suggestions to get the host endianness at build time?
> 
> compile and run:
> 
> #include <stdio.h>
> union {
> 	int x;
> 	char c[4];
> } z = {
> 	.x = ('4' << 24) | ('3' << 16) | ('2' << 8) | '1'
> };
> 
> int
> main(void)
> {
> 	printf("%4.4s\n", z.c);
> 	return 0;
> }
> 

That is rather a PITA because you need the host compiler in the wrong
part of the build system.

Something based on:
    (set $(echo a|od -h); [ $2 = 0a61 ] && echo little || echo big;)
probably avoids needin a host compiler.

	David
(Continue reading)

David Holland | 8 Feb 2010 08:22
Picon

Re: host endianness

On Mon, Feb 08, 2010 at 07:03:17AM +0000, David Laight wrote:
 > Something based on:
 >     (set $(echo a|od -h); [ $2 = 0a61 ] && echo little || echo big;)
 > probably avoids needin a host compiler.

clever :-) how about this:

echo -n 'C!' | od -h | sed 's/[^1234]*//;s/2143/4321/p;d'

--

-- 
David A. Holland
dholland <at> netbsd.org

Alan Barrett | 8 Feb 2010 08:44
Gravatar

Re: host endianness

On Mon, 08 Feb 2010, David Holland wrote:
> echo -n 'C!' | od -h | sed 's/[^1234]*//;s/2143/4321/p;d'

Host shells might not support "echo -n", so please use printf "%s" "C!"
instead.

Also, the above assumes an ascii-compatible environment on the
cross-build host, and I don't know whether other parts of the build
already assume that.

--apb (Alan Barrett)

David Holland | 8 Feb 2010 09:19
Picon

Re: host endianness

On Mon, Feb 08, 2010 at 09:44:35AM +0200, Alan Barrett wrote:
 > > echo -n 'C!' | od -h | sed 's/[^1234]*//;s/2143/4321/p;d'
 > 
 > Host shells might not support "echo -n", so please use printf "%s" "C!"
 > instead.

Why not just printf "C!"? However,

   echo 'C!' | od -N 2 -h | sed 's/[^1234]*//;s/2143/4321/p;d'

is somewhat tidier.

 > Also, the above assumes an ascii-compatible environment on the
 > cross-build host, and I don't know whether other parts of the build
 > already assume that.

I suppose that calls for

   printf '\x43\x21' | od -h | sed 's/[^1234]*//;s/2143/4321/p;d'

although I doubt that very much will work on a non-ascii host. Might
be amusing to try if anyone has one though...

--

-- 
David A. Holland
dholland <at> netbsd.org

Ignatios Souvatzis | 8 Feb 2010 09:29
Picon

Re: host endianness

On Mon, Feb 08, 2010 at 08:19:34AM +0000, David Holland wrote:
> On Mon, Feb 08, 2010 at 09:44:35AM +0200, Alan Barrett wrote:
>  > > echo -n 'C!' | od -h | sed 's/[^1234]*//;s/2143/4321/p;d'
>  > 
>  > Host shells might not support "echo -n", so please use printf "%s" "C!"
>  > instead.
> 
> Why not just printf "C!"? However,
> 
>    echo 'C!' | od -N 2 -h | sed 's/[^1234]*//;s/2143/4321/p;d'
> 
> is somewhat tidier.

If this's s'ppossed to be host os and machine independent:

No 'od -h' on Solaris 8, neither on 10.

	-is

Izumi Tsutsui | 8 Feb 2010 15:17
Picon
Gravatar

Re: host endianness

> > In the native build of pcc(1), we use a pre-generated config.h which
> > contains HOST_(BIG|LITTLE)_ENDIAN and TARGET_(BIG|LITTLE)_ENDIAN
> > definitions which should really be provided at build time. I found
> > <bsd.endian.mk> which supplies TARGET_ENDIANNESS but nothing about the
> > host.
> >
> > Is it ok to add the test below so I can supply the HOST_*_ENDIAN symbol to
> > the pcc build as appropriate? Its basically a copy of the
> > MACHINE_ARCH/TARGET_ENDIANNESS test already there..
> 
> Hm, except that test doesn't actually work.. seems that HOST_ARCH is
> actually _HOST_ARCH and it's not always set.
> 
> any other suggestions to get the host endianness at build time?

With nbtool_config.h like src/sbin/disklabel/bswap.h?

---
#include <sys/types.h>

#if HAVE_NBTOOL_CONFIG_H
#ifndef BYTE_ORDER
#ifdef WORDS_BIGENDIAN
#define BYTE_ORDER		BIG_ENDIAN
#else
#define BYTE_ORDER		LITTLE_ENDIAN
#endif
#endif
#endif

(Continue reading)

David Holland | 9 Feb 2010 07:10
Picon

Re: host endianness

On Mon, Feb 08, 2010 at 09:29:59AM +0100, Ignatios Souvatzis wrote:
 > > Why not just printf "C!"? However,
 > > 
 > >    echo 'C!' | od -N 2 -h | sed 's/[^1234]*//;s/2143/4321/p;d'
 > > 
 > > is somewhat tidier.
 > 
 > If this's s'ppossed to be host os and machine independent:
 > 
 > No 'od -h' on Solaris 8, neither on 10.

Spoilsport :-)

--

-- 
David A. Holland
dholland <at> netbsd.org


Gmane