diff mbox series

[meta-oe,wrynose] ltrace: fix PRIb64 length modifier on LP64 musl

Message ID 20260720225209.3736953-1-amery@apptly.co
State Under Review
Headers show
Series [meta-oe,wrynose] ltrace: fix PRIb64 length modifier on LP64 musl | expand

Commit Message

Alejandro Mery July 20, 2026, 10:52 p.m. UTC
lens_default.c defines PRIb64 through a fallback that hardcodes
__PRI64_PREFIX as "ll". That is only correct where uint64_t is unsigned
long long (ILP32). On LP64 musl targets uint64_t is unsigned long, so the
resulting "%llb" conversion does not match the argument and do_compile
aborts under -Werror=format:

    lens_default.c:90:48: error: format '%llb' expects argument of type
    'long long unsigned int', but argument 3 has type 'uint64_t'
    {aka 'long unsigned int'}

glibc never reaches the fallback: it defines __PRI64_PREFIX itself,
wordsize aware, in <inttypes.h>. musl provides the same modifier there
under the name __PRI64 but not __PRI64_PREFIX, so the hardcoded "ll" is
used and is wrong on 64-bit. Reuse musl's __PRI64 when __PRI64_PREFIX is
absent, keeping "ll" as a last resort. glibc builds are unaffected: the
block is skipped entirely.

Signed-off-by: Alejandro Mery <amery@apptly.co>
---
 ...t-fix-PRIb64-length-modifier-on-musl.patch | 49 +++++++++++++++++++
 .../recipes-devtools/ltrace/ltrace_0.8.1.bb   |  1 +
 2 files changed, 50 insertions(+)
 create mode 100644 meta-oe/recipes-devtools/ltrace/ltrace/0001-lens_default-fix-PRIb64-length-modifier-on-musl.patch

Comments

Anuj Mittal July 20, 2026, 11:46 p.m. UTC | #1
Hi,

On Tue, Jul 21, 2026 at 6:52 AM Alejandro Mery via
lists.openembedded.org <amery=apptly.co@lists.openembedded.org> wrote:
>
> lens_default.c defines PRIb64 through a fallback that hardcodes
> __PRI64_PREFIX as "ll". That is only correct where uint64_t is unsigned
> long long (ILP32). On LP64 musl targets uint64_t is unsigned long, so the
> resulting "%llb" conversion does not match the argument and do_compile
> aborts under -Werror=format:
>
>     lens_default.c:90:48: error: format '%llb' expects argument of type
>     'long long unsigned int', but argument 3 has type 'uint64_t'
>     {aka 'long unsigned int'}
>
> glibc never reaches the fallback: it defines __PRI64_PREFIX itself,
> wordsize aware, in <inttypes.h>. musl provides the same modifier there
> under the name __PRI64 but not __PRI64_PREFIX, so the hardcoded "ll" is
> used and is wrong on 64-bit. Reuse musl's __PRI64 when __PRI64_PREFIX is
> absent, keeping "ll" as a last resort. glibc builds are unaffected: the
> block is skipped entirely.
>
> Signed-off-by: Alejandro Mery <amery@apptly.co>
> ---
>  ...t-fix-PRIb64-length-modifier-on-musl.patch | 49 +++++++++++++++++++
>  .../recipes-devtools/ltrace/ltrace_0.8.1.bb   |  1 +

master has the same version so I'm guessing this fix is applicable
there as well. Please send it for master branch first and wrynose fix
can be cherry picked from there.

Thanks,

Anuj
diff mbox series

Patch

diff --git a/meta-oe/recipes-devtools/ltrace/ltrace/0001-lens_default-fix-PRIb64-length-modifier-on-musl.patch b/meta-oe/recipes-devtools/ltrace/ltrace/0001-lens_default-fix-PRIb64-length-modifier-on-musl.patch
new file mode 100644
index 0000000000..b644efff94
--- /dev/null
+++ b/meta-oe/recipes-devtools/ltrace/ltrace/0001-lens_default-fix-PRIb64-length-modifier-on-musl.patch
@@ -0,0 +1,49 @@ 
+From 1a03dca3000616aa61d2c8137068706c9095a653 Mon Sep 17 00:00:00 2001
+From: Alejandro Mery <amery@geeks.cl>
+Date: Mon, 20 Jul 2026 20:13:56 +0000
+Subject: [PATCH] lens_default: fix PRIb64 length modifier on LP64 musl
+
+The fallback that defines PRIb64 hardcodes __PRI64_PREFIX as "ll", which
+is only correct where uint64_t is unsigned long long (ILP32). On LP64
+targets uint64_t is unsigned long, so the resulting "%llb" conversion
+does not match the argument and, with -Werror=format, aborts the build:
+
+    lens_default.c:90:48: error: format '%llb' expects argument of type
+    'long long unsigned int', but argument 3 has type 'uint64_t'
+    {aka 'long unsigned int'}
+
+glibc never reaches the fallback: it defines __PRI64_PREFIX itself,
+wordsize aware, in <inttypes.h>. musl provides the same modifier there
+under the name __PRI64 but not __PRI64_PREFIX, so the hardcoded "ll" is
+used and is wrong on 64-bit.
+
+Reuse musl's __PRI64 when __PRI64_PREFIX is absent, keeping the literal
+"ll" as a last resort for C libraries that expose neither.
+
+Upstream-Status: Submitted [https://gitlab.com/cespedes/ltrace/-/merge_requests/69]
+Signed-off-by: Alejandro Mery <amery@geeks.cl>
+---
+ lens_default.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/lens_default.c b/lens_default.c
+index 0de6f37..28df811 100644
+--- a/lens_default.c
++++ b/lens_default.c
+@@ -64,8 +64,13 @@ READER(read_double, double)
+ 
+ #ifndef PRIb64  // Underlying format supported by bookworm glibc, but macros not exposed until 2.38
+ #ifndef __PRI64_PREFIX
++/* glibc exposes the 64-bit length modifier as __PRI64_PREFIX; musl as __PRI64 */
++#ifdef __PRI64
++#define __PRI64_PREFIX __PRI64
++#else
+ #define __PRI64_PREFIX "ll"
+ #endif
++#endif
+ #define PRIb64 __PRI64_PREFIX "b"
+ #endif
+ #define HANDLE_WIDTH(BITS)						\
+-- 
+2.47.3
+
diff --git a/meta-oe/recipes-devtools/ltrace/ltrace_0.8.1.bb b/meta-oe/recipes-devtools/ltrace/ltrace_0.8.1.bb
index 77bb61830b..aa377e2ec8 100644
--- a/meta-oe/recipes-devtools/ltrace/ltrace_0.8.1.bb
+++ b/meta-oe/recipes-devtools/ltrace/ltrace_0.8.1.bb
@@ -27,6 +27,7 @@  SRC_URI = "git://gitlab.com/cespedes/ltrace.git;protocol=https;branch=main;tag=$
            file://0001-proc-Make-PROC_PID_FILE-not-use-variable-length-arra.patch \
            file://0001-dwarf_prototypes-return-NULL-from-NEXT_SIBLING-on-er.patch \
            file://0001-trace-fix-1-bit-bitfield-assignments-for-clang-Wsing.patch \
+           file://0001-lens_default-fix-PRIb64-length-modifier-on-musl.patch \
            "
 SRC_URI:append:libc-musl = " file://add_ppc64le.patch"