-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Provide clang flag to opt out of wasm-opt
when linking wasm?
#55781
Comments
@llvm/issue-subscribers-clang-driver |
cc: @sunfishcode, @sbc100, @tlively or anyone else who may have worked on this: what do you all think about retaining the |
I think the simplest thing would be to preserve it in all cases. If folks want to strip it they can use I think it might be as simple as adding |
In other words, let wasm-ld decide what debug into to include, and ask wasm-opt to do its best to preserve it. |
Should I submit a change request to add |
Adding I think another way might be to just, change binaryen's behavior so that even without For example, if I create clang -g test.c -c -emit-llvm -o test.ll And finish compiling llc -filetype-obj test.ll -o test.o clang -c test.ll -o test.o Even though the second |
@aheejin Hmm, I think changing binaryen may be a little risky. It's a change to a long-existing user interface and the result could be people shipping name sections unnecessarily without noticing it (if they don't measure code size). Also, there is a reason binaryen differs from Still, for the reasons in the first paragraph I think it's better not to change binaryen here. Instead, could clang pass |
@kripken, I also was thinking along the lines of "conditionally pass |
Its in the clang driver linked above:
wasm-ld never calls wasm-opt itself.. its something that run after wasm-ld. |
Also, I think its has to be unconditional since wasm-ld will produce debug info based on input object files, and not based on the Assuming |
Unfortunately that's not true. Binaryen IR doesn't mention the presence or lack of debug info. That is, having or not having a names section is something the wasm binary format has, but not the text format, and not Binaryen IR which abstracts over both the text and binary format. Atm But if there isn't a better solution, then adding that might be ok. We already have |
(But if we did that, we'd need to add a new flag for it, likely, because of the breaking change issue from before - we don't want wasm-opt to start or stop emitting the names section in new ways compared to what it did before.) |
I new option sounds reasonable. Something like |
Looks like
|
The problem with |
OK, how about this: Why don't we do what |
It's probably rare, but an example use case of generating debug info when there was none before is:
My main concern there is that it's a breaking change for users. They had an existing workflow that does not emit a names section, and now it does. This is worrying because names sections are silent bloat and the user might not realize they are starting to ship larger wasm files for no reason. That idea might be simpler overall, but it's also riskier. in contrast I think |
I can't think of any reason we want wasm-opt to do that.
This involves the user passing an explicit flag though, so if
I agree that this isn't great. IMO it's slightly mitigated by the fact that wasm-opt users are expected to be toolchain developers who are driving wasm-opt with some kind of frontend (as opposed to "end" users developing apps). This means there are fewer direct users, and they will be updating their wasm-opt version explicitly, and (it seems to me) more likely to notice behavior changes than an end user (and maybe it's easier for us to warn them). But there's still some risk. |
Fair point, yeah, it's mostly toolchain people that are relevant here. I agree that reduces the risk. I don't feel super-strongly if everyone else disagrees with me. But I would prefer not to emit a name section by default in any mode, just because of that risk of silent bloat. I'd rather people need to opt-in to get something that has such a risk, using |
Either of those sounds reasonable to me, as long as (one their own) they don't introduce a name section where there was none before. |
By exporting the WASMLABS_SKIP_WASM_OPT envvar, the wasm-opt wrapper present in the wasm-base container image will make the wasm-opt call a no-op. This is useful for cases when we don't desire wasm-opt to be called, for example when invoked directly by clang (llvm/llvm-project#55781).
By exporting the WASMLABS_SKIP_WASM_OPT envvar, the wasm-opt wrapper present in the wasm-base container image will make the wasm-opt call a no-op. This is useful for cases when we don't desire wasm-opt to be called, for example when invoked directly by clang (llvm/llvm-project#55781).
By exporting the WASMLABS_SKIP_WASM_OPT envvar, the wasm-opt wrapper present in the wasm-base container image will make the wasm-opt call a no-op. This is useful for cases when we don't desire wasm-opt to be called, for example when invoked directly by clang (llvm/llvm-project#55781).
By exporting the WASMLABS_SKIP_WASM_OPT envvar, the wasm-opt wrapper present in the wasm-base container image will make the wasm-opt call a no-op. This is useful for cases when we don't desire wasm-opt to be called, for example when invoked directly by clang (llvm/llvm-project#55781).
IMO, it's simpler just to remove the automatic wasm-opt invocation. |
This confused me today as well. I was inspecting the line number extraction of inlined calls in our profiler. The dwarf ranges didn't make sense, but they worked in our CI. Eventually, I realized wasm-opt was being run when on the path, which was the case on my machine, but not on our build container. In my opinion, wasm-opt should never be invoked by the driver. If folks want to use it, they can set it up as part of their build system. Not being able to produce correct wasm modules with |
@llvm/issue-subscribers-lld-wasm Author: Cheng Shao (TerrorJack)
Currently, when linking wasm, `clang` attempts to detect `wasm-opt` in the environment, and invokes it with certain flags based on current optimization level. [source](https://github.com/llvm/llvm-project/blob/940e290860894d274c986c88bea2dcc17f1e93c3/clang/lib/Driver/ToolChains/WebAssembly.cpp#L133)
This behavior is undesirable when user wants to customize when or how |
Sorry but it doesn't seem to me 89d5635 closes this ticket at all. |
@sbc100, did you mean to close this? |
This is also a problem with 3rd-party toolchains that don't properly embed target_features list but use clang for linking (looking at you, .NET). Arguably they should fix this issue on their side but meanwhile it means that linking will fail as soon as optimisation is enabled with lots of errors like
Maybe |
|
I thought it only affected validation? I didn't realise it also allows it to introduce new features. If not, maybe |
It's not just validation. The features affect what optimizations are run and what the optimizations are allowed to do as well. Skipping validation might help, but without e.g. the sign-ext feature being set, wasm-opt will not perform optimizations that introduce sign extension instructions. I wouldn't be surprised if some optimizations hit assertion failures if the features don't match the module, too. |
I stumbled on this bug too. Having the behavior (and even the good working) of clang with frequently used flags such as I believe that there are two problems here, that may be separated in two issues if you find it relevant. The first one is that clang compiling to Wasm and calling Regarding these two problems, I think that the easiest solution would be to remove the If removing the default call for Once correct support for passing flags from clang to Finally, I'll put some questions here in order to better understand the situation around
|
In theory yes, but it would be a large amount of both initial and ongoing effort, so I doubt it. That effort can't be deduplicated because from the wasm side it makes sense to add new optimizations in (Personally I agree with you on the main matter here that the current |
@kripken thanks for the clarifications. I understand that technically, I'm curious though to know if there is any kind of overlap between LLVM optimization features and the ones of I hope that we can all agree on a solution soon, and accept a patch accordingly. |
This flag causes wasm-ld preserve a section even in the face of `--strip-all`. This is useful, for example, to preserve the target_features section in the ase of clang (which can run wasm-opt after linking), and emcc (which performs a bunch of post-link work). Fixes: llvm/llvm-project#60613 Fixes: llvm/llvm-project#55781 Differential Revision: https://reviews.llvm.org/D149917
I've hit this issue a number of times recently. The two problematic outcomes for me were:
|
I'm also in favor of having a flag to disable wasm-opt. If someone could submit a patch, I'd review it. |
This PR fixes llvm#55781 by adding the `--no-wasm-opt` and `--wasm-opt` flags in clang to disable/enable the `wasm-opt` optimizations. The default is to enable `wasm-opt` as before in order to not break existing workflows. I think that adding a warning when no flag or the `--wasm-opt` flag is given but `wasm-opt` wasn't found in the path may be relevant here. It allows people using `wasm-opt` to be aware of if it have been used on their produced binary or not. The only downside I see to this is that people already using the toolchain with the `-O` and `-Werror` flags but without `wasm-opt` in the path will see their toolchain break (with an easy fix: either adding `--no-wasm-opt` or add `wasm-opt` to the path). I haven't implemented this here because I haven't figured out how to add such a warning, and I don't know if this warning should be added here or in another PR. CC @sunfishcode that proposed in the associated issue to review this patch.
Currently, when linking wasm,
clang
attempts to detectwasm-opt
in the environment, and invokes it with certain flags based on current optimization level. sourceThis behavior is undesirable when user wants to customize when or how
wasm-opt
is run. It would be nice if aclang
command line flag can be provided to opt-out of this behavior.The text was updated successfully, but these errors were encountered: