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