blob: db078533fdf419eba4ef8ba2b4777ef1964b6035 [file] [log] [blame]
Roland McGrath8190db62006-12-17 23:56:51 +00001/* Copyright (C) 2002, 2005, 2006 Red Hat, Inc.
Ulrich Drepper361df7d2006-04-04 21:38:57 +00002 This file is part of Red Hat elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00003 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4
Ulrich Drepper361df7d2006-04-04 21:38:57 +00005 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.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00008
Ulrich Drepper361df7d2006-04-04 21:38:57 +00009 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.
13
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,
Ulrich Drepper1e9ef502006-04-04 22:29:06 +000016 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000017
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>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000025
26#include <config.h>
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31
32#include <libelfP.h>
33
34static struct
35{
36 int id;
37 const char *expected;
38} libelf_msgs[ELF_E_NUM] =
39 {
40 { ELF_E_NOERROR, "no error" },
41 { ELF_E_UNKNOWN_ERROR, "unknown error" },
42 { ELF_E_UNKNOWN_VERSION, "unknown version" },
43 { ELF_E_UNKNOWN_TYPE, "unknown type" },
44 { ELF_E_INVALID_HANDLE, "invalid `Elf' handle" },
45 { ELF_E_SOURCE_SIZE, "invalid size of source operand" },
46 { ELF_E_DEST_SIZE, "invalid size of destination operand" },
47 { ELF_E_INVALID_ENCODING, "invalid encoding" },
48 { ELF_E_NOMEM, "out of memory" },
49 { ELF_E_INVALID_FILE, "invalid file descriptor" },
50 { ELF_E_INVALID_OP, "invalid operation" },
51 { ELF_E_NO_VERSION, "ELF version not set" },
52 { ELF_E_INVALID_CMD, "invalid command" },
53 { ELF_E_RANGE, "offset out of range" },
54 { ELF_E_ARCHIVE_FMAG, "invalid fmag field in archive header" },
55 { ELF_E_INVALID_ARCHIVE, "invalid archive file" },
56 { ELF_E_NO_ARCHIVE, "descriptor is not for an archive" },
57 { ELF_E_NO_INDEX, "no index available" },
58 { ELF_E_READ_ERROR, "cannot read data from file" },
59 { ELF_E_WRITE_ERROR, "cannot write data to file" },
60 { ELF_E_INVALID_CLASS, "invalid binary class" },
61 { ELF_E_INVALID_INDEX, "invalid section index" },
62 { ELF_E_INVALID_OPERAND, "invalid operand" },
63 { ELF_E_INVALID_SECTION, "invalid section" },
64 { ELF_E_INVALID_COMMAND, "invalid command" },
65 { ELF_E_WRONG_ORDER_EHDR, "executable header not created first" },
66 { ELF_E_FD_DISABLED, "file descriptor disabled" },
67 { ELF_E_FD_MISMATCH, "archive/member fildes mismatch" },
68 { ELF_E_OFFSET_RANGE, "offset out of range" },
69 { ELF_E_NOT_NUL_SECTION, "cannot manipulate null section" },
70 { ELF_E_DATA_MISMATCH, "data/scn mismatch" },
71 { ELF_E_INVALID_SECTION_HEADER, "invalid section header" },
72 { ELF_E_INVALID_DATA, "invalid data" },
73 { ELF_E_DATA_ENCODING, "unknown data encoding" },
74 { ELF_E_SECTION_TOO_SMALL, "section `sh_size' too small for data" },
75 { ELF_E_INVALID_ALIGN, "invalid section alignment" },
76 { ELF_E_INVALID_SHENTSIZE, "invalid section entry size" },
77 { ELF_E_UPDATE_RO, "update() for write on read-only file" },
78 { ELF_E_NOFILE, "no such file" },
79 { ELF_E_GROUP_NOT_REL,
80 "only relocatable files can contain section groups" },
81 { ELF_E_INVALID_PHDR,
Ulrich Drepper56bc0b82006-12-18 22:38:08 +000082 "program header only allowed in executables, shared objects, \
83and core files" },
Ulrich Drepper41de4882005-08-03 00:02:56 +000084 { ELF_E_NO_PHDR, "file has no program header" },
85 { ELF_E_INVALID_OFFSET, "invalid offset" }
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000086 };
87
88
89int
90main (void)
91{
92 size_t cnt;
93 int result = EXIT_SUCCESS;
94
95 /* Clear the error state. */
96 (void) elf_errno ();
97
98 /* Check all the messages of libelf. */
99 for (cnt = 1; cnt < ELF_E_NUM; ++cnt)
100 {
101 const char *str = elf_errmsg (libelf_msgs[cnt].id);
102
103 if (strcmp (str, libelf_msgs[cnt].expected) != 0)
104 {
105 printf ("libelf msg %zu: expected \"%s\", got \"%s\"\n",
106 cnt, libelf_msgs[cnt].expected, str);
107 result = EXIT_FAILURE;
108 }
109 }
110
111 return result;
112}