1MOLD(1)                   BSD General Commands Manual                  MOLD(1)
2

NAME

4     mold — a modern linker
5

SYNOPSIS

7     mold [-options] objfile ...
8

DESCRIPTION

10     mold is a faster drop-in replacement for the default GNU ld(1).
11
12   How to use mold
13     See https://github.com/rui314/mold#how-to-use
14
15   Compatibility
16     mold is designed to be a drop-in replacement for the GNU linkers for
17     linking user-land programs.  If your user-land program cannot be built
18     due to missing command-line options, please file a bug at
19     https://github.com/rui314/mold/issues
20
21     mold supports a very limited set of linker script features, which is just
22     sufficient to read /usr/lib/x86_64-linux-gnu/libc.so on Linux systems (on
23     Linux, that file is despite its name not a shared library but an ASCII
24     linker script that loads a real libc.so file.)  Beyond that, we have no
25     plan to support any linker script features.  The linker script is an ad-
26     hoc, over-designed, complex language which we believe needs to be dis‐
27     rupted by a simpler mechanism.  We have a plan to add a replacement for
28     the linker script to mold instead.
29
30   Archive symbol resolution
31     Traditionally, Unix linkers are sensitive to the order in which input
32     files appear on command line.  They process input files from the first
33     (left-most) file to the last (right-most) file one-by-one.  While reading
34     input files, they maintain sets of defined and undefined symbols.  When
35     visiting an archive file (.a files), they pull out object files to re‐
36     solve as many undefined symbols as possible and go on to the next input
37     file.  Object files that weren't pulled out will never have a chance for
38     a second look.
39
40     Due to this semantics, you usually have to add archive files at the end
41     of a command line, so that when a linker reaches archive files, it knows
42     what symbols are remain undefined.  If you put archive files at the be‐
43     ginning of a command line, a linker doesn't have any undefined symbol,
44     and thus no object files will be pulled out from archives.
45
46     You can change the processing order by --start-group and --end-group op‐
47     tions, though they make a linker slower.
48
49     mold as well as LLVM lld(1) linker take a different approach.  They memo‐
50     rize what symbols can be resolved from archive files instead of forget‐
51     ting it after processing each archive.  Therefore, mold and lld(1) can
52     "go back" in a command line to pull out object files from archives, if
53     they are needed to resolve remaining undefined symbols.  They are not
54     sensitive to the input file order.
55
56     --start-group and --end-group are still accepted by mold and lld(1) for
57     compatibility with traditional linkers, but they are silently ignored.
58
59   Dynamic symbol resolution
60     Some Unix linker features are unable to be understood without understand‐
61     ing the semantics of dynamic symbol resolution.  Therefore, even though
62     that's not specific to mold, we'll explain it here.
63
64     We use "ELF module" or just "module" as a collective term to refer an ex‐
65     ecutable or a shared library file in the ELF format.
66
67     An ELF module may have lists of imported symbols and exported symbols, as
68     well as a list of shared library names from which imported symbols should
69     be imported.  The point is that imported symbols are not bound to any
70     specific shared library until runtime.
71
72     Here is how the Unix dynamic linker resolves dynamic symbols.  Upon the
73     start of an ELF program, the dynamic linker construct a list of ELF mod‐
74     ules which as a whole consist of a complete program.  The executable file
75     is always at the beginning of the list followed by its depending shared
76     libraries.  An imported symbol is searched from the beginning of the list
77     to the end.  If two or more modules define the same symbol, the one that
78     appears first in the list takes precedence over the others.
79
80     This Unix semantics are contrary to systems such as Windows that have the
81     two-level namespace for dynamic symbols.  On Windows, for example, dy‐
82     namic symbols are represented as a tuple of (symbol-name,
83     shared-library-name), so that each dynamic symbol is guaranteed to be re‐
84     solved from some specific library.
85
86     Typically, an ELF module that exports a symbol also imports the same sym‐
87     bol.  Such a symbol is usually resolved to itself, but that's not the
88     case if a module that appears before in the symbol search list provides
89     another definition of the same symbol.
90
91     Let me take malloc(3) as an example.  Assume that you define your version
92     of malloc(3) in your main executable file.  Then, all malloc calls from
93     any module are resolved to your function instead of that in libc, because
94     the executable is always at the beginning of the dynamic symbol search
95     list. Note that even malloc(3) calls within libc are resolved to your
96     definition since libc exports and imports malloc.  Therefore, by defining
97     malloc yourself, you can overwrite a library function, and the malloc(3)
98     in libc becomes dead code.
99
100     These Unix semantics are tricky and sometimes considered harmful.  For
101     example, assume that you accidentally define atoi(3) as a global function
102     in your executable that behaves completely differently from the one in
103     the C standard.  Then, all atoi function calls from any modules (even
104     function calls within libc) are redirected to your function instead of
105     the one in libc which obviously causes a problem.  That is a somewhat
106     surprising consequence for an accidental name conflict.  On the other
107     hand, this semantic is sometimes considered useful because it allows
108     users to overwrite library functions without recompiling modules contain‐
109     ing them.  Whether good or bad, you should keep this semantic in mind to
110     understand the Unix linkers behaviors.
111
112   Build reproducibility
113     mold's output is deterministic.  That is, if you pass the same object
114     files and the same command-line options to the same version of mold, it
115     is guaranteed to always produce the same output.  The linker's internal
116     randomness, such as the timing of thread scheduling or iteration orders
117     of hash tables, doesn't affect the output.
118
119     mold does not have any host-specific default settings.  This is contrary
120     to the GNU linkers to which some configurable values, such as system-de‐
121     pendent library search paths, are hard-coded.  mold depends only on its
122     command-line arguments.
123

