Skip to content

Commit 75b6166

Browse files
authored
Fix #24982: emsymbolizer failed to parse symbol map from C++ project (#24994)
1. fix symbol map line parse 2. update tests: test/runner "other.test_emsymbolizer*" This PR fixes #24982
1 parent 0afa0bd commit 75b6166

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

test/test_other.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11021,6 +11021,57 @@ def check_symbolmap_info(address, func):
1102111021
# The name section will not show bar, as it's inlined into main
1102211022
check_symbolmap_info(unreachable_addr, '__original_main')
1102311023

11024+
def test_emsymbolizer_symbol_map_names(self):
11025+
"""Test emsymbolizer with symbol map which contains demangled C++ names"""
11026+
create_file('test_symbol_map.cpp', r'''
11027+
#include <emscripten.h>
11028+
EM_JS(int, out_to_js, (), { return 0; });
11029+
11030+
namespace Namespace {
11031+
class ClassA{};
11032+
class ClassB{};
11033+
11034+
void __attribute__((noinline)) foo(ClassA v) { out_to_js(); }
11035+
11036+
template <typename T>
11037+
void __attribute__((noinline)) bar(ClassB t) { __builtin_trap(); }
11038+
};
11039+
11040+
int main() {
11041+
// call function to avoid Dead-code elimination
11042+
Namespace::foo({});
11043+
// instantiate template function
11044+
Namespace::bar<Namespace::ClassA>(Namespace::ClassB{});
11045+
return 0;
11046+
}
11047+
''')
11048+
self.run_process([EMXX, 'test_symbol_map.cpp',
11049+
'-O1', '--emit-symbol-map', '-o', 'test_symbol_map.js'])
11050+
self.assertExists('test_symbol_map.js.symbols')
11051+
11052+
out_to_js_call_addr = self.get_instr_addr('call\t0', 'test_symbol_map.wasm')
11053+
unreachable_addr = self.get_instr_addr('unreachable', 'test_symbol_map.wasm')
11054+
11055+
def check_cpp_symbolmap_info(address, func):
11056+
out = self.run_process([emsymbolizer, '--source=symbolmap', '-f', 'test_symbol_map.js.symbols', 'test_symbol_map.wasm', address], stdout=PIPE).stdout
11057+
self.assertIn(func, out)
11058+
11059+
def check_symbol_map_contains(func):
11060+
out = read_file('test_symbol_map.js.symbols')
11061+
self.assertIn(func, out)
11062+
11063+
# function name: "Namespace::foo(Namespace::ClassA)"
11064+
check_cpp_symbolmap_info(out_to_js_call_addr, 'Namespace::foo')
11065+
check_cpp_symbolmap_info(out_to_js_call_addr, 'Namespace::ClassA')
11066+
11067+
# function name: "void Namespace::bar<Namespace::ClassA>(Namespace::ClassB)"
11068+
check_cpp_symbolmap_info(unreachable_addr, 'Namespace::bar')
11069+
check_cpp_symbolmap_info(unreachable_addr, 'Namespace::ClassA')
11070+
check_cpp_symbolmap_info(unreachable_addr, 'Namespace::ClassB')
11071+
11072+
# JS imports
11073+
check_symbol_map_contains('out_to_js')
11074+
1102411075
def test_separate_dwarf(self):
1102511076
self.run_process([EMCC, test_file('hello_world.c'), '-g'])
1102611077
self.assertExists('a.out.wasm')

tools/emsymbolizer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,14 @@ def symbolize_address_symbolmap(module, address, symbol_map_file):
230230
"""Symbolize using a symbol map file."""
231231
func_names = {}
232232

233+
def split_symbolmap_line(line):
234+
assert ':' in line, f'invalid symbolmap line: {line}'
235+
return line.split(':', 1)
236+
233237
with open(symbol_map_file) as f:
234238
lines = f.read().splitlines()
235239
for line in lines:
236-
index, name = line.split(':')
240+
index, name = split_symbolmap_line(line)
237241
func_names[int(index)] = name
238242

239243
func_index = -1

0 commit comments

Comments
 (0)