• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2002, 2005, 2006 Red Hat, Inc.
2    This file is part of elfutils.
3    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4 
5    This file is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9 
10    elfutils is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17 
18 #include <config.h>
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include <libelfP.h>
25 
26 static struct
27 {
28   int id;
29   const char *expected;
30 } libelf_msgs[ELF_E_NUM] =
31   {
32     { ELF_E_NOERROR, "no error" },
33     { ELF_E_UNKNOWN_ERROR, "unknown error" },
34     { ELF_E_UNKNOWN_VERSION, "unknown version" },
35     { ELF_E_UNKNOWN_TYPE, "unknown type" },
36     { ELF_E_INVALID_HANDLE, "invalid `Elf' handle" },
37     { ELF_E_SOURCE_SIZE, "invalid size of source operand" },
38     { ELF_E_DEST_SIZE, "invalid size of destination operand" },
39     { ELF_E_INVALID_ENCODING, "invalid encoding" },
40     { ELF_E_NOMEM, "out of memory" },
41     { ELF_E_INVALID_FILE, "invalid file descriptor" },
42     { ELF_E_INVALID_OP, "invalid operation" },
43     { ELF_E_NO_VERSION, "ELF version not set" },
44     { ELF_E_INVALID_CMD, "invalid command" },
45     { ELF_E_RANGE, "offset out of range" },
46     { ELF_E_ARCHIVE_FMAG, "invalid fmag field in archive header" },
47     { ELF_E_INVALID_ARCHIVE, "invalid archive file" },
48     { ELF_E_NO_ARCHIVE, "descriptor is not for an archive" },
49     { ELF_E_NO_INDEX, "no index available" },
50     { ELF_E_READ_ERROR, "cannot read data from file" },
51     { ELF_E_WRITE_ERROR, "cannot write data to file" },
52     { ELF_E_INVALID_CLASS, "invalid binary class" },
53     { ELF_E_INVALID_INDEX, "invalid section index" },
54     { ELF_E_INVALID_OPERAND, "invalid operand" },
55     { ELF_E_INVALID_SECTION, "invalid section" },
56     { ELF_E_INVALID_COMMAND, "invalid command" },
57     { ELF_E_WRONG_ORDER_EHDR, "executable header not created first" },
58     { ELF_E_FD_DISABLED, "file descriptor disabled" },
59     { ELF_E_FD_MISMATCH, "archive/member file descriptor mismatch" },
60     { ELF_E_OFFSET_RANGE, "offset out of range" },
61     { ELF_E_NOT_NUL_SECTION, "cannot manipulate null section" },
62     { ELF_E_DATA_MISMATCH, "data/scn mismatch" },
63     { ELF_E_INVALID_SECTION_HEADER, "invalid section header" },
64     { ELF_E_INVALID_DATA, "invalid data" },
65     { ELF_E_DATA_ENCODING, "unknown data encoding" },
66     { ELF_E_SECTION_TOO_SMALL, "section `sh_size' too small for data" },
67     { ELF_E_INVALID_ALIGN, "invalid section alignment" },
68     { ELF_E_INVALID_SHENTSIZE, "invalid section entry size" },
69     { ELF_E_UPDATE_RO, "update() for write on read-only file" },
70     { ELF_E_NOFILE, "no such file" },
71     { ELF_E_GROUP_NOT_REL,
72       "only relocatable files can contain section groups" },
73     { ELF_E_INVALID_PHDR,
74       "program header only allowed in executables, shared objects, \
75 and core files" },
76     { ELF_E_NO_PHDR, "file has no program header" },
77     { ELF_E_INVALID_OFFSET, "invalid offset" },
78     { ELF_E_INVALID_SECTION_TYPE , "invalid section type" },
79     { ELF_E_INVALID_SECTION_FLAGS , "invalid section flags" },
80     { ELF_E_NOT_COMPRESSED, "section does not contain compressed data" },
81     { ELF_E_ALREADY_COMPRESSED, "section contains compressed data" },
82     { ELF_E_UNKNOWN_COMPRESSION_TYPE, "unknown compression type" },
83     { ELF_E_COMPRESS_ERROR, "cannot compress data" },
84     { ELF_E_DECOMPRESS_ERROR, "cannot decompress data" }
85   };
86 
87 
88 int
main(void)89 main (void)
90 {
91   size_t cnt;
92   int result = EXIT_SUCCESS;
93 
94   /* Clear the error state.  */
95   (void) elf_errno ();
96 
97   /* Check all the messages of libelf.  */
98   for (cnt = 1; cnt < ELF_E_NUM; ++cnt)
99     {
100       const char *str = elf_errmsg (libelf_msgs[cnt].id);
101 
102       if (strcmp (str, libelf_msgs[cnt].expected) != 0)
103 	{
104 	  printf ("libelf msg %zu: expected \"%s\", got \"%s\"\n",
105 		  cnt, libelf_msgs[cnt].expected, str);
106 	  result = EXIT_FAILURE;
107 	}
108     }
109 
110   return result;
111 }
112