1.\" Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2.\" See https://llvm.org/LICENSE.txt for license information.
3.\" SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4.\"
5.\" This man page documents only lld's ELF linking support, obtained originally
6.\" from FreeBSD.
7.Dd May 12, 2019
8.Dt LD.LLD 1
9.Os
10.Sh NAME
11.Nm ld.lld
12.Nd ELF linker from the LLVM project
13.Sh SYNOPSIS
14.Nm ld.lld
15.Op Ar options
16.Ar objfile ...
17.Sh DESCRIPTION
18A linker takes one or more object, archive, and library files, and combines
19them into an output file (an executable, a shared library, or another object
20file).
21It relocates code and data from the input files and resolves symbol
22references between them.
23.Pp
24.Nm
25is a drop-in replacement for the GNU BFD and gold linkers.
26It accepts most of the same command line arguments and linker scripts
27as GNU linkers.
28.Pp
29.Nm
30currently supports i386, x86-64, ARM, AArch64, PowerPC32, PowerPC64,
31MIPS32, MIPS64, RISC-V, AMDGPU, Hexagon and SPARC V9 targets.
32.Nm
33acts as a Microsoft link.exe-compatible linker if invoked as
34.Nm lld-link
35and as macOS's ld if invoked as
36.Nm ld.ld64.
37All these targets are always supported however
38.Nm
39was built, so you can always use
40.Nm
41as a native linker as well as a cross linker.
42.Sh OPTIONS
43Many options have both a single-letter and long form.
44When using the long form options other than those beginning with the
45letter
46.Cm o
47may be specified using either one or two dashes preceding the option name.
48Long options beginning with
49.Cm o
50require two dashes to avoid confusion with the
51.Fl o Ar path
52option.
53.Pp
54.Bl -tag -width indent
55.It Fl -allow-multiple-definition
56Do not error if a symbol is defined multiple times.
57The first definition will be used.
58.It Fl -allow-shlib-undefined
59Allow unresolved references in shared libraries.
60This option is enabled by default when linking a shared library.
61.It Fl -apply-dynamic-relocs
62Apply link-time values for dynamic relocations.
63.It Fl -as-needed
64Only set
65.Dv DT_NEEDED
66for shared libraries if used.
67.It Fl -auxiliary Ns = Ns Ar value
68Set the
69.Dv DT_AUXILIARY
70field to the specified name.
71.It Fl -Bdynamic , Fl -dy
72Link against shared libraries.
73.It Fl -Bstatic , Fl -static , Fl -dn
74Do not link against shared libraries.
75.It Fl -Bsymbolic
76Bind defined symbols locally.
77.It Fl -Bsymbolic-functions
78Bind defined function symbols locally.
79.It Fl -build-id Ns = Ns Ar value
80Generate a build ID note.
81.Ar value
82may be one of
83.Cm fast ,
84.Cm md5 ,
85.Cm sha1 ,
86.Cm tree ,
87.Cm uuid ,
88.Cm 0x Ns Ar hex-string ,
89and
90.Cm none .
91.Cm tree
92is an alias for
93.Cm sha1 .
94Build-IDs of type
95.Cm fast ,
96.Cm md5 ,
97.Cm sha1 ,
98and
99.Cm tree
100are calculated from the object contents.
101.Cm fast
102is not intended to be cryptographically secure.
103.It Fl -build-id
104Synonym for
105.Fl -build-id Ns = Ns Cm fast .
106.It Fl -color-diagnostics Ns = Ns Ar value
107Use colors in diagnostics.
108.Ar value
109may be one of
110.Cm always ,
111.Cm auto ,
112and
113.Cm never .
114.Cm auto
115enables color if and only if output is to a terminal.
116.It Fl -color-diagnostics
117Alias for
118.Fl -color-diagnostics Ns = Ns Cm auto .
119.It Fl -compress-debug-sections Ns = Ns Ar value
120Compress DWARF debug sections.
121.Ar value
122may be
123.Cm none
124or
125.Cm zlib .
126The default compression level is 1 (fastest) as the debug info usually
127compresses well at that level, but if you want to compress it more,
128you can specify
129.Fl O2
130to set the compression level to 6.
131.It Fl -cref
132Output cross reference table.
133.It Fl -define-common , Fl d
134Assign space to common symbols.
135.It Fl -defsym Ns = Ns Ar symbol Ns = Ns Ar expression
136Define a symbol alias.
137.Ar expression
138may be another symbol or a linker script expression.
139For example,
140.Ql --defsym=foo=bar
141or
142.Ql --defsym=foo=bar+0x100 .
143.It Fl -demangle
144Demangle symbol names.
145.It Fl -disable-new-dtags
146Disable new dynamic tags.
147.It Fl -discard-all , Fl x
148Delete all local symbols.
149.It Fl -discard-locals , Fl X
150Delete temporary local symbols.
151.It Fl -discard-none
152Keep all symbols in the symbol table.
153.It Fl -dynamic-linker Ns = Ns Ar value
154Specify the dynamic linker to be used for a dynamically linked executable.
155This is recorded in an ELF segment of type
156.Dv PT_INTERP .
157.It Fl -dynamic-list Ns = Ns Ar file
158Read a list of dynamic symbols from
159.Ar file .
160(executable) Put matched non-local defined symbols to the dynamic symbol table.
161(shared object) References to matched non-local STV_DEFAULT symbols shouldn't be bound to definitions within the shared object. Implies
162.Cm -Bsymbolic
163but does not set DF_SYMBOLIC
164.It Fl -eh-frame-hdr
165Request creation of
166.Li .eh_frame_hdr
167section and
168.Dv PT_GNU_EH_FRAME
169segment header.
170.It Fl -emit-relocs , Fl q
171Generate relocations in the output.
172.It Fl -enable-new-dtags
173Enable new dynamic tags.
174.It Fl -end-lib
175End a grouping of objects that should be treated as if they were together
176in an archive.
177.It Fl -entry Ns = Ns Ar entry
178Name of entry point symbol.
179.It Fl -error-limit Ns = Ns Ar value
180Maximum number of errors to emit before stopping.
181A value of zero indicates that there is no limit.
182.It Fl -error-unresolved-symbols
183Report unresolved symbols as errors.
184.It Fl -error-handing-script Ns = Ns Ar script_path
185Call script
186.Ar script_path
187upon some error, with
188.Ar tag
189as first argument, and an extra parameter as second argument. The script is
190expected to return 0 on success. Any other value is considered a generic error.
191.Ar tag
192may be
193.Cm missing-lib
194followed by the name of the missing library.
195.Cm undefined-symbol
196followed by the name of the undefined symbol.
197.It Fl -execute-only
198Mark executable sections unreadable.
199This option is currently only supported on AArch64.
200.It Fl -exclude-libs Ns = Ns Ar value
201Exclude static libraries from automatic export.
202.It Fl -export-dynamic , Fl E
203Put symbols in the dynamic symbol table.
204.It Fl -export-dynamic-symbol Ns = Ns Ar glob
205(executable) Put matched non-local defined symbols to the dynamic symbol table.
206(shared object) References to matched non-local STV_DEFAULT symbols shouldn't be bound to definitions within the shared object even if they would otherwise be due to
207.Cm -Bsymbolic
208,
209.Cm -Bsymbolic-functions
210or
211.Cm --dynamic-list
212.It Fl -fatal-warnings
213Treat warnings as errors.
214.It Fl -filter Ns = Ns Ar value , Fl F Ar value
215Set the
216.Dv DT_FILTER
217field to the specified value.
218.It Fl -fini Ns = Ns Ar symbol
219Specify a finalizer function.
220.It Fl -format Ns = Ns Ar input-format , Fl b Ar input-format
221Specify the format of the inputs following this option.
222.Ar input-format
223may be one of
224.Cm binary ,
225.Cm elf ,
226and
227.Cm default .
228.Cm default
229is a synonym for
230.Cm elf .
231.It Fl -gc-sections
232Enable garbage collection of unused sections.
233.It Fl -gdb-index
234Generate
235.Li .gdb_index
236section.
237.It Fl -hash-style Ns = Ns Ar value
238Specify hash style.
239.Ar value
240may be
241.Cm sysv ,
242.Cm gnu ,
243or
244.Cm both .
245.Cm both
246is the default.
247.It Fl -help
248Print a help message.
249.It Fl -icf Ns = Ns Cm all
250Enable identical code folding.
251.It Fl -icf Ns = Ns Cm safe
252Enable safe identical code folding.
253.It Fl -icf Ns = Ns Cm none
254Disable identical code folding.
255.It Fl -ignore-data-address-equality
256Ignore address equality of data. C/C++ requires each data to have a unique
257address.
258This option allows lld to do unsafe optimization that breaks the
259requirement: create copies of read-only data or merge two or more read-only data
260that happen to have the same value.
261.It Fl -ignore-function-address-equality
262Ignore address equality of functions.
263This option allows non-PIC calls to a function with non-default visibility in
264a shared object.
265The function may have different addresses within the executable and within the
266shared object.
267.It Fl -image-base Ns = Ns Ar value
268Set the base address to
269.Ar value .
270.It Fl -init Ns = Ns Ar symbol
271Specify an initializer function.
272.It Fl -keep-unique Ns = Ns Ar symbol
273Do not fold
274.Ar symbol
275during ICF.
276.It Fl l Ar libName, Fl -library Ns = Ns Ar libName
277Root name of library to use.
278.It Fl L Ar dir , Fl -library-path Ns = Ns Ar dir
279Add a directory to the library search path.
280.It Fl -lto-aa-pipeline Ns = Ns Ar value
281AA pipeline to run during LTO.
282Used in conjunction with
283.Fl -lto-newpm-passes .
284.It Fl -lto-newpm-passes Ns = Ns Ar value
285Passes to run during LTO.
286.It Fl -lto-O Ns Ar opt-level
287Optimization level for LTO.
288.It Fl -lto-partitions Ns = Ns Ar value
289Number of LTO codegen partitions.
290.It Fl m Ar value
291Set target emulation.
292.It Fl -Map Ns = Ns Ar file , Fl M Ar file
293Print a link map to
294.Ar file .
295.It Fl -nmagic , Fl n
296Do not page align sections, link against static libraries.
297.It Fl -no-allow-shlib-undefined
298Do not allow unresolved references in shared libraries.
299This option is enabled by default when linking an executable.
300.It Fl -no-as-needed
301Always set
302.Dv DT_NEEDED
303for shared libraries.
304.It Fl -no-color-diagnostics
305Do not use colors in diagnostics.
306.It Fl -no-define-common
307Do not assign space to common symbols.
308.It Fl -no-demangle
309Do not demangle symbol names.
310.It Fl -no-dynamic-linker
311Inhibit output of an
312.Li .interp
313section.
314.It Fl -no-fortran-common
315Do not search archive members for definitions to override COMMON symbols.
316.It Fl -no-gc-sections
317Disable garbage collection of unused sections.
318.It Fl -no-gnu-unique
319Disable STB_GNU_UNIQUE symbol binding.
320.It Fl -no-merge-exidx-entries
321Disable merging .ARM.exidx entries.
322.It Fl -no-nmagic
323Page align sections.
324.It Fl -no-omagic
325Do not set the text data sections to be writable, page align sections.
326.It Fl -no-relax
327Disable target-specific relaxations. This is currently a no-op.
328.It Fl -no-rosegment
329Do not put read-only non-executable sections in their own segment.
330.It Fl -no-undefined-version
331Report version scripts that refer undefined symbols.
332.It Fl -no-undefined
333Report unresolved symbols even if the linker is creating a shared library.
334.It Fl -no-warn-symbol-ordering
335Do not warn about problems with the symbol ordering file or call graph profile.
336.It Fl -no-whole-archive
337Restores the default behavior of loading archive members.
338.It Fl -no-pie , Fl -no-pic-executable
339Do not create a position independent executable.
340.It Fl -noinhibit-exec
341Retain the executable output file whenever it is still usable.
342.It Fl -nostdlib
343Only search directories specified on the command line.
344.It Fl o Ar path
345Write the output executable, library, or object to
346.Ar path .
347If not specified,
348.Dv a.out
349is used as a default.
350.It Fl O Ns Ar value
351Optimize output file size.
352.Ar value
353may be:
354.Pp
355.Bl -tag -width 2n -compact
356.It Cm 0
357Disable string merging.
358.It Cm 1
359Enable string merging.
360.It Cm 2
361Enable string tail merging. If
362.Fl -compress-debug-sections
363is given, compress debug sections at compression level 6 instead of 1.
364.El
365.Pp
366.Fl O Ns Cm 1
367is the default.
368.It Fl -oformat Ns = Ns Ar format
369Specify the format for the output object file.
370The only supported
371.Ar format
372is
373.Cm binary ,
374which produces output with no ELF header.
375.It Fl -omagic , Fl N
376Set the text and data sections to be readable and writable, do not page align
377sections, link against static libraries.
378.It Fl -opt-remarks-filename Ar file
379Write optimization remarks in YAML format to
380.Ar file .
381.It Fl -opt-remarks-passes Ar pass-regex
382Filter optimization remarks by only allowing the passes matching
383.Ar pass-regex .
384.It Fl -opt-remarks-with-hotness
385Include hotness information in the optimization remarks file.
386.It Fl -orphan-handling Ns = Ns Ar mode
387Control how orphan sections are handled.
388An orphan section is one not specifically mentioned in a linker script.
389.Ar mode
390may be:
391.Pp
392.Bl -tag -width 2n -compact
393.It Cm place
394Place orphan sections in suitable output sections.
395.It Cm warn
396Place orphan sections as for
397.Cm place
398and also report a warning.
399.It Cm error
400Place orphan sections as for
401.Cm place
402and also report an error.
403.El
404.Pp
405.Cm place
406is the default.
407.It Fl -pack-dyn-relocs Ns = Ns Ar format
408Pack dynamic relocations in the given format.
409.Ar format
410may be:
411.Pp
412.Bl -tag -width 2n -compact
413.It Cm none
414Do not pack.
415Dynamic relocations are encoded in SHT_REL(A).
416.It Cm android
417Pack dynamic relocations in SHT_ANDROID_REL(A).
418.It Cm relr
419Pack relative relocations in SHT_RELR, and the rest of dynamic relocations in
420SHT_REL(A).
421.It Cm android+relr
422Pack relative relocations in SHT_RELR, and the rest of dynamic relocations in
423SHT_ANDROID_REL(A).
424.El
425.Pp
426.Cm none
427is the default.
428If
429.Fl -use-android-relr-tags
430is specified, use SHT_ANDROID_RELR instead of SHT_RELR.
431.Pp
432.It Fl -pic-veneer
433Always generate position independent thunks.
434.It Fl -pie , Fl -pic-executable
435Create a position independent executable.
436.It Fl -print-gc-sections
437List removed unused sections.
438.It Fl -print-icf-sections
439List identical folded sections.
440.It Fl -print-map
441Print a link map to the standard output.
442.It Fl -print-archive-stats Ns = Ns Ar file
443Write archive usage statistics to the specified file.
444Print the numbers of members and fetched members for each archive.
445.It Fl -push-state
446Save the current state of
447.Fl -as-needed ,
448.Fl -static ,
449and
450.Fl -whole-archive.
451.It Fl -pop-state
452Undo the effect of
453.Fl -push-state.
454.It Fl -relocatable , Fl r
455Create relocatable object file.
456.It Fl -reproduce Ns = Ns Ar path
457Write a tar file to
458.Ar path,
459containing all the input files needed to reproduce the link, a text file called
460response.txt containing the command line options and a text file called
461version.txt containing the output of ld.lld --version.
462The archive when
463unpacked can be used to re-run the linker with the same options and input files.
464.It Fl -retain-symbols-file Ns = Ns Ar file
465Retain only the symbols listed in the file.
466.It Fl -rpath Ns = Ns Ar value , Fl R Ar value
467Add a
468.Dv DT_RUNPATH
469to the output.
470.It Fl -rsp-quoting Ns = Ns Ar value
471Quoting style for response files.
472The supported values are
473.Cm windows
474and
475.Cm posix .
476.It Fl -script Ns = Ns Ar file , Fl T Ar file
477Read linker script from
478.Ar file .
479If multiple linker scripts are given, they are processed as if they
480were concatenated in the order they appeared on the command line.
481.It Fl -section-start Ns = Ns Ar section Ns = Ns Ar address
482Set address of section.
483.It Fl -shared , Fl -Bsharable
484Build a shared object.
485.It Fl -shuffle-sections Ns = Ns Ar seed
486Shuffle input sections using the given seed. If 0, use a random seed.
487.It Fl -soname Ns = Ns Ar value , Fl h Ar value
488Set
489.Dv DT_SONAME
490to
491.Ar value .
492.It Fl -sort-common
493This option is ignored for GNU compatibility.
494.It Fl -sort-section Ns = Ns Ar value
495Specifies sections sorting rule when linkerscript is used.
496.It Fl -start-lib
497Start a grouping of objects that should be treated as if they were together
498in an archive.
499.It Fl -strip-all , Fl s
500Strip all symbols.
501.It Fl -strip-debug , Fl S
502Strip debugging information.
503.It Fl -symbol-ordering-file Ns = Ns Ar file
504Lay out sections in the order specified by
505.Ar file .
506.It Fl -sysroot Ns = Ns Ar value
507Set the system root.
508.It Fl -target1-abs
509Interpret
510.Dv R_ARM_TARGET1
511as
512.Dv R_ARM_ABS32 .
513.It Fl -target1-rel
514Interpret
515.Dv R_ARM_TARGET1
516as
517.Dv R_ARM_REL32 .
518.It Fl -target2 Ns = Ns Ar type
519Interpret
520.Dv R_ARM_TARGET2
521as
522.Ar type ,
523where
524.Ar type
525is one of
526.Cm rel ,
527.Cm abs ,
528or
529.Cm got-rel .
530.It Fl -Tbss Ns = Ns Ar value
531Same as
532.Fl -section-start
533with
534.Li .bss
535as the sectionname.
536.It Fl -Tdata Ns = Ns Ar value
537Same as
538.Fl -section-start
539with
540.Li .data
541as the sectionname.
542.It Fl -Ttext Ns = Ns Ar value
543Same as
544.Fl -section-start
545with
546.Li .text
547as the sectionname.
548.It Fl -thinlto-cache-dir Ns = Ns Ar value
549Path to ThinLTO cached object file directory.
550.It Fl -thinlto-cache-policy Ns = Ns Ar value
551Pruning policy for the ThinLTO cache.
552.It Fl -thinlto-jobs Ns = Ns Ar value
553Number of ThinLTO jobs.
554.It Fl -threads Ns = Ns Ar N
555Number of threads.
556.Cm all
557(default) means all of concurrent threads supported.
558.Cm 1
559disables multi-threading.
560.It Fl -time-trace
561Record time trace.
562.It Fl -time-trace-file Ns = Ns Ar file
563Write time trace output to
564.Ar file .
565.It Fl -time-trace-granularity Ns = Ns Ar value
566Minimum time granularity (in microseconds) traced by time profiler.
567.It Fl -trace
568Print the names of the input files.
569.It Fl -trace-symbol Ns = Ns Ar symbol , Fl y Ar symbol
570Trace references to
571.Ar symbol .
572.It Fl -undefined Ns = Ns Ar symbol , Fl u Ar symbol
573If
574.Ar symbol
575is not defined after symbol resolution, and there's a static library
576that contains an object file defining the symbol, load the member
577to include the object file in the output file.
578.It Fl -undefined-glob Ns = Ns Ar pattern
579Synonym for
580.Fl -undefined ,
581except that it takes a glob pattern.
582In a glob pattern,
583.Cm *
584matches zero or more characters,
585.Cm ?
586matches any single character, and
587.Cm [...]
588matches the characters within brackets.
589All symbols that match
590a given pattern are handled as if they were given as arguments of
591.Fl -undefined .
592.It Fl -unique
593Creates a separate output section for every orphan input section.
594.It Fl -unresolved-symbols Ns = Ns Ar value
595Determine how to handle unresolved symbols.
596.It Fl -use-android-relr-tags
597Use SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_RELR / DT_RELR*.
598.It Fl v
599Display the version number and proceed with linking if object files are
600specified.
601.It Fl V , Fl -version
602Display the version number and exit.
603.It Fl -verbose
604Verbose mode.
605.It Fl -version-script Ns = Ns Ar file
606Read version script from
607.Ar file .
608.It Fl -warn-backrefs
609Warn about reverse or cyclic dependencies to or between static archives.
610This can be used to ensure linker invocation remains compatible with
611traditional Unix-like linkers.
612.It Fl -warn-backrefs-exclude Ns = Ns Ar glob
613Glob describing an archive (or an object file within --start-lib)
614which should be ignored for
615.Fl -warn-backrefs
616.It Fl -warn-common
617Warn about duplicate common symbols.
618.It Fl -warn-ifunc-textrel
619Warn about using ifunc symbols in conjunction with text relocations.
620Older versions of glibc library (2.28 and earlier) has a bug that causes
621the segment that includes ifunc symbols to be marked as not executable when
622they are relocated.
623As a result, although the program compiles and links
624successfully, it gives segmentation fault when the instruction pointer reaches
625an ifunc symbol.
626Use -warn-ifunc-textrel to let lld give a warning, if the
627code may include ifunc symbols, may do text relocations and be linked with
628an older glibc version.
629Otherwise, there is no need to use it, as the default value does not give a
630warning.
631This flag has been introduced in late 2018, has no counter part in ld and gold
632linkers, and may be removed in the future.
633.It Fl -warn-unresolved-symbols
634Report unresolved symbols as warnings.
635.It Fl -whole-archive
636Force load of all members in a static library.
637.It Fl -wrap Ns = Ns Ar symbol
638Use wrapper functions for symbol.
639.It Fl z Ar option
640Linker option extensions.
641.Bl -tag -width indent -compact
642.Pp
643.It Cm dead-reloc-in-nonalloc Ns = Ns Ar section_glob=value
644Resolve a relocation in a matched non-SHF_ALLOC section referencing a discarded symbol to
645.Ar value
646Accepts globs, in the event of a section matching more than one option, the last
647option takes precedence. An order of least specific to most specific match is
648recommended.
649.Pp
650.It Cm execstack
651Make the main stack executable.
652Stack permissions are recorded in the
653.Dv PT_GNU_STACK
654segment.
655.Pp
656.It Cm force-bti
657Force enable AArch64 BTI instruction in PLT, warn if Input ELF file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property.
658.Pp
659.It Cm force-ibt
660Force enable Intel Indirect Branch Tracking in PLT, warn if an input ELF file
661does not have GNU_PROPERTY_X86_FEATURE_1_IBT property.
662.Pp
663.It Cm global
664Sets the
665.Dv DF_1_GLOBAL flag in the
666.Dv DYNAMIC
667section.
668Different loaders can decide how to handle this flag on their own.
669.Pp
670.It Cm ifunc-noplt
671Do not emit PLT entries for ifunc symbols.
672Instead, emit text relocations referencing the resolver.
673This is an experimental optimization and only suitable for standalone
674environments where text relocations do not have the usual drawbacks.
675This option must be combined with the
676.Fl z Li notext
677option.
678.Pp
679.It Cm initfirst
680Sets the
681.Dv DF_1_INITFIRST
682flag to indicate the module should be initialized first.
683.Pp
684.It Cm interpose
685Set the
686.Dv DF_1_INTERPOSE
687flag to indicate to the runtime linker that the object is an interposer.
688During symbol resolution interposers are searched after the application
689but before other dependencies.
690.Pp
691.It Cm muldefs
692Do not error if a symbol is defined multiple times.
693The first definition will be used.
694This is a synonym for
695.Fl -allow-multiple-definition.
696.Pp
697.It Cm nocombreloc
698Disable combining and sorting multiple relocation sections.
699.Pp
700.It Cm nocopyreloc
701Disable the creation of copy relocations.
702.Pp
703.It Cm nodefaultlib
704Set the
705.Dv DF_1_NODEFLIB
706flag to indicate that default library search paths should be ignored.
707.Pp
708.It Cm nodelete
709Set the
710.Dv DF_1_NODELETE
711flag to indicate that the object cannot be unloaded from a process.
712.Pp
713.It Cm nodlopen
714Set the
715.Dv DF_1_NOOPEN
716flag to indicate that the object may not be opened by
717.Xr dlopen 3 .
718.Pp
719.It Cm nognustack
720Do not emit the
721.Dv PT_GNU_STACK
722segment.
723.Pp
724.It Cm norelro
725Do not indicate that portions of the object should be mapped read-only
726after initial relocation processing.
727The object will omit the
728.Dv PT_GNU_RELRO
729segment.
730.Pp
731.It Cm notext
732Allow relocations against read-only segments.
733Sets the
734.Dv DT_TEXTREL flag in the
735.Dv DYNAMIC
736section.
737.Pp
738.It Cm now
739Set the
740.Dv DF_BIND_NOW
741flag to indicate that the run-time loader should perform all relocation
742processing as part of object initialization.
743By default relocations may be performed on demand.
744.Pp
745.It Cm origin
746Set the
747.Dv DF_ORIGIN
748flag to indicate that the object requires
749$ORIGIN
750processing.
751.Pp
752.It Cm pac-plt
753AArch64 only, use pointer authentication in PLT.
754.Pp
755.It Cm rel
756Use REL format for dynamic relocations.
757.Pp
758.It Cm rela
759Use RELA format for dynamic relocations.
760.Pp
761.It Cm retpolineplt
762Emit retpoline format PLT entries as a mitigation for CVE-2017-5715.
763.Pp
764.It Cm rodynamic
765Make the
766.Li .dynamic
767section read-only.
768The
769.Dv DT_DEBUG
770tag will not be emitted.
771.Pp
772.It Cm separate-loadable-segments
773.It Cm separate-code
774.It Cm noseparate-code
775Specify whether two adjacent PT_LOAD segments are allowed to overlap in pages.
776.Cm noseparate-code
777(default) allows overlap.
778.Cm separate-code
779allows overlap between two executable segments, or two non-executable segments.
780.Cm separate-loadable-segments
781disallows overlap.
782.Pp
783.It Cm shstk
784x86 only, use shadow stack.
785.Pp
786.It Cm stack-size Ns = Ns Ar size
787Set the main thread's stack size to
788.Ar size .
789The stack size is recorded as the size of the
790.Ar size .
791.Dv PT_GNU_STACK
792program segment.
793.Pp
794.It Cm text
795Do not allow relocations against read-only segments.
796This is the default.
797.Pp
798.It Cm wxneeded
799Create a
800.Dv PT_OPENBSD_WXNEEDED
801segment.
802.El
803.El
804.Sh IMPLEMENTATION NOTES
805.Nm Ap s
806handing of archive files (those with a
807.Pa .a
808file extension) is different from traditional linkers used on Unix-like
809systems.
810.Pp
811Traditional linkers maintain a set of undefined symbols during linking.
812The linker processes each file in the order in which it appears on the
813command line, until the set of undefined symbols becomes empty.
814An object file is linked into the output object when it is encountered,
815with its undefined symbols added to the set.
816Upon encountering an archive file a traditional linker searches the objects
817contained therein, and processes those that satisfy symbols in the unresolved
818set.
819.Pp
820Handling mutually dependent archives may be awkward when using a traditional
821linker.
822Archive files may have to be specified multiple times, or the special command
823line options
824.Fl -start-group
825and
826.Fl -end-group
827may be used to have the linker loop over the files in the group until no new
828symbols are added to the set.
829.Pp
830.Nm
831records all symbols found in objects and archives as it iterates over
832command line arguments.
833When
834.Nm
835encounters an undefined symbol that can be resolved by an object file
836contained in a previously processed archive file, it immediately extracts
837and links it into the output object.
838.Pp
839With certain archive inputs
840.Nm
841may produce different results compared to traditional linkers.
842In practice, large bodies of third party software have been linked with
843.Nm
844without material issues.
845.Pp
846The
847.Fl -warn-backrefs
848option may be used to identify a linker invocation that may be incompatible
849with traditional Unix-like linker behavior.
850