Skip to contentSkip to conversation

package/perl: fix build issue with musl

PATCH Applied Thomas Petazzoni via buildroot 2 participants 4 messages Aug 26 – Sep 4

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/perl: fix build issue with musl

perl does not build with musl due to memrchr() being unavailable. This is caused by a perl-cross bug, which does function availability detection with _GNU_SOURCE defined, but then does the build without _GNU_SOURCE defined. At least OpenEmbedded and NixOS have faced the same issue, and worked it around in slightly different ways.

On our side, we create a patch, which was submitted upstream, to solve the issue.

This issue has been introduced in perl-cross commit b40c560f5d5e, which was first merged in perl-cross release 1.4.1. From a Buildroot perspective, we bumped from perl-cross 1.4 to 1.4.1 in commit 8a289667f5dba6fffb3a21faa14517e9b49726a4, which was merged 2023.05. And indeed the build failure can be reproduced even on our LTS 2025.02.x, so the fix needs to be backported there.

It should be noted that even if the patch is against perl-cross, we add it to package/perl/ directly, as patches in perl are applied after perl has been extracted *and* perl-cross has been extracted on top.

Fixes:

https://autobuild.buildroot.net/results/3e47ade0963642988fd8e1be9a6e8042700619ec/

---
 ...gure-keep-_GNU_SOURCE-in-build-flags.patch | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch
package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch new file +55 -0
new file mode 100644
index 0000000000..497e58c502
@@ -0,0 +1,55 @@
+From 6bdfdff24f4a7d17d3b7d9d02bca3eac11c235a4 Mon Sep 17 00:00:00 2001
+From: Thomas Petazzoni <[email protected]>
+Date: Wed, 26 Aug 2026 19:34:39 +0200
+Subject: [PATCH] configure: keep _GNU_SOURCE in build flags
+
+The checkfunc() function probes available libc functions with _GNU_SOURCE
+defined. The generated config.sh did not retain that define in ccflags, so
+the actual cross build could use functions whose prototypes remain hidden by
+feature-test macros. This breaks musl builds, where memrchr is declared only
+with _GNU_SOURCE.
+
+To fix this, append _GNU_SOURCE to explicit -Dccflags values while parsing
+configure arguments. Such values are locked before configure_tool.sh can
+append flags. This keeps the function-availability checks and subsequent
+compilation in the same feature set, including when flags are supplied
+through CFLAGS.
+
+This fixes the regression introduced by b40c560f5d5e (configure_func.sh: Add
+_GNU_SOURCE define and function signatures).
+
+It fixes the following build issue with musl:
+
+    In file included from op.c:163:
+    op.c: In function 'Perl_newATTRSUB_x':
+    perl.h:2385:25: error: implicit declaration of function 'memrchr'; did
+    you mean 'memchr'? [-Wimplicit-function-declaration]
+     2385 | #    define my_memrchr  memrchr
+          |                         ^~~~~~~
+
+This issue is worked around in several build systems:
+
+- In OpenEmbedded:
+  https://github.com/openembedded/openembedded-core/commit/6422e62
+
+- In NixOS:
+  https://github.com/NixOS/nixpkgs/pull/441527
+
+Fixes: https://github.com/arsv/perl-cross/issues/158
+Upstream: https://github.com/arsv/perl-cross/pull/180
+Signed-off-by: Thomas Petazzoni <[email protected]>
+
+diff --git a/cnf/configure_args.sh b/cnf/configure_args.sh
+index 5bc4c6b..65ffc96 100644
+--- a/cnf/configure_args.sh
++++ b/cnf/configure_args.sh
+@@ -225,6 +225,9 @@ while [ $i -le $# -o -n "$n" ]; do
+ 		host|target|build) ;;
+ 		# original Configure options
+ 		D)
++			if [ "$k" = 'ccflags' ]; then
++				v="$v -D_GNU_SOURCE"
++			fi
+ 			setordefine "$k" "$x" "$v" 'define' 'true'
+ 			;;
+ 		U)
Signature · 6 lines
2.55.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 20 lines · Thomas Petazzoni via buildroot

perl does not build with musl due to memrchr() being unavailable. This is caused by a perl-cross bug, which does function availability detection with _GNU_SOURCE defined, but then does the build without _GNU_SOURCE defined. At least OpenEmbedded and NixOS have faced the same issue, and worked it around in slightly different ways.

On our side, we create a patch, which was submitted upstream, to solve the issue.

