From patchwork Sun Jun 20 23:36:18 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: 43926 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 D2C063851C00 for ; Sun, 20 Jun 2021 23:39:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2C063851C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624232384; bh=e6MNRySEAZ/zsgsbLOo0t4QpmaIVfNX9VyOT1+uMDNo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=o+/WLmvVJ2eMQc02UqVKiSxfWY2k3bKNeyR+ZSUYvaE1WCiZphHdMvDI/BzoBoxef PW2/3W40/ttB7sncokLwxY49dtQOkYQezNiqA918jiHDjK0+pLhjucLB5RmSsIwTf5 MHNg0rt5okFX85kNMkFRvUckaV07g5FSXqVvylWw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id F0D4F385502A for ; Sun, 20 Jun 2021 23:36:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F0D4F385502A Received: by mail-pf1-x432.google.com with SMTP id x16so12229831pfa.13 for ; Sun, 20 Jun 2021 16:36:23 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e6MNRySEAZ/zsgsbLOo0t4QpmaIVfNX9VyOT1+uMDNo=; b=ce3cJK7OnbkZURVu8K70sCbIXyUaYniGgjT04iLTyzzldFNrHmXlpFW7ULIS0bS4Wq +1lTHaAHyoirM7QcMlVIg66eJofV6mm/PbtKkTSq+PpKq73bL7MkB6l2FFRC3T1fwl8g UkvuBxjL3c9SAYb5xbaNh2URWR9HbVkQTPNZG/8XRDfj12aNL9xFDkawaMDMJwwn4sP2 /1m2MzuBPbDuxFkGXzXUjgB8QMlvX2HXzUw5WhVfxUDvr3bARZbwqk3ktuBnGCiMJMvP ptMo64rAHDsvTD+AcbkqL2WU10enKOssk2+JIUAaBK3nr6/7BrB9OOkOKLqDQ/ao0tlC ALvA== X-Gm-Message-State: AOAM531m4NQlupD9m++SUWs5HqoCrZnpHQAhcqwfSHM0qv3tghS3aLAc Q6/Cd78z+acQtfGZ2dsMnDDGhKCpU4I= X-Google-Smtp-Source: ABdhPJwPw5YyjDd/zPl+Brj93leQLYyclfbk5cgQ15Xii011gtMFS83Expmyzcd2vTKukQc8aAmLhg== X-Received: by 2002:a65:4985:: with SMTP id r5mr20734073pgs.122.1624232182628; Sun, 20 Jun 2021 16:36:22 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.115]) by smtp.gmail.com with ESMTPSA id u21sm13449967pfh.163.2021.06.20.16.36.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Jun 2021 16:36:22 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 49C5DC056D for ; Sun, 20 Jun 2021 16:36:20 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/4] Check -z single-global-definition and -fsingle-global-definition Date: Sun, 20 Jun 2021 16:36:18 -0700 Message-Id: <20210620233620.391576-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210620233620.391576-1-hjl.tools@gmail.com> References: <20210620233620.391576-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3032.0 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" Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 1. Check linker support for -z single-global-definition. If GNU_PROPERTY_1_NEEDED_SINGLE_GLOBAL_DEFINITION is set on any input relocatable files: a. Don't generate copy relocations. b. Turn off extern_protected_data. c. Treate reference to protected symbols with single global definition as local. d. Set GNU_PROPERTY_1_NEEDED_SINGLE_GLOBAL_DEFINITION on output. e. Add -z [no]single-global-definition to control single global definition. 2. Check compiler support for -fsingle-global-definition: a. Generate a single global definition 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 190218 9672 416 200306 30e72 ld.so (original) 190258 9336 416 200010 30d4a ld.so (-fsingle-global-definition) 1917384 20232 52424 1990040 1e5d98 libc.so (original) 1919946 20240 52432 1992618 1e67aa libc.so (-fsingle-global-definition) 261734 10339 744 272817 429b1 localedef (original) 233084 41734 648 275466 4340a localedef (-fsingle-global-definition) 2. On i686: text data bss dec hex filename 199369 6796 212 206377 32629 ld.so (original) 199381 6796 212 206389 32635 ld.so (-fsingle-global-definition) 2058080 11136 38856 2108072 202aa8 libc.so (original) 2058092 11136 38856 2108084 202ab4 libc.so (-fsingle-global-definition) 276207 9559 552 286318 45e6e localedef (original) 254249 33734 520 288503 466f7 localedef (-fsingle-global-definition) --- configure | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++- configure.ac | 37 ++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 9619c10991..5844dad68f 100755 --- a/configure +++ b/configure @@ -732,6 +732,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -844,6 +845,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1096,6 +1098,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1233,7 +1244,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1386,6 +1397,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -5746,6 +5758,65 @@ fi $as_echo "$libc_cv_insert" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking -z single-global-definition" >&5 +$as_echo_n "checking -z single-global-definition... " >&6; } +if ${libc_cv_z_single_global_definition+:} 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_single_global_definition=yes + else + libc_cv_z_single_global_definition=no + fi + rm -f conftest.* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_z_single_global_definition" >&5 +$as_echo "$libc_cv_z_single_global_definition" >&6; } +config_vars="$config_vars +have-z-single-global-definition = $libc_cv_z_single_global_definition" + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fsingle-global-definition" >&5 +$as_echo_n "checking for -fsingle-global-definition... " >&6; } +if ${libc_cv_fsingle_global_definition+:} 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_fsingle_global_definition=yes + else + libc_cv_fsingle_global_definition=no + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_fsingle_global_definition" >&5 +$as_echo "$libc_cv_fsingle_global_definition" >&6; } +config_vars="$config_vars +have-fsingle-global-definition = $libc_cv_fsingle_global_definition" + { $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..26932812da 100644 --- a/configure.ac +++ b/configure.ac @@ -1222,6 +1222,43 @@ EOF ]) AC_SUBST(libc_cv_insert) +AC_CACHE_CHECK(-z single-global-definition, + libc_cv_z_single_global_definition, + [cat > conftest.c <&AS_MESSAGE_LOG_FD]); then + libc_cv_z_single_global_definition=yes + else + libc_cv_z_single_global_definition=no + fi + rm -f conftest.* + ]) +LIBC_CONFIG_VAR([have-z-single-global-definition], + [$libc_cv_z_single_global_definition]) + +AC_CACHE_CHECK(for -fsingle-global-definition, + libc_cv_fsingle_global_definition, + [cat > conftest.c <&AS_MESSAGE_LOG_FD]); then + libc_cv_fsingle_global_definition=yes + else + libc_cv_fsingle_global_definition=no + fi + rm -f conftest*]) +LIBC_CONFIG_VAR([have-fsingle-global-definition], + [$libc_cv_fsingle_global_definition]) + AC_CACHE_CHECK(for broken __attribute__((alias())), libc_cv_broken_alias_attribute, [cat > conftest.c <