summaryrefslogtreecommitdiffstatshomepage
path: root/unix
diff options
context:
space:
mode:
authorDave Hylands <dhylands@gmail.com>2016-01-26 09:46:40 -0800
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-01-28 22:31:24 +0200
commit6a804cbabad37c0e69e86cc1f18a6b78875e2e45 (patch)
tree0b1f10b3bf398d146aea6f77f9d193e7709b6eed /unix
parent7b05b1b22526d28f15da4c656440ebc6ba1455b8 (diff)
downloadmicropython-6a804cbabad37c0e69e86cc1f18a6b78875e2e45.tar.gz
micropython-6a804cbabad37c0e69e86cc1f18a6b78875e2e45.zip
lib/utils/printf: Fix printf on release builds
When using newer glibc's the compiler automatically sets _FORTIFY_SOURCE when building with -O1 and this causes a special inlined version of printf to be declared which then bypasses our version of printf.
Diffstat (limited to 'unix')
-rw-r--r--unix/Makefile25
1 files changed, 25 insertions, 0 deletions
diff --git a/unix/Makefile b/unix/Makefile
index 39e671f9de..49cf8bac16 100644
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -28,6 +28,31 @@ CFLAGS += -g
COPT = -O0
else
COPT = -Os #-DNDEBUG
+# _FORTIFY_SOURCE is a feature in gcc/glibc which is intended to provide extra
+# security for detecting buffer overflows. Some distros (Ubuntu at the very least)
+# have it enabled by default.
+#
+# gcc already optimizes some printf calls to call puts and/or putchar. When
+# _FORTIFY_SOURCE is enabled and compiling with -O1 or greater, then some
+# printf calls will also be optimized to call __printf_chk (in glibc). Any
+# printfs which get redirected to __printf_chk are then no longer synchronized
+# with printfs that go through mp_printf.
+#
+# In MicroPython, we don't want to use the runtime library's printf but rather
+# go through mp_printf, so that stdout is properly tied into streams, etc.
+# This means that we either need to turn off _FORTIFY_SOURCE or provide our
+# own implementation of __printf_chk. We've chosen to turn off _FORTIFY_SOURCE.
+# It should also be noted that the use of printf in MicroPython is typically
+# quite limited anyways (primarily for debug and some error reporting, etc
+# in the unix version).
+#
+# Information about _FORTIFY_SOURCE seems to be rather scarce. The best I could
+# find was this: https://securityblog.redhat.com/2014/03/26/fortify-and-you/
+# Original patchset was introduced by
+# https://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html .
+#
+# Turning off _FORTIFY_SOURCE is only required when compiling with -O1 or greater
+CFLAGS += -U _FORTIFY_SOURCE
endif
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.