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_debuglinksection 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 typeSHT_NOTEif the name starts with โ.noteโ. Otherwise, it'll have typeSHT_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 tollvm-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. use0for 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 ofSHF_ALLOCsections that are notSHT_NOTEby making themSHT_NOBITSand 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 theSHF_ALLOCflag.load= if the section hasSHT_NOBITStype, mark it as aSHT_PROGBITSsection.readonly= if this flag is not specified, add theSHF_WRITEflag.exclude= add theSHF_EXCLUDEflag.code= add theSHF_EXECINSTRflag.merge= add theSHF_MERGEflag.strings= add theSHF_STRINGSflag.contents= if the section hasSHT_NOBITStype, mark it as aSHT_PROGBITSsection.
For COFF objects, the flags have the following effects:
alloc= add theIMAGE_SCN_CNT_UNINITIALIZED_DATAandIMAGE_SCN_MEM_READflags, unless theloadflag is specified.noload= add theIMAGE_SCN_LNK_REMOVEandIMAGE_SCN_MEM_READflags.readonly= if this flag is not specified, add theIMAGE_SCN_MEM_WRITEflag.exclude= add theIMAGE_SCN_LNK_REMOVEandIMAGE_SCN_MEM_READflags.debug= add theIMAGE_SCN_CNT_INITIALIZED_DATA,IMAGE_SCN_MEM_DISCARDABLEandIMAGE_SCN_MEM_READflags.code= add theIMAGE_SCN_CNT_CODE,IMAGE_SCN_MEM_EXECUTEandIMAGE_SCN_MEM_READflags.data= add theIMAGE_SCN_CNT_INITIALIZED_DATAandIMAGE_SCN_MEM_READflags.share= add theIMAGE_SCN_MEM_SHAREDandIMAGE_SCN_MEM_READflags.
--strip-all-gnuโ Removes all symbols, debug sections and relocations from the output. This option is equivalent to GNU objcopyโs--strip-allswitch. 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.attributesections 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 thellvm-objcopyexecutable. 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 anSTT_FILEsymbol.section= the symbol will be anSTT_SECTIONsymbol.object= the symbol will be anSTT_OBJECTsymbol.function= the symbol will be anSTT_FUNCsymbol.indirect-function= the symbol will be anSTT_GNU_IFUNCsymbol.
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โ Letsllvm-objcopyremove sections even if that would leave invalid section references behind. Any invalidsh_linkfields 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 iszlib. If you omit<format>, it useszlib. 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.Lfrom the output. Bye girl ๐.--extract-dwoโ Removes all sections that aren't DWARF.dwosections 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-objcopywill try to figure out the format automatically. It's giving detective energy ๐.--keep-file-symbolsโ Keeps symbols of typeSTT_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:defaulthiddeninternalprotected
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-flagsfor 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-startor--adjust-startoptions you specified earlier โ it's the main character, it wins ๐.--split-dwo <dwo-file>โ Equivalent to runningllvm-objcopywith--extract-dwoand<dwo-file>as the output file and no other options, and then running it with--strip-dwoon the input file. Two-in-one moment โจ.--strip-dwoโ Removes all DWARF.dwosections 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-targetand--output-targetto 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).
binaryihexelf32-i386elf32-x86-64elf64-x86-64elf32-iamcuelf32-littlearmelf64-aarch64elf64-littleaarch64elf32-littleriscvelf64-littleriscvelf32-powerpcelf32-powerpcleelf64-powerpcelf64-powerpcleelf32-bigmipself32-ntradbigmipself32-ntradlittlemipself32-tradbigmipself32-tradlittlemipself64-tradbigmipself64-tradlittlemipself32-sparcelf32-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-targetand--targetonly actually have any effect for thebinaryandihexformats. Every other value gets ignored andllvm-objcopywill 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/>).
๐ COPYRIGHT ๐
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
- ubuntu jammy: llvm-15 1:15.0.7-0ubuntu0.22.04.3 ยท APACHE-2-LLVM-EXCEPTIONS
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms