lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 7 Oct 2023 10:30:35 +0200
From:   Willy Tarreau <w@....eu>
To:     Thomas Weißschuh <linux@...ssschuh.net>
Cc:     Shuah Khan <shuah@...nel.org>, linux-kernel@...r.kernel.org,
        linux-kselftest@...r.kernel.org
Subject: Re: [PATCH RFC] tools/nolibc: add support for constructors and
 destructors

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