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

rtld: invoke fini functions #1163

Merged
merged 6 commits into from
Oct 20, 2024
Merged

rtld: invoke fini functions #1163

merged 6 commits into from
Oct 20, 2024

Conversation

64
Copy link
Member

@64 64 commented Oct 15, 2024

#1092 was previously reverted because it caused a regression. In particular, it relied on DSOs to invoke __cxa_finalize, but mlibc itself is missing a call to __cxa_finalize in crtbegin, so any libc-related destructors (such as the guard that flushes all open files) were not run.

Fix this by adding a [[gnu::destructor]] function which calls __cxa_finalize with our own __dso_handle.

Also, while refactoring, I noticed that the crt{begin,end}.S are no longer needed (they were used for .ctor/.dtor handling, which we no longer use), and provided the definition of __dso_handle (which I've moved into C++).

Also add a regression test to ensure we run libc destructors somehow.

@64 64 force-pushed the rtld-fini branch 2 times, most recently from 1371687 to 94d3c42 Compare October 15, 2024 20:16
options/rtld/generic/linker.cpp Outdated Show resolved Hide resolved
options/rtld/generic/linker.hpp Outdated Show resolved Hide resolved
@avdgrinten
Copy link
Member

I'd prefer to not support circular dependencies as these are quite broken anyway.

@Geertiebear
Copy link
Member

Agreed, I misread the code and thought it was ensuring there were no circular dependencies, but actually this code is adding explicit support for it. This PR should keep the old code.

@64 64 marked this pull request as draft October 15, 2024 20:49
@64 64 marked this pull request as ready for review October 16, 2024 23:08
@64
Copy link
Member Author

64 commented Oct 17, 2024

I've removed handling of circular deps and removed crt{begin,end}.S so that we no longer support ctor/dtor (at least, not as part of mlibc - we should be able to load programs compiled with these just fine).

Copy link
Member

@ElectrodeYT ElectrodeYT left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@Dennisbonke Dennisbonke left a comment

Choose a reason for hiding this comment

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

LGTM

@Dennisbonke Dennisbonke merged commit feb4325 into managarm:master Oct 20, 2024
40 checks passed
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.

5 participants