LLVM-OBJCOPY(1)
π LLVM-OBJCOPY(1) π
object copying and editing tool, straight from the LLVM manual β bestie edition
β¨ NAME β¨
llvm-objcopy β object copying and editing tool. That's the name, that's the vibe, periodt.
π¦ SYNOPSIS π¦
llvm-objcopy [options] input [output]
π DESCRIPTION π
Okay so llvm-objcopy is the tool to copy and manipulate objects. In basic usage, it makes a semantic copy of the input to the output. If any options are specified, the output may be modified along the way β e.g. by removing sections. Very demure, very βcopy but make it editorial.β
If no output file is specified, the input file is modified in-place. 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. Stdin and stdout said βweβre involved now.β
If the input is an archive, any requested operations will be applied to each archive member individually. Every member gets the treatment, no skipping.
The tool is still in active development, but in most scenarios it works as a drop-in replacement for GNUβs objcopy. Lowkey iconic, ngl.
π GENERIC AND CROSS-PLATFORM OPTIONS π
The following options are either agnostic of the file format, or apply to multiple file formats. Universal besties, fr fr.
--add-gnu-debuglink <debug-file>β Add a.gnu_debuglinksection for <debug-file> to the output. Cute little debug breadcrumb.--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 typeSHT_NOTEif the name starts with.note; otherwise it will have typeSHT_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. Yes, literally ignored β sheβs just here for compatibility reasons, bestie.--disable-deterministic-archives,-Uβ Use real values for UIDs, GIDs and timestamps when updating archive member headers. No fake-zero era here.--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. Most local symbols? Gone. Debug sections? Also gone.--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. Deterministic queen behavior.--help,-hβ Print a summary of command line options. Your little map when youβre lost.--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. Itβs giving βdebug-only era.β
--only-section <section>,-jβ Remove all sections from the output, except for sections named <section>. Can be specified multiple times to keep multiple sections. Keep the chosen ones, banish the rest.
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. Symbol glow-up, basically.--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. Regex girlies, this oneβs for you.--remove-section <section>,-Rβ Remove the specified section from the output. Can be specified multiple times to remove multiple sections simultaneously. Section? Deleted. Many sections? Also deleted, in one go.
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 GNUobjcopyβs--strip-allswitch. Same energy, GNU-approved.--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. Debug info? Not invited.--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. If nobody needs it, itβs out.--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. The βif youβre not needed, youβre not stayingβ option.--version,-Vβ Display the version of thellvm-objcopyexecutable. Version check, bestie.--wildcard,-wβ Allow wildcard syntax for symbol-related flags. On by default for section-related flags. Incompatible with--regex. Sheβs giving wildcard energy, but donβt pair her with--regex.
So wildcard syntax has these special lil symbols you can use:
*β any number of characters (regex equivalent:.*)?β any single character (regex equivalent:.)\β escape the next character (regex equivalent:\)[a-z]β character class (regex equivalent:[a-z])[!a-z],[^a-z]β negated character class (regex equivalent:[^a-z])
And here's the plot twist π
β if you start a wildcard with !, it'll prevent a match, even if some other flag matches it. So like, -w -N '*' -N '!x' strips all the symbols except for x. Iconic.
Also the order of wildcards genuinely does not matter, bestie. -w -N '*' -N '!x' is literally the exact same as -w -N '!x' -N '*'. No cap.
@<FILE>β read command-line options and commands from the response file<FILE>. Very "don't repeat yourself" of it.
β¨ ELF-SPECIFIC OPTIONS β¨
Okay so these ones are implemented only for ELF objects. If you use them with other kinds of objects, llvm-objcopy will either throw an error at you or silently ignore them β which is lowkey the scariest of the two π.
--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>control the symbol's properties, and the 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. They're just there for the vibes π«Ά.
You can specify this multiple times to add multiple symbols. Stack 'em up.
--allow-broken-linksβ letsllvm-objcopyremove sections even if doing that would leave invalid section references behind. Any invalidsh_linkfields just get set to zero. Chaotic but make it functional π.--change-start <incr>,--adjust-startβ adds<incr>to the program's start address. Can be specified multiple times, and in that case the values get applied cumulatively. Math is mathing.--compress-debug-sections [<style>]β compresses DWARF debug sections in the output using whatever style you named. The supported styles arezlib-gnuandzlib. Defaults tozlibif you don't specify a style. Slay, compression.--decompress-debug-sectionsβ decompresses any compressed DWARF debug sections in the output. The un-squish.--discard-locals,-Xβ removes local symbols starting with.Lfrom the output. Bye bestie π.--extract-dwoβ removes all sections that are not DWARF.dwosections from the output.--extract-main-partitionβ extracts the main partition from the output.--extract-partition <name>β extracts the named partition 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. Main character energy for all of them π.--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 following a#also ignored. 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 the list of valid<format>values. If you don't specify it,llvm-objcopywill try to figure out the format automatically. She's intuitive like that β¨.--keep-file-symbolsβ keeps symbols of typeSTT_FILE, even if they'd otherwise get stripped. Protects them fr fr.--keep-global-symbol <symbol>β makes all symbols local in the output except the ones named<symbol>. Can be specified multiple times to ignore 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 a single symbol, with leading and trailing whitespace ignored, and anything following a#also ignored. Can be specified multiple times to read names from multiple files.--keep-section <section>β when removing sections from the output, don't remove sections named<section>. Can be specified multiple times to keep multiple sections.--keep-symbol <symbol>,-Kβ when removing symbols 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, with leading and trailing whitespace ignored, and anything following a#also ignored. 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. They get the quiet life πΈ.--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. Note the non-common part β that's doing real work there.--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 following a#also ignored. 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:defaulthiddeninternalprotected
The default is default. Cool cool cool.
--output-target <format>,-Oβ writes the output as the specified format. Peep SUPPORTED FORMATS for the list of valid<format>values. If you don't specify it, the output format is assumed to be the same as whatever you gave to--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. Every one. No exceptions π .--preserve-dates,-pβ preserves access and modification timestamps in the output. Keeping the receipts, literally.--rename-section <old>=<new>[,<flag>,...]β Renames sections called<old>to<new>in the output, and applies any<flag>values you specified. Peep--set-section-flagsfor the supported flags list. Can be specified multiple times to rename multiple sections. π--set-start-addr <addr>β Sets the start address of the output to<addr>. It overrides any previously specified--change-startor--adjust-startoptions. Periodt.--split-dwo <dwo-file>β Equivalent to runningllvm-objcopywith--extract-dwoand<dwo-file>as the output file and no other options, and then with--strip-dwoon the input file. Cute little combo, no cap.--strip-dwoβ Removes all DWARF.dwosections from the output. Bye DWARF dwo sections π--strip-non-allocβ Removes from the output all non-allocatable sections that are not within segments.--strip-sectionsβ Removes from the output all section headers and all section data not within segments. > Warning bestie: many tools will not be able to use an object without section headers, so this one is giving risky main character energy π--target <format>,-Fβ Equivalent to--input-targetand--output-targetfor the specified<format>. See 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 represents a single symbol, with leading and trailing whitespace ignored, as 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. All of them. Iconic.
π MACH-O-SPECIFIC OPTIONS π
--keep-undefinedβ Keeps undefined symbols, even if they would otherwise be stripped. Protecting the undefined girlies π«Ά
π SUPPORTED FORMATS π
The following values are currently supported by llvm-objcopy for the --input-target, --output-target, and --target options. For GNU objcopy compatibility, the values are all bfdnames. Slay.
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
Additionally, all targets except binary and ihex can have -freebsd as a suffix. Little suffix moment β¨
𧬠BINARY INPUT AND OUTPUT π§¬
If binary is used as the value for --input-target, the input file will be embedded as a data section in 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 the data, where <file_name> is the path of the input file as specified on the command line with non-alphanumeric characters converted to _.
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 will be 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 is an error. Otherwise, it exits with code 0. We love a clean exit π
π BUGS π
To report bugs, please visit <https://bugs.llvm.org/>.
There is a known issue with --input-target and --target causing only binary and ihex formats to have any effect. Other values will be ignored and llvm-objcopy will attempt to guess the input format. Not me learning this the hard way π
π SEE ALSO π
π AUTHOR π
Maintained by the LLVM Team (https://llvm.org/).
π COPYRIGHT π
2003-2023, LLVM Project
Bye bestie π«Άπ β that was LLVM-OBJCOPY(1), footer 13, dated 2023-07-14. Slay and stay safe out there! β¨π
π¦ where this page comes from
- ubuntu jammy: llvm-13 1:13.0.1-2ubuntu2.2 Β· 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