ia64/xen-unstable
changeset 19012:7df072566b8c
Move libelf headers out of xen public header dir.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Thu Jan 08 13:15:49 2009 +0000 (2009-01-08) |
parents | 275abe1c5d24 |
children | 6cec460c3290 |
files | tools/include/Makefile tools/libxc/xc_core.h tools/libxc/xc_dom.h tools/libxc/xc_elf.h tools/libxc/xc_hvm_build.c tools/xcutils/readnotes.c xen/arch/ia64/xen/domain.c xen/arch/x86/boot/mkelf32.c xen/arch/x86/domain_build.c xen/common/libelf/libelf-private.h xen/include/public/elfstructs.h xen/include/public/libelf.h xen/include/xen/elf.h xen/include/xen/elfstructs.h xen/include/xen/libelf.h |
line diff
1.1 --- a/tools/include/Makefile Thu Jan 08 13:08:37 2009 +0000 1.2 +++ b/tools/include/Makefile Thu Jan 08 13:15:49 2009 +0000 1.3 @@ -10,11 +10,12 @@ xen-foreign: 1.4 1.5 xen/.dir: 1.6 @rm -rf xen 1.7 - mkdir xen 1.8 + mkdir -p xen/libelf 1.9 ln -sf ../$(XEN_ROOT)/xen/include/public/COPYING xen 1.10 ln -sf $(addprefix ../,$(wildcard $(XEN_ROOT)/xen/include/public/*.h)) xen 1.11 ln -sf $(addprefix ../$(XEN_ROOT)/xen/include/public/,arch-ia64 arch-x86 hvm io xsm) xen 1.12 ln -sf ../xen-sys/$(XEN_OS) xen/sys 1.13 + ln -sf $(addprefix ../../$(XEN_ROOT)/xen/include/xen/,libelf.h elfstructs.h) xen/libelf/ 1.14 ln -s ../xen-foreign xen/foreign 1.15 touch $@ 1.16
2.1 --- a/tools/libxc/xc_core.h Thu Jan 08 13:08:37 2009 +0000 2.2 +++ b/tools/libxc/xc_core.h Thu Jan 08 13:15:49 2009 +0000 2.3 @@ -23,7 +23,7 @@ 2.4 2.5 #include "xen/version.h" 2.6 #include "xg_private.h" 2.7 -#include "xen/elfstructs.h" 2.8 +#include "xen/libelf/elfstructs.h" 2.9 2.10 /* section names */ 2.11 #define XEN_DUMPCORE_SEC_NOTE ".note.Xen"
3.1 --- a/tools/libxc/xc_dom.h Thu Jan 08 13:08:37 2009 +0000 3.2 +++ b/tools/libxc/xc_dom.h Thu Jan 08 13:15:49 2009 +0000 3.3 @@ -1,4 +1,4 @@ 3.4 -#include <xen/libelf.h> 3.5 +#include <xen/libelf/libelf.h> 3.6 3.7 #define INVALID_P2M_ENTRY ((xen_pfn_t)-1) 3.8
4.1 --- a/tools/libxc/xc_elf.h Thu Jan 08 13:08:37 2009 +0000 4.2 +++ b/tools/libxc/xc_elf.h Thu Jan 08 13:15:49 2009 +0000 4.3 @@ -1,1 +1,1 @@ 4.4 -#include <xen/elfstructs.h> 4.5 +#include <xen/libelf/elfstructs.h>
5.1 --- a/tools/libxc/xc_hvm_build.c Thu Jan 08 13:08:37 2009 +0000 5.2 +++ b/tools/libxc/xc_hvm_build.c Thu Jan 08 13:15:49 2009 +0000 5.3 @@ -17,7 +17,7 @@ 5.4 #include <xen/hvm/params.h> 5.5 #include "xc_e820.h" 5.6 5.7 -#include <xen/libelf.h> 5.8 +#include <xen/libelf/libelf.h> 5.9 5.10 #define SUPERPAGE_PFN_SHIFT 9 5.11 #define SUPERPAGE_NR_PFNS (1UL << SUPERPAGE_PFN_SHIFT)
6.1 --- a/tools/xcutils/readnotes.c Thu Jan 08 13:08:37 2009 +0000 6.2 +++ b/tools/xcutils/readnotes.c Thu Jan 08 13:15:49 2009 +0000 6.3 @@ -13,7 +13,7 @@ 6.4 #include <xg_private.h> 6.5 #include <xc_dom.h> /* gunzip bits */ 6.6 6.7 -#include <xen/libelf.h> 6.8 +#include <xen/libelf/libelf.h> 6.9 6.10 static void print_string_note(const char *prefix, struct elf_binary *elf, 6.11 const elf_note *note)
7.1 --- a/xen/arch/ia64/xen/domain.c Thu Jan 08 13:08:37 2009 +0000 7.2 +++ b/xen/arch/ia64/xen/domain.c Thu Jan 08 13:15:49 2009 +0000 7.3 @@ -31,7 +31,7 @@ 7.4 #include <xen/event.h> 7.5 #include <xen/console.h> 7.6 #include <xen/version.h> 7.7 -#include <public/libelf.h> 7.8 +#include <xen/libelf.h> 7.9 #include <asm/pgalloc.h> 7.10 #include <asm/offsets.h> /* for IA64_THREAD_INFO_SIZE */ 7.11 #include <asm/vcpu.h> /* for function declarations */
8.1 --- a/xen/arch/x86/boot/mkelf32.c Thu Jan 08 13:08:37 2009 +0000 8.2 +++ b/xen/arch/x86/boot/mkelf32.c Thu Jan 08 13:15:49 2009 +0000 8.3 @@ -25,7 +25,7 @@ 8.4 #define s16 int16_t 8.5 #define s32 int32_t 8.6 #define s64 int64_t 8.7 -#include "../../../include/public/elfstructs.h" 8.8 +#include "../../../include/xen/elfstructs.h" 8.9 8.10 #define DYNAMICALLY_FILLED 0 8.11 #define RAW_OFFSET 128
9.1 --- a/xen/arch/x86/domain_build.c Thu Jan 08 13:08:37 2009 +0000 9.2 +++ b/xen/arch/x86/domain_build.c Thu Jan 08 13:15:49 2009 +0000 9.3 @@ -19,6 +19,7 @@ 9.4 #include <xen/iocap.h> 9.5 #include <xen/bitops.h> 9.6 #include <xen/compat.h> 9.7 +#include <xen/libelf.h> 9.8 #include <asm/regs.h> 9.9 #include <asm/system.h> 9.10 #include <asm/io.h> 9.11 @@ -30,7 +31,6 @@ 9.12 #include <asm/e820.h> 9.13 9.14 #include <public/version.h> 9.15 -#include <public/libelf.h> 9.16 9.17 extern unsigned long initial_images_nrpages(void); 9.18 extern void discard_initial_images(void);
10.1 --- a/xen/common/libelf/libelf-private.h Thu Jan 08 13:08:37 2009 +0000 10.2 +++ b/xen/common/libelf/libelf-private.h Thu Jan 08 13:15:49 2009 +0000 10.3 @@ -7,9 +7,9 @@ 10.4 #include <xen/types.h> 10.5 #include <xen/string.h> 10.6 #include <xen/lib.h> 10.7 +#include <xen/libelf.h> 10.8 #include <asm/byteorder.h> 10.9 #include <public/elfnote.h> 10.10 -#include <public/libelf.h> 10.11 10.12 #define elf_msg(elf, fmt, args ... ) \ 10.13 if (elf->verbose) printk(fmt, ## args ) 10.14 @@ -49,7 +49,7 @@ 10.15 #error Unsupported OS 10.16 #endif 10.17 #include <xen/elfnote.h> 10.18 -#include <xen/libelf.h> 10.19 +#include <xen/libelf/libelf.h> 10.20 10.21 #include "xenctrl.h" 10.22 #include "xc_private.h"
11.1 --- a/xen/include/public/elfstructs.h Thu Jan 08 13:08:37 2009 +0000 11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 11.3 @@ -1,527 +0,0 @@ 11.4 -#ifndef __XEN_PUBLIC_ELFSTRUCTS_H__ 11.5 -#define __XEN_PUBLIC_ELFSTRUCTS_H__ 1 11.6 -/* 11.7 - * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved. 11.8 - * 11.9 - * Redistribution and use in source and binary forms, with or without 11.10 - * modification, are permitted provided that the following conditions 11.11 - * are met: 11.12 - * 1. Redistributions of source code must retain the above copyright 11.13 - * notice, this list of conditions and the following disclaimer. 11.14 - * 2. Redistributions in binary form must reproduce the above copyright 11.15 - * notice, this list of conditions and the following disclaimer in the 11.16 - * documentation and/or other materials provided with the distribution. 11.17 - * 3. The name of the author may not be used to endorse or promote products 11.18 - * derived from this software without specific prior written permission 11.19 - * 11.20 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 11.21 - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 11.22 - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 11.23 - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 11.24 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 11.25 - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 11.26 - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 11.27 - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 11.28 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 11.29 - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11.30 - */ 11.31 - 11.32 -typedef uint8_t Elf_Byte; 11.33 - 11.34 -typedef uint32_t Elf32_Addr; /* Unsigned program address */ 11.35 -typedef uint32_t Elf32_Off; /* Unsigned file offset */ 11.36 -typedef int32_t Elf32_Sword; /* Signed large integer */ 11.37 -typedef uint32_t Elf32_Word; /* Unsigned large integer */ 11.38 -typedef uint16_t Elf32_Half; /* Unsigned medium integer */ 11.39 - 11.40 -typedef uint64_t Elf64_Addr; 11.41 -typedef uint64_t Elf64_Off; 11.42 -typedef int32_t Elf64_Shalf; 11.43 - 11.44 -typedef int32_t Elf64_Sword; 11.45 -typedef uint32_t Elf64_Word; 11.46 - 11.47 -typedef int64_t Elf64_Sxword; 11.48 -typedef uint64_t Elf64_Xword; 11.49 - 11.50 -typedef uint32_t Elf64_Half; 11.51 -typedef uint16_t Elf64_Quarter; 11.52 - 11.53 -/* 11.54 - * e_ident[] identification indexes 11.55 - * See http://www.caldera.com/developers/gabi/2000-07-17/ch4.eheader.html 11.56 - */ 11.57 -#define EI_MAG0 0 /* file ID */ 11.58 -#define EI_MAG1 1 /* file ID */ 11.59 -#define EI_MAG2 2 /* file ID */ 11.60 -#define EI_MAG3 3 /* file ID */ 11.61 -#define EI_CLASS 4 /* file class */ 11.62 -#define EI_DATA 5 /* data encoding */ 11.63 -#define EI_VERSION 6 /* ELF header version */ 11.64 -#define EI_OSABI 7 /* OS/ABI ID */ 11.65 -#define EI_ABIVERSION 8 /* ABI version */ 11.66 -#define EI_PAD 9 /* start of pad bytes */ 11.67 -#define EI_NIDENT 16 /* Size of e_ident[] */ 11.68 - 11.69 -/* e_ident[] magic number */ 11.70 -#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ 11.71 -#define ELFMAG1 'E' /* e_ident[EI_MAG1] */ 11.72 -#define ELFMAG2 'L' /* e_ident[EI_MAG2] */ 11.73 -#define ELFMAG3 'F' /* e_ident[EI_MAG3] */ 11.74 -#define ELFMAG "\177ELF" /* magic */ 11.75 -#define SELFMAG 4 /* size of magic */ 11.76 - 11.77 -/* e_ident[] file class */ 11.78 -#define ELFCLASSNONE 0 /* invalid */ 11.79 -#define ELFCLASS32 1 /* 32-bit objs */ 11.80 -#define ELFCLASS64 2 /* 64-bit objs */ 11.81 -#define ELFCLASSNUM 3 /* number of classes */ 11.82 - 11.83 -/* e_ident[] data encoding */ 11.84 -#define ELFDATANONE 0 /* invalid */ 11.85 -#define ELFDATA2LSB 1 /* Little-Endian */ 11.86 -#define ELFDATA2MSB 2 /* Big-Endian */ 11.87 -#define ELFDATANUM 3 /* number of data encode defines */ 11.88 - 11.89 -/* e_ident[] Operating System/ABI */ 11.90 -#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ 11.91 -#define ELFOSABI_HPUX 1 /* HP-UX operating system */ 11.92 -#define ELFOSABI_NETBSD 2 /* NetBSD */ 11.93 -#define ELFOSABI_LINUX 3 /* GNU/Linux */ 11.94 -#define ELFOSABI_HURD 4 /* GNU/Hurd */ 11.95 -#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ 11.96 -#define ELFOSABI_SOLARIS 6 /* Solaris */ 11.97 -#define ELFOSABI_MONTEREY 7 /* Monterey */ 11.98 -#define ELFOSABI_IRIX 8 /* IRIX */ 11.99 -#define ELFOSABI_FREEBSD 9 /* FreeBSD */ 11.100 -#define ELFOSABI_TRU64 10 /* TRU64 UNIX */ 11.101 -#define ELFOSABI_MODESTO 11 /* Novell Modesto */ 11.102 -#define ELFOSABI_OPENBSD 12 /* OpenBSD */ 11.103 -#define ELFOSABI_ARM 97 /* ARM */ 11.104 -#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ 11.105 - 11.106 -/* e_ident */ 11.107 -#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ 11.108 - (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ 11.109 - (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ 11.110 - (ehdr).e_ident[EI_MAG3] == ELFMAG3) 11.111 - 11.112 -/* ELF Header */ 11.113 -typedef struct elfhdr { 11.114 - unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ 11.115 - Elf32_Half e_type; /* object file type */ 11.116 - Elf32_Half e_machine; /* machine */ 11.117 - Elf32_Word e_version; /* object file version */ 11.118 - Elf32_Addr e_entry; /* virtual entry point */ 11.119 - Elf32_Off e_phoff; /* program header table offset */ 11.120 - Elf32_Off e_shoff; /* section header table offset */ 11.121 - Elf32_Word e_flags; /* processor-specific flags */ 11.122 - Elf32_Half e_ehsize; /* ELF header size */ 11.123 - Elf32_Half e_phentsize; /* program header entry size */ 11.124 - Elf32_Half e_phnum; /* number of program header entries */ 11.125 - Elf32_Half e_shentsize; /* section header entry size */ 11.126 - Elf32_Half e_shnum; /* number of section header entries */ 11.127 - Elf32_Half e_shstrndx; /* section header table's "section 11.128 - header string table" entry offset */ 11.129 -} Elf32_Ehdr; 11.130 - 11.131 -typedef struct { 11.132 - unsigned char e_ident[EI_NIDENT]; /* Id bytes */ 11.133 - Elf64_Quarter e_type; /* file type */ 11.134 - Elf64_Quarter e_machine; /* machine type */ 11.135 - Elf64_Half e_version; /* version number */ 11.136 - Elf64_Addr e_entry; /* entry point */ 11.137 - Elf64_Off e_phoff; /* Program hdr offset */ 11.138 - Elf64_Off e_shoff; /* Section hdr offset */ 11.139 - Elf64_Half e_flags; /* Processor flags */ 11.140 - Elf64_Quarter e_ehsize; /* sizeof ehdr */ 11.141 - Elf64_Quarter e_phentsize; /* Program header entry size */ 11.142 - Elf64_Quarter e_phnum; /* Number of program headers */ 11.143 - Elf64_Quarter e_shentsize; /* Section header entry size */ 11.144 - Elf64_Quarter e_shnum; /* Number of section headers */ 11.145 - Elf64_Quarter e_shstrndx; /* String table index */ 11.146 -} Elf64_Ehdr; 11.147 - 11.148 -/* e_type */ 11.149 -#define ET_NONE 0 /* No file type */ 11.150 -#define ET_REL 1 /* relocatable file */ 11.151 -#define ET_EXEC 2 /* executable file */ 11.152 -#define ET_DYN 3 /* shared object file */ 11.153 -#define ET_CORE 4 /* core file */ 11.154 -#define ET_NUM 5 /* number of types */ 11.155 -#define ET_LOPROC 0xff00 /* reserved range for processor */ 11.156 -#define ET_HIPROC 0xffff /* specific e_type */ 11.157 - 11.158 -/* e_machine */ 11.159 -#define EM_NONE 0 /* No Machine */ 11.160 -#define EM_M32 1 /* AT&T WE 32100 */ 11.161 -#define EM_SPARC 2 /* SPARC */ 11.162 -#define EM_386 3 /* Intel 80386 */ 11.163 -#define EM_68K 4 /* Motorola 68000 */ 11.164 -#define EM_88K 5 /* Motorola 88000 */ 11.165 -#define EM_486 6 /* Intel 80486 - unused? */ 11.166 -#define EM_860 7 /* Intel 80860 */ 11.167 -#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ 11.168 -/* 11.169 - * Don't know if EM_MIPS_RS4_BE, 11.170 - * EM_SPARC64, EM_PARISC, 11.171 - * or EM_PPC are ABI compliant 11.172 - */ 11.173 -#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ 11.174 -#define EM_SPARC64 11 /* SPARC v9 64-bit unoffical */ 11.175 -#define EM_PARISC 15 /* HPPA */ 11.176 -#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ 11.177 -#define EM_PPC 20 /* PowerPC */ 11.178 -#define EM_PPC64 21 /* PowerPC 64-bit */ 11.179 -#define EM_ARM 40 /* Advanced RISC Machines ARM */ 11.180 -#define EM_ALPHA 41 /* DEC ALPHA */ 11.181 -#define EM_SPARCV9 43 /* SPARC version 9 */ 11.182 -#define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */ 11.183 -#define EM_IA_64 50 /* Intel Merced */ 11.184 -#define EM_X86_64 62 /* AMD x86-64 architecture */ 11.185 -#define EM_VAX 75 /* DEC VAX */ 11.186 - 11.187 -/* Version */ 11.188 -#define EV_NONE 0 /* Invalid */ 11.189 -#define EV_CURRENT 1 /* Current */ 11.190 -#define EV_NUM 2 /* number of versions */ 11.191 - 11.192 -/* Section Header */ 11.193 -typedef struct { 11.194 - Elf32_Word sh_name; /* name - index into section header 11.195 - string table section */ 11.196 - Elf32_Word sh_type; /* type */ 11.197 - Elf32_Word sh_flags; /* flags */ 11.198 - Elf32_Addr sh_addr; /* address */ 11.199 - Elf32_Off sh_offset; /* file offset */ 11.200 - Elf32_Word sh_size; /* section size */ 11.201 - Elf32_Word sh_link; /* section header table index link */ 11.202 - Elf32_Word sh_info; /* extra information */ 11.203 - Elf32_Word sh_addralign; /* address alignment */ 11.204 - Elf32_Word sh_entsize; /* section entry size */ 11.205 -} Elf32_Shdr; 11.206 - 11.207 -typedef struct { 11.208 - Elf64_Half sh_name; /* section name */ 11.209 - Elf64_Half sh_type; /* section type */ 11.210 - Elf64_Xword sh_flags; /* section flags */ 11.211 - Elf64_Addr sh_addr; /* virtual address */ 11.212 - Elf64_Off sh_offset; /* file offset */ 11.213 - Elf64_Xword sh_size; /* section size */ 11.214 - Elf64_Half sh_link; /* link to another */ 11.215 - Elf64_Half sh_info; /* misc info */ 11.216 - Elf64_Xword sh_addralign; /* memory alignment */ 11.217 - Elf64_Xword sh_entsize; /* table entry size */ 11.218 -} Elf64_Shdr; 11.219 - 11.220 -/* Special Section Indexes */ 11.221 -#define SHN_UNDEF 0 /* undefined */ 11.222 -#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */ 11.223 -#define SHN_LOPROC 0xff00 /* reserved range for processor */ 11.224 -#define SHN_HIPROC 0xff1f /* specific section indexes */ 11.225 -#define SHN_ABS 0xfff1 /* absolute value */ 11.226 -#define SHN_COMMON 0xfff2 /* common symbol */ 11.227 -#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */ 11.228 - 11.229 -/* sh_type */ 11.230 -#define SHT_NULL 0 /* inactive */ 11.231 -#define SHT_PROGBITS 1 /* program defined information */ 11.232 -#define SHT_SYMTAB 2 /* symbol table section */ 11.233 -#define SHT_STRTAB 3 /* string table section */ 11.234 -#define SHT_RELA 4 /* relocation section with addends*/ 11.235 -#define SHT_HASH 5 /* symbol hash table section */ 11.236 -#define SHT_DYNAMIC 6 /* dynamic section */ 11.237 -#define SHT_NOTE 7 /* note section */ 11.238 -#define SHT_NOBITS 8 /* no space section */ 11.239 -#define SHT_REL 9 /* relation section without addends */ 11.240 -#define SHT_SHLIB 10 /* reserved - purpose unknown */ 11.241 -#define SHT_DYNSYM 11 /* dynamic symbol table section */ 11.242 -#define SHT_NUM 12 /* number of section types */ 11.243 -#define SHT_LOPROC 0x70000000 /* reserved range for processor */ 11.244 -#define SHT_HIPROC 0x7fffffff /* specific section header types */ 11.245 -#define SHT_LOUSER 0x80000000 /* reserved range for application */ 11.246 -#define SHT_HIUSER 0xffffffff /* specific indexes */ 11.247 - 11.248 -/* Section names */ 11.249 -#define ELF_BSS ".bss" /* uninitialized data */ 11.250 -#define ELF_DATA ".data" /* initialized data */ 11.251 -#define ELF_DEBUG ".debug" /* debug */ 11.252 -#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ 11.253 -#define ELF_DYNSTR ".dynstr" /* dynamic string table */ 11.254 -#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ 11.255 -#define ELF_FINI ".fini" /* termination code */ 11.256 -#define ELF_GOT ".got" /* global offset table */ 11.257 -#define ELF_HASH ".hash" /* symbol hash table */ 11.258 -#define ELF_INIT ".init" /* initialization code */ 11.259 -#define ELF_REL_DATA ".rel.data" /* relocation data */ 11.260 -#define ELF_REL_FINI ".rel.fini" /* relocation termination code */ 11.261 -#define ELF_REL_INIT ".rel.init" /* relocation initialization code */ 11.262 -#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */ 11.263 -#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ 11.264 -#define ELF_REL_TEXT ".rel.text" /* relocation code */ 11.265 -#define ELF_RODATA ".rodata" /* read-only data */ 11.266 -#define ELF_SHSTRTAB ".shstrtab" /* section header string table */ 11.267 -#define ELF_STRTAB ".strtab" /* string table */ 11.268 -#define ELF_SYMTAB ".symtab" /* symbol table */ 11.269 -#define ELF_TEXT ".text" /* code */ 11.270 - 11.271 - 11.272 -/* Section Attribute Flags - sh_flags */ 11.273 -#define SHF_WRITE 0x1 /* Writable */ 11.274 -#define SHF_ALLOC 0x2 /* occupies memory */ 11.275 -#define SHF_EXECINSTR 0x4 /* executable */ 11.276 -#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ 11.277 - /* specific section attributes */ 11.278 - 11.279 -/* Symbol Table Entry */ 11.280 -typedef struct elf32_sym { 11.281 - Elf32_Word st_name; /* name - index into string table */ 11.282 - Elf32_Addr st_value; /* symbol value */ 11.283 - Elf32_Word st_size; /* symbol size */ 11.284 - unsigned char st_info; /* type and binding */ 11.285 - unsigned char st_other; /* 0 - no defined meaning */ 11.286 - Elf32_Half st_shndx; /* section header index */ 11.287 -} Elf32_Sym; 11.288 - 11.289 -typedef struct { 11.290 - Elf64_Half st_name; /* Symbol name index in str table */ 11.291 - Elf_Byte st_info; /* type / binding attrs */ 11.292 - Elf_Byte st_other; /* unused */ 11.293 - Elf64_Quarter st_shndx; /* section index of symbol */ 11.294 - Elf64_Xword st_value; /* value of symbol */ 11.295 - Elf64_Xword st_size; /* size of symbol */ 11.296 -} Elf64_Sym; 11.297 - 11.298 -/* Symbol table index */ 11.299 -#define STN_UNDEF 0 /* undefined */ 11.300 - 11.301 -/* Extract symbol info - st_info */ 11.302 -#define ELF32_ST_BIND(x) ((x) >> 4) 11.303 -#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) 11.304 -#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) 11.305 - 11.306 -#define ELF64_ST_BIND(x) ((x) >> 4) 11.307 -#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf) 11.308 -#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) 11.309 - 11.310 -/* Symbol Binding - ELF32_ST_BIND - st_info */ 11.311 -#define STB_LOCAL 0 /* Local symbol */ 11.312 -#define STB_GLOBAL 1 /* Global symbol */ 11.313 -#define STB_WEAK 2 /* like global - lower precedence */ 11.314 -#define STB_NUM 3 /* number of symbol bindings */ 11.315 -#define STB_LOPROC 13 /* reserved range for processor */ 11.316 -#define STB_HIPROC 15 /* specific symbol bindings */ 11.317 - 11.318 -/* Symbol type - ELF32_ST_TYPE - st_info */ 11.319 -#define STT_NOTYPE 0 /* not specified */ 11.320 -#define STT_OBJECT 1 /* data object */ 11.321 -#define STT_FUNC 2 /* function */ 11.322 -#define STT_SECTION 3 /* section */ 11.323 -#define STT_FILE 4 /* file */ 11.324 -#define STT_NUM 5 /* number of symbol types */ 11.325 -#define STT_LOPROC 13 /* reserved range for processor */ 11.326 -#define STT_HIPROC 15 /* specific symbol types */ 11.327 - 11.328 -/* Relocation entry with implicit addend */ 11.329 -typedef struct { 11.330 - Elf32_Addr r_offset; /* offset of relocation */ 11.331 - Elf32_Word r_info; /* symbol table index and type */ 11.332 -} Elf32_Rel; 11.333 - 11.334 -/* Relocation entry with explicit addend */ 11.335 -typedef struct { 11.336 - Elf32_Addr r_offset; /* offset of relocation */ 11.337 - Elf32_Word r_info; /* symbol table index and type */ 11.338 - Elf32_Sword r_addend; 11.339 -} Elf32_Rela; 11.340 - 11.341 -/* Extract relocation info - r_info */ 11.342 -#define ELF32_R_SYM(i) ((i) >> 8) 11.343 -#define ELF32_R_TYPE(i) ((unsigned char) (i)) 11.344 -#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) 11.345 - 11.346 -typedef struct { 11.347 - Elf64_Xword r_offset; /* where to do it */ 11.348 - Elf64_Xword r_info; /* index & type of relocation */ 11.349 -} Elf64_Rel; 11.350 - 11.351 -typedef struct { 11.352 - Elf64_Xword r_offset; /* where to do it */ 11.353 - Elf64_Xword r_info; /* index & type of relocation */ 11.354 - Elf64_Sxword r_addend; /* adjustment value */ 11.355 -} Elf64_Rela; 11.356 - 11.357 -#define ELF64_R_SYM(info) ((info) >> 32) 11.358 -#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF) 11.359 -#define ELF64_R_INFO(s,t) (((s) << 32) + (u_int32_t)(t)) 11.360 - 11.361 -/* Program Header */ 11.362 -typedef struct { 11.363 - Elf32_Word p_type; /* segment type */ 11.364 - Elf32_Off p_offset; /* segment offset */ 11.365 - Elf32_Addr p_vaddr; /* virtual address of segment */ 11.366 - Elf32_Addr p_paddr; /* physical address - ignored? */ 11.367 - Elf32_Word p_filesz; /* number of bytes in file for seg. */ 11.368 - Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ 11.369 - Elf32_Word p_flags; /* flags */ 11.370 - Elf32_Word p_align; /* memory alignment */ 11.371 -} Elf32_Phdr; 11.372 - 11.373 -typedef struct { 11.374 - Elf64_Half p_type; /* entry type */ 11.375 - Elf64_Half p_flags; /* flags */ 11.376 - Elf64_Off p_offset; /* offset */ 11.377 - Elf64_Addr p_vaddr; /* virtual address */ 11.378 - Elf64_Addr p_paddr; /* physical address */ 11.379 - Elf64_Xword p_filesz; /* file size */ 11.380 - Elf64_Xword p_memsz; /* memory size */ 11.381 - Elf64_Xword p_align; /* memory & file alignment */ 11.382 -} Elf64_Phdr; 11.383 - 11.384 -/* Segment types - p_type */ 11.385 -#define PT_NULL 0 /* unused */ 11.386 -#define PT_LOAD 1 /* loadable segment */ 11.387 -#define PT_DYNAMIC 2 /* dynamic linking section */ 11.388 -#define PT_INTERP 3 /* the RTLD */ 11.389 -#define PT_NOTE 4 /* auxiliary information */ 11.390 -#define PT_SHLIB 5 /* reserved - purpose undefined */ 11.391 -#define PT_PHDR 6 /* program header */ 11.392 -#define PT_NUM 7 /* Number of segment types */ 11.393 -#define PT_LOPROC 0x70000000 /* reserved range for processor */ 11.394 -#define PT_HIPROC 0x7fffffff /* specific segment types */ 11.395 - 11.396 -/* Segment flags - p_flags */ 11.397 -#define PF_X 0x1 /* Executable */ 11.398 -#define PF_W 0x2 /* Writable */ 11.399 -#define PF_R 0x4 /* Readable */ 11.400 -#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ 11.401 - /* specific segment flags */ 11.402 - 11.403 -/* Dynamic structure */ 11.404 -typedef struct { 11.405 - Elf32_Sword d_tag; /* controls meaning of d_val */ 11.406 - union { 11.407 - Elf32_Word d_val; /* Multiple meanings - see d_tag */ 11.408 - Elf32_Addr d_ptr; /* program virtual address */ 11.409 - } d_un; 11.410 -} Elf32_Dyn; 11.411 - 11.412 -typedef struct { 11.413 - Elf64_Xword d_tag; /* controls meaning of d_val */ 11.414 - union { 11.415 - Elf64_Addr d_ptr; 11.416 - Elf64_Xword d_val; 11.417 - } d_un; 11.418 -} Elf64_Dyn; 11.419 - 11.420 -/* Dynamic Array Tags - d_tag */ 11.421 -#define DT_NULL 0 /* marks end of _DYNAMIC array */ 11.422 -#define DT_NEEDED 1 /* string table offset of needed lib */ 11.423 -#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */ 11.424 -#define DT_PLTGOT 3 /* address PLT/GOT */ 11.425 -#define DT_HASH 4 /* address of symbol hash table */ 11.426 -#define DT_STRTAB 5 /* address of string table */ 11.427 -#define DT_SYMTAB 6 /* address of symbol table */ 11.428 -#define DT_RELA 7 /* address of relocation table */ 11.429 -#define DT_RELASZ 8 /* size of relocation table */ 11.430 -#define DT_RELAENT 9 /* size of relocation entry */ 11.431 -#define DT_STRSZ 10 /* size of string table */ 11.432 -#define DT_SYMENT 11 /* size of symbol table entry */ 11.433 -#define DT_INIT 12 /* address of initialization func. */ 11.434 -#define DT_FINI 13 /* address of termination function */ 11.435 -#define DT_SONAME 14 /* string table offset of shared obj */ 11.436 -#define DT_RPATH 15 /* string table offset of library 11.437 - search path */ 11.438 -#define DT_SYMBOLIC 16 /* start sym search in shared obj. */ 11.439 -#define DT_REL 17 /* address of rel. tbl. w addends */ 11.440 -#define DT_RELSZ 18 /* size of DT_REL relocation table */ 11.441 -#define DT_RELENT 19 /* size of DT_REL relocation entry */ 11.442 -#define DT_PLTREL 20 /* PLT referenced relocation entry */ 11.443 -#define DT_DEBUG 21 /* bugger */ 11.444 -#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */ 11.445 -#define DT_JMPREL 23 /* add. of PLT's relocation entries */ 11.446 -#define DT_BIND_NOW 24 /* Bind now regardless of env setting */ 11.447 -#define DT_NUM 25 /* Number used. */ 11.448 -#define DT_LOPROC 0x70000000 /* reserved range for processor */ 11.449 -#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */ 11.450 - 11.451 -/* Standard ELF hashing function */ 11.452 -unsigned int elf_hash(const unsigned char *name); 11.453 - 11.454 -/* 11.455 - * Note Definitions 11.456 - */ 11.457 -typedef struct { 11.458 - Elf32_Word namesz; 11.459 - Elf32_Word descsz; 11.460 - Elf32_Word type; 11.461 -} Elf32_Note; 11.462 - 11.463 -typedef struct { 11.464 - Elf64_Half namesz; 11.465 - Elf64_Half descsz; 11.466 - Elf64_Half type; 11.467 -} Elf64_Note; 11.468 - 11.469 - 11.470 -#if defined(ELFSIZE) 11.471 -#define CONCAT(x,y) __CONCAT(x,y) 11.472 -#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) 11.473 -#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y)))) 11.474 -#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) 11.475 -#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) 11.476 -#endif 11.477 - 11.478 -#if defined(ELFSIZE) && (ELFSIZE == 32) 11.479 -#define Elf_Ehdr Elf32_Ehdr 11.480 -#define Elf_Phdr Elf32_Phdr 11.481 -#define Elf_Shdr Elf32_Shdr 11.482 -#define Elf_Sym Elf32_Sym 11.483 -#define Elf_Rel Elf32_Rel 11.484 -#define Elf_RelA Elf32_Rela 11.485 -#define Elf_Dyn Elf32_Dyn 11.486 -#define Elf_Word Elf32_Word 11.487 -#define Elf_Sword Elf32_Sword 11.488 -#define Elf_Addr Elf32_Addr 11.489 -#define Elf_Off Elf32_Off 11.490 -#define Elf_Nhdr Elf32_Nhdr 11.491 -#define Elf_Note Elf32_Note 11.492 - 11.493 -#define ELF_R_SYM ELF32_R_SYM 11.494 -#define ELF_R_TYPE ELF32_R_TYPE 11.495 -#define ELF_R_INFO ELF32_R_INFO 11.496 -#define ELFCLASS ELFCLASS32 11.497 - 11.498 -#define ELF_ST_BIND ELF32_ST_BIND 11.499 -#define ELF_ST_TYPE ELF32_ST_TYPE 11.500 -#define ELF_ST_INFO ELF32_ST_INFO 11.501 - 11.502 -#define AuxInfo Aux32Info 11.503 -#elif defined(ELFSIZE) && (ELFSIZE == 64) 11.504 -#define Elf_Ehdr Elf64_Ehdr 11.505 -#define Elf_Phdr Elf64_Phdr 11.506 -#define Elf_Shdr Elf64_Shdr 11.507 -#define Elf_Sym Elf64_Sym 11.508 -#define Elf_Rel Elf64_Rel 11.509 -#define Elf_RelA Elf64_Rela 11.510 -#define Elf_Dyn Elf64_Dyn 11.511 -#define Elf_Word Elf64_Word 11.512 -#define Elf_Sword Elf64_Sword 11.513 -#define Elf_Addr Elf64_Addr 11.514 -#define Elf_Off Elf64_Off 11.515 -#define Elf_Nhdr Elf64_Nhdr 11.516 -#define Elf_Note Elf64_Note 11.517 - 11.518 -#define ELF_R_SYM ELF64_R_SYM 11.519 -#define ELF_R_TYPE ELF64_R_TYPE 11.520 -#define ELF_R_INFO ELF64_R_INFO 11.521 -#define ELFCLASS ELFCLASS64 11.522 - 11.523 -#define ELF_ST_BIND ELF64_ST_BIND 11.524 -#define ELF_ST_TYPE ELF64_ST_TYPE 11.525 -#define ELF_ST_INFO ELF64_ST_INFO 11.526 - 11.527 -#define AuxInfo Aux64Info 11.528 -#endif 11.529 - 11.530 -#endif /* __XEN_PUBLIC_ELFSTRUCTS_H__ */
12.1 --- a/xen/include/public/libelf.h Thu Jan 08 13:08:37 2009 +0000 12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 12.3 @@ -1,266 +0,0 @@ 12.4 -/****************************************************************************** 12.5 - * libelf.h 12.6 - * 12.7 - * Permission is hereby granted, free of charge, to any person obtaining a copy 12.8 - * of this software and associated documentation files (the "Software"), to 12.9 - * deal in the Software without restriction, including without limitation the 12.10 - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 12.11 - * sell copies of the Software, and to permit persons to whom the Software is 12.12 - * furnished to do so, subject to the following conditions: 12.13 - * 12.14 - * The above copyright notice and this permission notice shall be included in 12.15 - * all copies or substantial portions of the Software. 12.16 - * 12.17 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12.18 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12.19 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 12.20 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 12.21 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 12.22 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 12.23 - * DEALINGS IN THE SOFTWARE. 12.24 - */ 12.25 - 12.26 -#ifndef __XC_LIBELF__ 12.27 -#define __XC_LIBELF__ 1 12.28 - 12.29 -#if defined(__i386__) || defined(__x86_64__) || defined(__ia64__) 12.30 -#define XEN_ELF_LITTLE_ENDIAN 12.31 -#else 12.32 -#error define architectural endianness 12.33 -#endif 12.34 - 12.35 -#undef ELFSIZE 12.36 -#include "elfnote.h" 12.37 -#include "elfstructs.h" 12.38 -#include "features.h" 12.39 - 12.40 -/* ------------------------------------------------------------------------ */ 12.41 - 12.42 -typedef union { 12.43 - Elf32_Ehdr e32; 12.44 - Elf64_Ehdr e64; 12.45 -} elf_ehdr; 12.46 - 12.47 -typedef union { 12.48 - Elf32_Phdr e32; 12.49 - Elf64_Phdr e64; 12.50 -} elf_phdr; 12.51 - 12.52 -typedef union { 12.53 - Elf32_Shdr e32; 12.54 - Elf64_Shdr e64; 12.55 -} elf_shdr; 12.56 - 12.57 -typedef union { 12.58 - Elf32_Sym e32; 12.59 - Elf64_Sym e64; 12.60 -} elf_sym; 12.61 - 12.62 -typedef union { 12.63 - Elf32_Rel e32; 12.64 - Elf64_Rel e64; 12.65 -} elf_rel; 12.66 - 12.67 -typedef union { 12.68 - Elf32_Rela e32; 12.69 - Elf64_Rela e64; 12.70 -} elf_rela; 12.71 - 12.72 -typedef union { 12.73 - Elf32_Note e32; 12.74 - Elf64_Note e64; 12.75 -} elf_note; 12.76 - 12.77 -struct elf_binary { 12.78 - /* elf binary */ 12.79 - const char *image; 12.80 - size_t size; 12.81 - char class; 12.82 - char data; 12.83 - 12.84 - const elf_ehdr *ehdr; 12.85 - const char *sec_strtab; 12.86 - const elf_shdr *sym_tab; 12.87 - const char *sym_strtab; 12.88 - 12.89 - /* loaded to */ 12.90 - char *dest; 12.91 - uint64_t pstart; 12.92 - uint64_t pend; 12.93 - uint64_t reloc_offset; 12.94 - 12.95 - uint64_t bsd_symtab_pstart; 12.96 - uint64_t bsd_symtab_pend; 12.97 - 12.98 -#ifndef __XEN__ 12.99 - /* misc */ 12.100 - FILE *log; 12.101 -#endif 12.102 - int verbose; 12.103 -}; 12.104 - 12.105 -/* ------------------------------------------------------------------------ */ 12.106 -/* accessing elf header fields */ 12.107 - 12.108 -#ifdef XEN_ELF_BIG_ENDIAN 12.109 -# define NATIVE_ELFDATA ELFDATA2MSB 12.110 -#else 12.111 -# define NATIVE_ELFDATA ELFDATA2LSB 12.112 -#endif 12.113 - 12.114 -#define elf_32bit(elf) (ELFCLASS32 == (elf)->class) 12.115 -#define elf_64bit(elf) (ELFCLASS64 == (elf)->class) 12.116 -#define elf_msb(elf) (ELFDATA2MSB == (elf)->data) 12.117 -#define elf_lsb(elf) (ELFDATA2LSB == (elf)->data) 12.118 -#define elf_swap(elf) (NATIVE_ELFDATA != (elf)->data) 12.119 - 12.120 -#define elf_uval(elf, str, elem) \ 12.121 - ((ELFCLASS64 == (elf)->class) \ 12.122 - ? elf_access_unsigned((elf), (str), \ 12.123 - offsetof(typeof(*(str)),e64.elem), \ 12.124 - sizeof((str)->e64.elem)) \ 12.125 - : elf_access_unsigned((elf), (str), \ 12.126 - offsetof(typeof(*(str)),e32.elem), \ 12.127 - sizeof((str)->e32.elem))) 12.128 - 12.129 -#define elf_sval(elf, str, elem) \ 12.130 - ((ELFCLASS64 == (elf)->class) \ 12.131 - ? elf_access_signed((elf), (str), \ 12.132 - offsetof(typeof(*(str)),e64.elem), \ 12.133 - sizeof((str)->e64.elem)) \ 12.134 - : elf_access_signed((elf), (str), \ 12.135 - offsetof(typeof(*(str)),e32.elem), \ 12.136 - sizeof((str)->e32.elem))) 12.137 - 12.138 -#define elf_size(elf, str) \ 12.139 - ((ELFCLASS64 == (elf)->class) \ 12.140 - ? sizeof((str)->e64) : sizeof((str)->e32)) 12.141 - 12.142 -uint64_t elf_access_unsigned(struct elf_binary *elf, const void *ptr, 12.143 - uint64_t offset, size_t size); 12.144 -int64_t elf_access_signed(struct elf_binary *elf, const void *ptr, 12.145 - uint64_t offset, size_t size); 12.146 - 12.147 -uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr); 12.148 - 12.149 -/* ------------------------------------------------------------------------ */ 12.150 -/* xc_libelf_tools.c */ 12.151 - 12.152 -int elf_shdr_count(struct elf_binary *elf); 12.153 -int elf_phdr_count(struct elf_binary *elf); 12.154 - 12.155 -const elf_shdr *elf_shdr_by_name(struct elf_binary *elf, const char *name); 12.156 -const elf_shdr *elf_shdr_by_index(struct elf_binary *elf, int index); 12.157 -const elf_phdr *elf_phdr_by_index(struct elf_binary *elf, int index); 12.158 - 12.159 -const char *elf_section_name(struct elf_binary *elf, const elf_shdr * shdr); 12.160 -const void *elf_section_start(struct elf_binary *elf, const elf_shdr * shdr); 12.161 -const void *elf_section_end(struct elf_binary *elf, const elf_shdr * shdr); 12.162 - 12.163 -const void *elf_segment_start(struct elf_binary *elf, const elf_phdr * phdr); 12.164 -const void *elf_segment_end(struct elf_binary *elf, const elf_phdr * phdr); 12.165 - 12.166 -const elf_sym *elf_sym_by_name(struct elf_binary *elf, const char *symbol); 12.167 -const elf_sym *elf_sym_by_index(struct elf_binary *elf, int index); 12.168 - 12.169 -const char *elf_note_name(struct elf_binary *elf, const elf_note * note); 12.170 -const void *elf_note_desc(struct elf_binary *elf, const elf_note * note); 12.171 -uint64_t elf_note_numeric(struct elf_binary *elf, const elf_note * note); 12.172 -const elf_note *elf_note_next(struct elf_binary *elf, const elf_note * note); 12.173 - 12.174 -int elf_is_elfbinary(const void *image); 12.175 -int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr); 12.176 - 12.177 -/* ------------------------------------------------------------------------ */ 12.178 -/* xc_libelf_loader.c */ 12.179 - 12.180 -int elf_init(struct elf_binary *elf, const char *image, size_t size); 12.181 -#ifdef __XEN__ 12.182 -void elf_set_verbose(struct elf_binary *elf); 12.183 -#else 12.184 -void elf_set_logfile(struct elf_binary *elf, FILE * log, int verbose); 12.185 -#endif 12.186 - 12.187 -void elf_parse_binary(struct elf_binary *elf); 12.188 -void elf_load_binary(struct elf_binary *elf); 12.189 - 12.190 -void *elf_get_ptr(struct elf_binary *elf, unsigned long addr); 12.191 -uint64_t elf_lookup_addr(struct elf_binary *elf, const char *symbol); 12.192 - 12.193 -void elf_parse_bsdsyms(struct elf_binary *elf, uint64_t pstart); /* private */ 12.194 - 12.195 -/* ------------------------------------------------------------------------ */ 12.196 -/* xc_libelf_relocate.c */ 12.197 - 12.198 -int elf_reloc(struct elf_binary *elf); 12.199 - 12.200 -/* ------------------------------------------------------------------------ */ 12.201 -/* xc_libelf_dominfo.c */ 12.202 - 12.203 -#define UNSET_ADDR ((uint64_t)-1) 12.204 - 12.205 -enum xen_elfnote_type { 12.206 - XEN_ENT_NONE = 0, 12.207 - XEN_ENT_LONG = 1, 12.208 - XEN_ENT_STR = 2 12.209 -}; 12.210 - 12.211 -struct xen_elfnote { 12.212 - enum xen_elfnote_type type; 12.213 - const char *name; 12.214 - union { 12.215 - const char *str; 12.216 - uint64_t num; 12.217 - } data; 12.218 -}; 12.219 - 12.220 -struct elf_dom_parms { 12.221 - /* raw */ 12.222 - const char *guest_info; 12.223 - const void *elf_note_start; 12.224 - const void *elf_note_end; 12.225 - struct xen_elfnote elf_notes[XEN_ELFNOTE_MAX + 1]; 12.226 - 12.227 - /* parsed */ 12.228 - char guest_os[16]; 12.229 - char guest_ver[16]; 12.230 - char xen_ver[16]; 12.231 - char loader[16]; 12.232 - int pae; 12.233 - int bsd_symtab; 12.234 - uint64_t virt_base; 12.235 - uint64_t virt_entry; 12.236 - uint64_t virt_hypercall; 12.237 - uint64_t virt_hv_start_low; 12.238 - uint64_t p2m_base; 12.239 - uint64_t elf_paddr_offset; 12.240 - uint32_t f_supported[XENFEAT_NR_SUBMAPS]; 12.241 - uint32_t f_required[XENFEAT_NR_SUBMAPS]; 12.242 - 12.243 - /* calculated */ 12.244 - uint64_t virt_offset; 12.245 - uint64_t virt_kstart; 12.246 - uint64_t virt_kend; 12.247 -}; 12.248 - 12.249 -static inline void elf_xen_feature_set(int nr, uint32_t * addr) 12.250 -{ 12.251 - addr[nr >> 5] |= 1 << (nr & 31); 12.252 -} 12.253 -static inline int elf_xen_feature_get(int nr, uint32_t * addr) 12.254 -{ 12.255 - return !!(addr[nr >> 5] & (1 << (nr & 31))); 12.256 -} 12.257 - 12.258 -int elf_xen_parse_features(const char *features, 12.259 - uint32_t *supported, 12.260 - uint32_t *required); 12.261 -int elf_xen_parse_note(struct elf_binary *elf, 12.262 - struct elf_dom_parms *parms, 12.263 - const elf_note *note); 12.264 -int elf_xen_parse_guest_info(struct elf_binary *elf, 12.265 - struct elf_dom_parms *parms); 12.266 -int elf_xen_parse(struct elf_binary *elf, 12.267 - struct elf_dom_parms *parms); 12.268 - 12.269 -#endif /* __XC_LIBELF__ */
13.1 --- a/xen/include/xen/elf.h Thu Jan 08 13:08:37 2009 +0000 13.2 +++ b/xen/include/xen/elf.h Thu Jan 08 13:15:49 2009 +0000 13.3 @@ -27,7 +27,7 @@ 13.4 #ifndef __XEN_ELF_H__ 13.5 #define __XEN_ELF_H__ 13.6 13.7 -#include <public/elfstructs.h> 13.8 +#include <xen/elfstructs.h> 13.9 13.10 #define ELFNOTE_ALIGN(_n_) (((_n_)+3)&~3) 13.11 #define ELFNOTE_NAME(_n_) ((char*)(_n_) + sizeof(*(_n_)))
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/xen/include/xen/elfstructs.h Thu Jan 08 13:15:49 2009 +0000 14.3 @@ -0,0 +1,527 @@ 14.4 +#ifndef __XEN_ELFSTRUCTS_H__ 14.5 +#define __XEN_ELFSTRUCTS_H__ 14.6 +/* 14.7 + * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved. 14.8 + * 14.9 + * Redistribution and use in source and binary forms, with or without 14.10 + * modification, are permitted provided that the following conditions 14.11 + * are met: 14.12 + * 1. Redistributions of source code must retain the above copyright 14.13 + * notice, this list of conditions and the following disclaimer. 14.14 + * 2. Redistributions in binary form must reproduce the above copyright 14.15 + * notice, this list of conditions and the following disclaimer in the 14.16 + * documentation and/or other materials provided with the distribution. 14.17 + * 3. The name of the author may not be used to endorse or promote products 14.18 + * derived from this software without specific prior written permission 14.19 + * 14.20 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14.21 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 14.22 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 14.23 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 14.24 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 14.25 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 14.26 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14.27 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14.28 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 14.29 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14.30 + */ 14.31 + 14.32 +typedef uint8_t Elf_Byte; 14.33 + 14.34 +typedef uint32_t Elf32_Addr; /* Unsigned program address */ 14.35 +typedef uint32_t Elf32_Off; /* Unsigned file offset */ 14.36 +typedef int32_t Elf32_Sword; /* Signed large integer */ 14.37 +typedef uint32_t Elf32_Word; /* Unsigned large integer */ 14.38 +typedef uint16_t Elf32_Half; /* Unsigned medium integer */ 14.39 + 14.40 +typedef uint64_t Elf64_Addr; 14.41 +typedef uint64_t Elf64_Off; 14.42 +typedef int32_t Elf64_Shalf; 14.43 + 14.44 +typedef int32_t Elf64_Sword; 14.45 +typedef uint32_t Elf64_Word; 14.46 + 14.47 +typedef int64_t Elf64_Sxword; 14.48 +typedef uint64_t Elf64_Xword; 14.49 + 14.50 +typedef uint32_t Elf64_Half; 14.51 +typedef uint16_t Elf64_Quarter; 14.52 + 14.53 +/* 14.54 + * e_ident[] identification indexes 14.55 + * See http://www.caldera.com/developers/gabi/2000-07-17/ch4.eheader.html 14.56 + */ 14.57 +#define EI_MAG0 0 /* file ID */ 14.58 +#define EI_MAG1 1 /* file ID */ 14.59 +#define EI_MAG2 2 /* file ID */ 14.60 +#define EI_MAG3 3 /* file ID */ 14.61 +#define EI_CLASS 4 /* file class */ 14.62 +#define EI_DATA 5 /* data encoding */ 14.63 +#define EI_VERSION 6 /* ELF header version */ 14.64 +#define EI_OSABI 7 /* OS/ABI ID */ 14.65 +#define EI_ABIVERSION 8 /* ABI version */ 14.66 +#define EI_PAD 9 /* start of pad bytes */ 14.67 +#define EI_NIDENT 16 /* Size of e_ident[] */ 14.68 + 14.69 +/* e_ident[] magic number */ 14.70 +#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ 14.71 +#define ELFMAG1 'E' /* e_ident[EI_MAG1] */ 14.72 +#define ELFMAG2 'L' /* e_ident[EI_MAG2] */ 14.73 +#define ELFMAG3 'F' /* e_ident[EI_MAG3] */ 14.74 +#define ELFMAG "\177ELF" /* magic */ 14.75 +#define SELFMAG 4 /* size of magic */ 14.76 + 14.77 +/* e_ident[] file class */ 14.78 +#define ELFCLASSNONE 0 /* invalid */ 14.79 +#define ELFCLASS32 1 /* 32-bit objs */ 14.80 +#define ELFCLASS64 2 /* 64-bit objs */ 14.81 +#define ELFCLASSNUM 3 /* number of classes */ 14.82 + 14.83 +/* e_ident[] data encoding */ 14.84 +#define ELFDATANONE 0 /* invalid */ 14.85 +#define ELFDATA2LSB 1 /* Little-Endian */ 14.86 +#define ELFDATA2MSB 2 /* Big-Endian */ 14.87 +#define ELFDATANUM 3 /* number of data encode defines */ 14.88 + 14.89 +/* e_ident[] Operating System/ABI */ 14.90 +#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ 14.91 +#define ELFOSABI_HPUX 1 /* HP-UX operating system */ 14.92 +#define ELFOSABI_NETBSD 2 /* NetBSD */ 14.93 +#define ELFOSABI_LINUX 3 /* GNU/Linux */ 14.94 +#define ELFOSABI_HURD 4 /* GNU/Hurd */ 14.95 +#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ 14.96 +#define ELFOSABI_SOLARIS 6 /* Solaris */ 14.97 +#define ELFOSABI_MONTEREY 7 /* Monterey */ 14.98 +#define ELFOSABI_IRIX 8 /* IRIX */ 14.99 +#define ELFOSABI_FREEBSD 9 /* FreeBSD */ 14.100 +#define ELFOSABI_TRU64 10 /* TRU64 UNIX */ 14.101 +#define ELFOSABI_MODESTO 11 /* Novell Modesto */ 14.102 +#define ELFOSABI_OPENBSD 12 /* OpenBSD */ 14.103 +#define ELFOSABI_ARM 97 /* ARM */ 14.104 +#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ 14.105 + 14.106 +/* e_ident */ 14.107 +#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ 14.108 + (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ 14.109 + (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ 14.110 + (ehdr).e_ident[EI_MAG3] == ELFMAG3) 14.111 + 14.112 +/* ELF Header */ 14.113 +typedef struct elfhdr { 14.114 + unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ 14.115 + Elf32_Half e_type; /* object file type */ 14.116 + Elf32_Half e_machine; /* machine */ 14.117 + Elf32_Word e_version; /* object file version */ 14.118 + Elf32_Addr e_entry; /* virtual entry point */ 14.119 + Elf32_Off e_phoff; /* program header table offset */ 14.120 + Elf32_Off e_shoff; /* section header table offset */ 14.121 + Elf32_Word e_flags; /* processor-specific flags */ 14.122 + Elf32_Half e_ehsize; /* ELF header size */ 14.123 + Elf32_Half e_phentsize; /* program header entry size */ 14.124 + Elf32_Half e_phnum; /* number of program header entries */ 14.125 + Elf32_Half e_shentsize; /* section header entry size */ 14.126 + Elf32_Half e_shnum; /* number of section header entries */ 14.127 + Elf32_Half e_shstrndx; /* section header table's "section 14.128 + header string table" entry offset */ 14.129 +} Elf32_Ehdr; 14.130 + 14.131 +typedef struct { 14.132 + unsigned char e_ident[EI_NIDENT]; /* Id bytes */ 14.133 + Elf64_Quarter e_type; /* file type */ 14.134 + Elf64_Quarter e_machine; /* machine type */ 14.135 + Elf64_Half e_version; /* version number */ 14.136 + Elf64_Addr e_entry; /* entry point */ 14.137 + Elf64_Off e_phoff; /* Program hdr offset */ 14.138 + Elf64_Off e_shoff; /* Section hdr offset */ 14.139 + Elf64_Half e_flags; /* Processor flags */ 14.140 + Elf64_Quarter e_ehsize; /* sizeof ehdr */ 14.141 + Elf64_Quarter e_phentsize; /* Program header entry size */ 14.142 + Elf64_Quarter e_phnum; /* Number of program headers */ 14.143 + Elf64_Quarter e_shentsize; /* Section header entry size */ 14.144 + Elf64_Quarter e_shnum; /* Number of section headers */ 14.145 + Elf64_Quarter e_shstrndx; /* String table index */ 14.146 +} Elf64_Ehdr; 14.147 + 14.148 +/* e_type */ 14.149 +#define ET_NONE 0 /* No file type */ 14.150 +#define ET_REL 1 /* relocatable file */ 14.151 +#define ET_EXEC 2 /* executable file */ 14.152 +#define ET_DYN 3 /* shared object file */ 14.153 +#define ET_CORE 4 /* core file */ 14.154 +#define ET_NUM 5 /* number of types */ 14.155 +#define ET_LOPROC 0xff00 /* reserved range for processor */ 14.156 +#define ET_HIPROC 0xffff /* specific e_type */ 14.157 + 14.158 +/* e_machine */ 14.159 +#define EM_NONE 0 /* No Machine */ 14.160 +#define EM_M32 1 /* AT&T WE 32100 */ 14.161 +#define EM_SPARC 2 /* SPARC */ 14.162 +#define EM_386 3 /* Intel 80386 */ 14.163 +#define EM_68K 4 /* Motorola 68000 */ 14.164 +#define EM_88K 5 /* Motorola 88000 */ 14.165 +#define EM_486 6 /* Intel 80486 - unused? */ 14.166 +#define EM_860 7 /* Intel 80860 */ 14.167 +#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ 14.168 +/* 14.169 + * Don't know if EM_MIPS_RS4_BE, 14.170 + * EM_SPARC64, EM_PARISC, 14.171 + * or EM_PPC are ABI compliant 14.172 + */ 14.173 +#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ 14.174 +#define EM_SPARC64 11 /* SPARC v9 64-bit unoffical */ 14.175 +#define EM_PARISC 15 /* HPPA */ 14.176 +#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ 14.177 +#define EM_PPC 20 /* PowerPC */ 14.178 +#define EM_PPC64 21 /* PowerPC 64-bit */ 14.179 +#define EM_ARM 40 /* Advanced RISC Machines ARM */ 14.180 +#define EM_ALPHA 41 /* DEC ALPHA */ 14.181 +#define EM_SPARCV9 43 /* SPARC version 9 */ 14.182 +#define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */ 14.183 +#define EM_IA_64 50 /* Intel Merced */ 14.184 +#define EM_X86_64 62 /* AMD x86-64 architecture */ 14.185 +#define EM_VAX 75 /* DEC VAX */ 14.186 + 14.187 +/* Version */ 14.188 +#define EV_NONE 0 /* Invalid */ 14.189 +#define EV_CURRENT 1 /* Current */ 14.190 +#define EV_NUM 2 /* number of versions */ 14.191 + 14.192 +/* Section Header */ 14.193 +typedef struct { 14.194 + Elf32_Word sh_name; /* name - index into section header 14.195 + string table section */ 14.196 + Elf32_Word sh_type; /* type */ 14.197 + Elf32_Word sh_flags; /* flags */ 14.198 + Elf32_Addr sh_addr; /* address */ 14.199 + Elf32_Off sh_offset; /* file offset */ 14.200 + Elf32_Word sh_size; /* section size */ 14.201 + Elf32_Word sh_link; /* section header table index link */ 14.202 + Elf32_Word sh_info; /* extra information */ 14.203 + Elf32_Word sh_addralign; /* address alignment */ 14.204 + Elf32_Word sh_entsize; /* section entry size */ 14.205 +} Elf32_Shdr; 14.206 + 14.207 +typedef struct { 14.208 + Elf64_Half sh_name; /* section name */ 14.209 + Elf64_Half sh_type; /* section type */ 14.210 + Elf64_Xword sh_flags; /* section flags */ 14.211 + Elf64_Addr sh_addr; /* virtual address */ 14.212 + Elf64_Off sh_offset; /* file offset */ 14.213 + Elf64_Xword sh_size; /* section size */ 14.214 + Elf64_Half sh_link; /* link to another */ 14.215 + Elf64_Half sh_info; /* misc info */ 14.216 + Elf64_Xword sh_addralign; /* memory alignment */ 14.217 + Elf64_Xword sh_entsize; /* table entry size */ 14.218 +} Elf64_Shdr; 14.219 + 14.220 +/* Special Section Indexes */ 14.221 +#define SHN_UNDEF 0 /* undefined */ 14.222 +#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */ 14.223 +#define SHN_LOPROC 0xff00 /* reserved range for processor */ 14.224 +#define SHN_HIPROC 0xff1f /* specific section indexes */ 14.225 +#define SHN_ABS 0xfff1 /* absolute value */ 14.226 +#define SHN_COMMON 0xfff2 /* common symbol */ 14.227 +#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */ 14.228 + 14.229 +/* sh_type */ 14.230 +#define SHT_NULL 0 /* inactive */ 14.231 +#define SHT_PROGBITS 1 /* program defined information */ 14.232 +#define SHT_SYMTAB 2 /* symbol table section */ 14.233 +#define SHT_STRTAB 3 /* string table section */ 14.234 +#define SHT_RELA 4 /* relocation section with addends*/ 14.235 +#define SHT_HASH 5 /* symbol hash table section */ 14.236 +#define SHT_DYNAMIC 6 /* dynamic section */ 14.237 +#define SHT_NOTE 7 /* note section */ 14.238 +#define SHT_NOBITS 8 /* no space section */ 14.239 +#define SHT_REL 9 /* relation section without addends */ 14.240 +#define SHT_SHLIB 10 /* reserved - purpose unknown */ 14.241 +#define SHT_DYNSYM 11 /* dynamic symbol table section */ 14.242 +#define SHT_NUM 12 /* number of section types */ 14.243 +#define SHT_LOPROC 0x70000000 /* reserved range for processor */ 14.244 +#define SHT_HIPROC 0x7fffffff /* specific section header types */ 14.245 +#define SHT_LOUSER 0x80000000 /* reserved range for application */ 14.246 +#define SHT_HIUSER 0xffffffff /* specific indexes */ 14.247 + 14.248 +/* Section names */ 14.249 +#define ELF_BSS ".bss" /* uninitialized data */ 14.250 +#define ELF_DATA ".data" /* initialized data */ 14.251 +#define ELF_DEBUG ".debug" /* debug */ 14.252 +#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ 14.253 +#define ELF_DYNSTR ".dynstr" /* dynamic string table */ 14.254 +#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ 14.255 +#define ELF_FINI ".fini" /* termination code */ 14.256 +#define ELF_GOT ".got" /* global offset table */ 14.257 +#define ELF_HASH ".hash" /* symbol hash table */ 14.258 +#define ELF_INIT ".init" /* initialization code */ 14.259 +#define ELF_REL_DATA ".rel.data" /* relocation data */ 14.260 +#define ELF_REL_FINI ".rel.fini" /* relocation termination code */ 14.261 +#define ELF_REL_INIT ".rel.init" /* relocation initialization code */ 14.262 +#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */ 14.263 +#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ 14.264 +#define ELF_REL_TEXT ".rel.text" /* relocation code */ 14.265 +#define ELF_RODATA ".rodata" /* read-only data */ 14.266 +#define ELF_SHSTRTAB ".shstrtab" /* section header string table */ 14.267 +#define ELF_STRTAB ".strtab" /* string table */ 14.268 +#define ELF_SYMTAB ".symtab" /* symbol table */ 14.269 +#define ELF_TEXT ".text" /* code */ 14.270 + 14.271 + 14.272 +/* Section Attribute Flags - sh_flags */ 14.273 +#define SHF_WRITE 0x1 /* Writable */ 14.274 +#define SHF_ALLOC 0x2 /* occupies memory */ 14.275 +#define SHF_EXECINSTR 0x4 /* executable */ 14.276 +#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ 14.277 + /* specific section attributes */ 14.278 + 14.279 +/* Symbol Table Entry */ 14.280 +typedef struct elf32_sym { 14.281 + Elf32_Word st_name; /* name - index into string table */ 14.282 + Elf32_Addr st_value; /* symbol value */ 14.283 + Elf32_Word st_size; /* symbol size */ 14.284 + unsigned char st_info; /* type and binding */ 14.285 + unsigned char st_other; /* 0 - no defined meaning */ 14.286 + Elf32_Half st_shndx; /* section header index */ 14.287 +} Elf32_Sym; 14.288 + 14.289 +typedef struct { 14.290 + Elf64_Half st_name; /* Symbol name index in str table */ 14.291 + Elf_Byte st_info; /* type / binding attrs */ 14.292 + Elf_Byte st_other; /* unused */ 14.293 + Elf64_Quarter st_shndx; /* section index of symbol */ 14.294 + Elf64_Xword st_value; /* value of symbol */ 14.295 + Elf64_Xword st_size; /* size of symbol */ 14.296 +} Elf64_Sym; 14.297 + 14.298 +/* Symbol table index */ 14.299 +#define STN_UNDEF 0 /* undefined */ 14.300 + 14.301 +/* Extract symbol info - st_info */ 14.302 +#define ELF32_ST_BIND(x) ((x) >> 4) 14.303 +#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) 14.304 +#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) 14.305 + 14.306 +#define ELF64_ST_BIND(x) ((x) >> 4) 14.307 +#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf) 14.308 +#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) 14.309 + 14.310 +/* Symbol Binding - ELF32_ST_BIND - st_info */ 14.311 +#define STB_LOCAL 0 /* Local symbol */ 14.312 +#define STB_GLOBAL 1 /* Global symbol */ 14.313 +#define STB_WEAK 2 /* like global - lower precedence */ 14.314 +#define STB_NUM 3 /* number of symbol bindings */ 14.315 +#define STB_LOPROC 13 /* reserved range for processor */ 14.316 +#define STB_HIPROC 15 /* specific symbol bindings */ 14.317 + 14.318 +/* Symbol type - ELF32_ST_TYPE - st_info */ 14.319 +#define STT_NOTYPE 0 /* not specified */ 14.320 +#define STT_OBJECT 1 /* data object */ 14.321 +#define STT_FUNC 2 /* function */ 14.322 +#define STT_SECTION 3 /* section */ 14.323 +#define STT_FILE 4 /* file */ 14.324 +#define STT_NUM 5 /* number of symbol types */ 14.325 +#define STT_LOPROC 13 /* reserved range for processor */ 14.326 +#define STT_HIPROC 15 /* specific symbol types */ 14.327 + 14.328 +/* Relocation entry with implicit addend */ 14.329 +typedef struct { 14.330 + Elf32_Addr r_offset; /* offset of relocation */ 14.331 + Elf32_Word r_info; /* symbol table index and type */ 14.332 +} Elf32_Rel; 14.333 + 14.334 +/* Relocation entry with explicit addend */ 14.335 +typedef struct { 14.336 + Elf32_Addr r_offset; /* offset of relocation */ 14.337 + Elf32_Word r_info; /* symbol table index and type */ 14.338 + Elf32_Sword r_addend; 14.339 +} Elf32_Rela; 14.340 + 14.341 +/* Extract relocation info - r_info */ 14.342 +#define ELF32_R_SYM(i) ((i) >> 8) 14.343 +#define ELF32_R_TYPE(i) ((unsigned char) (i)) 14.344 +#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) 14.345 + 14.346 +typedef struct { 14.347 + Elf64_Xword r_offset; /* where to do it */ 14.348 + Elf64_Xword r_info; /* index & type of relocation */ 14.349 +} Elf64_Rel; 14.350 + 14.351 +typedef struct { 14.352 + Elf64_Xword r_offset; /* where to do it */ 14.353 + Elf64_Xword r_info; /* index & type of relocation */ 14.354 + Elf64_Sxword r_addend; /* adjustment value */ 14.355 +} Elf64_Rela; 14.356 + 14.357 +#define ELF64_R_SYM(info) ((info) >> 32) 14.358 +#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF) 14.359 +#define ELF64_R_INFO(s,t) (((s) << 32) + (u_int32_t)(t)) 14.360 + 14.361 +/* Program Header */ 14.362 +typedef struct { 14.363 + Elf32_Word p_type; /* segment type */ 14.364 + Elf32_Off p_offset; /* segment offset */ 14.365 + Elf32_Addr p_vaddr; /* virtual address of segment */ 14.366 + Elf32_Addr p_paddr; /* physical address - ignored? */ 14.367 + Elf32_Word p_filesz; /* number of bytes in file for seg. */ 14.368 + Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ 14.369 + Elf32_Word p_flags; /* flags */ 14.370 + Elf32_Word p_align; /* memory alignment */ 14.371 +} Elf32_Phdr; 14.372 + 14.373 +typedef struct { 14.374 + Elf64_Half p_type; /* entry type */ 14.375 + Elf64_Half p_flags; /* flags */ 14.376 + Elf64_Off p_offset; /* offset */ 14.377 + Elf64_Addr p_vaddr; /* virtual address */ 14.378 + Elf64_Addr p_paddr; /* physical address */ 14.379 + Elf64_Xword p_filesz; /* file size */ 14.380 + Elf64_Xword p_memsz; /* memory size */ 14.381 + Elf64_Xword p_align; /* memory & file alignment */ 14.382 +} Elf64_Phdr; 14.383 + 14.384 +/* Segment types - p_type */ 14.385 +#define PT_NULL 0 /* unused */ 14.386 +#define PT_LOAD 1 /* loadable segment */ 14.387 +#define PT_DYNAMIC 2 /* dynamic linking section */ 14.388 +#define PT_INTERP 3 /* the RTLD */ 14.389 +#define PT_NOTE 4 /* auxiliary information */ 14.390 +#define PT_SHLIB 5 /* reserved - purpose undefined */ 14.391 +#define PT_PHDR 6 /* program header */ 14.392 +#define PT_NUM 7 /* Number of segment types */ 14.393 +#define PT_LOPROC 0x70000000 /* reserved range for processor */ 14.394 +#define PT_HIPROC 0x7fffffff /* specific segment types */ 14.395 + 14.396 +/* Segment flags - p_flags */ 14.397 +#define PF_X 0x1 /* Executable */ 14.398 +#define PF_W 0x2 /* Writable */ 14.399 +#define PF_R 0x4 /* Readable */ 14.400 +#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ 14.401 + /* specific segment flags */ 14.402 + 14.403 +/* Dynamic structure */ 14.404 +typedef struct { 14.405 + Elf32_Sword d_tag; /* controls meaning of d_val */ 14.406 + union { 14.407 + Elf32_Word d_val; /* Multiple meanings - see d_tag */ 14.408 + Elf32_Addr d_ptr; /* program virtual address */ 14.409 + } d_un; 14.410 +} Elf32_Dyn; 14.411 + 14.412 +typedef struct { 14.413 + Elf64_Xword d_tag; /* controls meaning of d_val */ 14.414 + union { 14.415 + Elf64_Addr d_ptr; 14.416 + Elf64_Xword d_val; 14.417 + } d_un; 14.418 +} Elf64_Dyn; 14.419 + 14.420 +/* Dynamic Array Tags - d_tag */ 14.421 +#define DT_NULL 0 /* marks end of _DYNAMIC array */ 14.422 +#define DT_NEEDED 1 /* string table offset of needed lib */ 14.423 +#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */ 14.424 +#define DT_PLTGOT 3 /* address PLT/GOT */ 14.425 +#define DT_HASH 4 /* address of symbol hash table */ 14.426 +#define DT_STRTAB 5 /* address of string table */ 14.427 +#define DT_SYMTAB 6 /* address of symbol table */ 14.428 +#define DT_RELA 7 /* address of relocation table */ 14.429 +#define DT_RELASZ 8 /* size of relocation table */ 14.430 +#define DT_RELAENT 9 /* size of relocation entry */ 14.431 +#define DT_STRSZ 10 /* size of string table */ 14.432 +#define DT_SYMENT 11 /* size of symbol table entry */ 14.433 +#define DT_INIT 12 /* address of initialization func. */ 14.434 +#define DT_FINI 13 /* address of termination function */ 14.435 +#define DT_SONAME 14 /* string table offset of shared obj */ 14.436 +#define DT_RPATH 15 /* string table offset of library 14.437 + search path */ 14.438 +#define DT_SYMBOLIC 16 /* start sym search in shared obj. */ 14.439 +#define DT_REL 17 /* address of rel. tbl. w addends */ 14.440 +#define DT_RELSZ 18 /* size of DT_REL relocation table */ 14.441 +#define DT_RELENT 19 /* size of DT_REL relocation entry */ 14.442 +#define DT_PLTREL 20 /* PLT referenced relocation entry */ 14.443 +#define DT_DEBUG 21 /* bugger */ 14.444 +#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */ 14.445 +#define DT_JMPREL 23 /* add. of PLT's relocation entries */ 14.446 +#define DT_BIND_NOW 24 /* Bind now regardless of env setting */ 14.447 +#define DT_NUM 25 /* Number used. */ 14.448 +#define DT_LOPROC 0x70000000 /* reserved range for processor */ 14.449 +#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */ 14.450 + 14.451 +/* Standard ELF hashing function */ 14.452 +unsigned int elf_hash(const unsigned char *name); 14.453 + 14.454 +/* 14.455 + * Note Definitions 14.456 + */ 14.457 +typedef struct { 14.458 + Elf32_Word namesz; 14.459 + Elf32_Word descsz; 14.460 + Elf32_Word type; 14.461 +} Elf32_Note; 14.462 + 14.463 +typedef struct { 14.464 + Elf64_Half namesz; 14.465 + Elf64_Half descsz; 14.466 + Elf64_Half type; 14.467 +} Elf64_Note; 14.468 + 14.469 + 14.470 +#if defined(ELFSIZE) 14.471 +#define CONCAT(x,y) __CONCAT(x,y) 14.472 +#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) 14.473 +#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y)))) 14.474 +#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) 14.475 +#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) 14.476 +#endif 14.477 + 14.478 +#if defined(ELFSIZE) && (ELFSIZE == 32) 14.479 +#define Elf_Ehdr Elf32_Ehdr 14.480 +#define Elf_Phdr Elf32_Phdr 14.481 +#define Elf_Shdr Elf32_Shdr 14.482 +#define Elf_Sym Elf32_Sym 14.483 +#define Elf_Rel Elf32_Rel 14.484 +#define Elf_RelA Elf32_Rela 14.485 +#define Elf_Dyn Elf32_Dyn 14.486 +#define Elf_Word Elf32_Word 14.487 +#define Elf_Sword Elf32_Sword 14.488 +#define Elf_Addr Elf32_Addr 14.489 +#define Elf_Off Elf32_Off 14.490 +#define Elf_Nhdr Elf32_Nhdr 14.491 +#define Elf_Note Elf32_Note 14.492 + 14.493 +#define ELF_R_SYM ELF32_R_SYM 14.494 +#define ELF_R_TYPE ELF32_R_TYPE 14.495 +#define ELF_R_INFO ELF32_R_INFO 14.496 +#define ELFCLASS ELFCLASS32 14.497 + 14.498 +#define ELF_ST_BIND ELF32_ST_BIND 14.499 +#define ELF_ST_TYPE ELF32_ST_TYPE 14.500 +#define ELF_ST_INFO ELF32_ST_INFO 14.501 + 14.502 +#define AuxInfo Aux32Info 14.503 +#elif defined(ELFSIZE) && (ELFSIZE == 64) 14.504 +#define Elf_Ehdr Elf64_Ehdr 14.505 +#define Elf_Phdr Elf64_Phdr 14.506 +#define Elf_Shdr Elf64_Shdr 14.507 +#define Elf_Sym Elf64_Sym 14.508 +#define Elf_Rel Elf64_Rel 14.509 +#define Elf_RelA Elf64_Rela 14.510 +#define Elf_Dyn Elf64_Dyn 14.511 +#define Elf_Word Elf64_Word 14.512 +#define Elf_Sword Elf64_Sword 14.513 +#define Elf_Addr Elf64_Addr 14.514 +#define Elf_Off Elf64_Off 14.515 +#define Elf_Nhdr Elf64_Nhdr 14.516 +#define Elf_Note Elf64_Note 14.517 + 14.518 +#define ELF_R_SYM ELF64_R_SYM 14.519 +#define ELF_R_TYPE ELF64_R_TYPE 14.520 +#define ELF_R_INFO ELF64_R_INFO 14.521 +#define ELFCLASS ELFCLASS64 14.522 + 14.523 +#define ELF_ST_BIND ELF64_ST_BIND 14.524 +#define ELF_ST_TYPE ELF64_ST_TYPE 14.525 +#define ELF_ST_INFO ELF64_ST_INFO 14.526 + 14.527 +#define AuxInfo Aux64Info 14.528 +#endif 14.529 + 14.530 +#endif /* __XEN_ELFSTRUCTS_H__ */
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/xen/include/xen/libelf.h Thu Jan 08 13:15:49 2009 +0000 15.3 @@ -0,0 +1,271 @@ 15.4 +/****************************************************************************** 15.5 + * libelf.h 15.6 + * 15.7 + * Permission is hereby granted, free of charge, to any person obtaining a copy 15.8 + * of this software and associated documentation files (the "Software"), to 15.9 + * deal in the Software without restriction, including without limitation the 15.10 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15.11 + * sell copies of the Software, and to permit persons to whom the Software is 15.12 + * furnished to do so, subject to the following conditions: 15.13 + * 15.14 + * The above copyright notice and this permission notice shall be included in 15.15 + * all copies or substantial portions of the Software. 15.16 + * 15.17 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15.18 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15.19 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15.20 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15.21 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 15.22 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 15.23 + * DEALINGS IN THE SOFTWARE. 15.24 + */ 15.25 + 15.26 +#ifndef __XEN_LIBELF_H__ 15.27 +#define __XEN_LIBELF_H__ 15.28 + 15.29 +#if defined(__i386__) || defined(__x86_64__) || defined(__ia64__) 15.30 +#define XEN_ELF_LITTLE_ENDIAN 15.31 +#else 15.32 +#error define architectural endianness 15.33 +#endif 15.34 + 15.35 +#undef ELFSIZE 15.36 +#include "elfstructs.h" 15.37 +#ifdef __XEN__ 15.38 +#include <public/elfnote.h> 15.39 +#include <public/features.h> 15.40 +#else 15.41 +#include <xen/elfnote.h> 15.42 +#include <xen/features.h> 15.43 +#endif 15.44 + 15.45 +/* ------------------------------------------------------------------------ */ 15.46 + 15.47 +typedef union { 15.48 + Elf32_Ehdr e32; 15.49 + Elf64_Ehdr e64; 15.50 +} elf_ehdr; 15.51 + 15.52 +typedef union { 15.53 + Elf32_Phdr e32; 15.54 + Elf64_Phdr e64; 15.55 +} elf_phdr; 15.56 + 15.57 +typedef union { 15.58 + Elf32_Shdr e32; 15.59 + Elf64_Shdr e64; 15.60 +} elf_shdr; 15.61 + 15.62 +typedef union { 15.63 + Elf32_Sym e32; 15.64 + Elf64_Sym e64; 15.65 +} elf_sym; 15.66 + 15.67 +typedef union { 15.68 + Elf32_Rel e32; 15.69 + Elf64_Rel e64; 15.70 +} elf_rel; 15.71 + 15.72 +typedef union { 15.73 + Elf32_Rela e32; 15.74 + Elf64_Rela e64; 15.75 +} elf_rela; 15.76 + 15.77 +typedef union { 15.78 + Elf32_Note e32; 15.79 + Elf64_Note e64; 15.80 +} elf_note; 15.81 + 15.82 +struct elf_binary { 15.83 + /* elf binary */ 15.84 + const char *image; 15.85 + size_t size; 15.86 + char class; 15.87 + char data; 15.88 + 15.89 + const elf_ehdr *ehdr; 15.90 + const char *sec_strtab; 15.91 + const elf_shdr *sym_tab; 15.92 + const char *sym_strtab; 15.93 + 15.94 + /* loaded to */ 15.95 + char *dest; 15.96 + uint64_t pstart; 15.97 + uint64_t pend; 15.98 + uint64_t reloc_offset; 15.99 + 15.100 + uint64_t bsd_symtab_pstart; 15.101 + uint64_t bsd_symtab_pend; 15.102 + 15.103 +#ifndef __XEN__ 15.104 + /* misc */ 15.105 + FILE *log; 15.106 +#endif 15.107 + int verbose; 15.108 +}; 15.109 + 15.110 +/* ------------------------------------------------------------------------ */ 15.111 +/* accessing elf header fields */ 15.112 + 15.113 +#ifdef XEN_ELF_BIG_ENDIAN 15.114 +# define NATIVE_ELFDATA ELFDATA2MSB 15.115 +#else 15.116 +# define NATIVE_ELFDATA ELFDATA2LSB 15.117 +#endif 15.118 + 15.119 +#define elf_32bit(elf) (ELFCLASS32 == (elf)->class) 15.120 +#define elf_64bit(elf) (ELFCLASS64 == (elf)->class) 15.121 +#define elf_msb(elf) (ELFDATA2MSB == (elf)->data) 15.122 +#define elf_lsb(elf) (ELFDATA2LSB == (elf)->data) 15.123 +#define elf_swap(elf) (NATIVE_ELFDATA != (elf)->data) 15.124 + 15.125 +#define elf_uval(elf, str, elem) \ 15.126 + ((ELFCLASS64 == (elf)->class) \ 15.127 + ? elf_access_unsigned((elf), (str), \ 15.128 + offsetof(typeof(*(str)),e64.elem), \ 15.129 + sizeof((str)->e64.elem)) \ 15.130 + : elf_access_unsigned((elf), (str), \ 15.131 + offsetof(typeof(*(str)),e32.elem), \ 15.132 + sizeof((str)->e32.elem))) 15.133 + 15.134 +#define elf_sval(elf, str, elem) \ 15.135 + ((ELFCLASS64 == (elf)->class) \ 15.136 + ? elf_access_signed((elf), (str), \ 15.137 + offsetof(typeof(*(str)),e64.elem), \ 15.138 + sizeof((str)->e64.elem)) \ 15.139 + : elf_access_signed((elf), (str), \ 15.140 + offsetof(typeof(*(str)),e32.elem), \ 15.141 + sizeof((str)->e32.elem))) 15.142 + 15.143 +#define elf_size(elf, str) \ 15.144 + ((ELFCLASS64 == (elf)->class) \ 15.145 + ? sizeof((str)->e64) : sizeof((str)->e32)) 15.146 + 15.147 +uint64_t elf_access_unsigned(struct elf_binary *elf, const void *ptr, 15.148 + uint64_t offset, size_t size); 15.149 +int64_t elf_access_signed(struct elf_binary *elf, const void *ptr, 15.150 + uint64_t offset, size_t size); 15.151 + 15.152 +uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr); 15.153 + 15.154 +/* ------------------------------------------------------------------------ */ 15.155 +/* xc_libelf_tools.c */ 15.156 + 15.157 +int elf_shdr_count(struct elf_binary *elf); 15.158 +int elf_phdr_count(struct elf_binary *elf); 15.159 + 15.160 +const elf_shdr *elf_shdr_by_name(struct elf_binary *elf, const char *name); 15.161 +const elf_shdr *elf_shdr_by_index(struct elf_binary *elf, int index); 15.162 +const elf_phdr *elf_phdr_by_index(struct elf_binary *elf, int index); 15.163 + 15.164 +const char *elf_section_name(struct elf_binary *elf, const elf_shdr * shdr); 15.165 +const void *elf_section_start(struct elf_binary *elf, const elf_shdr * shdr); 15.166 +const void *elf_section_end(struct elf_binary *elf, const elf_shdr * shdr); 15.167 + 15.168 +const void *elf_segment_start(struct elf_binary *elf, const elf_phdr * phdr); 15.169 +const void *elf_segment_end(struct elf_binary *elf, const elf_phdr * phdr); 15.170 + 15.171 +const elf_sym *elf_sym_by_name(struct elf_binary *elf, const char *symbol); 15.172 +const elf_sym *elf_sym_by_index(struct elf_binary *elf, int index); 15.173 + 15.174 +const char *elf_note_name(struct elf_binary *elf, const elf_note * note); 15.175 +const void *elf_note_desc(struct elf_binary *elf, const elf_note * note); 15.176 +uint64_t elf_note_numeric(struct elf_binary *elf, const elf_note * note); 15.177 +const elf_note *elf_note_next(struct elf_binary *elf, const elf_note * note); 15.178 + 15.179 +int elf_is_elfbinary(const void *image); 15.180 +int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr); 15.181 + 15.182 +/* ------------------------------------------------------------------------ */ 15.183 +/* xc_libelf_loader.c */ 15.184 + 15.185 +int elf_init(struct elf_binary *elf, const char *image, size_t size); 15.186 +#ifdef __XEN__ 15.187 +void elf_set_verbose(struct elf_binary *elf); 15.188 +#else 15.189 +void elf_set_logfile(struct elf_binary *elf, FILE * log, int verbose); 15.190 +#endif 15.191 + 15.192 +void elf_parse_binary(struct elf_binary *elf); 15.193 +void elf_load_binary(struct elf_binary *elf); 15.194 + 15.195 +void *elf_get_ptr(struct elf_binary *elf, unsigned long addr); 15.196 +uint64_t elf_lookup_addr(struct elf_binary *elf, const char *symbol); 15.197 + 15.198 +void elf_parse_bsdsyms(struct elf_binary *elf, uint64_t pstart); /* private */ 15.199 + 15.200 +/* ------------------------------------------------------------------------ */ 15.201 +/* xc_libelf_relocate.c */ 15.202 + 15.203 +int elf_reloc(struct elf_binary *elf); 15.204 + 15.205 +/* ------------------------------------------------------------------------ */ 15.206 +/* xc_libelf_dominfo.c */ 15.207 + 15.208 +#define UNSET_ADDR ((uint64_t)-1) 15.209 + 15.210 +enum xen_elfnote_type { 15.211 + XEN_ENT_NONE = 0, 15.212 + XEN_ENT_LONG = 1, 15.213 + XEN_ENT_STR = 2 15.214 +}; 15.215 + 15.216 +struct xen_elfnote { 15.217 + enum xen_elfnote_type type; 15.218 + const char *name; 15.219 + union { 15.220 + const char *str; 15.221 + uint64_t num; 15.222 + } data; 15.223 +}; 15.224 + 15.225 +struct elf_dom_parms { 15.226 + /* raw */ 15.227 + const char *guest_info; 15.228 + const void *elf_note_start; 15.229 + const void *elf_note_end; 15.230 + struct xen_elfnote elf_notes[XEN_ELFNOTE_MAX + 1]; 15.231 + 15.232 + /* parsed */ 15.233 + char guest_os[16]; 15.234 + char guest_ver[16]; 15.235 + char xen_ver[16]; 15.236 + char loader[16]; 15.237 + int pae; 15.238 + int bsd_symtab; 15.239 + uint64_t virt_base; 15.240 + uint64_t virt_entry; 15.241 + uint64_t virt_hypercall; 15.242 + uint64_t virt_hv_start_low; 15.243 + uint64_t p2m_base; 15.244 + uint64_t elf_paddr_offset; 15.245 + uint32_t f_supported[XENFEAT_NR_SUBMAPS]; 15.246 + uint32_t f_required[XENFEAT_NR_SUBMAPS]; 15.247 + 15.248 + /* calculated */ 15.249 + uint64_t virt_offset; 15.250 + uint64_t virt_kstart; 15.251 + uint64_t virt_kend; 15.252 +}; 15.253 + 15.254 +static inline void elf_xen_feature_set(int nr, uint32_t * addr) 15.255 +{ 15.256 + addr[nr >> 5] |= 1 << (nr & 31); 15.257 +} 15.258 +static inline int elf_xen_feature_get(int nr, uint32_t * addr) 15.259 +{ 15.260 + return !!(addr[nr >> 5] & (1 << (nr & 31))); 15.261 +} 15.262 + 15.263 +int elf_xen_parse_features(const char *features, 15.264 + uint32_t *supported, 15.265 + uint32_t *required); 15.266 +int elf_xen_parse_note(struct elf_binary *elf, 15.267 + struct elf_dom_parms *parms, 15.268 + const elf_note *note); 15.269 +int elf_xen_parse_guest_info(struct elf_binary *elf, 15.270 + struct elf_dom_parms *parms); 15.271 +int elf_xen_parse(struct elf_binary *elf, 15.272 + struct elf_dom_parms *parms); 15.273 + 15.274 +#endif /* __XEN_LIBELF_H__ */