function::stack_unused - Linux


Overview

function::stack_unused finds and lists all unused functions in the provided binary. This is useful for identifying functions that are included in the binary but are not actually called.

Syntax

function::stack_unused [-r <regex>] [-q] [-v] [-g|-G] <binary>

Options/Flags

  • -r <regex>: Specify a regular expression to filter the output. Only functions matching the regular expression will be listed.
  • -q: Quiet mode. Only print the names of unused functions, not their addresses.
  • -v: Verbose mode. Print additional information about each unused function, including its address and size.
  • -g or -G: Graph mode. Print a graph of the call graph, showing which functions are called by which other functions.

Examples

To list all unused functions in the binary ./my_binary, run the following command:

function::stack_unused ./my_binary

To list only unused functions with names that contain the string "foo", run the following command:

function::stack_unused -r '.*foo.*' ./my_binary

To print a graph of the call graph, run the following command:

function::stack_unused -g ./my_binary

Common Issues

One common issue is that function::stack_unused may report false positives. This can happen if a function is called by a function pointer that is not statically defined in the binary. To avoid this, you can use the -q or -v flags to see more information about each unused function.

Integration

function::stack_unused can be integrated with other Linux commands and tools to perform advanced tasks. For example, you can use function::stack_unused to identify unused functions in a library, and then use objdump to remove those functions from the library.

Related Commands

  • nm: List the symbols in a binary.
  • objdump: Dump the contents of a binary.
  • readelf: Read the ELF headers of a binary.