NetBSD-Bugs archive

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

lib/50887: __clzdi2 implementation in compile_rt incompatible with gcc

>Number:         50887
>Category:       lib
>Synopsis:       __clzdi2 implementation in compile_rt incompatible with gcc
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 03 07:30:00 +0000 2016
>Originator:     Martin Husemann
>Release:        NetBSD 7.99.26
The NetBSD Foundation, Inc.
System: NetBSD 7.99.26 NetBSD 7.99.26 (WHOEVER) #104: Wed Mar 2 15:42:38 CET 2016 sparc64
Architecture: sparc64
Machine: sparc64

There are three builtin "count leading zeros" functions in our current 
compilers, and in some circumstances the compiler will make them call
into helper functions. Typically these helper functions are provided
by libgcc*, but we also want them in libc (and long term get rid of
libgcc completely).

On sparc64 these helper functions are:

int _clzsi2(uint32_t);
int _clzdi2(uint64_t);
int _clzti2(uint128_t);

and the compile_rt implementation (which we use in libc) uses __builtin_clz()
[which is propageted to _clzsi2] to implement _clzdi2.

However, libgcc on sparc64 does not implement the underlying helper function
_clzsi2 at all and always inlines:

inlint int _clzsi2(uint32_t v) { return _clzdi2(v)-32; }

which is correct, but combined with the compile_rt implementation leads
to an obvious endless recursion.

From a backtrace in PR 50866:

#0  __clzdi2 (a=33)
    at /ssd/src/sys/external/bsd/compiler_rt/dist/lib/builtins/clzdi2.c:23
#1  0xfffffffff661fb64 in __clzdi2 (a=<optimized out>)
    at /ssd/src/sys/external/bsd/compiler_rt/dist/lib/builtins/clzdi2.c:27
#2  0xfffffffff661fb64 in __clzdi2 (a=<optimized out>)
    at /ssd/src/sys/external/bsd/compiler_rt/dist/lib/builtins/clzdi2.c:27
#3  0xfffffffff661fb64 in __clzdi2 (a=<optimized out>)
    at /ssd/src/sys/external/bsd/compiler_rt/dist/lib/builtins/clzdi2.c:27
#4  0xffffffffeeca4a78 in util_logbase2 (n=<optimized out>)
    at /ssd/xsrc/external/mit/MesaLib/dist/src/gallium/auxiliary/util/u_math.h:665


Trick a program to call _clzdi2() in libc.
We should arrange for a test case for all libc "millicode" functions
in the regular ATF test runs, verifying at least a few correct results,
as currently it is pretty rare for this code to be executed at all in
real world.

Not sure - find a flag to gcc to avoid that inlining?
#ifdef the code in compile_rt on _LP64 and gcc?

Home | Main Index | Thread Index | Old Index