From c6375cb970388a3d4f691350fecdfd528eb334df Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Mon, 7 Feb 2011 14:32:56 +0100 Subject: elff: Remove un-needed qemu-common.h include. The elff library doesn't really depend on anything QEMU-specific. This will allow us to use it in other projects later. Change-Id: I662b6e864b320cd9cf2fe246d04fbba95be66c56 --- elff/elf.h | 283 ----------------------------------------------------- elff/elf_alloc.h | 7 +- elff/elf_defs.h | 2 +- elff/elf_file.cc | 5 + elff/elff-common.h | 23 +---- elff/elff_api.h | 2 +- elff/elff_elf.h | 281 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 293 insertions(+), 310 deletions(-) delete mode 100644 elff/elf.h create mode 100644 elff/elff_elf.h (limited to 'elff') diff --git a/elff/elf.h b/elff/elf.h deleted file mode 100644 index f3f5abc..0000000 --- a/elff/elf.h +++ /dev/null @@ -1,283 +0,0 @@ -/* Copyright (C) 2007-2010 The Android Open Source Project -** -** This software is licensed under the terms of the GNU General Public -** License version 2, as published by the Free Software Foundation, and -** may be copied, distributed, and modified under those terms. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -*/ - -/* - * Contains declarations of types, constants and structures - * describing ELF file format. - */ - -#ifndef ELFF_ELH_H_ -#define ELFF_ELH_H_ - -extern "C" { -#include "qemu-common.h" -} -#include "elff-common.h" - -//============================================================================= -// ELF file definitions -//============================================================================= - -/* - * ELF format documentation uses Elf##_Xxx notation for data types, where - * ## stands for CPU architecture (32, or 64 bit), and Xxx stands for a - * specific type. For the sake of compliance, we will follow doc's notation - * when defining types used in ELF file descriptors. However, for the sake of - * code simplicity, we will drop CPU architecture index from the types that - * have equal sizes on both, 32 and 64 bit architectures. - */ - -/* - * Architecture independent types. - */ - -typedef uint8_t Elf_Byte; -typedef int8_t Elf_Sbyte; - -typedef uint16_t Elf_Half; -typedef int16_t Elf_Shalf; - -typedef uint32_t Elf_Word; -typedef int32_t Elf_Sword; - -typedef uint64_t Elf_Xword; -typedef int64_t Elf_Sxword; - -/* - * Architecture dependent types. - */ - -/* 32-bit ELF address. */ -typedef uint32_t Elf32_Addr; -/* 32-bit ELF offset. */ -typedef uint32_t Elf32_Off; - -/* 64-bit ELF address. */ -typedef uint64_t Elf64_Addr; -/* 64-bit ELF offset. */ -typedef uint64_t Elf64_Off; - -//============================================================================= -// ELF file header -//============================================================================= - -/* Byte size of the fixed portion of ELF header. */ -#define EI_NIDENT 16 - -/* Common (architecture independent portion of) ELF file header, - * that starts at offset 0 in ELF file. - */ -typedef struct Elf_CommonHdr { - union { - struct { - /* ei_mag0 - ei_mag3 contain ELF header signature. See ELFMAGx bellow. */ - Elf_Byte ei_mag0; - Elf_Byte ei_mag1; - Elf_Byte ei_mag2; - Elf_Byte ei_mag3; - - /* File class (32, or 64 bits). See ELFCLASSxxx bellow. */ - Elf_Byte ei_class; - - /* Data encoding (endianness). See ELFDATAxxx bellow. */ - Elf_Byte ei_data; - - /* ELF header version number. */ - Elf_Byte ei_version; - } ei_info; - unsigned char e_ident[EI_NIDENT]; - }; - - /* File type (executable, shared object, etc.) */ - Elf_Half e_type; - - /* Processor type. */ - Elf_Half e_machine; - - /* File version. */ - Elf_Word e_version; -} Elf_CommonHdr; - - -/* ELF header signature. */ -#define ELFMAG0 0x7f -#define ELFMAG1 'E' -#define ELFMAG2 'L' -#define ELFMAG3 'F' -#define ELFMAG "\177ELF" -#define SELFMAG 4 - -/* - * Possible ei_class values. - */ - -/* Invalid. */ -#define ELFCLASSNONE 0 -/* It's 32-bit ELF file. */ -#define ELFCLASS32 1 -/* It's 64-bit ELF file. */ -#define ELFCLASS64 2 - -/* - * Possible ei_data values. - */ - -/* Invalid. */ -#define ELFDATANONE 0 -/* ELF data is formatted in little-endian. */ -#define ELFDATA2LSB 1 -/* ELF data is formatted in big-endian. */ -#define ELFDATA2MSB 2 - -/* Tempated (architecture dependent) ELF file header. - * Template param: - * Elf_Addr - Actual type for address encoding (Elf32_Addr, or Elf64_Addr). - * Elf_Off - Actual type for offset encoding (Elf32_Off, or Elf64_Off). - */ -template -struct Elf_FHdr { - /* Common header. */ - Elf_CommonHdr common; - - /* Module entry point. */ - Elf_Addr e_entry; - - /* Programm header table offset (in bytes) from the beginning of the file. - * Zero if there is no programm header in this file. - */ - Elf_Off e_phoff; - - /* Section header table offset (in bytes) from the beginning of the file. - * Zero if there is no section header in this file. - */ - Elf_Off e_shoff; - - /* Processor-specific flags. */ - Elf_Word e_flags; - - /* This header size in bytes. */ - Elf_Half e_ehsize; - - /* Byte size of an entry in programm header table. All entries - * in the table are the same size. - */ - Elf_Half e_phentsize; - - /* Number of entries in programm header table. */ - Elf_Half e_phnum; - - /* Byte size of an entry in section header table. All entries - * in the table are the same size. - */ - Elf_Half e_shentsize; - - /* Number of entries in section header table. */ - Elf_Half e_shnum; - - /* Zero-based index of an entry for name string table section in the section - * header table. If no such section exists in the file this field contains - * SHN_UNDEF value. - */ - Elf_Half e_shstrndx; -}; -/* 32-bit ELF header. */ -typedef Elf_FHdr Elf32_FHdr; -/* 64-bit ELF header. */ -typedef Elf_FHdr Elf64_FHdr; - -//============================================================================= -// ELF section header -//============================================================================= - -/* Templated (architecture dependent) section header for ELF file. - * Template param: - * Elf_Addr - Actual type for address encoding (Elf32_Addr, or Elf64_Addr). - * Elf_Off - Actual type for offset encoding (Elf32_Off, or Elf64_Off). - */ -template -struct Elf_SHdr { - /* Index (byte offset) of section name in the name string table section. */ - Elf_Word sh_name; - - /* Section type and semantics. */ - Elf_Word sh_type; - - /* Section flags and attributes. */ - Elf_Word sh_flags; - - /* Section address in the memory image of the process. */ - Elf_Addr sh_addr; - - /* Byte offset from the beginning of the ELF file to the first - * byte in the section. - */ - Elf_Off sh_offset; - - /* Section size in bytes. */ - Elf_Word sh_size; - - /* Section header table index link. Depends on section type. */ - Elf_Word sh_link; - - /* Extra section information, depending on the section type. */ - Elf_Word sh_info; - - /* Address alignment constrains. 0 and 1 means that section has no - * alignment constrains. - */ - Elf_Word sh_addralign; - - /* Entry size for sections that hold some kind of a table. */ - Elf_Word sh_entsize; -}; -/* 32-bit section header. */ -typedef Elf_SHdr Elf32_SHdr; -/* 64-bit section header. */ -typedef Elf_SHdr Elf64_SHdr; - -/* - * Special section indices - */ -#define SHN_UNDEF 0 -#define SHN_LORESERVE 0xff00 -#define SHN_LOPROC 0xff00 -#define SHN_HIPROC 0xff1f -#define SHN_LOOS 0xff20 -#define SHN_HIOS 0xff3f -#define SHN_ABS 0xfff1 -#define SHN_COMMON 0xfff2 -#define SHN_XINDEX 0xffff -#define SHN_HIRESERVE 0xffff - -/* - * Values for sh_type - */ -#define SHT_NULL 0 -#define SHT_PROGBITS 1 -#define SHT_SYMTAB 2 -#define SHT_STRTAB 3 -#define SHT_RELA 4 -#define SHT_HASH 5 -#define SHT_DYNAMIC 6 -#define SHT_NOTE 7 -#define SHT_NOBITS 8 -#define SHT_REL 9 -#define SHT_SHLIB 10 -#define SHT_DYNSYM 11 -#define SHT_INIT_ARRAY 14 -#define SHT_FINI_ARRAY 15 -#define SHT_PREINIT_ARRAY 16 -#define SHT_GROUP 17 -#define SHT_SYMTAB_SHNDX 18 -#define SHT_NUM 19 - -#endif // ELFF_ELH_H_ diff --git a/elff/elf_alloc.h b/elff/elf_alloc.h index 648a1e9..bf3103b 100644 --- a/elff/elf_alloc.h +++ b/elff/elf_alloc.h @@ -18,9 +18,7 @@ #ifndef ELFF_ELF_ALLOC_H_ #define ELFF_ELF_ALLOC_H_ -extern "C" { -#include "qemu-common.h" -} +#include #include "elff-common.h" class ElfFile; @@ -157,4 +155,7 @@ class DwarfAllocBase { } }; +extern "C" void* elff_alloc(size_t size); +extern "C" void elff_free(void* ptr); + #endif // ELFF_ELF_ALLOC_H_ diff --git a/elff/elf_defs.h b/elff/elf_defs.h index 1eca81b..8687f0f 100644 --- a/elff/elf_defs.h +++ b/elff/elf_defs.h @@ -17,7 +17,7 @@ #ifndef ELFF_ELF_DEFS_H_ #define ELFF_ELF_DEFS_H_ -#include "elf.h" +#include "elff_elf.h" //============================================================================= // Macros. diff --git a/elff/elf_file.cc b/elff/elf_file.cc index 5a6392c..3f1825e 100644 --- a/elff/elf_file.cc +++ b/elff/elf_file.cc @@ -20,6 +20,11 @@ #include "dwarf_cu.h" #include "dwarf_utils.h" +#include +#ifndef O_BINARY +#define O_BINARY 0 +#endif + /* Tags to parse when collecting info about routines. */ static const Dwarf_Tag parse_rt_tags[] = { DW_TAG_compile_unit, diff --git a/elff/elff-common.h b/elff/elff-common.h index 8729736..a8ae7fb 100644 --- a/elff/elff-common.h +++ b/elff/elff-common.h @@ -22,6 +22,7 @@ #include "assert.h" #include "memory.h" #include "errno.h" +#include "stdlib.h" #ifdef WIN32 #include "windows.h" #else // WIN32 @@ -34,26 +35,4 @@ static inline void _set_errno(uint32_t err) { errno = err; } -/* Main operator new. We overwrite it to redirect memory - * allocations to qemu_malloc, instead of malloc. */ -inline void* operator new(size_t size) { - return qemu_malloc(size); -} - -/* Main operator delete. We overwrite it to redirect memory - * deallocation to qemu_free, instead of free. */ -inline void operator delete(void* p) { - if (p != NULL) { - qemu_free(p); - } -} - -/* Main operator delete for arrays. We overwrite it to redirect - * memory deallocation to qemu_free, instead of free. */ -inline void operator delete[](void* p) { - if (p != NULL) { - qemu_free(p); - } -} - #endif // ELFF_ELFF_COMMON_H_ diff --git a/elff/elff_api.h b/elff/elff_api.h index 7b02746..d18798b 100644 --- a/elff/elff_api.h +++ b/elff/elff_api.h @@ -23,7 +23,7 @@ extern "C" { #endif -#include "qemu-common.h" +#include /* Defines type for a handle used in ELFF API. */ typedef void* ELFF_HANDLE; diff --git a/elff/elff_elf.h b/elff/elff_elf.h new file mode 100644 index 0000000..ea19233 --- /dev/null +++ b/elff/elff_elf.h @@ -0,0 +1,281 @@ +/* Copyright (C) 2007-2010 The Android Open Source Project +** +** This software is licensed under the terms of the GNU General Public +** License version 2, as published by the Free Software Foundation, and +** may be copied, distributed, and modified under those terms. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +*/ + +/* + * Contains declarations of types, constants and structures + * describing ELF file format. + */ + +#ifndef ELFF_ELH_H_ +#define ELFF_ELH_H_ + +#include +#include "elff-common.h" + +//============================================================================= +// ELF file definitions +//============================================================================= + +/* + * ELF format documentation uses Elf##_Xxx notation for data types, where + * ## stands for CPU architecture (32, or 64 bit), and Xxx stands for a + * specific type. For the sake of compliance, we will follow doc's notation + * when defining types used in ELF file descriptors. However, for the sake of + * code simplicity, we will drop CPU architecture index from the types that + * have equal sizes on both, 32 and 64 bit architectures. + */ + +/* + * Architecture independent types. + */ + +typedef uint8_t Elf_Byte; +typedef int8_t Elf_Sbyte; + +typedef uint16_t Elf_Half; +typedef int16_t Elf_Shalf; + +typedef uint32_t Elf_Word; +typedef int32_t Elf_Sword; + +typedef uint64_t Elf_Xword; +typedef int64_t Elf_Sxword; + +/* + * Architecture dependent types. + */ + +/* 32-bit ELF address. */ +typedef uint32_t Elf32_Addr; +/* 32-bit ELF offset. */ +typedef uint32_t Elf32_Off; + +/* 64-bit ELF address. */ +typedef uint64_t Elf64_Addr; +/* 64-bit ELF offset. */ +typedef uint64_t Elf64_Off; + +//============================================================================= +// ELF file header +//============================================================================= + +/* Byte size of the fixed portion of ELF header. */ +#define EI_NIDENT 16 + +/* Common (architecture independent portion of) ELF file header, + * that starts at offset 0 in ELF file. + */ +typedef struct Elf_CommonHdr { + union { + struct { + /* ei_mag0 - ei_mag3 contain ELF header signature. See ELFMAGx bellow. */ + Elf_Byte ei_mag0; + Elf_Byte ei_mag1; + Elf_Byte ei_mag2; + Elf_Byte ei_mag3; + + /* File class (32, or 64 bits). See ELFCLASSxxx bellow. */ + Elf_Byte ei_class; + + /* Data encoding (endianness). See ELFDATAxxx bellow. */ + Elf_Byte ei_data; + + /* ELF header version number. */ + Elf_Byte ei_version; + } ei_info; + unsigned char e_ident[EI_NIDENT]; + }; + + /* File type (executable, shared object, etc.) */ + Elf_Half e_type; + + /* Processor type. */ + Elf_Half e_machine; + + /* File version. */ + Elf_Word e_version; +} Elf_CommonHdr; + + +/* ELF header signature. */ +#define ELFMAG0 0x7f +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFMAG "\177ELF" +#define SELFMAG 4 + +/* + * Possible ei_class values. + */ + +/* Invalid. */ +#define ELFCLASSNONE 0 +/* It's 32-bit ELF file. */ +#define ELFCLASS32 1 +/* It's 64-bit ELF file. */ +#define ELFCLASS64 2 + +/* + * Possible ei_data values. + */ + +/* Invalid. */ +#define ELFDATANONE 0 +/* ELF data is formatted in little-endian. */ +#define ELFDATA2LSB 1 +/* ELF data is formatted in big-endian. */ +#define ELFDATA2MSB 2 + +/* Tempated (architecture dependent) ELF file header. + * Template param: + * Elf_Addr - Actual type for address encoding (Elf32_Addr, or Elf64_Addr). + * Elf_Off - Actual type for offset encoding (Elf32_Off, or Elf64_Off). + */ +template +struct Elf_FHdr { + /* Common header. */ + Elf_CommonHdr common; + + /* Module entry point. */ + Elf_Addr e_entry; + + /* Programm header table offset (in bytes) from the beginning of the file. + * Zero if there is no programm header in this file. + */ + Elf_Off e_phoff; + + /* Section header table offset (in bytes) from the beginning of the file. + * Zero if there is no section header in this file. + */ + Elf_Off e_shoff; + + /* Processor-specific flags. */ + Elf_Word e_flags; + + /* This header size in bytes. */ + Elf_Half e_ehsize; + + /* Byte size of an entry in programm header table. All entries + * in the table are the same size. + */ + Elf_Half e_phentsize; + + /* Number of entries in programm header table. */ + Elf_Half e_phnum; + + /* Byte size of an entry in section header table. All entries + * in the table are the same size. + */ + Elf_Half e_shentsize; + + /* Number of entries in section header table. */ + Elf_Half e_shnum; + + /* Zero-based index of an entry for name string table section in the section + * header table. If no such section exists in the file this field contains + * SHN_UNDEF value. + */ + Elf_Half e_shstrndx; +}; +/* 32-bit ELF header. */ +typedef Elf_FHdr Elf32_FHdr; +/* 64-bit ELF header. */ +typedef Elf_FHdr Elf64_FHdr; + +//============================================================================= +// ELF section header +//============================================================================= + +/* Templated (architecture dependent) section header for ELF file. + * Template param: + * Elf_Addr - Actual type for address encoding (Elf32_Addr, or Elf64_Addr). + * Elf_Off - Actual type for offset encoding (Elf32_Off, or Elf64_Off). + */ +template +struct Elf_SHdr { + /* Index (byte offset) of section name in the name string table section. */ + Elf_Word sh_name; + + /* Section type and semantics. */ + Elf_Word sh_type; + + /* Section flags and attributes. */ + Elf_Word sh_flags; + + /* Section address in the memory image of the process. */ + Elf_Addr sh_addr; + + /* Byte offset from the beginning of the ELF file to the first + * byte in the section. + */ + Elf_Off sh_offset; + + /* Section size in bytes. */ + Elf_Word sh_size; + + /* Section header table index link. Depends on section type. */ + Elf_Word sh_link; + + /* Extra section information, depending on the section type. */ + Elf_Word sh_info; + + /* Address alignment constrains. 0 and 1 means that section has no + * alignment constrains. + */ + Elf_Word sh_addralign; + + /* Entry size for sections that hold some kind of a table. */ + Elf_Word sh_entsize; +}; +/* 32-bit section header. */ +typedef Elf_SHdr Elf32_SHdr; +/* 64-bit section header. */ +typedef Elf_SHdr Elf64_SHdr; + +/* + * Special section indices + */ +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_LOOS 0xff20 +#define SHN_HIOS 0xff3f +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_XINDEX 0xffff +#define SHN_HIRESERVE 0xffff + +/* + * Values for sh_type + */ +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_INIT_ARRAY 14 +#define SHT_FINI_ARRAY 15 +#define SHT_PREINIT_ARRAY 16 +#define SHT_GROUP 17 +#define SHT_SYMTAB_SHNDX 18 +#define SHT_NUM 19 + +#endif // ELFF_ELH_H_ -- cgit v1.1