Skip to content

[MONO][Wasm] Potential function signature mismatch in m2n invoke #99514

@Nemo-G

Description

@Nemo-G

Description

When collecting PInvoke in managed code and generate native m2n function, the function naming is following rules like

string FixupSymbolName(string name)

Regarding special chars, there is a table
private static readonly char[] s_charsToReplace = new[] { '.', '-', '+', '<', '>' };

With the above logic, the generated function map would only have underscore representing all special chars.
image

However in interpreter logic, either .Net9

if (key [i] == '.')

or .Net8
if (key [i] == '.')

The function name resolving logic cannot cover all cases when generating them as only '.' is replaced. There should be logic which resembles the C# FixupSymbolName. Otherwise we may resolve pinvoke function name from Assemly-CSharp-firstpass.dll to
image

Also the function length currently 128 seems not sufficient. I have doubled it to 256. Any consideration here regarding the 128 length?

Reproduction Steps

Having C# functions marked with PInvoke in assembly with - in its name (or other special chars)

Expected behavior

Resolve those chars as understore

Actual behavior

Failed to find those functions in wasm_native_to_interp_map (calling wasm_dl_get_native_to_interp )

Regression?

Yes

Known Workarounds

Implement FixupSymbolName logic in naive code when calling get_native_to_interp so as to keep align with the way it is generated(Module name in particular). And increase the key size limit to 256 for some super long generated functions.

Configuration

.Net8
.Net9

Other information

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions