-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Drop explicitly passed -lc unless -nodefaultlibs or similar is passed #22765
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2749,7 +2749,7 @@ def map_to_js_libs(library_name): | |
| return None | ||
|
|
||
|
|
||
| def process_libraries(state, linker_inputs): | ||
| def process_libraries(state, linker_inputs, nodefaultlibc): | ||
| new_flags = [] | ||
| libraries = [] | ||
| suffixes = STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS | ||
|
|
@@ -2761,6 +2761,12 @@ def process_libraries(state, linker_inputs): | |
| new_flags.append((i, flag)) | ||
| continue | ||
| lib = removeprefix(flag, '-l') | ||
| if lib == 'c' and not nodefaultlibc: | ||
| # Drop explicitly passed -lc unless they also passed -nodefaultlibs or | ||
| # similar. It's important to link libc after our other injected system | ||
| # libraries like libbulkmemory, but user linked libraries go ahead of | ||
| # system libraries, so if the user passes `-lc` then we can get crashes. | ||
| continue | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I agree this fixed the program at hand, it also seems a little to magical. What if user explictly wants to do something like this:
In this case removing the explicit Perhaps it would be better to fix rust not to pass the explicit
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should at least warn the user when we do this?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I suppose so. But passing What about the option of injecting the system libs ahead of the user object files? Do you think that would have any negative consequences?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well it seems to work for them with all of the other linker they use. I'm trying to fix it from rust's side too, but it seems to me like it's the linker's responsibility to correctly handle this and not the consumer's responsibility not to pass it.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any downside to remove it that you know of? Why is it even there?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the workaround on the rust side is pretty short nad has no downsides I know of. It was rejected two years ago when I tried to merge the fix to rust, but I opened a new PR with the same fix and maybe it will be accepted this time. I think their response was roughly "if it breaks to pass
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, anyone of passes So I think that removing Another solution would be to merge all out libc libraries into a single one but then we would end up with even more variants, e.g.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading the Rust codebase, I am not at all sure where it gets decided that it should pass
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I guess now that we know more about the problem we can make a better argument for removing it. We can say "supplying -lc on its own just doesn't work with emscripten and will break the build". Also, since the compiler always includes libc by default this flag is redundant and pointless. Removing it is simply better for everyone.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I'd just really like either Emscripten or Rust to merge a fix for this, I'll see what comments I get on the Rust PR. |
||
|
|
||
| logger.debug('looking for library "%s"', lib) | ||
|
|
||
|
|
@@ -3026,12 +3032,12 @@ def package_files(options, target): | |
|
|
||
|
|
||
| @ToolchainProfiler.profile_block('calculate linker inputs') | ||
| def phase_calculate_linker_inputs(options, state, linker_inputs): | ||
| def phase_calculate_linker_inputs(options, state, linker_inputs, nodefaultlibc): | ||
| using_lld = not (options.oformat == OFormat.OBJECT and settings.LTO) | ||
| state.link_flags = filter_link_flags(state.link_flags, using_lld) | ||
|
|
||
| # Decide what we will link | ||
| process_libraries(state, linker_inputs) | ||
| process_libraries(state, linker_inputs, nodefaultlibc) | ||
|
|
||
| # Interleave the linker inputs with the linker flags while maintainging their | ||
| # relative order on the command line (both of these list are pairs, with the | ||
|
|
@@ -3072,8 +3078,10 @@ def run(linker_inputs, options, state, newargs): | |
|
|
||
| target, wasm_target = phase_linker_setup(options, state, newargs) | ||
|
|
||
| nodefaultlibc = '-nodefaultlibs' in newargs or '-nolibc' in newargs or '-nostdlib' in newargs | ||
|
|
||
| # Link object files using wasm-ld or llvm-link (for bitcode linking) | ||
| linker_arguments = phase_calculate_linker_inputs(options, state, linker_inputs) | ||
| linker_arguments = phase_calculate_linker_inputs(options, state, linker_inputs, nodefaultlibc) | ||
|
|
||
| # Embed and preload files | ||
| if len(options.preload_files) or len(options.embed_files): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.