From patchwork Sat Jan 15 22:29:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 50074 X-Patchwork-Delegate: siddhesh@gotplt.org 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 B6B783858D3C for ; Sat, 15 Jan 2022 22:29:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6B783858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642285789; bh=4vUCTIr9eQhGVm/zDxdY34xze2hVz5+4MSUYv/yza+E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=EaAjByGpHUsZXYh9AAXTUJktPGCcOdfdsezYuNj8Cg+MKJY8VJ5V1AY52z/o9tlTW hOpgJevLAtyQJkTBIkDawWv4LW3575NTBAD4MoG++VK2gmJnPiMF02wDMhUT2dYLgj Mq0r4YtvQYtbIN8oP/QgbCSGTam8pb0920kadHKE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id E1D8B3886C79; Sat, 15 Jan 2022 22:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1D8B3886C79 Received: by mail-ot1-x330.google.com with SMTP id i5-20020a05683033e500b0057a369ac614so14724328otu.10; Sat, 15 Jan 2022 14:29:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4vUCTIr9eQhGVm/zDxdY34xze2hVz5+4MSUYv/yza+E=; b=tFLHzlrdtmAljpQVGtf+LkmInwKAhmbJUlT8pyXvPJhgmeMmfYc00vl5TaFClgCiHZ erkuL9qdC/agCcfYwbAclndsgFP9HF4fWJ+hChUmPlCYUYx5m/FS19Ci4n+OlE86CwGp xO/VbBfFWVlvGuw8uvm/BTj0LSKpiljeDciTBf9XdprUxR1wcDpbENC+OdaUYaPHSnit nXC647uJyayYpSHgl/HMKiEBHMUKgJQT35PRJIgIkWc4LRM7kvbOl4MlFTn4G0OKbNn0 aL3s7XUFhKtL4j0ECGOh+nMssTah/eVb4oOTytNd1rc2aPS7IpFfPTBxqHXNqJXpbmhq VKRA== X-Gm-Message-State: AOAM532ZoNduDwiuhpIc1aOn+ygvak3wRV3nK5C/UchzNAj0pvkwOOH+ ARGnGGBMLvqJ0q3z225sxI2kTUStMTg= X-Google-Smtp-Source: ABdhPJzO3LAye2QGwApHENTfA2nGn6J3MxfYNipY7bof1faTe9U2Gf68Tjr85ctfdR01paovS5jphA== X-Received: by 2002:a9d:3e9:: with SMTP id f96mr11492242otf.245.1642285761095; Sat, 15 Jan 2022 14:29:21 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id b4sm2122236oop.35.2022.01.15.14.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jan 2022 14:29:20 -0800 (PST) Received: from gnu-tgl-2.localdomain (gnu-tgl-2 [192.168.1.42]) by gnu-tgl-3.localdomain (Postfix) with ESMTPS id A32D7C03AA; Sat, 15 Jan 2022 14:29:17 -0800 (PST) Received: from gnu-tgl-2.. (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id 5EAF630032F; Sat, 15 Jan 2022 14:29:16 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH] Properly handle --disable-default-pie [BZ #28780] Date: Sat, 15 Jan 2022 14:29:16 -0800 Message-Id: <20220115222916.2148942-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3028.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Siddhesh Poyarekar Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" When --disable-default-pie is used, glibc programs and the testsuite should be built as position dependent executables (non-PIE), regardless if the build compiler supports PIE or static PIE. When --disable-default-pie is used, don't build PIE nor static PIE. by default. This fixes BZ #28780. --- configure | 47 +++++++++++++++++++++++++++++------------------ configure.ac | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 32 deletions(-) diff --git a/configure b/configure index 6a7e5c6164..a12f66fa58 100755 --- a/configure +++ b/configure @@ -7035,32 +7035,35 @@ cc-pie-default = $libc_cv_cc_pie_default" { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build programs as PIE" >&5 $as_echo_n "checking if we can build programs as PIE... " >&6; } -if test "x$default_pie" != xno; then - # Disable build-pie-default if target does not support it. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext +cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef PIE_UNSUPPORTED # error PIE is not supported #endif _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - libc_cv_pie_default=yes + libc_cv_pie_supported=yes else - libc_cv_pie_default=no + libc_cv_pie_supported=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_supported" >&5 +$as_echo "$libc_cv_pie_supported" >&6; } +# Disable build-pie-default if target does not support it or glibc is +# configured with --disable-default-pie. +if test "x$default_pie" = xno; then + build_pie_default=no +else + build_pie_default=$libc_cv_pie_supported fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_default" >&5 -$as_echo "$libc_cv_pie_default" >&6; } config_vars="$config_vars -build-pie-default = $libc_cv_pie_default" +build-pie-default = $build_pie_default" { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build static PIE programs" >&5 $as_echo_n "checking if we can build static PIE programs... " >&6; } -libc_cv_static_pie=$libc_cv_pie_default -if test "x$libc_cv_pie_default" != xno \ +libc_cv_static_pie_supported=$libc_cv_pie_supported +if test "x$libc_cv_pie_supported" != xno \ -a "$libc_cv_no_dynamic_linker" = yes; then - # Enable static-pie if available cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifndef SUPPORT_STATIC_PIE @@ -7068,18 +7071,26 @@ if test "x$libc_cv_pie_default" != xno \ #endif _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - libc_cv_static_pie=yes + libc_cv_static_pie_supported=yes else - libc_cv_static_pie=no + libc_cv_static_pie_supported=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - if test "$libc_cv_static_pie" = "yes"; then - $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie_supported" >&5 +$as_echo "$libc_cv_static_pie_supported" >&6; } + +# Enable static-pie only if it is available and glibc isn't configured +# with --disable-default-pie. +if test "x$default_pie" == xno; then + libc_cv_static_pie=no +else + libc_cv_static_pie=$libc_cv_static_pie_supported +fi +if test "$libc_cv_static_pie" = "yes"; then + $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h - fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie" >&5 -$as_echo "$libc_cv_static_pie" >&6; } config_vars="$config_vars enable-static-pie = $libc_cv_static_pie" diff --git a/configure.ac b/configure.ac index 40f2de1661..cacf00140d 100644 --- a/configure.ac +++ b/configure.ac @@ -1868,28 +1868,40 @@ rm -f conftest.*]) LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default]) AC_MSG_CHECKING(if we can build programs as PIE) -if test "x$default_pie" != xno; then - # Disable build-pie-default if target does not support it. - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED +AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED # error PIE is not supported -#endif]])], [libc_cv_pie_default=yes], [libc_cv_pie_default=no]) +#endif]])], [libc_cv_pie_supported=yes], [libc_cv_pie_supported=no]) +AC_MSG_RESULT($libc_cv_pie_supported) +# Disable build-pie-default if target does not support it or glibc is +# configured with --disable-default-pie. +if test "x$default_pie" = xno; then + build_pie_default=no +else + build_pie_default=$libc_cv_pie_supported fi -AC_MSG_RESULT($libc_cv_pie_default) -LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default]) +LIBC_CONFIG_VAR([build-pie-default], [$build_pie_default]) AC_MSG_CHECKING(if we can build static PIE programs) -libc_cv_static_pie=$libc_cv_pie_default -if test "x$libc_cv_pie_default" != xno \ +libc_cv_static_pie_supported=$libc_cv_pie_supported +if test "x$libc_cv_pie_supported" != xno \ -a "$libc_cv_no_dynamic_linker" = yes; then - # Enable static-pie if available AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE # error static PIE is not supported -#endif]])], [libc_cv_static_pie=yes], [libc_cv_static_pie=no]) - if test "$libc_cv_static_pie" = "yes"; then - AC_DEFINE(ENABLE_STATIC_PIE) - fi +#endif]])], [libc_cv_static_pie_supported=yes], + [libc_cv_static_pie_supported=no]) +fi +AC_MSG_RESULT($libc_cv_static_pie_supported) + +# Enable static-pie only if it is available and glibc isn't configured +# with --disable-default-pie. +if test "x$default_pie" == xno; then + libc_cv_static_pie=no +else + libc_cv_static_pie=$libc_cv_static_pie_supported +fi +if test "$libc_cv_static_pie" = "yes"; then + AC_DEFINE(ENABLE_STATIC_PIE) fi -AC_MSG_RESULT($libc_cv_static_pie) LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie]) # Set the `multidir' variable by grabbing the variable from the compiler.