LLVM-OBJCOPY(1)

πŸ’… NAME πŸ’…

llvm-objcopy β€” the object copying and editing tool, and yes she's that girl πŸŽ€

This is the LLVM manual, section 1, bestie β€” welcome to the group chat ✨


✨ SYNOPSIS ✨

llvm-objcopy [options] input [output]

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so picture this: llvm-objcopy is a tool that copies objects and manipulates them. In basic usage it literally just makes a semantic copy of the input over to the output. That's it. That's the vibe. 🌸

But the second you start specifying options? Oh she's working now β€” the output may get modified along the way, like for example by removing sections. Not me casually editing binaries on a Tuesday πŸ’…

Lowkey important stuff about files, so pay attention bestie 🫢
  • If no output file is specified, the input file is modified in-place. (Yes, in-place. On the original. Handle with care 😭)
  • If - is specified for the input file, the input is read from the program's standard input stream.
  • If - is specified for the output file, the output is written to the standard output stream of the program.

And here's the iconic part: if the input is an archive, any requested operations get applied to each archive member individually. Every single one. Fr fr, she goes member by member, no skipping πŸ”₯

Quick reality check tho: the tool is still in active development 🚧 β€” but in most scenarios it works as a drop-in replacement for GNU's objcopy. So like, she's growing, she's thriving, and she already eats in most situations πŸ‘‘

✨ GENERIC AND CROSS-PLATFORM OPTIONS ✨

