Re: False positive in skalibs system feature test

From: Guillermo <>
Date: Fri, 25 Oct 2019 16:35:20 -0300

El vie., 25 oct. 2019 a las 14:30, Shengjing Zhu escribió:
> Not familiar with autoconf, but I found the following snippet in autoconf code.
> ```
> #if defined __stub_$1 || defined __stub___$1
> choke me
> #endif

This seems to be indeed what Autoconf currently uses when the
AC_CHECK_FUNC macro is used to check if a function is available. The
__stub_* macros are in <gnu/stubs.h> (which on my Gentoo x86_64 system
includes <gnu/stubs-64.h>), an autogenerated GNU libc header included
by <features.h>. I tried this with getrandom(), which exists, and
lchmod(), which is a libc stub. Here are the results:

$ nm -D /lib64/ | grep -E 'lchmod|getrandom'
000000000003d980 T getrandom
00000000000f5aa0 T lchmod

$ cat /usr/include/gnu/stubs-64.h
/* This file is automatically generated.
   It defines a symbol `__stub_FUNCTION' for each function
   in the C library which is a stub, meaning it will fail
   every time called, usually setting errno to ENOSYS. */
#ifdef _LIBC
 #error Applications may not define the macro _LIBC
#define __stub_lchmod

$ cat
AC_INIT(example, 1.0)

$ autoconf -V
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<>, <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David J. MacKenzie and Akim Demaille.

$ autoconf
$ ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for getrandom... yes
checking for lchmod... no
configure: creating ./config.status

$ cat config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by example configure 1.0, which was
generated by GNU Autoconf 2.69.
configure:2634: checking for lchmod
configure:2634: gcc -o conftest -g -O2 conftest.c >&5
conftest.c:37:1: error: unknown type name 'choke'
 choke me
conftest.c:37:9: error: expected ';' before 'int'
 choke me
configure:2634: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "example"
| #define PACKAGE_TARNAME "example"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "example 1.0"
| #define PACKAGE_URL ""
| /* end confdefs.h. */
| /* Define lchmod to an innocuous variant, in case <limits.h> declares lchmod.
| For example, HP-UX 11i <limits.h> declares gettimeofday. */
| #define lchmod innocuous_lchmod
| /* System header to define __stub macros and hopefully few prototypes,
| which can conflict with char lchmod (); below.
| Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
| <limits.h> exists even on freestanding compilers. */
| #ifdef __STDC__
| # include <limits.h>
| #else
| # include <assert.h>
| #endif
| #undef lchmod
| /* Override any GCC internal prototype to avoid an error.
| Use char because int might match the return type of a GCC
| builtin and then its argument prototype would still apply. */
| #ifdef __cplusplus
| extern "C"
| #endif
| char lchmod ();
| /* The GNU C library defines this for functions which it implements
| to always fail with ENOSYS. Some functions are actually named
| something starting with __ and the normal name is an alias. */
| #if defined __stub_lchmod || defined __stub___lchmod
| choke me
| #endif
| int
| main ()
| {
| return lchmod ();
| ;
| return 0;
| }
configure:2634: result: no

As you can see, only the equivalent of a 'choose cl' is used here.

Received on Fri Oct 25 2019 - 19:35:20 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC