]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Move NO_PIE_CFLAGS logic from gcc to libgcc
authorJohn Ericson <git@JohnEricson.me>
Tue, 9 Dec 2025 22:06:51 +0000 (22:06 +0000)
committerJoseph Myers <josmyers@redhat.com>
Tue, 9 Dec 2025 22:06:51 +0000 (22:06 +0000)
My goal is to be able to build libgcc cleanly in isolation --- today one
needs to figure `make ...` misc things in the gcc subdir.

Following Andrew Pinski's suggestions in
https://gcc.gnu.org/pipermail/gcc-patches/2025-July/689683.html, this
commit moves the NO_PIE_CFLAGS logic.

gcc/ChangeLog:

* Makefile.in:: Remove NO_PIE_CFLAGS logic, since it is now in
libgcc.
* configure: Regenerate.
* configure.ac: Remove the enable_default_pie substitution, since
libgcc now has its own logic.

libgcc/ChangeLog:

* Makefile.in: Define NO_PIE_CFLAGS make variable via autoconf
substitution.
* configure: Regenerate.
* configure.ac: New configure check to define NO_PIE_CFLAGS
using the algorithm Andrew asked for in the linked mail.

Suggested-by: Andrew Pinski <quic_apinski@quicinc.com>
Signed-off-by: John Ericson <git@JohnEricson.me>
gcc/Makefile.in
gcc/configure
gcc/configure.ac
libgcc/Makefile.in
libgcc/configure
libgcc/configure.ac

index 2c3194e7d1e38f80b28e15475b018a7df5bf16ac..a9264bde9bc5c73aca083ede07711d7e3d5f6fd4 100644 (file)
@@ -2504,12 +2504,6 @@ libgcc.mvars: config.status Makefile specs xgcc$(exeext)
        echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
        echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
        echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
-       if test @enable_default_pie@ = yes; then \
-         NO_PIE_CFLAGS="-fno-PIE"; \
-       else \
-         NO_PIE_CFLAGS=; \
-       fi; \
-       echo NO_PIE_CFLAGS = "$$NO_PIE_CFLAGS" >> tmp-libgcc.mvars
 
        mv tmp-libgcc.mvars libgcc.mvars
 
index d7074355e42b5dc860d8a2690b97a9942b852d58..f349c1dc4c12814b903691d16627d20390d2ff2a 100755 (executable)
@@ -635,7 +635,6 @@ LIBOBJS
 CET_HOST_FLAGS
 LD_PICFLAG
 PICFLAG
-enable_default_pie
 libgccjit_version
 enable_host_bind_now
 LIBGDIAGNOSTICS
@@ -21877,7 +21876,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 21880 "configure"
+#line 21879 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -21983,7 +21982,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 21986 "configure"
+#line 21985 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -34939,7 +34938,6 @@ $as_echo "#define ENABLE_DEFAULT_PIE 1" >>confdefs.h
 
 fi
 
-
 # Check if -fno-PIE works.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-PIE option" >&5
 $as_echo_n "checking for -fno-PIE option... " >&6; }
index b6d9608d5994f559fe7b1ccd1deb86a530195615..c652257f29eb15f21cc56a5d6428b386227a6f01 100644 (file)
@@ -7765,7 +7765,6 @@ if test x$enable_default_pie = xyes ; then
   AC_DEFINE(ENABLE_DEFAULT_PIE, 1,
       [Define if your target supports default PIE and it is enabled.])
 fi
-AC_SUBST([enable_default_pie])
 
 # Check if -fno-PIE works.
 AC_CACHE_CHECK([for -fno-PIE option],
index 32a5a15813f81c683b5988e6b2c942d3320548ae..f0cbcb8004b9c2b03a2aadf9701a16757b801dfd 100644 (file)
@@ -298,6 +298,8 @@ override CFLAGS := $(filter-out -fprofile-generate -fprofile-use,$(CFLAGS))
 INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
                  $(INCLUDES) @set_have_cc_tls@ @set_use_emutls@
 
+NO_PIE_CFLAGS = @NO_PIE_CFLAGS@
+
 # Options to use when compiling crtbegin/end.
 CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
   $(NO_PIE_CFLAGS) -finhibit-size-directive -fno-inline -fno-exceptions \
index be5b5a91ece8b5d130d4182202d5f28c71835629..fe7a21c296c3b7cd945c9822b34e47554500171e 100755 (executable)
@@ -610,6 +610,7 @@ accel_dir_suffix
 use_tm_clone_registry
 force_explicit_eh_registry
 CET_FLAGS
+NO_PIE_CFLAGS
 fixed_point
 enable_decimal_float
 decimal_float
@@ -4836,6 +4837,40 @@ $as_echo "$libgcc_cv_fixed_point" >&6; }
 fixed_point=$libgcc_cv_fixed_point
 
 
+# Check whether the compiler defines __PIE__ by default, so -fno-PIE is needed.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler defines __PIE__" >&5
+$as_echo_n "checking whether the compiler defines __PIE__... " >&6; }
+if ${libgcc_cv_no_pie_cflags+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#ifdef __PIE__
+#error __PIE__ defined
+#endif
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libgcc_cv_no_pie_cflags=''
+else
+  libgcc_cv_no_pie_cflags='-fno-PIE'
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgcc_cv_no_pie_cflags" >&5
+$as_echo "$libgcc_cv_no_pie_cflags" >&6; }
+
+NO_PIE_CFLAGS=$libgcc_cv_no_pie_cflags
+
+
 # For platforms with the unwind ABI which includes an unwind library,
 # libunwind, we can choose to use the system libunwind.
 # config.gcc also contains tests of with_system_libunwind.
index 97fd17cddc695f27957ce440ecf8019d063a7976..59452436bd8ab379c69fc096ee1fb83898d20cbd 100644 (file)
@@ -258,6 +258,20 @@ AC_CACHE_CHECK([whether fixed-point is supported], [libgcc_cv_fixed_point],
 fixed_point=$libgcc_cv_fixed_point
 AC_SUBST(fixed_point)
 
+# Check whether the compiler defines __PIE__ by default, so -fno-PIE is needed.
+AC_CACHE_CHECK([whether the compiler defines __PIE__], [libgcc_cv_no_pie_cflags],
+  [AC_COMPILE_IFELSE(
+     [AC_LANG_PROGRAM([[
+#ifdef __PIE__
+#error __PIE__ defined
+#endif
+     ]], [[]])],
+     [libgcc_cv_no_pie_cflags=''],
+     [libgcc_cv_no_pie_cflags='-fno-PIE'])])
+
+NO_PIE_CFLAGS=$libgcc_cv_no_pie_cflags
+AC_SUBST([NO_PIE_CFLAGS])
+
 # For platforms with the unwind ABI which includes an unwind library,
 # libunwind, we can choose to use the system libunwind.
 # config.gcc also contains tests of with_system_libunwind.