Skip to content

Commit ffed1d3

Browse files
authored
Look for orig$ functions from side modules too (#9906)
Fixes #9901
1 parent 5b2fc36 commit ffed1d3

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

emscripten.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,10 +1823,11 @@ def create_fp_accessors(metadata):
18231823
accessors.append('''
18241824
Module['%(full)s'] = function() {
18251825
%(assert)s
1826-
// Use the wasm function itself, for the table.
1826+
// Use the original wasm function itself, for the table, from the main module.
18271827
var func = Module['asm']['%(original)s'];
1828-
// If there is no wasm function, this may be a JS library function or
1829-
// something from another module.
1828+
// Try an original version from a side module.
1829+
if (!func) func = Module['_%(original)s'];
1830+
// Otherwise, look for a regular function or JS library function.
18301831
if (!func) func = Module['%(mangled)s'];
18311832
if (!func) func = %(mangled)s;
18321833
var fp = addFunction(func, '%(sig)s');

tests/test_core.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3996,6 +3996,57 @@ def test_dylink_i64_b(self):
39963996
}
39973997
''', 'other says -1311768467750121224.\nmy fp says: 43.\nmy second fp says: 43.')
39983998

3999+
@needs_dlfcn
4000+
def test_dylink_i64_c(self):
4001+
self.dylink_test(r'''
4002+
#include <cstdio>
4003+
#include <cinttypes>
4004+
#include "header.h"
4005+
4006+
typedef int32_t (*fp_type_32)(int32_t, int32_t, int32_t);
4007+
typedef int64_t (*fp_type_64)(int32_t, int32_t, int32_t);
4008+
4009+
int32_t internal_function_ret_32(int32_t i, int32_t j, int32_t k) {
4010+
return 32;
4011+
}
4012+
int64_t internal_function_ret_64(int32_t i, int32_t j, int32_t k) {
4013+
return 64;
4014+
}
4015+
4016+
int main() {
4017+
fp_type_32 fp32_internal = &internal_function_ret_32;
4018+
fp_type_32 fp32_external = &function_ret_32;
4019+
fp_type_64 fp64_external = &function_ret_64;
4020+
fp_type_64 fp64_internal = &internal_function_ret_64;
4021+
int32_t ires32 = fp32_internal(0,0,0);
4022+
printf("res32 - internal %d\n",ires32);
4023+
int32_t eres32 = fp32_external(0,0,0);
4024+
printf("res32 - external %d\n",eres32);
4025+
4026+
int64_t ires64 = fp64_internal(0,0,0);
4027+
printf("res64 - internal %" PRId64 "\n",ires64);
4028+
int64_t eres64 = fp64_external(0,0,0);
4029+
printf("res64 - external %" PRId64 "\n",eres64);
4030+
return 0;
4031+
}
4032+
''', '''
4033+
#include "header.h"
4034+
int32_t function_ret_32(int32_t i, int32_t j, int32_t k) {
4035+
return 32;
4036+
}
4037+
int64_t function_ret_64(int32_t i, int32_t j, int32_t k) {
4038+
return 64;
4039+
}
4040+
''', '''res32 - internal 32
4041+
res32 - external 32
4042+
res64 - internal 64
4043+
res64 - external 64\n''', header='''
4044+
#include <emscripten.h>
4045+
#include <cstdint>
4046+
EMSCRIPTEN_KEEPALIVE int32_t function_ret_32(int32_t i, int32_t j, int32_t k);
4047+
EMSCRIPTEN_KEEPALIVE int64_t function_ret_64(int32_t i, int32_t j, int32_t k);
4048+
''')
4049+
39994050
@needs_dlfcn
40004051
def test_dylink_class(self):
40014052
self.dylink_test(header=r'''

0 commit comments

Comments
 (0)