Driver¶
Note: this document discuss Mach-O port of LLD. For ELF and COFF, see LLD - The LLVM Linker.
Introduction¶
This document describes the lld driver. The purpose of this document is to describe both the motivation and design goals for the driver, as well as details of the internal implementation.
Overview¶
The lld driver is designed to support a number of different command line interfaces. The main interfaces we plan to support are binutils’ ld, Apple’s ld, and Microsoft’s link.exe.
Flavors¶
Each of these different interfaces is referred to as a flavor. There is also an extra flavor “core” which is used to exercise the core functionality of the linker it the test suite.
- gnu
 - darwin
 - link
 - core
 
Selecting a Flavor¶
There are two different ways to tell lld which flavor to be. They are checked in
order, so the second overrides the first. The first is to symlink lld
as lld-{flavor} or just {flavor}. You can also specify
it as the first command line argument using -flavor:
$ lld -flavor gnu
There is a shortcut for -flavor core as -core.
Adding an Option to an existing Flavor¶
- Add the option to the desired 
lib/Driver/flavorOptions.td. - Add to 
lld::FlavorLinkingContexta getter and setter method for the option. - Modify 
lld::FlavorDriver::parse()in :file: lib/Driver/{Flavor}Driver.cpp to call the targetInfo setter for corresponding to the option. - Modify {Flavor}Reader and {Flavor}Writer to use the new targtInfo option.
 
Adding a Flavor¶
- Add an entry for the flavor in 
include/lld/Common/Driver.htolld::UniversalDriver::Flavor. - Add an entry in 
lib/Driver/UniversalDriver.cpptolld::Driver::strToFlavor()andlld::UniversalDriver::link(). This allows the flavor to be selected via symlink and -flavor. - Add a tablegen file called 
lib/Driver/flavorOptions.tdthat describes the options. If the options are a superset of another driver, that driver’s td file can simply be included. TheflavorOptions.tdfile must also be added tolib/Driver/CMakeLists.txt. - Add a 
{flavor}Driveras a subclass oflld::Driverinlib/Driver/flavorDriver.cpp. 
