What are stripped and not-stripped executables in Unix?
68,589
If you compile an executable with gcc's -g flag, it contains debugging information. That means for each instruction there is information which line of the source code generated it, the name of the variables in the source code is retained and can be associated to the matching memory at runtime etc. Strip can remove this debugging information and other data included in the executable which is not necessary for execution in order to reduce the size of the executable.
Related videos on Youtube
Author by
Lazer
Updated on September 17, 2022Comments
-
Lazer over 1 year
From man file,
EXAMPLES $ file file.c file /dev/{wd0a,hda} file.c: C program text file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped /dev/wd0a: block special (0/0) /dev/hda: block special (3/0) $ file -s /dev/wd0{b,d} /dev/wd0b: data /dev/wd0d: x86 boot sector $ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10} /dev/hda: x86 boot sector /dev/hda1: Linux/i386 ext2 filesystem /dev/hda2: x86 boot sector /dev/hda3: x86 boot sector, extended partition table /dev/hda4: Linux/i386 ext2 filesystem /dev/hda5: Linux/i386 swap file /dev/hda6: Linux/i386 swap file /dev/hda7: Linux/i386 swap file /dev/hda8: Linux/i386 swap file /dev/hda9: empty /dev/hda10: empty $ file -i file.c file /dev/{wd0a,hda} file.c: text/x-c file: application/x-executable, dynamically linked (uses shared libs), not stripped /dev/hda: application/x-not-regular-file /dev/wd0a: application/x-not-regular-file
What does executable stripping mean?
Why are some of the executables stripped while others are not?
-
Michael Mrozek over 13 yearsSee also the strip(1) manpage. Generally strip removes all symbols since they're not strictly necessary; it removes debugging info too, but symbols are the big thing
-
Gilles 'SO- stop being evil' over 13 yearsThe concept generalizes to most executable formats, this isn't specific to gcc or even to unix.
-
dbush almost 13 yearsI had a 40MB executable that when stripped was reduced to 6MB - just so you get an idea of the kind of space that debugging data takes up.
-
ysap almost 9 yearsSo, does stripping an executable
prog.e
that was built withgcc -g -o prog.e prog.c
gets you the equivalent of compiling withgcc -O0 -o prog.e prog.c
? -
LouisDev almost 9 years@ysap no, it has nothing to do with optimizing (-O). The assembly code stays the same whether or not the file is stripped. You get an executable without the debugging info (so you're right about the loss of "-g") and without all symbols (that is, function names, global variable names...). It is the equivalent of "gcc -s -o prog.e prog.c". When a program is executed, symbols do not make any difference. But for example proprietary software always have symbols stripped because otherwise everyone could know the original names of functions and their locations.
-
Ilias ETTOUKI over 5 yearsJust to clarify. Even if you compile the file without the
-g
switch, it will still be 'non stripped', at least in terms of thefile
utility. So, the debug information is just one thing which can be stripped, but not the only one. But there are also symbols and relocation information, which may be as significant both in terms of importance and size.