From 92b23022ba6d04a9e889b4368dc49881c0bc6393 Mon Sep 17 00:00:00 2001
From: Alessandro Rubini <rubini@gnudd.com>
Date: Mon, 20 May 2013 10:04:18 +0200
Subject: [PATCH] check-error: new file, to catch undesired function calls

We don't want to call the real printf, which brings in the whole of
newlib, but it sometimes happen. So let's diagnose the problem
immediately rather than letting users wonder what is wrong with the
size.

Similarly, if building under ppsi, ensure we are not calling libgcc
division functions: any 64-bit division my be done with __div64_32
offered by ppsi/lib (copied from the kernel).

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
---
 Makefile      |  2 ++
 check-error.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 check-error.c

diff --git a/Makefile b/Makefile
index 21fed2e..28b974b 100644
--- a/Makefile
+++ b/Makefile
@@ -95,6 +95,8 @@ include sockitowm/sockitowm.mk
 include dev/dev.mk
 
 
+obj-y += check-error.o
+
 CFLAGS = $(CFLAGS_PLATFORM) $(cflags-y) -Wall \
 	-ffunction-sections -fdata-sections -Os \
 	-include include/trace.h -ggdb
diff --git a/check-error.c b/check-error.c
new file mode 100644
index 0000000..c6f7bd8
--- /dev/null
+++ b/check-error.c
@@ -0,0 +1,33 @@
+
+/*
+ * This file includes stuff we don't want to link, so if it is
+ * called in error we get a clear error message, rather than a
+ * "doesn't fit in ram" error
+ */
+#include <stdio.h>
+
+extern void __you_should_not_call_printf_from_wrpc_sw(void);
+extern void __you_should_not_divide_ll_in_wrpc_sw(void);
+
+#undef printf /* Under ptp-noposix, this is #defined to mprintf */
+int printf(const char *fmt, ...)
+{
+	__you_should_not_call_printf_from_wrpc_sw();
+	return 0;
+}
+
+#ifdef CONFIG_PPSI /* with ppsi we can avoid libgcc code for division */
+/* was used twice in picos_to_ts  */
+long long __moddi3 (long long A, long long B)
+{
+	__you_should_not_divide_ll_in_wrpc_sw();
+	return 0;
+}
+
+/* was used in set_phase_shift, phase_to_cf_units */
+long long __divdi3 (long long A, long long B)
+{
+	__you_should_not_divide_ll_in_wrpc_sw();
+	return 0;
+}
+#endif /* config_ppsi */
-- 
GitLab