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

Couple of refactorings to make adding dynamic linker support easier #111

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bjorn3
Copy link
Contributor

@bjorn3 bjorn3 commented Mar 5, 2024

No description provided.

Self-relocation is not actually initializing runtime state, but making
it possible to safely run any code at all. When using a dynamic linker
the dynamic linker needs to be relocated before it can do dynamic
linking, but some of the runtime intialization needs to happen after
dynamic linking when all static DSO's that use thread local storage are
known.
Also move writing __stack_chk_guard earlier. This makes future
refactorings easier.
Also move the TLS for spawned threads away from the stack to simplify
the logic and possibly allow using the regular memory allocator for
allocating the TLS block for all threads other than the main thread.
Copy link
Owner

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

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

Overall these changes look good; my main concern is that thread creation and cleanup look like they get more expensive. Currently thread creation is just mmap, mprotect, and clone. With these changes it looks like there will be two mmaps. Similarly, thread cleanup goes from one munmap to two.

Would it be feasible to keep initilaize_main separate from create, but factor out the redundant code into utility functions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants