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

Load global symbols #30

Closed
wants to merge 7 commits into from
Closed

Load global symbols #30

wants to merge 7 commits into from

Conversation

ahcorde
Copy link
Contributor

@ahcorde ahcorde commented Nov 2, 2020

This is the basic PR to make use of ign-plugin in other libraries.

This comment in this other PR gazebosim/gz-sensors#38 (comment) explains what is going on. Basically some libraries pre-load some symbols of other libraries (for example libignition-gazebo4-sensors-system.so pre-load some ign-sensor symbols) and when you need to load some of the ign-sensor libraries you can't access these symbols because it was load previously.

Using RTLD_GLOBAL we can access theses symbols but we should filter in all the libraries and look for the right one.

Signed-off-by: ahcorde ahcorde@gmail.com

@ahcorde ahcorde added the 🏢 edifice Ignition Edifice label Nov 2, 2020
@ahcorde ahcorde requested a review from mjcarroll November 2, 2020 15:39
@ahcorde ahcorde requested a review from mxgrey as a code owner November 2, 2020 15:39
@ahcorde ahcorde self-assigned this Nov 2, 2020
@github-actions github-actions bot added 🏰 citadel Ignition Citadel 📜 blueprint Ignition Blueprint 🔮 dome Ignition Dome labels Nov 2, 2020
@traversaro
Copy link

Just as a curiosity, which version of dlfcn-win32 is used in the CI ? vcpkg has 1.1.1 while conda-forge has 1.2.0, and the 1.2.0 had some changes w.r.t. 1.1.1 related also to the RTLD_GLOBAL flag (see dlfcn-win32/dlfcn-win32#44).

Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

Do you think it would be feasible to write a test case that fails without this PR?

@codecov
Copy link

codecov bot commented Nov 2, 2020

Codecov Report

Merging #30 (7ff136d) into main (03d6551) will decrease coverage by 0.33%.
The diff coverage is 60.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #30      +/-   ##
==========================================
- Coverage   99.82%   99.48%   -0.34%     
==========================================
  Files          15       15              
  Lines         584      587       +3     
==========================================
+ Hits          583      584       +1     
- Misses          1        3       +2     
Impacted Files Coverage Δ
loader/src/Loader.cc 99.05% <60.00%> (-0.95%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03d6551...7ff136d. Read the comment docs.

@ahcorde ahcorde removed 🏰 citadel Ignition Citadel 📜 blueprint Ignition Blueprint 🔮 dome Ignition Dome labels Nov 3, 2020
@ahcorde ahcorde force-pushed the ahcorde/global/symbols branch 2 times, most recently from c804ef4 to 1b70d52 Compare November 3, 2020 15:57
@ahcorde ahcorde requested a review from chapulina November 4, 2020 09:17
@chapulina chapulina removed their request for review December 30, 2020 04:04
@ahcorde
Copy link
Contributor Author

ahcorde commented Jan 13, 2021

Thinking a little bit more about this I think this should target main. There are no changes in the API but the behaviour of the library has changed and this will required to modify the existing code that makes use of ign-plugin1. What do you think @mjcarroll and @chapulina ?

@mjcarroll
Copy link
Contributor

I agree that main probably makes more sense. @chapulina are we bumping plugin for Edifice?

@chapulina
Copy link
Contributor

are we bumping plugin for Edifice?

If you peeps are certain that this change is needed to get ign-sensors to work, I'm ok bumping ign-plugin in Edifice. Every downstream library is already being bumped, so this shouldn't have a large impact.

@ahcorde ahcorde changed the base branch from ign-plugin1 to main January 14, 2021 16:58
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde force-pushed the ahcorde/global/symbols branch from bb4eb14 to a8160b2 Compare January 14, 2021 17:04
@ahcorde
Copy link
Contributor Author

ahcorde commented Jan 14, 2021

Retargeted to main.

@ahcorde
Copy link
Contributor Author

ahcorde commented Jan 26, 2021

friendly ping @mjcarroll and @chapulina

@chapulina
Copy link
Contributor

Just as a curiosity, which version of dlfcn-win32 is used in the CI ?

That's a question for @j-rivero

@@ -136,8 +134,6 @@ TEST(EnablePluginFromThis, LibraryManagement)
}

EXPECT_TRUE(weak.IsExpired());

CHECK_FOR_LIBRARY(libraryPath, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe these checks are here to make sure the library is unloaded correctly. But @mxgrey's comment on the function suggests that it may not be reliable, so that could explain why you had to remove these. What do you think @mxgrey , should we remove the false checks, or adjust the CHECK_FOR_LIBRARY function somehow?

https://github.com/ignitionrobotics/ign-plugin/blob/07c20cbc61007bf0982583b3eecb7761ca5cf7c9/test/integration/utils.hh#L32-L42

}

/////////////////////////////////////////////////
TEST(Loader, LoadBadPlugins)
Copy link
Contributor

Choose a reason for hiding this comment

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

Was there a reason to move this test down here? Was it failing above?

@@ -368,7 +368,7 @@ namespace ignition
#endif

void *dlHandle = dlopen(_pathToLibrary.c_str(),
RTLD_NOLOAD | RTLD_LAZY | RTLD_LOCAL);
RTLD_NOLOAD | RTLD_LAZY | RTLD_GLOBAL);
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think, @mxgrey , are we trying to do something that ign-plugin wasn't meant to do, or is this a reasonable change?

