Attached are two patches needed to get nearly everything working on PPC64
(At least, Fedora 18)

At the moment, nativecall goes SEGV bigtime, because dyncall is misidentifying
the system as PPC32, and hence using the 32 bit calling code. D'oh!

As far as I can figure out, dyncall isn't really as robust as it should be.

gcc defaults to -m64, so `gcc` and `gcc -m64` are identical:

[nick@gcc1-power7 MoarVM]$ md5sum <(gcc -dM -E - </dev/null)  <(gcc -m64 -dM -E 
- </dev/null)
4b704a3390c5934bf2502cfff4ed0302  /dev/fd/63
4b704a3390c5934bf2502cfff4ed0302  /dev/fd/62

The differences in relevant macro output between -m32 and -m64 are as follows:


[nick@gcc1-power7 rakudo]$ diff -u <(gcc -m64 -dM -E - </dev/null | egrep -i 
'ppc|power' | sort)  <(gcc -m32 -dM -E - </dev/null | egrep -i 'ppc|power' | 
sort) 
--- /dev/fd/63  2015-03-05 11:30:47.420648411 -0800
+++ /dev/fd/62  2015-03-05 11:30:47.420648411 -0800
@@ -1,7 +1,7 @@
 #define _ARCH_PPC 1
-#define _ARCH_PPC64 1
-#define _ARCH_PPCGR 1
+#define __powerpc 1
 #define __powerpc__ 1
-#define __powerpc64__ 1
+#define powerpc 1
+#define __PPC 1
 #define __PPC__ 1
-#define __PPC64__ 1
+#define PPC 1


Note that __powerpc__ is defined for both 32 and 64 bit (and two other macros
that the code isn't checking). Hence the default order trips up:

#elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc) || 
defined(__POWERPC__) || defined(__ppc__) || defined(__power__)
# define ARCH_PPC
#elif defined(__ppc64__) || defined(_ARCH_PPC64) || defined(__power64__)
# define ARCH_PPC64

because it seees __powerpc__ and assumes that means 32 bit.

I think it would be far more robust to check for the 64 bit *specific* macros
first, and then fall back to assuming 32 bit if non-specific macros are seen.
Hence first patch.

Tested with both `gcc` and `gcc -m64` - gives the correct results on each.

I assume that ultimately this needs to go upstream to dyncall. I'm not
volunteering to shepherd that process.


Second patch is to rakudo, because its tests wrongly assume that bare `char`
is signed. That's not true on PPC [or ARM, or even x64_64 if I compiler with
`-funsigned-char`. Which I did :-)]


With these, PPC64 now builds, passes all NQP tests, all rakudo tests, and most
spectests.

t/spec/S02-types/native.rakudo.moar fails 3:

not ok 32 - Bound alias to int32 native works
not ok 33 - Bound alias to int16 native works
not ok 34 - Bound alias to int8 native works

because the write to the int8 (or int16 or int32) variable is not going
through the correct REPR code. (It has to be writing a 64 bit value, which
doesn't matter on Little Endian systems)

t/spec/S17-procasync/print.t sometimes fails an assertion.

./perl6-m -Ilib t/spec/S17-procasync/print.t                                
1..16
ok 1 - could we write the tester
ok 2 - did the tester arrive ok
ok 3 - The object is-a 'Proc::Async'
ok 4 - 
ok 5 - 
ok 6 - STDOUT should be empty
ok 7 - STDERR should be empty
ok 8 - The object is-a 'Promise'
ok 9 - The object is-a 'Promise'
ok 10 - The object is-a 'Promise'
ok 11 - did the close of STDIN work
moar: src/core/validation.c:601: MVM_validate_static_frame: Assertion 
`fb->bytecode == fb->orig_bytecode' failed.
Aborted


t/spec/S17-lowlevel/thread.t and
t/spec/integration/advent2014-day05.rakudo.moar
sometimes fail that assertion.

Apart from that, all is good.

Sadly PPC32 is a mess. With these patches NQP will build, and the nativecall
tests pass. However 2 other tests fail (arithmetic and printf problems), and
the Rakudo build explodes with a syntax error backtrace.

I assume that until the NQP tests pass it's not even worth attempting to
figure out the Rakudo problem, as it might be caused by the NQP bugs.

Nicholas Clark
>From 14f8c73cce49fc789088d660f262eadb8e0c27c2 Mon Sep 17 00:00:00 2001
From: Nicholas Clark <n...@ccl4.org>
Date: Thu, 5 Mar 2015 11:13:38 -0800
Subject: [PATCH] The nativecall test for int8 should use `signed char`
 explicitly.

Otherwise on architectures where bare `char` is unsigned, the test fails,
because it returns the wrong value. (-103 + 256, instead of -103)
---
 t/04-nativecall/03-simple-returns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/04-nativecall/03-simple-returns.c b/t/04-nativecall/03-simple-returns.c
index 5949186..6c6276b 100644
--- a/t/04-nativecall/03-simple-returns.c
+++ b/t/04-nativecall/03-simple-returns.c
@@ -17,7 +17,7 @@ DLLEXPORT short ReturnShort()
     return 102;
 }
 
-DLLEXPORT char ReturnByte()
+DLLEXPORT signed char ReturnByte()
 {
     return -103;
 }
-- 
1.8.1.4

>From 75cb9c8765ddee36140875466db52661f6b3dcb9 Mon Sep 17 00:00:00 2001
From: Nicholas Clark <n...@ccl4.org>
Date: Thu, 5 Mar 2015 11:09:24 -0800
Subject: [PATCH] Move the checks for PPC64 defines ahead of PPC(32) defines.

On PPC64 Fedora (at least F18), gcc -m64 defines all the macros that the
header knows about, with none of the macros only being defined for gcc -m32.
Hence check for the 64-bit only macros first, to avoid a false positive for
"32 bit".
---
 autovar/autovar_ARCH.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/autovar/autovar_ARCH.h b/autovar/autovar_ARCH.h
index da97eb6..4ec7058 100644
--- a/autovar/autovar_ARCH.h
+++ b/autovar/autovar_ARCH.h
@@ -32,10 +32,10 @@
 # define ARCH_X64
 #elif defined(_M_IA64) || defined(__ia64__)
 # define ARCH_IA64
-#elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__ppc__) || defined(__power__)
-# define ARCH_PPC
 #elif defined(__ppc64__) || defined(_ARCH_PPC64) || defined(__power64__)
 # define ARCH_PPC64
+#elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__ppc__) || defined(__power__)
+# define ARCH_PPC
 #elif defined(__mips64__) || defined(__mips64)
 # define ARCH_MIPS64
 #elif defined(_M_MRX000) || defined(__mips__)
-- 
1.8.1.4

Reply via email to