defer test for limits.h existence to runtime [PR80677]

Message ID 20240430184539.GA1403510@subdivi.de
State New
Headers
Series defer test for limits.h existence to runtime [PR80677] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed

Commit Message

Helmut Grohne April 30, 2024, 6:45 p.m. UTC
  The definition of LIMITS_H_TEST evaluates its existence in
BUILD_SYSTEM_HEADER_DIR, but we'd actually need it to check a target
version. Hence this check occasionally produces misdetections when build
and target differ. In some cases such as cygming, the header is only
installed after performing the build. Instead of resolving these
situations by guessing, defer the test to the time of use and check for
the header using __has_include_next which will use the correct include
search path.

2024-04-30  Helmut Grohne  <helmut@subdivi.de>

	PR bootstrap/80677
        * gcc/limitx.h: Only #include syslimits.h when another <limits.h>
	  exists.
        * gcc/limity.h: Only #include limits.h when another <limits.h>
	  exists.
        * gcc/Makefile.in: Delete LIMITS_H_TEST default and always wrap
	  limits.h with limitx.h and limity.h.
	* Makefile.tpl: Drop forwarding of LIMITS_H_TEST
	* Makefile.in: Regenerate.
	* gcc/config/i386/t-cygming: Delete unused LIMITS_H_TEST.
	* gcc/config/t-rtems: Likewise.
	* gcc/config/t-vxworks: Likewise.
	* gcc/config/vms/t-vms: Likewise.

Signed-off-by: Helmut Grohne <helmut@subdivi.de>
---
 Makefile.in               | 3 +--
 Makefile.tpl              | 3 +--
 gcc/Makefile.in           | 9 +--------
 gcc/config/i386/t-cygming | 4 ----
 gcc/config/t-rtems        | 2 --
 gcc/config/t-vxworks      | 6 ------
 gcc/config/vms/t-vms      | 2 --
 gcc/limitx.h              | 2 +-
 gcc/limity.h              | 2 +-
 9 files changed, 5 insertions(+), 28 deletions(-)

Please Cc me in replies.

"make bootstrap" passes on today's gcc master.

Bootstrapping Debian without this patch produces a broken toolchain that
assumes absent <limits.h> and thus defines limits inconsistently with
glibc.
  

Patch

diff --git a/Makefile.in b/Makefile.in
index db4fa6c6260..16785a98305 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1069,8 +1069,7 @@  TARGET_FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_TARGET_FLAGS)
 EXTRA_GCC_FLAGS = \
 	"GCC_FOR_TARGET=$(GCC_FOR_TARGET) $$TFLAGS" \
 	"GM2_FOR_TARGET=$(GM2_FOR_TARGET) $$TFLAGS" \
-	"`echo 'STMP_FIXPROTO=$(STMP_FIXPROTO)' | sed -e s'/[^=][^=]*=$$/XFOO=/'`" \
-	"`echo 'LIMITS_H_TEST=$(LIMITS_H_TEST)' | sed -e s'/[^=][^=]*=$$/XFOO=/'`"
+	"`echo 'STMP_FIXPROTO=$(STMP_FIXPROTO)' | sed -e s'/[^=][^=]*=$$/XFOO=/'`"
 
 GCC_FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_HOST_FLAGS) $(EXTRA_GCC_FLAGS)
 
diff --git a/Makefile.tpl b/Makefile.tpl
index 1d5813cd569..991d9738016 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -825,8 +825,7 @@  TARGET_FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_TARGET_FLAGS)
 EXTRA_GCC_FLAGS = \
 	"GCC_FOR_TARGET=$(GCC_FOR_TARGET) $$TFLAGS" \
 	"GM2_FOR_TARGET=$(GM2_FOR_TARGET) $$TFLAGS" \
