From patchwork Tue Nov 16 13:52:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 47766 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 481533857027 for ; Tue, 16 Nov 2021 14:03:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 481533857027 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637071413; bh=BVgj0o9CPzTwcsdm4XZ9KdHzeZfXXnZlW3qAtALq01g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=duSeXyNupcnlu7jjdwEsikIwsapvofJyhJnc14g8QCd370yuqvjzy524fKrPT/6kq ikoKfO16HiWiKwDqopZN+3WvRh3TKeGCz8QrkQfD5FCKz6RqYg24cfL+S/poAqv33S LYT8Vw1JDkMFN74j0VHWMOFOsIzdYrn0tsKtY9Xs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from brown.elm.relay.mailchannels.net (brown.elm.relay.mailchannels.net [23.83.212.23]) by sourceware.org (Postfix) with ESMTPS id 90B8B385AC1F for ; Tue, 16 Nov 2021 14:02:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 90B8B385AC1F X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id E9A519203E3; Tue, 16 Nov 2021 13:53:04 +0000 (UTC) Received: from pdx1-sub0-mail-a306.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 8698892184D; Tue, 16 Nov 2021 13:53:03 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a306.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.250.31 (trex/6.4.3); Tue, 16 Nov 2021 13:53:04 +0000 X-MC-Relay: Junk X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Continue-Hysterical: 2fdd82453fbf832b_1637070784789_1008249278 X-MC-Loop-Signature: 1637070784789:66609827 X-MC-Ingress-Time: 1637070784789 Received: from rhbox.redhat.com (unknown [1.186.223.33]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a306.dreamhost.com (Postfix) with ESMTPSA id 4HtnZN08WGz1Wg; Tue, 16 Nov 2021 05:52:59 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH] New option --enable-pie-programs Date: Tue, 16 Nov 2021 19:22:40 +0530 Message-Id: <20211116135240.3092651-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3495.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: fweimer@redhat.com Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Add a new option --enable-pie-programs to build tests and binaries as PIE. This allows building all dynamic programs in glibc (e.g. iconvconfig, getconf, etc.) as PIE on architectures that do not have -static-pie. Signed-off-by: Siddhesh Poyarekar --- INSTALL | 10 +++++++--- Makeconfig | 7 +++++++ configure | 17 +++++++++++++++++ configure.ac | 11 +++++++++++ manual/install.texi | 9 +++++++-- 5 files changed, 49 insertions(+), 5 deletions(-) diff --git a/INSTALL b/INSTALL index 02dcf6b1ca..30a071a702 100644 --- a/INSTALL +++ b/INSTALL @@ -111,6 +111,10 @@ if 'CFLAGS' is specified it must enable optimization. For example: systems support shared libraries; you need ELF support and (currently) the GNU linker. +'--enable-pie-programs' + Build glibc programs and tests in the testsuite as position + independent executables (PIE). + '--enable-static-pie' Enable static position independent executable (static PIE) support. Static PIE is similar to static executable, but can be loaded at @@ -118,9 +122,9 @@ if 'CFLAGS' is specified it must enable optimization. For example: programs as well as static tests are built as static PIE, except for those marked with no-pie. The resulting glibc can be used with the GCC option, -static-pie, which is available with GCC 8 or - above, to create static PIE. This option also implies that glibc - programs and tests are created as dynamic position independent - executables (PIE) by default. + above, to create static PIE. This option also implies + '--enable-pie-programs', where glibc programs and tests are created + as dynamic position independent executables (PIE) by default. '--enable-cet' '--enable-cet=permissive' diff --git a/Makeconfig b/Makeconfig index 3fa2f13003..1695e48ead 100644 --- a/Makeconfig +++ b/Makeconfig @@ -1,4 +1,5 @@ # Copyright (C) 1991-2021 Free Software Foundation, Inc. +# Copyright (C) The GNU Toolchain Authors. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -390,6 +391,12 @@ default-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text endif endif +# Build glibc programs with PIE. +ifeq (yes,$(pie-programs)) +pic-default = -DPIC +pie-default = $(pie-ccflag) +endif + # If lazy relocations are disabled, add the -z now flag. Use # LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to # test modules. diff --git a/configure b/configure index 2f9adca064..47f5536745 100755 --- a/configure +++ b/configure @@ -767,6 +767,7 @@ with_nonshared_cflags enable_sanity_checks enable_shared enable_profile +enable_pie_programs enable_static_pie enable_timezone_tools enable_hardcoded_path_in_tests @@ -1423,6 +1424,8 @@ Optional Features: in special situations) [default=yes] --enable-shared build shared library [default=yes if GNU ld] --enable-profile build profiled library [default=no] + --enable-pie-programs Build glibc programs and tests in the testsuite as + PIE [default=no] --enable-static-pie enable static PIE support and use it in the testsuite [default=no] --disable-timezone-tools @@ -3408,6 +3411,13 @@ else profile=no fi +# Check whether --enable-pie-programs was given. +if test "${enable_pie_programs+set}" = set; then : + enableval=$enable_pie_programs; pie_programs=$enableval +else + pie_programs=no +fi + # Check whether --enable-static-pie was given. if test "${enable_static_pie+set}" = set; then : enableval=$enable_static_pie; static_pie=$enableval @@ -7014,6 +7024,13 @@ fi config_vars="$config_vars enable-static-pie = $static_pie" +if test "$pie_programs" = yes; then + libc_cv_pie_default=yes +fi +config_vars="$config_vars +pie-programs = $pie_programs" + + diff --git a/configure.ac b/configure.ac index 7eb4239359..7cfbf3f825 100644 --- a/configure.ac +++ b/configure.ac @@ -179,6 +179,11 @@ AC_ARG_ENABLE([profile], [build profiled library @<:@default=no@:>@]), [profile=$enableval], [profile=no]) +AC_ARG_ENABLE([pie-programs], + AS_HELP_STRING([--enable-pie-programs], + [Build glibc programs and tests in the testsuite as PIE @<:@default=no@:>@]), + [pie_programs=$enableval], + [pie_programs=no]) AC_ARG_ENABLE([static-pie], AS_HELP_STRING([--enable-static-pie], [enable static PIE support and use it in the testsuite @<:@default=no@:>@]), @@ -1876,6 +1881,12 @@ if test "$static_pie" = yes; then fi LIBC_CONFIG_VAR([enable-static-pie], [$static_pie]) +if test "$pie_programs" = yes; then + libc_cv_pie_default=yes +fi +LIBC_CONFIG_VAR([pie-programs], [$pie_programs]) + + AC_SUBST(profile) AC_SUBST(static_nss) diff --git a/manual/install.texi b/manual/install.texi index 46f73b538d..9f7acfe9cd 100644 --- a/manual/install.texi +++ b/manual/install.texi @@ -141,6 +141,10 @@ Don't build shared libraries even if it is possible. Not all systems support shared libraries; you need ELF support and (currently) the GNU linker. +@item --enable-pie-programs +Build glibc programs and tests in the testsuite as position independent +executables (PIE). + @item --enable-static-pie Enable static position independent executable (static PIE) support. Static PIE is similar to static executable, but can be loaded at any @@ -148,8 +152,9 @@ address without help from a dynamic linker. All static programs as well as static tests are built as static PIE, except for those marked with no-pie. The resulting glibc can be used with the GCC option, -static-pie, which is available with GCC 8 or above, to create static -PIE. This option also implies that glibc programs and tests are created -as dynamic position independent executables (PIE) by default. +PIE. This option also implies @option{--enable-pie-programs}, where glibc +programs and tests are created as dynamic position independent executables +(PIE) by default. @item --enable-cet @itemx --enable-cet=permissive