LLVM-OBJCOPY(1)
π NAME π
okay so bestie, this is the manual page for LLVM-OBJCOPY(1), and the icon of the hour is llvm-objcopy β literally the object copying and editing tool. It's giving "copy objects, edit objects, main character energy," and we're obsessed. π
β¨ SYNOPSIS β¨
llvm-objcopy [options] input [output]
πΈ DESCRIPTION πΈ
okay 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. No cap. But if any options are specified, the output may be modified along the way β e.g. by removing sections. It's giving "copy, but make it fashion." π
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. Periodt. π
If the input is an archive, any requested operations will be applied to each archive member individually. The way that it just handles each member separately? iconic.
The tool is still in active development, but in most scenarios it works as a drop-in replacement for GNU's objcopy. Lowkey serving compatibility realness. β¨
π GENERIC AND CROSS-PLATFORM OPTIONS π
The following options are either agnostic of the file format, or apply to multiple file formats. iykyk.
--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. Not me finding out it's just there for vibes. π--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. π--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 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. π--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,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.
- Supported flag names are
--strip-all-gnuβ Remove all symbols, debug sections and relocations from the output. This option is equivalent to GNUobjcopy'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, bestie β memorize these, they're the whole game:
*β any number of characters. Equivalent regex:.*?β any single character. Equivalent regex:.\β escape the next character. Equivalent regex:\[a-z]β character class. Equivalent regex:[a-z][!a-z],[^a-z]β negated character class. Equivalent regex:[^a-z]
Also, real talk: if you start a wildcard with !, that will prevent a match, even if another flag matches. So for example -w -N '*' -N '!x' will strip all symbols except for x. π
And 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 response file <FILE>. Like a little cheat sheet of flags, but make it a file. π
β¨ ELF-SPECIFIC OPTIONS β¨
Okay so these options are implemented only for ELF objects. If you use them with other objects, llvm-objcopy will either emit an error or silently ignore them. Lowkey chaotic of it, but that's the vibe. π
--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.
Can be specified multiple times to add multiple symbols. Obsessed. π
--allow-broken-linksβ Allowllvm-objcopyto remove sections even if it would leave invalid section references. Any invalidsh_linkfields will be set to zero. Basically it lets you break stuff on purpose and patches the damage. π«Ά--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, bestie. π₯--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. Undoing the squeeze, periodt.--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. It's giving very organized. β¨--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. She guesses. And she's usually right. π--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β write the output as <format>, bestie. Peep SUPPORTED FORMATS for the full list of valid <format> values. If you don't say anything, the output format just assumes it's the same as whatever you gave to--input-target, or the input file's own format if you didn't specify that one either. β¨--prefix-alloc-sections <prefix>β slap <prefix> onto the front of the names of every allocatable section in the output. π--prefix-symbols <prefix>β same energy but for symbols: <prefix> goes in front of every single symbol name in the output.--preserve-dates,-pβ keeps the access and modification timestamps intact in the output. not me being sentimental about mtimes π₯Ί--rename-section <old>=<new>[,<flag>,...]β renames sections called <old> to <new> in the output, and applies whatever <flag> values you threw in there too. Check--set-section-flagsfor the list of supported flags. You can pass this multiple times to rename multiple sections β go off. π--set-start-addr <addr>β sets the start address of the output to <addr>. This one overrides any--change-startor--adjust-startoptions you specified earlier. it said what it said π--split-dwo <dwo-file>β literally equivalent to runningllvm-objcopywith--extract-dwoand <dwo-file> as the output file and no other options, and then running it again with--strip-dwoon the input file. two-for-one, iconic. π¦--strip-dwoβ removes all DWARF.dwosections from the output. gone, bye. π--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.
heads up bestie: many tools will not be able to use an object without section headers. this is giving chaos, not convenience. π
--target <format>,-Fβ equivalent to setting both--input-targetand--output-targetto the specified <format>. See SUPPORTED FORMATS for valid <format> values. one flag, both jobs, main character energy π--weaken-symbol <symbol>,-Wβ marks any global symbol named <symbol> as a weak symbol in the output. Pass it multiple times to weaken multiple symbols. no cap.--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 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. all of them. the whole roster. periodt.
π SUPPORTED FORMATS π
Here's the current roster of values llvm-objcopy supports for the --input-target, --output-target, and --target options. For GNU objcopy compatibility, all of these 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 β plot twist β all targets except binary and ihex can have -freebsd as a suffix. π
π§ BINARY INPUT AND OUTPUT π§
Okay so if binary is what you put as the value for --input-target, your input file gets embedded as a data section inside an ELF relocatable object. The symbols _binary_<file_name>_start, _binary_<file_name>_end, and _binary_<file_name>_size represent 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 _. π
And if binary is what you put for --output-target, the output file will be a raw binary file holding the memory image of the input file. Symbols and relocation information get discarded, bestie. The image starts at the address of the first loadable section in the output. lowkey elegant π¦
π EXIT STATUS π
llvm-objcopy exits with a non-zero exit code if there's an error. Otherwise it exits with code 0. that's it, that's the whole vibe check β¨
π BUGS π
To report bugs, please visit <https://bugs.llvm.org/>.
There's a known issue where --input-target and --target only actually do anything for the binary and ihex formats. Other values get ignored and llvm-objcopy will just try to guess the input format. yeah. it's giving "I'll figure it out myself." π
π SEE ALSO π
πΈ AUTHOR πΈ
Maintained by the LLVM Team (https://llvm.org/).
π COPYRIGHT π
2003-2024, LLVM Project
and that's the whole page, bestie β LLVM-OBJCOPY(1), this rendition dated 2024-07-18, page 11 of the manual. go forth and copy objects responsibly π«Άβ¨
π¦ where this page comes from
- fedora 43: llvm11 11.1.0-14.fc41 Β· NCSA
- fedora 43: llvm11 11.1.0-14.fc41 Β· NCSA
- fedora 44: llvm11 11.1.0-14.fc41 Β· NCSA
- fedora 44: llvm11 11.1.0-14.fc41 Β· NCSA
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms