Skip to contentSkip to conversation

package/libffi: fix build on ARC

PATCH In review Thomas Petazzoni via buildroot 2 participants 3 messages Aug 17, 2024 – Aug 18, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 package/libffi: fix build on ARC

This commit brings two patches that have been submitted to upstream libffi by Synopsys people, to fix libffi build issues on ARC.

This build issue was introduced by upstream commit c4df19c99f8d8841942e3edaadbf331d30e298c8, which landed in libffi 3.4.5, so the issue exists in Buildroot since we bumped from libffi 3.4.4 to 3.4.6 in commit f382de2b0f8a528a09bb975cc088a4342b663134, which landed in Buildroot 2024.05. This issue therefore doesn't exist in the 2024.02.x LTS branch.

Fixes:

http://autobuild.buildroot.net/results/3accebc6775b9a479876a5898d55bde005d4b12b/

---
 package/libffi/0002-arc-Fix-warnings.patch    | 56 +++++++++++++++++++
 ...ot-use-mov_s-and-movl_s-instructions.patch | 45 +++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 package/libffi/0002-arc-Fix-warnings.patch
 create mode 100644 package/libffi/0003-arc-Do-not-use-mov_s-and-movl_s-instructions.patch
package/libffi/0002-arc-Fix-warnings.patch new file +56 -0
new file mode 100644
index 0000000000..45a2c9dbd7
@@ -0,0 +1,56 @@
+From 4f25e5be1a8a429b6925527c1cb94b6acd05642b Mon Sep 17 00:00:00 2001
+From: Yuriy Kolerov <[email protected]>
+Date: Wed, 17 Jul 2024 18:56:52 +0300
+Subject: [PATCH] arc: Fix warnings
+
+These warnings are fixed:
+
+1. A series of "unused variables".
+2. Implicit conversion from a pointer to uint32_t.
+
+Signed-off-by: Yuriy Kolerov <[email protected]>
+Upstream: https://github.com/libffi/libffi/pull/844
+Signed-off-by: Thomas Petazzoni <[email protected]>
+---
+ src/arc/ffi.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/src/arc/ffi.c b/src/arc/ffi.c
+index d729274..0632319 100644
+--- a/src/arc/ffi.c
++++ b/src/arc/ffi.c
+@@ -192,9 +192,10 @@ static void unmarshal_atom(call_builder *cb, int type, void *data) {
+ /* for arguments passed by reference returns the pointer, otherwise the arg is copied (up to MAXCOPYARG bytes) */
+ static void *unmarshal(call_builder *cb, ffi_type *type, int var, void *data) {
+   size_t realign[2];
+-  void *pointer;
+ 
+ #if defined(__ARC64_ARCH64__)
++  void *pointer;
++
+   if (type->size > 2 * __SIZEOF_POINTER__) {
+         /* pass by reference */
+         unmarshal_atom(cb, FFI_TYPE_POINTER, (char*)&pointer);
+@@ -348,7 +349,10 @@ ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif,
+ 		      void *user_data, void *codeloc)
+ {
+   uint32_t *tramp = (uint32_t *) & (closure->tramp[0]);
++
++#if defined(__ARC64_ARCH64__)
+   size_t address_ffi_closure = (size_t) ffi_closure_asm;
++#endif
+ 
+   switch (cif->abi)
+     {
+@@ -367,7 +371,7 @@ ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif,
+       FFI_ASSERT (tramp == codeloc);
+       tramp[0] = CODE_ENDIAN (0x200a1fc0);	/* mov r8, pcl  */
+       tramp[1] = CODE_ENDIAN (0x20200f80);	/* j [long imm] */
+-      tramp[2] = CODE_ENDIAN (ffi_closure_asm);
++      tramp[2] = CODE_ENDIAN ((uint32_t) ffi_closure_asm);
+       break;
+ #endif
+ 
+-- 
+2.46.0
+
package/libffi/0003-arc-Do-not-use-mov_s-and-movl_s-instructions.patch new file +45 -0

45 lines not on this page · raw message

Signature · 6 lines
2.46.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 2/2 package/libffi: fix build on OpenRISC

The build of libffi on OpenRISC is broken with GCC 14.x. This commit brings two patches, submitted upstream, that address those two build issues. Both issues always existed in the OpenRISC libffi code base.

Fixes:

http://autobuild.buildroot.net/results/fb95d9a0f8322a58cd266014f3dea4eaa1b483e5/

---
 ...ffi.c-fix-prototype-of-ffi_call_SYSV.patch | 47 +++++++++++++++++
 ...-ffi.c-fix-incompatible-pointer-type.patch | 50 +++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 package/libffi/0004-src-or1k-ffi.c-fix-prototype-of-ffi_call_SYSV.patch
 create mode 100644 package/libffi/0005-src-or1k-ffi.c-fix-incompatible-pointer-type.patch
package/libffi/0004-src-or1k-ffi.c-fix-prototype-of-ffi_call_SYSV.patch new file +47 -0
new file mode 100644
index 0000000000..f3a7b29e3b
@@ -0,0 +1,47 @@
+From 4506e943289ed1363f3921bc201d5da76f750229 Mon Sep 17 00:00:00 2001
+From: Thomas Petazzoni <[email protected]>
+Date: Sat, 17 Aug 2024 12:56:22 +0200
+Subject: [PATCH] src/or1k/ffi.c: fix prototype of ffi_call_SYSV()
+
+The current code base of libffi on OpenRISC (or1k) fails to build with
+GCC 14.x with the following error:
+
+../src/or1k/ffi.c: In function 'ffi_call':
+../src/or1k/ffi.c:167:34: error: passing argument 3 of 'ffi_call_SYSV' from incompatible pointer type [-Wincompatible-pointer-types]
+  167 |       ffi_call_SYSV(size, &ecif, ffi_prep_args, rvalue, fn, cif->flags);
+      |                                  ^~~~~~~~~~~~~
+      |                                  |
+      |                                  void * (*)(char *, extended_cif *)
+../src/or1k/ffi.c:113:27: note: expected 'void * (*)(int *, extended_cif *)' but argument is of type 'void * (*)(char *, extended_cif *)'
+  113 |                           void *(*)(int *, extended_cif *),
+      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This is due to the fact that ffi_prep_args() is in fact defined as:
+
+  void* ffi_prep_args(char *stack, extended_cif *ecif)
+
+so, let's fix the prototype of the function pointer, which anyway gets
+passed to assembly code, so the typing gets lost.
+
+Upstream: https://github.com/libffi/libffi/pull/854
+Signed-off-by: Thomas Petazzoni <[email protected]>
+---
+ src/or1k/ffi.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/or1k/ffi.c b/src/or1k/ffi.c
+index 9451d4e..157388e 100644
+--- a/src/or1k/ffi.c
++++ b/src/or1k/ffi.c
+@@ -110,7 +110,7 @@ void* ffi_prep_args(char *stack, extended_cif *ecif)
+ 
+ extern void ffi_call_SYSV(unsigned,
+                           extended_cif *,
+-                          void *(*)(int *, extended_cif *),
++                          void *(*)(char *, extended_cif *),
+                           unsigned *,
+                           void (*fn)(void),
+                           unsigned);
+-- 
+2.46.0
+
package/libffi/0005-src-or1k-ffi.c-fix-incompatible-pointer-type.patch new file +50 -0

50 lines not on this page · raw message

Signature · 6 lines
2.46.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
In reply to Thomas Petazzoni via buildroot

Thomas, All,

On 2024-08-17 14:30 +0200, Thomas Petazzoni via buildroot spake thusly:

Quoted 10 lines

This commit brings two patches that have been submitted to upstream libffi by Synopsys people, to fix libffi build issues on ARC.

This build issue was introduced by upstream commit c4df19c99f8d8841942e3edaadbf331d30e298c8, which landed in libffi 3.4.5, so the issue exists in Buildroot since we bumped from libffi 3.4.4 to 3.4.6 in commit f382de2b0f8a528a09bb975cc088a4342b663134, which landed in Buildroot 2024.05. This issue therefore doesn't exist in the 2024.02.x LTS branch.

Quoted 5 lines

Fixes:

http://autobuild.buildroot.net/results/3accebc6775b9a479876a5898d55bde005d4b12b/

Series of two patches applied to master, thanks.

Regards,
Yann E. MORIN.

Quoted 127 lines
---
 package/libffi/0002-arc-Fix-warnings.patch    | 56 +++++++++++++++++++
 ...ot-use-mov_s-and-movl_s-instructions.patch | 45 +++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 package/libffi/0002-arc-Fix-warnings.patch
 create mode 100644 package/libffi/0003-arc-Do-not-use-mov_s-and-movl_s-instructions.patch
package/libffi/0002-arc-Fix-warnings.patch new file +56 -0
new file mode 100644
index 0000000000..45a2c9dbd7
@@ -0,0 +1,56 @@
+From 4f25e5be1a8a429b6925527c1cb94b6acd05642b Mon Sep 17 00:00:00 2001
+From: Yuriy Kolerov <[email protected]>
+Date: Wed, 17 Jul 2024 18:56:52 +0300
+Subject: [PATCH] arc: Fix warnings
+
+These warnings are fixed:
+
+1. A series of "unused variables".
+2. Implicit conversion from a pointer to uint32_t.
+
+Signed-off-by: Yuriy Kolerov <[email protected]>
+Upstream: https://github.com/libffi/libffi/pull/844
+Signed-off-by: Thomas Petazzoni <[email protected]>
+---
+ src/arc/ffi.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/src/arc/ffi.c b/src/arc/ffi.c
+index d729274..0632319 100644
+--- a/src/arc/ffi.c
++++ b/src/arc/ffi.c
+@@ -192,9 +192,10 @@ static void unmarshal_atom(call_builder *cb, int type, void *data) {
+ /* for arguments passed by reference returns the pointer, otherwise the arg is copied (up to MAXCOPYARG bytes) */
+ static void *unmarshal(call_builder *cb, ffi_type *type, int var, void *data) {
+   size_t realign[2];
+-  void *pointer;
+ 
+ #if defined(__ARC64_ARCH64__)
++  void *pointer;
++
+   if (type->size > 2 * __SIZEOF_POINTER__) {
+         /* pass by reference */
+         unmarshal_atom(cb, FFI_TYPE_POINTER, (char*)&pointer);
+@@ -348,7 +349,10 @@ ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif,
+ 		      void *user_data, void *codeloc)
+ {
+   uint32_t *tramp = (uint32_t *) & (closure->tramp[0]);
++
++#if defined(__ARC64_ARCH64__)
+   size_t address_ffi_closure = (size_t) ffi_closure_asm;
++#endif
+ 
+   switch (cif->abi)
+     {
+@@ -367,7 +371,7 @@ ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif,
+       FFI_ASSERT (tramp == codeloc);
+       tramp[0] = CODE_ENDIAN (0x200a1fc0);	/* mov r8, pcl  */
+       tramp[1] = CODE_ENDIAN (0x20200f80);	/* j [long imm] */
+-      tramp[2] = CODE_ENDIAN (ffi_closure_asm);
++      tramp[2] = CODE_ENDIAN ((uint32_t) ffi_closure_asm);
+       break;
+ #endif
+ 
+-- 
+2.46.0
+
package/libffi/0003-arc-Do-not-use-mov_s-and-movl_s-instructions.patch new file +45 -0
new file mode 100644
index 0000000000..3577ddf19d
@@ -0,0 +1,45 @@
+From 97c273519e41a7ef2841cb7531c6eda01fc69dc2 Mon Sep 17 00:00:00 2001
+From: Yuriy Kolerov <[email protected]>
+Date: Wed, 17 Jul 2024 19:19:30 +0300
+Subject: [PATCH] arc: Do not use mov_s and movl_s instructions
+
+mov_s and movl_s instructions use a restricted set of registers.
+However, a list of available registers for such instructions for
+one ARC target may not match a list for another ARC targets. For
+example, it is applicable to ARC700 and ARC HS3x/4x - build
+fails because mov_s formats may be incompatible in some cases.
+
+The easiest and the most straightforward way to fix this issue
+is to use mov and movl instead of mov_s and movl_s.
+
+Signed-off-by: Yuriy Kolerov <[email protected]>
+Upstream: https://github.com/libffi/libffi/pull/844
+Signed-off-by: Thomas Petazzoni <[email protected]>
+---
+ src/arc/arcompact.S | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/arc/arcompact.S b/src/arc/arcompact.S
+index 1d7f1a1..e749341 100644
+--- a/src/arc/arcompact.S
++++ b/src/arc/arcompact.S
+@@ -39,14 +39,14 @@
+ #define LARG ldl
+ #define SARG stl
+ #define ADDPTR addl
+-#define MOVPTR movl_s
++#define MOVPTR movl
+ #else
+ #define PTRS 4
+ #define FLTS 4
+ #define LARG ld
+ #define SARG st
+ #define ADDPTR add
+-#define MOVPTR mov_s
++#define MOVPTR mov
+ #endif
+ 
+ #define FRAME_LEN (8 * PTRS + 16)
+-- 
+2.46.0
+
Signature · 6 lines
2.46.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot