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

Allow DlLoader to have multiple fallback names when searching for a library #1635

Merged
merged 3 commits into from
Feb 22, 2018

Conversation

Qining
Copy link
Contributor

@Qining Qining commented Feb 20, 2018

Fix #1634

Copy link
Contributor

@AWoloszyn AWoloszyn left a comment

Choose a reason for hiding this comment

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

Looks ok to me, but I will leave it to @ben-clayton to do the final review, in case he was any other opinions.

Copy link
Contributor

@ben-clayton ben-clayton left a comment

Choose a reason for hiding this comment

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

What is this actually trying to fix?
Please can we have a "why" in the CL description?

size_t len = strlen(name) + sizeof(".1");
char* fallback_name = new char[len];
strcat(fallback_name, ".1");
return dlopen(name, RTLD_NOW | RTLD_LOCAL);
Copy link
Contributor

Choose a reason for hiding this comment

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

... and don't you mean fallback_name?

// Try name + ".1"
size_t len = strlen(name) + sizeof(".1");
char* fallback_name = new char[len];
strcat(fallback_name, ".1");
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. You need to clear the memory.
  2. You need to actually copy in name.
  3. You need to free the memory.
  4. You're better of using std::stringstream

Copy link
Contributor

@ben-clayton ben-clayton left a comment

Choose a reason for hiding this comment

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

Perhaps it would be better to add the fallback to the places that attempt to load libvulkan.so - at least then we're loading a version we're confident should be compatible?

@ben-clayton
Copy link
Contributor

@Qining
Copy link
Contributor Author

Qining commented Feb 21, 2018

But the situation for Vulkan is different to libGL.so. At least on my machine, libvulkan.so does exist and it is the one should be opened I think.

The current DlLoader panics if the given library is not found, so for searching both libvulkan.so and libvulkan.so.1 (and potential future versions), it is not capable to handle.

@Qining
Copy link
Contributor Author

Qining commented Feb 21, 2018

Or do you mean we should always only searching for a specific version of Vulkan?

@Qining Qining force-pushed the search-libvulkan-so-1-also branch from 36623a3 to bf661a1 Compare February 21, 2018 19:37
@Qining
Copy link
Contributor Author

Qining commented Feb 21, 2018

Changed to just loading libvulkan.so.1. And this looks working on Android.

@y-novikov
Copy link
Contributor

I think it's working on Android because Android uses core/cc/android/get_vulkan_proc_address.cpp which still has libvulkan.so, which is good, since I don't have libvulkan.so.1 on my Android O Nexus 5X.

@y-novikov
Copy link
Contributor

I think we can't be 100% sure that all Linux drivers have libvulkan.so.1. I prefer the version that tries libvulkan.so and if it is not found looks for libvulkan.so.1.

@y-novikov
Copy link
Contributor

Also, you probably need to change HasVulkanLoader as well.

@Qining Qining force-pushed the search-libvulkan-so-1-also branch from bf661a1 to 92887c6 Compare February 22, 2018 00:44
@Qining
Copy link
Contributor Author

Qining commented Feb 22, 2018

@y-novikov 5ae192f should have the support to searching across multiple names in order and HasVulkanLoader updated

@y-novikov
Copy link
Contributor

Thank you, @Qining, looks good. You probably should also update the description to reference issue 1634.

@Qining Qining changed the title Try appending ".1" to library file name when searching for libraries on Linux Allow DlLoader to have multiple fallback names when searching for a library Feb 22, 2018
Copy link
Contributor

@ben-clayton ben-clayton left a comment

Choose a reason for hiding this comment

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

Cool!

DL(CC _1, CC _2, CC _3);
DL(CC _1, CC _2, CC _3, CC _4);
DL(CC _1, CC _2, CC _3, CC _4, CC _5);
#undef DLLOADER
Copy link
Contributor

Choose a reason for hiding this comment

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

#undef DL ?

// (if any). Names will be used to try to find the library in order. If the
// library cannot be loaded then this is a fatal error. For *nix systems,
// a nullptr can be used to search the application's functions.
template<typename... ConstCharPtrs>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason we are doing this with template magic, rather than something like std::initializer_list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, I just feel DlLoader("libvulkan.so") looks a little bit better than DlLoader({"libvulkan.so"}). But yes, initializer list can do the same and does not need explicit instantiation...Don't have other particular reasons.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, as much as I personally love templates, reading

void* load() {
    return nullptr;
}

template<typename... ConstCharPtrs>
void* load(const char* name, ConstCharPtrs... fallback_names) {
....
...
    return load(fallback_names...);
...
...
Bunch of macros that will cause a link error if we hit 6 arguments.
...

is a lot harder to parse than

void* load(std::initializer_list<const char* name> names) {
   for (auto& nm: names) {
   }

@Qining Qining merged commit 0a1be56 into google:master Feb 22, 2018
@Qining Qining deleted the search-libvulkan-so-1-also branch October 23, 2018 17:25
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