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_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 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 tollvm-objcopyand 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. use0for 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 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β remove all symbols, debug sections and relocations from the output. This option is equivalent to GNU objcopyβs--strip-allswitch. π§Ή--strip-all,-Sβ for ELF objects, remove 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, 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 thellvm-objcopyexecutable. π¦--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 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: debug, constructor, warning, indirect, synthetic, unique-object, before.
You can pass this multiple times to add multiple symbols. Slay. π
--allow-broken-linksβ letsllvm-objcopyremove sections even when doing so would leave invalid section references behind. Any invalidsh_linkfields 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 arezlib-gnuandzlib. Defaults tozlibif 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.Lfrom the output.--extract-dwoβ removes all sections from the output that are not DWARF.dwosections.--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-objcopywill try to figure out the format all by itself. main character detective energy π--keep-file-symbolsβ keeps symbols of typeSTT_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:defaulthiddeninternalprotected
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-flagsfor 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-startor--adjust-startoptions.--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.--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 with no section headers. This one's a real commitment. π
--target <format>,-Fβ equivalent to using--input-targetand--output-targetfor 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 π
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, 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 π
π AUTHOR π
Maintained by the LLVM Team (<https://llvm.org/>).
Β©οΈ COPYRIGHT Β©οΈ
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
- ubuntu questing: llvm-14 1:14.0.6-20ubuntu3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms