xref: /freebsd/contrib/llvm-project/lld/docs/MachO/ld64-vs-lld.rst (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1=================
2ld64 vs LLD-MachO
3=================
4
5This doc lists all significant deliberate differences in behavior between ld64
6and LLD-MachO.
7
8Dead Stripping Duplicate Symbols
9********************************
10ld64 strips dead code before reporting duplicate symbols. By default, LLD does
11the opposite. ld64's behavior hides ODR violations, so we have chosen not
12to follow it. But, to make adoption easy, LLD can mimic this behavior via
13the ``--dead-strip-duplicates`` flag. Usage of this flag is discouraged, and
14this behavior should be fixed in the source. However, for sources that are not
15within the user's control, this will mitigate users for adoption.
16
17``-no_deduplicate`` Flag
18************************
19- ld64: This turns off ICF (deduplication pass) in the linker.
20- LLD: This turns off ICF and string merging in the linker.
21
22String Alignment
23****************
24LLD is `slightly less conservative about aligning cstrings
25<https://reviews.llvm.org/D121342>`_, allowing it to pack them more compactly.
26This should not result in any meaningful semantic difference.
27
28ObjC Symbols Treatment
29**********************
30There are differences in how LLD and ld64 handle ObjC symbols loaded from
31archives.
32
33- ld64:
34   1. Duplicate ObjC symbols from the same archives will not raise an error.
35      ld64 will pick the first one.
36   2. Duplicate ObjC symbols from different archives will raise a "duplicate
37      symbol" error.
38- LLD: Duplicate symbols, regardless of which archives they are from, will
39  raise errors.
40
41Aliases
42=======
43ld64 treats all aliases as strong extern definitions. Having two aliases of the
44same name, or an alias plus a regular extern symbol of the same name, both
45result in duplicate symbol errors. LLD does not check for duplicate aliases;
46instead we perform alias resolution first, and only then do we check for
47duplicate symbols. In particular, we will not report a duplicate symbol error if
48the aliased symbols turn out to be weak definitions, but ld64 will.
49
50``ZERO_AR_DATE`` enabled by default
51***********************************
52ld64 has a special mode where it sets some stabs modification times to 0 for
53hermetic builds, enabled by setting any value for the ``ZERO_AR_DATE``
54environment variable. LLD flips this default to prefer hermetic builds, but
55allows disabling this behavior by setting ``ZERO_AR_DATE=0``. Any other value
56of ``ZERO_AR_DATE`` will be ignored.
57