-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add option to use RTLD_NODELETE when loading a library #102
Conversation
Signed-off-by: Addisu Z. Taddese <[email protected]>
Codecov Report
@@ Coverage Diff @@
## gz-plugin2 #102 +/- ##
===========================================
Coverage 98.25% 98.26%
===========================================
Files 23 23
Lines 745 748 +3
===========================================
+ Hits 732 735 +3
Misses 13 13
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
This could target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any way to add some test for this new method?
@@ -431,7 +437,8 @@ namespace gz | |||
|
|||
// NOTE: We open using RTLD_LOCAL instead of RTLD_GLOBAL to prevent the | |||
// symbols of different libraries from writing over each other. | |||
void *dlHandle = dlopen(_full_path.c_str(), RTLD_LAZY | RTLD_LOCAL); | |||
int dlopenMode = RTLD_LAZY | RTLD_LOCAL | (_noDelete ? RTLD_NODELETE : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might need an ifdef
for RTLD_NODELETE
on windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 644f613
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, the behavior of dlopen is different between Linux and macOS. On Linux, if you dlopen (with RTLD_NODELETE) , dlclose, and dlopen again, since the plugin is not deleted, dlopen will reuse the existing plugin. On macOS, however, even though the plugin is not deleted, dlopen will treat the second dlopen as though a new library is being loaded and end up loading it into a new memory location. Thus, the type of test I was using won't work. Since we're running out of time, I've decided to enable the test only on Linux. If there are other ways to test this, I'm open to ideas.
Should we add __APPLE__
to the ifdef
?
Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
Added a test in 739ae12. |
Signed-off-by: Addisu Z. Taddese <[email protected]>
@ahcorde Apparently, the behavior of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, left a minor comment
@@ -431,7 +437,8 @@ namespace gz | |||
|
|||
// NOTE: We open using RTLD_LOCAL instead of RTLD_GLOBAL to prevent the | |||
// symbols of different libraries from writing over each other. | |||
void *dlHandle = dlopen(_full_path.c_str(), RTLD_LAZY | RTLD_LOCAL); | |||
int dlopenMode = RTLD_LAZY | RTLD_LOCAL | (_noDelete ? RTLD_NODELETE : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, the behavior of dlopen is different between Linux and macOS. On Linux, if you dlopen (with RTLD_NODELETE) , dlclose, and dlopen again, since the plugin is not deleted, dlopen will reuse the existing plugin. On macOS, however, even though the plugin is not deleted, dlopen will treat the second dlopen as though a new library is being loaded and end up loading it into a new memory location. Thus, the type of test I was using won't work. Since we're running out of time, I've decided to enable the test only on Linux. If there are other ways to test this, I'm open to ideas.
Should we add __APPLE__
to the ifdef
?
@jennuine , RTLD_NODELETE still works on macOS, it just that |
@ahcorde, do you have time to give this another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor style comments
Signed-off-by: Louise Poubel <[email protected]>
🎉 New feature
Summary
Some of our segfaults in gz-sim runs and tests (flaky tests) is caused by the access of memory (data or code) that resides in a plugin/shared library after the library has been unloaded and deleted. With
RTLD_NODELETE
,dlclose
will unload the shared library and run it'sfini
function, but doesn't actually delete it. Thus, access to code (eg. destructors) after the library has been "dlclosed" will not cause a segfault.Test it
TODO
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.