Skip to content

eliminate dependency on LLD for Mach-O #8727

Closed
@andrewrk

Description

@andrewrk

This is a sub-task of #8726.

LLD on Mach-O is fatally flawed for a few reasons. One example is #3295.

However Zig still falls back to LLD for Mach-O in a handful of cases. Here is the current logic:

zig/src/Compilation.zig

Lines 714 to 751 in 2d11967

// Make a decision on whether to use LLD or our own linker.
const use_lld = if (options.use_lld) |explicit| explicit else blk: {
if (!build_options.have_llvm)
break :blk false;
if (ofmt == .c)
break :blk false;
if (options.want_lto) |lto| {
if (lto) {
break :blk true;
}
}
// Our linker can't handle objects or most advanced options yet.
if (options.link_objects.len != 0 or
options.c_source_files.len != 0 or
options.frameworks.len != 0 or
options.system_libs.len != 0 or
options.link_libc or options.link_libcpp or
options.link_eh_frame_hdr or
options.link_emit_relocs or
options.output_mode == .Lib or
options.lld_argv.len != 0 or
options.image_base_override != null or
options.linker_script != null or options.version_script != null)
{
break :blk true;
}
if (use_llvm) {
// If stage1 generates an object file, self-hosted linker is not
// yet sophisticated enough to handle that.
break :blk options.root_pkg != null;
}
break :blk false;
};

zig/src/link/MachO.zig

Lines 637 to 656 in 2d11967

const use_zld = blk: {
if (self.base.options.is_native_os and self.base.options.system_linker_hack) {
// If the user forces the use of ld64, make sure we are running native!
break :blk false;
}
if (self.base.options.target.cpu.arch == .aarch64) {
// On aarch64, always use zld.
break :blk true;
}
if (self.base.options.output_mode == .Lib or
self.base.options.linker_script != null)
{
// Fallback to LLD in this handful of cases on x86_64 only.
break :blk false;
}
break :blk true;
};

This issue is to improve self-hosted linking on Mach-O enough that for Mach-O targets, we always use self-hosted linking, and we can remove this line from cmake:

FIND_AND_ADD_LLD_LIB(lldMachO)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.linkingos-macos

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions