LLVM-OBJCOPY(1)
β¨ NAME β¨
llvm-objcopy β object copying and editing tool. It lives in the LLVM manual, section 1, and it's genuinely the bestie you want on your team when you're messing with object files π
πΈ SYNOPSIS πΈ
llvm-objcopy [options] input [output]
π DESCRIPTION π
okay so. llvm-objcopy is a tool to copy and manipulate objects. That's the whole vibe. In basic usage, it makes a semantic copy of the input to the output β like, a real, faithful copy, not a "eh close enough" copy β¨
If you specify any options, though, the output may be modified along the way, e.g. by removing sections. That's the fun part.
If no output file is specified, the input file is modified in-place. Yes bestie, it edits your original file. No cap. π«Ά
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 yes, you can pipe it, she's flexible like that π
If the input is an archive, any requested operations will be applied to each archive member individually. Every member gets the treatment, no one gets left out π
The tool is still in active development, but in most scenarios it works as a drop-in replacement for GNU's objcopy. That's iconic behavior honestly π
π GENERIC AND CROSS-PLATFORM OPTIONS π
The following options are either agnostic of the file format, or apply to multiple file formats. So they're the universal girlies π
--add-gnu-debuglink <debug-file>β Add a.gnu_debuglinksection for<debug-file>to the output. Pointing at your debug file so the vibes stay linked π¦--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 β stack 'em up, no limit β¨
For MachO objects, <section> must be formatted as <segment name>,<section name>. Don't forget the comma, she's picky about that π€
--binary-architecture <arch>,-Bβ Ignored for compatibility. Literally just vibing there so your old scripts don't crash. Not me keeping a flag around for emotional support π--disable-deterministic-archives,-Uβ Use real values for UIDs, GIDs and timestamps when updating archive member headers. The chaos mode of archive metadata π₯--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. So it's "most", not "all" β read the fine print bestie π--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. So she dumps the raw you, untouched, and still does the rest of her job π
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. Reproducible builds said "main character energy" π--help,-hβ Print a summary of command line options. When you're lost, she's got you π«Ά--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. She's stripping the fit down to just the debug essentials π
--only-section <section>,-jβ Remove all sections from the output, except for sections named<section>. Can be specified multiple times to keep multiple sections. Strict queen behavior β if you're not on the list, you're out π
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 for symbols, fr fr β¨--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. It's giving bulk rename energy π--regexβ If specified, symbol and section names specified by other switches are treated as extended POSIX regular expression patterns. Now she speaks regex. Powerful and slightly terrifying π₯--remove-section <section>,-Rβ Remove the specified section from the output. Can be specified multiple times to remove multiple sections simultaneously. Blocked. Deleted. Gone π
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. Line that section up, she loves symmetry π--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. Yes, you can comma-stack the flags. Obsessed.
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. (Some of them just show up and do nothing, like that one friend at the party π)
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. It's the same girl, different name π--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. Total reset. Nothing left but the vibes π₯
--strip-debug,-gβ Remove all debug sections from the output. Debug girlies, you're out π--strip-symbol <symbol>,-Nβ Remove all symbols named<symbol>from the output. Can be specified multiple times to remove multiple symbols. Targeted deletion, very demure π--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. Hit list, but make it a text file π--strip-unneeded-symbol <symbol>β Remove from the output all symbols named<symbol>that are local or undefined and are not required by any relocation. Only the unneeded ones get cut β she checks first, she's not reckless π«Ά--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. Same energy, but in bulk β¨--strip-unneededβ Remove from the output all local or undefined symbols that are not required by relocations. Also remove all debug sections. The full clean-out. Spring cleaning but for your binary πΈ--version,-Vβ Display the version of thellvm-objcopyexecutable. Know who you're dealing with π--wildcard,-wβ Allow wildcard syntax for symbol-related flags. On by default for section-related flags. Incompatible with--regex. So you gotta pick a lane bestie β wildcards or regex, not both π
Wildcard syntax allows these special symbols, and honestly bestie they're giving regex energy:
*β 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])
Also, if you start a wildcard with ! it will prevent a match, even if another flag matches. So like, -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 '*'. No cap.
@<FILE>β read command-line options and commands from the response file<FILE>. yes, a whole file of vibes
π¦ ELF-SPECIFIC OPTIONS π¦
Okay so these next ones are only implemented for ELF objects. If you use them with other objects, llvm-objcopy will either emit an error or silently ignore them. Silently. Like it just won't tell you. Rude but iconic.
--add-symbol <name>=[<section>:]<value>[,<flags>]β add a new symbol called<name>to the output symbol table, in the section named<section>, with value<value>. If<section>is not specified, the symbol is 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. (they're just there for the plot, they don't do anything)
Can be specified multiple times to add multiple symbols. β¨
--allow-broken-linksβ letllvm-objcopyremove sections even if it would leave invalid section references. Any invalidsh_linkfields will be set to zero. it's a little chaotic, but it's allowed π--build-id-link-dir <dir>β set the directory used by--build-id-link-inputand--build-id-link-output. π--build-id-link-input <suffix>β hard-link the input to<dir>/xx/xxx<suffix>, where<dir>is the directory specified by--build-id-link-dir. The path used is derived from the hex build ID. π--build-id-link-output <suffix>β hard-link the output to<dir>/xx/xxx<suffix>, where<dir>is the directory specified by--build-id-link-dir. The path used is derived from the hex build ID. π--change-start <incr>,--adjust-startβ add<incr>to the program's start address. Can be specified multiple times, in which case the values will be applied cumulatively. (stack 'em up, queen)--compress-debug-sections [<style>]β compress DWARF debug sections in the output, using the specified style. Supported styles arezlib-gnuandzlib. Defaults tozlibif no style is specified. ποΈ--decompress-debug-sectionsβ decompress any compressed DWARF debug sections in the output. un-squish them--discard-locals,-Xβ remove local symbols starting with".L"from the output. ποΈ--extract-dwoβ remove all sections that are not DWARF.dwosections from the output.--extract-main-partitionβ extract the main partition from the output. π--extract-partition <name>β extract the named partition from the output.--globalize-symbol <symbol>β mark any defined symbols named<symbol>as global symbols in the output. Can be specified multiple times to mark multiple symbols. π--globalize-symbols <filename>β read a list of names from the file<filename>and mark 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. π--input-target <format>,-Iβ read 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. π΅οΈββοΈ--keep-file-symbolsβ keep symbols of typeSTT_FILE, even if they would otherwise be stripped. π«Ά--keep-global-symbol <symbol>β make all symbols local in the output, except for symbols with the name<symbol>. Can be specified multiple times to ignore multiple symbols.--keep-global-symbols <filename>β make 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.--keep-section <section>β when removing sections from the output, do not remove sections named<section>. Can be specified multiple times to keep multiple sections. π--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.--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.--localize-hiddenβ make all symbols with hidden or internal visibility local in the output. π--localize-symbol <symbol>,-Lβ mark 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>β read a list of names from the file<filename>and mark 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.--new-symbol-visibility <visibility>β specify the visibility of the symbols automatically created when using binary input or--add-symbol. Valid options are:defaulthiddeninternalprotected
The default is default. β
--output-target <format>,-Oβ writes the output as whatever<format>you picked. valid<format>values live in the SUPPORTED FORMATS section. If you don't specify anything, the output format is assumed to be the same as the value you gave for--input-target, or the input file's format if that option is also unspecified. π--prefix-alloc-sections <prefix>β slaps<prefix>onto the front of the names of all allocatable sections in the output. β¨--prefix-symbols <prefix>β puts<prefix>in front of every single symbol name in the output. no cap. π--preserve-dates,-pβ keeps access and modification timestamps in the output. time is fake but timestamps are real bestie π°οΈ--rename-section <old>=<new>[,<flag>,...]β renames sections called<old>to<new>in the output, and applies any<flag>values you list. peep--set-section-flagsfor the supported flag menu. Can be specified multiple times to rename multiple sections. π--set-start-addr <addr>β sets the start address of the output to<addr>. Overrides any previously specified--change-startor--adjust-startoptions. periodt.--split-dwo <dwo-file>β exactly 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. bye bye debug info π¦--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. Note that many tools will not be able to use an object without section headers. it's giving risky π--target <format>,-Fβ same as setting both--input-targetand--output-targetto<format>. See SUPPORTED FORMATS for 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<filename>and marks global symbols with those names as weak in the output. In that file, each line is one symbol, leading and trailing whitespace is ignored, and anything after a#is ignored too. Can be specified multiple times to read names from multiple files. π--weakenβ marks all defined global symbols as weak in the output. weakness is a vibe π
β¨ SUPPORTED FORMATS β¨
These are the values llvm-objcopy currently supports for --input-target, --output-target, and --target. For GNU objcopy compatibility, all values are bfdnames. π
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. πΈ
π§ BINARY INPUT AND OUTPUT π§
If binary is used as the value for --input-target, the input file gets 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. Here <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 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 is an error. Otherwise, it exits with code 0. periodt. π
π 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 getting ignored π
π SEE ALSO π
π AUTHOR π
Maintained by the LLVM Team (https://llvm.org/). π«Ά
π COPYRIGHT π
2003-2024, LLVM Project
That's the whole page, bestie! This was LLVM-OBJCOPY(1), dated 2024-07-18, page 12 β slay, go touch some object files π
β¨
π¦ where this page comes from
- fedora 43: llvm12 12.0.1-12.fc41 Β· NCSA
- fedora 43: llvm12 12.0.1-12.fc41 Β· NCSA
- fedora 44: llvm12 12.0.1-12.fc41 Β· NCSA
- fedora 44: llvm12 12.0.1-12.fc41 Β· NCSA
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms