elfhdr.c revision 48906
1/* 2 * Copyright (c) 1999 Global Technology Associates, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 19 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 20 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 21 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 23 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $Id:$ 27 */ 28 29#include <stddef.h> 30#include "elfhdr.h" 31 32#define KGZ_FIX_NSIZE 0 /* Run-time fixup */ 33 34/* 35 * Relocatable header template. 36 */ 37const struct kgz_elfhdr elfhdr = { 38 /* ELF header */ 39 { 40 { 41 ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* e_ident */ 42 ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0, 43 'F', 'r', 'e', 'e', 'B', 'S', 'D', 0 44 }, 45 ET_EXEC, /* e_type */ 46 EM_386, /* e_machine */ 47 EV_CURRENT, /* e_version */ 48 0, /* e_entry */ 49 0, /* e_phoff */ 50 offsetof(struct kgz_elfhdr, sh), /* e_shoff */ 51 0, /* e_flags */ 52 sizeof(Elf32_Ehdr), /* e_ehsize */ 53 0, /* e_phentsize */ 54 0, /* e_phnum */ 55 sizeof(Elf32_Shdr), /* e_shentsize */ 56 KGZ_SHNUM, /* e_shnum */ 57 KGZ_SH_SHSTRTAB /* e_shstrndx */ 58 }, 59 /* Section header */ 60 { 61 { 62 0, /* sh_name */ 63 SHT_NULL, /* sh_type */ 64 0, /* sh_flags */ 65 0, /* sh_addr */ 66 0, /* sh_offset */ 67 0, /* sh_size */ 68 SHN_UNDEF, /* sh_link */ 69 0, /* sh_info */ 70 0, /* sh_addralign */ 71 0 /* sh_entsize */ 72 }, 73 { 74 offsetof(struct kgz_shstrtab, symtab), /* sh_name */ 75 SHT_SYMTAB, /* sh_type */ 76 0, /* sh_flags */ 77 0, /* sh_addr */ 78 offsetof(struct kgz_elfhdr, st), /* sh_offset */ 79 sizeof(Elf32_Sym) * KGZ_STNUM, /* sh_size */ 80 KGZ_SH_STRTAB, /* sh_link */ 81 1, /* sh_info */ 82 4, /* sh_addralign */ 83 sizeof(Elf32_Sym) /* sh_entsize */ 84 }, 85 { 86 offsetof(struct kgz_shstrtab, shstrtab), /* sh_name */ 87 SHT_STRTAB, /* sh_type */ 88 0, /* sh_flags */ 89 0, /* sh_addr */ 90 offsetof(struct kgz_elfhdr, shstrtab), /* sh_offset */ 91 sizeof(struct kgz_shstrtab), /* sh_size */ 92 SHN_UNDEF, /* sh_link */ 93 0, /* sh_info */ 94 1, /* sh_addralign */ 95 0 /* sh_entsize */ 96 }, 97 { 98 offsetof(struct kgz_shstrtab, strtab), /* sh_name */ 99 SHT_STRTAB, /* sh_type */ 100 0, /* sh_flags */ 101 0, /* sh_addr */ 102 offsetof(struct kgz_elfhdr, strtab), /* sh_offset */ 103 sizeof(struct kgz_strtab), /* sh_size */ 104 SHN_UNDEF, /* sh_link */ 105 0, /* sh_info */ 106 1, /* sh_addralign */ 107 0 /* sh_entsize */ 108 }, 109 { 110 offsetof(struct kgz_shstrtab, data), /* sh_name */ 111 SHT_PROGBITS, /* sh_type */ 112 SHF_ALLOC | SHF_WRITE, /* sh_flags */ 113 0, /* sh_addr */ 114 sizeof(struct kgz_elfhdr), /* sh_offset */ 115 sizeof(struct kgz_hdr) + KGZ_FIX_NSIZE, /* sh_size */ 116 SHN_UNDEF, /* sh_link */ 117 0, /* sh_info */ 118 4, /* sh_addralign */ 119 0 /* sh_entsize */ 120 } 121 }, 122 /* Symbol table */ 123 { 124 { 125 0, /* st_name */ 126 0, /* st_value */ 127 0, /* st_size */ 128 0, /* st_info */ 129 0, /* st_other */ 130 SHN_UNDEF /* st_shndx */ 131 }, 132 { 133 offsetof(struct kgz_strtab, kgz), /* st_name */ 134 0, /* st_value */ 135 sizeof(struct kgz_hdr), /* st_size */ 136 ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), /* st_info */ 137 0, /* st_other */ 138 KGZ_SH_DATA /* st_shndx */ 139 }, 140 { 141 offsetof(struct kgz_strtab, kgz_ndata), /* st_name */ 142 sizeof(struct kgz_hdr), /* st_value */ 143 KGZ_FIX_NSIZE, /* st_size */ 144 ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), /* st_info */ 145 0, /* st_other */ 146 KGZ_SH_DATA /* st_shndx */ 147 } 148 }, 149 /* Section header string table */ 150 { 151 KGZ_SHSTR_ZERO, /* zero */ 152 KGZ_SHSTR_SYMTAB, /* symtab */ 153 KGZ_SHSTR_SHSTRTAB, /* shstrtab */ 154 KGZ_SHSTR_STRTAB, /* strtab */ 155 KGZ_SHSTR_DATA /* data */ 156 }, 157 /* String table */ 158 { 159 KGZ_STR_ZERO, /* zero */ 160 KGZ_STR_KGZ, /* kgz */ 161 KGZ_STR_KGZ_NDATA /* kgz_ndata */ 162 } 163}; 164