From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 9F712384B83A for ; Fri, 13 May 2022 08:07:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9F712384B83A Received: by mail-wm1-x32b.google.com with SMTP id n126-20020a1c2784000000b0038e8af3e788so4313580wmn.1 for ; Fri, 13 May 2022 01:07:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=yc1V7aONq4FnxJYOS71WBesRmsTD29cnGod1csWIXz8=; b=HPO4AYkrbgHfyVw89Slsr1dD4HhwO1n/7Sj4GKeovqG9E8MIlkzxc0jiU9OQmoby/O +Sw37lN8mTFbi6mlH2YSu6b91gKOktePOIKtdg0soQOrQ6GR2xPf3CyV4/WZugYRxWEv 87nFy46Hryg/bHmUGRvY56+Cx9MK0O5p7twAV5RyxpFQ/1N/pDLcrqSBRloxBbSDsLed Ac8GNXJixiUVnbUxWnR3OcRiHpFzHIKeUi/5ifdI7COeCuWo8xRlU9YbqkJkCnujqG7C /YK6vn5fFxGdr/bRbHWHmkmelbyztGqZLRwqA07MDLIW9XaZOMWjXoscxdXJWsmIlvn4 klPw== X-Gm-Message-State: AOAM531rY0dpavHqSIobqusT3D2IuPcUV6kdwWvpXyoNBIqP35m9cjoT tqS4PLn7zOWrlCBvgrI60KBNdVC0kmnTUw== X-Google-Smtp-Source: ABdhPJwDLV1VzmvWViwkD3ijyPDtpEKU3FrBKOj5m7QhkG6M4mswFYhKgiuYkfc91XbmZ7Afm+wjVw== X-Received: by 2002:a1c:7510:0:b0:394:1961:708 with SMTP id o16-20020a1c7510000000b0039419610708mr13717484wmc.201.1652429276418; Fri, 13 May 2022 01:07:56 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id r14-20020adfa14e000000b0020c5253d8cesm1477959wrr.26.2022.05.13.01.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 01:07:55 -0700 (PDT) Date: Fri, 13 May 2022 08:07:55 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Only use alternate stack when needed Message-ID: <20220513080755.GA2552348@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Nq2Wo0NMKNjxTN9z" Content-Disposition: inline X-Spam-Status: No, score=-13.2 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 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 08:07:59 -0000 --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline If we're not going to install a signal handler for SIGSEGV then we do not need an alternate stack to handle this signal (and e.g. stack overflows). Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnarl/s-taprop__linux.adb (Initialize): Do not use an alternate stack if no handler for SEGV is installed. --Nq2Wo0NMKNjxTN9z Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/libgnarl/s-taprop__linux.adb b/gcc/ada/libgnarl/s-taprop__linux.adb --- a/gcc/ada/libgnarl/s-taprop__linux.adb +++ b/gcc/ada/libgnarl/s-taprop__linux.adb @@ -96,7 +96,7 @@ package body System.Task_Primitives.Operations is Foreign_Task_Elaborated : aliased Boolean := True; -- Used to identified fake tasks (i.e., non-Ada Threads) - Use_Alternate_Stack : constant Boolean := Alternate_Stack_Size /= 0; + Use_Alternate_Stack : Boolean := Alternate_Stack_Size /= 0; -- Whether to use an alternate signal stack for stack overflows Abort_Handler_Installed : Boolean := False; @@ -1375,9 +1375,9 @@ package body System.Task_Primitives.Operations is function State (Int : System.Interrupt_Management.Interrupt_ID) return Character; pragma Import (C, State, "__gnat_get_interrupt_state"); - -- Get interrupt state. Defined in a-init.c - -- The input argument is the interrupt number, - -- and the result is one of the following: + -- Get interrupt state. Defined in init.c. + -- The input argument is the interrupt number, and the result is one of + -- the following: Default : constant Character := 's'; -- 'n' this interrupt not set by any Interrupt_State pragma @@ -1409,6 +1409,12 @@ package body System.Task_Primitives.Operations is Specific.Initialize (Environment_Task); + -- Do not use an alternate stack if no handler for SEGV is installed + + if State (SIGSEGV) = Default then + Use_Alternate_Stack := False; + end if; + if Use_Alternate_Stack then Environment_Task.Common.Task_Alternate_Stack := Alternate_Stack'Address; --Nq2Wo0NMKNjxTN9z--