Skip to content

Commit 04bf0e2

Browse files
authored
Improve test_symbol_map (#25060)
- Add expectations files so we can track changes to the generated files - Add a C++ symbol to demonstrate the current strange mangling (#24982)
1 parent f540c49 commit 04bf0e2

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
0:run_js
2+
1:emscripten_asm_const_int
3+
2:__wasm_call_ctors
4+
3:foo::cpp_func\28int\29
5+
4:middle
6+
5:main
7+
6:_emscripten_stack_restore
8+
7:_emscripten_stack_alloc
9+
8:emscripten_stack_get_current
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
0:run_js
2+
1:emscripten_asm_const_int
3+
2:middle
4+
3:main
5+
4:foo::cpp_func\28int\29
6+
5:__wasm_call_ctors

test/test_other.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5690,7 +5690,7 @@ def test_warn_dylibs(self):
56905690
def test_symbol_map(self, opts, wasm):
56915691
def read_symbol_map(symbols_file):
56925692
symbols = read_file(symbols_file)
5693-
lines = [line.split(':') for line in symbols.splitlines()]
5693+
lines = [line.split(':', 1) for line in symbols.splitlines()]
56945694
return lines
56955695

56965696
def get_minified_middle(symbols_file):
@@ -5706,27 +5706,35 @@ def is_js_symbol_map(symbols_file):
57065706
return True
57075707
return False
57085708

5709-
create_file('src.c', r'''
5709+
create_file('src.cpp', r'''
57105710
#include <emscripten.h>
57115711

5712+
namespace foo {
5713+
5714+
EMSCRIPTEN_KEEPALIVE void* cpp_func(int foo) {
5715+
return 0;
5716+
}
5717+
5718+
}
5719+
57125720
EM_JS(int, run_js, (), {
5713-
out(new Error().stack);
5714-
return 0;
5721+
out(new Error().stack);
5722+
return 0;
57155723
});
57165724

57175725
EMSCRIPTEN_KEEPALIVE
5718-
void middle() {
5719-
if (run_js()) {
5720-
// fake recursion that is never reached, to avoid inlining in binaryen and LLVM
5721-
middle();
5722-
}
5726+
extern "C" void middle() {
5727+
if (run_js()) {
5728+
// fake recursion that is never reached, to avoid inlining in binaryen and LLVM
5729+
middle();
5730+
}
57235731
}
57245732

57255733
int main() {
5726-
EM_ASM({ _middle() });
5734+
EM_ASM({ _middle() });
57275735
}
57285736
''')
5729-
cmd = [EMCC, 'src.c', '--emit-symbol-map'] + opts
5737+
cmd = [EMXX, 'src.cpp', '--emit-symbol-map'] + opts
57305738
if wasm != 1:
57315739
cmd.append(f'-sWASM={wasm}')
57325740
self.run_process(cmd)
@@ -5749,6 +5757,10 @@ def is_js_symbol_map(symbols_file):
57495757
self.assertTrue(is_js_symbol_map('a.out.js.symbols'), 'Primary symbols file should store JS mappings')
57505758
elif wasm == 1:
57515759
self.assertFalse(is_js_symbol_map('a.out.js.symbols'), 'Primary symbols file should store Wasm mappings')
5760+
if '-O2' in opts:
5761+
self.assertFileContents(test_file('other/test_symbol_map.O2.symbols'), read_file('a.out.js.symbols'))
5762+
else:
5763+
self.assertFileContents(test_file('other/test_symbol_map.O3.symbols'), read_file('a.out.js.symbols'))
57525764
elif wasm == 2:
57535765
# special case when both JS and Wasm targets are created
57545766
minified_middle_2 = get_minified_middle('a.out.wasm.js.symbols')

0 commit comments

Comments
 (0)