Brian Silverman | 8649792 | 2018-02-10 19:28:39 -0500 | [diff] [blame^] | 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_ELF, "invalid ELF file data" }, |
| 43 | { 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" }, |
| 60 | { ELF_E_FD_MISMATCH, "archive/member file descriptor mismatch" }, |
| 61 | { 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, |
| 75 | "program header only allowed in executables, shared objects, \ |
| 76 | and core files" }, |
| 77 | { ELF_E_NO_PHDR, "file has no program header" }, |
| 78 | { ELF_E_INVALID_OFFSET, "invalid offset" }, |
| 79 | { ELF_E_INVALID_SECTION_TYPE , "invalid section type" }, |
| 80 | { ELF_E_INVALID_SECTION_FLAGS , "invalid section flags" }, |
| 81 | { 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" } |
| 86 | }; |
| 87 | |
| 88 | |
| 89 | int |
| 90 | main (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 | } |