gcc 4.1.2 miscompiles uClibc 0.9.32
Denys Vlasenko
vda.linux at googlemail.com
Thu Sep 15 15:01:16 UTC 2011
On Thu, Sep 15, 2011 at 12:13 PM, <u-uclibc-y2lt at aetey.se> wrote:
> Hello,
>
> A warning for people who can be hit by the same or similar issue:
>
> gcc 4.1.2 with -march=i486 here with -Os and even with -O2 or -O
> is "optimizing away" the check
>
> if (_stdio_term)
>
> in libc/stdlib/_atexit.c
>
> which results in a "call 0" and a segfault at exit
> if you do not happen to link in stdio.
>
> Presumably gcc believes _stdio_term to be a non-zero constant.
Yes, it does. Apparently C standard says function address is never NULL.
> Setting -O0 produces a sane exit.os and a usable library.
I committed a fix which uses:
+static __always_inline int not_null_ptr(const void *p)
+{
+ const void *q;
+ __asm__ (""
+ : "=r" (q) /* output */
+ : "0" (p) /* input */
+ );
+ return q != 0;
+}
...
- if (_stdio_term) {
+ if (not_null_ptr(_stdio_term)) {
_stdio_term();
}
--
vda
More information about the uClibc
mailing list