Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp853583rdb; Sat, 7 Oct 2023 01:42:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFABSytBnfP9mDE2z5G97ggzh4fk5PGD2SRoRPBCgfVEAuMAT0X8SRxk9Hfnx582/+AUUOa X-Received: by 2002:a05:6358:419e:b0:14d:b8d3:97e8 with SMTP id w30-20020a056358419e00b0014db8d397e8mr11362317rwc.16.1696668145493; Sat, 07 Oct 2023 01:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696668145; cv=none; d=google.com; s=arc-20160816; b=vYc0XgCot5M3/2tfZ+ikLlyrqdhSSvMMgCuwOQWMTZ0BQVPTKKANB0VyMTACIWjjBM yRs6OSex/4v+fBuwmfDS9dF6Sf2fOaPdE3F6XW0dWLaST8MN29XY8ghN8L9p9fRgLimg nmLnZcH9jq6muw2KgFyH/t6Ld3GDI4SMi7yiy9FWbo2WlXOGIh7R3YAoLO7d7PxfCpob nTBee3V98axnn9hPkKDgez5Pb/NXpgeVkVfX9wI39PGLIiUEO+61r/8Vlv7lfA7ZqrI3 79a8/KrGmRK+7oWmMa92qSDMxANYKfL+KhMnocG/2wfyvbwHcDGMnBoC8v7cw141AHVn pV5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Aw/ujK0bN6R0bFd9p7TBXmBodPxN6MRsJi3hitcnssQ=; fh=pTx9fEY7ua+lm7qrJvkJuQzqwoXTh0iZZAyDx4UpkYw=; b=WfBbazIOcN3CuHmsNZtjDdLiptUa3SprIs56DFHZGyuEjzjLu05BX4XDAWzEeStaB9 A/X/8mKgo09UU01sItsxjqiadSB6+ZeHlRB8feiPUJ0PPDtCGhy2Zk3s+G+4u9DLinPa n2ErkAIcWUrYhN49A+94dBWP95MyC6ZBtMJ7ZSz6R/B7PnU9S1tSicnrAGtj4UBmul6l AHjVgcQK4EhPw2ld/zJKHP/I78K8xy+JI3wz20mxcKc/eqUZ+obTdJKA+Yhkzrm75nT5 rEoISGnruuAvjOZnOtptU19d+Ukvgo0PfvRq0toWIahl2AKItifwvP+pzy/BQsylXwkJ MqSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=txnU3414; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id pj3-20020a17090b4f4300b0027724d42e7esi5682762pjb.123.2023.10.07.01.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 01:42:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=txnU3414; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7E597802924F; Sat, 7 Oct 2023 01:42:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234148AbjJGImV (ORCPT + 99 others); Sat, 7 Oct 2023 04:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232558AbjJGImT (ORCPT ); Sat, 7 Oct 2023 04:42:19 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10D059C; Sat, 7 Oct 2023 01:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1696668136; bh=2Vvew6fqSBv6tVBypSBxMHQdLCQoQrI+qlg1pZeHdOE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=txnU3414A6HGKSNh/zpDKbKS8idjPSh1hNbv9HB3d03bf9lsoj8LiwLyBBmv9n23G G2vZXuVc8VNC33EMy/vne4qXUr2Qzl6B9OlnuTjO7YVd+OVatFUkeXOhdPPEsh1vng 2sFMtsvprLjDeAx+QRSonvODYVBpDzxvznkkV+l8= Date: Sat, 7 Oct 2023 10:42:16 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Willy Tarreau Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH RFC] tools/nolibc: add support for constructors and destructors Message-ID: References: <20231005-nolibc-constructors-v1-1-776d56bbe917@weissschuh.net> <20231007065025.GZ20998@1wt.eu> <485b8b48-673a-4b1d-8651-2c0038d478cf@t-8ch.de> <20231007083035.GA21880@1wt.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231007083035.GA21880@1wt.eu> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 07 Oct 2023 01:42:24 -0700 (PDT) On 2023-10-07 10:30:35+0200, Willy Tarreau wrote: > On Sat, Oct 07, 2023 at 09:28:45AM +0200, Thomas Weißschuh wrote: > > > In the past I learned the hard way that you can never trust the execution > > > order of constructors, so if you're unlucky above you could very well end > > > up with 1 and that would be correct. I suggest that instead you do something > > > such as: > > > > > > constructor_test_value += 1; > > > ... > > > constructor_test_value += 2; > > > > > > and check for value 3 in the test to make sure they were both executed > > > exactly once each. > > > > Was this indeterminism for constructors from the same translation unit? > > Or across different translation units/shared objects? > > I'm certain that there's no guarantee from multiple units, but I seem > to remember something about possible reordering within a same unit. > > > I'm not entirely sure, but the GCC [0] docs could be read that within a > > given TU the execution order for constructors is the same as the > > definition order, even for C. > > > > The priorities for constructor and destructor functions are the same > > as those specified for namespace-scope C++ objects > > > > And linked from there: > > > > In Standard C++, objects defined at namespace scope are guaranteed > > to be initialized in an order in strict accordance with that of > > their definitions *in a given translation unit*. No guarantee is made > > for initializations across translation units. > > Then that's probably OK. I'd say it all depends what you want to test. > If you also want the test to cover for this, then your test is stricter, > but then maybe you should put a comment there saying that it's on purpose > to also verify they execute in the expected order ;-) Given that the worst failure mode that could happen here is that the tests fail and directly point at the issue, it should not be too risky to try to rely on this behaviour. Verifying the order was indeed the goal. I'll add the comment. Thanks, Thomas