LLVM-OBJCOPY(1)
π LLVM-OBJCOPY(1) π
okay bestie, welcome to the LLVM corner of the man pages, this one's called llvm-objcopy and she's literally the object copying and editing tool β¨
πΈ NAME πΈ
llvm-objcopy β object copying and editing tool π«Ά
π SYNOPSIS π
llvm-objcopy [options] input [output]
likeβ¦ that's it. that's the whole vibe. input, maybe output, sprinkle some [options] on top and go π
β¨ 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. But the second you start throwing options at her, the output can get modified along the way β like, for example, by removing sections. it's giving glow-up, but make it ELF π₯
If no output file is specified, the input file is modified in-place. yes, in-place. she's editing the original. no backup, no take-backs π
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 like, pipes? iconic. she does pipes π
If the input is an archive, any requested operations will be applied to each archive member individually. every single one. she does not skip anybody π
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 from GNU land, hi bestie, you're gonna be fine π¦
more of this page is coming, don't go anywhere π
π GENERIC AND CROSS-PLATFORM OPTIONS π
okay bestie, these next ones are the format-agnostic girlies π they either literally do not care what file format you're working with, or they show up for multiple formats at once. versatile. iconic. no notes. β¨
--add-gnu-debuglink <debug-file>β adds a.gnu_debuglinksection for<debug-file>into the output. cute lil pointer, very demure. π--add-section <section=file>β adds a section named<section>to the output, filled with the contents of<file>. For ELF objects the section gets typeSHT_NOTEif the name starts with.note; otherwise it's typeSHT_PROGBITS. you can drop this flag multiple times to add multiple sections, go off. β¨
For MachO objects, <section> has to be formatted as <segment name>,<section name>.
--binary-architecture <arch>,-Bβ ignored for compatibility. it's just vibing in the corner, do not perceive it. π--disable-deterministic-archives,-Uβ use real values for UIDs, GIDs and timestamps when you're updating archive member headers. raw and unfiltered. π₯--discard-all,-xβ removes most local symbols from the output. different file formats might limit this to a subset of the local symbols β for example, file and section symbols in ELF objects will not be discarded. also nukes all debug sections. bye girl π--dump-section <section>=<file>β dumps the contents of section<section>into the file<file>. can be specified multiple times to dump multiple sections into different files. heads up:<file>is unrelated to the input and output files you handed tollvm-objcopy, so the normal copying and editing operations still happen anyway. and no operations are performed on the sections before dumping them β they're dumped exactly as they are. π
For MachO objects, <section> must be formatted as <segment name>,<section name>.
--enable-deterministic-archives,-Dβ turns on deterministic mode when copying archives, i.e. use0for the archive member header UIDs, GIDs and timestamp fields. this one is on by default, so she's already slaying. π--help,-hβ prints a summary of command line options. the classic "wait what does this do again" button. π--only-keep-debugβ produces a debug file as the output that only preserves the contents of sections that are useful for debugging purposes. main character energy: everything else gets cut. β¨
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β removes all sections from the output except the ones named<section>. can be specified multiple times to keep multiple sections. very picky, very valid. π
For MachO objects, <section> must be formatted as <segment name>,<section name>.
--redefine-sym <old>=<new>β renames symbols called<old>to<new>in the output. can be specified multiple times to rename multiple symbols. glow-up for your symbol table. π¦--redefine-syms <filename>β renames symbols in the output as described in the file<filename>. in that file, each line is a single symbol to rename, with the old name and new name separated by whitespace. leading and trailing whitespace is ignored, and so is anything following a#. can be specified multiple times to read names from multiple files. batch renaming, we love to see it. πΈ--regexβ if you specify this, symbol and section names given by other switches get treated as extended POSIX regular expression patterns. regex girlies rise π§--remove-section <section>,-Rβ removes the specified section from the output. can be specified multiple times to remove multiple sections at once. not me deleting sections, it's giving spring cleaning π§Ή
For MachO objects, <section> must be formatted as <segment name>,<section name>.
--set-section-alignment <section>=<align>β sets the alignment of section<section>to<align>. can be specified multiple times to update multiple sections. alignment is self-care bestie. β¨--set-section-flags <section>=<flag>[,<flag>,...]β sets the section properties in the output for section<section>based on the<flag>values you gave. can be specified multiple times to update multiple sections.
the supported flag names are alloc, load, noload, readonly, exclude, debug, code, data, rom, share, contents, merge and strings. ngl, not all flags are meaningful for all object file formats β so some of these do nothing depending on what you're feeding her. π
For ELF objects, the flags do this:
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 do this:
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β removes all symbols, debug sections and relocations from the output. this option is equivalent to GNU objcopy's--strip-allswitch. periodt. π--strip-all,-Sβ for ELF objects, removes from the output all symbols and non-alloc sections that aren't within segments, except for.gnu.warning,.ARM.attributesections and the section name table. don't worry, those three are protected. π«Ά
For COFF and Mach-O objects, removes all symbols, debug sections, and relocations from the output.
--strip-debug,-gβ removes all debug sections from the output. no debug thoughts, head empty. π--strip-symbol <symbol>,-Nβ removes all symbols named<symbol>from the output. can be specified multiple times to remove multiple symbols. targeted deletion, we love a precise queen. βοΈ--strip-symbols <filename>β removes all symbols whose names appear in the file<filename>from the output. in that file, each line is 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>β removes from the output all symbols named<symbol>that are local or undefined and aren't required by any relocation. she only leaves if nobody needs her. π--strip-unneeded-symbols <filename>β removes all symbols whose names appear in the file<filename>from the output, if they're local or undefined and aren't required by any relocation. in that file, each line is 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β removes from the output all local or undefined symbols that aren't required by relocations. also removes all debug sections. full reset, no baggage. β¨--update-section <name>=<file>β replaces the contents of section<name>with contents from the file<file>. β οΈ but if the section<name>is part of a segment, the new contents cannot be larger than the existing section β she does not stretch, no cap.--version,-Vβ displays the version of thellvm-objcopyexecutable. the "who even are you" check. π--wildcard,-wβ allows wildcard syntax for symbol-related flags. it's on by default for section-related flags. incompatible with--regexβ pick a lane bestie, you cannot have both. π
wildcard syntax lets you use these 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 for x. iconic exclusion behaviour. π¦
the order of wildcards does not matter. for example, -w -N '*' -N '!x' is the same as -w -N '!x' -N '*'. she is unbothered by your ordering. β¨
@<FILE>β reads command-line options and commands from the response file<FILE>. yes, it's the little@at the front, so fancy. π
β¨ ELF-SPECIFIC OPTIONS β¨
Okay bestie, these ones are ELF-only β like, they only work on ELF objects, periodt. If you try them on anything else, llvm-objcopy is either gonna throw an error at you or just silently ignore you (rude, but okay). π
--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 the value<value>. If you don't give a<section>, the symbol gets added as an absolute symbol. The<flags>are what give the symbol its β¨propertiesβ¨. Here's what you can pass:global= the symbol gets global binding.local= the symbol gets local binding.weak= the symbol gets weak binding.default= the symbol gets default visibility.hidden= the symbol gets hidden visibility.protected= the symbol gets protected visibility.file= the symbol becomes anSTT_FILEsymbol.section= the symbol becomes anSTT_SECTIONsymbol.object= the symbol becomes anSTT_OBJECTsymbol.function= the symbol becomes anSTT_FUNCsymbol.indirect-function= the symbol becomes anSTT_GNU_IFUNCsymbol.
Also, these next flags are accepted but literally ignored: debug, constructor, warning, indirect, synthetic, unique-object, before. They're just there for the vibes, no cap.
You can specify this multiple times to add a whole squad of symbols. π
--allow-broken-linksβ letsllvm-objcopyremove sections even when doing so would leave invalid section references behind. Any invalidsh_linkfields get set to zero. Fixing the mess, bestie. π«Ά--change-start <incr>,--adjust-startβ adds<incr>to the program's start address. Can be specified multiple times, and when you do, the values stack up cumulatively. π₯--compress-debug-sections [<format>]β compresses the DWARF debug sections in the output using whatever format you name. Supported formats arezlibandzstd. If you leave<format>out, it useszlib.--decompress-debug-sectionsβ decompresses any compressed DWARF debug sections in the output.--discard-locals,-Xβ yeets every local symbol starting with".L"right out of the output. π--extract-dwoβ removes all sections from the output that aren't 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. Specify it multiple times to globalize 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 one symbol; leading and trailing whitespace is ignored, and so is anything after a#. Can be specified multiple times to pull names from multiple files. π--input-target <format>,-Iβ reads the input as the format you name. Peep SUPPORTED FORMATS for the list of valid<format>values. If you don't say anything,llvm-objcopytries to figure the format out on its own. π--keep-file-symbolsβ keeps symbols of typeSTT_FILE, even when they'd normally get stripped.--keep-global-symbol <symbol>,-Gβ makes every symbol local in the output except the ones named<symbol>. Specify it multiple times to spare multiple symbols.--keep-global-symbols <filename>β makes every symbol local in the output except the ones named in the file<filename>. Same file rules: one symbol per line, leading/trailing whitespace ignored, and anything after a#ignored too. Can be specified multiple times to read from multiple files.--keep-section <section>β when removing sections from the output, don't remove the ones named<section>. Specify it multiple times to keep multiple sections. π--keep-symbol <symbol>,-Kβ when removing symbols from the output, don't remove the ones named<symbol>. Specify it multiple times to keep multiple symbols.--keep-symbols <filename>β when removing symbols from the output, don't remove the ones named in the file<filename>. One symbol per line, leading/trailing whitespace ignored, and everything after a#ignored. Can be specified multiple times to read from multiple files.--localize-hiddenβ makes every symbol 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. Specify it multiple times to localize multiple symbols.--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. One symbol per line, leading/trailing whitespace ignored, and anything after a#ignored too. Can be specified multiple times to read from multiple files.--new-symbol-visibility <visibility>β sets 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. β¨
--output-target <format>,-Oβ writes the output as the format you name. See SUPPORTED FORMATS for the valid<format>values. If you don't specify it, the output format is assumed to match whatever you gave to--input-target, or the input file's format if that option wasn't given either.--prefix-alloc-sections <prefix>β slaps<prefix>onto the front of the names of every allocatable section in the output.--prefix-symbols <prefix>β slaps<prefix>onto the front of every single symbol name in the output.--preserve-dates,-pβ preserves the 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 list. Check--set-section-flagsfor the list of supported flags. Specify it multiple times to rename multiple sections.--set-section-type <section>=<type>β sets the type of section<section>to the integer<type>. Can be specified multiple times to update multiple sections.--set-start-addr <addr>β sets the start address of the output to<addr>. This overrides any--change-startor--adjust-startoptions you specified earlier. π₯--split-dwo <dwo-file>β same as runningllvm-objcopywith--extract-dwoand<dwo-file>as the output file and no other options, and then running--strip-dwoon the input file.--strip-dwoβ removes every DWARF.dwosection from the output.--strip-non-allocβ removes from the output every non-allocatable section that isn't inside segments.--strip-sectionsβ removes from the output all section headers and all section data that isn't inside segments. Heads up bestie: lots of tools won't be able to use an object with no section headers at all. π--target <format>,-Fβ equivalent to setting--input-targetand--output-targetto the format you name. See SUPPORTED FORMATS for the valid<format>values.--weaken-symbol <symbol>,-Wβ marks any global symbol named<symbol>as a weak symbol in the output. Specify it multiple times to weaken multiple symbols.--weaken-symbols <filename>β reads a list of names from the file<filename>and marks global symbols with those names as weak in the output. One symbol per line, leading/trailing whitespace ignored, and anything after a#ignored too. Can be specified multiple times to read from multiple files.--weakenβ marks every defined global symbol as weak in the output.
π MACH-O-SPECIFIC OPTIONS π
--keep-undefinedβ keeps undefined symbols, even when 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 the 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, every target except binary and ihex can have -freebsd tacked on as a suffix. π¦
π§ 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. It comes with the 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 exactly as you wrote it on the command line, with every non-alphanumeric character converted to _. πΈ
If you use binary as the value for --output-target, the output file becomes a raw binary file containing the memory image of the input file. Symbols and relocation info get tossed out entirely. The image starts 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. β¨
π BUGS π
To report bugs, please visit <https://github.com/llvm/llvm-project/labels/tools:llvm-objcopy/strip/>.
There's a known issue where --input-target and --target only actually do anything for the binary and ihex formats. Any other value just gets ignored, and llvm-objcopy will try to guess the input format instead. π
π SEE ALSO π
π AUTHOR π
Maintained by the LLVM Team (<https://llvm.org/>).
π COPYRIGHT π
okay bestie, the legal bit, and then we're done for real π
2003-2024, LLVM Project π«Ά
that's it. that's the whole thing. the LLVM Project has been holding it down since 2003 and is still going strong in 2024, no cap β¨ like... two decades of compilers and object file magic?? we love a long-running icon π
and that's a wrap on the whole LLVM-OBJCOPY(1) page, fr fr π you made it to the end, which is genuinely main character energy π
cute lil' sign-off for the receipts π§Ύβ¨
- this was page
15of the manual π - dated
2024-04-14πΈ - and it lives under the name
LLVM-OBJCOPY(1)π¦
go copy some objects, bestie. you got this. periodt π
π¦ where this page comes from
- ubuntu noble: llvm-16 1:16.0.6-23ubuntu4 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms