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.
50 lines
876 B
C
50 lines
876 B
C
#include "stdio_impl.h"
|
|
|
|
static int __fflush_unlocked(FILE *f)
|
|
{
|
|
/* If writing, flush output */
|
|
if (f->wpos > f->wbase) {
|
|
f->write(f, 0, 0);
|
|
if (!f->wpos) return EOF;
|
|
}
|
|
|
|
/* If reading, sync position, per POSIX */
|
|
if (f->rpos < f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR);
|
|
|
|
/* Clear read and write modes */
|
|
f->wpos = f->wbase = f->wend = 0;
|
|
f->rpos = f->rend = 0;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* stdout.c will override this if linked */
|
|
static FILE *volatile dummy = 0;
|
|
weak_alias(dummy, __stdout_used);
|
|
|
|
int fflush(FILE *f)
|
|
{
|
|
int r;
|
|
|
|
if (f) {
|
|
FLOCK(f);
|
|
r = __fflush_unlocked(f);
|
|
FUNLOCK(f);
|
|
return r;
|
|
}
|
|
|
|
r = __stdout_used ? fflush(__stdout_used) : 0;
|
|
|
|
OFLLOCK();
|
|
for (f=libc.ofl_head; f; f=f->next) {
|
|
FLOCK(f);
|
|
if (f->wpos > f->wbase) r |= __fflush_unlocked(f);
|
|
FUNLOCK(f);
|
|
}
|
|
OFLUNLOCK();
|
|
|
|
return r;
|
|
}
|
|
|
|
weak_alias(__fflush_unlocked, fflush_unlocked);
|