blob: aa974d00f3e1684898a9348f36bcb1f1d1d54089 [file] [log] [blame]
Roland McGrath8190db62006-12-17 23:56:51 +00001/* Copyright (C) 2002, 2005, 2006 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02002 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00003 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4
Mark Wielaardde2ed972012-06-05 17:15:16 +02005 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.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00009
Mark Wielaardde2ed972012-06-05 17:15:16 +020010 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000011 WITHOUT ANY WARRANTY; without even the implied warranty of
Mark Wielaardde2ed972012-06-05 17:15:16 +020012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000014
Mark Wielaardde2ed972012-06-05 17:15:16 +020015 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/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000017
18#include <config.h>
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23
24#include <libelfP.h>
25
26static 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" },
Mark Wielaardfef9e112017-10-04 16:51:15 +020042 { ELF_E_INVALID_ELF, "invalid ELF file data" },
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000043 { ELF_E_INVALID_OP, "invalid operation" },
44 { ELF_E_NO_VERSION, "ELF version not set" },
45 { ELF_E_INVALID_CMD, "invalid command" },
46 { ELF_E_RANGE, "offset out of range" },
47 { ELF_E_ARCHIVE_FMAG, "invalid fmag field in archive header" },
48 { ELF_E_INVALID_ARCHIVE, "invalid archive file" },
49 { ELF_E_NO_ARCHIVE, "descriptor is not for an archive" },
50 { ELF_E_NO_INDEX, "no index available" },
51 { ELF_E_READ_ERROR, "cannot read data from file" },
52 { ELF_E_WRITE_ERROR, "cannot write data to file" },
53 { ELF_E_INVALID_CLASS, "invalid binary class" },
54 { ELF_E_INVALID_INDEX, "invalid section index" },
55 { ELF_E_INVALID_OPERAND, "invalid operand" },
56 { ELF_E_INVALID_SECTION, "invalid section" },
57 { ELF_E_INVALID_COMMAND, "invalid command" },
58 { ELF_E_WRONG_ORDER_EHDR, "executable header not created first" },
59 { ELF_E_FD_DISABLED, "file descriptor disabled" },
Ulrich Drepperc2d1e482010-04-10 18:23:47 -070060 { ELF_E_FD_MISMATCH, "archive/member file descriptor mismatch" },
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000061 { ELF_E_OFFSET_RANGE, "offset out of range" },
62 { ELF_E_NOT_NUL_SECTION, "cannot manipulate null section" },
63 { ELF_E_DATA_MISMATCH, "data/scn mismatch" },
64 { ELF_E_INVALID_SECTION_HEADER, "invalid section header" },
65 { ELF_E_INVALID_DATA, "invalid data" },
66 { ELF_E_DATA_ENCODING, "unknown data encoding" },
67 { ELF_E_SECTION_TOO_SMALL, "section `sh_size' too small for data" },
68 { ELF_E_INVALID_ALIGN, "invalid section alignment" },
69 { ELF_E_INVALID_SHENTSIZE, "invalid section entry size" },
70 { ELF_E_UPDATE_RO, "update() for write on read-only file" },
71 { ELF_E_NOFILE, "no such file" },
72 { ELF_E_GROUP_NOT_REL,
73 "only relocatable files can contain section groups" },
74 { ELF_E_INVALID_PHDR,
Ulrich Drepper56bc0b82006-12-18 22:38:08 +000075 "program header only allowed in executables, shared objects, \
76and core files" },
Ulrich Drepper41de4882005-08-03 00:02:56 +000077 { ELF_E_NO_PHDR, "file has no program header" },
Mark Wielaard5ddb50a2015-11-20 00:12:37 +010078 { ELF_E_INVALID_OFFSET, "invalid offset" },
79 { ELF_E_INVALID_SECTION_TYPE , "invalid section type" },
80 { ELF_E_INVALID_SECTION_FLAGS , "invalid section flags" },
Mark Wielaard272018b2015-12-19 01:29:54 +010081 { ELF_E_NOT_COMPRESSED, "section does not contain compressed data" },
82 { ELF_E_ALREADY_COMPRESSED, "section contains compressed data" },
83 { ELF_E_UNKNOWN_COMPRESSION_TYPE, "unknown compression type" },
84 { ELF_E_COMPRESS_ERROR, "cannot compress data" },
85 { ELF_E_DECOMPRESS_ERROR, "cannot decompress data" }
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}