LinuxCommandLibrary

strip

Remove symbols from object files

TLDR

Replace the input file with its stripped version

$ strip [path/to/file]
copy

Strip symbols from a file, saving the output to a specific file
$ strip [path/to/input_file] -o [path/to/output_file]
copy

Strip debug symbols only
$ strip [[-d|--strip-debug]] [path/to/file.o]
copy

SYNOPSIS

strip [options] file...

PARAMETERS

-s, --strip-all
    Remove all symbols (debug, non-global, relocation) from the input file(s).

-g, -S, --strip-debug
    Remove debugging symbols and sections only (e.g., '.debug', '.line'). Other symbols are preserved.

-p, --strip-unneeded
    Remove all symbols that are not needed for relocation processing. This often keeps more symbols than --strip-all but fewer than --strip-debug.

-d, --discard-all
    Remove all local symbols from the output. Global symbols are kept.

-x, --discard-locals
    Remove all non-global symbols from the output. This is similar to -d.

-R SECTIONNAME, --remove-section=SECTIONNAME
    Remove the specified section from the output file. Can be used multiple times.

-K SECTIONNAME, --keep-section=SECTIONNAME
    Do not strip the specified section. This is useful when using --strip-all but you want to preserve certain sections.

-N SYMBOLNAME, --strip-symbol=SYMBOLNAME
    Do not strip the specified symbol. Useful for preserving specific symbols even with aggressive stripping.

-o FILE, --output=FILE
    Write the stripped output to FILE, rather than modifying the input file in place. This option is only valid when stripping a single file.

-F BFDNAME, --target=BFDNAME
    Specify the binary file format of the input files. For example, 'elf64-x86-64'.

-I BFDNAME, --input-target=BFDNAME
    Specify the binary file format of the input files. Alias for --target.

-O BFDNAME, --output-target=BFDNAME
    Specify the binary file format for the output file. Allows converting between formats.

-v, --verbose
    List all object file names as they are processed, providing verbose output.

--help
    Display a summary of the command's options and usage.

--version
    Display the version number of the strip utility.

DESCRIPTION

strip is a utility program that modifies executable files, shared libraries, or object files by removing symbols and debugging information. These symbols include function names, variable names, and line numbers, which are typically used by debuggers. By removing this metadata, strip can significantly reduce the file size of the binary, which is beneficial for embedded systems, network transfer, or when disk space is a concern.

Additionally, stripping can offer a minor security benefit by making reverse engineering slightly more difficult, as meaningful names are replaced by addresses. While strip makes binaries smaller and potentially harder to analyze, it also means that debugging a stripped executable becomes much more challenging, as symbolic information needed for traceback and breakpoint setting is no longer available. It is part of the GNU Binutils package.

CAVEATS

Stripping an executable makes it significantly harder to debug, as symbolic information (function names, line numbers) vital for debuggers and stack traces is removed.

While it adds a minor hurdle, stripping does not prevent determined reverse engineering or analysis using disassemblers.

Care must be taken when stripping shared libraries, as removing too much can break other executables that depend on specific symbols being present.

OBJECT FILE FORMATS AND BFD

strip uses the Binary File Descriptor (BFD) library to read and write object files. BFD provides a common interface for strip (and other binutils like ld, objdump) to work with various file formats (ELF, COFF, PE, a.out) across different architectures. This allows strip to be highly portable and versatile.

SYMBOL TYPES

Symbols stripped by the command can be broadly categorized. Debugging symbols (e.g., DWARF information) are used by debuggers. Local symbols are internal to a compilation unit (e.g., static functions/variables). Global symbols are visible externally and used for linking between different object files or libraries. Understanding these distinctions helps in choosing the appropriate strip options for desired outcomes.

HISTORY

The strip command is a long-standing utility, dating back to early Unix systems. It is now a core component of the GNU Binutils project, a collection of binary tools maintained by the GNU Project. Its development has focused on supporting various object file formats (like ELF, COFF, a.out) and providing fine-grained control over what information to remove, adapting to the complexities of modern compilation and linking processes.

SEE ALSO

objdump(1), readelf(1), nm(1), ld(1), gcc(1)

Copied to clipboard