Symbols, Stripping and What Remains
A binary built with symbols tells you the name of every function and global variable; one built with debug information also tells you types, source lines and local variable names. Release binaries are usually stripped: the names are removed to save space (and sometimes in the hope of making analysis harder). An analyst needs to know exactly what stripping removes and, more importantly, what it can't remove, because the leftovers (imported function names, strings, unwind tables, build ids) are where the analysis of a stripped binary starts.
Definitions
.symtab: the full symbol table, every function and global with its address, size and type, includingstaticones. Used by linkers and debuggers, not needed to run the program..dynsym: the dynamic symbol table, only the symbols needed for dynamic linking: functions and variables imported from shared libraries, and those the binary exports. Needed at run time, so stripping can't remove it.- Symbol types in
nmoutput:T/tcode (upper case = global, lower case = local/static),D/dinitialised data,B/bzero-initialised data (.bss),R/rread-only data,Uundefined (imported),Wweak. - Debug information (DWARF, sections
.debug_*, from-g): types, line numbers, variables. Can be split into a separate file and linked by.gnu_debuglinkor the build id. strip: removes.symtab,.strtaband debug sections (--strip-all, the default forstripwith no options), or only debug information (--strip-debug).
Before and after strip
The session builds a toy with a global variable, a static helper and an exported function, then compares what each tool sees before and after strip. It compiles at -O0 so the helper stays a separate function; at -O1 GCC would inline it and fold strlen of the constant path, and both names would vanish before strip even runs.
cat > toy.c <<'SRC'
#include <stdio.h>
#include <string.h>
int request_count = 0;
static const char *SECRET_PATH = "/etc/toy/secret.conf";
static int checksum(const char *s) { /* a static (local) helper */
int h = 0;
for (; *s; s++) h = h * 31 + (unsigned char)*s;
return h;
}
int handle_request(const char *msg) {
request_count++;
return checksum(msg) ^ (int)strlen(SECRET_PATH);
}
int main(int argc, char **argv) {
printf("%d\n", handle_request(argc > 1 ? argv[1] : "ping"));
return 0;
}
SRC
gcc -O0 -g toy.c -o toy
cp toy toy-stripped && strip toy-stripped
echo "== nm toy (functions and data from the program itself)"
nm toy | grep -E ' [TtDdBbRr] ' | grep -vE ' _|frame_dummy|deregister|register_tm|completed'
echo "== nm toy-stripped"
nm toy-stripped 2>&1
echo "== still there after strip"
echo "dynamic imports: $(nm -D toy-stripped | awk '$1=="U"{print $2}' | sed 's/@.*//' | sort | tr '\n' ' ')"
echo "strings: $(strings -n 8 toy-stripped | grep toy)"
echo "unwind entries: $(readelf --debug-dump=frames toy-stripped 2>/dev/null | grep -c FDE) FDEs in .eh_frame"
echo "build id: $(readelf -n toy-stripped | awk '/Build ID/{print substr($3,1,8)}')..."
for f in toy toy-stripped; do printf '%-13s %6s bytes, %2s sections, file says: %s\n' "$f" \
"$(stat -c %s $f)" "$(readelf -SW $f | grep -c '^ \[')" "$(file -b $f | grep -oE '(not )?stripped')"; done== nm toy (functions and data from the program itself)
0000000000004010 d SECRET_PATH
0000000000001169 t checksum
00000000000011ae T handle_request
00000000000011f3 T main
000000000000401c B request_count
== nm toy-stripped
nm: toy-stripped: no symbols
== still there after strip
dynamic imports: __libc_start_main printf strlen
strings: /etc/toy/secret.conf
unwind entries: 7 FDEs in .eh_frame
build id: 257f7a42...
toy 17936 bytes, 38 sections, file says: not stripped
toy-stripped 14480 bytes, 30 sections, file says: stripped
What strip removed: the names checksum, handle_request, request_count and SECRET_PATH, the debug information, and with it a large part of the file. What it couldn't remove:
- Imported names (
printf,strlen,__libc_start_main): the dynamic loader needs them. - Strings: the secret path is data the program uses.
- Unwind tables (
.eh_frame): each FDE (frame description entry) describes one function's address range so exceptions and stack traces work. Counting FDEs gives a rough function count (here 7: the program's three functions plus_startand one each for the.plt,.plt.gotand.plt.secstubs), and their start addresses are function boundaries, which tools such as Ghidra and IDA use to find functions in stripped files. - The build id: a hash of the build that links this file to its separate debug file, crash reports and package metadata.
Shipping without symbols, debugging with them
The standard practice is to ship stripped binaries and keep the debug information in a separate file, found by build id. The session splits the debug info out and shows gdb finding it again.
printf 'int add(int a, int b) { return a + b; }\nint main(void) { return add(2, 3); }\n' > dbg.c
gcc -O0 -g dbg.c -o app
objcopy --only-keep-debug app app.debug
strip --strip-all app
objcopy --add-gnu-debuglink=app.debug app
printf 'app %s bytes, app.debug %s bytes\n' "$(stat -c %s app)" "$(stat -c %s app.debug)"
gdb -q -batch -ex 'info line add' -ex 'break add' -ex 'run' -ex 'info args' ./app 2>&1 | grep -vE '^\[|libthread|^