From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id 51ADC3858C98 for ; Wed, 31 Jan 2024 00:08:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51ADC3858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 51ADC3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::533 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706659721; cv=none; b=dwEeT4Q/ciK4DAVlBb1WARIIjEDeyoBqoHaAgP24hRb+WjtuZyLsVNariSwqIStp6TxxZHiwasT9YeO1sD7PAyejqUwXMKqNIa2tvqNLPXpdQp/Yc3NyKHrWtXBvS7eMJ5iXDrbIeZclYnRX+tIjS9xgFXSCPVMbdn4Thio8DR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706659721; c=relaxed/simple; bh=2gHrmkvod1piDnpc7oVT6wP8cMBzTEyRekpE8EEttes=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=bww/fdQi56qzpTxU+j/PkOHhHA7jWpx4FcbAiBa+5PrhjsuBw8vRDQwhe5YKv8PY49Hqjc4RCqSBkm+nXcyQp1KSnIsiG2yjNptJRlJj1cu/Q3R/0OpnFFN8ufohdJhBHP0QBn2SFG69ZkrS+r6GL5I5s8ld0mlO/1SkBWyazp4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5d3907ff128so3747875a12.3 for ; Tue, 30 Jan 2024 16:08:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706659718; x=1707264518; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=IkpLRMoh+kwWvZLJuEa+NUfLrka87sKGxOPbaR/yKWc=; b=YDg17RtMH9ogY7/yxtZqJF5EImbCA5mvNgpCMeBMsbQyifAL44T4nAX3VTgUTPd0hH wy02Mn/HEggs5YIpOLKNcpA4G+CyxZ10tI3BEhG1qjKsgGYySeUsSd6yyUewtDYcxeZM 38K8X4Vxg097q34nwa8C7z1oRcE6Pm4/E0vG3xAn8NjO3DyvNmuyfLpCNCmGHB/UV1PR 6wkpJJwF+MlTgi88UFgytVvJixbUUThw5SeRN23nOb/w30EHZGKg3PsLvi9owWlRXbzg 9pVJ8ffsrapCBsLZQyfwCFpKE4CIttCrvYc9P6u85h2cWmiUTrJJdXOUDZPmLdLAyysW HeGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706659718; x=1707264518; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IkpLRMoh+kwWvZLJuEa+NUfLrka87sKGxOPbaR/yKWc=; b=vV1+n+eFIN2WZzgSnWlJaUfGbtyCbm1ou1xweuXq5Z7EJJcX93fUso/GLgT6j3Ep0y 9ckyDRr3DfFpaeu6A405Ezf6zqCrmar5kYDfgMw5RB2Z7pCVrmWDV6jSdoDAsHprtmPq YAVCw2fZNlH+tSqxLQyaQk21AlMwB9IS+9SsjR+kKTR9xXd/Z2AN6v9AsgrlZ7kJcBUs 8ewXgIXg1+48Hidbn3mA181ydDsIEXJ6OZUQvTQqx8Xd7XEo1Clx/cJYqaC6mi4abz2v PSu2USIww8p/uBIgOKN/UMZtcZg2nWFOzrSYf8TbZkfnFppUvZhZIfJd9symZK/QIMGZ J9tQ== X-Gm-Message-State: AOJu0YwuoED3gZ5asDXaBbI8jnm7bYBLAhZOIBUaLQ/w2KO1UaC8tEPR oXINtazuL9wfbdud60vPBbudFJXJQzcJviqGBQaneHKz16cjLFtM X-Google-Smtp-Source: AGHT+IHGsu+jYsvpxJLf/FsNYKsoT4AIP+zxkepDsAOfxOMEqgwS/eC7R1udrrsVPrPMSG1DKMZunA== X-Received: by 2002:a05:6a20:b703:b0:19d:afe5:fd5 with SMTP id fg3-20020a056a20b70300b0019dafe50fd5mr10957pzb.33.1706659718206; Tue, 30 Jan 2024 16:08:38 -0800 (PST) Received: from ?IPV6:2001:f40:91b::4ad? ([2001:f40:91b::4ad]) by smtp.gmail.com with ESMTPSA id sn13-20020a17090b2e8d00b00295066a69c4sm7900004pjb.36.2024.01.30.16.08.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jan 2024 16:08:37 -0800 (PST) Message-ID: Date: Wed, 31 Jan 2024 00:08:33 +0000 MIME-Version: 1.0 User-Agent: Betterbird (Linux) Subject: Re: Ping: Re: [PATCH] libgcc: fix SEH C++ rethrow semantics [PR113337] To: Matteo Italia , gcc-patches@gcc.gnu.org, Liu Hao Cc: tristan.gingold@cern.ch References: <20240117115144.50181-1-matteo@mitalia.net> <6e99ca24-96b1-400b-8df7-3329b71b7dbc@mitalia.net> From: Jonathan Yong <10walls@gmail.com> Content-Language: en-US Autocrypt: addr=10walls@gmail.com; keydata= xsFNBFDEdwIBEACSrmywJMpgYlgJa0HJ1AFu9tQp8yVpVS21EfnrSK16TS6PoW/JS78D5CYx pshPzr1iil8yeL8/val1yXkI8uNZjMnhLxMBU5C7WEMCeY/h760btG3bZZ5BMCNCkC0Yfrtv JJQDEyv1H+p1U7yMFRyxNtMjaf6QDzoRjTVOzO6mtNMZWYnlhzC54etiVt3HQ4jKOlKbI+dw jigIw8B1SZ+xWcukAHRMBcIZYLjbnAI/XNu796pfwh6QEhJjr8EpvyNjdHLFSMMuyUPO/a3s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GCe1RFrE8bOI8mQCiLpV+FzwyCe4 dmrdKwFeqfyOIcAZeuXj9a0p3M48A6jN63TK4wImOUQiLHtVMtnEQWFdd/p+Zags9XQ/r417 /gRmLQL8nMrGJVWfnnEMmRGcW2Pmi3yTqHQc8mEe+PJMHp5Po7mv2NXv29YDACtWjdydzY07 4ERRFGNj6JbODc4CbryIgC7lkIAUGUXQoAnEei+rhUtVR0ZR0WCN+IMOAxfdUWYXlOH6X7Sn cB/mA+JtLCp99ongTewiNwVOWT7QDuNX53e6MoCGTzTSJmNIeof6g4hW1iPC3yXTv4p3n0R/ ZjTf6sp+6a0wEm4FUK9gIEQx1qulsSFVqBEU1u5P5PYrMq4QAkpk/DzwkfF3xWpj7o7seNRo eJMnJNUeOnz5R3vMX0lJDbfp+hu+bRyFtjJoWqyaN5SZAieOaMxUkc4I8tLiGKG1gRXs81/d 6TrOqX2RA/kCkpcxDSNck4hY20CrCm/3KwjPsHwsxUDwQQle+MMM41hPIdhxoLwSFE/kkQiT /WrWkF5eTU+WypRO9cvg4m46E/ql0AHEFsZ8HPg55eG23av7Xw/8rRLfJGg= In-Reply-To: <6e99ca24-96b1-400b-8df7-3329b71b7dbc@mitalia.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3037.5 required=5.0 tests=BAYES_00,BODY_8BITS,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,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 List-Id: On 1/24/24 15:17, Matteo Italia wrote: > Ping! That's a one-line fix, and you can find all the details in the > bugzilla entry. Also, I can provide executables built with the affected > toolchains, demonstrating the problem and the fix. > > Thanks, > Matteo > I was away last week. LH, care to comment? Changes look fine to me. > Il 17/01/24 12:51, Matteo Italia ha scritto: >> SEH _Unwind_Resume_or_Rethrow invokes abort directly if >> _Unwind_RaiseException doesn't manage to find a handler for the rethrown >> exception; this is incorrect, as in this case std::terminate should be >> invoked, allowing an application-provided terminate handler to handle >> the situation instead of straight crashing the application through >> abort. >> >> The bug can be demonstrated with this simple test case: >> === >> static void custom_terminate_handler() { >>      fprintf(stderr, "custom_terminate_handler invoked\n"); >>      std::exit(1); >> } >> >> int main(int argc, char *argv[]) { >>      std::set_terminate(&custom_terminate_handler); >>      if (argc < 2) return 1; >>      const char *mode = argv[1]; >>      fprintf(stderr, "%s\n", mode); >>      if (strcmp(mode, "throw") == 0) { >>          throw std::exception(); >>      } else if (strcmp(mode, "rethrow") == 0) { >>          try { >>              throw std::exception(); >>          } catch (...) { >>              throw; >>          } >>      } else { >>          return 1; >>      } >>      return 0; >> } >> === >> >> On all gcc builds with non-SEH exceptions, this will print >> "custom_terminate_handler invoked" both if launched as ./a.out throw or >> as ./a.out rethrow, on SEH builds instead if will work as expected only >> with ./a.exe throw, but will crash with the "built-in" abort message >> with ./a.exe rethrow. >> >> This patch fixes the problem, forwarding back the error code to the >> caller (__cxa_rethrow), that calls std::terminate if >> _Unwind_Resume_or_Rethrow returns. >> >> The change makes the code path coherent with SEH _Unwind_RaiseException, >> and with the generic _Unwind_Resume_or_Rethrow from libgcc/unwind.inc >> (used for SjLj and Dw2 exception backend). >> >> libgcc/ChangeLog: >> >>          * unwind-seh.c (_Unwind_Resume_or_Rethrow): forward >>          _Unwind_RaiseException return code back to caller instead of >>          calling abort, allowing __cxa_rethrow to invoke std::terminate >>          in case of uncaught rethrown exception >> --- >>   libgcc/unwind-seh.c | 6 +++--- >>   1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/libgcc/unwind-seh.c b/libgcc/unwind-seh.c >> index 8ef0257b616..f1b8f5a8519 100644 >> --- a/libgcc/unwind-seh.c >> +++ b/libgcc/unwind-seh.c >> @@ -395,9 +395,9 @@ _Unwind_Reason_Code >>   _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc) >>   { >>     if (exc->private_[0] == 0) >> -    _Unwind_RaiseException (exc); >> -  else >> -    _Unwind_ForcedUnwind_Phase2 (exc); >> +    return _Unwind_RaiseException (exc); >> + >> +  _Unwind_ForcedUnwind_Phase2 (exc); >>     abort (); >>   }