Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] flex: fix stage1flex build under a C23 default
@ 2026-09-13 16:05 Aurelien DESBRIERES
  2026-09-13 20:21 ` [OE-core] " Richard Purdie
  0 siblings, 1 reply; 5+ messages in thread
From: Aurelien DESBRIERES @ 2026-09-13 16:05 UTC (permalink / raw)
  To: openembedded-core; +Cc: aurelien.desbrieres

lib/malloc.c declares "void *malloc ();" with an empty parameter list
and calls it with one argument. That meant "unspecified" in C89 and
means "none" in C23, so the call is rejected:

  lib/malloc.c:16:15: error: too many arguments to function 'malloc';
                             expected 0, have 1

It is the language mode that decides, not the compiler version: the
same GCC 16 compiles the file with -std=gnu17 and rejects it with
-std=gnu23. GCC 15 made gnu23 the default, so every host from that
release on hits it while GCC 14 does not.

The file is compiled by stage1flex -- the bootstrap scanner flex builds
with the host compiler before it can build itself -- so neither CFLAGS
nor BUILD_CFLAGS reaches that command line and no flag in the recipe
can silence it.

stdlib.h has the right declaration and the file already includes
sys/types.h for size_t. lib/realloc.c includes stdlib.h already and
needs no change.

Signed-off-by: Aurelien DESBRIERES <aurelien@hackers.camp>
---
 ...b-malloc-declare-malloc-via-stdlib.h.patch | 38 +++++++++++++++++++
 meta/recipes-devtools/flex/flex_2.6.4.bb      |  1 +
 2 files changed, 39 insertions(+)
 create mode 100644 meta/recipes-devtools/flex/flex/0001-lib-malloc-declare-malloc-via-stdlib.h.patch

diff --git a/meta/recipes-devtools/flex/flex/0001-lib-malloc-declare-malloc-via-stdlib.h.patch b/meta/recipes-devtools/flex/flex/0001-lib-malloc-declare-malloc-via-stdlib.h.patch
new file mode 100644
index 0000000000..a64d6220a8
--- /dev/null
+++ b/meta/recipes-devtools/flex/flex/0001-lib-malloc-declare-malloc-via-stdlib.h.patch
@@ -0,0 +1,38 @@
+From: Aurelien Desbrieres <aurelien@hackers.camp>
+Date: Sat, 13 Sep 2026 00:00:00 +0200
+Subject: [PATCH] lib/malloc.c: declare malloc via stdlib.h
+
+The gnulib fallback declares "void *malloc ();" with an empty parameter
+list and calls it with one argument. That meant "unspecified" in C89 and
+means "none" in C23, which GCC 14 and later implement by default, so the
+call is rejected:
+
+  lib/malloc.c:16:15: error: too many arguments to function 'malloc';
+                             expected 0, have 1
+
+stdlib.h has the right declaration and the file already includes
+sys/types.h for size_t, so the local one has nothing to add.
+lib/realloc.c includes stdlib.h already and needs no change.
+
+The file is dead code wherever malloc(0) returns non-NULL -- glibc
+included -- since AC_FUNC_MALLOC substitutes rpl_malloc only where it
+does not, but it is compiled regardless and the build stops there.
+
+Upstream-Status: Inappropriate [flex 2.6.4 is the last release, 2017]
+
+Signed-off-by: Aurelien Desbrieres <aurelien@hackers.camp>
+---
+ lib/malloc.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/lib/malloc.c
++++ b/lib/malloc.c
+@@ -3,7 +3,7 @@
+      
+      #include <sys/types.h>
+      
+-     void *malloc ();
++#include <stdlib.h>
+      
+      /* Allocate an N-byte block of memory from the heap.
+         If N is zero, allocate a 1-byte block.  */
diff --git a/meta/recipes-devtools/flex/flex_2.6.4.bb b/meta/recipes-devtools/flex/flex_2.6.4.bb
index 793a935962..96c596764b 100644
--- a/meta/recipes-devtools/flex/flex_2.6.4.bb
+++ b/meta/recipes-devtools/flex/flex_2.6.4.bb
@@ -19,6 +19,7 @@ SRC_URI = "${GITHUB_BASE_URI}/download/v${PV}/flex-${PV}.tar.gz \
            file://check-funcs.patch \
            file://0001-Emit-no-line-directives-if-gen_line_dirs-is-false.patch \
            file://0001-build-tests-add-missing-parser-scanner-dependencies.patch \
+           file://0001-lib-malloc-declare-malloc-via-stdlib.h.patch \
            "
 
 SRC_URI[md5sum] = "2882e3179748cc9f9c23ec593d6adc8d"
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [OE-core] [PATCH] flex: fix stage1flex build under a C23 default
  2026-09-13 16:05 [PATCH] flex: fix stage1flex build under a C23 default Aurelien DESBRIERES
@ 2026-09-13 20:21 ` Richard Purdie
  2026-09-14  8:53   ` [PATCH v2] flex: backport the upstream malloc prototype fix Aurelien DESBRIERES
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Purdie @ 2026-09-13 20:21 UTC (permalink / raw)
  To: aurelien, openembedded-core; +Cc: aurelien.desbrieres

On Sun, 2026-09-13 at 18:05 +0200, Aurelien DESBRIERES via lists.openembedded.org wrote:
> lib/malloc.c declares "void *malloc ();" with an empty parameter list
> and calls it with one argument. That meant "unspecified" in C89 and
> means "none" in C23, so the call is rejected:
> 
>   lib/malloc.c:16:15: error: too many arguments to function 'malloc';
>                              expected 0, have 1
> 
> It is the language mode that decides, not the compiler version: the
> same GCC 16 compiles the file with -std=gnu17 and rejects it with
> -std=gnu23. GCC 15 made gnu23 the default, so every host from that
> release on hits it while GCC 14 does not.
> 
> The file is compiled by stage1flex -- the bootstrap scanner flex builds
> with the host compiler before it can build itself -- so neither CFLAGS
> nor BUILD_CFLAGS reaches that command line and no flag in the recipe
> can silence it.
> 
> stdlib.h has the right declaration and the file already includes
> sys/types.h for size_t. lib/realloc.c includes stdlib.h already and
> needs no change.
> 
> Signed-off-by: Aurelien DESBRIERES <aurelien@hackers.camp>
> ---
>  ...b-malloc-declare-malloc-via-stdlib.h.patch | 38 +++++++++++++++++++
>  meta/recipes-devtools/flex/flex_2.6.4.bb      |  1 +
>  2 files changed, 39 insertions(+)
>  create mode 100644 meta/recipes-devtools/flex/flex/0001-lib-malloc-declare-malloc-via-stdlib.h.patch
> 
> diff --git a/meta/recipes-devtools/flex/flex/0001-lib-malloc-declare-malloc-via-stdlib.h.patch b/meta/recipes-devtools/flex/flex/0001-lib-malloc-declare-malloc-via-stdlib.h.patch
> new file mode 100644
> index 0000000000..a64d6220a8
> --- /dev/null
> +++ b/meta/recipes-devtools/flex/flex/0001-lib-malloc-declare-malloc-via-stdlib.h.patch
> @@ -0,0 +1,38 @@
> +From: Aurelien Desbrieres <aurelien@hackers.camp>
> +Date: Sat, 13 Sep 2026 00:00:00 +0200
> +Subject: [PATCH] lib/malloc.c: declare malloc via stdlib.h
> +
> +The gnulib fallback declares "void *malloc ();" with an empty parameter
> +list and calls it with one argument. That meant "unspecified" in C89 and
> +means "none" in C23, which GCC 14 and later implement by default, so the
> +call is rejected:
> +
> +  lib/malloc.c:16:15: error: too many arguments to function 'malloc';
> +                             expected 0, have 1
> +
> +stdlib.h has the right declaration and the file already includes
> +sys/types.h for size_t, so the local one has nothing to add.
> +lib/realloc.c includes stdlib.h already and needs no change.
> +
> +The file is dead code wherever malloc(0) returns non-NULL -- glibc
> +included -- since AC_FUNC_MALLOC substitutes rpl_malloc only where it
> +does not, but it is compiled regardless and the build stops there.
> +
> +Upstream-Status: Inappropriate [flex 2.6.4 is the last release, 2017]

I'm not sure I follow that reasoning. It might be better to follow what
upstream did:

https://github.com/westes/flex/commit/bf254c75b1e0d2641ebbd7fc85fb183f36a62ea7

so this patch is then a backport and will fall out if/as/when we do see
another release of flex?

Cheers,

Richard




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] flex: backport the upstream malloc prototype fix
  2026-09-13 20:21 ` [OE-core] " Richard Purdie
