From patchwork Thu May 28 13:05:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 6952 Received: (qmail 125557 invoked by alias); 28 May 2015 13:05:38 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 122970 invoked by uid 89); 28 May 2015 13:05:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.2 required=5.0 tests=AWL, BAYES_99, BAYES_999, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-pd0-f182.google.com X-Received: by 10.66.141.231 with SMTP id rr7mr5436149pab.86.1432818325629; Thu, 28 May 2015 06:05:25 -0700 (PDT) Date: Thu, 28 May 2015 06:05:23 -0700 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] [BZ #17841]: Build failure if compiler defaults to PIE Message-ID: <20150528130523.GA16533@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) 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. OK for master? H.J. --- [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. --- Makeconfig | 6 ++++++ config.make.in | 1 + configure | 21 +++++++++++++++++++++ configure.ac | 13 +++++++++++++ elf/Makefile | 1 + 5 files changed, 42 insertions(+) diff --git a/Makeconfig b/Makeconfig index d32a0fd..831604a 100644 --- a/Makeconfig +++ b/Makeconfig @@ -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/config.make.in b/config.make.in index 5a18dae..a9f5696 100644 --- a/config.make.in +++ b/config.make.in @@ -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@ diff --git a/configure b/configure index 1e4138b..45cc7cb 100755 --- 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 <&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; } + + diff --git a/configure.ac b/configure.ac index ff66b87..7e9383a 100644 --- a/configure.ac +++ b/configure.ac @@ -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 <&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) diff --git a/elf/Makefile b/elf/Makefile index dedf3c7..d4421e9 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -150,6 +150,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)