-	"`echo 'STMP_FIXPROTO=$(STMP_FIXPROTO)' | sed -e s'/[^=][^=]*=$$/XFOO=/'`" \
-	"`echo 'LIMITS_H_TEST=$(LIMITS_H_TEST)' | sed -e s'/[^=][^=]*=$$/XFOO=/'`"
+	"`echo 'STMP_FIXPROTO=$(STMP_FIXPROTO)' | sed -e s'/[^=][^=]*=$$/XFOO=/'`"
 
 GCC_FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_HOST_FLAGS) $(EXTRA_GCC_FLAGS)
 
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index a74761b7ab3..debcc5a6bb0 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -581,9 +581,6 @@  BUILD_SYSTEM_HEADER_DIR = `echo @BUILD_SYSTEM_HEADER_DIR@ | sed -e :a -e 's,[^/]
 # Control whether to run fixincludes.
 STMP_FIXINC = @STMP_FIXINC@
 
-# Test to see whether <limits.h> exists in the system header files.
-LIMITS_H_TEST = [ -f $(BUILD_SYSTEM_HEADER_DIR)/limits.h ]
-
 # Directory for prefix to system directories, for
 # each of $(system_prefix)/usr/include, $(system_prefix)/usr/lib, etc.
 TARGET_SYSTEM_ROOT = @TARGET_SYSTEM_ROOT@
@@ -3327,11 +3324,7 @@  stmp-int-hdrs: $(STMP_FIXINC) $(T_GLIMITS_H) $(T_STDINT_GCC_H) $(USER_H) fixinc_
 	  sysroot_headers_suffix=`echo $${ml} | sed -e 's/;.*$$//'`; \
 	  multi_dir=`echo $${ml} | sed -e 's/^[^;]*;//'`; \
 	  include_dir=include$${multi_dir}; \
-	  if $(LIMITS_H_TEST) ; then \
-	    cat $(srcdir)/limitx.h $(T_GLIMITS_H) $(srcdir)/limity.h > tmp-xlimits.h; \
-	  else \
-	    cat $(T_GLIMITS_H) > tmp-xlimits.h; \
-	  fi; \
+	  cat $(srcdir)/limitx.h $(T_GLIMITS_H) $(srcdir)/limity.h > tmp-xlimits.h; \
 	  $(mkinstalldirs) $${include_dir}; \
 	  chmod a+rx $${include_dir} || true; \
 	  $(SHELL) $(srcdir)/../move-if-change \
diff --git a/gcc/config/i386/t-cygming b/gcc/config/i386/t-cygming
index af01f69acd1..50bf0c149e8 100644
--- a/gcc/config/i386/t-cygming
+++ b/gcc/config/i386/t-cygming
@@ -16,10 +16,6 @@ 
 # along with GCC; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.
 
-# cygwin and mingw always have a limits.h, but, depending upon how we are
-# doing the build, it may not be installed yet.
-LIMITS_H_TEST = true
-
 winnt.o: $(srcdir)/config/i386/winnt.cc $(CONFIG_H) $(SYSTEM_H) coretypes.h \
   $(TM_H) $(RTL_H) $(REGS_H) hard-reg-set.h output.h $(TREE_H) flags.h \
   $(TM_P_H) $(HASH_TABLE_H) $(GGC_H) $(LTO_STREAMER_H)
diff --git a/gcc/config/t-rtems b/gcc/config/t-rtems
index baa00d83176..e69de29bb2d 100644
--- a/gcc/config/t-rtems
+++ b/gcc/config/t-rtems
@@ -1,2 +0,0 @@ 
-# RTEMS always has limits.h.
-LIMITS_H_TEST = true
diff --git a/gcc/config/t-vxworks b/gcc/config/t-vxworks
index 6063943e346..a73759b29cc 100644
--- a/gcc/config/t-vxworks
+++ b/gcc/config/t-vxworks
@@ -40,12 +40,6 @@  vxworks-rust.o: $(srcdir)/config/vxworks-rust.cc
 
 NATIVE_SYSTEM_HEADER_DIR =
 
-# Both the kernel and RTP headers provide limits.h.  They embed VxWorks
-# specificities and are dated on some configurations so we both need to
-# provide our own version and make sure the system one gets exposed.
-
-LIMITS_H_TEST = true
-
 # VxWorks system environments have been GCC based for a long time and
 # we need to make sure that our files and the system ones use distinct
 # macro names to protect against recursive inclusions.  We achieve
diff --git a/gcc/config/vms/t-vms b/gcc/config/vms/t-vms
index 251915ca017..08ac7352469 100644
--- a/gcc/config/vms/t-vms
+++ b/gcc/config/vms/t-vms
@@ -16,8 +16,6 @@ 
 # along with GCC; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.
 
-LIMITS_H_TEST = false
-
 vms-crtlmap.h: $(srcdir)/config/vms/vms-crtlmap.map  \
   $(srcdir)/config/vms/make-crtlmap.awk
 	$(AWK) -f $(srcdir)/config/vms/make-crtlmap.awk \
diff --git a/gcc/limitx.h b/gcc/limitx.h
index e27597ef699..13b233b0090 100644
--- a/gcc/limitx.h
+++ b/gcc/limitx.h
@@ -29,7 +29,7 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #ifndef _GCC_LIMITS_H_  /* Terminated in limity.h.  */
 #define _GCC_LIMITS_H_
 
-#ifndef _LIBC_LIMITS_H_
+#if !defined(_LIBC_LIMITS_H_) && __has_include_next(<limits.h>)
 /* Use "..." so that we find syslimits.h only in this same directory.  */
 #include "syslimits.h"
 #endif
diff --git a/gcc/limity.h b/gcc/limity.h
index 8bb398f6786..29998be8033 100644
--- a/gcc/limity.h
+++ b/gcc/limity.h
@@ -3,7 +3,7 @@ 
 
 #else /* not _GCC_LIMITS_H_ */
 
-#ifdef _GCC_NEXT_LIMITS_H
+#if defined(_GCC_NEXT_LIMITS_H) && __has_include_next(<limits.h>)
 #include_next <limits.h>		/* recurse down to the real one */
 #endif