@ 2026-09-14  8:53   ` Aurelien DESBRIERES
  2026-09-15  7:37     ` [OE-core] " Antonin Godard
  0 siblings, 1 reply; 5+ messages in thread
From: Aurelien DESBRIERES @ 2026-09-14  8:53 UTC (permalink / raw)
  To: openembedded-core; +Cc: aurelien.desbrieres

lib/malloc.c declares "void *malloc ();" with an empty parameter list
and calls it with one argument. That meant "unspecified" in C89 and
means "none" in C23, so a host compiler defaulting to C23 -- GCC 15 and
later -- rejects the call:

  lib/malloc.c:16:15: error: too many arguments to function 'malloc';
                             expected 0, have 1

The file is built by stage1flex with the build host's compiler before
flex can build itself, so neither CFLAGS nor BUILD_CFLAGS reaches that
command line and no flag in the recipe can silence it.

Upstream fixed it in bf254c75b1e0 and the patch falls out when flex
next releases. Gentoo carries the same backport as
flex-2.6.4-fix-malloc-prototype.patch.

Signed-off-by: Aurelien DESBRIERES <aurelien@hackers.camp>
---
 ....c-match-malloc-signature-to-its-use.patch | 37 +++++++++++++++++++
 meta/recipes-devtools/flex/flex_2.6.4.bb      |  1 +
 2 files changed, 38 insertions(+)
 create mode 100644 meta/recipes-devtools/flex/flex/0001-lib-malloc.c-match-malloc-signature-to-its-use.patch

