Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 1 | # LLD for Mac builds |
| 2 | |
Nico Weber | 9d31eda | 2023-06-05 17:54:06 | [diff] [blame] | 3 | Like on other platforms, Chromium uses the LLD linker on iOS and macOS. |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 4 | |
| 5 | ## Background |
| 6 | |
Nico Weber | 44f066e | 2022-09-05 02:36:13 | [diff] [blame] | 7 | Chromium uses [LLD](https://lld.llvm.org/) as linker on all platforms. |
| 8 | LLD is faster than other ELF linkers (ELF |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 9 | is the executable file format used on most OSs, including Linux, Android, |
| 10 | Chrome OS, Fuchsia), and it's faster than other COFF linkers (the executable |
| 11 | file format on Windows). |
| 12 | |
Nico Weber | 9d31eda | 2023-06-05 17:54:06 | [diff] [blame] | 13 | LLD is currently twice as fast as ld64, the macOS system linker, at linking |
Nico Weber | 2fe54574 | 2021-07-09 19:44:36 | [diff] [blame] | 14 | Chromium Framework in symbol\_level=0 release builds, despite ld64 being already |
Nico Weber | 9d31eda | 2023-06-05 17:54:06 | [diff] [blame] | 15 | fast. (Before Xcode 14.1, LLD was 6x as fast as ld64.) |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 16 | |
Nico Weber | 588d3d53 | 2021-07-09 11:22:43 | [diff] [blame] | 17 | LLD has advantages unrelated to speed, too: |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 18 | |
Nico Weber | 588d3d53 | 2021-07-09 11:22:43 | [diff] [blame] | 19 | - It's developed in the LLVM repository, and we ship it in our clang package. |
| 20 | We can fix issues upstream and quickly deploy fixed versions, instead of |
| 21 | having to wait for Xcode releases (which is where ld64 ships). |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 22 | |
| 23 | - For the same reason, it has a much simpler LTO setup: Clang and LLD both link |
| 24 | in the same LLVM libraries that are built at the same revision, and compiler |
| 25 | and linker bitcodes are interopable for that reason. With ld64, the LTO code |
| 26 | has to be built as a plugin that's loaded by the linker. |
| 27 | |
| 28 | - LLD/Mach-O supports "LLVM-y" features that the ELF and COFF LLDs support as |
Nico Weber | 413f122 | 2020-12-22 17:58:30 | [diff] [blame] | 29 | well, such as thin archives, colored diagnostics, and response files |
| 30 | (ld64 supports this too as of Xcode 12, but we had to wait many years for it, |
| 31 | and it's currently [too crashy](https://crbug.com/1147968) to be usable). |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 32 | |
Nico Weber | 588d3d53 | 2021-07-09 11:22:43 | [diff] [blame] | 33 | - While LLD for ELF, LLD for COFF, and LLD for MachO are mostly independent |
| 34 | codebases, they all use LLVM libraries. That gives them similar behavior. |
| 35 | Using LLD unifies the build across platforms somewhat. |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 36 | |
Nico Weber | 9710c12 | 2021-10-05 22:50:54 | [diff] [blame] | 37 | For that reason, we moved to LLD for iOS and macOS builds. |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 38 | |
| 39 | Just like the LLD ELF port tries to be commandline-compatible with other ELF |
| 40 | linkers and the LLD COFF port tries to be commandline-compatible with the |
| 41 | Visual Studio linker link.exe, the LLD Mach-O port tries to be |
| 42 | commandline-compatible with ld64. This means LLD accepts different flags on |
| 43 | different platforms. |
| 44 | |
Nico Weber | 44c615f | 2021-01-05 20:22:36 | [diff] [blame] | 45 | ## Current status and known issues |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 46 | |
Nico Weber | 9d31eda | 2023-06-05 17:54:06 | [diff] [blame] | 47 | LLD is used by default in all build configurations. |
| 48 | All tests on all bots are passing, both Intel and Arm. |
| 49 | Most things even work. |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 50 | |
Nico Weber | 588d3d53 | 2021-07-09 11:22:43 | [diff] [blame] | 51 | ## Hacking on LLD |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 52 | |
Johann | 48fbca9 | 2021-07-16 18:29:41 | [diff] [blame] | 53 | If you want to work on LLD, follow [this paragraph](clang.md#Using-a-custom-clang-binary). |
Nico Weber | 22d0d66 | 2020-12-07 23:35:06 | [diff] [blame] | 54 | |
Nico Weber | 44c615f | 2021-01-05 20:22:36 | [diff] [blame] | 55 | ## Creating stand-alone repros for bugs |
| 56 | |
| 57 | For simple cases, LLD's `--reproduce=foo.tar` flag / `LLD_REPRODUCE=foo.tar` |
| 58 | env var is sufficient. |
| 59 | |
| 60 | See "Note to self:" [here](https://bugs.llvm.org/show_bug.cgi?id=48657#c0) for |
Johann | 48fbca9 | 2021-07-16 18:29:41 | [diff] [blame] | 61 | making a repro file that involved the full app and framework bundles. |