public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@sourceware.org>
To: libc-alpha@sourceware.org
Cc: fweimer@redhat.com, carlos@redhat.com
Subject: [PATCH] New option --enable-pie-programs
Date: Tue, 16 Nov 2021 19:22:40 +0530	[thread overview]
Message-ID: <20211116135240.3092651-1-siddhesh@sourceware.org> (raw)

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 <siddhesh@sourceware.org>
---
 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
-- 
2.31.1


             reply	other threads:[~2021-11-16 14:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16 13:52 Siddhesh Poyarekar [this message]
2021-11-16 13:58 ` Florian Weimer
2021-11-16 15:17   ` Siddhesh Poyarekar
2021-11-17  8:39     ` Florian Weimer
2021-11-17  8:50       ` Siddhesh Poyarekar
2021-11-17  9:10         ` Florian Weimer
2021-11-17 10:04           ` Siddhesh Poyarekar
2021-11-18  9:24             ` Siddhesh Poyarekar
2021-11-18 12:42               ` H.J. Lu
2021-11-18 12:49                 ` Adhemerval Zanella
2021-11-18 13:26                   ` Siddhesh Poyarekar
2021-11-18 13:41                     ` H.J. Lu
2021-11-18 16:36                       ` Siddhesh Poyarekar
2021-11-18 16:44                         ` H.J. Lu
2021-11-18 16:49                           ` Siddhesh Poyarekar
2021-11-18 16:56                             ` H.J. Lu
2021-11-18 17:54                               ` Siddhesh Poyarekar
2021-11-18 17:58                                 ` H.J. Lu
2021-11-18 18:09                                   ` Siddhesh Poyarekar
2021-11-18 18:18                                     ` H.J. Lu
2021-11-22 23:40                                       ` Fangrui Song
2021-11-24  1:04                                         ` Fāng-ruì Sòng
2021-11-24  1:27                                           ` Siddhesh Poyarekar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211116135240.3092651-1-siddhesh@sourceware.org \
    --to=siddhesh@sourceware.org \
    --cc=carlos@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).