diff --git a/meta/recipes-devtools/flex/flex/0001-lib-malloc.c-match-malloc-signature-to-its-use.patch b/meta/recipes-devtools/flex/flex/0001-lib-malloc.c-match-malloc-signature-to-its-use.patch
new file mode 100644
index 0000000000..7adeedcaa6
--- /dev/null
+++ b/meta/recipes-devtools/flex/flex/0001-lib-malloc.c-match-malloc-signature-to-its-use.patch
@@ -0,0 +1,37 @@
+From bf254c75b1e0d2641ebbd7fc85fb183f36a62ea7 Mon Sep 17 00:00:00 2001
+From: Richard Barnes <rbarnes@umn.edu>
+Date: Wed, 2 Oct 2024 10:35:09 -0700
+Subject: [PATCH] Match `malloc` signature to its use
+
+The gnulib fallback declares "void *malloc ();" with an empty parameter
+list and calls it with one argument. That meant "unspecified" in C89 and
+means "none" in C23, so a compiler defaulting to C23 -- GCC 15 and later
+-- rejects the call:
+
+  lib/malloc.c:16:15: error: too many arguments to function 'malloc';
+                             expected 0, have 1
+
+The file is built by stage1flex with the build host's compiler before
+flex can build itself, so neither CFLAGS nor BUILD_CFLAGS reaches that
+command line and no flag in the recipe can silence it.
+
+Upstream-Status: Backport [https://github.com/westes/flex/commit/bf254c75b1e0d2641ebbd7fc85fb183f36a62ea7]
+
+Signed-off-by: Aurelien DESBRIERES <aurelien@hackers.camp>
+---
+ lib/malloc.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/lib/malloc.c b/lib/malloc.c
+index 75e8ef97c..701b9b39d 100755
+--- a/lib/malloc.c
++++ b/lib/malloc.c
+@@ -3,7 +3,7 @@
+      
+      #include <sys/types.h>
+      
+-     void *malloc ();
++     void *malloc (size_t n);
+      
+      /* Allocate an N-byte block of memory from the heap.
+         If N is zero, allocate a 1-byte block.  */
diff --git a/meta/recipes-devtools/flex/flex_2.6.4.bb b/meta/recipes-devtools/flex/flex_2.6.4.bb
index 793a935962..3b652bda80 100644
--- a/meta/recipes-devtools/flex/flex_2.6.4.bb
+++ b/meta/recipes-devtools/flex/flex_2.6.4.bb
@@ -19,6 +19,7 @@ SRC_URI = "${GITHUB_BASE_URI}/download/v${PV}/flex-${PV}.tar.gz \
            file://check-funcs.patch \
            file://0001-Emit-no-line-directives-if-gen_line_dirs-is-false.patch \
            file://0001-build-tests-add-missing-parser-scanner-dependencies.patch \
+           file://0001-lib-malloc.c-match-malloc-signature-to-its-use.patch \
            "
 
 SRC_URI[md5sum] = "2882e3179748cc9f9c23ec593d6adc8d"
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [OE-core] [PATCH v2] flex: backport the upstream malloc prototype fix
  2026-09-14  8:53   ` [PATCH v2] flex: backport the upstream malloc prototype fix Aurelien DESBRIERES
@ 2026-09-15  7:37     ` Antonin Godard
  2026-09-15  7:49       ` Aurelien DESBRIERES
  0 siblings, 1 reply; 5+ messages in thread
From: Antonin Godard @ 2026-09-15  7:37 UTC (permalink / raw)
  To: Aurelien DESBRIERES, openembedded-core; +Cc: aurelien.desbrieres

On Mon Sep 14, 2026 at 10:53 AM CEST, Aurelien DESBRIERES wrote:
> lib/malloc.c declares "void *malloc ();" with an empty parameter list
> and calls it with one argument. That meant "unspecified" in C89 and
> means "none" in C23, so a host compiler defaulting to C23 -- GCC 15 and
> later -- rejects the call:
>
>   lib/malloc.c:16:15: error: too many arguments to function 'malloc';
>                              expected 0, have 1
>
> The file is built by stage1flex with the build host's compiler before
> flex can build itself, so neither CFLAGS nor BUILD_CFLAGS reaches that
> command line and no flag in the recipe can silence it.
>
> Upstream fixed it in bf254c75b1e0 and the patch falls out when flex
> next releases. Gentoo carries the same backport as
> flex-2.6.4-fix-malloc-prototype.patch.

This patch is already applied to flex on the master branch, from commit
e1832f02d70b ("flex: fix build with gcc-15 on host"). Maybe you need to rebase?

Antonin


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [OE-core] [PATCH v2] flex: backport the upstream malloc prototype fix
  2026-09-15  7:37     ` [OE-core] " Antonin Godard
@ 2026-09-15  7:49       ` Aurelien DESBRIERES
  0 siblings, 0 replies; 5+ messages in thread
From: Aurelien DESBRIERES @ 2026-09-15  7:49 UTC (permalink / raw)
  To: antonin.godard; +Cc: openembedded-core, aurelien.desbrieres

Thanks, you are right -- 98f2376d82 carries the same upstream commit and
I was working from walnascar. Please drop this one.

Aurelien


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-15  8:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-13 16:05 [PATCH] flex: fix stage1flex build under a C23 default Aurelien DESBRIERES
2026-09-13 20:21 ` [OE-core] " Richard Purdie
2026-09-14  8:53   ` [PATCH v2] flex: backport the upstream malloc prototype fix Aurelien DESBRIERES
2026-09-15  7:37     ` [OE-core] " Antonin Godard
2026-09-15  7:49       ` Aurelien DESBRIERES

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox