Bug 28425 - new __attribute_nonnull__(params) conflicts with third-party
Summary: new __attribute_nonnull__(params) conflicts with third-party
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2021-10-05 20:58 UTC by gstrauss
Modified: 2021-10-05 23:26 UTC (History)
2 users (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description gstrauss 2021-10-05 20:58:38 UTC
new __attribute_nonnull__(params) conflicts with third-party

(Staring with a summary, then following with details.)

I am fully aware that leading _ and leading __ and any __ are reserved in C indentifiers.

This bug report suggests a patch to hopefully reduce breakage caused by
the introduction of __attribute_nonnull__.

diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index 4dac9d264d..70d6ef37f4 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -329,7 +329,7 @@
 # endif
 #ifndef __nonnull
-# define __nonnull(params) __attribute_nonnull__ (params)
+# define __nonnull(params) __attribute__ ((__nonnull__ params))

 /* The returns_nonnull function attribute marks the return type of the function


__attribute_xxxxx__ is a useful idiom that I and others have used for 20+ years
in software ported to multiple platforms, including alternative libc libraries.
Using __attribute_xxxxx__ in code allows for `#define __attribute_xxxxx__ /*nothing*/` in environments without support for __attribute__ ((__xxxxx__)).  For example:
#ifndef __attribute_nonnull__
#if __has_attribute(nonnull) \
 || __GNUC_PREREQ(3,3)
#define __attribute_nonnull__  __attribute__((__nonnull__))
#define __attribute_nonnull__
I have used the above for some 20+ years with compilers including
  gcc, clang, Sun Studio cc, IBM xlc, HP acc
  on Linux, *BSD, Solaris, AIX, HPUX
Code can be annotated with __attribute_nonull__ and the attribute
is defined for compilers which support it, and defined to a no-op for those which do not.

I have the same code in the lighttpd web server

Unfortunately, there is a limitation in C in how macros are handled
with and without arguments.

In glibc 2.35 development, __attribute_nonnull__(params) has been introduced.


This breaks pre-existing usage of the idiom __attribute_nonnull__
if used *without params*

Some gcc attributes take an *optional* argument,
  e.g. __nonnull__, __deprecated__, __sentinel__

In https://github.com/gstrauss/plasma, I differentiated with macros
__attribute_nonnull__ and __attribute_nonnull_x__(params)
I am not saying this is the only solution, but it does differentiate.

Unfortunately, the new macro in glibc for __attribute_nonnull__(params)
breaks historical usage of __attribute_nonnull__ without params.  As I
mentioned above, I recognize that leading __ names are reserved for the
system libraries, and it is glibc's prerogative to define the macro for
__attribute_nonnull__ however glibc developers please.

There is already macro __nonnull(params) in gcc and clang
#define __nonnull(params) __attribute__ ((__nonnull__ params))

==> For greatest compatibility, I kindly request that glibc 2.35
    *not define* __attribute_nonull__ at all and instead continue
    to use __nonnull(params)

If not, then please consider the patch at the top of this post
which continues to define __nonnull(params) directly to
#define __nonnull(params) __attribute__ ((__nonnull__ params))
so that others who may have used the __attribute_nonnull__ idiom
do not have to track down weird compiler errors from system headers
using __nonnull(params) in addition to the application code which
uses __attribute_nonnull__ without params.

The impetus for this bug report is that lighttpd 1.4.60 release
breaks in Fedora Rawhide (which is using glibc 2.34.9000), due to
both lighttpd and glibc 2.34.9000 having different definitions
for __attribute_nonnull__.  lighttpd usage of __attribute_nonull__
does not expect __attribute_nonnull__(params) to require parameters,
leading to compiler errors where lighttpd headers uses
__attribute_nonnull__ without params.

Thank you.  Glenn
Comment 1 gstrauss 2021-10-05 23:26:44 UTC
In order to match glibc 2.35 development, I have modified lighttpd to define __attribute_nonnull__(params) with an argument for params, and I have modified lighttpd usage from __attribute_nonnull__ to __attribute_nonnull__().  (This is also extensible to filling in params, e.g. __attribute_nonnull((1,2,3)), as is recommended by gcc for passing a single arg or no arg to attributes.)

lighttpd patch (not glibc):
 #ifndef __attribute_nonnull__
 #if __has_attribute(nonnull) \
  || __GNUC_PREREQ(3,3)
-#define __attribute_nonnull__  __attribute__((__nonnull__))
+#define __attribute_nonnull__(params)  __attribute__((__nonnull__ params))
-#define __attribute_nonnull__
+#define __attribute_nonnull__(params)

(In hindsight, that is probably how I should have defined macros for attributes which take an optional single argument as parenthesized set of 0 or more arguments.)