MOLD-SPECIFIC OPTIONS

125     --chroot=dir
126             Set dir to root directory.
127
128     --color-diagnostics=[auto | always | never]
129     --color-diagnostics
130     --no-color-diagnostics
131
132             Show diagnostics messages in color using ANSI escape sequences.
133             auto means that mold prints out messages in color only if the
134             standard output is connected to a TTY. Default is auto.
135
136     --fork
137     --no-fork
138             Spawn a child process and let it do the actual linking. When
139             linking a large program, the OS kernel can take a few hundred
140             milliseconds to terminate a mold process.  --fork hides that la‐
141             tency. By default, it does fork.
142
143     --perf  Print performance statistics.
144
145     --print-dependencies
146             Print out dependency information for input files.
147
148             Each line of the output for this option shows that which file de‐
149             pends on which file to use which symbol. This option is useful to
150             debug why some object file in a static archive got linked or why
151             some shared library is kept in an output file's dependency list
152             even with --as-needed.
153
154     -N, --omagic
155     --no-omagic
156             Force mold to emit an output file with an old-fashioned memory
157             layout.  First, it makes the first data segment to not be aligned
158             to a page boundary.  Second, text segments are marked as writable
159             if the option is given.
160
161
162     --repro
163             Archive input files as a tar file.
164
165     --reverse-sections
166             Reverses the order of input sections before assigning them the
167             offsets in the output file.
168
169             This option is useful for finding a bug that depends on an ini‐
170             tialization order of global objects. In C++, constructors of
171             global objects in a single  source file are guaranteed to be exe‐
172             cuted in the source order, but there's no such guarantee across
173             compilation units. Usually, constructors are executed in the or‐
174             der given to the linker, but depending on it is a mistake.
175
176             By reversing the order of input sections using
177             --reverse-sections, you can easily test that your program works
178             in the reversed initialization order.
179
180     --run command arg file ...
181             Run command with mold as /usr/bin/ld.  Specifically, mold runs a
182             given command with the LD_PRELOAD environment set to intercept
183             exec(3) family functions and replaces argv[0] with itself if it
184             is ld, ld.gold or ld.lld.
185
186     --shuffle-sections
187     --shuffle-sections=number
188             Randomizes the output by shuffling the order of input sections
189             before assigning them the offsets in the output file. If number
190             is given, it's used as a seed for the random number generator, so
191             that the linker produces the same output as for the same seed. If
192             no seed is given, a random number is used as a seed.
193
194             This option is useful for benchmarking. Modern CPUs are sensitive
195             to program's memory layout. A seeming benign change in program
196             layout (such as a small size increase of a function in the middle
197             of a program) can affect program's performance. Therefore, even
198             if you write new code and get a good benchmark result, it is hard
199             to say whether or not the new code improves the programs perfor‐
200             mance. It is possible that the new memory layout happens to per‐
201             form better.
202
203             By running a benchmark multiple time with shuffling memory layout
204             using --shuffle-sections, you can isolate your program's real
205             performance number from the randomness caused by memory layout
206             changes.
207
208     --stats
209             Print input statistics.
210
211     --thread-count=count
212             Use count number of threads.
213
214     --threads
215     --no-threads
216             Use multiple threads.  By default, mold uses as many threads as
217             the number of cores or 32, whichever is the smallest.  The reason
218             why it is capped to 32 is because mold doesn't scale well beyond
219             that point.  To use only one thread, pass --no-threads or
220             --thread-count=1.
221
222     --quick-exit
223     --no-quick-exit
224             Use or do not use quick_exit to exit.
225

