Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Nov 26, 2025

The code here expands -lfoo to /path/to/libfoo.so for fake shared libraries so that the linker can find them (it won't look for .so files otherwise when static linking).

The code here expands `-lfoo` to `/path/to/libfoo.so` for fake shared libraries so that the linker can find them (it won't look for .so files otherwise when static linking). Also, on
@sbc100 sbc100 requested a review from kripken November 26, 2025 22:35
@sbc100 sbc100 enabled auto-merge (squash) November 26, 2025 22:35
@sbc100 sbc100 requested a review from dschuff November 26, 2025 22:35
@sbc100
Copy link
Collaborator Author

sbc100 commented Dec 3, 2025

Ping..

# Attempting to link statically against a side module (libside.so) should fail.
err = self.expect_fail([EMCC, '-L.', '-lside'])
self.assertContained(r'error: attempted static link of dynamic object \.[/\\]libside.so', err, regex=True)
self.assert_fail([EMCC, '-L.', '-lside'], 'wasm-ld: error: unable to find library -lside')
Copy link
Member

Choose a reason for hiding this comment

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

Is the old error message not clearer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe, but the new error is more consistent with how lld reports this error which I think is a good thing.

I think its better to pass argument directly to lld (or clang) where we can, and remove special logic like this from the emcc driver.

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 also dont think this is a very common error that is likely to show up much)

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough.

# Attempting to link statically against a side module (libside.so) should fail.
err = self.expect_fail([EMCC, '-L.', '-lside'])
self.assertContained(r'error: attempted static link of dynamic object \.[/\\]libside.so', err, regex=True)
self.assert_fail([EMCC, '-L.', '-lside'], 'wasm-ld: error: unable to find library -lside')
Copy link
Member

Choose a reason for hiding this comment

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

Fair enough.


static_lib = f'lib{lib}.a'
if not settings.RELOCATABLE and not find_library(static_lib, options.lib_dirs):
if not settings.RELOCATABLE and not settings.MAIN_MODULE and not find_library(static_lib, options.lib_dirs):
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 main_module excluded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When we are building with real dynamic linking (i.e. MAIN_MODULE or RELOCATOABLE) we don't need to do any of this since the wasm-ld will just find a use the dynamic libraries.

We only need to do this when fake dylibs are being used.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, but why wasn't it needed 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.

Expanding these -l flags is harmless enough in all cases. Its just work that is not necessary when actually dynamic linking (since wasm-ld will do it in that case).

Copy link
Member

Choose a reason for hiding this comment

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

lgtm, but I'm still confused here...

Even with enabling dynamic linking, you can statically link libraries to the main module? That is, why does dynamic linking mode differ from non-dynamic linking mode, with respect to static linking..?

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 suppose you could have some fake dynamic libraries and some real ones I guess? But if we want to support then then we should remove both settings.RELOCATABLE and settings.MAIN_MODULE here. It seems like a rare case though. Normally one is either doing real dynamic linking of fake dynamic linking, not some hybrid of the two.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh wait.. I remember why this is not necessary in the dynamic linking case.

This is because wasm-ld will search the library path for .so files on its own in that case. No need to expand anything here in those cases.

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks, so wasm-ld behaves differently in that case...

@sbc100 sbc100 merged commit 23242cb into emscripten-core:main Dec 3, 2025
34 checks passed
@sbc100 sbc100 deleted the fake_side_modules branch December 3, 2025 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants