LLVM-OBJCOPY(1)
π llvm-objcopy β from the LLVM manual, bestie
okay so real talk, this is llvm-objcopy from the LLVM manual page (LLVM-OBJCOPY(1), if you're keeping track), and honestly? she's that girl. let's get into it π«Ά
β¨ NAME β¨
llvm-objcopy β the object copying and editing tool. that's it, that's the whole vibe. copy things, edit things, live your truth π
πΈ SYNOPSIS πΈ
llvm-objcopy [options] input [output]
like, options first, then what you're feeding her, then where it goes. classic order, no cap.
π¦ DESCRIPTION π¦
so llvm-objcopy is a tool to copy and manipulate objects. in basic usage, it makes a semantic copy of the input to the output β literally just "here's the same thing, but elsewhere", iconic behaviour honestly β¨
but the moment you start passing options? that's when it gets juicy. the output may be modified along the way β e.g. by removing sections. like, you can genuinely just be like "yeah take those sections out" and she'll do it. main character energy fr π₯
now, the important bits, listen up π
- if no output file is specified, the input file is modified in-place. so like, she's editing the same file. be normal about that, okay? π
- 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.
so those little dashes? they're the whole "stdin/stdout" pipeline moment. iykyk π
β also: if the input is an archive, any requested operations will be applied to each archive member individually. every single one gets the treatment, no member left behind π
and ngl, the tool is still in active development β but in most scenarios it works as a drop-in replacement for GNU's objcopy. so if you're coming over from GNU land, she's got you. lowkey slay π§
(still more to come, don't go anywhere π)
β¨ GENERIC AND CROSS-PLATFORM OPTIONS β¨
okay bestie, these are the options that are either totally agnostic of the file format, or they apply to multiple file formats. universal flag energy, no cap. π¦
--add-gnu-debuglink <debug-file>β Add a.gnu_debuglinksection for<debug-file>to the output. π--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_NOTE, if 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. literally just vibing there. π--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. periodt. π--help,-hβ Print a summary of command line options. your little map, bestie. π--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 ofSHF_ALLOCsections that are notSHT_NOTEby making themSHT_NOBITSand 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. glow-up but for 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. regex girlies rise. π₯--remove-section <section>,-Rβ Remove the specified section from the output. Can be specified multiple times to remove multiple sections simultaneously. bye-bye section, hope u had a good run. π 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 arealloc,load,noload,readonly,exclude,debug,code,data,rom,share,contents,mergeandstrings. 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. debug info? never heard of her. π--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. lowkey selective. πΈ--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. π§--update-section <name>=<file>β Replace 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. β οΈ read that twice, bestie.--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 to.*?β Any single character β equivalent to.\β Escape the next character β equivalent to\[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 forx. 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 so these next ones are ELF-only, bestie β llvm-objcopy implements them just for ELF objects. If you use them on other objects, itβll either emit an error or silently ignore them. noted π
--add-symbol <name>=[<section>:]<value>[,<flags>]β adds a new symbol called<name>to the output symbol table, in the section named<section>, with value<value>. If<section>isnβt specified, the symbol gets added as an absolute symbol. The<flags>affect the symbol 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.
Additionally, the following flags are accepted but ignored: debug, constructor, warning, indirect, synthetic, unique-object, before. Can be specified multiple times to add multiple symbols. slay β¨
--allow-broken-linksβ allowsllvm-objcopyto remove sections even if it would leave invalid section references. Any invalidsh_linkfields will be set to zero. problem solved-ish π«Ά--change-start <incr>,--adjust-startβ adds<incr>to the programβs start address. Can be specified multiple times, in which case the values will be applied cumulatively. stack βem up π--compress-debug-sections [<format>]β compresses DWARF debug sections in the output using the specified format. Supported formats arezlib. Usezlibif<format>is omitted. tiny debug energy π¦--decompress-debug-sectionsβ decompresses any compressed DWARF debug sections in the output. unzip the lore π--discard-locals,-Xβ removes local symbols starting with".L"from the output. bye local besties π--extract-dwoβ removes all sections that are not DWARF.dwosections from the output. dwo-only era π--extract-main-partitionβ extracts the main partition from the output. main character partition π--extract-partition <name>β extracts the named partition from the output. named partition, very demure π--globalize-symbol <symbol>β marks any defined symbols named<symbol>as global symbols in the output. Can be specified multiple times to mark multiple symbols. go global, bestie π--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 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. file full of fame β--input-target <format>,-Iβ reads the input as the specified format. See SUPPORTED FORMATS for a list of valid<format>values. If unspecified,llvm-objcopywill attempt to determine the format automatically. detective mode π--keep-file-symbolsβ keeps symbols of typeSTT_FILE, even if they would otherwise be stripped. protect the file symbols π‘οΈ--keep-global-symbol <symbol>,-Gβ makes all symbols local in the output, except for symbols with the name<symbol>. Can be specified multiple times to ignore multiple symbols. VIP symbol only π--keep-global-symbols <filename>β makes all symbols local in the output, except for symbols named in the file<filename>. 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. guest list behavior π--keep-section <section>β when removing sections from the output, do not remove sections named<section>. Can be specified multiple times to keep multiple sections. section saved from the purge π«Ά--keep-symbol <symbol>,-Kβ when removing symbols from the output, do not remove symbols named<symbol>. Can be specified multiple times to keep multiple symbols. symbol immunity β¨--keep-symbols <filename>β when removing symbols from the output do not remove symbols named in the file<filename>. 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. protected list, no cap π--localize-hiddenβ makes all symbols with hidden or internal visibility local in the output. hidden girlies become local π--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 the defined non-common ones π--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 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. same energy, from a file πΏ--new-symbol-visibility <visibility>β specifies the visibility of the symbols automatically created when using binary input or--add-symbol. Valid options are:defaulthiddeninternalprotected
The default is default. choose your visibility era π
--output-target <format>,-Oβ writes the output as the specified format. See SUPPORTED FORMATS for a list of valid<format>values. If unspecified, the output format is assumed to be the same as the value specified for--input-targetor the input fileβs format if that option is also unspecified. output glow-up π¦--prefix-alloc-sections <prefix>β adds<prefix>to the front of the names of all allocatable sections in the output. prefix the allocatable section names π--prefix-symbols <prefix>β adds<prefix>to the front of every symbol name in the output. every symbol gets a little name tag π·οΈ--preserve-dates,-pβ preserves access and modification timestamps in the output. timestamps stay iconic β°--rename-section <old>=<new>[,<flag>,...]β renames sections called<old>to<new>in the output, and applies any specified<flag>values. See--set-section-flagsfor a list of supported flags. Can be specified multiple times to rename multiple sections. section rebrand π--set-section-type <section>=<type>β sets the type of section<section>to the integer<type>. Can be specified multiple times to update multiple sections. integer type agenda π’--set-start-addr <addr>β sets the start address of the output to<addr>. Overrides any previously specified--change-startor--adjust-startoptions. final boss start address π--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. dwo split, no drama π§--strip-dwoβ removes all DWARF.dwosections from the output. dwo sections? gone π--strip-non-allocβ removes from the output all non-allocatable sections that are not within segments. non-alloc purge π§Ή--strip-sectionsβ removes from the output all section headers and all section data not within segments. careful, bestie β many tools will not be able to use an object without section headers.--target <format>,-Fβ equivalent to--input-targetand--output-targetfor the specified format. See SUPPORTED FORMATS for a list of valid<format>values. both sides, one flag π«Ά--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. weak binding, strong energy π--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. weak from a whole file πΏ--weakenβ marks all defined global symbols as weak in the output. everyone gets weakened π
π MACH-O-SPECIFIC OPTIONS π
--keep-undefinedβ keeps undefined symbols, even if they would otherwise be stripped. undefined but not forgotten π«Ά
β COFF-SPECIFIC OPTIONS β
--subsystem <name>[:<version>]β sets the PE subsystem, and optionally the subsystem version. PE subsystem glow-up β¨
π 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. 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
Additionally, all targets except binary and ihex can have -freebsd as a suffix. freebsd 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 _. binary input enters the ELF chat π¬
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. raw binary, no extras π
π EXIT STATUS π
llvm-objcopy exits with a non-zero exit code if there is an error. Otherwise, it exits with code 0. zero means we ate π
π BUGS π
To report bugs, please visit https://github.com/llvm/llvm-project/labels/tools:llvm-objcopy/strip/. bug report link is right there, bestie π«Ά
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. known issue, very much noted π
π SEE ALSO π
llvm-strip(1) go check the strip girlies β¨
π AUTHOR π
Maintained by the LLVM Team (https://llvm.org/). LLVM team era π
π COPYRIGHT π
okay so legally speaking β and yes we're doing the boring-but-important part, stay with me bestie β this whole thing is:
2003-2023, LLVM Project
that's it, that's the copyright line. the LLVM Project has been holding it down since 2003 and honestly? iconic longevity. π
and that's a wrap on the whole page, bestie!! π«Ά you made it to the very end, I'm so proud. this edition of the page is from LLVM version 15, dated 2023-01-14 β so if you're reading this way in the future and something looks different on your machine, that's why, no cap. go forth and llvm-objcopy responsibly π
β¨πΈ
bye bestie, ily, go touch some object files π¦
π¦ where this page comes from
- opensuse-leap 16.0: llvm15 15.0.7-160000.3.1 Β· Apache-2.0 WITH LLVM-exception AND NCSA
- opensuse-leap 16.0: llvm15 15.0.7-160000.3.1 Β· Apache-2.0 WITH LLVM-exception AND NCSA
- opensuse-leap 16.0: llvm15 15.0.7-160000.3.1 Β· Apache-2.0 WITH LLVM-exception AND NCSA
- opensuse-leap 16.0: llvm15 15.0.7-160000.3.1 Β· Apache-2.0 WITH LLVM-exception AND NCSA
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms