Skip to content

Fix for -lGL + AUTO_NATIVE_LIBRARIES=0 #14337

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

Merged
merged 1 commit into from
Jun 7, 2021
Merged

Fix for -lGL + AUTO_NATIVE_LIBRARIES=0 #14337

merged 1 commit into from
Jun 7, 2021

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 1, 2021

When calling map_to_js_libs('GL') we were mapping this to the JS
libraries, and not also including the native libgl library. Normally
this doesn't matter since libgl is included by default, but not
when AUTO_NATIVE_LIBRARIES=0 is used.

This also happens to fix an old bug (#10171) where we would look on the
file system for libGL.a before looking in map_to_js_libs.

Fixes: #10171
Fixes: #14335

@sbc100 sbc100 requested a review from kripken June 1, 2021 18:07
@sbc100 sbc100 force-pushed the fix_libgl branch 4 times, most recently from a608686 to b89154e Compare June 2, 2021 01:03

def test_explict_gl_linking(self):
# ensure libgl exists
self.run_process([EMBUILDER, 'build', 'libgl'])
Copy link
Member

Choose a reason for hiding this comment

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

what happens if embuilder isn't run here? wouldn't we build the library automatically?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No. As of today if you use NO_AUTO_NATIVE_LIBRARIES there is no way to trigger the auto-building of the affected libraries (libgl, libal, libhtml5). I think we can fix that as part of #14341

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(this PR doesn't change that)

Copy link
Member

Choose a reason for hiding this comment

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

Force pushes make it hard to see, but is the addition of NO_AUTO_NATIVE_LIBRARIES new? Or did I just miss it before?

Regardless, why is it here? Wouldn't the test be shorter without it, as we could delete the above line?

If the reasoning is that NO_AUTO_NATIVE_LIBRARIES gives us an error if we try to use a missing library, and the point of the test is to check for that error, how does this avoid the library already existing because it was built by the test harness (or another test) before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NO_AUTO_NATIVE_LIBRARIES was always there.

And yes I can not remove the line above your are right. Sorry about that.

The reason that NO_AUTO_NATIVE_LIBRARIES is needed is because -lGL was previously failing in that mode (NO_AUTO_NATIVE_LIBRARIES is enabled in strict mode which is more common than the almost unknown/unused NO_AUTO_NATIVE_LIBRARIES).

Before:

-sSTRING -lGL -> link failure because to interpret -lGL as being just about JS libraries

After:

-sSTRICT -lGL -> link success because we find and use the native library.

@sbc100 sbc100 force-pushed the fix_libgl branch 5 times, most recently from a91b043 to c662994 Compare June 3, 2021 01:45
@sbc100
Copy link
Collaborator Author

sbc100 commented Jun 3, 2021

Removed hacky comment and workaround. This should be good to go now.

@sbc100 sbc100 requested a review from kripken June 3, 2021 01:49
@sbc100 sbc100 enabled auto-merge (squash) June 3, 2021 03:19
@@ -1339,7 +1339,6 @@ def is_wasm_dylib(filename):
def map_to_js_libs(library_name):
# Some native libraries are implemented in Emscripten as system side JS libraries
library_map = {
'c': [],
Copy link
Member

Choose a reason for hiding this comment

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

why is it safe to remove this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its not just safe, but essential if we want to continue to allow folks to do -lc on the command line.

The reason is that previously we would search for libc.a on the filesystem before looking in this map. With this change we call map_to_js_libs first, so this would cause -lc to be ignored, which we don't want.

In practice anyone who passes -lc today might not get the correct version of libc, but that was true both before and after this change. To fix that issue we have #14355, although that issue is completely separate to this change.

Copy link
Member

Choose a reason for hiding this comment

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

I am having a hard time understanding this. How is, say, libc (which is removed here) different from libdl (which is not)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

libdl and libm don't exist under musl, since they all get rolled into libc. So the libdl and libm cases here are different because we really do want them to be no-ops.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are pretending to have -ldl support for compat with glibc

Copy link
Member

Choose a reason for hiding this comment

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

In that case, how about comments on each one explaining the issues? Sorry, but this is all quite unclear to me. Maybe this is just part of the codebase I am unfamiliar with.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree.. that would be more clear.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After rebasing on top of #14382 perhaps this is more clear now?

@sbc100 sbc100 force-pushed the fix_libgl branch 2 times, most recently from 982bc5e to 483091e Compare June 4, 2021 03:19
sbc100 added a commit that referenced this pull request Jun 4, 2021
sbc100 added a commit that referenced this pull request Jun 4, 2021
@sbc100 sbc100 force-pushed the fix_libgl branch 2 times, most recently from 690236f to 7b3716a Compare June 4, 2021 21:09
@sbc100 sbc100 disabled auto-merge June 4, 2021 21:09
@sbc100 sbc100 force-pushed the fix_libgl branch 2 times, most recently from 17240e5 to c77b6c6 Compare June 4, 2021 22:41
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Looks a lot better! But still, I don't get the test, see comment...


def test_explict_gl_linking(self):
# ensure libgl exists
self.run_process([EMBUILDER, 'build', 'libgl'])
Copy link
Member

Choose a reason for hiding this comment

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

Force pushes make it hard to see, but is the addition of NO_AUTO_NATIVE_LIBRARIES new? Or did I just miss it before?

Regardless, why is it here? Wouldn't the test be shorter without it, as we could delete the above line?

If the reasoning is that NO_AUTO_NATIVE_LIBRARIES gives us an error if we try to use a missing library, and the point of the test is to check for that error, how does this avoid the library already existing because it was built by the test harness (or another test) before?

sbc100 added a commit that referenced this pull request Jun 4, 2021
@sbc100 sbc100 changed the base branch from main to refactor_process_libraries June 4, 2021 23:27
@sbc100
Copy link
Collaborator Author

sbc100 commented Jun 4, 2021

Rebased onto refactor #14384

@kripken
Copy link
Member

kripken commented Jun 4, 2021

Side note, the github UI seems to be hitting a bug here... you responded in detail to my previous comment (thanks!) but it does not show up on this page, nor on the file contents page. It makes sense not to be there, since the file was updated around the comment. But it's like your response is gone, with even the "conversations" tab not allowing access to it... I had to find the email to me to re-read it.

Base automatically changed from refactor_process_libraries to main June 5, 2021 00:25
sbc100 added a commit that referenced this pull request Jun 5, 2021
When calling `map_to_js_libs('GL')` we were mapping this to the JS
libraries, and not also including the native `libgl` library.  Normally
this doesn't matter since `libgl` is included by default, but not when
`AUTO_NATIVE_LIBRARIES=0` is used.

This also happens to fix an old bug (#10171) where we would look on the
file system for `libGL.a` before looking in `map_to_js_libs`.

Fixes: #10171
Fixes: #14335
@sbc100 sbc100 enabled auto-merge (squash) June 5, 2021 00:27
@sbc100 sbc100 merged commit 0ca7b3a into main Jun 7, 2021
@sbc100 sbc100 deleted the fix_libgl branch June 7, 2021 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants