mainAutoconf - Support: sr #110382, Make confdefs.h idempotent vs...

 
 

sr #110382: Make confdefs.h idempotent vs compiler warnings

Submitter:  Sergei Trofimovich <slyfox>
Submitted:  Wed 25 Nov 2020 07:53:31 AM UTC
   
 
Priority:  * 3 - Release N+1 Severity:  1 - Wish
Status:  Confirmed Privacy:  Public
Assigned to:  None Open/Closed:  Open
Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 08 Dec 2023 02:25:20 PM UTC, comment #3: 

Thinking about this one some more, I see two ways to make confdefs.h idempotent:

1. A conventional "multiple inclusion guard", wrapping the body of the file in #ifndef ... #endif.  This will work on all compilers and regardless of whether confdefs.h is included or concatenated with the test program, but requires us to change AC_DEFINE and friends to do something like


#define MACRO 1


The thing I'm worried about with this one is if there's third party macros out there somewhere that bypass AC_DEFINE.  The sed construct up there should be portable.

2. Alternatively, use #pragma once and change AC_LANG_CONFTEST(C) to #include confdefs.h rather than prepending its contents to the test program.  This would keep macros that bypass AC_DEFINE working, but would break with compilers that make #pragma once do something wacky (it should be no worse than the status quo with compilers that merely ignore #pragma once). I also wonder if there's a concrete reason why AC_LANG_CONFTEST(C) shouldn't #include confdefs.h.

We should be able to get this done for 2.73.

Zack Weinberg <zackw>
Group administrator
Wed 25 Nov 2020 08:06:30 PM UTC, comment #2: 

Autoconf has always implicitly embedded the contents of confdefs.h at the top of every test program it compiles.  This behavior is at least 20 years old, probably even longer -- I think I remember autoconf 2.13 doing it.

Your code breaks with 2.69d because AC_USE_SYSTEM_EXTENSIONS defines more macros now, and that trips what appears to be a bug in GCC. Consider this test fragment:


#define ordinary_macro 1
#define ordinary_macro 1
#define __STDC_anything 1
#define __STDC_anything 1


Compiling with -Werror, I get a "macro __STDC_anything redefined" error with GCC 9 and 10, but I do not get a "macro ordinary_macro redefined" error.  With clang, I get no errors at all.  I've reported this as a bug in GCC: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97998>.

> I wonder if 'confdefs.h' would benefit from '#ifndef / #define / #endif' guards.


This is a good idea but will not be possible for 2.70, because confdefs.h is built up over the course of the configure process, by appending to it with shell `>>`.  We would have to come up with a way to insert each new definition before the #endif.  I think this would be possible with clever use of `sed` but it would be too risky of a change for how close to the release we are.

I'm going to tag this bug to be revisited after the 2.70 release, when we may be able to make a change along the lines you suggest, and add something to the release notes about this problem.

Please be aware that running configure tests with -Werror in effect is not supported.  We cannot currently guarantee that the code generated for various tests will remain warning-free as C compilers continue to get pickier.  It's on the TODO list, but it's going to take major internal changes (for instance, the code generated by AC_CHECK_FUNC is just plain wrong, but we've been putting off a fix for decades because of how difficult it will be to fix it without breaking anything).

Zack Weinberg <zackw>
Group administrator
Wed 25 Nov 2020 06:49:23 PM UTC, comment #1: 

I attempted to fix in `apr` by using `AC_LANG_PROGRAM` as https://github.com/apache/apr/pull/25

Sergei Trofimovich <slyfox>
Wed 25 Nov 2020 07:53:31 AM UTC, original submission:  

I'm not sure if it's a bug or feature. Filing a bug to clarify.

Initially bug is observed on apr-1.7.0 package: https://bugs.gentoo.org/750353

Here is a small example extracted from apr source code at https://github.com/apache/apr/blob/trunk/build/apr_common.m4#L508:


AC_PREREQ([2.59])

AC_INIT

dnl this seems to be the trigger:
AC_USE_SYSTEM_EXTENSIONS

CFLAGS="$CFLAGS -Werror"
AC_COMPILE_IFELSE(
  [AC_LANG_SOURCE(
   [#include "confdefs.h"
   int main(int argc, const char *const *argv) { return 0; }]
  )], [:], [AC_MSG_ERROR(Found warnings)])

AC_OUTPUT


Worked before as:


$ autoreconf-2.69 && ./configure --host=x86_64-pc-linux-gnu
checking for x86_64-pc-linux-gnu-gcc... x86_64-pc-linux-gnu-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 x86_64-pc-linux-gnu-gcc accepts -g... yes
checking for x86_64-pc-linux-gnu-gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... x86_64-pc-linux-gnu-gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
configure: creating ./config.status


OK.

Fails now:


$ autoreconf-2.69d && ./configure --host=x86_64-pc-linux-gnu
checking for x86_64-pc-linux-gnu-gcc... x86_64-pc-linux-gnu-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 the compiler supports GNU C... yes
checking whether x86_64-pc-linux-gnu-gcc accepts -g... yes
checking for x86_64-pc-linux-gnu-gcc option to enable C11 features... none needed
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking whether _XOPEN_SOURCE should be defined... no
configure: error: Found warnings


config.log says it happens because now "confdefs.h" is already included in tests:


...
configure:3350: x86_64-pc-linux-gnu-gcc -c -g -O2 -Werror  conftest.c >&5
In file included from conftest.c:31:
confdefs.h:22: error: "__STDC_WANT_IEC_60559_ATTRIBS_EXT__" redefined [-Werror]
   22 | #define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1
      |
...
cc1: all warnings being treated as errors
configure:3350: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define STDC_HEADERS 1
| #define __EXTENSIONS__ 1
| #define _ALL_SOURCE 1
| #define _DARWIN_C_SOURCE 1
| #define _GNU_SOURCE 1
| #define _POSIX_PTHREAD_SEMANTICS 1
| #define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1
| #define __STDC_WANT_IEC_60559_BFP_EXT__ 1
| #define __STDC_WANT_IEC_60559_DFP_EXT__ 1
| #define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1
| #define __STDC_WANT_IEC_60559_TYPES_EXT__ 1
| #define __STDC_WANT_LIB_EXT2__ 1
| #define __STDC_WANT_MATH_SPEC_FUNCS__ 1
| #define _TANDEM_SOURCE 1
| /* end confdefs.h.  */
| #include "confdefs.h"
|    int main(int argc, const char *const *argv) { return 0; }
|
configure:3354: error: Found warnings


I wonder if 'confdefs.h' would benefit from '#ifndef / #define / #endif' guards.

Thank you!

Sergei Trofimovich <slyfox>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by zackw (Posted a comment)
  • -email is unavailable- added by slyfox (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-12-08 zackw SummaryMake confdefs.h idempotent Make confdefs.h idempotent vs compiler warnings
    2023-12-08 zackw SummaryIn autoconf-2.69d AC_LANG_SOURCE implicitly includes '#include &quot;confdefs.h&quot;' Make confdefs.h idempotent
    2023-12-08 zackw Priority1 - Blocked 3 - Release N+1
    2020-11-25 zackw Priority5 - Unprioritized 1 - Blocked
        Severity3 - Normal 1 - Wish
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-5190.
    Corresponding source code