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

On Linux, favor local symbols when loading a shared library #82973

Merged

Conversation

dsnopek
Copy link
Contributor

@dsnopek dsnopek commented Oct 7, 2023

Fixes #82812

Myself and the reporter of that issue, are seeing a strange situation where a GDExtension will use a class defined by the engine with the same name, rather than the class defined in the GDExtension.

Passing RTLD_DEEPBIND to dlopen() when loading the GDExtension seems to fix it in my testing!

About RTLD_DEEPBIND, the man page says:

Place the lookup scope of the symbols in this shared object ahead of the global scope. This means that a self-contained object will use its own symbols in preference to global symbols with the same name contained in objects that have already been loaded.

I'm definitely not an expert on platform-level stuff, so I don't know if this flag has any limitations or caveats associated with it.

Downloading pre-compiled binaries:

  1. Login into github
  2. Click the "checks" tab of this PR
  3. On the right there's an "artifacts" button.
  4. Download the appropriate build for your plaform

image

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

That's likely won't build on macOS and BSDs, the function is overridden on macOS but generic Unix code is still built.

@dsnopek
Copy link
Contributor Author

dsnopek commented Oct 7, 2023

Ah, ok, so should I override it in OS_LinuxBSD? Or just add an #ifdef in OS_Unix (it'd still need an #ifdef in OS_LinuxBSD so BSD doesn't use it)?

@dsnopek
Copy link
Contributor Author

dsnopek commented Oct 7, 2023

Or, actually, I wonder if this problem also affects GDExtensions on MacOS and *BSD? If so, then perhaps the other solution discussed on the issue (building with -fvisibility=hidden) would be the better way to go?

@bruvzg
Copy link
Member

bruvzg commented Oct 7, 2023

Ah, ok, so should I override it in OS_LinuxBSD?

I would probably add something like:

#ifndef RTLD_DEEPBIND
#define RTLD_DEEPBIND 0
#endif

@dsnopek dsnopek force-pushed the gdextension-linux-favor-local-symbols branch from dd37bda to 7f4e700 Compare October 7, 2023 16:07
@dsnopek
Copy link
Contributor Author

dsnopek commented Oct 9, 2023

The OP on issue #82812 confirmed that this fixed their problem as well

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

I can't reproduce the issue on macOS.

As far as I can tell, adding RTLD_DEEPBIND seems fine.

@akien-mga akien-mga merged commit 4949529 into godotengine:master Oct 10, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants