From patchwork Thu Jun 24 13:49:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 43999 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 9E4783888C78 for ; Thu, 24 Jun 2021 13:54:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E4783888C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624542881; bh=mipaf1W5Jt/uuKOr2T+4wihl2swjwa96Jxu97vvaHw8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=QAOtLUUKIfZOhGlbaq2JVYPyA7SopzcITTRJXzlIT8nMS/OHy2yOtVdC+EW4Bv2EV +Ad/oTCoB8kmtxDHvXHy2EZZtFye53iRvFjZ/k/WdESG0uFt0PW3fUYm/TPHwgs+Na TpY0CLLNP8ooRp9OFIyDX61vc6rUcHWBsHXdD4LA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 72E343888C58 for ; Thu, 24 Jun 2021 13:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72E343888C58 Received: by mail-pf1-x42f.google.com with SMTP id t32so5231969pfg.2 for ; Thu, 24 Jun 2021 06:49:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mipaf1W5Jt/uuKOr2T+4wihl2swjwa96Jxu97vvaHw8=; b=CJgDdj5wwnZBcG52aWXejG7jGqPEWeydkjFttyyFT/O7czaC+ltlv0y8nvFqWgUgzL OTyJCpTcJSrns1xVeD5kkH8sXOvhic5JzHttSj5iOhfRHLv9yavJ3nDugQXuCV9oey4T 3ZtvgeojcVD9y91gBzy4MkESJ906poY01Xwg9pXRRxzF37Ztor6XoMQnP2582vC9BIQf dfE1MxMSFy2fmgChcUDn6r76sgqhxORenqf8UzU3zipSzam0TEdxUSfJHDpaE0qiLXpj dUCQnTMMfL8awOSWdOqKfWNH8P8/3T43ZkZ5skMlYC3dOsamTBz2UdyMOY1DqWb5bATT IcBA== X-Gm-Message-State: AOAM531dqUWcxgjGLz8YreunS8Qcs5JjOmSSvc857ylrXhsG7RYoTZhh g9lZL/DPEIEhyqdWGJ6MY7QWrq9Jf7E= X-Google-Smtp-Source: ABdhPJyvFjN1G7ohFeom7Jww0LqWiUkwa+ouRHGyzvjkHMG2Mj25d/T32NX3lAE9fRodFDiRR9PpuA== X-Received: by 2002:a65:5189:: with SMTP id h9mr4764335pgq.353.1624542580575; Thu, 24 Jun 2021 06:49:40 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.115]) by smtp.gmail.com with ESMTPSA id v21sm3193501pfu.77.2021.06.24.06.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 06:49:40 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id DDE84C035E; Thu, 24 Jun 2021 06:49:38 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 2/4] Check -z indirect-extern-access and -fno-direct-extern-access Date: Thu, 24 Jun 2021 06:49:36 -0700 Message-Id: <20210624134938.2025098-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624134938.2025098-1-hjl.tools@gmail.com> References: <20210624134938.2025098-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3031.8 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, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 1. Check linker support for -z indirect-extern-access. If GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS is set on any input relocatable files: a. Don't generate copy relocations. b. Turn off extern_protected_data since it implies GNU_PROPERTY_NO_COPY_ON_PROTECTED. c. Treate reference to protected symbols with indirect external access as local. d. Set GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS on output. e. When generating executable, clear this bit when there are non-GOT or non-PLT relocations in input relocatable files without the bit set. f. Add -z [no]indirect-extern-access to control indirect external access. 2. Check compiler support for -fno-direct-extern-access: a. Generate an indirect external access marker in relocatable objects. i. Always use GOT to access undefined data and function symbols, including in PIE and non-PIE. These will avoid copy relocations in executables. ii. This is compatible with existing executables and shared libraries. b. In executable and shared library, bind symbols with the STV_PROTECTED visibility locally: i. The address of data symbol is the address of data body. ii. For systems without function descriptor, the function pointer is the address of function body. iii. The resulting shared libraries may not be incompatible with executables which have copy relocations on protected symbols. Size comparison of non-PIE builds with GCC 12 -O2: 1. On x86-64: text data bss dec hex filename 189958 9304 416 199678 30bfe ld.so (original) 189974 9304 416 199694 30c0e ld.so (-fno-direct-extern-access) 1922458 20240 52432 1995130 1e717a libc.so (original) 1922474 20240 52432 1995146 1e718a libc.so (-fno-direct-extern-access) 49321 1363 192 50876 c6bc iconv_prog (original) 47053 3638 120 50811 c67b iconv_prog (-fno-direct-extern-access) 261978 10339 744 273061 42aa5 localedef (original) 233344 41734 648 275726 4350e localedef (-fno-direct-extern-access) The size difference in localedef mainly comes from .data.rel.ro .data.rel.ro 0x000005 (original) .data.rel.ro 0x007a88 (-fno-direct-extern-access) For example, with -fno-direct-extern-access, localedef.o has 172 relocation entries against section '.rela.data.rel.ro.local' vs none without -fno-direct-extern-access. --- configure | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/configure b/configure index 9619c10991..093c59e25e 100755 --- a/configure +++ b/configure @@ -5746,6 +5746,65 @@ fi $as_echo "$libc_cv_insert" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking -z indirect-extern-access" >&5 +$as_echo_n "checking -z indirect-extern-access... " >&6; } +if ${libc_cv_z_indirect_extern_access+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat > conftest.c <&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + libc_cv_z_indirect_extern_access=yes + else + libc_cv_z_indirect_extern_access=no + fi + rm -f conftest.* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_z_indirect_extern_access" >&5 +$as_echo "$libc_cv_z_indirect_extern_access" >&6; } +config_vars="$config_vars +have-z-indirect-extern-access = $libc_cv_z_indirect_extern_access" + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-direct-extern-access" >&5 +$as_echo_n "checking for -fno-direct-extern-access... " >&6; } +if ${libc_cv_fno_direct_extern_access+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat > conftest.c <&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + libc_cv_fno_direct_extern_access=yes + else + libc_cv_fno_direct_extern_access=no + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_fno_direct_extern_access" >&5 +$as_echo "$libc_cv_fno_direct_extern_access" >&6; } +config_vars="$config_vars +have-fno-direct-extern-access = $libc_cv_fno_direct_extern_access" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for broken __attribute__((alias()))" >&5 $as_echo_n "checking for broken __attribute__((alias()))... " >&6; } if ${libc_cv_broken_alias_attribute+:} false; then : diff --git a/configure.ac b/configure.ac index 34ecbba540..195abe0827 100644 --- a/configure.ac +++ b/configure.ac @@ -1222,6 +1222,43 @@ EOF ]) AC_SUBST(libc_cv_insert) +AC_CACHE_CHECK(-z indirect-extern-access, + libc_cv_z_indirect_extern_access, + [cat > conftest.c <&AS_MESSAGE_LOG_FD]); then + libc_cv_z_indirect_extern_access=yes + else + libc_cv_z_indirect_extern_access=no + fi + rm -f conftest.* + ]) +LIBC_CONFIG_VAR([have-z-indirect-extern-access], + [$libc_cv_z_indirect_extern_access]) + +AC_CACHE_CHECK(for -fno-direct-extern-access, + libc_cv_fno_direct_extern_access, + [cat > conftest.c <&AS_MESSAGE_LOG_FD]); then + libc_cv_fno_direct_extern_access=yes + else + libc_cv_fno_direct_extern_access=no + fi + rm -f conftest*]) +LIBC_CONFIG_VAR([have-fno-direct-extern-access], + [$libc_cv_fno_direct_extern_access]) + AC_CACHE_CHECK(for broken __attribute__((alias())), libc_cv_broken_alias_attribute, [cat > conftest.c <