1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-19 03:23:49 +01:00
RIOT/pkg/mpaland-printf/patches/0004-Wrapper-targets-Add-endpoints-for-Wl-wrap.patch
Marian Buschsieweke 7caf2066d8
pkg/mpaland-printf: fix overriding printf with printf_float
This makes sure that newlib's printf is correctly overridden by:

1. Adding wrappers for some more obscure printf() variants
2. Forcing a compilation failure when newlib's stdio is still linked in
   while mpaland-printf is used
3. Not adding `-u _printf_float` to the linker flags when mpaland-printf
   is used.
2025-04-26 15:28:17 +02:00

116 lines
2.4 KiB
Diff

From adf017ec04c42a615b536ee035db6d3f1eebdb31 Mon Sep 17 00:00:00 2001
From: Marian Buschsieweke <marian.buschsieweke@posteo.net>
Date: Sat, 11 May 2024 17:51:38 +0200
Subject: [PATCH 4/4] Wrapper targets: Add endpoints for -Wl,wrap=...
This adds aliases needed to wrap printf() and friends.
---
printf.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
diff --git a/printf.c b/printf.c
index 7c1ac61..8a1311c 100644
--- a/printf.c
+++ b/printf.c
@@ -32,6 +32,9 @@
#include <stdbool.h>
#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
#include "printf.h"
#include "stdio_base.h"
@@ -920,3 +923,87 @@ static void _putchar(char character)
{
stdio_write(&character, sizeof(character));
}
+
+
+/* provide entry points for linker to redirect stdio */
+__attribute__((alias("printf_")))
+int __wrap_printf(const char* format, ...);
+
+
+__attribute__((alias("sprintf_")))
+int __wrap_sprintf(char* buffer, const char* format, ...);
+
+
+__attribute__((alias("snprintf_")))
+int __wrap_snprintf(char* buffer, size_t count, const char* format, ...);
+
+
+__attribute__((alias("vprintf_")))
+int __wrap_vprintf(const char* format, va_list va);
+
+
+__attribute__((alias("vsnprintf_")))
+int __wrap_vsnprintf(char* buffer, size_t count, const char* format, va_list va);
+
+
+int __wrap_putchar(int c)
+{
+ _putchar((char)c);
+ return 1;
+}
+
+
+int __wrap_puts(const char *s)
+{
+ size_t len = strlen(s);
+ stdio_write(s, len);
+ stdio_write("\n", 1);
+ return len + 1;
+}
+
+
+int __wrap_vfprintf(FILE *stream, const char *format, va_list va)
+{
+ if (stream != stdout) {
+ return 0;
+ }
+
+ return vprintf_(format, va);
+}
+
+
+int __wrap_fprintf(FILE *stream, const char *format, ...)
+{
+ va_list va;
+ va_start(va, format);
+ int result = __wrap_vfprintf(stream, format, va);
+ va_end(va);
+ return result;
+}
+
+
+int __wrap_vdprintf(int fd, const char *format, va_list va)
+{
+ if (fd != STDOUT_FILENO) {
+ return 0;
+ }
+
+ return vprintf_(format, va);
+}
+
+
+int __wrap_vsprintf(char* buffer, const char* format, va_list va)
+{
+ return __wrap_vsnprintf(buffer, (size_t)-1, format, va);
+}
+
+
+int __wrap_dprintf(int fd, const char *format, ...)
+{
+ va_list va;
+ va_start(va, format);
+ int result = __wrap_vdprintf(fd, format, va);
+ va_end(va);
+ return result;
+
+}
--
2.43.0