Skip to content

Commit 77144dd

Browse files
Ericson2314jsm28
authored andcommitted
Move NO_PIE_CFLAGS logic from gcc to libgcc
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 <[email protected]> Signed-off-by: John Ericson <[email protected]>
1 parent e5d853b commit 77144dd

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

gcc/Makefile.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,12 +2504,6 @@ libgcc.mvars: config.status Makefile specs xgcc$(exeext)
25042504
echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
25052505
echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
25062506
echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
2507-
if test @enable_default_pie@ = yes; then \
2508-
NO_PIE_CFLAGS="-fno-PIE"; \
2509-
else \
2510-
NO_PIE_CFLAGS=; \
2511-
fi; \
2512-
echo NO_PIE_CFLAGS = "$$NO_PIE_CFLAGS" >> tmp-libgcc.mvars
25132507

25142508
mv tmp-libgcc.mvars libgcc.mvars
25152509

gcc/configure

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,6 @@ LIBOBJS
635635
CET_HOST_FLAGS
636636
LD_PICFLAG
637637
PICFLAG
638-
enable_default_pie
639638
libgccjit_version
640639
enable_host_bind_now
641640
LIBGDIAGNOSTICS
@@ -21877,7 +21876,7 @@ else
2187721876
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
2187821877
lt_status=$lt_dlunknown
2187921878
cat > conftest.$ac_ext <<_LT_EOF
21880-
#line 21880 "configure"
21879+
#line 21879 "configure"
2188121880
#include "confdefs.h"
2188221881

2188321882
#if HAVE_DLFCN_H
@@ -21983,7 +21982,7 @@ else
2198321982
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
2198421983
lt_status=$lt_dlunknown
2198521984
cat > conftest.$ac_ext <<_LT_EOF
21986-
#line 21986 "configure"
21985+
#line 21985 "configure"
2198721986
#include "confdefs.h"
2198821987

2198921988
#if HAVE_DLFCN_H
@@ -34939,7 +34938,6 @@ $as_echo "#define ENABLE_DEFAULT_PIE 1" >>confdefs.h
3493934938

3494034939
fi
3494134940

34942-
3494334941
# Check if -fno-PIE works.
3494434942
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-PIE option" >&5
3494534943
$as_echo_n "checking for -fno-PIE option... " >&6; }

gcc/configure.ac

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7765,7 +7765,6 @@ if test x$enable_default_pie = xyes ; then
77657765
AC_DEFINE(ENABLE_DEFAULT_PIE, 1,
77667766
[Define if your target supports default PIE and it is enabled.])
77677767
fi
7768-
AC_SUBST([enable_default_pie])
77697768

77707769
# Check if -fno-PIE works.
77717770
AC_CACHE_CHECK([for -fno-PIE option],

libgcc/Makefile.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ override CFLAGS := $(filter-out -fprofile-generate -fprofile-use,$(CFLAGS))
298298
INTERNAL_CFLAGS = $(CFLAGS) $(LIBGCC2_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
299299
$(INCLUDES) @set_have_cc_tls@ @set_use_emutls@
300300

301+
NO_PIE_CFLAGS = @NO_PIE_CFLAGS@
302+
301303
# Options to use when compiling crtbegin/end.
302304
CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
303305
$(NO_PIE_CFLAGS) -finhibit-size-directive -fno-inline -fno-exceptions \

libgcc/configure

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ accel_dir_suffix
610610
use_tm_clone_registry
611611
force_explicit_eh_registry
612612
CET_FLAGS
613+
NO_PIE_CFLAGS
613614
fixed_point
614615
enable_decimal_float
615616
decimal_float
@@ -4836,6 +4837,40 @@ $as_echo "$libgcc_cv_fixed_point" >&6; }
48364837
fixed_point=$libgcc_cv_fixed_point
48374838
48384839
4840+
# Check whether the compiler defines __PIE__ by default, so -fno-PIE is needed.
4841+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler defines __PIE__" >&5
4842+
$as_echo_n "checking whether the compiler defines __PIE__... " >&6; }
4843+
if ${libgcc_cv_no_pie_cflags+:} false; then :
4844+
$as_echo_n "(cached) " >&6
4845+
else
4846+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
4847+
/* end confdefs.h. */
4848+
4849+
#ifdef __PIE__
4850+
#error __PIE__ defined
4851+
#endif
4852+
4853+
int
4854+
main ()
4855+
{
4856+
4857+
;
4858+
return 0;
4859+
}
4860+
_ACEOF
4861+
if ac_fn_c_try_compile "$LINENO"; then :
4862+
libgcc_cv_no_pie_cflags=''
4863+
else
4864+
libgcc_cv_no_pie_cflags='-fno-PIE'
4865+
fi
4866+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
4867+
fi
4868+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgcc_cv_no_pie_cflags" >&5
4869+
$as_echo "$libgcc_cv_no_pie_cflags" >&6; }
4870+
4871+
NO_PIE_CFLAGS=$libgcc_cv_no_pie_cflags
4872+
4873+
48394874
# For platforms with the unwind ABI which includes an unwind library,
48404875
# libunwind, we can choose to use the system libunwind.
48414876
# config.gcc also contains tests of with_system_libunwind.

libgcc/configure.ac

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,20 @@ AC_CACHE_CHECK([whether fixed-point is supported], [libgcc_cv_fixed_point],
258258
fixed_point=$libgcc_cv_fixed_point
259259
AC_SUBST(fixed_point)
260260

261+
# Check whether the compiler defines __PIE__ by default, so -fno-PIE is needed.
262+
AC_CACHE_CHECK([whether the compiler defines __PIE__], [libgcc_cv_no_pie_cflags],
263+
[AC_COMPILE_IFELSE(
264+
[AC_LANG_PROGRAM([[
265+
#ifdef __PIE__
266+
#error __PIE__ defined
267+
#endif
268+
]], [[]])],
269+
[libgcc_cv_no_pie_cflags=''],
270+
[libgcc_cv_no_pie_cflags='-fno-PIE'])])
271+
272+
NO_PIE_CFLAGS=$libgcc_cv_no_pie_cflags
273+
AC_SUBST([NO_PIE_CFLAGS])
274+
261275
# For platforms with the unwind ABI which includes an unwind library,
262276
# libunwind, we can choose to use the system libunwind.
263277
# config.gcc also contains tests of with_system_libunwind.

0 commit comments

Comments
 (0)