Okay so these are the options that are either file-format agnostic or work across multiple formats. No cap, they’re the universal besties of the tool β€” let’s get into it πŸ’…

  • --add-gnu-debuglink <debug-file> β€” Add a .gnu_debuglink section for <debug-file> to the output.
  • --add-section <section=file> β€” Add a section named <section> with the contents of <file> to the output. For ELF objects the section will be of type SHT_NOTE, if the name starts with ".note". Otherwise, it will have type SHT_PROGBITS. Can be specified multiple times to add multiple sections.
    • For MachO objects, <section> must be formatted as <segment name>,<section name>.
  • --binary-architecture <arch>, -B β€” Ignored for compatibility.
  • --disable-deterministic-archives, -U β€” Use real values for UIDs, GIDs and timestamps when updating archive member headers.
  • --discard-all, -x β€” Remove most local symbols from the output. Different file formats may limit this to a subset of the local symbols. For example, file and section symbols in ELF objects will not be discarded. Additionally, remove all debug sections.
  • --dump-section <section>=<file> β€” Dump the contents of section <section> into the file <file>. Can be specified multiple times to dump multiple sections to different files. <file> is unrelated to the input and output files provided to llvm-objcopy and as such the normal copying and editing operations will still be performed. No operations are performed on the sections prior to dumping them.
    • For MachO objects, <section> must be formatted as <segment name>,<section name>.
  • --enable-deterministic-archives, -D β€” Enable deterministic mode when copying archives, i.e. use 0 for archive member header UIDs, GIDs and timestamp fields. On by default.
  • --help, -h β€” Print a summary of command line options.
  • --only-keep-debug β€” Produce a debug file as the output that only preserves contents of sections useful for debugging purposes.
    • For ELF objects, this removes the contents of SHF_ALLOC sections that are not SHT_NOTE by making them SHT_NOBITS and shrinking the program headers where possible.
  • --only-section <section>, -j β€” Remove all sections from the output, except for sections named <section>. Can be specified multiple times to keep multiple sections.
    • For MachO objects, <section> must be formatted as <segment name>,<section name>.
  • --redefine-sym <old>=<new> β€” Rename symbols called <old> to <new> in the output. Can be specified multiple times to rename multiple symbols.
  • --redefine-syms <filename> β€” Rename symbols in the output as described in the file <filename>. In the file, each line represents a single symbol to rename, with the old name and new name separated by whitespace. Leading and trailing whitespace is ignored, as is anything following a '#'. Can be specified multiple times to read names from multiple files.
  • --regex β€” If specified, symbol and section names specified by other switches are treated as extended POSIX regular expression patterns.
  • --remove-section <section>, -R β€” Remove the specified section from the output. Can be specified multiple times to remove multiple sections simultaneously.
    • For MachO objects, <section> must be formatted as <segment name>,<section name>.
  • --set-section-alignment <section>=<align> β€” Set the alignment of section <section> to <align>. Can be specified multiple times to update multiple sections.
  • --set-section-flags <section>=<flag>[,<flag>,...] β€” Set section properties in the output of section <section> based on the specified <flag> values. Can be specified multiple times to update multiple sections.
    • Supported flag names are alloc, load, noload, readonly, exclude, debug, code, data, rom, share, contents, merge and strings. Not all flags are meaningful for all object file formats.
    • For ELF objects, the flags have the following effects:
      • alloc = add the SHF_ALLOC flag.
      • load = if the section has SHT_NOBITS type, mark it as a SHT_PROGBITS section.
      • readonly = if this flag is not specified, add the SHF_WRITE flag.
      • exclude = add the SHF_EXCLUDE flag.
      • code = add the SHF_EXECINSTR flag.
      • merge = add the SHF_MERGE flag.
      • strings = add the SHF_STRINGS flag.
      • contents = if the section has SHT_NOBITS type, mark it as a SHT_PROGBITS section.
    • For COFF objects, the flags have the following effects:
      • alloc = add the IMAGE_SCN_CNT_UNINITIALIZED_DATA and IMAGE_SCN_MEM_READ flags, unless the load flag is specified.
      • noload = add the IMAGE_SCN_LNK_REMOVE and IMAGE_SCN_MEM_READ flags.
      • readonly = if this flag is not specified, add the IMAGE_SCN_MEM_WRITE flag.
      • exclude = add the IMAGE_SCN_LNK_REMOVE and IMAGE_SCN_MEM_READ flags.
      • debug = add the IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE and IMAGE_SCN_MEM_READ flags.
      • code = add the IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE and IMAGE_SCN_MEM_READ flags.
      • data = add the IMAGE_SCN_CNT_INITIALIZED_DATA and IMAGE_SCN_MEM_READ flags.
      • share = add the IMAGE_SCN_MEM_SHARED and IMAGE_SCN_MEM_READ flags.
  • --strip-all-gnu β€” Remove all symbols, debug sections and relocations from the output. This option is equivalent to GNU objcopy's --strip-all switch.
  • --strip-all, -S β€” For ELF objects, remove from the output all symbols and non-alloc sections not within segments, except for .gnu.warning, .ARM.attribute sections and the section name table.
    • For COFF and Mach-O objects, remove all symbols, debug sections, and relocations from the output.
  • --strip-debug, -g β€” Remove all debug sections from the output.
  • --strip-symbol <symbol>, -N β€” Remove all symbols named <symbol> from the output. Can be specified multiple times to remove multiple symbols.
  • --strip-symbols <filename> β€” Remove all symbols whose names appear in the file <filename>, from the output. In the file, each line represents a single symbol name, with leading and trailing whitespace ignored, as is anything following a '#'. Can be specified multiple times to read names from multiple files.
  • --strip-unneeded-symbol <symbol> β€” Remove from the output all symbols named <symbol> that are local or undefined and are not required by any relocation.
  • --strip-unneeded-symbols <filename> β€” Remove all symbols whose names appear in the file <filename>, from the output, if they are local or undefined and are not required by any relocation. In the file, each line represents a single symbol name, with leading and trailing whitespace ignored, as is anything following a '#'. Can be specified multiple times to read names from multiple files.
  • --strip-unneeded β€” Remove from the output all local or undefined symbols that are not required by relocations. Also remove all debug sections.
  • --update-section <name>=<file> β€” Replace the contents of the section <name> with contents from the file <file>. If the section <name> is part of a segment, the new contents cannot be larger than the existing section.
  • --version, -V β€” Display the version of the llvm-objcopy executable.
  • --wildcard, -w β€” Allow wildcard syntax for symbol-related flags. On by default for section-related flags. Incompatible with --regex.
    • Wildcard syntax allows the following special symbols:
      • * β€” Any number of characters. Equivalent: .*
      • ? β€” Any single character. Equivalent: .
      • \ β€” Escape the next character. Equivalent: \
      • [a-z] β€” Character class. Equivalent: [a-z]
      • [!a-z], [^a-z] β€” Negated character class. Equivalent: [^a-z]
    • Additionally, starting a wildcard with '!' will prevent a match, even if another flag matches. For example -w -N '*' -N '!x' will strip all symbols except for x.
    • The order of wildcards does not matter. For example, -w -N '*' -N '!x' is the same as -w -N '!x' -N '*'.
  • @<FILE> β€” Read command-line options and commands from response file <FILE>.

