mainAutoconf - Support: sr #110660, AC_LANG_INT_SAVE (used by...

 
 

sr #110660: AC_LANG_INT_SAVE (used by AC_CHECK_SIZEOF) includes stdlib.h without checking whether it actually exists

Submitter:  Alain Knaff <alainknaff>
Submitted:  Tue 17 May 2022 06:15:00 PM UTC
   
 
Priority:  * 3 - Release N+1 Severity:  1 - Wish
Status:  Done Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 08 Dec 2023 02:15:34 AM UTC, comment #4: 

From this minimal configure.ac


AC_INIT([test], [1.0])
AC_PROG_CC
AC_CHECK_SIZEOF([size_t])
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT


autoconf 2.71 generates a configure script which successfully detects the size of size_t when given a compiler that supplies stddef.h and stdint.h but not stdlib.h:


$ ./configure --host=aarch64-unknown-none CC="gcc -ffreestanding -nostdinc -nostdlib -nostartfiles -isystem /usr/lib/gcc/aarch64-unknown-linux-gnu/12.1.0/include"
checking for aarch64-unknown-none-gcc... gcc -ffreestanding -nostdinc -nostdlib -nostartfiles -isystem /usr/lib/gcc/aarch64-unknown-linux-gnu/12.1.0/include
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... yes
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc -ffreestanding -nostdinc -nostdlib -nostartfiles -isystem /usr/lib/gcc/aarch64-unknown-linux-gnu/12.1.0/include accepts -g... yes
checking for gcc -ffreestanding -nostdinc -nostdlib -nostartfiles -isystem /usr/lib/gcc/aarch64-unknown-linux-gnu/12.1.0/include option to enable C11 features... none needed
checking for stdio.h... no
checking for stdlib.h... no
checking for string.h... no
checking for inttypes.h... no
checking for stdint.h... yes
checking for strings.h... no
checking for sys/stat.h... no
checking for sys/types.h... no
checking for unistd.h... no
checking size of size_t... 8
configure: creating ./config.status
config.status: creating config.h


I also manually inspected configure and verified that it would not have malfunctioned if stdint.h hadn't been available. Since stddef.h must be provided even by a freestanding implementation of C89, I don't think there's anything left to do for this bug report and I'm going to go ahead and close it.  Please file new bugs if you encounter any more problems with running configure scripts against freestanding implementations of C.

Zack Weinberg <zackw>
Group administrator
Tue 17 May 2022 09:28:38 PM UTC, comment #3: 


> This fails if stdlib.h doesn't actually exist.

Yes, and that's documented behavior. The Autoconf manual says:

> If your program needs to be portable to a freestanding
> environment, such as an embedded OS that doesn't provide all of the
> facilities of the C90 standard library, you may need to test for some of
> the above headers as well.  Note that many Autoconf macros internally
> assume that the complete set of C90 headers are available.

It'd be nice if Autoconf also worked for freestanding programs too. That'd require a bit of work though. In the meantime I'll mark this as a wishlist item.

Paul Eggert <eggert>
Group administrator
Tue 17 May 2022 08:19:11 PM UTC, comment #2: 


comment #1:

> You've been filing all of these bugs -- exactly which version of Autoconf are you using to generate the configure scripts that show these bugs?


I'm using 2.69-14, currently included with Debian 11.

>  Some of the things you have said (e.g. talking about configure.in instead of configure.ac) suggest that you are using a very old version of Autoconf.


Indeed, I just noticed that this is 10 years old, and that there have been 2 new releases last year.

Sorry for not having noticed that earlier.

I'll continue my tests with the new version... Don't expect fast updates to my other bugs though, as a full run of configure takes between 2 and 3 hours...


>
> The code generated for AC_CHECK_SIZEOF, in current versions of autoconf, is completely different from the code you quoted, and does not make any use of either stdio.h or stdlib.h, so the bug seems moot to me.
>
> (N.B. Current versions of autoconf do not support pre-C89 compilers.  However, the bug report is abstractly valid anyway, because a "freestanding" C89 compiler doesn't have to provide stdio.h and stdlib.h.)


The compiler included with the UnixPC image I'm using is gcc 2.5.8 if that helps.
UnixPC also has a "native" cc compiler, but that one is unusable for the purpose as it is Kernighan&Ritchie syntax (no types in prototype)

Alain Knaff <alainknaff>
Tue 17 May 2022 07:44:38 PM UTC, comment #1: 

You've been filing all of these bugs -- exactly which version of Autoconf are you using to generate the configure scripts that show these bugs?  Some of the things you have said (e.g. talking about configure.in instead of configure.ac) suggest that you are using a very old version of Autoconf.

The code generated for AC_CHECK_SIZEOF, in current versions of autoconf, is completely different from the code you quoted, and does not make any use of either stdio.h or stdlib.h, so the bug seems moot to me.

(N.B. Current versions of autoconf do not support pre-C89 compilers.  However, the bug report is abstractly valid anyway, because a "freestanding" C89 compiler doesn't have to provide stdio.h and stdlib.h.)

Zack Weinberg <zackw>
Group administrator
Tue 17 May 2022 06:15:00 PM UTC, original submission:  

if stdlib.h doesn't exist, AC_CHECK_SIZEOF(size_t) fails with

conftest.c:80: stdlib.h: No such file or directory
configure:5433: error: cannot compute sizeof (size_t)



Code quoted in config.log includes the following:

...
| #ifdef HAVE_UNISTD_H
| # include <unistd.h>
| #endif
| static long int longval () { return (long int) (sizeof (size_t)); }
| static unsigned long int ulongval () { return (long int) (sizeof (size_t)); }
| #include <stdio.h>
| #include <stdlib.h>
| int
| main ()
| {
|
|   FILE *f = fopen ("conftest.val", "w");
|   if (! f)
|     return 1;
|   if (((long int) (sizeof (size_t))) < 0)
|     {
|       long int i = longval ();
|       if (i != ((long int) (sizeof (size_t))))
| return 1;
|       fprintf (f, "%ld", i);
|     }
|   else
|     {
|       unsigned long int i = ulongval ();
|       if (i != ((long int) (sizeof (size_t))))
| return 1;
|       fprintf (f, "%lu", i);
|     }
|   /* Do not output a trailing newline, as this causes \r\n confusion
|      on some platforms.  */
|   return ferror (f) || fclose (f) != 0;
...

As you see, most includes are correctly protected by #ifdef HAVE_*, except stdio.h and stdlib.h

This fails if stdlib.h doesn't actually exist. Most other tests until then run fine (AC_CHECK_LIB, AC_CHECK_HEADERS, AC_CHECK_TYPES).

N.B. I do have AC_CHECK_HEADERS(stdlib.h) early in my configure.in, it correctly determines that stdlib.h doesn't exist, but that result is not used by AC_LANG_INT_SAVE

Alain Knaff <alainknaff>

 

(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 eggert (Posted a comment)
  • -email is unavailable- added by zackw (Posted a comment)
  • -email is unavailable- added by alainknaff (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-12-08 zackw StatusNone Done
        Open/ClosedOpen Closed
    2022-05-17 eggert Priority5 - Unprioritized 3 - Release N+1
        Severity3 - Normal 1 - Wish

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code