Skip to content

Commit dee7d9a

Browse files
authored
Fix EM_ASM with addresses over 2gb (#19982)
1 parent 2d72c4d commit dee7d9a

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ jobs:
618618
wasm64
619619
wasm64_4gb.test_hello_world
620620
wasm64_4gb.test_em_asm
621+
core_2gb.test_em_asm
621622
wasm64l.test_bigswitch
622623
other.test_memory64_proxies
623624
other.test_failing_growth_wasm64"

test/runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'core3',
5757
'cores',
5858
'corez',
59+
'core_2gb',
5960
'strict',
6061
'wasm2js0',
6162
'wasm2js1',

test/test_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9789,6 +9789,10 @@ def setUp(self):
97899789
cores = make_run('cores', emcc_args=['-Os'])
97909790
corez = make_run('corez', emcc_args=['-Oz'])
97919791

9792+
# Test >2gb memory addresses
9793+
core_2gb = make_run('core_2gb', emcc_args=['--profiling-funcs'],
9794+
settings={'INITIAL_MEMORY': '2200mb', 'GLOBAL_BASE': '2gb'})
9795+
97929796
# MEMORY64=1
97939797
wasm64 = make_run('wasm64', emcc_args=['-O1', '-Wno-experimental', '--profiling-funcs'],
97949798
settings={'MEMORY64': 1}, require_wasm64=True, require_node=True)

tools/extract_metadata.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,19 @@ def get_passive_segment_offsets(module):
149149
return offset_map
150150

151151

152+
def to_unsigned(val):
153+
if val < 0:
154+
return val & ((2 ** 32) - 1)
155+
else:
156+
return val
157+
158+
152159
def find_segment_with_address(module, address):
153160
segments = module.get_segments()
154161
active = [s for s in segments if s.init]
155162

156163
for seg in active:
157-
offset = get_const_expr_value(seg.init)
164+
offset = to_unsigned(get_const_expr_value(seg.init))
158165
if offset is None:
159166
continue
160167
if address >= offset and address < offset + seg.size:
@@ -194,8 +201,8 @@ def get_section_strings(module, export_map, section_name):
194201
end = export_map[stop_name]
195202
start_global = module.get_global(start.index)
196203
end_global = module.get_global(end.index)
197-
start_addr = get_global_value(start_global)
198-
end_addr = get_global_value(end_global)
204+
start_addr = to_unsigned(get_global_value(start_global))
205+
end_addr = to_unsigned(get_global_value(end_global))
199206

200207
seg = find_segment_with_address(module, start_addr)
201208
if not seg:

tools/webassembly.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ def read_init(self):
236236
while 1:
237237
opcode = OpCode(self.read_byte())
238238
args = []
239-
if opcode in (OpCode.GLOBAL_GET, OpCode.I32_CONST, OpCode.I64_CONST):
239+
if opcode == OpCode.GLOBAL_GET:
240240
args.append(self.read_uleb())
241+
elif opcode in (OpCode.I32_CONST, OpCode.I64_CONST):
242+
args.append(self.read_sleb())
241243
elif opcode in (OpCode.REF_NULL,):
242244
args.append(self.read_type())
243245
elif opcode in (OpCode.END, OpCode.I32_ADD, OpCode.I64_ADD):

0 commit comments

Comments
 (0)