This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: compile failure for powerpc with latest CVS
- To: Ben Collins <bcollins at debian dot org>,GNU C Library <libc-alpha at sourceware dot cygnus dot com>
- Subject: Re: compile failure for powerpc with latest CVS
- From: Franz Sirl <Franz dot Sirl-kernel at lauterbach dot com>
- Date: Thu, 8 Mar 2001 22:35:13 +0100
- References: <20010308133131.I24675@visi.net> <01030822132700.01579@enzo.bigblue.local>
On Thursday 08 March 2001 22:13, Franz Sirl wrote:
> On Thursday 08 March 2001 19:31, Ben Collins wrote:
> > I get this compile failure (with backtrace) when compiling on ppc-linux:
> >
> >
> > /usr/src/glibc/glibc-2.2.2/powerpc-linux/obj/elf/sln
> > /usr/src/glibc/glibc-2.2.2/powerpc-linux/obj/elf/symlink.list make[2]:
> > *** [install-symbolic-link] Segmentation fault
> >
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x10000928 in atexit (func=0x1004d348 <_fini>) at atexit.c:31
> > 31 return __cxa_atexit ((void (*) (void *)) func, NULL,
> > (gdb) bt full
> > #0 0x10000928 in atexit (func=0x1004d348 <_fini>) at atexit.c:31
> > No locals.
> > #1 0x1000078c in __libc_start_main (argc=2, ubp_av=0x7ffffb94,
> > ubp_ev=0x7ffffba0, auxvec=0x7ffffbe9, rtld_fini=0x1004d348 <_fini>,
> > stinfo=0x1004d370, stack_on_entry=0x53) at
> > ../sysdeps/powerpc/elf/libc-start.c:104
> > dummy_addr = (int *) 0x0
>
> I was just looking at this after the same report from Kaoro. This is caused
> by a deficiency of gcc (all versions AFICS), constructs like
>
> &__dso_handle ? __dso_handle : 0
>
> are not safe if __dso_handle is a weak symbol. See this comment in
> rtlanal.c:
>
> /* Return 0 if the use of X as an address in a MEM can cause a trap. */
>
> static int
> rtx_addr_can_trap_p (x)
> register rtx x;
> {
> register enum rtx_code code = GET_CODE (x);
>
> switch (code)
> {
> case SYMBOL_REF:
> case LABEL_REF:
> /* SYMBOL_REF is problematic due to the possible presence of
> a #pragma weak, but to say that loads from symbols can trap is
> *very* costly. It's not at all clear what's best here. For
> now, we ignore the impact of #pragma weak. */
> return 0;
> ...
>
> So if such constructs work in glibc, it's by luck and not by design :-(.
> Maybe it's enough if all glibc files containing such constructs are
> compiled with -O0/-O1? Or create a separate function? Or even better, trick
> the compiler:
>
> #define PROTECT_WEAK_SYM(SYM) ({ __asm__ __volatile__(""); SYM;})
>
> int
> atexit (void (*func) (void))
> {
> return __cxa_atexit ((void (*) (void *)) func, NULL,
> &__dso_handle == NULL ? NULL :
> PROTECT_WEAK_SYM(__dso_handle));
> }
>
> This seems to work fine.
Or even nicer:
#define RET_WEAK_SYM_IF_SET_ELSE_NULL(SYM) \
( &SYM ? ({__asm__ __volatile__ (""); SYM;}) \
: ({__asm__ __volatile__ (""); NULL;}))
int
atexit (void (*func) (void))
{
return __cxa_atexit ((void (*) (void *)) func, NULL,
RET_WEAK_SYM_IF_SET_ELSE_NULL (__dso_handle));
}
Franz.