1*12c85518Srobert====================
2*12c85518SrobertClang Linker Wrapper
3*12c85518Srobert====================
4*12c85518Srobert
5*12c85518Srobert.. contents::
6*12c85518Srobert   :local:
7*12c85518Srobert
8*12c85518Srobert.. _clang-linker-wrapper:
9*12c85518Srobert
10*12c85518SrobertIntroduction
11*12c85518Srobert============
12*12c85518Srobert
13*12c85518SrobertThis tool works as a wrapper of the normal host linking job. This tool is used
14*12c85518Srobertto create linked device images for offloading and the necessary runtime calls to
15*12c85518Srobertregister them. It works by first scanning the linker's input for embedded device
16*12c85518Srobertoffloading data stored at the ``.llvm.offloading`` section. This section
17*12c85518Srobertcontains binary data created by the :doc:`ClangOffloadPackager`. The extracted
18*12c85518Srobertdevice files will then be linked. The linked modules will then be wrapped into a
19*12c85518Srobertnew object file containing the code necessary to register it with the offloading
20*12c85518Srobertruntime.
21*12c85518Srobert
22*12c85518SrobertUsage
23*12c85518Srobert=====
24*12c85518Srobert
25*12c85518SrobertThis tool can be used with the following options. Any arguments not intended
26*12c85518Srobertonly for the linker wrapper will be forwarded to the wrapped linker job.
27*12c85518Srobert
28*12c85518Srobert.. code-block:: console
29*12c85518Srobert
30*12c85518Srobert  USAGE: clang-linker-wrapper [options] -- <options to passed to the linker>
31*12c85518Srobert
32*12c85518Srobert  OPTIONS:
33*12c85518Srobert    --bitcode-library=<kind>-<triple>-<arch>=<path>
34*12c85518Srobert                           Extra bitcode library to link
35*12c85518Srobert    --cuda-path=<dir>      Set the system CUDA path
36*12c85518Srobert    --device-debug         Use debugging
37*12c85518Srobert    --device-linker=<value> or <triple>=<value>
38*12c85518Srobert                           Arguments to pass to the device linker invocation
39*12c85518Srobert    --dry-run              Print program arguments without running
40*12c85518Srobert    --embed-bitcode        Embed linked bitcode in the module
41*12c85518Srobert    --help-hidden          Display all available options
42*12c85518Srobert    --help                 Display available options (--help-hidden for more)
43*12c85518Srobert    --host-triple=<triple> Triple to use for the host compilation
44*12c85518Srobert    --linker-path=<path>   The linker executable to invoke
45*12c85518Srobert    -L <dir>               Add <dir> to the library search path
46*12c85518Srobert    -l <libname>           Search for library <libname>
47*12c85518Srobert    --opt-level=<O0, O1, O2, or O3>
48*12c85518Srobert                           Optimization level for LTO
49*12c85518Srobert    -o <path>              Path to file to write output
50*12c85518Srobert    --pass-remarks-analysis=<value>
51*12c85518Srobert                           Pass remarks for LTO
52*12c85518Srobert    --pass-remarks-missed=<value>
53*12c85518Srobert                           Pass remarks for LTO
54*12c85518Srobert    --pass-remarks=<value> Pass remarks for LTO
55*12c85518Srobert    --print-wrapped-module Print the wrapped module's IR for testing
56*12c85518Srobert    --ptxas-arg=<value>    Argument to pass to the 'ptxas' invocation
57*12c85518Srobert    --save-temps           Save intermediate results
58*12c85518Srobert    --sysroot<value>       Set the system root
59*12c85518Srobert    --verbose              Verbose output from tools
60*12c85518Srobert    --v                    Display the version number and exit
61*12c85518Srobert    --                     The separator for the wrapped linker arguments
62*12c85518Srobert
63*12c85518Srobert
64*12c85518SrobertExample
65*12c85518Srobert=======
66*12c85518Srobert
67*12c85518SrobertThis tool links object files with offloading images embedded within it using the
68*12c85518Srobert``-fembed-offload-object`` flag in Clang. Given an input file containing the
69*12c85518Srobertmagic section we can pass it to this tool to extract the data contained at that
70*12c85518Srobertsection and run a device linking job on it.
71*12c85518Srobert
72*12c85518Srobert.. code-block:: console
73*12c85518Srobert
74*12c85518Srobert  clang-linker-wrapper --host-triple=x86_64 --linker-path=/usr/bin/ld -- <Args>
75