-
Notifications
You must be signed in to change notification settings - Fork 532
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
Make APK and shared library alignment configurable #9046
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,8 @@ sealed class InputFiles | |
[Required] | ||
public string AndroidBinUtilsDirectory { get; set; } | ||
|
||
public int ZipAlignmentPages { get; set; } = AndroidZipAlign.DefaultZipAlignment; | ||
|
||
public override System.Threading.Tasks.Task RunTaskAsync () | ||
{ | ||
return this.WhenAll (GetLinkerConfigs (), RunLinker); | ||
|
@@ -129,7 +131,6 @@ IEnumerable<Config> GetLinkerConfigs () | |
"-soname libxamarin-app.so " + | ||
"-z relro " + | ||
"-z noexecstack " + | ||
"-z max-page-size=4096 " + | ||
"--enable-new-dtags " + | ||
"--build-id " + | ||
"--warn-shared-textrel " + | ||
|
@@ -186,6 +187,14 @@ IEnumerable<Config> GetLinkerConfigs () | |
} | ||
} | ||
|
||
uint maxPageSize = ZipAlignmentPages switch { | ||
4 => 4096, | ||
16 => 16384, | ||
_ => throw new InvalidOperationException ($"Internal error: unsupported zip page alignment value {ZipAlignmentPages}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we'd use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I probably should just move this switch to a method inside |
||
}; | ||
targetLinkerArgs.Add ("-z"); | ||
targetLinkerArgs.Add ($"max-page-size={maxPageSize}"); | ||
|
||
string targetArgs = String.Join (" ", targetLinkerArgs); | ||
yield return new Config { | ||
LinkerPath = ld, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,11 +63,12 @@ public sealed class ApplicationConfig | |
public uint jnienv_registerjninatives_method_token; | ||
public uint jni_remapping_replacement_type_count; | ||
public uint jni_remapping_replacement_method_index_entry_count; | ||
public uint zip_alignment_mask; | ||
public uint mono_components_mask; | ||
public string android_package_name = String.Empty; | ||
} | ||
|
||
const uint ApplicationConfigFieldCount = 26; | ||
const uint ApplicationConfigFieldCount = 27; | ||
|
||
const string ApplicationConfigSymbolName = "application_config"; | ||
const string AppEnvironmentVariablesSymbolName = "app_environment_variables"; | ||
|
@@ -326,12 +327,17 @@ static ApplicationConfig ReadApplicationConfig (EnvironmentFile envFile) | |
ret.jni_remapping_replacement_method_index_entry_count = ConvertFieldToUInt32 ("jni_remapping_replacement_method_index_entry_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]); | ||
break; | ||
|
||
case 24: // mono_components_mask: uint32_t / .word | .long | ||
case 24: // zip_alignment_mask: uint32_t / .word | .long | ||
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}"); | ||
ret.zip_alignment_mask = ConvertFieldToUInt32 ("zip_alignment_mask", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]); | ||
break; | ||
Comment on lines
-329
to
+333
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any benefit to putting new settings at the end? Then it could be slightly more compatible with existing files? (Does it even matter?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't matter. There's no guarantee of compatibility between any releases of XA with regards to this (by design). |
||
|
||
case 25: // mono_components_mask: uint32_t / .word | .long | ||
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}"); | ||
ret.mono_components_mask = ConvertFieldToUInt32 ("mono_components_mask", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]); | ||
break; | ||
|
||
case 25: // android_package_name: string / [pointer type] | ||
case 26: // android_package_name: string / [pointer type] | ||
Assert.IsTrue (expectedPointerTypes.Contains (field [0]), $"Unexpected pointer field type in '{envFile.Path}:{item.LineNumber}': {field [0]}"); | ||
pointers.Add (field [1].Trim ()); | ||
break; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,9 @@ sealed class ApplicationConfig | |
public uint jni_remapping_replacement_type_count; | ||
public uint jni_remapping_replacement_method_index_entry_count; | ||
|
||
// 3, for 4-byte alignment (4k memory pages); 15, for 16-byte alignment (16k memory pages) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are the mask 3 and 15 respecitvely? noth 4 and 16? (silly question). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With alignment to 4k, bits 0 and 1 of the address must be 0 and with 16k, bits 0-3 must be 0. We could use the actual alignment here and then subtract The relevant code is here |
||
public uint zip_alignment_mask; | ||
|
||
[NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)] | ||
public uint mono_components_mask; | ||
public string android_package_name = String.Empty; | ||
|
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 log an error with an error code instead of
throw
?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 treat this condition as an internal error, because the property that specifies the alignment is "private" and shouldn't be modified by our users (it's mostly for our convenience of testing) and so I want the invalid value to be signaled in as loud and annoying kind of way :)