* Eric Blake:
On 7/17/20 6:48 AM, Richard W.M. Jones wrote:
>> I suspect that the fragment lands in the body of main, where the
>> reference to sys_errlist is simply optimized away.
>
> Very true. Let's see what the test file actually contains
> by adding an exit into the configure script ...
> int
> main ()
> {
> extern int sys_errlist; char *p = &sys_errlist;
> ;
> return 0;
Indeed, this could be a case of link-time optimization (since p is not
used, the resolution of &sys_errlist does not matter).
Link-time optimization is not necessary because it's a local variable.
Perhaps enhancing the test to do:
char *p = &sys_errlist;
return p[0];
bypasses the chance for link optimization?
Not really, since the type of sys_errlist is wrong. If LTO detects
that, the compiler should probably turn the reference into a trap, and
then it's gone as well.
Thanks,
Florian