Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

eliminate dependency on LLD for Mach-O #8727

Closed
Tracked by #16270 ...
andrewrk opened this issue May 9, 2021 · 0 comments · Fixed by #9266
Closed
Tracked by #16270 ...

eliminate dependency on LLD for Mach-O #8727

andrewrk opened this issue May 9, 2021 · 0 comments · Fixed by #9266
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. linking os-macos
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented May 9, 2021

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)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. linking os-macos
Projects
None yet
1 participant