[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#748733: [4.9/4.10 Regression] Invalid optimizations for extern vars with local weak definitions



Package: gcc
Version: 4.9
Severity: important
Tags: upstream,confirmed,sid,experimental

GCC 4.9 introduced a bug in optimization (present at all -O levels
except -O0) in the presence of extern objects with weak definitions
local to the translation unit.

The following minimal testcase shows the problem:

static int dummy = 0;
extern int foo __attribute__((__weak__, __alias__("dummy")));
int bar() { if (foo) return 1; return 0; }

This should produce a nontrivial bar which can conditionally return 0
or 1 depending on the contents of foo. Instead, on 4.9.0, it produces
a function which always returns 0.

GCC versions with this bug have been reported to produce a seriously
broken libc.a/libc.so for musl libc (e.g. fflush(NULL) fails to flush
stdout).

Removing static above causes the symptom to go away, so presumably GCC
is wrongly transferring knowledge that "dummy" is static onto "foo",
and thereby assuming "foo" is not externally reachable/modifiable.
IIRC clang/LLVM had the same bug a couple years back and fixed it; it
looks like GCC has newly introduced it.

This bug affects at least the debian package "musl" which does not
build correctly.


Reply to: