summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-07-16 21:32:06 -0400
committerRich Felker <dalias@aerifal.cx>2014-07-28 00:27:59 -0400
commit5ee811110444a615bbbf84a3daacccf734e4ef2c (patch)
treec1954a0456a797a290a4b4d0e12d02b2ba1767df /src
parentcad5e1c8baf0d97d3b4195864c46fa68f0a1b0b6 (diff)
downloadmusl-5ee811110444a615bbbf84a3daacccf734e4ef2c.tar.gz
work around constant folding bug 61144 in gcc 4.9.0 and 4.9.1
previously we detected this bug in configure and issued advice for a workaround, but this turned out not to work. since then gcc 4.9.0 has appeared in several distributions, and now 4.9.1 has been released without a fix despite this being a wrong code generation bug which is supposed to be a release-blocker, per gcc policy. since the scope of the bug seems to affect only data objects (rather than functions) whose definitions are overridable, and there are only a very small number of these in musl, I am just changing them from const to volatile for the time being. simply removing the const would be sufficient to make gcc 4.9.1 work (the non-const case was inadvertently fixed as part of another change in gcc), and this would also be sufficient with 4.9.0 if we forced -O0 on the affected files or on the whole build. however it's cleaner to just remove all the broken compiler detection and use volatile, which will ensure that they are never constant-folded. the quality of a non-broken compiler's output should not be affected except for the fact that these objects are no longer const and thus possibly add a few bytes to data/bss. this change can be reconsidered and possibly reverted at some point in the future when the broken gcc versions are no longer relevant. (cherry picked from commit a6adb2bcd8145353943377d6119c1d7a4242bae1)
Diffstat (limited to 'src')
-rw-r--r--src/stdio/__stdio_exit.c2
-rw-r--r--src/stdio/fflush.c2
-rw-r--r--src/stdio/stderr.c2
-rw-r--r--src/stdio/stdin.c2
-rw-r--r--src/stdio/stdout.c2
-rw-r--r--src/thread/pthread_create.c6
-rw-r--r--src/thread/pthread_key_create.c2
7 files changed, 9 insertions, 9 deletions
diff --git a/src/stdio/__stdio_exit.c b/src/stdio/__stdio_exit.c
index e4380aaf..716e5f73 100644
--- a/src/stdio/__stdio_exit.c
+++ b/src/stdio/__stdio_exit.c
@@ -1,6 +1,6 @@
#include "stdio_impl.h"
-static FILE *const dummy_file = 0;
+static FILE *volatile dummy_file = 0;
weak_alias(dummy_file, __stdin_used);
weak_alias(dummy_file, __stdout_used);
weak_alias(dummy_file, __stderr_used);
diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c
index af709503..7bf862a6 100644
--- a/src/stdio/fflush.c
+++ b/src/stdio/fflush.c
@@ -19,7 +19,7 @@ static int __fflush_unlocked(FILE *f)
}
/* stdout.c will override this if linked */
-static FILE *const dummy = 0;
+static FILE *volatile dummy = 0;
weak_alias(dummy, __stdout_used);
int fflush(FILE *f)
diff --git a/src/stdio/stderr.c b/src/stdio/stderr.c
index 3fd8f81d..229c8651 100644
--- a/src/stdio/stderr.c
+++ b/src/stdio/stderr.c
@@ -13,4 +13,4 @@ static FILE f = {
.lock = -1,
};
FILE *const stderr = &f;
-FILE *const __stderr_used = &f;
+FILE *volatile __stderr_used = &f;
diff --git a/src/stdio/stdin.c b/src/stdio/stdin.c
index 476dc708..171ff22a 100644
--- a/src/stdio/stdin.c
+++ b/src/stdio/stdin.c
@@ -12,4 +12,4 @@ static FILE f = {
.lock = -1,
};
FILE *const stdin = &f;
-FILE *const __stdin_used = &f;
+FILE *volatile __stdin_used = &f;
diff --git a/src/stdio/stdout.c b/src/stdio/stdout.c
index 3855dd0b..6b188942 100644
--- a/src/stdio/stdout.c
+++ b/src/stdio/stdout.c
@@ -13,4 +13,4 @@ static FILE f = {
.lock = -1,
};
FILE *const stdout = &f;
-FILE *const __stdout_used = &f;
+FILE *volatile __stdout_used = &f;
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index f60cd4a3..02b966ab 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -108,12 +108,12 @@ static int start(void *p)
#define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE)
/* pthread_key_create.c overrides this */
-static const size_t dummy = 0;
+static volatile size_t dummy = 0;
weak_alias(dummy, __pthread_tsd_size);
-static void *const dummy_tsd[1] = { 0 };
+static void *dummy_tsd[1] = { 0 };
weak_alias(dummy_tsd, __pthread_tsd_main);
-static FILE *const dummy_file = 0;
+static FILE *volatile dummy_file = 0;
weak_alias(dummy_file, __stdin_used);
weak_alias(dummy_file, __stdout_used);
weak_alias(dummy_file, __stderr_used);
diff --git a/src/thread/pthread_key_create.c b/src/thread/pthread_key_create.c
index c29935c1..d534b1a2 100644
--- a/src/thread/pthread_key_create.c
+++ b/src/thread/pthread_key_create.c
@@ -1,6 +1,6 @@
#include "pthread_impl.h"
-const size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX;
+volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX;
void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 };
static void (*keys[PTHREAD_KEYS_MAX])(void *);