GNU-COMPATIBLE OPTIONS

227     --help  Report usage information to stdout and exit.
228
229     -v, --version
230             Report version information to stdout.
231
232     -V      Report version and target information to stdout.
233
234     -C dir, --directory dir
235             Change to dir before doing anything.
236
237     -E, --export-dynamic
238     --no-export-dynamic
239             When creating an executable, using the -E option causes all
240             global symbols to be put into the dynamic symbol table, so that
241             the symbols are visible from other ELF modules at runtime.
242
243             By default, or if --no-export-dynamic is given, only symbols that
244             are referenced by DSOs at link-time are exported from an exe‐
245             cutable.
246
247     -F libname, --filter=libname
248             Set the DT_FILTER dynamic section field to libname.
249
250     -Ifile, --dynamic-linker=file
251     --no-dynamic-linker
252             Set the dynamic linker path to file.  If no -I option is given,
253             or if --no-dynamic-linker is given, no dynamic linker path is set
254             to an output file.  This is contrary to the GNU linkers which
255             sets a default dynamic linker path in that case.  However, this
256             difference doesn't usually make any difference because the com‐
257             piler driver always passes -I to a linker.
258
259     -Ldir, --library-path=dir
260             Add dir to the list of library search paths from which mold
261             searches libraries for the -l option.
262
263             Unlike the GNU linkers, mold does not have the default search
264             paths.  This difference doesn't usually make any difference be‐
265             cause the compiler driver always passes all necessary search
266             paths to a linker.
267
268     -M, --print-map
269             Write a map file to stdout.
270
271     -N, --omagic
272     --no-omagic
273             Force mold to emit an output file with an old-fashioned memory
274             layout.  First, it makes the first data segment to not be aligned
275             to a page boundary.  Second, text segments are marked as writable
276             if the option is given.
277
278     -S, --strip-debug
279             Omit .debug_* sections from the output file.
280
281     -T file, --script=file
282             Read linker script from file.
283
284     -X, --discard-locals
285             Discard temporary local symbols to reduce the sizes of the symbol
286             table and the string table.  Temporary local symbols are local
287             symbols starting with .L.  Compilers usually generate such sym‐
288             bols for unnamed program elements such as string literals or
289             floating-point literals.
290
291     -e symbol, --entry=symbol
292             Use symbol as the entry point symbol instead of the default entry
293             point symbol _start.
294
295     -f shlib, --auxiliary=shlib
296             Set the DT_AUXILIARY dynamic section field to shlib.
297
298     -h libname, --soname=libname
299             Set the DT_SONAME dynamic section field to libname.  This option
300             is used when creating a shared object file.  Typically, when you
301             create SyXXX lib foo.so, you want to pass --soname=foo to a
302             linker.
303
304     -llibname
305             Search for Sylib libname.so or Sylib libname.a from library
306             search paths.
307
308     -m [target]
309             Choose a target.
310
311     -o file, --output=file
312             Use file as the output file name instead of the default name
313             a.out.
314
315     -r, --relocatable
316             Instead of generating an executable or a shared object file, com‐
317             bine input object files to generate another object file that can
318             be used as an input to a linker.
319
320     --relocatable-merge-sections
321             By default, mold doesn't merge input sections by name when merg‐
322             ing input object files into a single output object file for -r.
323             For example, .text.foo and .text.bar aren't merged for -r even
324             though they are merged into .text according to the default sec‐
325             tion merging rules.
326
327             This option changes the behavior so that mold merges input sec‐
328             tions by name by the default section merging rules.
329
330     -s, --strip-all
331             Omit .symtab section from the output file.
332
333     -u symbol, --undefined=symbol
334             If symbol remains as an undefined symbol after reading all object
335             files, and if there is an static archive that contains an object
336             file defining symbol, pull out the object file and link it so
337             that the output file contains a definition of symbol.
338
339     --Bdynamic
340             Link against shared libraries.
341
342     --Bstatic
343             Do not link against shared libraries.
344
345     --Bsymbolic
346             When creating a shared library, make global symbols export-only
347             (i.e. do not import the same symbol).  As a result, references
348             within a shared library is always resolved locally, negating sym‐
349             bol override at runtime.  See Dynamic symbol resolution for more
350             information about symbol imports and exports.
351
352     --Bsymbolic-functions
353             Have the same effect as --Bsymbolic but works only for function
354             symbols.  Data symbols remains being both imported and exported.
355
356     --Bno-symbolic
357             Cancel --Bsymbolic and --Bsymbolic-functions.
358
359     --Map=file
360             Write map file to file.
361
362     --Tbss=address
363             Alias for --section-start=.bss=address.
364
365     --Tdata=address
366             Alias for --section-start=.data=address.
367
368     --Ttext=address
369             Alias for --section-start=.text=address.
370
371     --allow-multiple-definition
372             Normally, the linker reports an error if there are more than one
373             definition of a symbol.  This option changes the default behavior
374             so that it doesn't report an error for duplicate definitions and
375             instead use the first definition.
376
377     --as-needed
378     --no-as-needed
379             By default, shared libraries given to a linker are uncondition‐
380             ally added to the list of required libraries in an output file.
381             However, shared libraries after --as-needed are added to the list
382             only when at least one symbol is actually used by an object file.
383             In other words, shared libraries after --as-needed are not added
384             to the list of needed libraries if they are not needed by a pro‐
385             gram.
386
387             The --no-as-needed option restores the default behavior for sub‐
388             sequent files.
389
390     --build-id
391     --build-id=[none | md5 | sha1 | sha256 | uuid | 0xhexstring]
392     --no-build-id
393             Create a .note.gnu.build-id section containing a byte string to
394             uniquely identify an output file.  --build-id and
395             --build-id=sha256 compute a 256-bit cryptographic hash of an out‐
396             put file and set it to build-id.  md5 and sha1 compute the same
397             hash but truncate it to 128 and 160 bits, respectively, before
398             setting it to build-id.  uuid sets a random 128-bit UUID.
399             0xhexstring sets hexstring.
400
401     --defsym=symbol=value
402
403     --compress-debug-sections=[none | zlib | zlib-gabi | zstd]
404             Compress DWARF debug info (.debug_* sections) using the zlib or
405             zstd compression algorithm.  -zlib-gabi is an alias for -zlib.
406
407     --defsym=symbol=value
408             Define symbol as an alias for value.
409
410             value is either an integer (in decimal or hexadecimal with ‘0x’
411             prefix) or a symbol name.  If an integer is given as a value,
412             symbol is defined as an absolute symbol with the given value.
413
414     --default-symver
415             Use soname as a symbol version and append that version to all
416             symbols.
417
418     --demangle
419     --no-demangle
420             Demangle C++ symbols in log messages.
421
422     --dependency-file=file
423             Write a dependency file to file.  The contents of the written
424             file is readable by make, which defines only one rule with the
425             linker's output file as a target and all input files as its pre‐
426             requisite. Users are expected to include the generated dependency
427             file into a Makefile to automate the dependency management. This
428             option is analogous to the compiler's -MM -MF options.
429
430     --dynamic-list=file
431             Read a list of dynamic symbols from file.  Same as
432             --export-dynamic-symbol-list, except that it implies --Bsymbolic.
433
434             If file does not exist in the current directory, it is searched
435             from library search paths for the sake of compatibility with GNU
436             ld.
437
438     --eh-frame-hdr
439     --no-eh-frame-hdr
440             Create .eh_frame_hdr section.
441
442     --emit-relocs
443             A linker usually "consumes" relocation sections. That is, a
444             linker applies relocations to other sections, and relocation sec‐
445             tions themselves are discarded.
446
447             The --emit-relocs instructs the linker to leave relocation sec‐
448             tions in the output file. Some post-link binary analysis or opti‐
449             mization tools such as LLVM Bolt need them.
450
451     --enable-new-dtags
452     --disable-new-dtags
453             By default, mold emits DT_RUNPATH for --rpath.  If you pass
454             --disable-new-dtags, mold emits DT_RPATH for --rpath instead.
455
456     --execute-only
457             Traditionally, most processors require both executable and read‐
458             able bits to 1 to make the page executable, which allows machine
459             code to read itself as data at runtime. This is actually what an
460             attacker often does after gaining a limited control of a process
461             to find pieces of machine code they can use to gain the full con‐
462             trol of the process.
463
464             As a mitigation, some recent processors allows "execute-only"
465             pages. If a page is execute-only, you can call a function there
466             as long as you know its address but can't read it as data.
467
468             This option marks text segments execute-only. This option cur‐
469             rently works only on some ARM64 processors.
470
471     --exclude-libs=libraries...
472             Mark all symbols in the given libraries hidden.
473
474     --export-dynamic-symbol=sym
475             Put symbols matching sym in the dynamic symbol table.  sym may be
476             a glob, with the same syntax as the globs used in
477             --export-dynamic-symbol-list or --version-script.
478
479     --export-dynamic-symbol-list=file
480             Read a list of dynamic symbols from file.
481
482     --fatal-warnings
483     --no-fatal-warnings
484             Treat warnings as errors.
485
486     --fini=symbol
487             Call symbol at unload-time.
488
489     --gc-sections
490     --no-gc-sections
491             Remove unreferenced sections.
492
493     --gdb-index
494             Create a .gdb_index section to speed up GNU debugger. To use
495             this, you need to compile source files with the -ggnu-pubnames
496             compiler flag.
497
498     --hash-style=[sysv | gnu | both]
499             Set hash style.
500
501     --icf=[none | safe | all]
502     --no-icf
503             It is not uncommon for a program to contain many identical func‐
504             tions that differ only in name. For example, a C++ template
505             std::vector is very likely to be instantiated to the identical
506             code for std::vector<int> and std::vector<unsigned> because the
507             container cares only about the size of the parameter type. Iden‐
508             tical Code Folding (ICF) is a size optimization to identify and
509             merge such identical functions.
510
511             If --icf=all is given, mold tries to merge all identical func‐
512             tions. This reduces the size of the output most, but it is not
513             “safe” optimization. It is guaranteed in C and C++ that two
514             pointers pointing two different functions will never be equal,
515             but --icf=all breaks that assumption as two functions have the
516             same address after merging. So a care must be taken when you use
517             that flag that your program does not depend on the function
518             pointer uniqueness.
519
520             --icf=safe is a flag to merge functions only when it is safe to
521             do so. That is, if a program does not take an address of a func‐
522             tion, it is safe to merge that function with other function, as
523             you cannot compare a function pointer with something else without
524             taking an address of a function.  needs to be used with a com‐
525             piler that supports .llvm_addrsig section which contains the in‐
526             formation as to what symbols are address-taken. LLVM/Clang sup‐
527             ports that section by default. Since GCC does not support it yet,
528             you cannot use --icf=safe with GCC (it doesn't do any harm but
529             can't optimize at all.)
530
531             --icf=none and --no-icf disables ICF.
532
533     --ignore-data-address-equality
534             Make ICF to merge not only functions but also data. This option
535             should be used in combination with --icf=all.
536
537     --image-base=addr
538             Set the base address to addr.
539
540     --init=symbol
541             Call symbol at load-time.
542
543     --no-undefined
544             Report undefined symbols (even with --shared).
545
546     --noinhibit-exec
547             Create an output file even if errors occur.
548
549     --pack-dyn-relocs=[none | relr]
550             If relr is specified, all R_*_RELATIVE relocations are put into
551             .relr.dyn section instead of .rel.dyn or .rela.dyn section. Since
552             .relr.dyn section uses a space-efficient encoding scheme, speci‐
553             fying this flag can reduce the size of the output. This is typi‐
554             cally most effective for position-independent executable.
555
556             Note that a runtime loader has to support .relr.dyn to run exe‐
557             cutables or shared libraries linked with --pack-dyn-relocs=relr,
558             and only ChromeOS, Android and Fuchsia support it as of now in
559             2022.
560
561     --package-metadata=string
562             Embed string to a .note.package section. This option in intended
563             to be used by a package management command such as rpm to embed
564             metadata regarding a package to each executable file.
565
566     --pie, --pic-executable
567     --no-pie, --no-pic-executable
568             Create a position-independent executable.
569
570     --print-gc-sections
571     --no-print-gc-sections
572             Print removed unreferenced sections.
573
574     --print-icf-sections
575     --no-print-icf-sections
576             Print folded identical sections.
577
578     --push-state
579     --pop-state
580             --push-state saves the current values of --as-needed,
581             --whole-archive, --static, and --start-lib.  The saved values can
582             be restored by --pop-state.
583
584             --push-state and --pop-state pairs can nest.
585
586             These options are useful when you want to construct linker com‐
587             mand line options programmatically. For example, if you want to
588             link libfoo.so by as-needed basis but don't want to change the
589             global state of --as-needed, you can append "--push-state --as-
590             needed -lfoo --pop-state" to the linker command line options.
591
592     --relax
593     --no-relax
594             Rewrite machine instructions with more efficient ones for some
595             relocations.  The feature is enabled by default.
596
597     --require-defined=symbol
598             Like --undefined, except the new symbol must be defined by the
599             end of the link.
600
601     --retain-symbols-file=file
602             Keep only symbols listed in file.
603
604             file is a text file containing a symbol name on each line.  mold
605             discards all local symbols as well as global symbol that are not
606             in file.  Note that this option removes symbols only from .symtab
607             section and does not affect .dynsym section, which is used for
608             dynamic linking.
609
610     --rpath=dir
611             Add dir to runtime search path.
612
613     --section-start=section=address
614             Set address to section.  address is a hexadecimal number that may
615             start with an optional ‘0x’.
616
617     --shared, --Bshareable
618             Create a share library.
619
620     --spare-dynamic-tags=number
621             Reserve given number of tags in .dynamic section.
622
623     --start-lib
624     --end-lib
625             Handle object files between --start-lib and --end-lib as if they
626             were in an archive file. That means object files between them are
627             linked only when they are needed to resolve undefined symbols.
628             The options are useful if you want to link object files only when
629             they are needed but want to avoid the overhead of running ar(3).
630
631     --static
632             Do not link against shared libraries.
633
634     --sysroot=dir
635             Set target system root directory to dir.
636     --trace
637             Print name of each input file.
638
639     --undefined-version
640     --no-undefined-version
641             By default, mold warns on a symbol specified by a version script
642             or by --export-dynamic-symbol if it is not defined. You can si‐
643             lence the warning by --undefined-version.
644
645     --unique=pattern
646             Don't merge input sections that match pattern.
647
648     --unresolved-symbols=[report-all | ignore-all | ignore-in-object-files |
649             ignore-in-shared-libs]
650             How to handle undefined symbols.
651
652     --version-script=file
653             Read version script from file.  If file does not exist in the
654             current directory, it is searched from library search paths for
655             the sake of compatibility with GNU ld.
656
657     --warn-common
658     --no-warn-common
659             Warn about common symbols.
660
661     --warn-once
662             Only warn once for each undefined symbol instead of warn for each
663             relocation referring an undefined symbol.
664
665     --warn-unresolved-symbols
666     --error-unresolved-symbols
667             Normally, the linker reports an error for unresolved symbols.
668             --warn-unresolved-symbols option turns it into a warning.
669             --error-unresolved-symbols option restores the default behavior.
670
671     --whole-archive
672     --no-whole-archive
673             When archive files (.a files) are given to a linker, only object
674             files that are needed to resolve undefined symbols are extracted
675             from them and linked to an output file.  --whole-archive changes
676             that behavior for subsequent archives so that a linker extracts
677             all object files and link them to an output.  For example, if you
678             are creating a shared object file and you want to include all ar‐
679             chive members to the output, you should pass --whole-archive.
680             --no-whole-archive restores the default behavior for subsequent
681             archives.
682
683     --wrap=symbol
684             Make symbol to be resolved to __wrap_symbol.  The original symbol
685             can be resolved as __real_symbol.  This option is typically used
686             for wrapping an existing function.
687
688     -z cet-report=[none | warning | error]
689             Intel Control-flow Enforcement Technology (CET) is a new x86 fea‐
690             ture available since Tiger Lake which is released in 2020.  It
691             defines new instructions to harden security to protect programs
692             from control hijacking attacks. You can tell compiler to use the
693             feature by specifying the -fcf-protection flag.
694
695             -z cet-report flag is used to make sure that all object files
696             were compiled with a correct -fcf-protection flag. If warning or
697             error are given, mold prints out a warning or an error message if
698             an object file was not compiled with the compiler flag.
699
700             mold looks for GNU_PROPERTY_X86_FEATURE_1_IBT bit and
701             GNU_PROPERTY_X86_FEATURE_1_SHSTK bit in .note.gnu.property sec‐
702             tion to determine whether or not an object file was compiled with
703             -fcf-protection.
704
705     -z now
706     -z lazy
707             By default, functions referring other ELF modules are resolved by
708             the dynamic linker when they are called for the first time.  -z
709             now marks an executable or a shared library file so that all dy‐
710             namic symbols are loaded when a file is loaded to memory.  -z
711             lazy restores the default behavior.
712
713     -z origin
714             Mark object requiring immediate $ORIGIN processing at runtime.
715
716     -z ibt  Turn on GNU_PROPERTY_X86_FEATURE_1_IBT bit in .note.gnu.property
717             section to indicate that the output uses IBT-enabled PLT. This
718             option implies -z ibtplt.
719
720     -z ibtplt
721             Generate Intel Branch Tracking (IBT)-enabled PLT which is the de‐
722             fault on x86-64.
723
724     -z execstack
725     -z noexecstack
726             By default, the pages for the stack area (i.e. the pages where
727             local variables reside) are not executable for security reasons.
728             -z execstack makes it executable.  -z noexecstack restores the
729             default behavior.
730
731     -z keep-text-section-prefix
732     -z nokeep-text-section-prefix
733             Keep .text.hot, .text.unknown, .text.unlikely, .text.startup and
734             .text.exit as separate sections in the final binary.
735
736     -z relro
737     -z norelro
738             Some sections such as .dynamic have to be writable only during an
739             executable or a shared library file is being loaded to memory.
740             Once the dynamic linker finishes its job, such sections won't be
741             mutated by anyone.  As a security mitigation, it is preferred to
742             make such segments read-only during program execution.
743
744             -z relro puts such sections into a special segment called relro.
745             The dynamic linker make a relro segment read-only after it fin‐
746             ishes its job.
747
748             By default, mold generates a relro segment.  -z norelro disables
749             the feature.
750
751     -z separate-loadable-segments
752     -z separate-code
753     -z noseparate-code
754             If one memory page contains multiple segments, the page protec‐
755             tion bits are set in such a way that needed attributes (writable
756             or executable) are satisfied for all segments.  This usually hap‐
757             pens at a boundary of two segments with two different attributes.
758
759             separate-loadable-segments adds paddings between segments with
760             different attributes so that they do not share the same page.
761             This is the default.
762
763             separate-code adds paddings only between executable and non-exe‐
764             cutable segments.
765
766             noseparate-code does not add any paddings between segments.
767
768     -z defs
769     -z nodefs
770             Report undefined symbols (even with --shared).
771
772     -z shstk
773             Enforce shadow stack by turning GNU_PROPERTY_X86_FEATURE_1_SHSTK
774             bit in .note.gnu.property output section. Shadow stack is part of
775             Intel Control-flow Enforcement Technology (CET), which is avail‐
776             able since Tiger Lake (2020).
777
778     -z text
779     -z notext, -z textoff
780             mold by default reports an error if dynamic relocations are cre‐
781             ated in read-only sections.  If -z notext or -z textoff are
782             given, mold creates such dynamic relocations without reporting an
783             error.  -z text restores the default behavior.
784
785     -z max-page-size
786             Some CPU ISAs support multiple different memory page sizes.  This
787             option specifies the maximum page size that an output binary can
788             run on.  If you specify a large value, the output can run on both
789             large and small page systems, but it wastes a bit of memory at
790             page boundaries on systems with small pages.
791
792             The default value is 4 KiB for i386, x86-64 and RISC-V, and 64
793             KiB for ARM64.
794
795     -z nodefaultlib
796             Make the dynamic loader to ignore default search paths.
797
798     -z nodelete
799             Mark DSO non-deletable at runtime.
800
801     -z nodlopen
802             Mark DSO not available to dlopen(3).  This option makes it possi‐
803             ble for the linker to optimize thread-local variable accesses by
804             rewriting instructions for some targets.
805
806     -z nodump
807             Mark DSO not available to dldump(3).
808
809     -z nocopyreloc
810             Do not create copy relocations.
811
812     -z initfirst
813             Mark DSO to be initialized first at runtime.
814
815     -z interpose
816             Mark object to interpose all DSOs but executable.
817

SEE ALSO

819     gold(1), ld(1), elf(5), ld.so(8)
820

AUTHORS

822     Rui Ueyama <ruiu@cs.stanford.edu>
823

BUGS

825     Report bugs to https://github.com/rui314/mold/issues
826
827BSD                            February 6, 2023                            BSD
Impressum