Skip to content

Conversation

mkhamoyan
Copy link
Contributor

@mkhamoyan mkhamoyan commented Apr 16, 2024

While working on this PR found #101434 and #101476.
Once it will be fixed test cases will be updated accordingly.

Fixes #99514

@mkhamoyan mkhamoyan added the arch-wasm WebAssembly architecture label Apr 16, 2024
@mkhamoyan mkhamoyan self-assigned this Apr 16, 2024
@ghost ghost added the area-Build-mono label Apr 16, 2024
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

@mkhamoyan mkhamoyan marked this pull request as ready for review April 17, 2024 15:34
@mkhamoyan mkhamoyan requested a review from fanyang-mono as a code owner April 22, 2024 16:54
@mkhamoyan mkhamoyan requested a review from thaystg as a code owner April 23, 2024 10:27
@mkhamoyan
Copy link
Contributor Author

Failures are not related.

// Append the hexadecimal representation of b between underscores
sprintf(&fixedName[sb_index], "_%X_", b);
sb_index += 4; // Move the index after the appended hexadecimal characters
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to add a check that sb_index is < 252 (to account for the possible 4 hex bytes + 1 null terminate) in the loop so we don't write past the fixedName boundary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and ideally use snprintf to make it clear the code is doing this


// Null-terminate the fixedName string
fixedName[sb_index] = '\0';
return fixedName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of the call sites need to free this or we're leaking the memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks , will create a PR for these changes.

#ifdef TARGET_WASM
acfg->static_linking_symbol = g_strdup (mono_fixup_symbol_name(symbol));
#else
/* Get rid of characters which cannot occur in symbols */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this needs to be wasm-specific, shouldn't we do the same logic everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It broke iOS/tvOS tests that's why I applied the logic only for wasm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm that sounds concerning, I don't see why it should break iOS/tvOS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what error looked like (from https://dev.azure.com/dnceng-public/public/_build/results?buildId=652242&view=logs&j=88e1dda0-08c6-5d85-6ee4-8e42aeff31b6&t=b4bb5080-7a46-5114-c100-ade75b904ada)
ios_error

My guess is that for iOS/tvOS in other places it still expects the previous logic. And I'm not sure that for other platforms there is a need to apply the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we need to find these places, the logic should be consistent

}
else
{
sb.Append($"_{b:X}_");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of the exact constraints for this name mapping algorithm but could we just replace all chars outside of a-z/0-9 with underscore? that would allow us to not allocate in the native side

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed when mapping two assemblies to the same name.
For example having an app project that references a library project named in a way that maps to the same name, but is different before fixup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so e.g. HelloÖProject.DoSomething() and HelloÜProject.DoSomething() would both map to Hello_Project_DoSomething, makes sense.

Copy link
Member

@akoeplinger akoeplinger Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure whether it'd be strictly better but we could also collect the special chars and append them at the end or return them separately. that'd have the benefit of not needing to allocate on the native side when the string doesn't have special chars

@lambdageek for thoughts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how adding the characters in a suffix would make a difference.

On the native side I guess it would be nice to have a function that precomputes the required space for the entire mangled name and just does a single allocation. (ie: get rid of the g_strdup_printf with the prefix and the name together with the mangling loop - and just make a helper that that does a single allocation for the final mangled name)

matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Build-mono
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MONO][Wasm] Potential function signature mismatch in m2n invoke
8 participants