LLVM-OBJCOPY(1)

๐ŸŽ€ NAME

okay so, <rainbow>llvm-objcopy</rainbow> โ€” it's literally the object copying and editing tool ๐Ÿ’… that's the whole name, that's the whole vibe.


โœจ SYNOPSIS

llvm-objcopy [options] input [output]

that's it, that's the whole group chat invitation: some options, an input, and a maybe-output. ๐Ÿซถ


๐Ÿ’– DESCRIPTION

okay bestie, so <pink>llvm-objcopy</pink> is a tool to copy and manipulate objects โœจ. In basic usage โ€” like, no extra flags, just vibing โ€” it makes a semantic copy of the input to the output. no cap, that's the default main character energy.

but the moment you specify any options, the output may be modified along the way โ€” for example by removing sections. it's giving "glow-up on the way out the door" ๐Ÿ’….

now, the iconic little details, and yes you need to know them:

  • If no output file is specified, the input file is modified in-place ๐Ÿ˜ญ โ€” like, it edits the original. be aware, bestie.
  • 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 if the input is an archive, any requested operations will be applied to each archive member individually โœจ โ€” one by one, every single one, no skipping. periodt.

๐Ÿฆ‹ real talk: the tool is still in active development. but in most scenarios it works as a drop-in replacement for GNU's objcopy. so likeโ€ฆ slay, honestly ๐Ÿ‘‘.

โœจ GENERIC AND CROSS-PLATFORM OPTIONS โœจ

Bestie, these flags are either totally format-agnostic or they work across multiple file formats. Let's get into it ๐Ÿ’…

  • --add-gnu-debuglink <debug-file> โ€” Adds a .gnu_debuglink section for <debug-file> to the output. ๐ŸŽ€
  • --add-section <section=file> โ€” Adds 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'll have type SHT_PROGBITS. You can specify this 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. Literally just vibes ๐Ÿ˜Œ
  • --disable-deterministic-archives, -U โ€” Use real values for UIDs, GIDs and timestamps when updating archive member headers. No fake numbers here ๐Ÿ’…
  • --discard-all, -x โ€” Removes 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, it removes all debug sections. Bye-bye clutter โœจ
  • --dump-section <section>=<file> โ€” Dumps the contents of section <section> into the file <file>. You can specify this multiple times to dump multiple sections to different files. Note that <file> is unrelated to the input and output files provided to llvm-objcopy, so 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 โ€” Enables deterministic mode when copying archives, i.e. use 0 for archive member header UIDs, GIDs and timestamp fields. It's on by default, bestie. ๐Ÿ”ฅ
  • --help, -h โ€” Prints a summary of command line options. Your fave little helper ๐Ÿฅบ
  • --only-keep-debug โ€” Produces 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. Debug mode activated ๐Ÿ›
  • --only-section <section>, -j โ€” Removes all sections from the output except for sections named <section>. You can specify this multiple times to keep multiple sections. For MachO objects, <section> must be formatted as <segment name>,<section name>. Keep only the good stuff ๐Ÿ‘‘
  • --redefine-sym <old>=<new> โ€” Renames symbols called <old> to <new> in the output. Can be specified multiple times to rename multiple symbols. Glow-up for your symbols ๐Ÿ’ซ
  • --redefine-syms <filename> โ€” Renames 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. Regex girlies rise ๐Ÿงš
  • --remove-section <section>, -R โ€” Removes 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>. Yeet that section ๐Ÿ—‘๏ธ
  • --set-section-alignment <section>=<align> โ€” Sets the alignment of section <section> to <align>. Can be specified multiple times to update multiple sections. Alignment is self-care โœจ
  • --set-section-flags <section>=<flag>[,<flag>,...] โ€” Sets 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 โ€” Removes all symbols, debug sections and relocations from the output. This option is equivalent to GNU objcopyโ€™s --strip-all switch. Clean sweep ๐Ÿงน
  • --strip-all, -S โ€” For ELF objects, removes 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, removes all symbols, debug sections, and relocations from the output. Going full minimal โœจ
  • --strip-debug, -g โ€” Removes all debug sections from the output. Debug? Don't know her ๐Ÿ’…
  • --strip-symbol <symbol>, -N โ€” Removes all symbols named <symbol> from the output. Can be specified multiple times to remove multiple symbols. Bye bestie ๐Ÿ‘‹
  • --strip-symbols <filename> โ€” Removes 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> โ€” Removes from the output all symbols named <symbol> that are local or undefined and are not required by any relocation. Unneeded? Not on my watch ๐Ÿšฎ
  • --strip-unneeded-symbols <filename> โ€” Removes 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 โ€” Removes from the output all local or undefined symbols that are not required by relocations. Also removes all debug sections. Glow-up by subtraction ๐Ÿ’–
  • --update-section <name>=<file> โ€” Replaces 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. Upgrade time ๐Ÿ”„
  • --version, -V โ€” Displays the version of the llvm-objcopy executable. Know your tools ๐Ÿ› ๏ธ
  • --wildcard, -w โ€” Allows 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 to .*
  • ? โ€” Any single character โ€” equivalent to .
  • \ โ€” Escape the next character
  • [a-z] โ€” Character class โ€” equivalent to [a-z]
  • [!a-z], [^a-z] โ€” Negated character class โ€” equivalent to [^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 '*'. Wildcard queen ๐Ÿ‘‘

  • @<FILE> โ€” Reads command-line options and commands from response file <FILE>. File inception, but make it cute ๐ŸŽ€

๐Ÿ’œ ELF-SPECIFIC OPTIONS ๐Ÿ’œ

Okay bestie, real talk: everything in this whole section is ELF-only. Like, these options only work on ELF objects. Use them on anything else and llvm-objcopy will either throw a whole error at you or just silently ignore you (rude, but okay ๐Ÿ’€).

  • --add-symbol <name>=[<section>:]<value>[,<flags>] โ€” Adds a brand new symbol called <name> to the output symbol table, living in the section named <section>, with the value <value>. If you don't give a <section>, the symbol gets added as an absolute symbol โ€” main character energy, belongs to no section โœจ. The <flags> control 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 get accepted but straight up ignored (they're just there for the vibes, no cap): debug, constructor, warning, indirect, synthetic, unique-object, before.

