Skip to content

Commit 3bd068c

Browse files
authored
Pass -dumpdir to clang in compile-and-link mode (#28045)
In Clang 17+ (matching GCC 11), compiling and linking in a single command passes `-dumpdir <output>-` to `clang -cc1` so that auxiliary output files (such as `.dwo` from `-gsplit-dwarf` or `.json` from `-ftime-trace`) are named `<output>-<input>.<ext>` in the current working directory rather than being written to `/tmp` alongside the temporary object file. Pass `-dumpdir <target>-` for all non-assembly compilations in `phase_compile_inputs` instead of manually passing `-Xclang -split-dwarf-file` and `-Xclang -split-dwarf-output`.
1 parent d5c8b4e commit 3bd068c

3 files changed

Lines changed: 27 additions & 14 deletions

File tree

‎ChangeLog.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ See docs/process.md for more on how version tagging works.
2020

2121
6.0.14 (in development)
2222
-----------------------
23+
- When compiling and linking in a single command, auxiliary compiler output
24+
files (such as `.dwo` files from `-gsplit-dwarf` or `.json` files from
25+
`-ftime-trace`) are now named `<output>-<input>.<ext>`, matching the behavior
26+
of `clang`. Previously, `.dwo` files were named `<input>.dwo` and other
27+
auxiliary files were written to the temporary directory. (#28045)
2328
- libunwind and compiler-rt were updated to LLVM 23.1.3. (#28011, #28014)
2429
- mimalloc was updated to 3.5.3. (#28026)
2530

‎emcc.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,14 +586,16 @@ def compile_source_file(input_file):
586586
if ext == '.pcm':
587587
cmd = [c for c in cmd if not c.startswith('-fprebuilt-module-path=')]
588588
cmd += [*compile_args, '-c', input_file, '-o', output_file]
589-
if options.requested_debug == '-gsplit-dwarf':
589+
if ext not in ASSEMBLY_EXTENSIONS:
590590
# When running in COMPILE_AND_LINK mode we compile objects to a temporary location
591-
# but we want the `.dwo` file to be generated in the current working directory,
592-
# like it is under clang. We could avoid this hack if we use the clang driver
593-
# to generate the temporary files, but that would also involve using the clang
594-
# driver to perform linking which would be a big change.
595-
cmd += ['-Xclang', '-split-dwarf-file', '-Xclang', unsuffixed_basename(input_file) + '.dwo']
596-
cmd += ['-Xclang', '-split-dwarf-output', '-Xclang', unsuffixed_basename(input_file) + '.dwo']
591+
# but we want side-effect files (such as `.dwo` or `-ftime-trace` `.json` files)
592+
# to be generated in the current working directory, like they are under clang.
593+
# We could avoid this hack if we use the clang driver to generate the temporary
594+
# files, but that would also involve using the clang driver to perform linking
595+
# which would be a big change.
596+
# See https://github.com/emscripten-core/emscripten/pull/27866
597+
target = options.output_file or 'a.out.js'
598+
cmd += ['-dumpdir', f'{target}-']
597599
shared.check_call(cmd)
598600
if not shared.SKIP_SUBPROCS:
599601
assert os.path.exists(output_file)

‎test/test_other.py‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10459,27 +10459,27 @@ def test_separate_dwarf(self):
1045910459
def test_split_dwarf_dwp(self):
1046010460
self.run_process([EMCC, test_file('hello_world.c'), '-g', '-gsplit-dwarf'])
1046110461
self.assertExists('a.out.wasm')
10462-
self.assertExists('hello_world.dwo')
10462+
self.assertExists('a.out.js-hello_world.dwo')
1046310463

1046410464
# The wasm will have full debug info for libc (ignore that), but only a
1046510465
# skeleton for hello_world.c (no subprogram for main)
1046610466
dwdump = self.run_process([LLVM_DWARFDUMP, 'a.out.wasm'], stdout=PIPE).stdout
10467-
self.assertIn('DW_AT_GNU_dwo_name\t("hello_world.dwo")', dwdump)
10467+
self.assertIn('DW_AT_GNU_dwo_name\t("a.out.js-hello_world.dwo")', dwdump)
1046810468
self.assertNotIn('DW_AT_name\t("main")', dwdump)
1046910469

1047010470
# The dwo will have a subprogram for main in a section with a .dwo suffix
10471-
dwdump = self.run_process([LLVM_DWARFDUMP, 'hello_world.dwo'],
10471+
dwdump = self.run_process([LLVM_DWARFDUMP, 'a.out.js-hello_world.dwo'],
1047210472
stdout=PIPE).stdout
1047310473
self.assertIn('.debug_info.dwo contents:', dwdump)
10474-
self.assertIn('DW_AT_GNU_dwo_name\t("hello_world.dwo")', dwdump)
10474+
self.assertIn('DW_AT_GNU_dwo_name\t("a.out.js-hello_world.dwo")', dwdump)
1047510475
self.assertIn('DW_AT_name\t("main")', dwdump)
1047610476

1047710477
# Check that dwp runs, and results in usable output as well
1047810478
self.run_process([LLVM_DWP, '-e', 'a.out.wasm', '-o', 'a.out.wasm.dwp'])
1047910479
self.assertExists('a.out.wasm.dwp')
10480-
self.run_process([LLVM_DWARFDUMP, 'a.out.wasm.dwp'], stdout=PIPE)
10480+
dwdump = self.run_process([LLVM_DWARFDUMP, 'a.out.wasm.dwp'], stdout=PIPE).stdout
1048110481
self.assertIn('.debug_info.dwo contents:', dwdump)
10482-
self.assertIn('DW_AT_GNU_dwo_name\t("hello_world.dwo")', dwdump)
10482+
self.assertIn('DW_AT_GNU_dwo_name\t("a.out.js-hello_world.dwo")', dwdump)
1048310483
self.assertIn('DW_AT_name\t("main")', dwdump)
1048410484

1048510485
def test_separate_dwarf_with_filename(self):
@@ -13499,7 +13499,13 @@ def test_split_dwarf_implicit_compile(self):
1349913499
# Verify that the dwo file is generated in the current working directory, even when implicitly
1350013500
# compiling (compile+link).
1350113501
self.run_process([EMCC, test_file('hello_world.c'), '-g', '-gsplit-dwarf'])
13502-
self.assertExists('hello_world.dwo')
13502+
self.assertExists('a.out.js-hello_world.dwo')
13503+
13504+
def test_ftime_trace_implicit_compile(self):
13505+
# Verify that the time-trace json file is generated in the current working directory, even when
13506+
# implicitly compiling (compile+link).
13507+
self.run_process([EMCC, test_file('hello_world.c'), '-ftime-trace'])
13508+
self.assertExists('a.out.js-hello_world.json')
1350313509

1350413510
@parameterized({
1350513511
'': ([],),

0 commit comments

Comments
 (0)