From patchwork Thu Oct 7 20:08:12 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: 45968 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 3413D3857C6A for ; Thu, 7 Oct 2021 20:10:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3413D3857C6A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633637404; bh=iEgNquMUyqQfpsQq7f7ljzuY6WA8CBvP5q0lQpAQuOw=; 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=dViM1eOBIhngwG1pIeXUKYxuDqZjLJpWbrwJq1STVYwB8tdmFrcRDBmyOtcIdSHDT 3GFCnEvRyFkXNrJvIIHdKFERXzhzeF3tvFIqmgUj2sD1EYuuZnVOFwMQ6EwHueHWbI PDY2zU9v1GhqfPNRw1Fvekttym1IlTammYOHomd4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 60E133858001 for ; Thu, 7 Oct 2021 20:08:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 60E133858001 Received: by mail-pg1-x532.google.com with SMTP id 75so868009pga.3 for ; Thu, 07 Oct 2021 13:08:16 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=iEgNquMUyqQfpsQq7f7ljzuY6WA8CBvP5q0lQpAQuOw=; b=HUKiQTKuzFl2cPZED3BDs9ucW4nbMUw13PPnHbDI/4dbVE5x5YukQdd/josBIYgFV1 TsiatxeHnfR0J+l586ydlTw3ZMRG+z+bUa5OsXOy/JtwO8QEpRlOtTG7WkCS5MmVn10D QrjDt4Ho40tn5eUwY/A371jIGfe7n9H7kbRJv7IJ6hCoLVJ5+1YwKZXGi+BPjPd7CFYT N5odchxTvH+rE2O6+j0S7xW27FwS3WXG94+6PIghC1qnVdlE9RvYeq5ObhtluYnXZIw/ cekopCZrJQp19SWg3eCCfPHrI5Fn8iYYG8UJks+Ro83TwmchqYy1cePFNM18mro4GlNe m9+w== X-Gm-Message-State: AOAM531eAuSM9WSQxoPkQuFe3nL5bznGx204k4ckdEx4IuqfVzZEfu85 7v9qsZ4F8FTdswKfyrlcOz8DI0/J7rU= X-Google-Smtp-Source: ABdhPJxojvZMJH9hSpxrEXkn6nCTwNMkKA1kFm90bjj3hFtwcuFuAQlVZbFhqyorfqSyN48MSaSq1Q== X-Received: by 2002:a63:1e03:: with SMTP id e3mr1236144pge.213.1633637295418; Thu, 07 Oct 2021 13:08:15 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.58.39.6]) by smtp.gmail.com with ESMTPSA id v2sm115005pje.15.2021.10.07.13.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 13:08:14 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 6A567C0305; Thu, 7 Oct 2021 13:08:13 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/3] Check compiler support for -fno-direct-extern-access Date: Thu, 7 Oct 2021 13:08:12 -0700 Message-Id: <20211007200813.1626777-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211007200813.1626777-1-hjl.tools@gmail.com> References: <20211007200813.1626777-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3031.5 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, URIBL_BLACK 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: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Compiler with -fno-direct-extern-access does: 1. Generate an indirect external access marker in relocatable objects. a. Always use GOT to access undefined data and function symbols, including in PIE and non-PIE. These will avoid copy relocations in executables. b. This is compatible with existing executables and shared libraries. 2. In executable and shared library, bind symbols with the STV_PROTECTED visibility locally: a. The address of data symbol is the address of data body. b. For systems without function descriptor, the function pointer is the address of function body. c. 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 | 27 +++++++++++++++++++++++++++ configure.ac | 16 ++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/configure b/configure index ac24218009..fb79301e72 100755 --- a/configure +++ b/configure @@ -5851,6 +5851,33 @@ $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 8bb0d1a838..e9f9038f25 100644 --- a/configure.ac +++ b/configure.ac @@ -1256,6 +1256,22 @@ EOF 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 <