Pro tip: you can specify this multiple times to add multiple symbols ๐Ÿซถ.

  • --allow-broken-links โ€” Lets llvm-objcopy remove sections even if that would leave invalid section references behind. Any invalid sh_link fields get set to zero. Basically "yes I know the links are broken, do it anyway" ๐Ÿ’….
  • --change-start <incr>, --adjust-start โ€” Adds <incr> to the program's start address. Specify it multiple times and the values stack cumulatively ๐Ÿ”ฅ.
  • --compress-debug-sections [<format>] โ€” Compresses DWARF debug sections in the output using the given format. Only supported format is zlib. If you omit <format>, it uses zlib. Iconic, honestly.
  • --decompress-debug-sections โ€” Does the reverse: decompresses any compressed DWARF debug sections in the output ๐Ÿฆ‹.
  • --discard-locals, -X โ€” Removes local symbols starting with .L from the output. Bye girl ๐Ÿ‘‹.
  • --extract-dwo โ€” Removes all sections that aren't DWARF .dwo sections from the output.
  • --extract-main-partition โ€” Extracts the main partition from the output.
  • --extract-partition <name> โ€” Extracts the partition named <name> from the output.
  • --globalize-symbol <symbol> โ€” Marks any defined symbols named <symbol> as globals in the output. Specify it multiple times to mark multiple symbols โญ.
  • --globalize-symbols <filename> โ€” Reads a list of names from <filename> and marks defined symbols with those names as global in the output. In the file, each line is one symbol โ€” leading and trailing whitespace is ignored, and so is anything after a #. Specify it 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 one, llvm-objcopy will try to figure out the format automatically. It's giving detective energy ๐Ÿ”.
  • --keep-file-symbols โ€” Keeps symbols of type STT_FILE, even if they'd otherwise get stripped. Protect them at all costs ๐ŸŽ€.
  • --keep-global-symbol <symbol>, -G โ€” Makes all symbols local in the output except the ones named <symbol>. Specify it multiple times to spare multiple symbols.
  • --keep-global-symbols <filename> โ€” Makes all symbols local in the output, except the ones named in the file <filename>. In the file, each line is one symbol โ€” leading and trailing whitespace is ignored, and so is anything after a #. Specify it multiple times to read names from multiple files.
  • --keep-section <section> โ€” When removing sections from the output, don't remove sections named <section>. Specify it multiple times to keep multiple sections ๐Ÿ’–.
  • --keep-symbol <symbol>, -K โ€” When removing symbols from the output, don't remove symbols named <symbol>. Specify it multiple times to keep multiple symbols.
  • --keep-symbols <filename> โ€” When removing symbols from the output, don't remove symbols named in the file <filename>. In the file, each line is one symbol โ€” leading and trailing whitespace is ignored, and so is anything after a #. Specify it multiple times to read names from multiple files.
  • --localize-hidden โ€” Makes every symbol with hidden or internal visibility local in the output. They're not like other symbols, they stay home ๐Ÿ™ˆ.
  • --localize-symbol <symbol>, -L โ€” Marks any defined non-common symbol named <symbol> as a local symbol in the output. Specify it multiple times to mark multiple symbols as local.
  • --localize-symbols <filename> โ€” Reads a list of names from <filename> and marks defined non-common symbols with those names as local in the output. In the file, each line is one symbol โ€” leading and trailing whitespace is ignored, and so is anything after a #. Specify it multiple times to read names from multiple files.
  • --new-symbol-visibility <visibility> โ€” Sets the visibility of 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 you don't specify one, the output format is assumed to be whatever you gave to --input-target, or the input file's own format if that option was also left out. It just inherits, honestly ๐Ÿ’….
  • --prefix-alloc-sections <prefix> โ€” Sticks <prefix> at the front of the names of all allocatable sections in the output.
  • --prefix-symbols <prefix> โ€” Sticks <prefix> at the front of every single symbol name in the output. Everyone gets a little name tag ๐ŸŽ€.
  • --preserve-dates, -p โ€” Preserves access and modification timestamps in the output. Time is a construct but okay โฐ.
  • --rename-section <old>=<new>[,<flag>,...] โ€” Renames sections called <old> to <new> in the output, and applies any <flag> values you list. Check --set-section-flags for the supported flags. Specify it multiple times to rename multiple sections ๐Ÿฆ‹.
  • --set-section-type <section>=<type> โ€” Sets the type of section <section> to the integer <type>. Specify it multiple times to update multiple sections.
  • --set-start-addr <addr> โ€” Sets the start address of the output to <addr>. This overrides any --change-start or --adjust-start options you specified earlier โ€” it's the main character, it wins ๐Ÿ‘‘.
  • --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 running it with --strip-dwo on the input file. Two-in-one moment โœจ.
  • --strip-dwo โ€” Removes all DWARF .dwo sections from the output.
  • --strip-non-alloc โ€” Removes from the output all non-allocatable sections that aren't inside segments.
  • --strip-sections โ€” Removes from the output all section headers and all section data that isn't within segments.