See gazebosim/gz-sensors#38 (comment) for the reason why this change is needed.

@j-rivero
Copy link
Contributor

j-rivero commented Feb 2, 2021

Just as a curiosity, which version of dlfcn-win32 is used in the CI ?

That's a question for @j-rivero

Uhm. We are using tarball in the ign-plugin build, I can not find the version on the code. The date of the tarball is Nov 2017, probably 1.1.1?

@chapulina
Copy link
Contributor

I talked to @mxgrey and he had the nice suggestion of adding a flag to enable the new behaviour. If we do this, we may not need to bump the version and only enable the new behaviour for the libraries that need it.

Then I started looking more closely and noticed that the dlopen call being changed is inside ForgetLibrary. I hadn't noticed this detail before. I think it explains the changes in the tests. But now I'm confused about how this helps ign-sensors. Can you elaborate a bit more on why this is needed, @ahcorde ?

@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 2, 2021

@chapulina

Adding a flag required to keep the two functionalities at the same time but the idea it's to keep just one way to load libraries (remove the code in ign-common if I remember correctly).

The function dlclose() decrements the reference count on the dynamic library handle. If the reference count drops to zero and no other loaded libraries use symbols in it, then the dynamic library is unloaded. But this is not reliable. Anyhow I'm also using NODELETE to avoid unload something that it's already running. I remember I got some segfault without this .

I not really sure about how this could help the different libraries (ign-sensors, ign-gui, ign-rendering or ign-gazebo). But the idea it's to use ign-plugin which is the library focuses on loading shared libraries. Maybe there is a deeper implementation issue inside ign-plugin and we don't want to move forward with this implemention, because we nned to load all the symbols an filter them in each library.

@traversaro
Copy link

traversaro commented Feb 3, 2021

Just as a curiosity, which version of dlfcn-win32 is used in the CI ?

That's a question for @j-rivero

Uhm. We are using tarball in the ign-plugin build, I can not find the version on the code. The date of the tarball is Nov 2017, probably 1.1.1?

Thanks! I am asking as in the journey to get a reliable working Gazebo with vcpkg-installed dependencies I became the dlfcn-win32 maintainer, even if I am definitively not an expert of Windows shared library interface. However, several users over time contributed quite a lot to the library. In particular in the release 1.2.0 that came out in 2019 (https://github.com/dlfcn-win32/dlfcn-win32/releases/tag/v1.2.0) there have been some works on loading of global symbols (see dlfcn-win32/dlfcn-win32#44). I would expect for everything to work fine for both dlfcn-win32 1.1.1 and 1.2.0, but with this tricky issues problems can always emerge.

Actually I already wrote most of this in the original comment ( #30 (comment) ), but I forgot about that, sorry for the noise. : )

@chapulina chapulina added the beta Targeting beta release of upcoming collection label Mar 17, 2021
@chapulina chapulina removed the beta Targeting beta release of upcoming collection label Mar 23, 2021
@chapulina
Copy link
Contributor

Removing beta label, we won't have time to wrap this up before code freeze. Let's retarget at Ignition-F.

@chapulina chapulina added 🏯 fortress Ignition Fortress and removed 🏢 edifice Ignition Edifice labels Apr 1, 2021
@chapulina
Copy link
Contributor

This isn't necessary anymore as we solved the ign-sensors needs by removing plugin functionality.

@chapulina chapulina closed this Aug 17, 2021
@chapulina chapulina deleted the ahcorde/global/symbols branch August 17, 2021 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏯 fortress Ignition Fortress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants