diff mbox series

nasm: Fix build with musl+clang

Message ID 20251210012547.1262043-1-raj.khem@gmail.com
State New
Headers show
Series nasm: Fix build with musl+clang | expand

Commit Message

Khem Raj Dec. 10, 2025, 1:25 a.m. UTC
Fixes `bool` related errors w.r.t. C23

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 ...0001-compiler.h-Backport-C23-support.patch | 102 ++++++++++++++++++
 meta/recipes-devtools/nasm/nasm_3.01.bb       |   1 +
 2 files changed, 103 insertions(+)
 create mode 100644 meta/recipes-devtools/nasm/nasm/0001-compiler.h-Backport-C23-support.patch
diff mbox series

Patch

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..946450f2e1
--- /dev/null
+++ b/meta/recipes-devtools/nasm/nasm/0001-compiler.h-Backport-C23-support.patch
@@ -0,0 +1,102 @@ 
+From e402e82d34569b4642ffbb3344c7240d1ea07776 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+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 <raj.khem@gmail.com>
+---
+ include/compiler.h | 42 ++++++++++++++++++------------------------
+ 1 file changed, 18 insertions(+), 24 deletions(-)
+
+diff --git a/include/compiler.h b/include/compiler.h
+index 41c1cbf..df66880 100644
+--- a/include/compiler.h
++++ b/include/compiler.h
+@@ -181,23 +181,10 @@ size_t strlcpy(char *, const char *, size_t);
+ char * pure_func strrchrnul(const char *, int);
+ #endif
+ 
+-#if !defined(HAVE_STRLCAT) || !HAVE_DECL_STRLCAT
+-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 <stdbool.h> exists, include it explicitly to prevent it from
+-   begin included later, causing the "bool" macro to be defined. */
+ #  include <stdbool.h>
+-#  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 +192,10 @@ size_t strlcat(char *, const char *, size_t);
+ # 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 +308,11 @@ static inline void *mempset(void *dst, int c, size_t n)
+  * 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 +469,15 @@ static inline unsigned int watcom_switch_hack(uint64_t x)
+ # define default case BOGUS_CASE: default
+ #endif
+ 
++#ifndef unreachable              /* C23 defines as a macro in <stddef.h> */
++# 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"