1/*- 2 * Copyright (c) 2006 Joseph Koshy 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 PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 2006 Joseph Koshy 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 PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
|
28__FBSDID("$FreeBSD: head/lib/libelf/libelf_align.c 164190 2006-11-11 17:16:35Z jkoshy $");
| 28__FBSDID("$FreeBSD: head/lib/libelf/libelf_align.c 165316 2006-12-18 05:36:23Z jkoshy $");
|
29 30#include <sys/types.h> 31 32#include <machine/elf.h> 33#include <machine/endian.h> 34 35#include <libelf.h> 36#include <osreldate.h> 37 38#include "_libelf.h" 39 40struct align { 41 int a32; 42 int a64; 43}; 44 45#ifdef __GNUC__ 46#define MALIGN(N) { \ 47 .a32 = __alignof__(Elf32_##N), \ 48 .a64 = __alignof__(Elf64_##N) \ 49 } 50#define MALIGN64(V) { \ 51 .a32 = 0, \ 52 .a64 = __alignof__(Elf64_##V) \ 53 } 54#else 55#error Need the __alignof__ builtin. 56#endif 57#define UNSUPPORTED() { \ 58 .a32 = 0, \ 59 .a64 = 0 \ 60 } 61 62static struct align malign[ELF_T_NUM] = { 63 [ELF_T_ADDR] = MALIGN(Addr), 64 [ELF_T_BYTE] = { .a32 = 1, .a64 = 1 },
| 29 30#include <sys/types.h> 31 32#include <machine/elf.h> 33#include <machine/endian.h> 34 35#include <libelf.h> 36#include <osreldate.h> 37 38#include "_libelf.h" 39 40struct align { 41 int a32; 42 int a64; 43}; 44 45#ifdef __GNUC__ 46#define MALIGN(N) { \ 47 .a32 = __alignof__(Elf32_##N), \ 48 .a64 = __alignof__(Elf64_##N) \ 49 } 50#define MALIGN64(V) { \ 51 .a32 = 0, \ 52 .a64 = __alignof__(Elf64_##V) \ 53 } 54#else 55#error Need the __alignof__ builtin. 56#endif 57#define UNSUPPORTED() { \ 58 .a32 = 0, \ 59 .a64 = 0 \ 60 } 61 62static struct align malign[ELF_T_NUM] = { 63 [ELF_T_ADDR] = MALIGN(Addr), 64 [ELF_T_BYTE] = { .a32 = 1, .a64 = 1 },
|
65#if __FreeBSD_version >= 700009
| 65#if __FreeBSD_version >= 700025
|
66 [ELF_T_CAP] = MALIGN(Cap), 67#endif 68 [ELF_T_DYN] = MALIGN(Dyn), 69 [ELF_T_EHDR] = MALIGN(Ehdr), 70 [ELF_T_HALF] = MALIGN(Half),
| 66 [ELF_T_CAP] = MALIGN(Cap), 67#endif 68 [ELF_T_DYN] = MALIGN(Dyn), 69 [ELF_T_EHDR] = MALIGN(Ehdr), 70 [ELF_T_HALF] = MALIGN(Half),
|
71#if __FreeBSD_version >= 700009
| 71#if __FreeBSD_version >= 700025
|
72 [ELF_T_LWORD] = MALIGN(Lword), 73 [ELF_T_MOVE] = MALIGN(Move), 74#endif 75 [ELF_T_MOVEP] = UNSUPPORTED(),
| 72 [ELF_T_LWORD] = MALIGN(Lword), 73 [ELF_T_MOVE] = MALIGN(Move), 74#endif 75 [ELF_T_MOVEP] = UNSUPPORTED(),
|
76#if __FreeBSD_version >= 700009
| 76#if __FreeBSD_version >= 700025
|
77 [ELF_T_NOTE] = MALIGN(Nhdr), 78#endif 79 [ELF_T_OFF] = MALIGN(Off), 80 [ELF_T_PHDR] = MALIGN(Phdr), 81 [ELF_T_REL] = MALIGN(Rel), 82 [ELF_T_RELA] = MALIGN(Rela), 83 [ELF_T_SHDR] = MALIGN(Shdr), 84 [ELF_T_SWORD] = MALIGN(Sword), 85 [ELF_T_SXWORD] = MALIGN64(Sxword), 86 [ELF_T_SYM] = MALIGN(Sym),
| 77 [ELF_T_NOTE] = MALIGN(Nhdr), 78#endif 79 [ELF_T_OFF] = MALIGN(Off), 80 [ELF_T_PHDR] = MALIGN(Phdr), 81 [ELF_T_REL] = MALIGN(Rel), 82 [ELF_T_RELA] = MALIGN(Rela), 83 [ELF_T_SHDR] = MALIGN(Shdr), 84 [ELF_T_SWORD] = MALIGN(Sword), 85 [ELF_T_SXWORD] = MALIGN64(Sxword), 86 [ELF_T_SYM] = MALIGN(Sym),
|
87#if __FreeBSD_version >= 700009
| 87#if __FreeBSD_version >= 700025
|
88 [ELF_T_SYMINFO] = MALIGN(Syminfo), 89#endif 90#if __FreeBSD_version >= 700009 91 [ELF_T_VDEF] = MALIGN(Verdef), 92 [ELF_T_VNEED] = MALIGN(Verneed), 93#endif 94 [ELF_T_WORD] = MALIGN(Word), 95 [ELF_T_XWORD] = MALIGN64(Xword) 96}; 97 98int 99_libelf_malign(Elf_Type t, int elfclass) 100{ 101 if (t >= ELF_T_NUM || (int) t < 0) 102 return (0); 103 104 return (elfclass == ELFCLASS32 ? malign[t].a32 : 105 malign[t].a64); 106} 107 108#define FALIGN(A32,A64) { .a32 = (A32), .a64 = (A64) } 109 110static struct align falign[ELF_T_NUM] = { 111 [ELF_T_ADDR] = FALIGN(4,8), 112 [ELF_T_BYTE] = FALIGN(1,1),
| 88 [ELF_T_SYMINFO] = MALIGN(Syminfo), 89#endif 90#if __FreeBSD_version >= 700009 91 [ELF_T_VDEF] = MALIGN(Verdef), 92 [ELF_T_VNEED] = MALIGN(Verneed), 93#endif 94 [ELF_T_WORD] = MALIGN(Word), 95 [ELF_T_XWORD] = MALIGN64(Xword) 96}; 97 98int 99_libelf_malign(Elf_Type t, int elfclass) 100{ 101 if (t >= ELF_T_NUM || (int) t < 0) 102 return (0); 103 104 return (elfclass == ELFCLASS32 ? malign[t].a32 : 105 malign[t].a64); 106} 107 108#define FALIGN(A32,A64) { .a32 = (A32), .a64 = (A64) } 109 110static struct align falign[ELF_T_NUM] = { 111 [ELF_T_ADDR] = FALIGN(4,8), 112 [ELF_T_BYTE] = FALIGN(1,1),
|
113#if __FreeBSD_version >= 700009
| 113#if __FreeBSD_version >= 700025
|
114 [ELF_T_CAP] = FALIGN(4,8), 115#endif 116 [ELF_T_DYN] = FALIGN(4,8), 117 [ELF_T_EHDR] = FALIGN(4,8), 118 [ELF_T_HALF] = FALIGN(2,2),
| 114 [ELF_T_CAP] = FALIGN(4,8), 115#endif 116 [ELF_T_DYN] = FALIGN(4,8), 117 [ELF_T_EHDR] = FALIGN(4,8), 118 [ELF_T_HALF] = FALIGN(2,2),
|
119#if __FreeBSD_version >= 700009
| 119#if __FreeBSD_version >= 700025
|
120 [ELF_T_LWORD] = FALIGN(8,8), 121 [ELF_T_MOVE] = FALIGN(8,8), 122#endif 123 [ELF_T_MOVEP] = UNSUPPORTED(),
| 120 [ELF_T_LWORD] = FALIGN(8,8), 121 [ELF_T_MOVE] = FALIGN(8,8), 122#endif 123 [ELF_T_MOVEP] = UNSUPPORTED(),
|
124#if __FreeBSD_version >= 700009
| 124#if __FreeBSD_version >= 700025
|
125 [ELF_T_NOTE] = FALIGN(4,4), 126#endif 127 [ELF_T_OFF] = FALIGN(4,8), 128 [ELF_T_PHDR] = FALIGN(4,8), 129 [ELF_T_REL] = FALIGN(4,8), 130 [ELF_T_RELA] = FALIGN(4,8), 131 [ELF_T_SHDR] = FALIGN(4,8), 132 [ELF_T_SWORD] = FALIGN(4,4), 133 [ELF_T_SXWORD] = FALIGN(0,8), 134 [ELF_T_SYM] = FALIGN(4,8),
| 125 [ELF_T_NOTE] = FALIGN(4,4), 126#endif 127 [ELF_T_OFF] = FALIGN(4,8), 128 [ELF_T_PHDR] = FALIGN(4,8), 129 [ELF_T_REL] = FALIGN(4,8), 130 [ELF_T_RELA] = FALIGN(4,8), 131 [ELF_T_SHDR] = FALIGN(4,8), 132 [ELF_T_SWORD] = FALIGN(4,4), 133 [ELF_T_SXWORD] = FALIGN(0,8), 134 [ELF_T_SYM] = FALIGN(4,8),
|
135#if __FreeBSD_version >= 700009
| 135#if __FreeBSD_version >= 700025
|
136 [ELF_T_SYMINFO] = FALIGN(2,2), 137#endif 138#if __FreeBSD_version >= 700009 139 [ELF_T_VDEF] = FALIGN(4,4), 140 [ELF_T_VNEED] = FALIGN(4,4), 141#endif 142 [ELF_T_WORD] = FALIGN(4,4), 143 [ELF_T_XWORD] = FALIGN(0,8) 144}; 145 146int 147_libelf_falign(Elf_Type t, int elfclass) 148{ 149 if (t >= ELF_T_NUM || (int) t < 0) 150 return (0); 151 152 return (elfclass == ELFCLASS32 ? falign[t].a32 : 153 falign[t].a64); 154}
| 136 [ELF_T_SYMINFO] = FALIGN(2,2), 137#endif 138#if __FreeBSD_version >= 700009 139 [ELF_T_VDEF] = FALIGN(4,4), 140 [ELF_T_VNEED] = FALIGN(4,4), 141#endif 142 [ELF_T_WORD] = FALIGN(4,4), 143 [ELF_T_XWORD] = FALIGN(0,8) 144}; 145 146int 147_libelf_falign(Elf_Type t, int elfclass) 148{ 149 if (t >= ELF_T_NUM || (int) t < 0) 150 return (0); 151 152 return (elfclass == ELFCLASS32 ? falign[t].a32 : 153 falign[t].a64); 154}
|