From patchwork Mon Feb 21 22:04:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 51275 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 726FA385F013 for ; Mon, 21 Feb 2022 22:05:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 726FA385F013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1645481130; bh=/AzznbPyKyohzu7XktRGJj4e8fJCkJALPfdNjR+2ZNU=; 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=nIYdzR7ZzUiXJtuvBuovbSMoYuXhHK3At47soqo1I+tQ9c+T/wIXEL4vAKOz2tv5r 8I0djFNaeDxumQByCGy0hH1smRmSCLAEG9Yk6sjeNzHcuJblk+XBriYoUWePtkEGos Xhs+/9xTi2DI0+sDSDuCSo70IRnKcRHQiYo82Hr4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from magnesium.8pit.net (magnesium.8pit.net [45.76.88.171]) by sourceware.org (Postfix) with ESMTP id D434C3858C2C; Mon, 21 Feb 2022 22:04:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D434C3858C2C Received: from localhost (ip5f5ae040.dynamic.kabel-deutschland.de [95.90.224.64]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 2aade332 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:YES); Mon, 21 Feb 2022 23:04:57 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] x86: Fix -fsplit-stack feature detection via TARGET_CAN_SPLIT_STACK Date: Mon, 21 Feb 2022 23:04:49 +0100 Message-Id: <20220221220449.20130-1-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221075116.11790-1-soeren@soeren-tempel.net> References: <20220221075116.11790-1-soeren@soeren-tempel.net> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: soeren--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: soeren@soeren-tempel.net Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Sören Tempel Since commit c163647ffbc9a20c8feb6e079dbecccfe016c82e -fsplit-stack is only supported on glibc targets. However, this original commit required some fixups. As part of the fixup, the changes to the gnu-user-common.h and gnu.h were partially reverted in commit 60953a23d57b13a672f751bec0c6eefc059eb1ab thus causing TARGET_CAN_SPLIT_STACK to be defined for non-glibc targets even though -fsplit-stack is actually not supported and attempting to use it causes a runtime error. This causes gcc internal code, such as ./gcc/go/gospec.c to not correctly detect that -fsplit-stack is not supported and thus causes gccgo to fail compilation on non-glibc targets. This commit ensures that TARGET_CAN_SPLIT_STACK is only set if the default libc is glibc. It is presently unclear to me if there is a better way to detect glibc at pre-processor time. The proposed changes have been tested on x86 and x86_64 Alpine Linux (which uses musl libc) and fix compilation of gccgo for this target. Signed-off-by: Sören Tempel gcc/ChangeLog: * config/i386/gnu-user-common.h (defined): Only define TARGET_CAN_SPLIT_STACK for glibc targets. * config/i386/gnu.h (defined): Ditto. --- Changes since v1: Use (DEFAULT_LIBC == LIBC_GLIBC) instead of OPTION_GLIBC_P to detect use of glibc in a pre-processor context. Is there a better way to detect use of glibc in the config header? gcc/config/i386/gnu-user-common.h | 5 +++-- gcc/config/i386/gnu.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gcc/config/i386/gnu-user-common.h b/gcc/config/i386/gnu-user-common.h index 00226f5a455..e126c3fa9fa 100644 --- a/gcc/config/i386/gnu-user-common.h +++ b/gcc/config/i386/gnu-user-common.h @@ -66,7 +66,8 @@ along with GCC; see the file COPYING3. If not see #define STACK_CHECK_STATIC_BUILTIN 1 /* We only build the -fsplit-stack support in libgcc if the - assembler has full support for the CFI directives. */ -#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE + assembler has full support for the CFI directives. Also + we only support -fsplit-stack on glibc targets. */ +#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && (DEFAULT_LIBC == LIBC_GLIBC) #define TARGET_CAN_SPLIT_STACK #endif diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h index 25fbc07f58c..17494333bb9 100644 --- a/gcc/config/i386/gnu.h +++ b/gcc/config/i386/gnu.h @@ -41,8 +41,9 @@ along with GCC. If not, see . #define TARGET_THREAD_SSP_OFFSET 0x14 /* We only build the -fsplit-stack support in libgcc if the - assembler has full support for the CFI directives. */ -#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE + assembler has full support for the CFI directives. Also + we only support -fsplit-stack on glibc targets. */ +#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && (DEFAULT_LIBC == LIBC_GLIBC) #define TARGET_CAN_SPLIT_STACK #endif /* We steal the last transactional memory word. */