global variables and static initializers that log are not sound #368

Open
opened 2024-06-01 04:04:17 +00:00 by qyriad · 0 comments
Owner

Brought up in https://github.com/NixOS/nix/issues/10772, see also #306 and #359 for more context. -Wl,--whole-archive seems to work around the specific issue at hand, but the order of static initializers is undefined in C++, and lots of things assume nix::logger != nullptr and just dereference it willy nilly. In https://github.com/NixOS/nix/issues/10772 the global nix::evalSettings constructor calls getDefaultNixPath(), which ends up calling getStateDir(), which of course calls getHome(), which logs a warning if $HOME isn't owned by the current user.

This is fucked. We should not be doing any IO before main in the first place, and we should probably replace the raw pointer nix::logger with a smart pointer or something

Brought up in https://github.com/NixOS/nix/issues/10772, see also #306 and #359 for more context. `-Wl,--whole-archive` seems to work around the specific issue at hand, but the order of static initializers is undefined in C++, and lots of things assume `nix::logger != nullptr` and just dereference it willy nilly. In https://github.com/NixOS/nix/issues/10772 the global `nix::evalSettings` constructor calls `getDefaultNixPath()`, which ends up calling `getStateDir()`, which of course calls `getHome()`, which logs a warning if `$HOME` isn't owned by the current user. This is *fucked*. We should *not* be doing any IO before main in the first place, and we should probably replace the raw pointer `nix::logger` with a smart pointer or something
qyriad added the
stability
label 2024-06-01 04:04:17 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#368
No description provided.