]>
Commit | Line | Data |
---|---|---|
0b4e3aa0 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 A |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
7 | * | |
8 | * This file contains Original Code and/or Modifications of Original Code | |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
0b4e3aa0 A |
14 | * |
15 | * The Original Code and all software distributed under the License are | |
43866e37 | 16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
0b4e3aa0 A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
0b4e3aa0 A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* $NetBSD: exec.h,v 1.6 1994/10/27 04:16:05 cgd Exp $ */ | |
26 | ||
27 | /* | |
28 | * Copyright (c) 1993 Christopher G. Demetriou | |
29 | * All rights reserved. | |
30 | * | |
31 | * Redistribution and use in source and binary forms, with or without | |
32 | * modification, are permitted provided that the following conditions | |
33 | * are met: | |
34 | * 1. Redistributions of source code must retain the above copyright | |
35 | * notice, this list of conditions and the following disclaimer. | |
36 | * 2. Redistributions in binary form must reproduce the above copyright | |
37 | * notice, this list of conditions and the following disclaimer in the | |
38 | * documentation and/or other materials provided with the distribution. | |
39 | * 3. The name of the author may not be used to endorse or promote products | |
40 | * derived from this software without specific prior written permission | |
41 | * | |
42 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
43 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
44 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
45 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
46 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
47 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
48 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
49 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
50 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
51 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
52 | */ | |
53 | ||
54 | #ifndef _MACHO_RELOC_H_ | |
55 | #define _MACHO_RELOC_H_ | |
56 | ||
57 | /* | |
58 | * Format of a relocation entry of a Mach-O file. Modified from the 4.3BSD | |
59 | * format. The modifications from the original format were changing the value | |
60 | * of the r_symbolnum field for "local" (r_extern == 0) relocation entries. | |
61 | * This modification is required to support symbols in an arbitrary number of | |
62 | * sections not just the three sections (text, data and bss) in a 4.3BSD file. | |
63 | * Also the last 4 bits have had the r_type tag added to them. | |
64 | */ | |
65 | struct relocation_info { | |
66 | long r_address; /* offset in the section to what is being | |
67 | relocated */ | |
68 | unsigned int r_symbolnum:24, /* symbol index if r_extern == 1 or section | |
69 | ordinal if r_extern == 0 */ | |
70 | r_pcrel:1, /* was relocated pc relative already */ | |
71 | r_length:2, /* 0=byte, 1=word, 2=long */ | |
72 | r_extern:1, /* does not include value of sym referenced */ | |
73 | r_type:4; /* if not 0, machine specific relocation type */ | |
74 | }; | |
75 | #define R_ABS 0 /* absolute relocation type for Mach-O files */ | |
76 | ||
77 | /* | |
78 | * The r_address is not really the address as it's name indicates but an offset. | |
79 | * In 4.3BSD a.out objects this offset is from the start of the "segment" for | |
80 | * which relocation entry is for (text or data). For Mach-O object files it is | |
81 | * also an offset but from the start of the "section" for which the relocation | |
82 | * entry is for. See comments in <mach-o/loader.h> about the r_address feild | |
83 | * in images for used with the dynamic linker. | |
84 | * | |
85 | * In 4.3BSD a.out objects if r_extern is zero then r_symbolnum is an ordinal | |
86 | * for the segment the symbol being relocated is in. These ordinals are the | |
87 | * symbol types N_TEXT, N_DATA, N_BSS or N_ABS. In Mach-O object files these | |
88 | * ordinals refer to the sections in the object file in the order their section | |
89 | * structures appear in the headers of the object file they are in. The first | |
90 | * section has the ordinal 1, the second 2, and so on. This means that the | |
91 | * same ordinal in two different object files could refer to two different | |
92 | * sections. And further could have still different ordinals when combined | |
93 | * by the link-editor. The value R_ABS is used for relocation entries for | |
94 | * absolute symbols which need no further relocation. | |
95 | */ | |
96 | ||
97 | /* | |
98 | * For RISC machines some of the references are split across two instructions | |
99 | * and the instruction does not contain the complete value of the reference. | |
100 | * In these cases a second, or paired relocation entry, follows each of these | |
101 | * relocation entries, using a PAIR r_type, which contains the other part of the | |
102 | * reference not contained in the instruction. This other part is stored in the | |
103 | * pair's r_address field. The exact number of bits of the other part of the | |
104 | * reference store in the r_address field is dependent on the particular | |
105 | * relocation type for the particular architecture. | |
106 | */ | |
107 | ||
108 | /* | |
109 | * To make scattered loading by the link editor work correctly "local" | |
110 | * relocation entries can't be used when the item to be relocated is the value | |
111 | * of a symbol plus an offset (where the resulting expresion is outside the | |
112 | * block the link editor is moving, a blocks are divided at symbol addresses). | |
113 | * In this case. where the item is a symbol value plus offset, the link editor | |
114 | * needs to know more than just the section the symbol was defined. What is | |
115 | * needed is the actual value of the symbol without the offset so it can do the | |
116 | * relocation correctly based on where the value of the symbol got relocated to | |
117 | * not the value of the expression (with the offset added to the symbol value). | |
118 | * So for the NeXT 2.0 release no "local" relocation entries are ever used when | |
119 | * there is a non-zero offset added to a symbol. The "external" and "local" | |
120 | * relocation entries remain unchanged. | |
121 | * | |
122 | * The implemention is quite messy given the compatibility with the existing | |
123 | * relocation entry format. The ASSUMPTION is that a section will never be | |
124 | * bigger than 2**24 - 1 (0x00ffffff or 16,777,215) bytes. This assumption | |
125 | * allows the r_address (which is really an offset) to fit in 24 bits and high | |
126 | * bit of the r_address field in the relocation_info structure to indicate | |
127 | * it is really a scattered_relocation_info structure. Since these are only | |
128 | * used in places where "local" relocation entries are used and not where | |
129 | * "external" relocation entries are used the r_extern field has been removed. | |
130 | * | |
131 | * For scattered loading to work on a RISC machine where some of the references | |
132 | * are split across two instructions the link editor needs to be assured that | |
133 | * each reference has a unique 32 bit reference (that more than one reference is | |
134 | * NOT sharing the same high 16 bits for example) so it move each referenced | |
135 | * item independent of each other. Some compilers guarantees this but the | |
136 | * compilers don't so scattered loading can be done on those that do guarantee | |
137 | * this. | |
138 | */ | |
139 | #if defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__) | |
140 | /* | |
141 | * The reason for the ifdef's of __BIG_ENDIAN__ and __LITTLE_ENDIAN__ are that | |
142 | * when stattered relocation entries were added the mistake of using a mask | |
143 | * against a structure that is made up of bit fields was used. To make this | |
144 | * design work this structure must be laid out in memory the same way so the | |
145 | * mask can be applied can check the same bit each time (r_scattered). | |
146 | */ | |
147 | #endif /* defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__) */ | |
148 | #define R_SCATTERED 0x80000000 /* mask to be applied to the r_address field | |
149 | of a relocation_info structure to tell that | |
150 | is is really a scattered_relocation_info | |
151 | stucture */ | |
152 | struct scattered_relocation_info { | |
153 | #ifdef __BIG_ENDIAN__ | |
154 | unsigned int r_scattered:1, /* 1=scattered, 0=non-scattered (see above) */ | |
155 | r_pcrel:1, /* was relocated pc relative already */ | |
156 | r_length:2, /* 0=byte, 1=word, 2=long */ | |
157 | r_type:4, /* if not 0, machine specific relocation type */ | |
158 | r_address:24; /* offset in the section to what is being | |
159 | relocated */ | |
160 | long r_value; /* the value the item to be relocated is | |
161 | refering to (without any offset added) */ | |
162 | #endif /* __BIG_ENDIAN__ */ | |
163 | #ifdef __LITTLE_ENDIAN__ | |
164 | unsigned int | |
165 | r_address:24, /* offset in the section to what is being | |
166 | relocated */ | |
167 | r_type:4, /* if not 0, machine specific relocation type */ | |
168 | r_length:2, /* 0=byte, 1=word, 2=long */ | |
169 | r_pcrel:1, /* was relocated pc relative already */ | |
170 | r_scattered:1; /* 1=scattered, 0=non-scattered (see above) */ | |
171 | long r_value; /* the value the item to be relocated is | |
172 | refering to (without any offset added) */ | |
173 | #endif /* __LITTLE_ENDIAN__ */ | |
174 | }; | |
175 | ||
176 | /* | |
177 | * Relocation types used in a generic implementation. Relocation entries for | |
178 | * nornal things use the generic relocation as discribed above and their r_type | |
179 | * is GENERIC_RELOC_VANILLA (a value of zero). | |
180 | * | |
181 | * Another type of generic relocation, GENERIC_RELOC_SECTDIFF, is to support | |
182 | * the difference of two symbols defined in different sections. That is the | |
183 | * expression "symbol1 - symbol2 + constant" is a relocatable expression when | |
184 | * both symbols are defined in some section. For this type of relocation the | |
185 | * both relocations entries are scattered relocation entries. The value of | |
186 | * symbol1 is stored in the first relocation entry's r_value field and the | |
187 | * value of symbol2 is stored in the pair's r_value field. | |
188 | * | |
189 | * A special case for a prebound lazy pointer is needed to beable to set the | |
190 | * value of the lazy pointer back to its non-prebound state. This is done | |
191 | * using the GENERIC_RELOC_PB_LA_PTR r_type. This is a scattered relocation | |
192 | * entry where the r_value feild is the value of the lazy pointer not prebound. | |
193 | */ | |
194 | enum reloc_type_generic | |
195 | { | |
196 | GENERIC_RELOC_VANILLA, /* generic relocation as discribed above */ | |
197 | GENERIC_RELOC_PAIR, /* Only follows a GENRIC_RELOC_SECTDIFF */ | |
198 | GENERIC_RELOC_SECTDIFF, | |
199 | GENERIC_RELOC_PB_LA_PTR /* prebound lazy pointer */ | |
200 | }; | |
201 | ||
202 | #endif /* _MACHO_RELOC_H_ */ |