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

Improve shared library relative paths handling #320

Merged
merged 8 commits into from
Dec 22, 2020

Conversation

hidmic
Copy link
Contributor

@hidmic hidmic commented Dec 11, 2020

Connected to #143. This patch ensures relative library paths are properly handled.

CI up to test_communication:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status (known test failure)
  • Windows Build Status

image_name = candidate_name;
}
if (dlclose(handle) != 0) {
RCUTILS_SET_ERROR_MSG("dlclose error: %s", dlerror());
Copy link
Contributor

Choose a reason for hiding this comment

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

RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 5915051.

@hidmic hidmic requested a review from ahcorde December 14, 2020 19:11
@hidmic hidmic requested review from azeey and ahcorde and removed request for clalancette and ahcorde December 15, 2020 20:08
Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

LGTM

#if defined(__APPLE__)
const char * image_name = NULL;
uint32_t image_count = _dyld_image_count();
for (uint32_t i = 0; NULL == image_name && i < image_count; ++i) {
Copy link

Choose a reason for hiding this comment

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

I feel like I'm missing something. Is my understanding correct that what ends up in lib->library_path is the absolute path of library_path? If so, can't we just call realpath? Or is it possible library_path and lib->library_path will point to two different files?

Copy link
Contributor Author

@hidmic hidmic Dec 16, 2020

Choose a reason for hiding this comment

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

If so, can't we just call realpath?

The thing is, library_path might simply be the library name e.g. libfoo.so. And that doesn't mean it should be searched in the current working directory. It's only after dlopen performs the search over RPATHs, (DY)LD_LIBRARY_PATHs, and RUNPATHs and actually finds it that you can get the full path to it.

Copy link

Choose a reason for hiding this comment

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

Ah, that makes sense. Thanks! I don't know what the comment etiquette is for this package, but I think it would be great to have that paragraph as a comment just to explain what the goal of this section of code is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing. See 1d4276a.

Copy link

@azeey azeey left a comment

Choose a reason for hiding this comment

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

LGTM

#if defined(__APPLE__)
const char * image_name = NULL;
uint32_t image_count = _dyld_image_count();
for (uint32_t i = 0; NULL == image_name && i < image_count; ++i) {
Copy link

Choose a reason for hiding this comment

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

Ah, that makes sense. Thanks! I don't know what the comment etiquette is for this package, but I think it would be great to have that paragraph as a comment just to explain what the goal of this section of code is.

Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
@hidmic
Copy link
Contributor Author

hidmic commented Dec 22, 2020

Ok, I finally managed to write some tests! It stumbled with CMake and dlopen quirks, but it should be fine now.

@hidmic
Copy link
Contributor Author

hidmic commented Dec 22, 2020

Re-running CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Michel Hidalgo <[email protected]>
@hidmic
Copy link
Contributor Author

hidmic commented Dec 22, 2020

Alright, all tests passing! Thanks for the reviews.

@hidmic hidmic merged commit aec3da4 into master Dec 22, 2020
@delete-merged-branch delete-merged-branch bot deleted the hidmic/shared-library-relpaths branch December 22, 2020 20:58
@cottsay
Copy link
Member

cottsay commented Jan 4, 2021

@hidmic, this change broke clang nightly builds on macOS. Please submit a fix.
https://ci.ros2.org/view/nightly/job/nightly_linux_clang_libcxx/

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.

4 participants