Fix debug-compilation-dir for system libs#20776
Fix debug-compilation-dir for system libs#20776kripken merged 8 commits intoemscripten-core:mainfrom
Conversation
|
Good catch! It's worth adding a test for this in |
tools/system_libs.py
Outdated
| source_dir = utils.path_from_root() | ||
| cflags += [f'-ffile-prefix-map={source_dir}=/emsdk/emscripten', | ||
| '-fdebug-compilation-dir=/emsdk/emscripten'] | ||
| f'-fdebug-compilation-dir={build_dir}'] |
There was a problem hiding this comment.
This seems like maybe the wrong fix.
I think the mapping on the line about is the one that needs updating so it ends up being something like -ffile-prefix-map=../..=/emsdk/emscripten'. I think the best way would be to replace source_dir` with somekind of relative source dir?
There was a problem hiding this comment.
You mean that the DWARF entries should be like this?
DW_AT_name ("/emsdk/emscripten/system/lib/compiler-rt/__trap.c")
DW_AT_comp_dir ("/emsdk/emscripten")
I agree with your direction so that unnecessary build sub directories (like cache/build/libcompiler_rt-tmp) would be stripped out from dwarf info.
|
Regarding testing, maybe checking the contents of dwarfdump is simplest, like e.g. Lines 9713 to 9720 in cfc68d8 |
b5ea021 to
156691d
Compare
| '-sSEPARATE_DWARF_URL=http://somewhere.com/hosted.wasm']) | ||
| self.assertIn(b'somewhere.com/hosted.wasm', read_binary('a.out.wasm')) | ||
|
|
||
| def test_dwarf_system_lib(self): |
There was a problem hiding this comment.
Can you mark this new test a @crossplatform so it runs on mac and windows too?
There was a problem hiding this comment.
It looks the test is failing on Windows due to path separators (could be related to WebAssembly/binaryen#2781)
From CI output:
DW_AT_name\t("system\\\\lib/emmalloc.c")
DW_AT_comp_dir\t("/emsdk/emscripten")
@sbc100
Should we modify the test to make it pass on Windows? or drop @crossplatform?
There was a problem hiding this comment.
I think it would be good to fix if possible. Perhaps if this is a pre-existing issue maybe we don't have to fix it now, but it would be good to fix if possible.
Any idea how system\\\\lib/emmalloc.c could end up like that?
There was a problem hiding this comment.
After some digging on my local Windows machine, It seems backslashes in system\\\\lib/emmalloc.c are coming from the source file path we're passing to Clang, and the slash before basename is due to -ffile-reproducible.
Currently, embuilder is passing the source file path in the platform-specific format (with backslashes as separators on Windows):
clang.exe <redacted> -c ..\..\..\system\lib\emmalloc.c
and I get the following DWARF entry
DW_AT_name ("system\\lib/emmalloc.c")
Then when I replace backslashes in the source file path with slashes, the DWARF also have slashes in its file names.
clang.exe <redacted> -c ../../../system/lib/emmalloc.c
DW_AT_name ("system/lib/emmalloc.c")
Therefore, I think the best approach is to apply utils.normalize_path to source file names in the build command.
What do you think?
|
Looks like you need to add these lines to the new test: |
3ccba72 to
ef45f57
Compare
| '-sSEPARATE_DWARF_URL=http://somewhere.com/hosted.wasm']) | ||
| self.assertIn(b'somewhere.com/hosted.wasm', read_binary('a.out.wasm')) | ||
|
|
||
| def test_dwarf_system_lib(self): |
Fixes #20775
Before this change:
After this change: