Skip to content
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

[net8.0-xcode15] [tools] Improve enforcement of the classic linker. #18719

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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