How can I pass options to the linker?

The clang compiler driver controls all compiler, assembler, and linker calls during the process of generating an executable. Although it understands and forwards most of the common linker options, some need to be passed directly to the linker. There are two ways of passing options directly to the linker:

-Wl,<options>

<options> are passed from clang directly to the linker. Multiple options are to be separated by commas.

Example

clang test.c -Wl,-Map,--gc-sections
-Xlinker <option1> -Xlinker <option2>

<options> are passed from clang directly to the linker. The -Xlinker prefix must be used for each option separately.

Example

clang test.c -Xlinker -Map -Xlinker --gc-sections