From patchwork Mon Apr 19 08:27:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1467815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=d531VhM3; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FP0M606nJz9vFN for ; Mon, 19 Apr 2021 18:28:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B4E883959C7A; Mon, 19 Apr 2021 08:28:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 9DDD5394800A for ; Mon, 19 Apr 2021 08:28:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9DDD5394800A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wr1-x433.google.com with SMTP id e5so4358438wrg.7 for ; Mon, 19 Apr 2021 01:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=EJcS7+Y5Q3kHEuJLPT5tk7vr9Cn/JaPqnZr+rQeDQQI=; b=d531VhM3vKoeaBuXG8m4+iv9rF4aQ1K9u0OAk8sOyjMXJNJbxxbFjJv8vln7llHK/0 X8Qi1aGA4UQiJlkSBabNFb9ZjBxzMnj1jnvg7iZ6fMvoIQL/hEbyx0s3v2HDej/LBrSF xOw0xr/o/jo2XmDV/TAEeb783xku1h9s3iyc6iGlVezIlKk3FYI9B1BrBwqQ/BLTQWtm n6kCHH5S58EJBH1yjP/AXcWb3QJmR4xvWJKawa27xs87Ly/uoq4roClMTWZrk9nPDJEu pMHvJ6WFgfYZPuZuuhSy5EQyqgCGXs0QlxbfO3UfE2B8dlkcEQO8ZvXz+BYzadEY0Q6M CeYg== 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:mime-version :content-transfer-encoding; bh=EJcS7+Y5Q3kHEuJLPT5tk7vr9Cn/JaPqnZr+rQeDQQI=; b=DEkNyMiZUyGUoF1fEnQn2KSjHjQ3NX3NjlksnVsjAvAGxECOiEMJGgNjvQIRXfpc5f HKK6INaqQAsMFFmBIc5XD/c+yQNKZbad/MLteX/BZKEajfuT/UmEczaEvAeImxR7o6la W0SNQJCrZROofaG+5XzY9CDBl4PLHZZ0ljeSyJzGz2iZERF1wGBeOtAeoipUdBR0AGEh 3R0XIP5gOZRrRgc9DpuOKU6Tu4R1b57savgtJSiurgW/Lzb33wt8dqggYMInleRMfU2g gf3FWn1bhIGMDpyrKSQtWSq03bnvafaBBAKvtXxKxs1Glk+0MAQi6sLTRQLJoVhV3BYO YAbw== X-Gm-Message-State: AOAM531f87zHe8hH9tlrbvduFD5+9GZ6aRcdMluPRwQVPBCEPJH1xxGP RfL+K76AAT9PWBXrissuOoVkA41gKY5rjkz/ X-Google-Smtp-Source: ABdhPJyj01qSO+Uq7DRPrVoCya0R1b738C5WAfzvE5YiMkxwBphL4msmeG1xDEp3nrJp++PTaVWCuw== X-Received: by 2002:a05:6000:362:: with SMTP id f2mr13167048wrf.141.1618820887537; Mon, 19 Apr 2021 01:28:07 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id u6sm20774118wml.23.2021.04.19.01.28.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 01:28:06 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [x86] Fix another -freorder-blocks-and-partition glitch with Windows SEH Date: Mon, 19 Apr 2021 10:27:53 +0200 Message-ID: <12750987.uLZWGnKmhe@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Since GCC 8, the -freorder-blocks-and-partition pass can split a function into hot and cold parts, thus generating 2 FDEs for a single function in DWARF for exception purposes and doing an equivalent trick for Windows SEH on x86-64. Now the Windows system unwinder does not support arbitrarily large frames and there is even a hard limit on the encoding of the CFI, which changes the stack allocation strategy when it is topped and which must be reflected everywhere. I overlooked that when implementing the -freorder-blocks-and-partition support back in 2018 and this results in an ICE when gigantic frames, like e.g. in the attached Ada testcase. Bootstrapped on x86-64/Windows, applied on all active branches as obvious. 2021-04-19 Eric Botcazou * config/i386/winnt.c (i386_pe_seh_cold_init): Properly deal with frames larger than the SEH maximum frame size. 2021-04-19 Eric Botcazou * gnat.dg/opt92.adb: New test. diff --git a/gcc/config/i386/winnt.c b/gcc/config/i386/winnt.c index cc121965294..b66263ad243 100644 --- a/gcc/config/i386/winnt.c +++ b/gcc/config/i386/winnt.c @@ -921,15 +921,17 @@ i386_pe_seh_cold_init (FILE *f, const char *name) /* In the normal case, the frame pointer is near the bottom of the frame so we can do the full stack allocation and set it afterwards. There - is an exception when the function accesses prior frames so, in this - case, we need to pre-allocate a small chunk before setting it. */ - if (crtl->accesses_prior_frames) - alloc_offset = seh->cfa_offset; - else + is an exception if the function overflows the SEH maximum frame size + or accesses prior frames so, in this case, we need to pre-allocate a + small chunk of stack before setting it. */ + offset = seh->sp_offset - INCOMING_FRAME_SP_OFFSET; + if (offset < SEH_MAX_FRAME_SIZE && !crtl->accesses_prior_frames) alloc_offset = seh->sp_offset; + else + alloc_offset = MIN (seh->cfa_offset + 240, seh->sp_offset); offset = alloc_offset - INCOMING_FRAME_SP_OFFSET; - if (offset > 0 && offset < SEH_MAX_FRAME_SIZE) + if (offset > 0) fprintf (f, "\t.seh_stackalloc\t" HOST_WIDE_INT_PRINT_DEC "\n", offset); for (int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) @@ -958,7 +960,7 @@ i386_pe_seh_cold_init (FILE *f, const char *name) fprintf (f, ", " HOST_WIDE_INT_PRINT_DEC "\n", offset); } - if (crtl->accesses_prior_frames) + if (alloc_offset != seh->sp_offset) { offset = seh->sp_offset - alloc_offset; if (offset > 0 && offset < SEH_MAX_FRAME_SIZE)