Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp849738rdb; Sat, 7 Oct 2023 01:31:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfqOV77ova6YCgaLDFSgB4xduGhwMaVZ351FucsaXHA4r3QzimoZXMk9bWGtYjDpmmcdfI X-Received: by 2002:a17:903:2348:b0:1c5:6dbc:7938 with SMTP id c8-20020a170903234800b001c56dbc7938mr10941252plh.69.1696667464657; Sat, 07 Oct 2023 01:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696667464; cv=none; d=google.com; s=arc-20160816; b=asMg1WWjgrdac9w/oOrei6ADteB1rUOXBK6VdBLZVtBz/dvXiuikxPUaq1X61oer8Y pOkl9qaRNDHvE5N0ztmcszmlUi4b6dzeukey1wlbOTOz0MmbfaqkFGSmdK7eZllQ/krX 7IWEFmbgDg4qRNedbHBFivy7n/g73c4Rbmy3++vGQeBknjHpyxC2w8PCDzmZHdwx80ab TMP8CojZ/tV1UwNkeinSRNpkKq6VrRXGXm5TFZRmY9uf1yVFZY8olG/0iktOU9YjDVg1 fGv512ZEa9jnpYubO4z70NDwYmZQ1+7gPnkyO6qeYAYo8Chzk8ccJg5rL7N3VJ9eT6yP +QpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=t01CAsQqq+ntqO6BD8zekJf3ReriaEjua3QunUYhv28=; fh=qYSE4JWoGuek8PPANgtObAomYOrd4iJoUXDlbhr3PnI=; b=x3aiaQHNT4dBBmAuCC2XWayvvzW0WIdyZkG3QbnvIz9/qAandVfWzHCq16uS6EdsW0 TcwXfLR9NYiuDVrS0R6G+iLBrlVkMYPGIt5aa+FEevSWEGgzRBR0hfHHJ+94aUnZxCyJ hUuDGo1rtyMSVWg7LSI0LPN2/bdcsguT0J60JbERHxXlS+UP9zYSGAGqWYzD/Pa1SAcK pqoaeNWQehE+ahtK6hYdwDo9IKNSENQ47OWOdPV9eFmH/W1DWArfVYgSojSK+6H277tK 64xvaorlh6wNkpRXzSstiEv1ZbqqYAb2Kx+mDoFX84ColPZ/c0FglAtnLLyWq2Yo5AUc X/SA== ARC-Authentication-Results: i=1; mx.google.com; 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 b4-20020a170902ed0400b001c6189eaaebsi5204035pld.186.2023.10.07.01.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 01:31:04 -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; 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 CD4AA8029478; Sat, 7 Oct 2023 01:31:03 -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 S234156AbjJGIaz (ORCPT + 99 others); Sat, 7 Oct 2023 04:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232558AbjJGIax (ORCPT ); Sat, 7 Oct 2023 04:30:53 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A9530A6; Sat, 7 Oct 2023 01:30:50 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3978UZTu021895; Sat, 7 Oct 2023 10:30:35 +0200 Date: Sat, 7 Oct 2023 10:30:35 +0200 From: Willy Tarreau To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= 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: <20231007083035.GA21880@1wt.eu> References: <20231005-nolibc-constructors-v1-1-776d56bbe917@weissschuh.net> <20231007065025.GZ20998@1wt.eu> <485b8b48-673a-4b1d-8651-2c0038d478cf@t-8ch.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <485b8b48-673a-4b1d-8651-2c0038d478cf@t-8ch.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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:31:04 -0700 (PDT) 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 ;-) Willy