Skip to contentSkip to conversation

ltrace: fix PRIb64 length modifier on LP64 musl

PATCH In review Alejandro Mery 2 participants 2 messages Jul 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ltrace: fix PRIb64 length modifier on LP64 musl

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.

---
 ...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
meta-oe/recipes-devtools/ltrace/ltrace/0001-lens_default-fix-PRIb64-length-modifier-on-musl.patch new file +49 -0
new file mode 100644
index 0000000000..b644efff94
@@ -0,0 +1,49 @@
+From 1a03dca3000616aa61d2c8137068706c9095a653 Mon Sep 17 00:00:00 2001
+From: Alejandro Mery <[email protected]>
+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 <[email protected]>
+---
+ 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
+
meta-oe/recipes-devtools/ltrace/ltrace_0.8.1.bb +1 -0
index 77bb61830b..aa377e2ec8 100644
@@ -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"
 
Signature · 1 line
2.47.3
#1 lore raw

Hi,

Quoted 18 lines · Alejandro Mery via lists.openembedded.org

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.

Quoted 4 lines
---
 ...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