-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix debug-compilation-dir for system libs #20776
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
Conversation
Good catch! It's worth adding a test for this in |
tools/system_libs.py
Outdated
@@ -472,7 +472,7 @@ def generate_ninja(self, build_dir, libname): | |||
if self.deterministic_paths: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -9771,6 +9771,18 @@ def test_separate_dwarf_with_filename_and_path(self): | |||
'-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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mark this new test a @crossplatform
so it runs on mac and windows too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks right to me.
Looks like you need to add these lines to the new test:
|
3ccba72
to
ef45f57
Compare
@@ -9771,6 +9771,18 @@ def test_separate_dwarf_with_filename_and_path(self): | |||
'-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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks right to me.
Fixes #20775
Before this change:
After this change: