Skip to content

Fix EM_ASM with addresses over 2gb #19982

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

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ jobs:
wasm64
wasm64_4gb.test_hello_world
wasm64_4gb.test_em_asm
core_2gb.test_em_asm
wasm64l.test_bigswitch
other.test_memory64_proxies
other.test_failing_growth_wasm64"
Expand Down
1 change: 1 addition & 0 deletions test/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'core3',
'cores',
'corez',
'core_2gb',
'strict',
'wasm2js0',
'wasm2js1',
Expand Down
4 changes: 4 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9789,6 +9789,10 @@ def setUp(self):
cores = make_run('cores', emcc_args=['-Os'])
corez = make_run('corez', emcc_args=['-Oz'])

# Test >2gb memory addresses
core_2gb = make_run('core_2gb', emcc_args=['--profiling-funcs'],
settings={'INITIAL_MEMORY': '2200mb', 'GLOBAL_BASE': '2gb'})

# MEMORY64=1
wasm64 = make_run('wasm64', emcc_args=['-O1', '-Wno-experimental', '--profiling-funcs'],
settings={'MEMORY64': 1}, require_wasm64=True, require_node=True)
Expand Down
13 changes: 10 additions & 3 deletions tools/extract_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,19 @@ def get_passive_segment_offsets(module):
return offset_map


def to_unsigned(val):
if val < 0:
return val & ((2 ** 32) - 1)
else:
return val


def find_segment_with_address(module, address):
segments = module.get_segments()
active = [s for s in segments if s.init]

for seg in active:
offset = get_const_expr_value(seg.init)
offset = to_unsigned(get_const_expr_value(seg.init))
if offset is None:
continue
if address >= offset and address < offset + seg.size:
Expand Down Expand Up @@ -194,8 +201,8 @@ def get_section_strings(module, export_map, section_name):
end = export_map[stop_name]
start_global = module.get_global(start.index)
end_global = module.get_global(end.index)
start_addr = get_global_value(start_global)
end_addr = get_global_value(end_global)
start_addr = to_unsigned(get_global_value(start_global))
end_addr = to_unsigned(get_global_value(end_global))

seg = find_segment_with_address(module, start_addr)
if not seg:
Expand Down
4 changes: 3 additions & 1 deletion tools/webassembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ def read_init(self):
while 1:
opcode = OpCode(self.read_byte())
args = []
if opcode in (OpCode.GLOBAL_GET, OpCode.I32_CONST, OpCode.I64_CONST):
if opcode == OpCode.GLOBAL_GET:
args.append(self.read_uleb())
elif opcode in (OpCode.I32_CONST, OpCode.I64_CONST):
args.append(self.read_sleb())
elif opcode in (OpCode.REF_NULL,):
args.append(self.read_type())
elif opcode in (OpCode.END, OpCode.I32_ADD, OpCode.I64_ADD):
Expand Down