• Skip to sidebar navigation
  • Skip to content

Bitbucket

  • More
    ProjectsRepositories
  • Help
    • Online help
    • Learn Git
    • Welcome to Bitbucket
    • Keyboard shortcuts
  • Log In
Alexander Dahl
  1. Alexander Dahl

buildroot

Public
Actions
  • Clone
  • Compare

Learn more about cloning repositories

You have read-only access

Navigation
  • Source
  • Commits
  • Branches
  • All Branches Graph
  • Forks
  1. Alexander Dahl
  2. buildroot

Source

buildroot/toolchain/sstrip/sstrip.c
Peter KorsgaardPeter Korsgaard committed c0e307b848d13 Jul 2010
Raw file
Source viewDiff to previous
static int readphdrtable ## CLASS (int fd, Elf ## CLASS ## _Ehdr const *ehdr, \
 
1
/* http://www.muppetlabs.com/~breadbox/software/elfkickers.html */
2
​
3
/* sstrip: Copyright (C) 1999-2001 by Brian Raiter, under the GNU
4
 * General Public License. No warranty. See COPYING for details.
5
 *
6
 * Aug 23, 2004 Hacked by Manuel Novoa III <mjn3@codepoet.org> to
7
 * handle targets of different endianness and/or elf class, making
8
 * it more useful in a cross-devel environment.
9
 */
10
​
11
/* ============== original README ===================
12
 *
13
 * sstrip is a small utility that removes the contents at the end of an
14
 * ELF file that are not part of the program's memory image.
15
 * 
16
 * Most ELF executables are built with both a program header table and a
17
 * section header table. However, only the former is required in order
18
 * for the OS to load, link and execute a program. sstrip attempts to
19
 * extract the ELF header, the program header table, and its contents,
20
 * leaving everything else in the bit bucket. It can only remove parts of
21
 * the file that occur at the end, after the parts to be saved. However,
22
 * this almost always includes the section header table, and occasionally
23
 * a few random sections that are not used when running a program.
24
 * 
25
 * It should be noted that the GNU bfd library is (understandably)
26
 * dependent on the section header table as an index to the file's
27
 * contents. Thus, an executable file that has no section header table
28
 * cannot be used with gdb, objdump, or any other program based upon the
29
 * bfd library, at all. In fact, the program will not even recognize the
30
 * file as a valid executable. (This limitation is noted in the source
31
 * code comments for bfd, and is marked "FIXME", so this may change at
32
 * some future date. However, I would imagine that it is a pretty
33
 * low-priority item, as executables without a section header table are
34
 * rare in the extreme.) This probably also explains why strip doesn't
35
 * offer the option to do this.
36
 * 
37
 * Shared library files may also have their section header table removed.
38
 * Such a library will still function; however, it will no longer be
39
 * possible for a compiler to link a new program against it.
40
 * 
41
 * As an added bonus, sstrip also tries to removes trailing zero bytes
42
 * from the end of the file. (This normally cannot be done with an
43
 * executable that has a section header table.)
44
 * 
45
 * sstrip is a very simplistic program. It depends upon the common
46
 * practice of putting the parts of the file that contribute to the
47
 * memory image at the front, and the remaining material at the end. This
48
 * permits it to discard the latter material without affecting file
49
 * offsets and memory addresses in what remains. Of course, the ELF
50
 * standard permits files to be organized in almost any order, so if a
51
 * pathological linker decided to put its section headers at the top,
52
 * sstrip would be useless on such executables.
53
 */
54
​
55
#include    <stdio.h>
56
#include    <stdlib.h>
57
#include    <string.h>
58
#include    <errno.h>
59
#include    <unistd.h>
60
#include    <fcntl.h>
61
#include    <elf.h>
62
#include    <endian.h>
63
#include    <byteswap.h>
  • Git repository management for enterprise teams powered by Atlassian Bitbucket
  • Atlassian Bitbucket v6.7.2
  • Documentation
  • Request a feature
  • About
  • Contact Atlassian
Atlassian

Everything looks good. We'll let you know here if there's anything you should know about.