Hi
> > For now, you can sidestep the issue by arranging for HAVE_STDARG_H to be
> > defined before including readline.h, perhaps on the cc/gcc command line.
>
> I made this fix, but reverted it because I thought readline.h should be fixed.
I was wrong. rl_message() causes segfault without defining HAVE_STDARG_H.
=====================================================================
The version number and release status of Readline (e.g., 4.2-release)
8.2-release or before (already fixed on Git-devel)
========================================
The machine and OS that it is running on
macOS Ventura 13.4
=============================================================================
A list of the compilation flags or the contents of `config.h', if appropriate
========================
a description of the bug
rl_message() causes segfault on Apple Silicon mac (or other processors with similar ABIs).
$ cat rl_message_segfault.c
#include <stdio.h>
#include <readline/readline.h>
int
main ()
{
rl_initialize();
printf("%p\n", (char *)-1); // push a wrong pointer on the stack
rl_message("%s", "hello");
}
$ cc -DHAVE_STDARG_H -I/Users/hiroo/Work/trg/8.2/include -L /Users/hiroo/Work/trg/8.2/lib -lreadline rl_message_segfault.c -o rl_message_no_segfault
$ ./rl_message_no_segfault
0xffffffffffffffff
$ cc -I/Users/hiroo/Work/trg/8.2/include -L /Users/hiroo/Work/trg/8.2/lib -lreadline rl_message_segfault.c -o rl_message_segfault
rl_message_segfault.c:9:15: warning: passing arguments to 'rl_message' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
rl_message("%s", "hello");
^
1 warning generated.
$ ./rl_message_segfault
0xffffffffffffffff
make: *** [report] Segmentation fault: 11
...
If HAVE_STDARG_H is defined, we have no segfault.
If not, it causes segfault.
From https://developer.apple.com/documentation/apple-silicon/addressing-architectural-differences-in-your-macos-code#Dont-Redeclare-a-Function-to-Have-Variable-Parameters
> On x86_64, the compiler treats fixed and variadic parameters the same, placing parameters in registers first
> and only using the stack when no more registers are available. On arm64, the compiler always places variadic
> parameters on the stack, regardless of whether registers are available.
In the code above, rl_message() assumes a variadic parameter "hello" is placed on the stack.
But rl_message() in main() the parameter is placed in a register without the correct declaration of rl_message().
rl_messages() uses the parameter (char *)-1 which was left by printf().
========================================
a recipe for recreating the bug reliably
See above.
==================================
a fix for the bug if you have one!
Define HAVE_STDARG_H or use the next release (8.3 or later).