From: Khem Raj Date: Wed, 10 Dec 2025 03:34:40 +0000 (-0800) Subject: nasm: Fix build with musl+clang X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3d616a519c6c898561bb32ca25bbbc34bda2e72;p=thirdparty%2Fopenembedded%2Fopenembedded-core.git nasm: Fix build with musl+clang Fixes `bool` related errors w.r.t. C23 Signed-off-by: Khem Raj Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- diff --git a/meta/recipes-devtools/nasm/nasm/0001-compiler.h-Backport-C23-support.patch b/meta/recipes-devtools/nasm/nasm/0001-compiler.h-Backport-C23-support.patch new file mode 100644 index 0000000000..e1820870dd --- /dev/null +++ b/meta/recipes-devtools/nasm/nasm/0001-compiler.h-Backport-C23-support.patch @@ -0,0 +1,96 @@ +From e402e82d34569b4642ffbb3344c7240d1ea07776 Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Tue, 9 Dec 2025 17:17:36 -0800 +Subject: [PATCH] compiler.h: Backport C23 support + +These is a collection of changes done to compiler.h post +3.01 release. It fixes build with non-glibc ( musl ) +builds especially with clang compiler which is more +fussy + +Brings in squashed changed for compiler.h from + +https://github.com/netwide-assembler/nasm/commit/44e89ba9b650b5e1533bca43682e167f51a3511f +https://github.com/netwide-assembler/nasm/commit/746e7c9efa37cec9a44d84a1e96b8c38f385cc1f +https://github.com/netwide-assembler/nasm/commit/44ec97993a28ba109f98c4514e27cef813720399#diff-8e3e9367147ea2bbe07af8d84c1e07f80f5e19ca23282426324e396ee05947ba +https://github.com/netwide-assembler/nasm/commit/f4f7d18c06449a1859a62a10e7e24ca644032dff#diff-8e3e9367147ea2bbe07af8d84c1e07f80f5e19ca23282426324e396ee05947ba + +Upstream-Status: Backport [Above patches from master branch] + +Signed-off-by: Khem Raj +--- + include/compiler.h | 42 ++++++++++++++++++------------------------ + 1 file changed, 18 insertions(+), 24 deletions(-) + +--- a/include/compiler.h ++++ b/include/compiler.h +@@ -185,19 +185,10 @@ char * pure_func strrchrnul(const char * + size_t strlcat(char *, const char *, size_t); + #endif + +-#if !defined(__cplusplus) || (__STDC_VERSION >= 202311L) + /* C++ and C23 have bool, false, and true as proper keywords */ ++#if !defined(__cplusplus) && (__STDC_VERSION__ < 202311L) + # ifdef HAVE_STDBOOL_H +-/* If exists, include it explicitly to prevent it from +- begin included later, causing the "bool" macro to be defined. */ + # include +-# ifdef bool +-/* Force bool to be a typedef instead of a macro. What a "clever" hack +- this is... */ +- typedef bool /* The macro definition of bool */ +-# undef bool +- bool; /* No longer the macro definition */ +-# endif + # elif defined(HAVE___BOOL) + typedef _Bool bool; + # define false 0 +@@ -205,14 +196,10 @@ size_t strlcat(char *, const char *, siz + # else + /* This is a bit dangerous, because casting to this ersatz bool + will not produce the same result as the standard (bool) cast. +- Instead, use the bool() constructor-style macro defined below. */ ++ Instead, use the explicit construct !!x instead of relying on ++ implicit conversions or casts. */ + typedef enum bool { false, true } bool; + # endif +-/* This amounts to a C++-style conversion cast to bool. This works +- because C ignores an argument-taking macro when used without an +- argument and because bool was redefined as a typedef if it previously +- was defined as a macro (see above.) */ +-# define bool(x) ((bool)!!(x)) + #endif + + /* Create a NULL pointer of the same type as the address of +@@ -325,11 +312,11 @@ static inline void *mempset(void *dst, i + * less likely to be taken. + */ + #ifdef HAVE___BUILTIN_EXPECT +-# define likely(x) __builtin_expect(bool(x), true) +-# define unlikely(x) __builtin_expect(bool(x), false) ++# define likely(x) __builtin_expect(!!(x), true) ++# define unlikely(x) __builtin_expect(!!(x), false) + #else +-# define likely(x) bool(x) +-# define unlikely(x) bool(x) ++# define likely(x) (!!(x)) ++# define unlikely(x) (!!(x)) + #endif + + #ifdef HAVE___BUILTIN_PREFETCH +@@ -486,4 +473,15 @@ static inline unsigned int watcom_switch + # define default case BOGUS_CASE: default + #endif + ++#ifndef unreachable /* C23 defines as a macro in */ ++# ifdef HAVE___BUILTIN_UNREACHABLE ++# define unreachable() __builtin_unreachable() ++# else ++# define unreachable() do { abort(); } while(1) ++# endif ++#endif ++ ++/* This should be set from main() */ ++extern const char *_progname; ++ + #endif /* NASM_COMPILER_H */ diff --git a/meta/recipes-devtools/nasm/nasm_3.01.bb b/meta/recipes-devtools/nasm/nasm_3.01.bb index 4f4b47d665..1e4719000f 100644 --- a/meta/recipes-devtools/nasm/nasm_3.01.bb +++ b/meta/recipes-devtools/nasm/nasm_3.01.bb @@ -8,6 +8,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=6178dc4f5355e40552448080e67a214b" SRC_URI = "http://www.nasm.us/pub/nasm/releasebuilds/${PV}/nasm-${PV}.tar.bz2 \ file://0001-stdlib-Add-strlcat.patch \ file://0002-Add-debug-prefix-map-option.patch \ + file://0001-compiler.h-Backport-C23-support.patch \ " SRC_URI[sha256sum] = "7a7b1ff3b0eef3247862f2fbe4ca605ccef770545d7af7979eba84a9d045c0b1"