elfh.c (112092) | elfh.c (130927) |
---|---|
1/* 2 * Copyright (c) 1998 Robert Nordier 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) 1998 Robert Nordier 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/btxld/elfh.c 112092 2003-03-11 13:48:58Z ru $ | 26 * $FreeBSD: head/usr.sbin/btxld/elfh.c 130927 2004-06-22 17:05:39Z obrien $ |
27 */ 28 29#include <sys/types.h> | 27 */ 28 29#include <sys/types.h> |
30#include <sys/endian.h> |
|
30 31#include <stddef.h> 32#include "elfh.h" | 31 32#include <stddef.h> 33#include "elfh.h" |
33#include "endian.h" | |
34 35#define SET_ME 0xeeeeeeee /* filled in by btxld */ 36 37/* 38 * ELF header template. 39 */ 40const struct elfh elfhdr = { 41 { 42 { 43 ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* e_ident */ 44 ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0, 45 'F', 'r', 'e', 'e', 'B', 'S', 'D', 0 46 }, | 34 35#define SET_ME 0xeeeeeeee /* filled in by btxld */ 36 37/* 38 * ELF header template. 39 */ 40const struct elfh elfhdr = { 41 { 42 { 43 ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* e_ident */ 44 ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0, 45 'F', 'r', 'e', 'e', 'B', 'S', 'D', 0 46 }, |
47 HTOLE16(ET_EXEC), /* e_type */ 48 HTOLE16(EM_386), /* e_machine */ 49 HTOLE32(EV_CURRENT), /* e_version */ 50 HTOLE32(SET_ME), /* e_entry */ 51 HTOLE32(offsetof(struct elfh, p)), /* e_phoff */ 52 HTOLE32(offsetof(struct elfh, sh)), /* e_shoff */ | 47 htole16(ET_EXEC), /* e_type */ 48 htole16(EM_386), /* e_machine */ 49 htole32(EV_CURRENT), /* e_version */ 50 htole32(SET_ME), /* e_entry */ 51 htole32(offsetof(struct elfh, p)), /* e_phoff */ 52 htole32(offsetof(struct elfh, sh)), /* e_shoff */ |
53 0, /* e_flags */ | 53 0, /* e_flags */ |
54 HTOLE16(sizeof(elfhdr.e)), /* e_ehsize */ 55 HTOLE16(sizeof(elfhdr.p[0])), /* e_phentsize */ 56 HTOLE16(sizeof(elfhdr.p) / sizeof(elfhdr.p[0])), /* e_phnum */ 57 HTOLE16(sizeof(elfhdr.sh[0])), /* e_shentsize */ 58 HTOLE16(sizeof(elfhdr.sh) / sizeof(elfhdr.sh[0])), /* e_shnum */ 59 HTOLE16(1) /* e_shstrndx */ | 54 htole16(sizeof(elfhdr.e)), /* e_ehsize */ 55 htole16(sizeof(elfhdr.p[0])), /* e_phentsize */ 56 htole16(sizeof(elfhdr.p) / sizeof(elfhdr.p[0])), /* e_phnum */ 57 htole16(sizeof(elfhdr.sh[0])), /* e_shentsize */ 58 htole16(sizeof(elfhdr.sh) / sizeof(elfhdr.sh[0])), /* e_shnum */ 59 htole16(1) /* e_shstrndx */ |
60 }, 61 { 62 { | 60 }, 61 { 62 { |
63 HTOLE32(PT_LOAD), /* p_type */ 64 HTOLE32(sizeof(elfhdr)), /* p_offset */ 65 HTOLE32(SET_ME), /* p_vaddr */ 66 HTOLE32(SET_ME), /* p_paddr */ 67 HTOLE32(SET_ME), /* p_filesz */ 68 HTOLE32(SET_ME), /* p_memsz */ 69 HTOLE32(PF_R | PF_X), /* p_flags */ 70 HTOLE32(0x1000) /* p_align */ | 63 htole32(PT_LOAD), /* p_type */ 64 htole32(sizeof(elfhdr)), /* p_offset */ 65 htole32(SET_ME), /* p_vaddr */ 66 htole32(SET_ME), /* p_paddr */ 67 htole32(SET_ME), /* p_filesz */ 68 htole32(SET_ME), /* p_memsz */ 69 htole32(PF_R | PF_X), /* p_flags */ 70 htole32(0x1000) /* p_align */ |
71 }, 72 { | 71 }, 72 { |
73 HTOLE32(PT_LOAD), /* p_type */ 74 HTOLE32(SET_ME), /* p_offset */ 75 HTOLE32(SET_ME), /* p_vaddr */ 76 HTOLE32(SET_ME), /* p_paddr */ 77 HTOLE32(SET_ME), /* p_filesz */ 78 HTOLE32(SET_ME), /* p_memsz */ 79 HTOLE32(PF_R | PF_W), /* p_flags */ 80 HTOLE32(0x1000) /* p_align */ | 73 htole32(PT_LOAD), /* p_type */ 74 htole32(SET_ME), /* p_offset */ 75 htole32(SET_ME), /* p_vaddr */ 76 htole32(SET_ME), /* p_paddr */ 77 htole32(SET_ME), /* p_filesz */ 78 htole32(SET_ME), /* p_memsz */ 79 htole32(PF_R | PF_W), /* p_flags */ 80 htole32(0x1000) /* p_align */ |
81 } 82 }, 83 { 84 { | 81 } 82 }, 83 { 84 { |
85 0, HTOLE32(SHT_NULL), 0, 0, 0, 0, HTOLE32(SHN_UNDEF), 0, 0, 0 | 85 0, htole32(SHT_NULL), 0, 0, 0, 0, htole32(SHN_UNDEF), 0, 0, 0 |
86 }, 87 { | 86 }, 87 { |
88 HTOLE32(1), /* sh_name */ 89 HTOLE32(SHT_STRTAB), /* sh_type */ | 88 htole32(1), /* sh_name */ 89 htole32(SHT_STRTAB), /* sh_type */ |
90 0, /* sh_flags */ 91 0, /* sh_addr */ | 90 0, /* sh_flags */ 91 0, /* sh_addr */ |
92 HTOLE32(offsetof(struct elfh, shstrtab)), /* sh_offset */ 93 HTOLE32(sizeof(elfhdr.shstrtab)), /* sh_size */ 94 HTOLE32(SHN_UNDEF), /* sh_link */ | 92 htole32(offsetof(struct elfh, shstrtab)), /* sh_offset */ 93 htole32(sizeof(elfhdr.shstrtab)), /* sh_size */ 94 htole32(SHN_UNDEF), /* sh_link */ |
95 0, /* sh_info */ | 95 0, /* sh_info */ |
96 HTOLE32(1), /* sh_addralign */ | 96 htole32(1), /* sh_addralign */ |
97 0 /* sh_entsize */ 98 }, 99 { | 97 0 /* sh_entsize */ 98 }, 99 { |
100 HTOLE32(0xb), /* sh_name */ 101 HTOLE32(SHT_PROGBITS), /* sh_type */ 102 HTOLE32(SHF_EXECINSTR | SHF_ALLOC), /* sh_flags */ 103 HTOLE32(SET_ME), /* sh_addr */ 104 HTOLE32(SET_ME), /* sh_offset */ 105 HTOLE32(SET_ME), /* sh_size */ 106 HTOLE32(SHN_UNDEF), /* sh_link */ | 100 htole32(0xb), /* sh_name */ 101 htole32(SHT_PROGBITS), /* sh_type */ 102 htole32(SHF_EXECINSTR | SHF_ALLOC), /* sh_flags */ 103 htole32(SET_ME), /* sh_addr */ 104 htole32(SET_ME), /* sh_offset */ 105 htole32(SET_ME), /* sh_size */ 106 htole32(SHN_UNDEF), /* sh_link */ |
107 0, /* sh_info */ | 107 0, /* sh_info */ |
108 HTOLE32(4), /* sh_addralign */ | 108 htole32(4), /* sh_addralign */ |
109 0 /* sh_entsize */ 110 }, 111 { | 109 0 /* sh_entsize */ 110 }, 111 { |
112 HTOLE32(0x11), /* sh_name */ 113 HTOLE32(SHT_PROGBITS), /* sh_type */ 114 HTOLE32(SHF_ALLOC | SHF_WRITE), /* sh_flags */ 115 HTOLE32(SET_ME), /* sh_addr */ 116 HTOLE32(SET_ME), /* sh_offset */ 117 HTOLE32(SET_ME), /* sh_size */ 118 HTOLE32(SHN_UNDEF), /* sh_link */ | 112 htole32(0x11), /* sh_name */ 113 htole32(SHT_PROGBITS), /* sh_type */ 114 htole32(SHF_ALLOC | SHF_WRITE), /* sh_flags */ 115 htole32(SET_ME), /* sh_addr */ 116 htole32(SET_ME), /* sh_offset */ 117 htole32(SET_ME), /* sh_size */ 118 htole32(SHN_UNDEF), /* sh_link */ |
119 0, /* sh_info */ | 119 0, /* sh_info */ |
120 HTOLE32(4), /* sh_addralign */ | 120 htole32(4), /* sh_addralign */ |
121 0 /* sh_entsize */ 122 } 123 }, 124 "\0.shstrtab\0.text\0.data" /* shstrtab */ 125}; | 121 0 /* sh_entsize */ 122 } 123 }, 124 "\0.shstrtab\0.text\0.data" /* shstrtab */ 125}; |