]> git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/mach-o/nlist.h
xnu-792.18.15.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / mach-o / nlist.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 #ifndef _MACHO_NLIST_H_
29 #define _MACHO_NLIST_H_
30 /* $NetBSD: nlist.h,v 1.5 1994/10/26 00:56:11 cgd Exp $ */
31
32 /*-
33 * Copyright (c) 1991, 1993
34 * The Regents of the University of California. All rights reserved.
35 * (c) UNIX System Laboratories, Inc.
36 * All or some portions of this file are derived from material licensed
37 * to the University of California by American Telephone and Telegraph
38 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
39 * the permission of UNIX System Laboratories, Inc.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed by the University of
52 * California, Berkeley and its contributors.
53 * 4. Neither the name of the University nor the names of its contributors
54 * may be used to endorse or promote products derived from this software
55 * without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 * SUCH DAMAGE.
68 *
69 * @(#)nlist.h 8.2 (Berkeley) 1/21/94
70 */
71
72 /*
73 * Format of a symbol table entry of a Mach-O file. Modified from the BSD
74 * format. The modifications from the original format were changing n_other
75 * (an unused field) to n_sect and the addition of the N_SECT type. These
76 * modifications are required to support symbols in an arbitrary number of
77 * sections not just the three sections (text, data and bss) in a BSD file.
78 */
79 struct nlist {
80 union {
81 char *n_name; /* for use when in-core */
82 long n_strx; /* index into the string table */
83 } n_un;
84 unsigned char n_type; /* type flag, see below */
85 unsigned char n_sect; /* section number or NO_SECT */
86 short n_desc; /* see <mach-o/stab.h> */
87 unsigned long n_value; /* value of this symbol (or stab offset) */
88 };
89
90 /*
91 * This is the symbol table entry structure for 64-bit architectures.
92 */
93 struct nlist_64 {
94 union {
95 uint32_t n_strx; /* index into the string table */
96 } n_un;
97 uint8_t n_type; /* type flag, see below */
98 uint8_t n_sect; /* section number or NO_SECT */
99 uint16_t n_desc; /* see <mach-o/stab.h> */
100 uint64_t n_value; /* value of this symbol (or stab offset) */
101 };
102
103
104 /*
105 * Symbols with a index into the string table of zero (n_un.n_strx == 0) are
106 * defined to have a null, "", name. Therefore all string indexes to non null
107 * names must not have a zero string index. This is bit historical information
108 * that has never been well documented.
109 */
110
111 /*
112 * The n_type field really contains three fields:
113 * unsigned char N_STAB:3,
114 * N_PEXT:1,
115 * N_TYPE:3,
116 * N_EXT:1;
117 * which are used via the following masks.
118 */
119 #define N_STAB 0xe0 /* if any of these bits set, a symbolic debugging entry */
120 #define N_PEXT 0x10 /* private external symbol bit */
121 #define N_TYPE 0x0e /* mask for the type bits */
122 #define N_EXT 0x01 /* external symbol bit, set for external symbols */
123
124 /*
125 * Only symbolic debugging entries have some of the N_STAB bits set and if any
126 * of these bits are set then it is a symbolic debugging entry (a stab). In
127 * which case then the values of the n_type field (the entire field) are given
128 * in <mach-o/stab.h>
129 */
130
131 /*
132 * Values for N_TYPE bits of the n_type field.
133 */
134 #define N_UNDF 0x0 /* undefined, n_sect == NO_SECT */
135 #define N_ABS 0x2 /* absolute, n_sect == NO_SECT */
136 #define N_SECT 0xe /* defined in section number n_sect */
137 #define N_PBUD 0xc /* prebound undefined (defined in a dylib) */
138 #define N_INDR 0xa /* indirect */
139
140 /*
141 * If the type is N_INDR then the symbol is defined to be the same as another
142 * symbol. In this case the n_value field is an index into the string table
143 * of the other symbol's name. When the other symbol is defined then they both
144 * take on the defined type and value.
145 */
146
147 /*
148 * If the type is N_SECT then the n_sect field contains an ordinal of the
149 * section the symbol is defined in. The sections are numbered from 1 and
150 * refer to sections in order they appear in the load commands for the file
151 * they are in. This means the same ordinal may very well refer to different
152 * sections in different files.
153 *
154 * The n_value field for all symbol table entries (including N_STAB's) gets
155 * updated by the link editor based on the value of it's n_sect field and where
156 * the section n_sect references gets relocated. If the value of the n_sect
157 * field is NO_SECT then it's n_value field is not changed by the link editor.
158 */
159 #define NO_SECT 0 /* symbol is not in any section */
160 #define MAX_SECT 255 /* 1 thru 255 inclusive */
161
162 /*
163 * Common symbols are represented by undefined (N_UNDF) external (N_EXT) types
164 * who's values (n_value) are non-zero. In which case the value of the n_value
165 * field is the size (in bytes) of the common symbol. The n_sect field is set
166 * to NO_SECT.
167 */
168
169 /*
170 * To support the lazy binding of undefined symbols in the dynamic link-editor,
171 * the undefined symbols in the symbol table (the nlist structures) are marked
172 * with the indication if the undefined reference is a lazy reference or
173 * non-lazy reference. If both a non-lazy reference and a lazy reference is
174 * made to the same symbol the non-lazy reference takes precedence. A reference
175 * is lazy only when all references to that symbol are made through a symbol
176 * pointer in a lazy symbol pointer section.
177 *
178 * The implementation of marking nlist structures in the symbol table for
179 * undefined symbols will be to use some of the bits of the n_desc field as a
180 * reference type. The mask REFERENCE_TYPE will be applied to the n_desc field
181 * of an nlist structure for an undefined symbol to determine the type of
182 * undefined reference (lazy or non-lazy).
183 *
184 * The constants for the REFERENCE FLAGS are propagated to the reference table
185 * in a shared library file. In that case the constant for a defined symbol,
186 * REFERENCE_FLAG_DEFINED, is also used.
187 */
188 /* Reference type bits of the n_desc field of undefined symbols */
189 #define REFERENCE_TYPE 0xf
190 /* types of references */
191 #define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0
192 #define REFERENCE_FLAG_UNDEFINED_LAZY 1
193 #define REFERENCE_FLAG_DEFINED 2
194 #define REFERENCE_FLAG_PRIVATE_DEFINED 3
195 #define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4
196 #define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5
197
198 /*
199 * To simplify stripping of objects that use are used with the dynamic link
200 * editor, the static link editor marks the symbols defined an object that are
201 * referenced by a dynamicly bound object (dynamic shared libraries, bundles).
202 * With this marking strip knows not to strip these symbols.
203 */
204 #define REFERENCED_DYNAMICALLY 0x0010
205
206 /*
207 * The non-reference type bits of the n_desc field for global symbols are
208 * reserved for the dynamic link editor. All of these bits must start out
209 * zero in the object file.
210 */
211 #define N_DESC_DISCARDED 0x8000 /* symbol is discarded */
212
213 #endif