-
Notifications
You must be signed in to change notification settings - Fork 3.4k
1.38.24 does not generate asm.js with correct variable names with -g3/g4 #7883
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
Comments
Thanks @milizhang! Those details are very helpful. For the asm.js/fastcomp backend, it sounds like we need to port the For the LLVM wasm backend, we can assume people have a quite new LLVM build, so we can just use that flag. In both cases, yes, sounds like we should pass that flag when |
For asm.js backend, I think these new options were added as previously the behavior was controlled by cc1 argument Therefore I think porting |
Sounds good to me. I'm not sure offhand how easy it would be to port those? A first step might be to make emcc emit those flags for the LLVM wasm backend path, where we assume we are using a very recent LLVM, which has them. |
This change is another part that aims to solve #7883, by adding "-fno-discard-value-names" to clang invocation calls from emcc.py, when debug levels >= 3. It depends on emscripten-core/emscripten-fastcomp-clang#27.
I think this was fixed by those PRs. Please comment/reopen if there is remaining work here. |
This change is another part that aims to solve emscripten-core#7883, by adding "-fno-discard-value-names" to clang invocation calls from emcc.py, when debug levels >= 3. It depends on emscripten-core/emscripten-fastcomp-clang#27.
Symptom
The situation seems to be close to what was described in #5094.
For the following source code:
We will get results like the following in 1.38.24 with emcc -s WASM=0 -g4 1.c -o 1.html:
As shown above, all the variable names are stripped away here.
I can also confirm that 1.35.0 is emitting the variable names properly in asm.js. What we will get is like the following:
What is happening?
I believe Emscripten relies on the value names in LLVM IR to properly generate variable names in asm.js outputs. At some point, Clang introduced an option "-discard-value-names" in CC1, and seems like change rC263394 (Integrated into fastcomp-clang around 1.36.7) enabled it by default for NDEBUG builds:
This option discarded all the variable names in generated LLVM IRs, and effectively broke variable name generation for all prebuilt Emscripten SDK binaries since 1.36.7.
In the beginning I was surprised that there is only one single report of the issue (#5094) and it is even marked as closed. After digging a little bit into root cause, I think the potential reason why this issue has been so covert is probably because some of the Emscripten contributors might not be able to actually repro this issue, as they are likely running debug builds and does not have discard-value-names enabled by default. This explains why @kripken originally dismissed #5094 as not repro.
Potential Fixes
For most of clang's use cases, it makes sense to discard value names from LLVM IRs for non-contributor builds, as typical users only needs the DWARF information to debug their compiled binary. However, I feel it is probably not trivial for Emscripten to generate variable names from the DWARF information instead, and at the same time I believe we can all agree that leaving the variable name generation generation broken does significantly impairs user's ability to debug generated JS code.
Fortunately, later version of Clang adds a pair of options to the clang driver (-fdiscard-value-names and -fno-discard-value-names) to allow override of this behavior. If we do not have any near term plan to integrate a much newer version of clang, then it seems like the easiest solution would be to port this change to emscripten-fastcomp-clang, and turn on -fno-discard-value-names for emcc -g3 / -g4.
Thank you very much.
The text was updated successfully, but these errors were encountered: