From 660a0c3c89090548ff9ea5802eb3325dc1432727 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 1 Sep 2021 19:40:45 +0000 Subject: loosing time in freestanding gcc-opimized code with volatile string buffers on the stack (aka fun) --- miniany/libc-freestanding.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miniany/libc-freestanding.c b/miniany/libc-freestanding.c index 09d9fc8..31808e7 100644 --- a/miniany/libc-freestanding.c +++ b/miniany/libc-freestanding.c @@ -132,7 +132,11 @@ enum { static void print_char( int fd, int c ) { - char s[1]; + /* gcc 10 and 11 think on -O1 and -O2 that s can be held in registers, thus + * clobbering the output? Let's put a volatile here seems to help. Neither + * clang nor tcc show this behaviour.. + */ + volatile char s[1]; s[0] = c; syscall3( SYSCALL_WRITE, fd, (int)s, 1 ); } -- cgit v1.2.3-54-g00ecf