Skip to content

Commit 1852e20

Browse files
authored
[Debug] Fix debug-compilation-dir for system libs (#20776)
Fixes #20775 Before this change: $ llvm-dwarfdump -debug-info -debug-line --recurse-depth=0 emscripten/cache/sysroot/lib/wasm32-emscripten/libcompiler_rt.a ... DW_AT_comp_dir ("/emsdk/emscripten") After this change: $ llvm-dwarfdump -debug-info -debug-line --recurse-depth=0 emscripten/cache/sysroot/lib/wasm32-emscripten/libcompiler_rt.a ... DW_AT_comp_dir ("/emsdk/emscripten/cache/build/libcompiler_rt-tmp")
1 parent 569e4fa commit 1852e20

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

test/test_other.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9780,6 +9780,21 @@ def test_separate_dwarf_with_filename_and_path(self):
97809780
'-sSEPARATE_DWARF_URL=http://somewhere.com/hosted.wasm'])
97819781
self.assertIn(b'somewhere.com/hosted.wasm', read_binary('a.out.wasm'))
97829782

9783+
@crossplatform
9784+
def test_dwarf_system_lib(self):
9785+
if config.FROZEN_CACHE:
9786+
self.skipTest("test doesn't work with frozen cache")
9787+
self.run_process([EMBUILDER, 'build', 'libemmalloc', '--force'])
9788+
libc = os.path.join(config.CACHE, 'sysroot', 'lib', 'wasm32-emscripten', 'libemmalloc.a')
9789+
self.assertExists(libc)
9790+
9791+
dwdump = self.run_process(
9792+
[LLVM_DWARFDUMP, libc, '-debug-info', '-debug-line', '--recurse-depth=0'],
9793+
stdout=PIPE).stdout
9794+
# Check that the embedded location of the source file is correct.
9795+
self.assertIn('DW_AT_name\t("system/lib/emmalloc.c")', dwdump)
9796+
self.assertIn('DW_AT_comp_dir\t("/emsdk/emscripten")', dwdump)
9797+
97839798
@parameterized({
97849799
'O0': (['-O0'],),
97859800
'O1': (['-O1'],),

tools/system_libs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ def generate_ninja(self, build_dir, libname):
471471
cflags = self.get_cflags()
472472
if self.deterministic_paths:
473473
source_dir = utils.path_from_root()
474+
relative_source_dir = os.path.relpath(source_dir, build_dir)
474475
cflags += [f'-ffile-prefix-map={source_dir}=/emsdk/emscripten',
476+
f'-ffile-prefix-map={relative_source_dir}/=',
475477
'-fdebug-compilation-dir=/emsdk/emscripten']
476478
asflags = get_base_cflags(preprocess=False)
477479
input_files = self.get_files()
@@ -491,7 +493,9 @@ def build_objects(self, build_dir):
491493
cflags = self.get_cflags()
492494
if self.deterministic_paths:
493495
source_dir = utils.path_from_root()
496+
relative_source_dir = os.path.relpath(source_dir, build_dir)
494497
cflags += [f'-ffile-prefix-map={source_dir}=/emsdk/emscripten',
498+
f'-ffile-prefix-map={relative_source_dir}/=',
495499
'-fdebug-compilation-dir=/emsdk/emscripten']
496500
case_insensitive = is_case_insensitive(build_dir)
497501
for src in self.get_files():
@@ -531,6 +535,7 @@ def build_objects(self, build_dir):
531535
# Use relative paths to reduce the length of the command line.
532536
# This allows to avoid switching to a response file as often.
533537
src = os.path.relpath(src, build_dir)
538+
src = utils.normalize_path(src)
534539
batches.setdefault(tuple(cmd), []).append(src)
535540
objects.add(o)
536541

0 commit comments

Comments
 (0)