xref: /freebsd/contrib/llvm-project/lld/docs/MachO/index.rst (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1*bdd1243dSDimitry AndricMach-O LLD Port
2*bdd1243dSDimitry Andric===============
3*bdd1243dSDimitry Andric
4*bdd1243dSDimitry AndricLLD is a linker from the LLVM project that is a drop-in replacement
5*bdd1243dSDimitry Andricfor system linkers and runs much faster than them. It also provides
6*bdd1243dSDimitry Andricfeatures that are useful for toolchain developers. This document
7*bdd1243dSDimitry Andricwill describe the Mach-O port.
8*bdd1243dSDimitry Andric
9*bdd1243dSDimitry AndricFeatures
10*bdd1243dSDimitry Andric--------
11*bdd1243dSDimitry Andric
12*bdd1243dSDimitry Andric- LLD is a drop-in replacement for Apple's Mach-O linker, ld64, that accepts the
13*bdd1243dSDimitry Andric  same command line arguments.
14*bdd1243dSDimitry Andric
15*bdd1243dSDimitry Andric- LLD is very fast. When you link a large program on a multicore
16*bdd1243dSDimitry Andric  machine, you can expect that LLD runs more than twice as fast as the ld64
17*bdd1243dSDimitry Andric  linker.
18*bdd1243dSDimitry Andric
19*bdd1243dSDimitry AndricDownload
20*bdd1243dSDimitry Andric--------
21*bdd1243dSDimitry Andric
22*bdd1243dSDimitry AndricLLD is available as a pre-built binary by going to the `latest release <https://github.com/llvm/llvm-project/releases>`_,
23*bdd1243dSDimitry Andricdownloading the appropriate bundle (``clang+llvm-<version>-<your architecture>-<your platform>.tar.xz``),
24*bdd1243dSDimitry Andricdecompressing it, and locating the binary at ``bin/ld64.lld``. Note
25*bdd1243dSDimitry Andricthat if ``ld64.lld`` is moved out of ``bin``, it must still be accompanied
26*bdd1243dSDimitry Andricby its sibling file ``lld``, as ``ld64.lld`` is technically a symlink to ``lld``.
27*bdd1243dSDimitry Andric
28*bdd1243dSDimitry AndricBuild
29*bdd1243dSDimitry Andric-----
30*bdd1243dSDimitry Andric
31*bdd1243dSDimitry AndricThe easiest way to build LLD is to
32*bdd1243dSDimitry Andriccheck out the entire LLVM projects/sub-projects from a git mirror and
33*bdd1243dSDimitry Andricbuild that tree. You need ``cmake`` and of course a C++ compiler.
34*bdd1243dSDimitry Andric
35*bdd1243dSDimitry Andric.. code-block:: console
36*bdd1243dSDimitry Andric
37*bdd1243dSDimitry Andric  $ git clone https://github.com/llvm/llvm-project llvm-project
38*bdd1243dSDimitry Andric  $ mkdir build
39*bdd1243dSDimitry Andric  $ cd build
40*bdd1243dSDimitry Andric  $ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS='lld' ../llvm-project/llvm
41*bdd1243dSDimitry Andric  $ ninja check-lld-macho
42*bdd1243dSDimitry Andric
43*bdd1243dSDimitry AndricThen you can find output binary at ``build/bin/ld64.lld``. Note
44*bdd1243dSDimitry Andricthat if ``ld64.lld`` is moved out of ``bin``, it must still be accompanied
45*bdd1243dSDimitry Andricby its sibling file ``lld``, as ``ld64.lld`` is technically a symlink to ``lld``.
46*bdd1243dSDimitry Andric
47*bdd1243dSDimitry AndricUsing LLD
48*bdd1243dSDimitry Andric---------
49*bdd1243dSDimitry Andric
50*bdd1243dSDimitry AndricLLD can be used by adding ``-fuse-ld=/path/to/ld64.lld`` to the linker flags.
51*bdd1243dSDimitry AndricFor Xcode, this can be done by adding it to "Other linker flags" in the build
52*bdd1243dSDimitry Andricsettings. For Bazel, this can be done with ``--linkopt`` or with
53*bdd1243dSDimitry Andric`rules_apple_linker <https://github.com/keith/rules_apple_linker>`_.
54*bdd1243dSDimitry Andric
55*bdd1243dSDimitry Andric.. seealso::
56*bdd1243dSDimitry Andric
57*bdd1243dSDimitry Andric  :doc:`ld64-vs-lld` has more info on the differences between the two linkers.
58*bdd1243dSDimitry Andric
59*bdd1243dSDimitry Andric.. toctree::
60*bdd1243dSDimitry Andric   :hidden:
61*bdd1243dSDimitry Andric
62*bdd1243dSDimitry Andric   ld64-vs-lld
63