From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id AF70D3858407 for ; Mon, 20 Feb 2023 12:20:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF70D3858407 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x231.google.com with SMTP id t22so1011995oiw.12 for ; Mon, 20 Feb 2023 04:20:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=FxVn1EhJdMcmMvk/RPOLU7e0n+TdY7HO9LP5Dy5twXE=; b=oXEyZ3TqpoM84WvmMGkTulHNJWPJ4p2kJmfQT7TvjGu7emln5l02wkNTBPTM4Tgxfn VNHkG1aVMLBXYG0q9G3KiYHlgZUabyjQreryuhK9eRXAo2r1nE1pNhwA+73BpaBB7N6F rJrln8Iji6Himzz68fqFU6XED4y2gaCI+z//nLk/Vp17mse+s9c8WgqF7Fk6dB13aWS7 7up+qkK6Zxt5QCSJ1A4bys5zMoXbSnzA5MDymREjPGHsvzGlpZXQu1/d+wGyUGm/aqbH pj59NOgkjp1oLEdXYOHjd/YchPaXOK9JDIfGRDOyqkxSeC+3Yyk3OsXQmR+D0dmYSZ0Z jxBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FxVn1EhJdMcmMvk/RPOLU7e0n+TdY7HO9LP5Dy5twXE=; b=Y2c9cTn8bvs+m4iuUo5UYmwfTWVfW30Gv9eYjc/dqseSDkC+hB4ZsnE7AS8vjdw61b x6Fn2cylgN/MJ0nMBS4hi8VA8+89JjARFUWoWCgXQLNdQ7fDpSRHc1ied5YxX363AXog /MHiyh7v7cjDAY0jUzoxi8bAoWleJ4AZ57VDMi2SIcd2VnzPvRbQC1WCQZ2H+YZbHm+v OCq7/lx7YakwF5QLZ1mpE04M2grKcrLVuh9d5nM/ELsuINHb9xWcyZnRTuvP3Iw6WuHS XdD+/BJVmgACkBV/hwHUYqmnwBwx0Vp+0GY8SzTZVqcTa4VkLVQmOaiDq8kw4BNWaovP Z0Jw== X-Gm-Message-State: AO0yUKVH688t0E2yRJjvvHZou0YfQ58Nt31TymlLJZ3AX/yj5sooV6ba InmxRakYypqDJFeraGdsKh69aA== X-Google-Smtp-Source: AK7set9wINZlph+TQX89aIEeY8+Kk3tshOHI5wjGBWoVrhmKVLzGABsrCNDp1Cg/H/dsEaKuezIK5A== X-Received: by 2002:a05:6808:6243:b0:37d:5743:3e89 with SMTP id dt3-20020a056808624300b0037d57433e89mr4740579oib.49.1676895620855; Mon, 20 Feb 2023 04:20:20 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c3:3a5:a0:9596:f951:7d30? ([2804:1b3:a7c3:3a5:a0:9596:f951:7d30]) by smtp.gmail.com with ESMTPSA id z23-20020a9d7a57000000b0068664355604sm4956932otm.22.2023.02.20.04.20.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Feb 2023 04:20:20 -0800 (PST) Message-ID: <11fe0db4-856e-fe7e-9d4a-1700abedaafe@linaro.org> Date: Mon, 20 Feb 2023 09:20:17 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCH] stdlib: Undo post review change to 16adc58e73f3 [BZ #27749] Content-Language: en-US To: Vitaly Buka , libc-alpha@sourceware.org Cc: Rasmus Villemoes References: <92772e3f-4809-ed81-5d3a-796a7dce4f45@linaro.org> <20230218205341.3180300-1-vitalybuka@google.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230218205341.3180300-1-vitalybuka@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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 18/02/23 17:53, Vitaly Buka wrote: > Post review removal of "goto restart" from > https://sourceware.org/pipermail/libc-alpha/2021-April/125470.html > introduced a bug when some atexit handers skipped. > > Signed-off-by: Vitaly Buka LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > stdlib/Makefile | 1 + > stdlib/exit.c | 7 +++- > stdlib/test-atexit-recursive.c | 75 ++++++++++++++++++++++++++++++++++ > 3 files changed, 81 insertions(+), 2 deletions(-) > create mode 100644 stdlib/test-atexit-recursive.c > > diff --git a/stdlib/Makefile b/stdlib/Makefile > index ff5096ad1b..cd32f53b56 100644 > --- a/stdlib/Makefile > +++ b/stdlib/Makefile > @@ -171,6 +171,7 @@ tests := \ > test-a64l \ > test-at_quick_exit-race \ > test-atexit-race \ > + test-atexit-recursive \ > test-bz22786 \ > test-canon \ > test-canon2 \ > diff --git a/stdlib/exit.c b/stdlib/exit.c > index 6b1eed6445..1cd0bdfe94 100644 > --- a/stdlib/exit.c > +++ b/stdlib/exit.c > @@ -51,7 +51,10 @@ __run_exit_handlers (int status, struct exit_function_list **listp, > exit (). */ > while (true) > { > - struct exit_function_list *cur = *listp; > + struct exit_function_list *cur; > + > + restart: > + cur = *listp; > > if (cur == NULL) > { > @@ -113,7 +116,7 @@ __run_exit_handlers (int status, struct exit_function_list **listp, > if (__glibc_unlikely (new_exitfn_called != __new_exitfn_called)) > /* The last exit function, or another thread, has registered > more exit functions. Start the loop over. */ > - continue; > + goto restart; > } > > *listp = cur->next; > diff --git a/stdlib/test-atexit-recursive.c b/stdlib/test-atexit-recursive.c > new file mode 100644 > index 0000000000..0596b9763b > --- /dev/null > +++ b/stdlib/test-atexit-recursive.c > @@ -0,0 +1,75 @@ > +/* Support file for atexit/exit, etc. race tests (BZ #27749). > + Copyright (C) 2023 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +/* Check that atexit handler registed from another handler still called. */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +static void > +atexit_cb (void) > +{ > +} > + > +static void > +atexit_last (void) > +{ > + _exit (1); > +} > + > +static void > +atexit_recursive (void) > +{ > + atexit (&atexit_cb); > + atexit (&atexit_last); > +} > + > +_Noreturn static void > +test_and_exit (int count) > +{ > + for (int i = 0; i < count; ++i) > + atexit (&atexit_cb); > + atexit (&atexit_recursive); > + exit (0); > +} > + > +static int > +do_test (void) > +{ > + for (int i = 0; i < 100; ++i) > + if (xfork () == 0) > + test_and_exit (i); > + > + for (int i = 0; i < 100; ++i) > + { > + int status; > + xwaitpid (0, &status, 0); > + if (!WIFEXITED (status)) > + FAIL_EXIT1 ("Failed iterations %d", i); > + TEST_COMPARE (WEXITSTATUS (status), 1); > + } > + > + return 0; > +} > + > +#define TEST_FUNCTION do_test > +#include