Heads up bestie: lots of tools will not be able to use an object that has no section headers. Like, it's genuinely a problem, not a cute aesthetic choice ๐Ÿ’€.
  • --target <format>, -F โ€” Equivalent to setting both --input-target and --output-target to 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. Specify it multiple times to mark multiple symbols as weak ๐Ÿ“.
  • --weaken-symbols <filename> โ€” Reads a list of names from <filename> and marks global symbols with those names as weak in the output. In the file, each line is one symbol โ€” leading and trailing whitespace is ignored, and so is anything after a #. Specify it multiple times to read names from multiple files.
  • --weaken โ€” Marks all defined global symbols as weak in the output. Everybody softens up ๐Ÿซถ.

๐ŸŽ MACH-O-SPECIFIC OPTIONS ๐ŸŽ

  • --keep-undefined โ€” Keeps undefined symbols, even if they'd otherwise get stripped. Clingy but make it valid ๐Ÿ’….

โ˜• COFF-SPECIFIC OPTIONS โ˜•

  • --subsystem <name>[:<version>] โ€” Sets the PE subsystem, and optionally the subsystem version too. Fancy โœจ.

๐ŸŒˆ SUPPORTED FORMATS ๐ŸŒˆ

These are the values llvm-objcopy currently supports for the --input-target, --output-target, and --target options. For GNU objcopy compatibility, 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

Also, literally every target except binary and ihex can have -freebsd as a suffix. Slay ๐Ÿงš.


๐Ÿงš BINARY INPUT AND OUTPUT ๐Ÿงš

Okay so if binary is the value for --input-target, the input file gets embedded as a data section inside an ELF relocatable object. It comes with three 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 exactly as you typed it on the command line, except every non-alphanumeric character gets converted to _. Nature is healing ๐ŸŒธ.

If binary is the value for --output-target, the output file becomes a raw binary file containing the memory image of the input file. Symbols and relocation information? Discarded. Gone. Not invited ๐Ÿ’€. The image starts 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. Simple as that, bestie ๐Ÿ’–.


๐Ÿ’€ BUGS ๐Ÿ’€

To report bugs, please visit <https://github.com/llvm/llvm-project/labels/tools:llvm-objcopy/strip/>. Do it, the maintainers love hearing from you ๐Ÿซถ.

There's a known issue where --input-target and --target only actually have any effect for the binary and ihex formats. Every other value gets ignored and llvm-objcopy will just try to guess the input format instead. Not me being fooled by a flag that does nothing ๐Ÿ˜ญ.

๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Maintained by the LLVM Team (<https://llvm.org/>).

2003-2023, LLVM Project

Like, that's the whole copyright block bestie โ€” short and sweet, just the years and the name, no cap. Respect the OGs who've been holding it down since 2003 ๐Ÿ’–


okay that's genuinely the entire page, we're done!! ๐Ÿฆ‹ huge slay for making it all the way through, you ate that fr fr ๐Ÿ‘‘

so this diva of a manpage is <italic>LLVM-OBJCOPY(1)</italic> โ€” yeah she's a section 1 girlie, main character energy โ€” and she's rocking version 15 of the docs, dated 2023-07-14 โœจ that's the source, the version, and the date all in one cute little bow ๐ŸŽ€ take it, screenshot it, cite it, whatever, it's yours now ๐Ÿซถ

now go objcopy something iconic ๐Ÿ’…๐Ÿ’œ

๐Ÿ“ฆ where this page comes from