From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id 0383E385803A; Mon, 17 Jan 2022 15:21:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0383E385803A Received: by mail-pj1-x1035.google.com with SMTP id hv15so20765319pjb.5; Mon, 17 Jan 2022 07:21:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EwKXdzj2NHrPAX0AcGHh4oD6uQWyKYNrtk4BSaztgBs=; b=UvI3NQreVYr7bXyPJHgRsHN2WGZr0qNeD5U+duSbzninXCfsdZWV7Jiaw9Y2PBmldY X8cjkK0ky+do7Hv4mF3ZJWScbRheh5O5lWVlj1eKC31zSV1RxkEZmLU2m5EhUFk0J/UC fJFDSJoxKoy6GwPBtLQ4BNla640HgVeHbyIxE+zIrUdycZVNitqdER7WiaL43lXsis+F HB9HBOzUnTXm5GtLUqSbXZ551Zmll5n7towYGMGd3jOdeh8VMqijCTlXb9D1Q/zCxA8R weI0ULE4uJeINHWMHi2L3QrI6T95g5gLPHcGekl4ZiCU5S0Ic59F+iWmjx60zeOUxDU2 aeRg== X-Gm-Message-State: AOAM530tSJkPZQkTlT2LHUiEmuxt08iE3ZiN0b3EiQtpnreErv6NmtK0 lP8lJKAWZ3/qpz+lFOyp17oXAFwyM/sHuSYKFj1vA+UC X-Google-Smtp-Source: ABdhPJz0MRbUSV6SR37NWGgIC0wSsHgpBRVOjoIDR1GgsjB5PtRN12vE1GJhXROJe3pJlOHNvWJTDOK9pI2gxzkRZBA= X-Received: by 2002:a17:902:e544:b0:14a:555c:add3 with SMTP id n4-20020a170902e54400b0014a555cadd3mr22434606plf.102.1642432890829; Mon, 17 Jan 2022 07:21:30 -0800 (PST) MIME-Version: 1.0 References: <20220115222916.2148942-1-hjl.tools@gmail.com> <2a9cc337-a3ca-bfbd-9e84-e5233aa3b56a@sourceware.org> In-Reply-To: <2a9cc337-a3ca-bfbd-9e84-e5233aa3b56a@sourceware.org> From: "H.J. Lu" Date: Mon, 17 Jan 2022 07:20:54 -0800 Message-ID: Subject: Re: [PATCH] Properly handle --disable-default-pie [BZ #28780] To: Siddhesh Poyarekar Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3027.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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-List-Received-Date: Mon, 17 Jan 2022 15:21:33 -0000 On Mon, Jan 17, 2022 at 6:35 AM Siddhesh Poyarekar wrote: > > OK review time since we're now on the same page as to what's going on. > Mostly minor nits below. > > On 16/01/2022 03:59, H.J. Lu via Libc-alpha wrote: > > 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. > > Please update the commit message to reflect the latest status on the > bug, i.e. it's static pie that doesn't honour default-pie, not all PIE. Fixed. > > > > 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 > > Single '=' here? Fixed. > > + 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. > I just sent out the v2 patch. -- H.J.