brintos

brintos / llvm-project-archived public Read only

0
0
Text · 23.5 KiB · 343e1d8 Raw
661 lines · plain
1llvm-objcopy - object copying and editing tool2==============================================3 4.. program:: llvm-objcopy5 6SYNOPSIS7--------8 9:program:`llvm-objcopy` [*options*] *input* [*output*]10 11DESCRIPTION12-----------13 14:program:`llvm-objcopy` is a tool to copy and manipulate objects. In basic15usage, it makes a semantic copy of the input to the output. If any options are16specified, the output may be modified along the way, e.g. by removing sections.17 18If no output file is specified, the input file is modified in-place. If "-" is19specified for the input file, the input is read from the program's standard20input stream. If "-" is specified for the output file, the output is written to21the standard output stream of the program.22 23If the input is an archive, any requested operations will be applied to each24archive member individually.25 26The tool is still in active development, but in most scenarios it works as a27drop-in replacement for GNU's :program:`objcopy`.28 29GENERIC AND CROSS-PLATFORM OPTIONS30----------------------------------31 32The following options are either agnostic of the file format, or apply to33multiple file formats.34 35.. option:: --add-gnu-debuglink <debug-file>36 37 Add a .gnu_debuglink section for ``<debug-file>`` to the output.38 39.. option:: --add-section <section=file>40 41 Add a section named ``<section>`` with the contents of ``<file>`` to the42 output. For ELF objects the section will be of type `SHT_NOTE`, if the name43 starts with ".note". Otherwise, it will have type `SHT_PROGBITS`. Can be44 specified multiple times to add multiple sections.45 46 For MachO objects, ``<section>`` must be formatted as47 ``<segment name>,<section name>``.48 49.. option:: --binary-architecture <arch>, -B50 51 Ignored for compatibility.52 53.. option:: --disable-deterministic-archives, -U54 55 Use real values for UIDs, GIDs and timestamps when updating archive member56 headers.57 58.. option:: --discard-all, -x59 60 Remove most local symbols not referenced by relocations from the output.61 Different file formats may limit this to a subset of the local symbols. For62 example, file and section symbols in ELF objects will not be discarded.63 Additionally, remove all debug sections.64 65.. option:: --dump-section <section>=<file>66 67 Dump the contents of section ``<section>`` into the file ``<file>``. Can be68 specified multiple times to dump multiple sections to different files.69 ``<file>`` is unrelated to the input and output files provided to70 :program:`llvm-objcopy` and as such the normal copying and editing71 operations will still be performed. No operations are performed on the sections72 prior to dumping them.73 74 For MachO objects, ``<section>`` must be formatted as75 ``<segment name>,<section name>``.76 77.. option:: --enable-deterministic-archives, -D78 79 Enable deterministic mode when copying archives, i.e. use 0 for archive member80 header UIDs, GIDs and timestamp fields. On by default.81 82.. option:: --extract-section <section>=<file>83 84 Extract the specified section ``<section>`` into the file ``<file>`` as a85 seperate object. Can be specified multiple times to extract multiple sections.86 ``<file>`` is unrelated to the input and output files provided to87 :program:`llvm-objcopy` and as such the normal copying and editing88 operations will still be performed. No operations are performed on the sections89 prior to dumping them.90 91.. option:: --globalize-symbol <symbol>92 93 Mark any defined symbols named ``<symbol>`` as global symbols in the output.94 Can be specified multiple times to mark multiple symbols.95 96.. option:: --globalize-symbols <filename>97 98 Read a list of names from the file ``<filename>`` and mark defined symbols with99 those names as global in the output. In the file, each line represents a single100 symbol, with leading and trailing whitespace ignored, as is anything following101 a '#'. Can be specified multiple times to read names from multiple files.102 103.. option:: --help, -h104 105 Print a summary of command line options.106 107.. option:: --keep-global-symbol <symbol>, -G108 109 Mark all symbols local in the output, except for symbols with the name110 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.111 112.. option:: --keep-global-symbols <filename>113 114 Mark all symbols local in the output, except for symbols named in the file115 ``<filename>``. In the file, each line represents a single symbol, with leading116 and trailing whitespace ignored, as is anything following a '#'. Can be117 specified multiple times to read names from multiple files.118 119.. option:: --localize-symbol <symbol>, -L120 121 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the122 output. Can be specified multiple times to mark multiple symbols as local.123 124.. option:: --localize-symbols <filename>125 126 Read a list of names from the file ``<filename>`` and mark defined non-common127 symbols with those names as local in the output. In the file, each line128 represents a single symbol, with leading and trailing whitespace ignored, as is129 anything following a '#'. Can be specified multiple times to read names from130 multiple files.131 132.. option:: --only-keep-debug133 134 Produce a debug file as the output that only preserves contents of sections135 useful for debugging purposes.136 137 For ELF objects, this removes the contents of `SHF_ALLOC` sections that are not138 `SHT_NOTE` by making them `SHT_NOBITS` and shrinking the program headers where139 possible.140 141.. option:: --only-section <section>, -j142 143 Remove all sections from the output, except for sections named ``<section>``.144 Can be specified multiple times to keep multiple sections.145 146 For MachO objects, ``<section>`` must be formatted as147 ``<segment name>,<section name>``.148 149.. option:: --redefine-sym <old>=<new>150 151 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified152 multiple times to rename multiple symbols.153 154.. option:: --redefine-syms <filename>155 156 Rename symbols in the output as described in the file ``<filename>``. In the157 file, each line represents a single symbol to rename, with the old name and new158 name separated by whitespace. Leading and trailing whitespace is ignored, as is159 anything following a '#'. Can be specified multiple times to read names from160 multiple files.161 162.. option:: --regex163 164 If specified, symbol and section names specified by other switches are treated165 as extended POSIX regular expression patterns.166 167.. option:: --remove-symbol-prefix <prefix>168 169 Remove ``<prefix>`` from the start of every symbol name. No-op for symbols that do170 not start with ``<prefix>``.171 172.. option:: --remove-section <section>, -R173 174 Remove the specified section from the output. Can be specified multiple times175 to remove multiple sections simultaneously.176 177 For MachO objects, ``<section>`` must be formatted as178 ``<segment name>,<section name>``.179 180.. option:: --set-section-alignment <section>=<align>181 182 Set the alignment of section ``<section>`` to ``<align>``. Can be specified183 multiple times to update multiple sections.184 185.. option:: --set-section-flags <section>=<flag>[,<flag>,...]186 187 Set section properties in the output of section ``<section>`` based on the188 specified ``<flag>`` values. Can be specified multiple times to update multiple189 sections.190 191 Supported flag names are `alloc`, `load`, `noload`, `readonly`, `exclude`,192 `debug`, `code`, `data`, `rom`, `share`, `contents`, `merge`, `strings`, and193 `large`. Not all flags are meaningful for all object file formats or target194 architectures.195 196 For ELF objects, the flags have the following effects:197 198 - `alloc` = add the `SHF_ALLOC` flag.199 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`200   section.201 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.202 - `exclude` = add the `SHF_EXCLUDE` flag.203 - `code` = add the `SHF_EXECINSTR` flag.204 - `merge` = add the `SHF_MERGE` flag.205 - `strings` = add the `SHF_STRINGS` flag.206 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`207   section.208 - `large` = add the `SHF_X86_64_LARGE` on x86_64; rejected if the target209   architecture is not x86_64.210 211 For COFF objects, the flags have the following effects:212 213 - `alloc` = add the `IMAGE_SCN_CNT_UNINITIALIZED_DATA` and `IMAGE_SCN_MEM_READ`214   flags, unless the `load` flag is specified.215 - `noload` = add the `IMAGE_SCN_LNK_REMOVE` and `IMAGE_SCN_MEM_READ` flags.216 - `readonly` = if this flag is not specified, add the `IMAGE_SCN_MEM_WRITE`217   flag.218 - `exclude` = add the `IMAGE_SCN_LNK_REMOVE` and `IMAGE_SCN_MEM_READ` flags.219 - `debug` = add the `IMAGE_SCN_CNT_INITIALIZED_DATA`,220   `IMAGE_SCN_MEM_DISCARDABLE` and  `IMAGE_SCN_MEM_READ` flags.221 - `code` = add the `IMAGE_SCN_CNT_CODE`, `IMAGE_SCN_MEM_EXECUTE` and222   `IMAGE_SCN_MEM_READ` flags.223 - `data` = add the `IMAGE_SCN_CNT_INITIALIZED_DATA` and `IMAGE_SCN_MEM_READ`224   flags.225 - `share` = add the `IMAGE_SCN_MEM_SHARED` and `IMAGE_SCN_MEM_READ` flags.226 227.. option:: --skip-symbol <symbol>228 229 Do not change the parameters of symbol ``<symbol>`` when executing other230 options that can change the symbol's name, binding or visibility.231 232.. option:: --skip-symbols <filename>233 234 Do not change the parameters of symbols named in the file ``<filename>`` when235 executing other options that can change the symbol's name, binding or236 visibility. In the file, each line represents a single symbol, with leading237 and trailing whitespace ignored, as is anything following a '#'.238 Can be specified multiple times to read names from multiple files.239 240.. option:: --strip-all-gnu241 242 Remove all symbols, debug sections and relocations from the output. This option243 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.244 245.. option:: --strip-all, -S246 247 For ELF objects, remove from the output all symbols and non-alloc sections not248 within segments, except for .gnu.warning, .ARM.attribute sections and the249 section name table.250 251 For COFF and Mach-O objects, remove all symbols, debug sections, and252 relocations from the output.253 254.. option:: --strip-debug, -g255 256 Remove all debug sections from the output.257 258.. option:: --strip-symbol <symbol>, -N259 260 Remove all symbols named ``<symbol>`` from the output. Can be specified261 multiple times to remove multiple symbols.262 263.. option:: --strip-symbols <filename>264 265 Remove all symbols whose names appear in the file ``<filename>``, from the266 output. In the file, each line represents a single symbol name, with leading267 and trailing whitespace ignored, as is anything following a '#'. Can be268 specified multiple times to read names from multiple files.269 270.. option:: --strip-unneeded-symbol <symbol>271 272 Remove from the output all symbols named ``<symbol>`` that are local or273 undefined and are not required by any relocation.274 275.. option:: --strip-unneeded-symbols <filename>276 277 Remove all symbols whose names appear in the file ``<filename>``, from the278 output, if they are local or undefined and are not required by any relocation.279 In the file, each line represents a single symbol name, with leading and280 trailing whitespace ignored, as is anything following a '#'. Can be specified281 multiple times to read names from multiple files.282 283.. option:: --strip-unneeded284 285 Remove from the output all local or undefined symbols that are not required by286 relocations. Also remove all debug sections.287 288.. option:: --update-section <name>=<file>289 290 Replace the contents of the section ``<name>`` with contents from the file291 ``<file>``. If the section ``<name>`` is part of a segment, the new contents292 cannot be larger than the existing section.293 294.. option:: --version, -V295 296 Display the version of the :program:`llvm-objcopy` executable.297 298.. option:: --wildcard, -w299 300  Allow wildcard syntax for symbol-related flags. On by default for301  section-related flags. Incompatible with --regex.302 303  Wildcard syntax allows the following special symbols:304 305  ====================== ========================= ==================306   Character              Meaning                   Equivalent307  ====================== ========================= ==================308  ``*``                  Any number of characters  ``.*``309  ``?``                  Any single character      ``.``310  ``\``                  Escape the next character ``\``311  ``[a-z]``              Character class           ``[a-z]``312  ``[!a-z]``, ``[^a-z]`` Negated character class   ``[^a-z]``313  ====================== ========================= ==================314 315  Additionally, starting a wildcard with '!' will prevent a match, even if316  another flag matches. For example ``-w -N '*' -N '!x'`` will strip all symbols317  except for ``x``.318 319  The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is320  the same as ``-w -N '!x' -N '*'``.321 322.. option:: @<FILE>323 324 Read command-line options and commands from response file `<FILE>`.325 326ELF-SPECIFIC OPTIONS327--------------------328 329The following options are implemented only for ELF objects. If used with other330objects, :program:`llvm-objcopy` will either emit an error or silently ignore331them.332 333.. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]334 335 Add a new symbol called ``<name>`` to the output symbol table, in the section336 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,337 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol338 properties. Accepted values are:339 340 - `global` = the symbol will have global binding.341 - `local` = the symbol will have local binding.342 - `weak` = the symbol will have weak binding.343 - `default` = the symbol will have default visibility.344 - `hidden` = the symbol will have hidden visibility.345 - `protected` = the symbol will have protected visibility.346 - `file` = the symbol will be an `STT_FILE` symbol.347 - `section` = the symbol will be an `STT_SECTION` symbol.348 - `object` = the symbol will be an `STT_OBJECT` symbol.349 - `function` = the symbol will be an `STT_FUNC` symbol.350 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.351 352 Additionally, the following flags are accepted but ignored: `debug`,353 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.354 355 Can be specified multiple times to add multiple symbols.356 357.. option:: --allow-broken-links358 359 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid360 section references. Any invalid sh_link fields will be set to zero.361 362.. option:: --change-section-lma \*{+-}<val>363 364 Shift LMA of non-zero-sized segments by ``<val>``.365 366.. option:: --change-section-address <section>{=+-}<val>, --adjust-section-vma367 368 Change the address of sections that match ``<section>`` pattern to the369 specified value, or apply ``+<val>``/``-<val>`` to the current value. Can be370 specified multiple times to specify multiple patterns. Each section is only371 modified by one ``--change-section-address`` argument. If a section name372 matches multiple patterns, the rightmost change applies. The object file needs373 to be of ET_REL type.374 375.. option:: --change-start <incr>, --adjust-start376 377 Add ``<incr>`` to the program's start address. Can be specified multiple378 times, in which case the values will be applied cumulatively.379 380.. option:: --compress-debug-sections [<format>]381 382 Compress DWARF debug sections in the output, using the specified format.383 Supported formats are ``zlib`` and ``zstd``. Use ``zlib`` if ``<format>`` is omitted.384 385.. option:: --compress-sections <section>=<format>386 387 Compress or decompress sections matched by ``<section>`` using the specified388 format. Supported formats are ``zlib`` and ``zstd``. Specify ``none`` for389 decompression. When a section is matched by multiple options, the last one390 wins. A wildcard ``<section>`` starting with '!' is disallowed.391 Sections within a segment cannot be (de)compressed.392 393.. option:: --decompress-debug-sections394 395 Decompress any compressed DWARF debug sections in the output.396 397.. option:: --discard-locals, -X398 399 Remove local symbols starting with ".L" not referenced by relocations from the output.400 401.. option:: --extract-dwo402 403 Remove all sections that are not DWARF .dwo sections from the output.404 405.. option:: --extract-main-partition406 407 Extract the main partition from the output.408 409.. option:: --extract-partition <name>410 411 Extract the named partition from the output.412 413.. option:: --gap-fill <value>414 415 For binary outputs, fill the gaps between sections with ``<value>`` instead416 of zero. The value must be an unsigned 8-bit integer.417 418.. option:: --input-target <format>, -I419 420 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of421 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt422 to determine the format automatically.423 424.. option:: --keep-file-symbols425 426 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.427 428.. option:: --keep-section <section>429 430 When removing sections from the output, do not remove sections named431 ``<section>``. Can be specified multiple times to keep multiple sections.432 433.. option:: --keep-symbol <symbol>, -K434 435 When removing symbols from the output, do not remove symbols named436 ``<symbol>``. Can be specified multiple times to keep multiple symbols.437 438.. option:: --keep-symbols <filename>439 440 When removing symbols from the output do not remove symbols named in the file441 ``<filename>``. In the file, each line represents a single symbol, with leading442 and trailing whitespace ignored, as is anything following a '#'. Can be443 specified multiple times to read names from multiple files.444 445.. option:: --localize-hidden446 447 Mark all symbols with hidden or internal visibility local in the output.448 449.. option:: --new-symbol-visibility <visibility>450 451 Specify the visibility of the symbols automatically created when using binary452 input or :option:`--add-symbol`. Valid options are:453 454 - `default`455 - `hidden`456 - `internal`457 - `protected`458 459 The default is `default`.460 461.. option:: --no-verify-note-sections462 463 When adding note sections, do not verify if the section format is valid.464 465.. option:: --output-target <format>, -O466 467 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list468 of valid ``<format>`` values. If unspecified, the output format is assumed to469 be the same as the value specified for :option:`--input-target` or the input470 file's format if that option is also unspecified.471 472.. option:: --pad-to <address>473 474 For binary outputs, pad the output to the load address ``<address>`` using a value475 of zero or the value specified by :option:`--gap-fill`.476 477.. option:: --prefix-alloc-sections <prefix>478 479 Add ``<prefix>`` to the front of the names of all allocatable sections in the480 output.481 482.. option:: --prefix-symbols <prefix>483 484 Add ``<prefix>`` to the front of every symbol name in the output.485 486.. option:: --preserve-dates, -p487 488 Preserve access and modification timestamps in the output.489 490.. option:: --remove-note [<name>/]<type>491 492 Remove notes of integer type ``<type>`` and name ``<name>`` from SHT_NOTE493 sections that are not in a segment. Can be specified multiple times.494 495.. option:: --rename-section <old>=<new>[,<flag>,...]496 497 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any498 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of499 supported flags. Can be specified multiple times to rename multiple sections.500 501.. option:: --set-section-type <section>=<type>502 503 Set the type of section ``<section>`` to the integer ``<type>``. Can be504 specified multiple times to update multiple sections.505 506.. option:: --set-start <addr>507 508 Set the start address of the output to ``<addr>``. Overrides any previously509 specified :option:`--change-start` or :option:`--adjust-start` options.510 511.. option:: --set-symbol-visibility <symbol>=<visibility>512 513 Change the visibility of a symbol to the specified value.514 515.. option:: --set-symbols-visibility <filename>=<visibility>516 517 Read a list of symbols from <filename> and change their visibility to the518 specified value. Visibility values: default, internal, hidden, protected.519 520.. option:: --split-dwo <dwo-file>521 522 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and523 ``<dwo-file>`` as the output file and no other options, and then with524 :option:`--strip-dwo` on the input file.525 526.. option:: --strip-dwo527 528 Remove all DWARF .dwo sections from the output.529 530.. option:: --strip-non-alloc531 532 Remove from the output all non-allocatable sections that are not within533 segments.534 535.. option:: --strip-sections536 537 Remove from the output all section headers and all section data not within538 segments. Note that many tools will not be able to use an object without539 section headers.540 541.. option:: --target <format>, -F542 543 Equivalent to :option:`--input-target` and :option:`--output-target` for the544 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``545 values.546 547.. option:: --verify-note-sections548 549 When adding note sections, verify if the section format is valid. On by550 default.551 552.. option:: --weaken-symbol <symbol>, -W553 554 Mark global symbols named ``<symbol>`` as weak symbols in the output. Can555 be specified multiple times to mark multiple symbols as weak.556 557.. option:: --weaken-symbols <filename>558 559 Read a list of names from the file ``<filename>`` and mark global symbols with560 those names as weak in the output. In the file, each line represents a single561 symbol, with leading and trailing whitespace ignored, as is anything following562 a '#'. Can be specified multiple times to read names from multiple files.563 564.. option:: --weaken565 566 Mark all defined global symbols as weak in the output.567 568MACH-O-SPECIFIC OPTIONS569-----------------------570 571.. option:: --keep-undefined572 573 Keep undefined symbols, even if they would otherwise be stripped.574 575COFF-SPECIFIC OPTIONS576---------------------577 578.. option:: --subsystem <name>[:<version>]579 580 Set the PE subsystem, and optionally subsystem version.581 582SUPPORTED FORMATS583-----------------584 585The following values are currently supported by :program:`llvm-objcopy` for the586:option:`--input-target`, :option:`--output-target`, and :option:`--target`587options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.588 589- `binary`590- `ihex`591- `elf32-i386`592- `elf32-x86-64`593- `elf64-x86-64`594- `elf32-iamcu`595- `elf32-littlearm`596- `elf64-aarch64`597- `elf64-littleaarch64`598- `elf32-littleriscv`599- `elf64-littleriscv`600- `elf32-powerpc`601- `elf32-powerpcle`602- `elf64-powerpc`603- `elf64-powerpcle`604- `elf32-bigmips`605- `elf32-ntradbigmips`606- `elf32-ntradlittlemips`607- `elf32-tradbigmips`608- `elf32-tradlittlemips`609- `elf64-tradbigmips`610- `elf64-tradlittlemips`611- `elf32-sparc`612- `elf32-sparcel`613- `elf32-hexagon`614- `elf32-loongarch`615- `elf64-loongarch`616- `elf64-s390`617 618The following formats are supported by :program:`llvm-objcopy` for the619:option:`--output-target` only:620 621- `srec`622 623Additionally, all targets except `binary`, `ihex`, and `srec` can have624`-freebsd` as a suffix.625 626BINARY INPUT AND OUTPUT627-----------------------628 629If `binary` is used as the value for :option:`--input-target`, the input file630will be embedded as a data section in an ELF relocatable object, with symbols631``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and632``_binary_<file_name>_size`` representing the start, end and size of the data,633where ``<file_name>`` is the path of the input file as specified on the command634line with non-alphanumeric characters converted to ``_``.635 636If `binary` is used as the value for :option:`--output-target`, the output file637will be a raw binary file, containing the memory image of the input file.638Symbols and relocation information will be discarded. The image will start at639the address of the first loadable section in the output.640 641EXIT STATUS642-----------643 644:program:`llvm-objcopy` exits with a non-zero exit code if there is an error.645Otherwise, it exits with code 0.646 647BUGS648----649 650To report bugs, please visit <https://github.com/llvm/llvm-project/labels/tools:llvm-objcopy/strip/>.651 652There is a known issue with :option:`--input-target` and :option:`--target`653causing only ``binary`` and ``ihex`` formats to have any effect. Other values654will be ignored and :program:`llvm-objcopy` will attempt to guess the input655format.656 657SEE ALSO658--------659 660:manpage:`llvm-strip(1)`661