From patchwork Thu Dec 14 21:28:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 178911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8863640dys; Thu, 14 Dec 2023 13:29:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMbu+AKk6iLFWN66/nAcmLpBVJt9dnByYZhlMs2STnHbI5r8r5m1oS0F5GAH4Lf8gb+kX4 X-Received: by 2002:ad4:41d0:0:b0:67e:fd7f:38e1 with SMTP id a16-20020ad441d0000000b0067efd7f38e1mr2988454qvq.62.1702589348553; Thu, 14 Dec 2023 13:29:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702589348; cv=pass; d=google.com; s=arc-20160816; b=PJ1tY3B5nd09hZe5hI+mw1agAJvatjsYeHfKLsdA+X7nZe/Z10RdwVbWrBuAIV1oWg z3h2GHPvuCgmNFj5lcjRGIyif+l2dKcct0hWzCNZTTDkhFZ32/63HNOQOOJvkzLI6/4Q 62rHXuEnobUVE/MyZhHRyfSKPFmxZdZe+CFgZppaP8jlFVdqYERerlOGujsUTV0quVSH YMH9Gfqn2zDB19aJpCdw9kixcRI4M5eWxk0UhHYao/yKI0rvuFAU7FdnO3JGQHeNs+kV R0c96wrr5sL1+xvJhFQJ3PnZ15ZaJTLTL9CvcDApEVGhQgSavsStMKRRZPTLvfVhvxyI Omsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:in-reply-to:date:references:organization:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=JfOMdZkveom3dpPw5atfBAGxaPJBLOoennVUbSB4XUA=; fh=bNk5JXvdI7C6mAB7KZhcMA/BpQtA2n2NRbo91aS1Hts=; b=WWf4d5BjpJdrp1Vw4nAR5o5NszNwTNAg5O8mNxDbtAPYsuZZqu1f7j1sSbmX0sTajT RkL6hA5v/KxKfvNrj5Q/qut1anOydI7EtGGV/CIQnVoafYeXiiuDVgD+v8XwtoidEoWY vXujPSl/WQnbyXcFnsVK5DtrwYCVVAB+rCxgri2L2U7ROnmHOEtx/WprTnlztW9asbcU KJofHTEI8aHZr4N8vgqLtVUzXlbJ6VfQDHb/c4n8rvfI+quOFZ1s9+QJITa1XMGcCW5H o3eF955D9zF8cmbbuESPGk8MWAtqj1MHOTV6X2SBfnyNDDXrjgDbLaZ8L3Y90+vjt8Xw iStg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b="i1S/eEhy"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b18-20020a0ccd12000000b00679e94355f5si1172388qvm.278.2023.12.14.13.29.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:29:08 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b="i1S/eEhy"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45A7A38618E8 for ; Thu, 14 Dec 2023 21:29:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 29E003858C2C for ; Thu, 14 Dec 2023 21:28:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29E003858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 29E003858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702589324; cv=none; b=JbzqclsmsvMowRBA1+vZve7o1TROzGt3tvfIk9N9EQz/ThLlxkPL+CK/K8Qeq1C8pe26EEpDD0DdSiqQbzbdtM9yixKw+rZwt8qp2GEfCG74DNLxv19lmhSXv9zkGnCRUfyvdc06HOsJVxb1qNYlvugdlkt08AqFaOttZa5MQsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702589324; c=relaxed/simple; bh=vuBk0siOunvGoWyUwOtFd507zlIlQDN7S2NpsVK0+ts=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AiofzNipEjpW7kBjl/NI2RvE4G23nzT0cCVvh4KdE2jE0xzWdC+6l8BITHMJBXYYwjItyypYslVcycKBY6H2bAoZx3254toS1nu3Yr7idAjYtCAsKp6wZ2FWHbo/cn1prxprI8z26O0NrNxvOWUFNrurXQ2wlRAlmRFWposwt5c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5c701bd98f3so35053a12.1 for ; Thu, 14 Dec 2023 13:28:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702589322; x=1703194122; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=JfOMdZkveom3dpPw5atfBAGxaPJBLOoennVUbSB4XUA=; b=i1S/eEhy0SWpbzhEFTG8zEsDxa3FIHsnnebqX3nauRiwSfn2Wou/Lo+Ghv8BHVO/pZ omrr0RmX7oIpF79kj3ypTWoopEVBWjrIHaqdNvFYj4cigMQpQqe4S2J+c4WxhK+u5hhK orJ7m/tfLY6olzYVHz3wukwqxXQeilwdUZQfZUC48m5UzfLwc9gs0HoE0zZldwmLhgRh kUYPl4klrksqn0pp1s/hFUQYTCOLaBvcrcIESNS1+UfjUadSA+BMj9++yV8bToW/VDp6 BIIVem1+uyu4bS+8oc2qCNtmQFfegASZpd64yrWIgsBgBsUon4GaABoQeY2RwAkwm/Tf qx3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702589322; x=1703194122; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JfOMdZkveom3dpPw5atfBAGxaPJBLOoennVUbSB4XUA=; b=pWv+KgHK/MD0l7fn8r4qY0WwsRpncmTe5f9KMTqebq4w65Bex3iFBTyNUe1ex4omrC LaC2+2ByzvUVRxsgTaJBWoelqT5SrTHHhParumgZFDh4lqwjlhHTT9uvNqz6BF1FDtDz lUWSo+/6XMLppPaDd+no7BeplUOpCuxAgLevhUlFcy8Um3j05j37JEtqH1nU9yewnmAn aceOkyH0DGjOX3MtO1vmCe4uuVSvoCc7W2bTlZFKXhlyAR0V1nqlVo6/WJh9Imni0SjA +JSFY12eG3/FHl84RNR3qaWCNvN6rseW3lg6ApKiHkLFuAasQ9w4YtGVa+UMpAWvroRx n0tg== X-Gm-Message-State: AOJu0YzXi397G9drVCBkN+QgPhGxJSjqTvvh0g2J3O3rQiljr3WysQtM XvgFpsiRyjZgw8mrUyGX4zBUTc/etVzTfZiLqhDhxw== X-Received: by 2002:a05:6a20:daa0:b0:190:37f5:f7da with SMTP id iy32-20020a056a20daa000b0019037f5f7damr6247847pzb.59.1702589321779; Thu, 14 Dec 2023 13:28:41 -0800 (PST) Received: from free.home ([2804:7f1:2080:cecc:5977:530e:86b5:e7be]) by smtp.gmail.com with ESMTPSA id p25-20020a056a0026d900b006ce3b01cba2sm11380636pfw.108.2023.12.14.13.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:28:41 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3BELSR5u491427 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 14 Dec 2023 18:28:27 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: Rainer Orth , Jakub Jelinek , "David S. Miller" , Eric Botcazou Subject: [PATCH #2/2] strub: sparc64: unbias the stack address [PR112917] Organization: Free thinker, does not speak for AdaCore References: Date: Thu, 14 Dec 2023 18:28:27 -0300 In-Reply-To: (Alexandre Oliva's message of "Thu, 14 Dec 2023 17:17:09 -0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785294328840594507 X-GMAIL-MSGID: 1785294328840594507 The stack pointer is biased by 2047 bytes on sparc64, so the range it delimits is way off. Unbias the addresses returned by __builtin_stack_address (), so that the strub builtins, inlined or not, can function correctly. I've considered introducing a new target macro, but using STACK_POINTER_OFFSET seems safe, and it enables the register save areas to be scrubbed as well. Because of the large fixed-size outgoing args area next to the register save area on sparc, we still need __strub_leave to not allocate its own frame, otherwise it won't be able to clear part of the frame it should. Regstrapped on x86_64-linux-gnu, also testing on sparc-solaris2.11.3. Ok to install? for gcc/ChangeLog PR middle-end/112917 * builtins.cc (expand_bultin_stack_address): Add STACK_POINTER_OFFSET. --- gcc/builtins.cc | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 7c2732ab79e6f..4c8c514fe8618 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -5443,8 +5443,38 @@ expand_builtin_frame_address (tree fndecl, tree exp) static rtx expand_builtin_stack_address () { - return convert_to_mode (ptr_mode, copy_to_reg (stack_pointer_rtx), - STACK_UNSIGNED); + rtx ret = convert_to_mode (ptr_mode, copy_to_reg (stack_pointer_rtx), + STACK_UNSIGNED); + + /* Unbias the stack pointer, bringing it to the boundary between the + stack area claimed by the active function calling this builtin, + and stack ranges that could get clobbered if it called another + function. It should NOT encompass any stack red zone, that is + used in leaf functions. + + On SPARC, the register save area is *not* considered active or + used by the active function, but rather as akin to the area in + which call-preserved registers are saved by callees. This + enables __strub_leave to clear what would otherwise overlap with + its own register save area. + + If the address is computed too high or too low, parts of a stack + range that should be scrubbed may be left unscrubbed, scrubbing + may corrupt active portions of the stack frame, and stack ranges + may be doubly-scrubbed by caller and callee. + + In order for it to be just right, the area delimited by + @code{__builtin_stack_address} and @code{__builtin_frame_address + (0)} should encompass caller's registers saved by the function, + local on-stack variables and @code{alloca} stack areas. + Accumulated outgoing on-stack arguments, preallocated as part of + a function's own prologue, are to be regarded as part of the + (caller) function's active area as well, whereas those pushed or + allocated temporarily for a call are regarded as part of the + callee's stack range, rather than the caller's. */ + ret = plus_constant (ptr_mode, ret, STACK_POINTER_OFFSET); + + return force_reg (ptr_mode, ret); } /* Expand a call to builtin function __builtin_strub_enter. */