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