That’s actually good news!
If there is a Mach-O linker that is able to self host Clang builds on macOS, then this is a really good starting point.
From reading a tiny bit about the history, and the LLVM pages on the design of the various linkers, it seems like there is a difference in opinion with respect to the Atom based design of the Mach-O LLD, and whether or not there was to be an abstract design that supports ELF, PE/COFF and Mach-O. It seems not. One would also assume that LTO and/or -ffunction-sections -fdata-sections would obviate the need for Atoms, and that it may in fact increase the complexity of the linker.
From my cursory examination of the source it seems that lld/lib should perhaps be renamed lld/MachO and become the MachO linker besides the ELF and COFF directproes as the common code is not being used by the ELF and the PE/COFF linkers.
besides the ELF and COFF directories (eyesight and spell checker fail).
I just need to figure out how to build and invoke the Mach-O linker. There is no ‘ld’ in the llvm bin directory as one would be led to believe. I’ll dig into the CMakeLists.txt. I guess lld/lib//Driver/DarwinLdDriver.cpp is the entry point. lld//lib/Driver/CMakeLists.txt however only appears to define a library, versus an executable and there is no top level MachO directory like there is for the other 2 linkers.
$ lld
lld is a generic driver.
Invoke ld.lld (Unix), ld (Mac) or lld-link (Windows) instead.
$ ld.lld --version
LLD 4.0.0
$ lld-link --version
ignoring unknown argument: --version
error: no input files
I read the source. It seems the ‘ld’ symlink for the Mach-O linker is not being created for some reason. The ld.lld and llld-link symlinks are created correctly for the ELF and PE/COFF linkers.
In any case, I have the Mach-O linker invoking now. I will do some testing…
$ ln -s lld ld
$ ./ld
OVERVIEW: LLVM Linker
USAGE: ./ld [options]
BUNDLE EXECUTABLE OPTIONS:
-bundle_loader The executable that will be loading this Mach-O bundle
DYLIB EXECUTABLE OPTIONS:
-compatibility_version
The dylib’s compatibility version
-current_version
The dylib’s current version
-install_name The dylib’s install name
-mark_dead_strippable_dylib
Marks the dylib as having no side effects during initialization
LIBRARY OPTIONS:
-all_load Forces all members of all static libraries to be loaded
-force_load
Forces all members of specified static libraries to be loaded
-F Add directory to framework search path
-L Add directory to library search path
-syslibroot Add path to SDK to all absolute library search paths
MAIN EXECUTABLE OPTIONS:
-export_dynamic Preserves all global symbols in main executables during LTO
-e entry symbol name
-no_pie Do not create Position Independent Executable
-pie Create Position Independent Executable (for ASLR)
-stack_size Specifies the maximum stack size for the main thread in a program. Must be a page-size multiple. (default=8Mb)
OBSOLETE OPTIONS:
-multi_module Unsupported way to build dylibs
-objc_gc_compaction Unsupported ObjC GC option
-objc_gc_only Unsupported ObjC GC option
-objc_gc Unsupported ObjC GC option
-single_module Default for dylibs
OPTIMIZATIONS:
-data_in_code_info Force generation of a data in code load command
-dead_strip Remove unreference code and data
-exported_symbols_list
Restricts which symbols will be exported
-exported_symbol
Restricts which symbols will be exported
-flat_namespace Resolves symbols in any (transitively) linked dynamic libraries. Source libraries are not recorded: dyld will re-search all images at runtime and use the first definition found.
-function_starts Force generation of a function starts load command
-ios_simulator_version_min
Minimum iOS simulator version
-ios_version_min
Minimum iOS version
-keep_private_externs Private extern (hidden) symbols should not be transformed into local symbols
-macosx_version_min
Minimum Mac OS X version
-mllvm Options to pass to LLVM during LTO
-no_data_in_code_info Disable generation of a data in code load command
-no_function_starts Disable generation of a function starts load command
-no_objc_category_merging
Disables the optimisation which merges Objective-C categories on a class in to the class itself.
-no_version_load_command
Disable generation of a version load command
-order_file re-order and move specified symbols to start of their section
-sdk_version SDK version
-source_version
Source version
-twolevel_namespace Resolves symbols in listed libraries only. Source libraries are recorded in the symbol table.
-undefined Determines how undefined symbols are handled.
-unexported_symbols_list
Lists symbols that should not be exported
-unexported_symbol
A symbol which should not be exported
-version_load_command Force generation of a version load command
OPTIONS:
-arch Architecture to link
-demangle Demangles symbol names in errors and warnings
-dependency_info Write binary list of files used during link
-filelist file containing paths to input files
-framework Base name of framework searched for in -F directories
-l Base name of library searched for in -L directories
-o Output file path
-path_exists Used with -test_file_usage to declare a path
-print_atoms Emit output as yaml atoms
-rpath Add path to the runpath search path list for image being created
-sectalign
Alignment for segment/section
-sectcreate
Create section / from contents of
-S Remove debug information (STABS or DWARF) from the output file
-test_file_usage Only files specified by -file_exists are considered to exist. Print which files would be used
-t Print the names of the input files as ld processes them
-upward-l Base name of upward library searched for in -L directories
-upward_framework
Base name of upward framework searched for in -F directories
-upward_library path to upward dylib to link with
-v Print linker information
-Z Do not search standard directories for libraries or frameworks
OUTPUT KIND:
-bundle Create dynamic bundle
-dylib Create dynamic library
-dynamic Create dynamic executable (default)
-execute Create main executable (default)
-preload Create binary for use with embedded systems
-r Create relocatable object file
-static Create static executable