Skip to contentSkip to conversation

configure: detect endian via compile test

PATCH In review Mike Frysinger 7 participants 7 messages Jul 1, 2013 – Nov 5, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: detect endian via compile test

This avoids needing to execute a program and keeping an (incomplete) list when cross-compiling.

---
 configure | 40 ++++++++++++++--------------------------
 1 file changed, 14 insertions(+), 26 deletions(-)
configure +14 -26
index 2206a87..19d0856 100755
@@ -1386,39 +1386,27 @@ feature_not_found() {
       "configure was not able to find it"
 }
 
-if test -z "$cross_prefix" ; then
-
 # ---
 # big/little endian test
 cat > $TMPC << EOF
-#include <inttypes.h>
-int main(void) {
-        volatile uint32_t i=0x01234567;
-        return (*((uint8_t*)(&i))) == 0x67;
+short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
+short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
+extern int foo(short *, short *);
+int main(int argc, char *argv[]) {
+    return foo(big_endian, little_endian);
 }
 EOF
 
-if compile_prog "" "" ; then
-$TMPE && bigendian="yes"
-else
-echo big/little test failed
-fi
-
-else
-
-# if cross compiling, cannot launch a program, so make a static guess
-case "$cpu" in
-  arm)
-    # ARM can be either way; ask the compiler which one we are
-    if check_define __ARMEB__; then
-      bigendian=yes
+if compile_object ; then
+    if grep -q BiGeNdIaN $TMPO ; then
+        bigendian="yes"
+    elif grep -q LiTtLeEnDiAn $TMPO ; then
+        bigendian="no"
+    else
+        echo big/little test failed
     fi
-  ;;
-  hppa|m68k|mips|mips64|ppc|ppc64|s390|s390x|sparc|sparc64)
-    bigendian=yes
-  ;;
-esac
-
+else
+    echo big/little test failed
 fi
 
 ##########################################
Signature · 1 line
1.8.2.1
#3 lore raw

Am 28.08.2013 10:21, schrieb James Hogan:

Quoted 8 lines · Mike Frysinger
Quoted 3 lines

This avoids needing to execute a program and keeping an (incomplete) list when cross-compiling. Signed-off-by: Mike Frysinger <[email protected]>

This fixes mipsel cross compiling. I also checked it detected a mips (be) compiler as big endian. Tested-by: James Hogan <[email protected]> [mips] Can somebody please apply this. Maybe for stable too? Cheers James

Ping? Aurelien, Anthony, who wants to commit this patch? Richard already reviewed it.

See also http://patchwork.ozlabs.org/patch/268687/ for another configure patch waiting for a commit.

Regards,
Stefan

#4 lore raw
Quoted 10 lines · Stefan Weil

Am 28.08.2013 10:21, schrieb James Hogan:

Quoted 8 lines · Mike Frysinger
Quoted 3 lines

This avoids needing to execute a program and keeping an (incomplete) list when cross-compiling. Signed-off-by: Mike Frysinger <[email protected]>

This fixes mipsel cross compiling. I also checked it detected a mips (be) compiler as big endian. Tested-by: James Hogan <[email protected]> [mips] Can somebody please apply this. Maybe for stable too? Cheers James

Quoted 10 lines

Ping? Aurelien, Anthony, who wants to commit this patch? Richard already reviewed it.

See also http://patchwork.ozlabs.org/patch/268687/ for another configure patch waiting for a commit.

Regards,
Stefan

Ping on getting this into master (and then over to stable).

Signature · 1 line
Doug Goldstein
#5 lore raw

Il 26/09/2013 05:22, Doug Goldstein ha scritto:

Quoted 17 lines · Stefan Weil
Quoted 16 lines

Am 28.08.2013 10:21, schrieb James Hogan:

Quoted 8 lines · Mike Frysinger
Quoted 3 lines

This avoids needing to execute a program and keeping an (incomplete) list when cross-compiling. Signed-off-by: Mike Frysinger <[email protected]>

This fixes mipsel cross compiling. I also checked it detected a mips (be) compiler as big endian. Tested-by: James Hogan <[email protected]> [mips] Can somebody please apply this. Maybe for stable too? Cheers James

Ping? Aurelien, Anthony, who wants to commit this patch? Richard already reviewed it.

See also http://patchwork.ozlabs.org/patch/268687/ for another configure patch waiting for a commit.

Quoted 7 lines
Quoted 4 lines

Regards,
Stefan

Ping on getting this into master (and then over to stable).

Thanks Doug. Anthony, Aurelien, can you commit it?

Paolo

#6 lore raw
Quoted 23 lines · Paolo Bonzini

Il 26/09/2013 05:22, Doug Goldstein ha scritto:

Quoted 22 lines · Stefan Weil
Quoted 20 lines

Am 28.08.2013 10:21, schrieb James Hogan:

Quoted 8 lines · Mike Frysinger
Quoted 3 lines

This avoids needing to execute a program and keeping an (incomplete) list when cross-compiling. Signed-off-by: Mike Frysinger <[email protected]>

This fixes mipsel cross compiling. I also checked it detected a mips (be) compiler as big endian. Tested-by: James Hogan <[email protected]> [mips] Can somebody please apply this. Maybe for stable too? Cheers James

Ping? Aurelien, Anthony, who wants to commit this patch? Richard already reviewed it.

See also http://patchwork.ozlabs.org/patch/268687/ for another configure patch waiting for a commit.

Regards,
Stefan

Quoted 4 lines
Quoted 2 lines

Ping on getting this into master (and then over to stable).

Thanks Doug. Anthony, Aurelien, can you commit it?

Ping -- looks like this one got dropped :-(

-- PMM