elfhdr.c (112089) | elfhdr.c (130927) |
---|---|
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 unchanged lines hidden (view full) --- 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 * | 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 unchanged lines hidden (view full) --- 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 * $FreeBSD: head/usr.sbin/kgzip/elfhdr.c 112089 2003-03-11 11:45:43Z ru $ | 26 * $FreeBSD: head/usr.sbin/kgzip/elfhdr.c 130927 2004-06-22 17:05:39Z obrien $ |
27 */ 28 | 27 */ 28 |
29#include <sys/endian.h> |
|
29#include <stddef.h> 30#include "elfhdr.h" | 30#include <stddef.h> 31#include "elfhdr.h" |
31#include "endian.h" | |
32 33#define KGZ_FIX_NSIZE 0 /* Run-time fixup */ 34 35/* 36 * Relocatable header template. 37 */ 38const struct kgz_elfhdr elfhdr = { 39 /* ELF header */ 40 { 41 { 42 ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* e_ident */ 43 ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0, 44 'F', 'r', 'e', 'e', 'B', 'S', 'D', 0 45 }, | 32 33#define KGZ_FIX_NSIZE 0 /* Run-time fixup */ 34 35/* 36 * Relocatable header template. 37 */ 38const struct kgz_elfhdr elfhdr = { 39 /* ELF header */ 40 { 41 { 42 ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* e_ident */ 43 ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0, 44 'F', 'r', 'e', 'e', 'B', 'S', 'D', 0 45 }, |
46 HTOLE16(ET_EXEC), /* e_type */ 47 HTOLE16(EM_386), /* e_machine */ 48 HTOLE32(EV_CURRENT), /* e_version */ | 46 htole16(ET_EXEC), /* e_type */ 47 htole16(EM_386), /* e_machine */ 48 htole32(EV_CURRENT), /* e_version */ |
49 0, /* e_entry */ 50 0, /* e_phoff */ | 49 0, /* e_entry */ 50 0, /* e_phoff */ |
51 HTOLE32(offsetof(struct kgz_elfhdr, sh)), /* e_shoff */ | 51 htole32(offsetof(struct kgz_elfhdr, sh)), /* e_shoff */ |
52 0, /* e_flags */ | 52 0, /* e_flags */ |
53 HTOLE16(sizeof(Elf32_Ehdr)), /* e_ehsize */ | 53 htole16(sizeof(Elf32_Ehdr)), /* e_ehsize */ |
54 0, /* e_phentsize */ 55 0, /* e_phnum */ | 54 0, /* e_phentsize */ 55 0, /* e_phnum */ |
56 HTOLE16(sizeof(Elf32_Shdr)), /* e_shentsize */ 57 HTOLE16(KGZ_SHNUM), /* e_shnum */ 58 HTOLE16(KGZ_SH_SHSTRTAB) /* e_shstrndx */ | 56 htole16(sizeof(Elf32_Shdr)), /* e_shentsize */ 57 htole16(KGZ_SHNUM), /* e_shnum */ 58 htole16(KGZ_SH_SHSTRTAB) /* e_shstrndx */ |
59 }, 60 /* Section header */ 61 { 62 { 63 0, /* sh_name */ | 59 }, 60 /* Section header */ 61 { 62 { 63 0, /* sh_name */ |
64 HTOLE32(SHT_NULL), /* sh_type */ | 64 htole32(SHT_NULL), /* sh_type */ |
65 0, /* sh_flags */ 66 0, /* sh_addr */ 67 0, /* sh_offset */ 68 0, /* sh_size */ | 65 0, /* sh_flags */ 66 0, /* sh_addr */ 67 0, /* sh_offset */ 68 0, /* sh_size */ |
69 HTOLE32(SHN_UNDEF), /* sh_link */ | 69 htole32(SHN_UNDEF), /* sh_link */ |
70 0, /* sh_info */ 71 0, /* sh_addralign */ 72 0 /* sh_entsize */ 73 }, 74 { | 70 0, /* sh_info */ 71 0, /* sh_addralign */ 72 0 /* sh_entsize */ 73 }, 74 { |
75 HTOLE32(offsetof(struct kgz_shstrtab, symtab)), /* sh_name */ 76 HTOLE32(SHT_SYMTAB), /* sh_type */ | 75 htole32(offsetof(struct kgz_shstrtab, symtab)), /* sh_name */ 76 htole32(SHT_SYMTAB), /* sh_type */ |
77 0, /* sh_flags */ 78 0, /* sh_addr */ | 77 0, /* sh_flags */ 78 0, /* sh_addr */ |
79 HTOLE32(offsetof(struct kgz_elfhdr, st)), /* sh_offset */ 80 HTOLE32(sizeof(Elf32_Sym) * KGZ_STNUM), /* sh_size */ 81 HTOLE32(KGZ_SH_STRTAB), /* sh_link */ 82 HTOLE32(1), /* sh_info */ 83 HTOLE32(4), /* sh_addralign */ 84 HTOLE32(sizeof(Elf32_Sym)) /* sh_entsize */ | 79 htole32(offsetof(struct kgz_elfhdr, st)), /* sh_offset */ 80 htole32(sizeof(Elf32_Sym) * KGZ_STNUM), /* sh_size */ 81 htole32(KGZ_SH_STRTAB), /* sh_link */ 82 htole32(1), /* sh_info */ 83 htole32(4), /* sh_addralign */ 84 htole32(sizeof(Elf32_Sym)) /* sh_entsize */ |
85 }, 86 { | 85 }, 86 { |
87 HTOLE32(offsetof(struct kgz_shstrtab, shstrtab)), /* sh_name */ 88 HTOLE32(SHT_STRTAB), /* sh_type */ | 87 htole32(offsetof(struct kgz_shstrtab, shstrtab)), /* sh_name */ 88 htole32(SHT_STRTAB), /* sh_type */ |
89 0, /* sh_flags */ 90 0, /* sh_addr */ | 89 0, /* sh_flags */ 90 0, /* sh_addr */ |
91 HTOLE32(offsetof(struct kgz_elfhdr, shstrtab)), /* sh_offset */ 92 HTOLE32(sizeof(struct kgz_shstrtab)), /* sh_size */ 93 HTOLE32(SHN_UNDEF), /* sh_link */ | 91 htole32(offsetof(struct kgz_elfhdr, shstrtab)), /* sh_offset */ 92 htole32(sizeof(struct kgz_shstrtab)), /* sh_size */ 93 htole32(SHN_UNDEF), /* sh_link */ |
94 0, /* sh_info */ | 94 0, /* sh_info */ |
95 HTOLE32(1), /* sh_addralign */ | 95 htole32(1), /* sh_addralign */ |
96 0 /* sh_entsize */ 97 }, 98 { | 96 0 /* sh_entsize */ 97 }, 98 { |
99 HTOLE32(offsetof(struct kgz_shstrtab, strtab)), /* sh_name */ 100 HTOLE32(SHT_STRTAB), /* sh_type */ | 99 htole32(offsetof(struct kgz_shstrtab, strtab)), /* sh_name */ 100 htole32(SHT_STRTAB), /* sh_type */ |
101 0, /* sh_flags */ 102 0, /* sh_addr */ | 101 0, /* sh_flags */ 102 0, /* sh_addr */ |
103 HTOLE32(offsetof(struct kgz_elfhdr, strtab)), /* sh_offset */ 104 HTOLE32(sizeof(struct kgz_strtab)), /* sh_size */ 105 HTOLE32(SHN_UNDEF), /* sh_link */ | 103 htole32(offsetof(struct kgz_elfhdr, strtab)), /* sh_offset */ 104 htole32(sizeof(struct kgz_strtab)), /* sh_size */ 105 htole32(SHN_UNDEF), /* sh_link */ |
106 0, /* sh_info */ | 106 0, /* sh_info */ |
107 HTOLE32(1), /* sh_addralign */ | 107 htole32(1), /* sh_addralign */ |
108 0 /* sh_entsize */ 109 }, 110 { | 108 0 /* sh_entsize */ 109 }, 110 { |
111 HTOLE32(offsetof(struct kgz_shstrtab, data)), /* sh_name */ 112 HTOLE32(SHT_PROGBITS), /* sh_type */ 113 HTOLE32(SHF_ALLOC | SHF_WRITE), /* sh_flags */ | 111 htole32(offsetof(struct kgz_shstrtab, data)), /* sh_name */ 112 htole32(SHT_PROGBITS), /* sh_type */ 113 htole32(SHF_ALLOC | SHF_WRITE), /* sh_flags */ |
114 0, /* sh_addr */ | 114 0, /* sh_addr */ |
115 HTOLE32(sizeof(struct kgz_elfhdr)), /* sh_offset */ 116 HTOLE32(sizeof(struct kgz_hdr) + KGZ_FIX_NSIZE), /* sh_size */ 117 HTOLE32(SHN_UNDEF), /* sh_link */ | 115 htole32(sizeof(struct kgz_elfhdr)), /* sh_offset */ 116 htole32(sizeof(struct kgz_hdr) + KGZ_FIX_NSIZE), /* sh_size */ 117 htole32(SHN_UNDEF), /* sh_link */ |
118 0, /* sh_info */ | 118 0, /* sh_info */ |
119 HTOLE32(4), /* sh_addralign */ | 119 htole32(4), /* sh_addralign */ |
120 0 /* sh_entsize */ 121 } 122 }, 123 /* Symbol table */ 124 { 125 { 126 0, /* st_name */ 127 0, /* st_value */ 128 0, /* st_size */ 129 0, /* st_info */ 130 0, /* st_other */ | 120 0 /* sh_entsize */ 121 } 122 }, 123 /* Symbol table */ 124 { 125 { 126 0, /* st_name */ 127 0, /* st_value */ 128 0, /* st_size */ 129 0, /* st_info */ 130 0, /* st_other */ |
131 HTOLE16(SHN_UNDEF) /* st_shndx */ | 131 htole16(SHN_UNDEF) /* st_shndx */ |
132 }, 133 { | 132 }, 133 { |
134 HTOLE32(offsetof(struct kgz_strtab, kgz)), /* st_name */ | 134 htole32(offsetof(struct kgz_strtab, kgz)), /* st_name */ |
135 0, /* st_value */ | 135 0, /* st_value */ |
136 HTOLE32(sizeof(struct kgz_hdr)), /* st_size */ | 136 htole32(sizeof(struct kgz_hdr)), /* st_size */ |
137 ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), /* st_info */ 138 0, /* st_other */ | 137 ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), /* st_info */ 138 0, /* st_other */ |
139 HTOLE16(KGZ_SH_DATA) /* st_shndx */ | 139 htole16(KGZ_SH_DATA) /* st_shndx */ |
140 }, 141 { | 140 }, 141 { |
142 HTOLE32(offsetof(struct kgz_strtab, kgz_ndata)), /* st_name */ 143 HTOLE32(sizeof(struct kgz_hdr)), /* st_value */ 144 HTOLE32(KGZ_FIX_NSIZE), /* st_size */ | 142 htole32(offsetof(struct kgz_strtab, kgz_ndata)), /* st_name */ 143 htole32(sizeof(struct kgz_hdr)), /* st_value */ 144 htole32(KGZ_FIX_NSIZE), /* st_size */ |
145 ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), /* st_info */ 146 0, /* st_other */ | 145 ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), /* st_info */ 146 0, /* st_other */ |
147 HTOLE16(KGZ_SH_DATA) /* st_shndx */ | 147 htole16(KGZ_SH_DATA) /* st_shndx */ |
148 } 149 }, 150 /* Section header string table */ 151 { 152 KGZ_SHSTR_ZERO, /* zero */ 153 KGZ_SHSTR_SYMTAB, /* symtab */ 154 KGZ_SHSTR_SHSTRTAB, /* shstrtab */ 155 KGZ_SHSTR_STRTAB, /* strtab */ 156 KGZ_SHSTR_DATA /* data */ 157 }, 158 /* String table */ 159 { 160 KGZ_STR_ZERO, /* zero */ 161 KGZ_STR_KGZ, /* kgz */ 162 KGZ_STR_KGZ_NDATA /* kgz_ndata */ 163 } 164}; | 148 } 149 }, 150 /* Section header string table */ 151 { 152 KGZ_SHSTR_ZERO, /* zero */ 153 KGZ_SHSTR_SYMTAB, /* symtab */ 154 KGZ_SHSTR_SHSTRTAB, /* shstrtab */ 155 KGZ_SHSTR_STRTAB, /* strtab */ 156 KGZ_SHSTR_DATA /* data */ 157 }, 158 /* String table */ 159 { 160 KGZ_STR_ZERO, /* zero */ 161 KGZ_STR_KGZ, /* kgz */ 162 KGZ_STR_KGZ_NDATA /* kgz_ndata */ 163 } 164}; |