1 /* Test program for elf_update function.
2 Copyright (C) 2000, 2002, 2005 Red Hat, Inc.
3 This file is part of elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
6 This file is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 elfutils is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 main (int argc, char *argv[] __attribute__ ((unused)))
35 const char *fname = "xxx_update1";
41 fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
44 printf ("cannot open `%s': %s\n", fname, strerror (errno));
48 elf_version (EV_CURRENT);
50 elf = elf_begin (fd, ELF_C_WRITE, NULL);
53 printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
57 /* Create an ELF header. */
58 ehdr = elf32_newehdr (elf);
61 printf ("cannot create ELF header: %s\n", elf_errmsg (-1));
65 /* Print the ELF header values. */
68 for (i = 0; i < EI_NIDENT; ++i)
69 printf (" %02x", ehdr->e_ident[i]);
71 \ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
72 "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
73 "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
74 ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
75 ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
76 ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
77 ehdr->e_shnum, ehdr->e_shstrndx);
80 ehdr->e_ident[0] = 42;
88 /* Write out the file. */
89 if (elf_update (elf, ELF_C_WRITE) < 0)
91 printf ("failure in elf_update: %s\n", elf_errmsg (-1));
95 /* Create an ELF header. */
96 ehdr = elf32_newehdr (elf);
99 printf ("cannot create ELF header: %s\n", elf_errmsg (-1));
103 /* Print the ELF header values. */
106 for (i = 0; i < EI_NIDENT; ++i)
107 printf (" %02x", ehdr->e_ident[i]);
109 \ntype = %hu\nmachine = %hu\nversion = %u\nentry = %u\nphoff = %u\n"
110 "shoff = %u\nflags = %u\nehsize = %hu\nphentsize = %hu\n"
111 "phnum = %hu\nshentsize = %hu\nshnum = %hu\nshstrndx = %hu\n",
112 ehdr->e_type, ehdr->e_machine, ehdr->e_version, ehdr->e_entry,
113 ehdr->e_phoff, ehdr->e_shoff, ehdr->e_flags, ehdr->e_ehsize,
114 ehdr->e_phentsize, ehdr->e_phnum, ehdr->e_shentsize,
115 ehdr->e_shnum, ehdr->e_shstrndx);
118 if (elf_end (elf) != 0)
120 printf ("failure in elf_end: %s\n", elf_errmsg (-1));