This issue has been introduced in perl-cross commit b40c560f5d5e, which was first merged in perl-cross release 1.4.1. From a Buildroot perspective, we bumped from perl-cross 1.4 to 1.4.1 in commit 8a289667f5dba6fffb3a21faa14517e9b49726a4, which was merged 2023.05. And indeed the build failure can be reproduced even on our LTS 2025.02.x, so the fix needs to be backported there.

It should be noted that even if the patch is against perl-cross, we add it to package/perl/ directly, as patches in perl are applied after perl has been extracted *and* perl-cross has been extracted on top.

Quoted 6 lines

Fixes:

https://autobuild.buildroot.net/results/3e47ade0963642988fd8e1be9a6e8042700619ec/

Applied to master, thanks.
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#2 lore raw
In reply to Thomas Petazzoni via buildroot

Thomas,

this commit currently breaks host-perl which is a dependency of every package using the perl-package infrastructure.

the patch is against the content of the perl-cross tarball, not the content of perl tarball.
unluckily, perl-cross is only extracted with perl, no with host-perl.

the easiest fix is to extract perl-cross also for host-perl.

HOST_PERL_POST_EXTRACT_HOOKS += PERL_CROSS_EXTRACT will do the job.

Francois

Quoted 99 lines · Thomas Petazzoni

perl does not build with musl due to memrchr() being unavailable. This is caused by a perl-cross bug, which does function availability detection with _GNU_SOURCE defined, but then does the build without _GNU_SOURCE defined. At least OpenEmbedded and NixOS have faced the same issue, and worked it around in slightly different ways.

On our side, we create a patch, which was submitted upstream, to solve the issue.

This issue has been introduced in perl-cross commit b40c560f5d5e, which was first merged in perl-cross release 1.4.1. From a Buildroot perspective, we bumped from perl-cross 1.4 to 1.4.1 in commit 8a289667f5dba6fffb3a21faa14517e9b49726a4, which was merged 2023.05. And indeed the build failure can be reproduced even on our LTS 2025.02.x, so the fix needs to be backported there.

It should be noted that even if the patch is against perl-cross, we add it to package/perl/ directly, as patches in perl are applied after perl has been extracted *and* perl-cross has been extracted on top.

Fixes:

https://autobuild.buildroot.net/results/3e47ade0963642988fd8e1be9a6e8042700619ec/

---
 ...gure-keep-_GNU_SOURCE-in-build-flags.patch | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644

package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch

diff --git a/package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch b/package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch new file mode 100644
index 0000000000..497e58c502

package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch new file +8 -0
@@ -0,0 +1,55 @@
+From 6bdfdff24f4a7d17d3b7d9d02bca3eac11c235a4 Mon Sep 17 00:00:00 2001
+From: Thomas Petazzoni <[email protected]>
+Date: Wed, 26 Aug 2026 19:34:39 +0200
+Subject: [PATCH] configure: keep _GNU_SOURCE in build flags
+
+The checkfunc() function probes available libc functions with _GNU_SOURCE
+defined. The generated config.sh did not retain that define in ccflags, so
+the actual cross build could use functions whose prototypes remain hidden

by
+feature-test macros. This breaks musl builds, where memrchr is declared only

package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch new file +9 -0
+with _GNU_SOURCE.
+
+To fix this, append _GNU_SOURCE to explicit -Dccflags values while parsing
+configure arguments. Such values are locked before configure_tool.sh can
+append flags. This keeps the function-availability checks and subsequent
+compilation in the same feature set, including when flags are supplied
+through CFLAGS.
+
+This fixes the regression introduced by b40c560f5d5e (configure_func.sh:

Add

package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch new file +37 -1
+_GNU_SOURCE define and function signatures).
+
+It fixes the following build issue with musl:
+
+    In file included from op.c:163:
+    op.c: In function 'Perl_newATTRSUB_x':
+    perl.h:2385:25: error: implicit declaration of function 'memrchr'; did
+    you mean 'memchr'? [-Wimplicit-function-declaration]
+     2385 | #    define my_memrchr  memrchr
+          |                         ^~~~~~~
+
+This issue is worked around in several build systems:
+
+- In OpenEmbedded:
+  https://github.com/openembedded/openembedded-core/commit/6422e62
+
+- In NixOS:
+  https://github.com/NixOS/nixpkgs/pull/441527
+
+Fixes: https://github.com/arsv/perl-cross/issues/158
+Upstream: https://github.com/arsv/perl-cross/pull/180
+Signed-off-by: Thomas Petazzoni <[email protected]>
+
+diff --git a/cnf/configure_args.sh b/cnf/configure_args.sh
+index 5bc4c6b..65ffc96 100644
+--- a/cnf/configure_args.sh
++++ b/cnf/configure_args.sh
+@@ -225,6 +225,9 @@ while [ $i -le $# -o -n "$n" ]; do
+               host|target|build) ;;
+               # original Configure options
+               D)
++                      if [ "$k" = 'ccflags' ]; then
++                              v="$v -D_GNU_SOURCE"
++                      fi
+                       setordefine "$k" "$x" "$v" 'define' 'true'
+                       ;;
+               U)
--
Quoted 3 lines

