Skip to content

Commit

Permalink
Fix unmangling of satellite assembly names
Browse files Browse the repository at this point in the history
Fixes: #9532
Context: 86260ed

All the assemblies are wrapped in a valid ELF shared library image and
placed in the `lib/{ABI}` directories inside the APK/AAB archive.  Since
those directories don't support subdirectories, we need to encode
satellite assembly culture in a way that doesn't use the `/` directory
separator char.  This encoding, as originally implemented, unfortunately
used the `-` character which made it ambiguous with culture names that
consist of two parts (e.g. `de-DE`), since the unmangling process would
look for the first occurrence of `-` to replace it with `/`, which would
form invalid assembly names such as `de/DE-MyAssembly.resources.dll`
instead of the correct `de-DE/MyAssembly.resources.dll`.  This would,
eventually, lead to a mismatch when looking for satellite assembly for
that specific culture.

Fix it by changing the `-` character to `_` so that mangled assembly
name looks like `lib_de-DE_MyAssembly.resources.dll.so` and we can
unambiguously decode it to the correct `de-DE/MyAssembly.resources.dll`
name.
  • Loading branch information
grendello committed Nov 21, 2024
1 parent 6b57cc2 commit 0d00539
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static string MakeZipArchivePath (string part1, ICollection<string>? path
public static string MakeDiscreteAssembliesEntryName (string name, string? culture = null)
{
if (!String.IsNullOrEmpty (culture)) {
return $"{MANGLED_ASSEMBLY_SATELLITE_ASSEMBLY_MARKER}{culture}-{name}{MANGLED_ASSEMBLY_NAME_EXT}";
return $"{MANGLED_ASSEMBLY_SATELLITE_ASSEMBLY_MARKER}{culture}_{name}{MANGLED_ASSEMBLY_NAME_EXT}";
}

return $"{MANGLED_ASSEMBLY_REGULAR_ASSEMBLY_MARKER}{name}{MANGLED_ASSEMBLY_NAME_EXT}";
Expand Down
2 changes: 1 addition & 1 deletion src/native/monodroid/embedded-assemblies.hh
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ namespace xamarin::android::internal {
if constexpr (IsSatelliteAssembly) {
// Make sure assembly name is {CULTURE}/assembly.dll
for (size_t idx = start_idx; idx < name.length (); idx++) {
if (name[idx] == SharedConstants::SATELLITE_ASSEMBLY_MARKER_CHAR) {
if (name[idx] == SharedConstants::SATELLITE_CULTURE_END_MARKER_CHAR) {
name[idx] = '/';
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/native/runtime-base/shared-constants.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace xamarin::android::internal
static constexpr std::string_view MANGLED_ASSEMBLY_SATELLITE_ASSEMBLY_MARKER { "lib-" };
static constexpr size_t SATELLITE_ASSEMBLY_MARKER_INDEX = 3uz; // this ☝️
static constexpr char SATELLITE_ASSEMBLY_MARKER_CHAR = MANGLED_ASSEMBLY_SATELLITE_ASSEMBLY_MARKER[SATELLITE_ASSEMBLY_MARKER_INDEX];
static constexpr char SATELLITE_CULTURE_END_MARKER_CHAR = '_';

static constexpr std::string_view MONO_ANDROID_RUNTIME_ASSEMBLY_NAME { "Mono.Android.Runtime" };
static constexpr std::string_view MONO_ANDROID_ASSEMBLY_NAME { "Mono.Android" };
Expand Down

0 comments on commit 0d00539

Please sign in to comment.