-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[wasm] PInvokeTableGenerator: Fixup symbol names with invalid chars #60814
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
Conversation
Tagging subscribers to 'arch-wasm': @lewing Issue Detailsnull
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use an allow-list instead of a deny list. there's a lot of stuff you can technically put in an IL method name, as far as I can tell from ECMA-335.
public string FileWrites { get; private set; } = string.Empty; | ||
|
||
private static char[] s_charsToReplace = new[] { '.', '-', }; | ||
private static char[] s_charsToReplace = new[] { '.', '-', ',', '|', '<', '>' }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this.
For one thing it's incomplete - for nested classes we also need to replace '/' when it's in a class name. For another thing, C# allows many unicode characters in an identifier (https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/identifier-names). And IL metadata actually doesn't seem to have any restrictions on identifiers - it's just sequences of bytes. I think we should do something like: convert the name to utf8; look at the bytes; for any bytes not in [0-9A-Za-z] replace them by "" or underscore and the byte hex code (ie F☃
will become "F_E2_98_83" https://www.compart.com/en/unicode/U+2603)
private static string SymbolNameForMethod(MethodInfo method) | ||
{ | ||
string module_symbol = method.DeclaringType!.Module!.Assembly!.GetName()!.Name!; | ||
string class_name = method.DeclaringType.Name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check method.DeclaringType.IsNested
and include the enclosing types' names?
string class_name = method.DeclaringType.Name; | ||
string method_name = method.Name; | ||
string entry_name = $"wasm_native_to_interp_{module_symbol}_{class_name}_{method_name}"; | ||
string entry_name = $"wasm_native_to_interp_{SymbolNameForMethod(method)}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're compiling for !aot
, we should check if the method UnmanagedCallersOnlyAttribute
has an EntryPoint
and emit the wasm_native_to_interp
callback with the supplied name.
src/tests/BuildWasmApps/testassets/AppUsingNativeLib/Program.cs
Outdated
Show resolved
Hide resolved
The interpreter runs of the new test are unhappy for some reason.
unclear why |
Draft Pull Request was automatically closed for inactivity. Please let us know if you'd like to reopen it. |
Includes: - Better error logging, and handling - Add @(NativeFileReference) to up-to-date check items for VS - Add `WasmBuild.sln` - Better fix up of symbol names for pinvokes, and callbacks, based on @lambdageek's suggestion in #60814 (comment) Fixes #60862
Fixes #60800