Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Fix 21465: Allocate _tlsRanges in C heap #3308

Merged
merged 1 commit into from
Dec 13, 2020

Conversation

omerfirmak
Copy link
Contributor

Similar to the issue fixed here #1655 (comment) ,
static version of the sections_elf_shared accesses TLS of a dead thread. The simplest fix is to allocate
_tlsRanges somewhere that would persist outside of the thread scope, for example the C heap.

This was encountered while porting ldc 1.24.0 to Alpine Linux which uses Musl.
https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/14364 But this issue should
be affecting other libc implementations as well.

Fixes https://issues.dlang.org/show_bug.cgi?id=21465

@omerfirmak omerfirmak requested a review from Burgos as a code owner December 9, 2020 17:05
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @omerfirmak! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + druntime#3308"

Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, did you encounter the same on gdc as well @Geod24 ?

static Array!(void[])* x = null;
if (x is null)
x = cast(Array!(void[])*).calloc(1, Array!(void[]).sizeof);
assert(x);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably too soon to throw Errors, and safeAssert a better fit.

Copy link
Contributor Author

@omerfirmak omerfirmak Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only alternative is to crash or error in initTLSRanges. I am making the change to safeAssert

@omerfirmak omerfirmak force-pushed the fix-21465-stable branch 2 times, most recently from f667d1b to 7ebfaaa Compare December 12, 2020 13:40
Similar to the issue fixed here dlang#1655 (comment) ,
static version of the sections_elf_shared accesses TLS of a dead thread. The simplest fix is to allocate
_tlsRanges somewhere that would persist outside of the thread scope, for example the C heap.

This was encountered while porting ldc 1.24.0 to Alpine Linux which uses Musl.
https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/14364 But this issue should
be affecting other libc implementations as well.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants