]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Support compilers defaulting to PIE
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 25 Jun 2015 09:37:04 +0000 (02:37 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 25 Jun 2015 09:49:53 +0000 (02:49 -0700)
To support building glibc with GCC 6 configured with --enable-default-pie,
which generates PIE by default, we need to build programs as PIE.  But
elf/tst-dlopen-aout must not be built as PIE since it tests dlopen on
ET_EXEC file and PIE is ET_DYN.

[BZ #17841]
* Makeconfig (no-pie-ldflag): New.
(+link): Set to $(+link-pie) if default to PIE.
(+link-tests): Set to $(+link-pie-tests) if default to PIE.
* config.make.in (build-pie-default): New.
* configure.ac (libc_cv_pie_default): New.  Set to yes if -fPIE
is default.  AC_SUBST.
* configure: Regenerated.
* elf/Makefile (LDFLAGS-tst-dlopen-aout): New.

ChangeLog
Makeconfig
NEWS
config.make.in
configure
configure.ac
elf/Makefile

index f9cf634a44f1fdbaab345bd39b1905d4527d9515..7fe8b821960dc39668002e869c23c1e1a02315f0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2015-06-25  H.J. Lu  <hongjiu.lu@intel.com>
+
+       [BZ #17841]
+       * Makeconfig (no-pie-ldflag): New.
+       (+link): Set to $(+link-pie) if default to PIE.
+       (+link-tests): Set to $(+link-pie-tests) if default to PIE.
+       * config.make.in (build-pie-default): New.
+       * configure.ac (libc_cv_pie_default): New.  Set to yes if -fPIE
+       is default.  AC_SUBST.
+       * configure: Regenerated.
+       * elf/Makefile (LDFLAGS-tst-dlopen-aout): New.
+
 2015-06-24  Roland McGrath  <roland@hack.frob.com>
 
        * nptl/descr.h (struct pthread): Change type of field setxid_futex
index 0f4b5497c1bdc823cece944c01d6d5f3bb399d41..7b46323bd288cbde4092d76720584869cb20bd39 100644 (file)
@@ -442,6 +442,11 @@ endif
 # Commands for linking programs with the C library.
 ifndef +link
 ifeq (yes,$(build-shared))
+ifeq (yes,$(build-pie-default))
+no-pie-ldflag = -no-pie
++link = $(+link-pie)
++link-tests = $(+link-pie-tests)
+else
 +link-before-libc = $(CC) -nostdlib -nostartfiles -o $@ \
              $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
              $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
@@ -462,6 +467,7 @@ $(+link-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
                     $(+link-after-libc)
 $(call after-link,$@)
 endef
+endif
 else
 +link = $(+link-static)
 +link-tests = $(+link-static-tests)
diff --git a/NEWS b/NEWS
index 727e21f770448c8bdd5c231a8e4da495f81f97dc..58f85e79bb804d353c298a6446027fa93ad4514a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,17 +14,17 @@ Version 2.22
   16526, 16538, 16560, 16704, 16783, 16850, 17053, 17090, 17195, 17269,
   17293, 17322, 17403, 17523, 17542, 17569, 17581, 17588, 17596, 17620,
   17621, 17628, 17631, 17692, 17711, 17715, 17776, 17779, 17792, 17836,
-  17912, 17916, 17930, 17932, 17944, 17949, 17964, 17965, 17967, 17969,
-  17977, 17978, 17987, 17991, 17996, 17998, 17999, 18007, 18019, 18020,
-  18029, 18030, 18032, 18034, 18036, 18038, 18039, 18042, 18043, 18046,
-  18047, 18049, 18068, 18080, 18093, 18100, 18104, 18110, 18111, 18116,
-  18125, 18128, 18138, 18185, 18196, 18197, 18206, 18210, 18211, 18217,
-  18219, 18220, 18221, 18234, 18244, 18245, 18247, 18287, 18319, 18324,
-  18333, 18346, 18371, 18397, 18409, 18410, 18412, 18418, 18422, 18434,
-  18444, 18468, 18469, 18470, 18479, 18483, 18495, 18496, 18497, 18498,
-  18507, 18512, 18513, 18519, 18520, 18522, 18527, 18528, 18529, 18530,
-  18532, 18533, 18534, 18536, 18539, 18540, 18542, 18544, 18545, 18546,
-  18547, 18553, 18558, 18569, 18583, 18585, 18586, 18593, 18594.
+  17841, 17912, 17916, 17930, 17932, 17944, 17949, 17964, 17965, 17967,
+  17969, 17977, 17978, 17987, 17991, 17996, 17998, 17999, 18007, 18019,
+  18020, 18029, 18030, 18032, 18034, 18036, 18038, 18039, 18042, 18043,
+  18046, 18047, 18049, 18068, 18080, 18093, 18100, 18104, 18110, 18111,
+  18116, 18125, 18128, 18138, 18185, 18196, 18197, 18206, 18210, 18211,
+  18217, 18219, 18220, 18221, 18234, 18244, 18245, 18247, 18287, 18319,
+  18324, 18333, 18346, 18371, 18397, 18409, 18410, 18412, 18418, 18422,
+  18434, 18444, 18468, 18469, 18470, 18479, 18483, 18495, 18496, 18497,
+  18498, 18507, 18512, 18513, 18519, 18520, 18522, 18527, 18528, 18529,
+  18530, 18532, 18533, 18534, 18536, 18539, 18540, 18542, 18544, 18545,
+  18546, 18547, 18553, 18558, 18569, 18583, 18585, 18586, 18593, 18594.
 
 * Cache information can be queried via sysconf() function on s390 e.g. with
   _SC_LEVEL1_ICACHE_SIZE as argument.
index 5a18daed24c41e2b53123c52d14386655ef8a295..a9f5696077a6e64fba116c0e83a85e2afab41c5d 100644 (file)
@@ -82,6 +82,7 @@ nss-crypt = @libc_cv_nss_crypt@
 # Configuration options.
 build-shared = @shared@
 build-pic-default= @libc_cv_pic_default@
+build-pie-default= @libc_cv_pie_default@
 build-profile = @profile@
 build-static-nss = @static_nss@
 add-ons = @add_ons@
index 1e4138b524ed3f2098de1a2cb805e65ccba61d43..45cc7cba2bff3d6ab9ac9b05d492fae1b23e56ae 100755 (executable)
--- a/configure
+++ b/configure
@@ -596,6 +596,7 @@ mach_interface_list
 DEFINES
 static_nss
 profile
+libc_cv_pie_default
 libc_cv_pic_default
 shared
 static
@@ -7317,6 +7318,26 @@ fi
 $as_echo "$libc_cv_pic_default" >&6; }
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fPIE is default" >&5
+$as_echo_n "checking whether -fPIE is default... " >&6; }
+if ${libc_cv_pie_default+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  libc_cv_pie_default=yes
+cat > conftest.c <<EOF
+#if defined __PIE__ || defined __pie__ || defined PIE || defined pie
+# error PIE is default.
+#endif
+EOF
+if eval "${CC-cc} -S conftest.c 2>&5 1>&5"; then
+  libc_cv_pie_default=no
+fi
+rm -f conftest.*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_default" >&5
+$as_echo "$libc_cv_pie_default" >&6; }
+
+
 
 
 
index ff66b875e3b43d2c1a39413c60ff0bcf9de6c693..7e9383a7f0b036ff7f558b1d436906245aa1941d 100644 (file)
@@ -2075,6 +2075,19 @@ fi
 rm -f conftest.*])
 AC_SUBST(libc_cv_pic_default)
 
+AC_CACHE_CHECK([whether -fPIE is default], libc_cv_pie_default,
+[libc_cv_pie_default=yes
+cat > conftest.c <<EOF
+#if defined __PIE__ || defined __pie__ || defined PIE || defined pie
+# error PIE is default.
+#endif
+EOF
+if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
+  libc_cv_pie_default=no
+fi
+rm -f conftest.*])
+AC_SUBST(libc_cv_pie_default)
+
 AC_SUBST(profile)
 AC_SUBST(static_nss)
 
index 4ea3ccf4410483cafa4b50e40ca537310ee4d0df..f21276c0064bb2bf6b2cdc6ef4c73d64e65e1851 100644 (file)
@@ -151,6 +151,7 @@ tests += loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
 #       reldep9
 ifeq ($(build-hardcoded-path-in-tests),yes)
 tests += tst-dlopen-aout
+LDFLAGS-tst-dlopen-aout = $(no-pie-ldflag)
 endif
 test-srcs = tst-pathopt
 selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)