1llvm-objcopy - object copying and editing tool 2============================================== 3 4.. program:: llvm-objcopy 5 6SYNOPSIS 7-------- 8 9:program:`llvm-objcopy` [*options*] *input* [*output*] 10 11DESCRIPTION 12----------- 13 14:program:`llvm-objcopy` is a tool to copy and manipulate objects. In basic 15usage, it makes a semantic copy of the input to the output. If any options are 16specified, 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 "-" is 19specified for the input file, the input is read from the program's standard 20input stream. If "-" is specified for the output file, the output is written to 21the standard output stream of the program. 22 23If the input is an archive, any requested operations will be applied to each 24archive member individually. 25 26The tool is still in active development, but in most scenarios it works as a 27drop-in replacement for GNU's :program:`objcopy`. 28 29GENERIC AND CROSS-PLATFORM OPTIONS 30---------------------------------- 31 32The following options are either agnostic of the file format, or apply to 33multiple 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 the 42 output. For ELF objects the section will be of type `SHT_NOTE`, if the name 43 starts with ".note". Otherwise, it will have type `SHT_PROGBITS`. Can be 44 specified multiple times to add multiple sections. 45 46 For MachO objects, ``<section>`` must be formatted as 47 ``<segment name>,<section name>``. 48 49.. option:: --binary-architecture <arch>, -B 50 51 Ignored for compatibility. 52 53.. option:: --disable-deterministic-archives, -U 54 55 Use real values for UIDs, GIDs and timestamps when updating archive member 56 headers. 57 58.. option:: --discard-all, -x 59 60 Remove most local symbols from the output. Different file formats may limit 61 this to a subset of the local symbols. For example, file and section symbols in 62 ELF objects will not be discarded. 63 64.. option:: --dump-section <section>=<file> 65 66 Dump the contents of section ``<section>`` into the file ``<file>``. Can be 67 specified multiple times to dump multiple sections to different files. 68 ``<file>`` is unrelated to the input and output files provided to 69 :program:`llvm-objcopy` and as such the normal copying and editing 70 operations will still be performed. No operations are performed on the sections 71 prior to dumping them. 72 73 For MachO objects, ``<section>`` must be formatted as 74 ``<segment name>,<section name>``. 75 76.. option:: --enable-deterministic-archives, -D 77 78 Enable deterministic mode when copying archives, i.e. use 0 for archive member 79 header UIDs, GIDs and timestamp fields. On by default. 80 81.. option:: --help, -h 82 83 Print a summary of command line options. 84 85.. option:: --only-keep-debug 86 87 Produce a debug file as the output that only preserves contents of sections 88 useful for debugging purposes. 89 90 For ELF objects, this removes the contents of `SHF_ALLOC` sections that are not 91 `SHT_NOTE` by making them `SHT_NOBITS` and shrinking the program headers where 92 possible. 93 94.. option:: --only-section <section>, -j 95 96 Remove all sections from the output, except for sections named ``<section>``. 97 Can be specified multiple times to keep multiple sections. 98 99 For MachO objects, ``<section>`` must be formatted as 100 ``<segment name>,<section name>``. 101 102.. option:: --redefine-sym <old>=<new> 103 104 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified 105 multiple times to rename multiple symbols. 106 107.. option:: --redefine-syms <filename> 108 109 Rename symbols in the output as described in the file ``<filename>``. In the 110 file, each line represents a single symbol to rename, with the old name and new 111 name separated by whitespace. Leading and trailing whitespace is ignored, as is 112 anything following a '#'. Can be specified multiple times to read names from 113 multiple files. 114 115.. option:: --regex 116 117 If specified, symbol and section names specified by other switches are treated 118 as extended POSIX regular expression patterns. 119 120.. option:: --remove-section <section>, -R 121 122 Remove the specified section from the output. Can be specified multiple times 123 to remove multiple sections simultaneously. 124 125 For MachO objects, ``<section>`` must be formatted as 126 ``<segment name>,<section name>``. 127 128.. option:: --set-section-alignment <section>=<align> 129 130 Set the alignment of section ``<section>`` to `<align>``. Can be specified 131 multiple times to update multiple sections. 132 133.. option:: --strip-all-gnu 134 135 Remove all symbols, debug sections and relocations from the output. This option 136 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch. 137 138.. option:: --strip-all, -S 139 140 For ELF objects, remove from the output all symbols and non-alloc sections not 141 within segments, except for .gnu.warning, .ARM.attribute sections and the 142 section name table. 143 144 For COFF and Mach-O objects, remove all symbols, debug sections, and 145 relocations from the output. 146 147.. option:: --strip-debug, -g 148 149 Remove all debug sections from the output. 150 151.. option:: --strip-symbol <symbol>, -N 152 153 Remove all symbols named ``<symbol>`` from the output. Can be specified 154 multiple times to remove multiple symbols. 155 156.. option:: --strip-symbols <filename> 157 158 Remove all symbols whose names appear in the file ``<filename>``, from the 159 output. In the file, each line represents a single symbol name, with leading 160 and trailing whitespace ignored, as is anything following a '#'. Can be 161 specified multiple times to read names from multiple files. 162 163.. option:: --strip-unneeded-symbol <symbol> 164 165 Remove from the output all symbols named ``<symbol>`` that are local or 166 undefined and are not required by any relocation. 167 168.. option:: --strip-unneeded-symbols <filename> 169 170 Remove all symbols whose names appear in the file ``<filename>``, from the 171 output, if they are local or undefined and are not required by any relocation. 172 In the file, each line represents a single symbol name, with leading and 173 trailing whitespace ignored, as is anything following a '#'. Can be specified 174 multiple times to read names from multiple files. 175 176.. option:: --strip-unneeded 177 178 Remove from the output all local or undefined symbols that are not required by 179 relocations. Also remove all debug sections. 180 181.. option:: --version, -V 182 183 Display the version of the :program:`llvm-objcopy` executable. 184 185.. option:: @<FILE> 186 187 Read command-line options and commands from response file `<FILE>`. 188 189.. option:: --wildcard, -w 190 191 Allow wildcard syntax for symbol-related flags. On by default for 192 section-related flags. Incompatible with --regex. 193 194 Wildcard syntax allows the following special symbols: 195 196 ====================== ========================= ================== 197 Character Meaning Equivalent 198 ====================== ========================= ================== 199 ``*`` Any number of characters ``.*`` 200 ``?`` Any single character ``.`` 201 ``\`` Escape the next character ``\`` 202 ``[a-z]`` Character class ``[a-z]`` 203 ``[!a-z]``, ``[^a-z]`` Negated character class ``[^a-z]`` 204 ====================== ========================= ================== 205 206 Additionally, starting a wildcard with '!' will prevent a match, even if 207 another flag matches. For example ``-w -N '*' -N '!x'`` will strip all symbols 208 except for ``x``. 209 210 The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is 211 the same as ``-w -N '!x' -N '*'``. 212 213COFF-SPECIFIC OPTIONS 214--------------------- 215 216The following options are implemented only for COFF objects. If used with other 217objects, :program:`llvm-objcopy` will either emit an error or silently ignore 218them. 219 220ELF-SPECIFIC OPTIONS 221-------------------- 222 223The following options are implemented only for ELF objects. If used with other 224objects, :program:`llvm-objcopy` will either emit an error or silently ignore 225them. 226 227.. option:: --add-symbol <name>=[<section>:]<value>[,<flags>] 228 229 Add a new symbol called ``<name>`` to the output symbol table, in the section 230 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified, 231 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol 232 properties. Accepted values are: 233 234 - `global` = the symbol will have global binding. 235 - `local` = the symbol will have local binding. 236 - `weak` = the symbol will have weak binding. 237 - `default` = the symbol will have default visibility. 238 - `hidden` = the symbol will have hidden visibility. 239 - `protected` = the symbol will have protected visibility. 240 - `file` = the symbol will be an `STT_FILE` symbol. 241 - `section` = the symbol will be an `STT_SECTION` symbol. 242 - `object` = the symbol will be an `STT_OBJECT` symbol. 243 - `function` = the symbol will be an `STT_FUNC` symbol. 244 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol. 245 246 Additionally, the following flags are accepted but ignored: `debug`, 247 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`. 248 249 Can be specified multiple times to add multiple symbols. 250 251.. option:: --allow-broken-links 252 253 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid 254 section references. Any invalid sh_link fields will be set to zero. 255 256.. option:: --build-id-link-dir <dir> 257 258 Set the directory used by :option:`--build-id-link-input` and 259 :option:`--build-id-link-output`. 260 261.. option:: --build-id-link-input <suffix> 262 263 Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory 264 specified by :option:`--build-id-link-dir`. The path used is derived from the 265 hex build ID. 266 267.. option:: --build-id-link-output <suffix> 268 269 Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory 270 specified by :option:`--build-id-link-dir`. The path used is derived from the 271 hex build ID. 272 273.. option:: --change-start <incr>, --adjust-start 274 275 Add ``<incr>`` to the program's start address. Can be specified multiple 276 times, in which case the values will be applied cumulatively. 277 278.. option:: --compress-debug-sections [<style>] 279 280 Compress DWARF debug sections in the output, using the specified style. 281 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is 282 specified. 283 284.. option:: --decompress-debug-sections 285 286 Decompress any compressed DWARF debug sections in the output. 287 288.. option:: --discard-locals, -X 289 290 Remove local symbols starting with ".L" from the output. 291 292.. option:: --extract-dwo 293 294 Remove all sections that are not DWARF .dwo sections from the output. 295 296.. option:: --extract-main-partition 297 298 Extract the main partition from the output. 299 300.. option:: --extract-partition <name> 301 302 Extract the named partition from the output. 303 304.. option:: --globalize-symbol <symbol> 305 306 Mark any defined symbols named ``<symbol>`` as global symbols in the output. 307 Can be specified multiple times to mark multiple symbols. 308 309.. option:: --globalize-symbols <filename> 310 311 Read a list of names from the file ``<filename>`` and mark defined symbols with 312 those names as global in the output. In the file, each line represents a single 313 symbol, with leading and trailing whitespace ignored, as is anything following 314 a '#'. Can be specified multiple times to read names from multiple files. 315 316.. option:: --input-target <format>, -I 317 318 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of 319 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt 320 to determine the format automatically. 321 322.. option:: --keep-file-symbols 323 324 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped. 325 326.. option:: --keep-global-symbol <symbol> 327 328 Make all symbols local in the output, except for symbols with the name 329 ``<symbol>``. Can be specified multiple times to ignore multiple symbols. 330 331.. option:: --keep-global-symbols <filename> 332 333 Make all symbols local in the output, except for symbols named in the file 334 ``<filename>``. In the file, each line represents a single symbol, with leading 335 and trailing whitespace ignored, as is anything following a '#'. Can be 336 specified multiple times to read names from multiple files. 337 338.. option:: --keep-section <section> 339 340 When removing sections from the output, do not remove sections named 341 ``<section>``. Can be specified multiple times to keep multiple sections. 342 343.. option:: --keep-symbol <symbol>, -K 344 345 When removing symbols from the output, do not remove symbols named 346 ``<symbol>``. Can be specified multiple times to keep multiple symbols. 347 348.. option:: --keep-symbols <filename> 349 350 When removing symbols from the output do not remove symbols named in the file 351 ``<filename>``. In the file, each line represents a single symbol, with leading 352 and trailing whitespace ignored, as is anything following a '#'. Can be 353 specified multiple times to read names from multiple files. 354 355.. option:: --localize-hidden 356 357 Make all symbols with hidden or internal visibility local in the output. 358 359.. option:: --localize-symbol <symbol>, -L 360 361 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the 362 output. Can be specified multiple times to mark multiple symbols as local. 363 364.. option:: --localize-symbols <filename> 365 366 Read a list of names from the file ``<filename>`` and mark defined non-common 367 symbols with those names as local in the output. In the file, each line 368 represents a single symbol, with leading and trailing whitespace ignored, as is 369 anything following a '#'. Can be specified multiple times to read names from 370 multiple files. 371 372.. option:: --new-symbol-visibility <visibility> 373 374 Specify the visibility of the symbols automatically created when using binary 375 input or :option:`--add-symbol`. Valid options are: 376 377 - `default` 378 - `hidden` 379 - `internal` 380 - `protected` 381 382 The default is `default`. 383 384.. option:: --output-target <format>, -O 385 386 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list 387 of valid ``<format>`` values. If unspecified, the output format is assumed to 388 be the same as the input file's format. 389 390.. option:: --prefix-alloc-sections <prefix> 391 392 Add ``<prefix>`` to the front of the names of all allocatable sections in the 393 output. 394 395.. option:: --prefix-symbols <prefix> 396 397 Add ``<prefix>`` to the front of every symbol name in the output. 398 399.. option:: --preserve-dates, -p 400 401 Preserve access and modification timestamps in the output. 402 403.. option:: --rename-section <old>=<new>[,<flag>,...] 404 405 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any 406 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of 407 supported flags. Can be specified multiple times to rename multiple sections. 408 409.. option:: --set-section-flags <section>=<flag>[,<flag>,...] 410 411 Set section properties in the output of section ``<section>`` based on the 412 specified ``<flag>`` values. Can be specified multiple times to update multiple 413 sections. 414 415 Following is a list of supported flags and their effects: 416 417 - `alloc` = add the `SHF_ALLOC` flag. 418 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS` 419 section. 420 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag. 421 - `code` = add the `SHF_EXECINSTR` flag. 422 - `merge` = add the `SHF_MERGE` flag. 423 - `strings` = add the `SHF_STRINGS` flag. 424 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS` 425 section. 426 427 The following flags are also accepted, but are ignored for GNU compatibility: 428 `noload`, `debug`, `data`, `rom`, `share`. 429 430.. option:: --set-start-addr <addr> 431 432 Set the start address of the output to ``<addr>``. Overrides any previously 433 specified :option:`--change-start` or :option:`--adjust-start` options. 434 435.. option:: --split-dwo <dwo-file> 436 437 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and 438 ``<dwo-file>`` as the output file and no other options, and then with 439 :option:`--strip-dwo` on the input file. 440 441.. option:: --strip-dwo 442 443 Remove all DWARF .dwo sections from the output. 444 445.. option:: --strip-non-alloc 446 447 Remove from the output all non-allocatable sections that are not within 448 segments. 449 450.. option:: --strip-sections 451 452 Remove from the output all section headers and all section data not within 453 segments. Note that many tools will not be able to use an object without 454 section headers. 455 456.. option:: --target <format>, -F 457 458 Equivalent to :option:`--input-target` and :option:`--output-target` for the 459 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>`` 460 values. 461 462.. option:: --weaken-symbol <symbol>, -W 463 464 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can 465 be specified multiple times to mark multiple symbols as weak. 466 467.. option:: --weaken-symbols <filename> 468 469 Read a list of names from the file ``<filename>`` and mark global symbols with 470 those names as weak in the output. In the file, each line represents a single 471 symbol, with leading and trailing whitespace ignored, as is anything following 472 a '#'. Can be specified multiple times to read names from multiple files. 473 474.. option:: --weaken 475 476 Mark all defined global symbols as weak in the output. 477 478SUPPORTED FORMATS 479----------------- 480 481The following values are currently supported by :program:`llvm-objcopy` for the 482:option:`--input-target`, :option:`--output-target`, and :option:`--target` 483options. For GNU :program:`objcopy` compatibility, the values are all bfdnames. 484 485- `binary` 486- `ihex` 487- `elf32-i386` 488- `elf32-x86-64` 489- `elf64-x86-64` 490- `elf32-iamcu` 491- `elf32-littlearm` 492- `elf64-aarch64` 493- `elf64-littleaarch64` 494- `elf32-littleriscv` 495- `elf64-littleriscv` 496- `elf32-powerpc` 497- `elf32-powerpcle` 498- `elf64-powerpc` 499- `elf64-powerpcle` 500- `elf32-bigmips` 501- `elf32-ntradbigmips` 502- `elf32-ntradlittlemips` 503- `elf32-tradbigmips` 504- `elf32-tradlittlemips` 505- `elf64-tradbigmips` 506- `elf64-tradlittlemips` 507- `elf32-sparc` 508- `elf32-sparcel` 509 510Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a 511suffix. 512 513BINARY INPUT AND OUTPUT 514----------------------- 515 516If `binary` is used as the value for :option:`--input-target`, the input file 517will be embedded as a data section in an ELF relocatable object, with symbols 518``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and 519``_binary_<file_name>_size`` representing the start, end and size of the data, 520where ``<file_name>`` is the path of the input file as specified on the command 521line with non-alphanumeric characters converted to ``_``. 522 523If `binary` is used as the value for :option:`--output-target`, the output file 524will be a raw binary file, containing the memory image of the input file. 525Symbols and relocation information will be discarded. The image will start at 526the address of the first loadable section in the output. 527 528EXIT STATUS 529----------- 530 531:program:`llvm-objcopy` exits with a non-zero exit code if there is an error. 532Otherwise, it exits with code 0. 533 534BUGS 535---- 536 537To report bugs, please visit <http://llvm.org/bugs/>. 538 539There is a known issue with :option:`--input-target` and :option:`--target` 540causing only ``binary`` and ``ihex`` formats to have any effect. Other values 541will be ignored and :program:`llvm-objcopy` will attempt to guess the input 542format. 543 544SEE ALSO 545-------- 546 547:manpage:`llvm-strip(1)` 548