1 /* Copyright (C) 1999, 2000, 2001, 2002, 2005 Red Hat, Inc.
2 This file is part of Red Hat elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 1999.
5 Red Hat elfutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by the
7 Free Software Foundation; version 2 of the License.
9 Red Hat elfutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with Red Hat elfutils; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
18 Red Hat elfutils is an included package of the Open Invention Network.
19 An included package of the Open Invention Network is a package for which
20 Open Invention Network licensees cross-license their patents. No patent
21 license is granted, either expressly or impliedly, by designation as an
22 included package. Should you wish to participate in the Open Invention
23 Network licensing program, please visit www.openinventionnetwork.com
24 <http://www.openinventionnetwork.com>. */
34 print_ehdr (Elf32_Ehdr *ehdr)
38 for (n = 0; n < EI_NIDENT; ++n)
39 printf (" %02x", ehdr->e_ident[n]);
41 printf ("\ntype = %d\nmachine = %d\nversion = %d\nentry = %d\n"
42 "phoff = %d\nshoff = %d\nflags = %d\nehsize = %d\n"
43 "phentsize = %d\nphnum = %d\nshentsize = %d\nshnum = %d\n"
61 main (int argc, char *argv[] __attribute__ ((unused)))
66 char fname[] = "newfile-XXXXXX";
71 printf ("cannot create temporary file: %m\n");
74 /* Remove the file when we exit. */
77 elf_version (EV_CURRENT);
78 elf = elf_begin (fd, ELF_C_WRITE, NULL);
81 printf ("elf_begin: %s\n", elf_errmsg (-1));
86 if (elf32_newehdr (elf) == NULL)
88 printf ("elf32_newehdr: %s\n", elf_errmsg (-1));
93 Elf32_Ehdr *ehdr = elf32_getehdr (elf);
97 printf ("elf32_getehdr: %s\n", elf_errmsg (-1));
105 /* Use argc as a debugging flag. */
109 for (i = 0; i < EI_NIDENT; ++i)
110 if (ehdr->e_ident[i] != 0)
112 printf ("ehdr->e_ident[%d] != 0\n", i);
117 #define VALUE_TEST(name, val) \
118 if (ehdr->name != val) \
120 printf ("ehdr->%s != %d\n", #name, val); \
123 #define ZERO_TEST(name) VALUE_TEST (name, 0)
125 ZERO_TEST (e_machine);
126 ZERO_TEST (e_version);
131 ZERO_TEST (e_ehsize);
132 ZERO_TEST (e_phentsize);
134 ZERO_TEST (e_shentsize);
136 ZERO_TEST (e_shstrndx);
138 if (elf32_newphdr (elf, 10) == NULL)
140 printf ("elf32_newphdr: %s\n", elf_errmsg (-1));
148 ehdr = elf32_getehdr (elf);
151 printf ("elf32_getehdr (#2): %s\n", elf_errmsg (-1));
157 ZERO_TEST (e_machine);
158 ZERO_TEST (e_version);
163 ZERO_TEST (e_ehsize);
164 VALUE_TEST (e_phentsize, (int) sizeof (Elf32_Phdr));
165 VALUE_TEST (e_phnum, 10);
166 ZERO_TEST (e_shentsize);
168 ZERO_TEST (e_shstrndx);
174 (void) elf_end (elf);