1 | sstrip is a small utility that removes the contents at the end of an
|
---|
2 | ELF file that are not part of the program's memory image.
|
---|
3 |
|
---|
4 | Most ELF executables are built with both a program header table and a
|
---|
5 | section header table. However, only the former is required in order
|
---|
6 | for the OS to load, link and execute a program. sstrip attempts to
|
---|
7 | extract the ELF header, the program header table, and its contents,
|
---|
8 | leaving everything else in the bit bucket. It can only remove parts of
|
---|
9 | the file that occur at the end, after the parts to be saved. However,
|
---|
10 | this almost always includes the section header table, and occasionally
|
---|
11 | a few random sections that are not used when running a program.
|
---|
12 |
|
---|
13 | It should be noted that the GNU bfd library is (understandably)
|
---|
14 | dependent on the section header table as an index to the file's
|
---|
15 | contents. Thus, an executable file that has no section header table
|
---|
16 | cannot be used with gdb, objdump, or any other program based upon the
|
---|
17 | bfd library, at all. In fact, the program will not even recognize the
|
---|
18 | file as a valid executable. (This limitation is noted in the source
|
---|
19 | code comments for bfd, and is marked "FIXME", so this may change at
|
---|
20 | some future date. However, I would imagine that it is a pretty
|
---|
21 | low-priority item, as executables without a section header table are
|
---|
22 | rare in the extreme.) This probably also explains why strip doesn't
|
---|
23 | offer the option to do this.
|
---|
24 |
|
---|
25 | Shared library files may also have their section header table removed.
|
---|
26 | Such a library will still function; however, it will no longer be
|
---|
27 | possible for a compiler to link a new program against it.
|
---|
28 |
|
---|
29 | As an added bonus, sstrip also tries to removes trailing zero bytes
|
---|
30 | from the end of the file. (This normally cannot be done with an
|
---|
31 | executable that has a section header table.)
|
---|
32 |
|
---|
33 | sstrip is a very simplistic program. It depends upon the common
|
---|
34 | practice of putting the parts of the file that contribute to the
|
---|
35 | memory image at the front, and the remaining material at the end. This
|
---|
36 | permits it to discard the latter material without affecting file
|
---|
37 | offsets and memory addresses in what remains. However, the ELF
|
---|
38 | standard permits files to be organized in almost any order. So
|
---|
39 | although this procedure usually works in practice, it is not meant to
|
---|
40 | be taken too seriously.
|
---|