πŸ’… ELF-SPECIFIC OPTIONS πŸ’…

okay so these next ones are ELF-only, bestie. like, they're implemented just for ELF objects. if you use them with other object types, llvm-objcopy will either throw an error at you or just silently ignore them (rude, but okay). πŸ™ˆ

  • --add-symbol <name>=[<section>:]<value>[,<flags>] β€” adds a brand new symbol called <name> to the output symbol table, sitting in the section named <section>, with value <value>. if you don't specify <section>, the symbol gets added as an absolute symbol. the <flags> bit controls the symbol's properties β€” accepted values are:
    • global = the symbol will have global binding.
    • local = the symbol will have local binding.
    • weak = the symbol will have weak binding.
    • default = the symbol will have default visibility.
    • hidden = the symbol will have hidden visibility.
    • protected = the symbol will have protected visibility.
    • file = the symbol will be an STT_FILE symbol.
    • section = the symbol will be an STT_SECTION symbol.
    • object = the symbol will be an STT_OBJECT symbol.
    • function = the symbol will be an STT_FUNC symbol.
    • indirect-function = the symbol will be an STT_GNU_IFUNC symbol.

also, these flags are accepted but ignored (they're just there for the vibes): debug, constructor, warning, indirect, synthetic, unique-object, before.

you can specify this multiple times to add multiple symbols. 🫢

  • --allow-broken-links β€” lets llvm-objcopy remove sections even if doing so would leave behind invalid section references. any invalid sh_link fields get set to zero. it's giving "we're breaking the links but we're doing it on purpose." πŸ’€
  • --change-start <incr>, --adjust-start β€” adds <incr> to the program's start address. can be specified multiple times, and if you do, the values get applied cumulatively.
  • --compress-debug-sections [<format>] β€” compresses DWARF debug sections in the output, using whatever <format> you name. supported formats are zlib and zstd. if you omit <format>, it uses zlib. πŸ—œοΈ
  • --decompress-debug-sections β€” does the opposite, bestie: decompresses any compressed DWARF debug sections in the output.
  • --discard-locals, -X β€” removes local symbols starting with ".L" from the output. bye-bye little locals πŸ‘‹
  • --extract-dwo β€” removes all sections that aren't DWARF .dwo sections from the output.
  • --extract-main-partition β€” extracts the main partition from the output. main character energy, literally.
  • --extract-partition <name> β€” extracts the partition named <name> from the output.
  • --globalize-symbol <symbol> β€” marks any defined symbols named <symbol> as global symbols in the output. can be specified multiple times to mark multiple symbols. ✨
  • --globalize-symbols <filename> β€” reads a list of names from the file <filename> and marks defined symbols with those names as global in the output. in the file, each line is a single symbol, with leading and trailing whitespace ignored, and anything after a '#' ignored too. can be specified multiple times to read names from multiple files. πŸ“„
  • --input-target <format>, -I β€” reads the input as the specified format. check SUPPORTED FORMATS for the valid <format> values. if you don't specify it, llvm-objcopy will attempt to determine the format automatically. πŸ•΅οΈ
  • --keep-file-symbols β€” keeps symbols of type STT_FILE, even if they'd otherwise get stripped.
  • --keep-global-symbol <symbol>, -G β€” makes all symbols local in the output, except for symbols with the name <symbol>. can be specified multiple times to ignore multiple symbols.
  • --keep-global-symbols <filename> β€” makes all symbols local in the output, except for symbols named in the file <filename>. in the file, each line is a single symbol, with leading and trailing whitespace ignored, and anything after a '#' ignored too. can be specified multiple times to read names from multiple files.
  • --keep-section <section> β€” when removing sections from the output, does NOT remove sections named <section>. can be specified multiple times to keep multiple sections. πŸ›Ÿ
  • --keep-symbol <symbol>, -K β€” when removing symbols from the output, does NOT remove symbols named <symbol>. can be specified multiple times to keep multiple symbols.
  • --keep-symbols <filename> β€” when removing symbols from the output, does NOT remove symbols named in the file <filename>. in the file, each line is a single symbol, with leading and trailing whitespace ignored, and anything after a '#' ignored too. can be specified multiple times to read names from multiple files.
  • --localize-hidden β€” makes all symbols with hidden or internal visibility local in the output. πŸ™ˆ
  • --localize-symbol <symbol>, -L β€” marks any defined non-common symbol named <symbol> as a local symbol in the output. can be specified multiple times to mark multiple symbols as local.
  • --localize-symbols <filename> β€” reads a list of names from the file <filename> and marks defined non-common symbols with those names as local in the output. in the file, each line is a single symbol, with leading and trailing whitespace ignored, and anything after a '#' ignored too. can be specified multiple times to read names from multiple files.
  • --new-symbol-visibility <visibility> β€” specifies the visibility of the symbols that get automatically created when you use binary input or --add-symbol. valid options are:
    • default
    • hidden
    • internal
    • protected

the default is default. πŸ’«

  • --output-target <format>, -O β€” writes the output as the specified format. check SUPPORTED FORMATS for the valid <format> values. if unspecified, the output format is assumed to be the same as the value you gave for --input-target, or the input file's format if that option is also unspecified.
  • --prefix-alloc-sections <prefix> β€” adds <prefix> to the front of the names of all allocatable sections in the output.
  • --prefix-symbols <prefix> β€” adds <prefix> to the front of every symbol name in the output. πŸ’–
  • --preserve-dates, -p β€” preserves access and modification timestamps in the output. nostalgia preservation, iconic.
  • --rename-section <old>=<new>[,<flag>,...] β€” renames sections called <old> to <new> in the output, and applies any <flag> values you listed. see --set-section-flags for the list of supported flags. can be specified multiple times to rename multiple sections. πŸŽ€
  • --set-section-type <section>=<type> β€” sets the type of section <section> to the integer <type>. can be specified multiple times to update multiple sections.
  • --set-start-addr <addr> β€” sets the start address of the output to <addr>. this one overrides any previously specified --change-start or --adjust-start options. it said what it said. πŸ‘‘
  • --split-dwo <dwo-file> β€” equivalent to running llvm-objcopy with --extract-dwo and <dwo-file> as the output file and no other options, and then with --strip-dwo on the input file.
  • --strip-dwo β€” removes all DWARF .dwo sections from the output.
  • --strip-non-alloc β€” removes from the output all non-allocatable sections that aren't within segments.
  • --strip-sections β€” removes from the output all section headers and all section data not within segments.
⚠️ heads up bestie: many tools will NOT be able to use an object without section headers. this one's a real commitment.
  • --target <format>, -F β€” equivalent to --input-target and --output-target for the specified format. check SUPPORTED FORMATS for the valid <format> values.
  • --weaken-symbol <symbol>, -W β€” marks any global symbol named <symbol> as a weak symbol in the output. can be specified multiple times to mark multiple symbols as weak.
  • --weaken-symbols <filename> β€” reads a list of names from the file <filename> and marks global symbols with those names as weak in the output. in the file, each line is a single symbol, with leading and trailing whitespace ignored, and anything after a '#' ignored too. can be specified multiple times to read names from multiple files.
  • --weaken β€” marks all defined global symbols as weak in the output. every single one. no survivors.

🍎 MACH-O-SPECIFIC OPTIONS 🍎

  • --keep-undefined β€” keeps undefined symbols, even if they'd otherwise get stripped. (yes, this is the whole Mach-O section. she's short and she's slaying.)

πŸͺŸ COFF-SPECIFIC OPTIONS πŸͺŸ

  • --subsystem <name>[:<version>] β€” sets the PE subsystem, and optionally the subsystem version too.

🌈 SUPPORTED FORMATS 🌈

these are the values currently supported by llvm-objcopy for the --input-target, --output-target, and --target options. for GNU objcopy compatibility, literally all the values are bfdnames. iykyk. ✨

  • binary
  • ihex
  • elf32-i386
  • elf32-x86-64
  • elf64-x86-64
  • elf32-iamcu
  • elf32-littlearm
  • elf64-aarch64
  • elf64-littleaarch64
  • elf32-littleriscv
  • elf64-littleriscv
  • elf32-powerpc
  • elf32-powerpcle
  • elf64-powerpc
  • elf64-powerpcle
  • elf32-bigmips
  • elf32-ntradbigmips
  • elf32-ntradlittlemips
  • elf32-tradbigmips
  • elf32-tradlittlemips
  • elf64-tradbigmips
  • elf64-tradlittlemips
  • elf32-sparc
  • elf32-sparcel

and also, all targets except binary and ihex can have -freebsd as a suffix. so go off, add the suffix. πŸ’…


🧚 BINARY INPUT AND OUTPUT 🧚

input vibes

if binary is used as the value for --input-target, the input file gets embedded as a data section in an ELF relocatable object, with the symbols _binary_<file_name>_start, _binary_<file_name>_end, and _binary_<file_name>_size representing the start, end, and size of the data. here <file_name> is the path of the input file as you specified it on the command line, with non-alphanumeric characters converted to _. 🫢

output vibes

if binary is used as the value for --output-target, the output file will be a raw binary file containing the memory image of the input file. symbols and relocation information get discarded. the image will start at the address of the first loadable section in the output. 🌸


🚦 EXIT STATUS 🚦

llvm-objcopy exits with a non-zero exit code if there's an error. otherwise, it exits with code 0. slay. βœ…


πŸ› BUGS πŸ›

to report bugs, please visit https://github.com/llvm/llvm-project/labels/tools:llvm-objcopy/strip/.

⚠️ there's a known issue with --input-target and --target where only the binary and ihex formats actually have any effect. other values get ignored and llvm-objcopy will just attempt to guess the input format. not ideal, but that's the situation, bestie. 😭

πŸ‘€ SEE ALSO πŸ‘€

llvm-strip(1)


🌟 AUTHOR 🌟

maintained by the LLVM Team (https://llvm.org/). 🫑

okay so legal stuff, but make it cute πŸ’– β€” this whole thing is:

2003-2023, LLVM Project

that's the copyright right there, bestie. 2003 through 2023, the LLVM Project, all of it. no cap, they've been at this for two whole decades and it shows ✨


and that's the whole page, bestie!! you made it to the end, i'm literally so proud of you 🫢 go forth and llvm-objcopy responsibly, ok? slay πŸ’…

this icon of a manual page is LLVM-OBJCOPY(1), and the source/version tag on it is 17, dated 2023-12-01 β€” like, that's the vintage, that's the timestamp, that's the lore πŸ¦‹

πŸ“¦ where this page comes from