LLVM-OBJCOPY(1)

πŸ’– LLVM-OBJCOPY(1) πŸ’–

okay bestie, so this is the tea on llvm-objcopy, from the LLVM manual page gang. it's an object copying and editing tool and honestly? it ate. let's get into it 🫢


✨ NAME ✨

llvm-objcopy β€” object copying and editing tool


πŸ¦‹ SYNOPSIS πŸ¦‹

llvm-objcopy [options] input [output]

🌸 DESCRIPTION 🌸

so like, llvm-objcopy is a tool to copy and manipulate objects. in basic usage, it makes a semantic copy of the input to the output. and if you specify any options? the output may be modified along the way β€” like, for example, by removing sections. it's giving glow-up makeover energy ✨

now the important deets, no cap:

  • if you don't specify an output file, the input file gets modified in-place. yes bestie, it edits itself. iconic behavior πŸ’…
  • 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 a lil plot twist: if the input is an archive, then any requested operations get applied to each archive member individually. one by one. individually. periodt. πŸ‘‘

real talk though β€” the tool is still in active development πŸ”§, but in most scenarios it works as a drop-in replacement for GNU's objcopy. so like, lowkey you can just swap it in and vibe 😌

more parts coming, don't go anywhere bestie πŸ’–

GENERIC AND CROSS-PLATFORM OPTIONS

okay bestie, these next ones are the glow-up options that work across file formats or just don't care about the format at all. let's go πŸ’…

  • --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 drop 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. πŸ’€
  • --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. ✨
  • --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 bestie, so these ones are ELF-only. If you try them on some other kind of object, llvm-objcopy will either throw an error at you or just silently ignore them β€” it's giving "not mad, just disappointed". πŸ’…

  • --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 value <value>. If you don't give a <section>, the symbol gets added as an absolute symbol. 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: debug, constructor, warning, indirect, synthetic, unique-object, before.

You can pass this multiple times to add multiple symbols. Slay. πŸŽ€

  • --allow-broken-links β€” lets llvm-objcopy remove sections even when doing so would leave invalid section references behind. Any invalid sh_link fields get set to zero. It's giving "we broke it but we broke 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 [<style>] β€” compresses DWARF debug sections in the output using the style you picked. Supported styles are zlib-gnu and zlib. Defaults to zlib if you don't specify a style.
  • --decompress-debug-sections β€” decompresses any compressed DWARF debug sections in the output. Undoing the compression, iconic behaviour. πŸ¦‹
  • --discard-locals, -X β€” removes local symbols starting with .L from the output.
  • --extract-dwo β€” removes all sections from the output that are not DWARF .dwo sections.
  • --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 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; leading and trailing whitespace is ignored, and so is anything following a #. Can be specified multiple times to read names from multiple files.
  • --input-target <format>, -I β€” reads the input as the specified format. Check out SUPPORTED FORMATS for a list of valid <format> values. If you don't specify it, llvm-objcopy will try to figure out the format all by itself. main character detective energy πŸ”
  • --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 named <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; leading and trailing whitespace is ignored, and so is anything following a #. Can be specified multiple times to read names from multiple files.
  • --keep-section <section> β€” when sections are getting removed from the output, don't remove sections named <section>. Can be specified multiple times to keep multiple sections.
  • --keep-symbol <symbol>, -K β€” when symbols are getting removed from the output, don't remove symbols named <symbol>. Can be specified 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 a single symbol; leading and trailing whitespace is ignored, and so is anything following a #. 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; leading and trailing whitespace is ignored, and so is anything following a #. Can be specified multiple times to read names from multiple files.
  • --new-symbol-visibility <visibility> β€” sets the visibility of the symbols that get auto-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 out SUPPORTED FORMATS for a list of valid <format> values. If you don't specify it, the output format is assumed to be the same as whatever you gave for --input-target, or the input file's format if that option is unspecified too.
  • --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 single symbol name in the output.
  • --preserve-dates, -p β€” preserves access and modification timestamps in the output. πŸ•°οΈ
  • --rename-section <old>=<new>[,<flag>,...] β€” renames sections called <old> to <new> in the output, and applies any <flag> values you specify. Peep --set-section-flags for the list of supported flags. Can be specified multiple times to rename multiple sections.
  • --set-start-addr <addr> β€” sets the start address of the output to <addr>. This overrides any previously specified --change-start or --adjust-start options.
  • --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.
  • --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 with no section headers. This one's a real commitment. 😭
  • --target <format>, -F β€” equivalent to using --input-target and --output-target for the specified format. Check out SUPPORTED FORMATS for a list of 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; leading and trailing whitespace is ignored, and so is anything following a #. Can be specified multiple times to read names from multiple files.
  • --weaken β€” marks all defined global symbols as weak in the output.

🍎 MACH-O-SPECIFIC OPTIONS 🍎

  • --keep-undefined β€” keeps undefined symbols, even if they'd otherwise get stripped.

β˜• COFF-SPECIFIC OPTIONS β˜•

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

🌈 SUPPORTED FORMATS 🌈

These are the values llvm-objcopy currently supports for the --input-target, --output-target, and --target options. For GNU objcopy compatibility, all of them 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, every target except binary and ihex can have -freebsd as a suffix. Cute little bonus. 🫢


🧚 BINARY INPUT AND OUTPUT 🧚

If you use binary as the value for --input-target, the input file gets embedded as a data section inside an ELF relocatable object, with symbols _binary_<file_name>_start, _binary_<file_name>_end, and _binary_<file_name>_size representing the start, end and size of that data β€” where <file_name> is the path of the input file as you specified it on the command line, with non-alphanumeric characters converted to _.

If you use binary 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. Simple as that, no notes. ✨


πŸ› 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 attempt to guess the input format instead. so if it's acting weird, it's not you, it's this. 😭


πŸ‘€ SEE ALSO πŸ‘€

llvm-strip(1)


πŸ’– AUTHOR πŸ’–

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


2003-2025, LLVM Project


and that's the whole page bestie β€” this one's from the LLVM Project, 14, dated 2025-05-22, and it lives at LLVM-OBJCOPY(1). go forth and copy objects, you absolute icon πŸ‘‘πŸ’…

πŸ“¦ where this page comes from