git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Is detecting endianness at compile-time unworkable?

From
MFMichael Felt <aixtools@felt.demon.nl>
Date
Jul 31, 2018, 14:01 UTC
Message-ID
<287cdba8-19c1-2fe8-4aff-d0385b38e92c@felt.demon.nl>
In-Reply-To
<87wotdt649.fsf@evledraar.gmail.com>
I hope a I have a "leap forward"
On 7/30/2018 11:39 AM, Ævar Arnfjörð Bjarmason wrote:
Show 5 quoted lines
> Perhaps it's worth taking a step back here and thinking about whether
> this whole thing is unworkable. It was hard enough to get this to work
> on the combination of Linux, *BSD and Solaris, but I suspect we'll run
> into increasingly obscure platforms where this is hard or impossible
> (AIX, HP/UX etc.)

While I still cannot say for HP/UX it does seem there is a potential solution based on the status for _LITTLE_ENDIAN and _BIG_ENDIAN. At least, gcc on POWER and xlc on POWER provides one or the other - and my hope is that gcc on other platforms also provides them.

For "other" compilers that do not provide them - a modification to CFLAGS to define one or the other should make "make" work.

Details (note - I am not a programmer, so by definition at least one of my "macros" will be wrong :)

AIX and xlc root@x066:[/]xlc   -qshowmacros -E /dev/null | grep -i endi 1506-297 (S) Unable to open input file null. A file or directory in the path name does not exist.. #define __HHW_BIG_ENDIAN__ 1 #define __BIG_ENDIAN__ 1 #define __THW_BIG_ENDIAN__ 1 #define _BIG_ENDIAN 1

On SLES12 (le) and xlc suse12test:~/images/littleEndian/sles # xlc -qshowmacros -dM -E x.c | grep -i endi #define _LITTLE_ENDIAN 1 #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ #define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__ #define __LITTLE_ENDIAN__ 1 #define __ORDER_BIG_ENDIAN__ 4321 #define __ORDER_LITTLE_ENDIAN__ 1234 #define __ORDER_PDP_ENDIAN__ 3412 #define __VEC_ELEMENT_REG_ORDER__ __ORDER_LITTLE_ENDIAN__

Based on what I can see on gcc on POWER and xlc on POWER I think an approach (simplified) can be:

#if undefined(_BIG_ENDIAN) && undef(_LITTLE_ENDIAN) #error "one of _BIG_ENDIAN or _LITTLE_ENDIAN must be defined. Try adding the correct value to CFLAGS" #else defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) #error "Only one of _BIG_ENDIAN and _LITTLE_ENDIAN may be defined, not both" #endif

And then logic based on the value set. This should also make cross-compile possible by unsetting an incorrect default and setting the correct value.

p.s. Is there a setting I need to set somewhere so I receive a copy of the email sent after it is received by the list. I could send myself a copy, but I much prefer it comes from the maillist - as verification it was received.

Previous: Michael FeltNext: Ævar Arnfjörð Bjarmason
Message 23 of 25 in “git broken for AIX somewhere between 2.13.2 and 2.13.3”
  1. MichaelJul 29, 2018
  2. brian m. carlsonJul 29, 2018
  3. MichaelJul 29, 2018
  4. Ævar Arnfjörð BjarmasonJul 29, 2018
  5. Andreas SchwabJul 29, 2018
  6. MichaelJul 30, 2018
  7. MichaelJul 29, 2018
  8. brian m. carlsonJul 29, 2018
  9. MichaelJul 29, 2018
  10. Is detecting endianness at compile-time unworkable?Ævar Arnfjörð Bjarmason, Jul 30, 2018
  11. Junio C HamanoJul 30, 2018
  12. Junio C HamanoJul 30, 2018
  13. Daniel ShumowJul 30, 2018
  14. Michael FeltJul 31, 2018
  15. Eric WongAug 1, 2018
  16. Ævar Arnfjörð BjarmasonAug 1, 2018
  17. Michael FeltJul 31, 2018
  18. Ævar Arnfjörð BjarmasonAug 1, 2018
  19. sha1dc: update from upstreamÆvar Arnfjörð Bjarmason, Aug 2, 2018
  20. Michael Felt (aixtools)Aug 2, 2018
  21. Stefan BellerAug 2, 2018
  22. Michael FeltJul 31, 2018
  23. Michael FeltJul 31, 2018
  24. Ævar Arnfjörð BjarmasonJul 31, 2018
  25. MichaelJul 31, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.