This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Incorrect optimization for function__libc_message on C-SKY


* Mao Han:

> Hi,
>
> I've got some probelm with the optimization of __libc_message on C-SKY.
> __libc_message show nothing when MALLOC_CHECK_=3 is set.
>
> ./include/stdio.h:101
> enum __libc_message_action
> {
>   do_message    = 0,            /* Print message.  */
>   do_abort      = 1 << 0,       /* Abort.  */
>   do_backtrace  = 1 << 1        /* Backtrace.  */
> };
>
> sysdeps/posix/libc_fatal.c:175
> if ((action & do_abort))
>     {
>       if ((action & do_backtrace))
>         BEFORE_ABORT (do_abort, written, fd);
>
>       /* Kill the application.  */
>       abort ();
>
> The type of action is enum __libc_message_action, the C-SKY compiler
> think the action can not be both do_abort and do_backtrace at the
> same time, this path is supposed to be inaccessible.

I expect that even with -fstrict-enums, 3 is valid value for enum
__libc_message_action because in order to represent 2, the
implemnetation must supplied two or three bits (unsigned and signed
case), and then the value 3 is representable as well.

Without -fstrict-enums, I think the C standard requires that every enum
can represent at least the non-negative values of type char.

> ./sysdeps/unix/sysv/linux/libc_fatal.c:41
> static void
> backtrace_and_maps (int do_abort, bool written, int fd)
> {
>   if (do_abort > 1 && written)
>     {
>       void *addrs[64];
> #define naddrs (sizeof (addrs) / sizeof (addrs[0]))
>       int n = __backtrace (addrs, naddrs);
>
> backtrace_and_maps is called with BEFORE_ABORT (do_abort, written, fd);
> do_abort equals to 1, and the function also check do_abort > 1, so the
> entire backtrace_and_maps is optimized.
>
> Some one can explain the excepted logic here?

I think nowadays, we practically never print a backtrace, so the code
can be simplified a lot.  It's only used for fortification failures, but
even there, its use is questionable.  We really do not want to elaborate
things (such as calling dlopen) when we know that the process is in a
bad state.

Thanks,
Florian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]