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