Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate TLS destructor order on Linux/Unix #2486

Closed
RalfJung opened this issue Aug 14, 2022 · 3 comments · Fixed by #2503
Closed

Investigate TLS destructor order on Linux/Unix #2486

RalfJung opened this issue Aug 14, 2022 · 3 comments · Fixed by #2503
Labels
A-shims Area: This affects the external function shims C-spec-question Category: it is unclear what the intended behavior of Miri for this case is

Comments

@RalfJung
Copy link
Member

@drmeepster reports that we are running the TLS destructors in a different order than what happens when you run rustc for real. However, to my knowledge the exact order in which TLS destructors are invoked is actually not documented. Still, we should ensure that is indeed the case, and add an appropriate comment in the code. (Or we could adjust the order, as that would make it consistent between Linux and Windows.)

@RalfJung RalfJung added A-shims Area: This affects the external function shims C-spec-question Category: it is unclear what the intended behavior of Miri for this case is labels Aug 14, 2022
@RalfJung
Copy link
Member Author

I can confirm that on my system, tests/pass/concurrency/tls_lib_drop.rs via rustc prints

Dropping: 15 (should be before 'Continue main 1').
Dropping: 5 (should be before 'Continue main 1').
Continue main 1.

but via Miri it prints

Dropping: 5 (should be before 'Continue main 1').
Dropping: 15 (should be before 'Continue main 1').
Continue main 1.

Interestingly though, tls_pthread_drop_order passes on both of them.

The documentation explicitly states

The order of destructor calls is unspecified if more than one destructor exists for a thread when it exits.

so Miri is, I think, perfectly right here. It might even be good for test coverage to have a different order than rustc. But I will make the test not depend on the order.

In the future we might want to actually randomize the order in Miri.

@RalfJung
Copy link
Member Author

Though it is strange that tls_pthread_drop_order passes on both -- that indicates they use the same order, but then something works differently in the other test. Hm...

@RalfJung
Copy link
Member Author

Ah of course, tls_pthread_drop_order tests the pthread_key drop order, but actual thread-locals don't use pthread_key on Linux, they use this function and Miri hits the fallback path there by not providing those weak symbols.

bors added a commit that referenced this issue Aug 22, 2022
@bors bors closed this as completed in e0f0e1f Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-shims Area: This affects the external function shims C-spec-question Category: it is unclear what the intended behavior of Miri for this case is
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant