* [PATCH] Implement libffi for AARCH64:ILP32
@ 2015-02-09 8:40 Andrew Pinski
2015-02-09 8:51 ` Andrew Haley
2015-02-10 18:35 ` Richard Henderson
0 siblings, 2 replies; 7+ messages in thread
From: Andrew Pinski @ 2015-02-09 8:40 UTC (permalink / raw)
To: GCC Patches, libffi-discuss
[-- Attachment #1: Type: text/plain, Size: 863 bytes --]
Hi,
The following GCC patch (I don't have the libffi code git checked
out) implements libffi for AARCH64:ILP32. The majority of the AARCH64
code works correctly for ILP32.
For ILP32, we need to use long long types for ffi_arg and ffi_sarg.
And then we need to fix up the closure code to load cif, fn, and
user_data by 32bit instead of 64bits as they are stored as pointers in
C code.
With this patch, I got no failures in the libffi testsuite that is
included with GCC.
OK? Built and tested on aarch64 with no regressions.
Thanks,
Andrew Pinski
ChangeLog:
* src/aarch64/ffitarget.h (ffi_arg): Use unsigned long long for ILP32.
(ffi_sarg): Use signed long long for ILP32.
* src/aarch64/sysv.S (PTR_REG): New macro.
(PTR_SIZE): New macro.
(ffi_closure_SYSV): Load cif, fn and user_data using PTR_REG.
(ffi_go_closure_SYSV): Load cif and fn using PTR_REG.
[-- Attachment #2: implementlibffiilp32.diff.txt --]
[-- Type: text/plain, Size: 1834 bytes --]
diff --git a/libffi/src/aarch64/ffitarget.h b/libffi/src/aarch64/ffitarget.h
index fca2811..c134fe3 100644
--- a/libffi/src/aarch64/ffitarget.h
+++ b/libffi/src/aarch64/ffitarget.h
@@ -27,8 +27,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#endif
#ifndef LIBFFI_ASM
+#ifdef __ILP32__
+typedef unsigned long long ffi_arg;
+typedef signed long long ffi_sarg;
+#else
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
+#endif
typedef enum ffi_abi
{
diff --git a/libffi/src/aarch64/sysv.S b/libffi/src/aarch64/sysv.S
index 46f50b9..c1bf9b9 100644
--- a/libffi/src/aarch64/sysv.S
+++ b/libffi/src/aarch64/sysv.S
@@ -45,6 +45,18 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
# define BE(X) 0
#endif
+#ifdef __ILP32__
+#define PTR_REG(n) w##n
+#else
+#define PTR_REG(n) x##n
+#endif
+
+#ifdef __ILP32__
+#define PTR_SIZE 4
+#else
+#define PTR_SIZE 8
+#endif
+
.text
.align 4
@@ -248,8 +260,8 @@ CNAME(ffi_closure_SYSV):
stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48]
/* Load ffi_closure_inner arguments. */
- ldp x0, x1, [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET] /* load cif, fn */
- ldr x2, [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET+16] /* load user_data */
+ ldp PTR_REG(0), PTR_REG(1), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET] /* load cif, fn */
+ ldr PTR_REG(2), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET+PTR_SIZE*2] /* load user_data */
.Ldo_closure:
add x3, sp, #16 /* load context */
add x4, sp, #ffi_closure_SYSV_FS /* load stack */
@@ -403,7 +415,7 @@ CNAME(ffi_go_closure_SYSV):
stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48]
/* Load ffi_closure_inner arguments. */
- ldp x0, x1, [x18, #8] /* load cif, fn */
+ ldp PTR_REG(0), PTR_REG(1), [x18, #PTR_SIZE]/* load cif, fn */
mov x2, x18 /* load user_data */
b .Ldo_closure
cfi_endproc
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Implement libffi for AARCH64:ILP32
2015-02-09 8:40 [PATCH] Implement libffi for AARCH64:ILP32 Andrew Pinski
@ 2015-02-09 8:51 ` Andrew Haley
2015-02-10 18:40 ` Richard Henderson
2015-02-10 18:35 ` Richard Henderson
1 sibling, 1 reply; 7+ messages in thread
From: Andrew Haley @ 2015-02-09 8:51 UTC (permalink / raw)
To: Andrew Pinski, GCC Patches, libffi-discuss
On 09/02/15 08:40, Andrew Pinski wrote:
> For ILP32, we need to use long long types for ffi_arg and ffi_sarg.
> And then we need to fix up the closure code to load cif, fn, and
> user_data by 32bit instead of 64bits as they are stored as pointers in
> C code.
Would it make more sense to use int64_t rather than long long?
Andrew.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Implement libffi for AARCH64:ILP32
2015-02-09 8:40 [PATCH] Implement libffi for AARCH64:ILP32 Andrew Pinski
2015-02-09 8:51 ` Andrew Haley
@ 2015-02-10 18:35 ` Richard Henderson
2015-02-10 19:02 ` Andrew Pinski
1 sibling, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2015-02-10 18:35 UTC (permalink / raw)
To: Andrew Pinski, GCC Patches, libffi-discuss
On 02/09/2015 12:40 AM, Andrew Pinski wrote:
> #ifndef LIBFFI_ASM
> +#ifdef __ILP32__
> +typedef unsigned long long ffi_arg;
> +typedef signed long long ffi_sarg;
> +#else
You need to set FFI_SIZEOF_ARG too.
Otherwise it looks ok.
r~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Implement libffi for AARCH64:ILP32
2015-02-10 18:35 ` Richard Henderson
@ 2015-02-10 19:02 ` Andrew Pinski
2015-02-10 21:20 ` Richard Henderson
0 siblings, 1 reply; 7+ messages in thread
From: Andrew Pinski @ 2015-02-10 19:02 UTC (permalink / raw)
To: Richard Henderson; +Cc: GCC Patches, libffi-discuss
On Tue, Feb 10, 2015 at 10:35 AM, Richard Henderson <rth@redhat.com> wrote:
> On 02/09/2015 12:40 AM, Andrew Pinski wrote:
>> #ifndef LIBFFI_ASM
>> +#ifdef __ILP32__
>> +typedef unsigned long long ffi_arg;
>> +typedef signed long long ffi_sarg;
>> +#else
>
> You need to set FFI_SIZEOF_ARG too.
>
> Otherwise it looks ok.
Thanks. I am testing the patch with the following added under the ILP32 check:
+#define FFI_SIZEOF_ARG 8
+#define FFI_SIZEOF_JAVA_RAW 4
Thanks,
Andrew Pinski
>
>
> r~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Implement libffi for AARCH64:ILP32
2015-02-10 19:02 ` Andrew Pinski
@ 2015-02-10 21:20 ` Richard Henderson
2015-02-10 22:46 ` Andrew Pinski
0 siblings, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2015-02-10 21:20 UTC (permalink / raw)
To: Andrew Pinski; +Cc: GCC Patches, libffi-discuss
On 02/10/2015 11:02 AM, Andrew Pinski wrote:
> +#define FFI_SIZEOF_JAVA_RAW 4
Since aarch64 doesn't implement the raw java api, this is irrelevant.
r~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Implement libffi for AARCH64:ILP32
2015-02-10 21:20 ` Richard Henderson
@ 2015-02-10 22:46 ` Andrew Pinski
0 siblings, 0 replies; 7+ messages in thread
From: Andrew Pinski @ 2015-02-10 22:46 UTC (permalink / raw)
To: Richard Henderson; +Cc: GCC Patches, libffi-discuss
[-- Attachment #1: Type: text/plain, Size: 810 bytes --]
On Tue, Feb 10, 2015 at 1:20 PM, Richard Henderson <rth@redhat.com> wrote:
> On 02/10/2015 11:02 AM, Andrew Pinski wrote:
>> +#define FFI_SIZEOF_JAVA_RAW 4
>
> Since aarch64 doesn't implement the raw java api, this is irrelevant.
Ok. This is what I applied to GCC after testing it (I don't have
access to the libffi git repo).
2015-02-10 Andrew Pinski <apinski@cavium.com>
* src/aarch64/ffitarget.h (ffi_arg): Use unsigned long long for ILP32.
(FFI_SIZEOF_ARG): Define to 64 for ILP32.
(ffi_sarg): Use signed long long for ILP32.
* src/aarch64/sysv.S (PTR_REG): New macro.
(PTR_SIZE): New macro.
(ffi_closure_SYSV): Load cif, fn and user_data using PTR_REG.
(ffi_go_closure_SYSV): Load cif and fn using PTR_REG.
Thanks,
Andrew Pinski
>
>
> r~
[-- Attachment #2: fixlibffi.diff.txt --]
[-- Type: text/plain, Size: 2363 bytes --]
commit b3d4df7304dcbc56475f400837b47fc52143292e
Author: Andrew Pinski <apinski@cavium.com>
Date: Mon Feb 9 08:41:09 2015 +0000
* src/aarch64/ffitarget.h (ffi_arg): Use unsigned long long for ILP32.
(FFI_SIZEOF_ARG): Define to 64 for ILP32.
(ffi_sarg): Use signed long long for ILP32.
* src/aarch64/sysv.S (PTR_REG): New macro.
(PTR_SIZE): New macro.
(ffi_closure_SYSV): Load cif, fn and user_data using PTR_REG.
(ffi_go_closure_SYSV): Load cif and fn using PTR_REG.
diff --git a/libffi/src/aarch64/ffitarget.h b/libffi/src/aarch64/ffitarget.h
index fca2811..2862ec7 100644
--- a/libffi/src/aarch64/ffitarget.h
+++ b/libffi/src/aarch64/ffitarget.h
@@ -27,8 +27,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#endif
#ifndef LIBFFI_ASM
+#ifdef __ILP32__
+#define FFI_SIZEOF_ARG 8
+typedef unsigned long long ffi_arg;
+typedef signed long long ffi_sarg;
+#else
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
+#endif
typedef enum ffi_abi
{
diff --git a/libffi/src/aarch64/sysv.S b/libffi/src/aarch64/sysv.S
index 46f50b9..c1bf9b9 100644
--- a/libffi/src/aarch64/sysv.S
+++ b/libffi/src/aarch64/sysv.S
@@ -45,6 +45,18 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
# define BE(X) 0
#endif
+#ifdef __ILP32__
+#define PTR_REG(n) w##n
+#else
+#define PTR_REG(n) x##n
+#endif
+
+#ifdef __ILP32__
+#define PTR_SIZE 4
+#else
+#define PTR_SIZE 8
+#endif
+
.text
.align 4
@@ -248,8 +260,8 @@ CNAME(ffi_closure_SYSV):
stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48]
/* Load ffi_closure_inner arguments. */
- ldp x0, x1, [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET] /* load cif, fn */
- ldr x2, [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET+16] /* load user_data */
+ ldp PTR_REG(0), PTR_REG(1), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET] /* load cif, fn */
+ ldr PTR_REG(2), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET+PTR_SIZE*2] /* load user_data */
.Ldo_closure:
add x3, sp, #16 /* load context */
add x4, sp, #ffi_closure_SYSV_FS /* load stack */
@@ -403,7 +415,7 @@ CNAME(ffi_go_closure_SYSV):
stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48]
/* Load ffi_closure_inner arguments. */
- ldp x0, x1, [x18, #8] /* load cif, fn */
+ ldp PTR_REG(0), PTR_REG(1), [x18, #PTR_SIZE]/* load cif, fn */
mov x2, x18 /* load user_data */
b .Ldo_closure
cfi_endproc
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-02-10 22:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-09 8:40 [PATCH] Implement libffi for AARCH64:ILP32 Andrew Pinski
2015-02-09 8:51 ` Andrew Haley
2015-02-10 18:40 ` Richard Henderson
2015-02-10 18:35 ` Richard Henderson
2015-02-10 19:02 ` Andrew Pinski
2015-02-10 21:20 ` Richard Henderson
2015-02-10 22:46 ` Andrew Pinski
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 read-only IMAP folder(s) and NNTP newsgroup(s).