2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1999 Global Technology Associates, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
22 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/endian.h>
35 #define KGZ_FIX_NSIZE 0 /* Run-time fixup */
38 * Relocatable header template.
40 const struct kgz_elfhdr elfhdr = {
44 ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* e_ident */
45 ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0,
46 'F', 'r', 'e', 'e', 'B', 'S', 'D', 0
48 htole16(ET_EXEC), /* e_type */
49 htole16(EM_386), /* e_machine */
50 htole32(EV_CURRENT), /* e_version */
53 htole32(offsetof(struct kgz_elfhdr, sh)), /* e_shoff */
55 htole16(sizeof(Elf32_Ehdr)), /* e_ehsize */
58 htole16(sizeof(Elf32_Shdr)), /* e_shentsize */
59 htole16(KGZ_SHNUM), /* e_shnum */
60 htole16(KGZ_SH_SHSTRTAB) /* e_shstrndx */
66 htole32(SHT_NULL), /* sh_type */
71 htole32(SHN_UNDEF), /* sh_link */
77 htole32(offsetof(struct kgz_shstrtab, symtab)), /* sh_name */
78 htole32(SHT_SYMTAB), /* sh_type */
81 htole32(offsetof(struct kgz_elfhdr, st)), /* sh_offset */
82 htole32(sizeof(Elf32_Sym) * KGZ_STNUM), /* sh_size */
83 htole32(KGZ_SH_STRTAB), /* sh_link */
84 htole32(1), /* sh_info */
85 htole32(4), /* sh_addralign */
86 htole32(sizeof(Elf32_Sym)) /* sh_entsize */
89 htole32(offsetof(struct kgz_shstrtab, shstrtab)), /* sh_name */
90 htole32(SHT_STRTAB), /* sh_type */
93 htole32(offsetof(struct kgz_elfhdr, shstrtab)), /* sh_offset */
94 htole32(sizeof(struct kgz_shstrtab)), /* sh_size */
95 htole32(SHN_UNDEF), /* sh_link */
97 htole32(1), /* sh_addralign */
101 htole32(offsetof(struct kgz_shstrtab, strtab)), /* sh_name */
102 htole32(SHT_STRTAB), /* sh_type */
105 htole32(offsetof(struct kgz_elfhdr, strtab)), /* sh_offset */
106 htole32(sizeof(struct kgz_strtab)), /* sh_size */
107 htole32(SHN_UNDEF), /* sh_link */
109 htole32(1), /* sh_addralign */
113 htole32(offsetof(struct kgz_shstrtab, data)), /* sh_name */
114 htole32(SHT_PROGBITS), /* sh_type */
115 htole32(SHF_ALLOC | SHF_WRITE), /* sh_flags */
117 htole32(sizeof(struct kgz_elfhdr)), /* sh_offset */
118 htole32(sizeof(struct kgz_hdr) + KGZ_FIX_NSIZE), /* sh_size */
119 htole32(SHN_UNDEF), /* sh_link */
121 htole32(4), /* sh_addralign */
133 htole16(SHN_UNDEF) /* st_shndx */
136 htole32(offsetof(struct kgz_strtab, kgz)), /* st_name */
138 htole32(sizeof(struct kgz_hdr)), /* st_size */
139 ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), /* st_info */
141 htole16(KGZ_SH_DATA) /* st_shndx */
144 htole32(offsetof(struct kgz_strtab, kgz_ndata)), /* st_name */
145 htole32(sizeof(struct kgz_hdr)), /* st_value */
146 htole32(KGZ_FIX_NSIZE), /* st_size */
147 ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), /* st_info */
149 htole16(KGZ_SH_DATA) /* st_shndx */
152 /* Section header string table */
154 KGZ_SHSTR_ZERO, /* zero */
155 KGZ_SHSTR_SYMTAB, /* symtab */
156 KGZ_SHSTR_SHSTRTAB, /* shstrtab */
157 KGZ_SHSTR_STRTAB, /* strtab */
158 KGZ_SHSTR_DATA /* data */
162 KGZ_STR_ZERO, /* zero */
163 KGZ_STR_KGZ, /* kgz */
164 KGZ_STR_KGZ_NDATA /* kgz_ndata */