ziglang/zig
objcopy
Active contributors: andrewrk
Purpose
lib/compiler/objcopy.zig (~31 KB) is the Zig implementation of objcopy. It backs the zig objcopy sub-command and provides a single binary that handles ELF, Mach-O, and COFF for the cases the toolchain needs — strip sections, extract debug info, convert formats, set/clear symbols.
Features
The flag set in lib/compiler/objcopy.zig mirrors the GNU objcopy features the Zig toolchain depends on, including:
--strip-debug/--strip-all/--only-keep-debug— debug info separation.-O <format>/-I <format>— output/input format conversion (where supported).--add-gnu-debuglink— link a stripped binary to an external symbol file.--set-section-flags,--rename-section— section editing.--extract-to <file>— extract debug info into its own file.
How it is used
- Stand-alone:
zig objcopy .... Uses the same CLI shape as GNU objcopy. - From the build system:
std.Build.Step.ObjCopyinlib/std/Build/Step/ObjCopy.ziginvokes it as a step. - From
Compilation: when split debug info is requested,src/Compilation.zigruns an objcopy pass over the linker output.
Implementation
The implementation reads the input file via lib/std/elf.zig, lib/std/macho.zig, or lib/std/coff.zig, applies the requested transformations in memory, and writes the result. Supporting helpers come from lib/std/Build/Cache.zig (paths) and lib/std/Io.zig (I/O).
Key source files
| File | Purpose |
|---|---|
lib/compiler/objcopy.zig |
Implementation. |
lib/std/Build/Step/ObjCopy.zig |
Build-step wrapper. |
lib/std/elf.zig, lib/std/macho.zig, lib/std/coff.zig |
File-format support. |
See Linkers for the upstream stage that produces the binary objcopy operates on.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.