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