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