Bug 2068692 - glibc: ppc64le error-ldbl.h does not provide noreturn/return cases for error function.
Summary: glibc: ppc64le error-ldbl.h does not provide noreturn/return cases for error ...
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Arjun Shankar
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-03-26 00:53 UTC by Mark Wielaard
Modified: 2022-04-12 13:24 UTC (History)
11 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2022-04-12 13:24:30 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Sourceware 29033 0 P2 NEW Calling 'error' on ppc64le can lead to spurious compiler error with -Wnull-dereference -Werror 2022-04-06 14:26:20 UTC

Description Mark Wielaard 2022-03-26 00:53:55 UTC
The combination of gcc (gcc-12.0.1-0.12.fc36.ppc64le) and glibc (glibc-2.35-2.fc36.ppc64le) produces bad warnings/errors when error (EXIT_FAILURE, ...) is used on ppc64le (every other architecture is fine).

Take the following program:

$ cat w.c 
#include <error.h>
#include <stddef.h>
#include <stdlib.h>

struct S
{
  int i;
};

int
main (int argc, char **argv)
{
  struct S ss;
  struct S *s = argv[argc - 1] == NULL ? &ss : NULL;
  if (s == NULL)
    error (EXIT_FAILURE, 0, "frob");

  if (s->i == 0)
    return 1;

  return 0;
}

Which compiles just fine on any architecture except ppc64le where it produces:

$ gcc -Wnull-dereference -Werror -O2 -g w.c
w.c: In function ‘main’:
w.c:18:8: error: potential null pointer dereference [-Werror=null-dereference]
   18 |   if (s->i == 0)
      |       ~^~~
cc1: all warnings being treated as errors

The warning is incorrect is because error (EXIT_FAILURE, ...) doesn't return, which makes sure s is never dereferenced when it is NULL. Except on ppc64le on f36.

Comment 1 Mark Wielaard 2022-03-29 13:28:46 UTC
Note for elfutils I created the following workaround:
https://sourceware.org/pipermail/elfutils-devel/2022q1/004814.html

Comment 2 Carlos O'Donell 2022-04-05 13:27:50 UTC
In misc/bits/error.h we took care of this properly in the glibc sources:

 34 /* If we know the function will never return make sure the compiler
 35    realizes that, too.  */
 36 __extern_always_inline void
 37 error (int __status, int __errnum, const char *__format, ...)
 38 {
 39   if (__builtin_constant_p (__status) && __status != 0)
 40     __error_noreturn (__status, __errnum, __format, __va_arg_pack ());
 41   else
 42     __error_alias (__status, __errnum, __format, __va_arg_pack ());
 43 }
 44 

We have two paths. One path for the __error_noreturn case when __status is non-zero. And the returning __error_alias case when __status is zero.

However misc/bits/error-ldbl.h doesn't have any of the inline function pieces to provide the same behaviour.

This is caused by the IEEE 128-bit long double switch. This is an upstream bug (we should file an upstream bug).

Comment 3 Arjun Shankar 2022-04-06 14:26:21 UTC
I filed this upstream.

Comment 4 Carlos O'Donell 2022-04-12 13:24:30 UTC
This bug is being tracked upstream here:
https://sourceware.org/bugzilla/show_bug.cgi?id=29033

We are going to raise this with IBM to fix upstream.

I am marking this closed upstream. When upstream gets fixed we can backport a fix.


Note You need to log in before you can comment on or make changes to this bug.