Remove building with NOCRYPTO option
[minix.git] / external / bsd / elftoolchain / dist / libelf / libelf_align.c
blobbea19a4790d7866707291159aa2607cc30ffd987
1 /* $NetBSD: libelf_align.c,v 1.3 2014/04/18 02:28:06 christos Exp $ */
3 /*-
4 * Copyright (c) 2006,2008 Joseph Koshy
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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 PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #if HAVE_NBTOOL_CONFIG_H
30 # include "nbtool_config.h"
31 #endif
33 #include <sys/cdefs.h>
35 #include <sys/types.h>
37 #include <libelf.h>
39 #include "_libelf.h"
41 __RCSID("$NetBSD: libelf_align.c,v 1.3 2014/04/18 02:28:06 christos Exp $");
42 ELFTC_VCSID("Id: libelf_align.c 2225 2011-11-26 18:55:54Z jkoshy ");
44 struct align {
45 int a32;
46 int a64;
49 #if defined(__GNUC__) || defined(__lint__)
50 #define MALIGN(N) { \
51 .a32 = __alignof__(Elf32_##N), \
52 .a64 = __alignof__(Elf64_##N) \
54 #define MALIGN64(V) { \
55 .a32 = 0, \
56 .a64 = __alignof__(Elf64_##V) \
58 #define MALIGN_WORD() { \
59 .a32 = __alignof__(int32_t), \
60 .a64 = __alignof__(int64_t) \
62 #else
63 #error Need the __alignof__ builtin.
64 #endif
65 #define UNSUPPORTED() { \
66 .a32 = 0, \
67 .a64 = 0 \
70 static struct align malign[ELF_T_NUM] = {
71 [ELF_T_ADDR] = MALIGN(Addr),
72 [ELF_T_BYTE] = { .a32 = 1, .a64 = 1 },
73 [ELF_T_CAP] = MALIGN(Cap),
74 [ELF_T_DYN] = MALIGN(Dyn),
75 [ELF_T_EHDR] = MALIGN(Ehdr),
76 [ELF_T_HALF] = MALIGN(Half),
77 [ELF_T_LWORD] = MALIGN(Lword),
78 [ELF_T_MOVE] = MALIGN(Move),
79 [ELF_T_MOVEP] = UNSUPPORTED(),
80 [ELF_T_NOTE] = MALIGN(Nhdr),
81 [ELF_T_OFF] = MALIGN(Off),
82 [ELF_T_PHDR] = MALIGN(Phdr),
83 [ELF_T_REL] = MALIGN(Rel),
84 [ELF_T_RELA] = MALIGN(Rela),
85 [ELF_T_SHDR] = MALIGN(Shdr),
86 [ELF_T_SWORD] = MALIGN(Sword),
87 [ELF_T_SXWORD] = MALIGN64(Sxword),
88 [ELF_T_SYM] = MALIGN(Sym),
89 [ELF_T_SYMINFO] = MALIGN(Syminfo),
90 [ELF_T_VDEF] = MALIGN(Verdef),
91 [ELF_T_VNEED] = MALIGN(Verneed),
92 [ELF_T_WORD] = MALIGN(Word),
93 [ELF_T_XWORD] = MALIGN64(Xword),
94 [ELF_T_GNUHASH] = MALIGN_WORD()
97 int
98 _libelf_malign(Elf_Type t, int elfclass)
100 if (t >= ELF_T_NUM || (int) t < 0)
101 return (0);
103 return (elfclass == ELFCLASS32 ? malign[t].a32 :
104 malign[t].a64);
107 #define FALIGN(A32,A64) { .a32 = (A32), .a64 = (A64) }
109 static struct align falign[ELF_T_NUM] = {
110 [ELF_T_ADDR] = FALIGN(4,8),
111 [ELF_T_BYTE] = FALIGN(1,1),
112 [ELF_T_CAP] = FALIGN(4,8),
113 [ELF_T_DYN] = FALIGN(4,8),
114 [ELF_T_EHDR] = FALIGN(4,8),
115 [ELF_T_HALF] = FALIGN(2,2),
116 [ELF_T_LWORD] = FALIGN(8,8),
117 [ELF_T_MOVE] = FALIGN(8,8),
118 [ELF_T_MOVEP] = UNSUPPORTED(),
119 [ELF_T_NOTE] = FALIGN(4,4),
120 [ELF_T_OFF] = FALIGN(4,8),
121 [ELF_T_PHDR] = FALIGN(4,8),
122 [ELF_T_REL] = FALIGN(4,8),
123 [ELF_T_RELA] = FALIGN(4,8),
124 [ELF_T_SHDR] = FALIGN(4,8),
125 [ELF_T_SWORD] = FALIGN(4,4),
126 [ELF_T_SXWORD] = FALIGN(0,8),
127 [ELF_T_SYM] = FALIGN(4,8),
128 [ELF_T_SYMINFO] = FALIGN(2,2),
129 [ELF_T_VDEF] = FALIGN(4,4),
130 [ELF_T_VNEED] = FALIGN(4,4),
131 [ELF_T_WORD] = FALIGN(4,4),
132 [ELF_T_XWORD] = FALIGN(0,8),
133 [ELF_T_GNUHASH] = FALIGN(4,8)
137 _libelf_falign(Elf_Type t, int elfclass)
139 if (t >= ELF_T_NUM || (int) t < 0)
140 return (0);
142 return (elfclass == ELFCLASS32 ? falign[t].a32 :
143 falign[t].a64);