|
3 | 3 | using System.Collections.Generic;
|
4 | 4 | using System.IO;
|
5 | 5 | using System.Linq;
|
| 6 | +using System.Text; |
6 | 7 | using Java.Interop.Tools.Diagnostics;
|
7 | 8 | using Microsoft.Android.Build.Tasks;
|
8 | 9 | using Microsoft.Build.Framework;
|
@@ -252,7 +253,7 @@ protected void GetAotOptions (NdkTools ndk, AndroidTargetArch arch, int level, s
|
252 | 253 | string GetLdFlags(NdkTools ndk, AndroidTargetArch arch, int level, string toolPrefix)
|
253 | 254 | {
|
254 | 255 | var toolchainPath = toolPrefix.Substring (0, toolPrefix.LastIndexOf (Path.DirectorySeparatorChar));
|
255 |
| - var ldFlags = string.Empty; |
| 256 | + var ldFlags = new StringBuilder (); |
256 | 257 | if (EnableLLVM) {
|
257 | 258 | string androidLibPath = string.Empty;
|
258 | 259 | try {
|
@@ -291,19 +292,31 @@ string GetLdFlags(NdkTools ndk, AndroidTargetArch arch, int level, string toolPr
|
291 | 292 | libs.Add (Path.Combine (androidLibPath, "libc.so"));
|
292 | 293 | libs.Add (Path.Combine (androidLibPath, "libm.so"));
|
293 | 294 |
|
294 |
| - ldFlags = $"\\\"{string.Join ("\\\";\\\"", libs)}\\\""; |
295 |
| - } |
| 295 | + ldFlags.Append ($"\\\"{string.Join ("\\\";\\\"", libs)}\\\""); |
| 296 | + } else { |
| 297 | + if (ldFlags.Length > 0) { |
| 298 | + ldFlags.Append (' '); |
| 299 | + } |
296 | 300 |
|
297 |
| - if (!StripLibraries) { |
298 |
| - return ldFlags; |
| 301 | + // |
| 302 | + // This flag is needed for Mono AOT to work correctly with the LLVM 14 `lld` linker due to the following change: |
| 303 | + // |
| 304 | + // The AArch64 port now supports adrp+ldr and adrp+add optimizations. --no-relax can suppress the optimization. |
| 305 | + // |
| 306 | + // Without the flag, `lld` will modify AOT-generated code in a way that the Mono runtime doesn't support. Until |
| 307 | + // the runtime issue is fixed, we need to pass this flag then. |
| 308 | + // |
| 309 | + ldFlags.Append ("--no-relax"); |
299 | 310 | }
|
300 | 311 |
|
301 |
| - const string StripFlag = "-s"; |
302 |
| - if (ldFlags.Length == 0) { |
303 |
| - return StripFlag; |
| 312 | + if (StripLibraries) { |
| 313 | + if (ldFlags.Length > 0) { |
| 314 | + ldFlags.Append (' '); |
| 315 | + } |
| 316 | + ldFlags.Append ("-s"); |
304 | 317 | }
|
305 | 318 |
|
306 |
| - return $"{ldFlags} {StripFlag}"; |
| 319 | + return ldFlags.ToString (); |
307 | 320 | }
|
308 | 321 |
|
309 | 322 | static string GetNdkToolchainLibraryDir (NdkTools ndk, string binDir, string archDir = null)
|
|
0 commit comments