Open tuxillo opened 1 year ago
@rustbot label O-dragonfly
I do think that panicking is the right thing to do here, because returning the same id twice means that the key generation definitely failed. Adding a message to the assertion should make this less obfuscated.
Sidenote: IMHO it would be great if DragonFly reported this by returning e.g. ENOSYS
, that would allow for nicer error handling.
I'm going to check why we return what we do. Also I'll check why FreeBSD does it differently and I'll report back.
Still pending on my side, please don't close.
ping @tuxillo? Any update?
When running the rust-cbindgen binary I get the following error:
After asking around in some IRC channels and in #contribute in discord, the smoking gun seemed this PR: https://github.com/rust-lang/rust/pull/105359
Some more digging revealed that DragonFly BSD's
pthread_key_create()
behaves differently depending on whether the resulting binary is linked against libpthread or not, just like in FreeBSD, for example. In DragonFly BSD, for single-threaded programs the key is untouched (undefined behaviour) and thepthread_key_create()
will be successful whereas FreeBSD returns an error.The below example illustrates it:
Test program:
FreeBSD
no pthread linkage:
pthread linkage:
DragonFly BSD
no pthread linkage:
pthread linkage:
Since the sentinel here is set to 0 and as DragonFly BSD always returns undefined (if initialized or in bss it will be 0, for the most part) for programs not linked against libpthread, then the assertion in
lazy_init()
is hit: https://github.com/rust-lang/rust/blob/1.68.2/library/std/src/sys_common/thread_local_key.rs#L122Additionally, I have found that FreeBSD links their rust-cbindgen binary against pthread whereas we don't do that for DragonFly BSD, which I think would have covered the issue for them.
As a note, we're discussing in the DragonFly BSD side whether we should start our keys at index 1 or not, but my personal opinion is that in this context is that it would just mask the issue already pointed out in the
lazy_init()
comment.Meta
rustc --version --verbose
:Backtrace
``` N/A ```