Fix and simplify HAVE_SEMIHOSTED_PRINTF
What changed, and why it matters
This commit cleans up how a special debug-only printing mode is enabled in the Ledger Bitcoin app. It only affects builds where DEBUG=10 is set, which is intended for use in the Speculos emulator and not on real hardware. The change moves a macro redefinition from the Makefile into a header file and removes an unused HAVE_PRINTF flag. There is no direct security vulnerability visible in the diff, but it touches debug infrastructure that could historically be misused if left enabled in production firmware.
Treat as a routine cleanup commit. Verify that DEBUG=10 builds remain excluded from release/firmware signing pipelines and that HAVE_SEMIHOSTED_PRINTF is not accidentally enabled in production. No immediate patch or incident response is indicated by this diff alone.
Security signals we found
Debug-only build path modified
Semihosted printf is an emulator-specific mechanism and should never be enabled in production firmware
No bounds-checking or input-validation changes
No cryptographic or transaction-handling code changed
Evidence from the diff
The patch changes the DEBUG=10 build path. Previously the Makefile defined both HAVE_PRINTF and HAVE_SEMIHOSTED_PRINTF and aliased PRINTF to semihosted_printf on the compiler command line. Now the Makefile only defines HAVE_SEMIHOSTED_PRINTF, and src/debug-helpers/debug.h conditionally #undefs PRINTF and re-#defines it to semihosted_printf when that flag is set. This is a refactoring/simplification of the same behavior. The semihosted_printf path is emulator-only (semihosting traps to the host debugger/emulator) and is not present in normal production builds.
Changed components
Makefile DEBUG=10 build configurationsrc/debug-helpers/debug.hInspect captured patch +8 / −1
diff --git a/Makefile b/Makefile
index 397ffc3..5af2f55 100644
--- a/Makefile
+++ b/Makefile
@@ -190,7 +190,7 @@ CFLAGS += -include debug-helpers/debug.h
ifeq ($(DEBUG),10)
$(warning Using semihosted PRINTF. Only run with speculos!)
- DEFINES += HAVE_PRINTF HAVE_SEMIHOSTED_PRINTF PRINTF=semihosted_printf
+ DEFINES += HAVE_SEMIHOSTED_PRINTF
endif
# Needed to be able to include the definition of G_cx
diff --git a/src/debug-helpers/debug.h b/src/debug-helpers/debug.h
index f327ee5..4f3de3f 100644
--- a/src/debug-helpers/debug.h
+++ b/src/debug-helpers/debug.h
@@ -7,6 +7,13 @@ void debug_write(const char *buf);
int semihosted_printf(const char *format, ...);
+#ifdef HAVE_SEMIHOSTED_PRINTF
+// Route PRINTF to the semihosted implementation, instead of the default one
+// that is routed through seproxyhal.
+#undef PRINTF
+#define PRINTF semihosted_printf
+#endif
+
void print_stack_pointer(const char *file, int line, const char *func_name);
// Helper macro
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.