Skip to content

Commit

Permalink
[net8.0-xcode15] [tools] Improve enforcement of the classic linker. (#…
Browse files Browse the repository at this point in the history
…18719)

* Only ask for the classic linker if we're using Xcode 15+.
* Implement a way out of the enforcing the classic linker.
  • Loading branch information
rolfbjarne authored Aug 15, 2023
1 parent 6c7bf85 commit 7988d05
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,10 @@
<ItemGroup>
<_AllLinkerFlags Include="@(_AssemblyLinkerFlags);@(_MainLinkerFlags);@(_CustomLinkFlags)" />
<_AllLinkerFlags Condition="'$(_ExportSymbolsExplicitly)' != 'true'" Include="@(_ReferencesLinkerFlags)" />

<!-- check if needs to be removed: https://github.com/xamarin/xamarin-macios/issues/18693 -->
<_AllLinkerFlags Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(_XcodeVersion)', '15.0')) And '$(_UseClassicLinker)' != 'false'" Include="-Xlinker" />
<_AllLinkerFlags Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(_XcodeVersion)', '15.0')) And '$(_UseClassicLinker)' != 'false'" Include="-ld_classic" />
</ItemGroup>

<LinkNativeCode
Expand Down
3 changes: 0 additions & 3 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/LinkNativeCodeTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ bool ExecuteUnsafe ()

var arguments = new List<string> ();
arguments.Add ("clang++");
// check if needs to be removed: https://github.com/xamarin/xamarin-macios/issues/18556
arguments.Add ("-Xlinker");
arguments.Add ("-ld_classic");

var hasEmbeddedFrameworks = false;

Expand Down
3 changes: 3 additions & 0 deletions tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ public bool IsDefaultMarshalManagedExceptionMode {

public bool SkipMarkingNSObjectsInUserAssemblies { get; set; }

// check if needs to be removed: https://github.com/xamarin/xamarin-macios/issues/18693
public bool DisableAutomaticLinkerSelection { get; set; }

// assembly_build_targets describes what kind of native code each assembly should be compiled into for mobile targets (iOS, tvOS, watchOS).
// An assembly can be compiled into: static object (.o), dynamic library (.dylib) or a framework (.framework).
// In the case of a framework, each framework may contain the native code for multiple assemblies.
Expand Down
16 changes: 8 additions & 8 deletions tools/common/CompilerFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public class CompilerFlags {
public HashSet<string> LinkWithLibraries; // X, added to Inputs
public HashSet<string> ForceLoadLibraries; // -force_load X, added to Inputs
public HashSet<string []> OtherFlags; // X
public List<string> InitialOtherFlags = new List<string> () {
"-Xlinker",
"-ld_classic",
}; // same as OtherFlags, only that they're the first argument(s) to clang (because order matters!). This is a list to preserve order (fifo).
public List<string> InitialOtherFlags; // same as OtherFlags, only that they're the first argument(s) to clang (because order matters!). This is a list to preserve order (fifo).

public HashSet<string> Defines; // -DX
public HashSet<string> UnresolvedSymbols; // -u X
Expand Down Expand Up @@ -109,10 +106,7 @@ public void AddStandardCppLibrary ()
public void AddOtherInitialFlag (string flag)
{
if (InitialOtherFlags is null)
InitialOtherFlags = new List<string> () {
"-Xlinker",
"-ld_classic",
};
InitialOtherFlags = new List<string> ();
InitialOtherFlags.Add (flag);
}

Expand Down Expand Up @@ -245,6 +239,12 @@ public void WriteArguments (IList<string> args)
}
}

// check if needs to be removed: https://github.com/xamarin/xamarin-macios/issues/18693
if (Driver.XcodeVersion.Major >= 15 && !Application.DisableAutomaticLinkerSelection) {
args.Insert (0, "-Xlinker");
args.Insert (1, "-ld_classic");
}

ProcessFrameworksForArguments (args);

if (LinkWithLibraries is not null) {
Expand Down
5 changes: 5 additions & 0 deletions tools/common/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ static bool ParseOptions (Application app, Mono.Options.OptionSet options, strin
app.SkipMarkingNSObjectsInUserAssemblies = ParseBool (v, "--skip-marking-nsobjects-in-user-assemblies");
});

// check if needs to be removed: https://github.com/xamarin/xamarin-macios/issues/18693
options.Add ("disable-automatic-linker-selection:", "Don't force the classic linker (ld64).", v => {
app.DisableAutomaticLinkerSelection = ParseBool (v, "--disable-automatic-linker-selection");
});

// Keep the ResponseFileSource option at the end.
options.Add (new Mono.Options.ResponseFileSource ());

Expand Down
5 changes: 4 additions & 1 deletion tools/mmp/aot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,11 @@ public void Compile (IFileEnumerator files)
aotArgs.Add ("hybrid");
if (needsLipo)
aotArgs.Add ($"outfile={Path.Combine (tempAotDir, "aot", abi.AsArchString (), Path.GetFileName (file) + ".dylib")}");
if (Driver.XcodeVersion.Major >= 15)

// check if needs to be removed: https://github.com/xamarin/xamarin-macios/issues/18693
if (Driver.XcodeVersion.Major >= 15 && !Driver.App.DisableAutomaticLinkerSelection)
aotArgs.Add ("ld-flags=-Xlinker -ld_classic");

cmd.Add ($"--aot={string.Join (",", aotArgs)}");
if (IsModern)
cmd.Add ("--runtime=mobile");
Expand Down
5 changes: 2 additions & 3 deletions tools/mmp/driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,9 @@ static void Compile ()
args.Add (Path.Combine (DeveloperDirectory, "Platforms", "MacOSX.platform", "Developer", "SDKs", "MacOSX" + sysRootSDKVersion + ".sdk"));
}

if (XcodeVersion.Major >= 15) {
// Xcode 15 ships with a new linker, which doesn't work, so request the old one.
// check if needs to be removed: https://github.com/xamarin/xamarin-macios/issues/18693
if (XcodeVersion.Major >= 15 && !App.DisableAutomaticLinkerSelection)
args.Add ("-Wl,-ld_classic");
}

if (App.RequiresPInvokeWrappers) {
var state = BuildTarget.LinkerOptions.MarshalNativeExceptionsState;
Expand Down

1 comment on commit 7988d05

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.