2.55.0

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

#3 lore raw
In reply to Thomas Petazzoni via buildroot

In reply of:

Quoted 20 lines

perl does not build with musl due to memrchr() being unavailable. This is caused by a perl-cross bug, which does function availability detection with _GNU_SOURCE defined, but then does the build without _GNU_SOURCE defined. At least OpenEmbedded and NixOS have faced the same issue, and worked it around in slightly different ways.

On our side, we create a patch, which was submitted upstream, to solve the issue.

This issue has been introduced in perl-cross commit b40c560f5d5e, which was first merged in perl-cross release 1.4.1. From a Buildroot perspective, we bumped from perl-cross 1.4 to 1.4.1 in commit 8a289667f5dba6fffb3a21faa14517e9b49726a4, which was merged 2023.05. And indeed the build failure can be reproduced even on our LTS 2025.02.x, so the fix needs to be backported there.

It should be noted that even if the patch is against perl-cross, we add it to package/perl/ directly, as patches in perl are applied after perl has been extracted *and* perl-cross has been extracted on top.

Quoted 5 lines

Fixes:

https://autobuild.buildroot.net/results/3e47ade0963642988fd8e1be9a6e8042700619ec/

Applied to 2025.02.x & 2026.05.x. Thanks

Quoted 73 lines
---
 ...gure-keep-_GNU_SOURCE-in-build-flags.patch | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch
package/perl/0001-configure-keep-_GNU_SOURCE-in-build-flags.patch new file +55 -0
new file mode 100644
index 0000000000..497e58c502
@@ -0,0 +1,55 @@
+From 6bdfdff24f4a7d17d3b7d9d02bca3eac11c235a4 Mon Sep 17 00:00:00 2001
+From: Thomas Petazzoni <[email protected]>
+Date: Wed, 26 Aug 2026 19:34:39 +0200
+Subject: [PATCH] configure: keep _GNU_SOURCE in build flags
+
+The checkfunc() function probes available libc functions with _GNU_SOURCE
+defined. The generated config.sh did not retain that define in ccflags, so
+the actual cross build could use functions whose prototypes remain hidden by
+feature-test macros. This breaks musl builds, where memrchr is declared only
+with _GNU_SOURCE.
+
+To fix this, append _GNU_SOURCE to explicit -Dccflags values while parsing
+configure arguments. Such values are locked before configure_tool.sh can
+append flags. This keeps the function-availability checks and subsequent
+compilation in the same feature set, including when flags are supplied
+through CFLAGS.
+
+This fixes the regression introduced by b40c560f5d5e (configure_func.sh: Add
+_GNU_SOURCE define and function signatures).
+
+It fixes the following build issue with musl:
+
+    In file included from op.c:163:
+    op.c: In function 'Perl_newATTRSUB_x':
+    perl.h:2385:25: error: implicit declaration of function 'memrchr'; did
+    you mean 'memchr'? [-Wimplicit-function-declaration]
+     2385 | #    define my_memrchr  memrchr
+          |                         ^~~~~~~
+
+This issue is worked around in several build systems:
+
+- In OpenEmbedded:
+  https://github.com/openembedded/openembedded-core/commit/6422e62
+
+- In NixOS:
+  https://github.com/NixOS/nixpkgs/pull/441527
+
+Fixes: https://github.com/arsv/perl-cross/issues/158
+Upstream: https://github.com/arsv/perl-cross/pull/180
+Signed-off-by: Thomas Petazzoni <[email protected]>
+
+diff --git a/cnf/configure_args.sh b/cnf/configure_args.sh
+index 5bc4c6b..65ffc96 100644
+--- a/cnf/configure_args.sh
++++ b/cnf/configure_args.sh
+@@ -225,6 +225,9 @@ while [ $i -le $# -o -n "$n" ]; do
+ 		host|target|build) ;;
+ 		# original Configure options
+ 		D)
++			if [ "$k" = 'ccflags' ]; then
++				v="$v -D_GNU_SOURCE"
++			fi
+ 			setordefine "$k" "$x" "$v" 'define' 'true'
+ 			;;
+ 		U)
Signature · 6 lines
2.55.0

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

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