[PATCH v4] assert: Refactor assert/assert_perror
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Wed Oct 1 18:01:12 GMT 2025
On 26/09/25 07:44, Yury Khrustalev wrote:
> Hi Adhemerval,
>
> On Thu, Aug 21, 2025 at 08:48:13AM -0300, Adhemerval Zanella wrote:
>> It now calls __libc_assert, which contains similar logic. The assert
>> call only requires memory allocation for the message translation, so
>> test-assert2.c is adapted to handle it.
>>
>> It also removes the fxprintf from assert/assert_perror; although it
>> is not 100% backwards-compatible (write message only if there is a
>> file descriptor associated with the stderr). It now writes bytes
>> directly without going through the wide stream state.
>>
>> Checked on aarch64-linux-gnu.
>
> This change causes compilation error when compiling with -Og:
>
> In file included from ../include/sys/cdefs.h:10,
> from ../include/features.h:524,
> from ../stdlib/errno.h:25,
> from ../include/errno.h:2,
> from ../sysdeps/unix/sysv/linux/libc_fatal.c:19:
> ../include/stdio.h: In function ‘__libc_message_wrapper’:
> ../misc/sys/cdefs.h:639:30: error: invalid use of ‘__builtin_va_arg_pack_len ()’
> 639 | # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../include/stdio.h:191:7: note: in expansion of macro ‘__va_arg_pack_len’
> 191 | if (__va_arg_pack_len () > LIBC_MESSAGE_MAX_ARGS)
> | ^~~~~~~~~~~~~~~~~
> In file included from ../sysdeps/posix/libc_fatal.c:23,
> from ../sysdeps/unix/sysv/linux/libc_fatal.c:36:
> ../include/stdio.h:194:7: error: call to ‘__libc_message_error’ declared with attribute error: invalid number of arguments
> 194 | __libc_message_error ();
> | ^~~~~~~~~~~~~~~~~~~~~~~
> ../include/stdio.h:197:3: error: invalid use of ‘__builtin_va_arg_pack ()’
> 197 | __libc_message_impl (vmaname, fmt, __va_arg_pack ());
>
>> ...
>>
Right, I haven't see it because this is not an usual compiler option.
>> diff --git a/include/stdio.h b/include/stdio.h
>> index 3d917dba5b..d9a839e115 100644
>> --- a/include/stdio.h
>> +++ b/include/stdio.h
>>
>> ...
>>
>> +static inline _Noreturn void __libc_message_wrapper (const char *vmaname,
>> + const char *fmt, ...)
>
> I think this should also have __attribute__ ((__always_inline__)) to
> make use of __builtin_va_arg_pack_len() valid for all optimisation
> levels.
It seems reasonable, although I think we will need to fix other issues
to fully enable -Og support. With gcc 15.1 I am seeing some build issues
with -Werror:
malloc.c:3315:20: error: ‘csize’ may be used uninitialized [-Werror=maybe-uninitialized]
3315 | && csize == nb
| ~~~~~~^~~~~
malloc.c: In function ‘_mid_memalign’:
malloc.c:3297:14: note: ‘csize’ was declared here
3297 | size_t csize;
| ^~~~~
cc1: all warnings being treated as errors
regexec.c: In function ‘check_node_accept_bytes’:
regexec.c:3776:36: error: ‘extra’ may be used uninitialized [-Werror=maybe-uninitialized]
3776 | const unsigned char *coll_sym = extra + cset->coll_syms[i];
| ^~~~~~~~
regexec.c:3762:42: note: ‘extra’ was declared here
3762 | const unsigned char *weights, *extra;
| ^~~~~
res_send.c: In function ‘reopen’:
res_send.c:856:21: error: ‘slen’ may be used uninitialized [-Werror=maybe-uninitialized]
856 | if (__connect (EXT (statp).nssocks[ns], nsap, slen) < 0) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
res_send.c:804:27: note: ‘slen’ was declared here
804 | socklen_t slen;
| ^~~~
These are issues that we already suppress for -Os, so I think we will need to
make it enable for -Og as well.
More information about the Libc-alpha
mailing list