···11+/*
22+ * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
33+ *
44+ * @APPLE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. Please obtain a copy of the License at
1010+ * http://www.opensource.apple.com/apsl/ and read it before using this
1111+ * file.
1212+ *
1313+ * The Original Code and all software distributed under the License are
1414+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1515+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
1616+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
1717+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
1818+ * Please see the License for the specific language governing rights and
1919+ * limitations under the License.
2020+ *
2121+ * @APPLE_LICENSE_HEADER_END@
2222+ */
2323+#ifndef _MACHO_NLIST_H_
2424+#define _MACHO_NLIST_H_
2525+/* $NetBSD: nlist.h,v 1.5 1994/10/26 00:56:11 cgd Exp $ */
2626+2727+/*-
2828+ * Copyright (c) 1991, 1993
2929+ * The Regents of the University of California. All rights reserved.
3030+ * (c) UNIX System Laboratories, Inc.
3131+ * All or some portions of this file are derived from material licensed
3232+ * to the University of California by American Telephone and Telegraph
3333+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
3434+ * the permission of UNIX System Laboratories, Inc.
3535+ *
3636+ * Redistribution and use in source and binary forms, with or without
3737+ * modification, are permitted provided that the following conditions
3838+ * are met:
3939+ * 1. Redistributions of source code must retain the above copyright
4040+ * notice, this list of conditions and the following disclaimer.
4141+ * 2. Redistributions in binary form must reproduce the above copyright
4242+ * notice, this list of conditions and the following disclaimer in the
4343+ * documentation and/or other materials provided with the distribution.
4444+ * 3. All advertising materials mentioning features or use of this software
4545+ * must display the following acknowledgement:
4646+ * This product includes software developed by the University of
4747+ * California, Berkeley and its contributors.
4848+ * 4. Neither the name of the University nor the names of its contributors
4949+ * may be used to endorse or promote products derived from this software
5050+ * without specific prior written permission.
5151+ *
5252+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5353+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5454+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5555+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5656+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5757+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5858+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5959+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6060+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6161+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6262+ * SUCH DAMAGE.
6363+ *
6464+ * @(#)nlist.h 8.2 (Berkeley) 1/21/94
6565+ */
6666+#include <stdint.h>
6767+6868+/*
6969+ * Format of a symbol table entry of a Mach-O file for 32-bit architectures.
7070+ * Modified from the BSD format. The modifications from the original format
7171+ * were changing n_other (an unused field) to n_sect and the addition of the
7272+ * N_SECT type. These modifications are required to support symbols in a larger
7373+ * number of sections not just the three sections (text, data and bss) in a BSD
7474+ * file.
7575+ */
7676+struct nlist {
7777+ union {
7878+#ifndef __LP64__
7979+ char *n_name; /* for use when in-core */
8080+#endif
8181+ uint32_t n_strx; /* index into the string table */
8282+ } n_un;
8383+ uint8_t n_type; /* type flag, see below */
8484+ uint8_t n_sect; /* section number or NO_SECT */
8585+ int16_t n_desc; /* see <mach-o/stab.h> */
8686+ uint32_t n_value; /* value of this symbol (or stab offset) */
8787+};
8888+8989+/*
9090+ * This is the symbol table entry structure for 64-bit architectures.
9191+ */
9292+struct nlist_64 {
9393+ union {
9494+ uint32_t n_strx; /* index into the string table */
9595+ } n_un;
9696+ uint8_t n_type; /* type flag, see below */
9797+ uint8_t n_sect; /* section number or NO_SECT */
9898+ uint16_t n_desc; /* see <mach-o/stab.h> */
9999+ uint64_t n_value; /* value of this symbol (or stab offset) */
100100+};
101101+102102+/*
103103+ * Symbols with a index into the string table of zero (n_un.n_strx == 0) are
104104+ * defined to have a null, "", name. Therefore all string indexes to non null
105105+ * names must not have a zero string index. This is bit historical information
106106+ * that has never been well documented.
107107+ */
108108+109109+/*
110110+ * The n_type field really contains four fields:
111111+ * unsigned char N_STAB:3,
112112+ * N_PEXT:1,
113113+ * N_TYPE:3,
114114+ * N_EXT:1;
115115+ * which are used via the following masks.
116116+ */
117117+#define N_STAB 0xe0 /* if any of these bits set, a symbolic debugging entry */
118118+#define N_PEXT 0x10 /* private external symbol bit */
119119+#define N_TYPE 0x0e /* mask for the type bits */
120120+#define N_EXT 0x01 /* external symbol bit, set for external symbols */
121121+122122+/*
123123+ * Only symbolic debugging entries have some of the N_STAB bits set and if any
124124+ * of these bits are set then it is a symbolic debugging entry (a stab). In
125125+ * which case then the values of the n_type field (the entire field) are given
126126+ * in <mach-o/stab.h>
127127+ */
128128+129129+/*
130130+ * Values for N_TYPE bits of the n_type field.
131131+ */
132132+#define N_UNDF 0x0 /* undefined, n_sect == NO_SECT */
133133+#define N_ABS 0x2 /* absolute, n_sect == NO_SECT */
134134+#define N_SECT 0xe /* defined in section number n_sect */
135135+#define N_PBUD 0xc /* prebound undefined (defined in a dylib) */
136136+#define N_INDR 0xa /* indirect */
137137+138138+/*
139139+ * If the type is N_INDR then the symbol is defined to be the same as another
140140+ * symbol. In this case the n_value field is an index into the string table
141141+ * of the other symbol's name. When the other symbol is defined then they both
142142+ * take on the defined type and value.
143143+ */
144144+145145+/*
146146+ * If the type is N_SECT then the n_sect field contains an ordinal of the
147147+ * section the symbol is defined in. The sections are numbered from 1 and
148148+ * refer to sections in order they appear in the load commands for the file
149149+ * they are in. This means the same ordinal may very well refer to different
150150+ * sections in different files.
151151+ *
152152+ * The n_value field for all symbol table entries (including N_STAB's) gets
153153+ * updated by the link editor based on the value of it's n_sect field and where
154154+ * the section n_sect references gets relocated. If the value of the n_sect
155155+ * field is NO_SECT then it's n_value field is not changed by the link editor.
156156+ */
157157+#define NO_SECT 0 /* symbol is not in any section */
158158+#define MAX_SECT 255 /* 1 thru 255 inclusive */
159159+160160+/*
161161+ * Common symbols are represented by undefined (N_UNDF) external (N_EXT) types
162162+ * who's values (n_value) are non-zero. In which case the value of the n_value
163163+ * field is the size (in bytes) of the common symbol. The n_sect field is set
164164+ * to NO_SECT. The alignment of a common symbol may be set as a power of 2
165165+ * between 2^1 and 2^15 as part of the n_desc field using the macros below. If
166166+ * the alignment is not set (a value of zero) then natural alignment based on
167167+ * the size is used.
168168+ */
169169+#define GET_COMM_ALIGN(n_desc) (((n_desc) >> 8) & 0x0f)
170170+#define SET_COMM_ALIGN(n_desc,align) \
171171+ (n_desc) = (((n_desc) & 0xf0ff) | (((align) & 0x0f) << 8))
172172+173173+/*
174174+ * To support the lazy binding of undefined symbols in the dynamic link-editor,
175175+ * the undefined symbols in the symbol table (the nlist structures) are marked
176176+ * with the indication if the undefined reference is a lazy reference or
177177+ * non-lazy reference. If both a non-lazy reference and a lazy reference is
178178+ * made to the same symbol the non-lazy reference takes precedence. A reference
179179+ * is lazy only when all references to that symbol are made through a symbol
180180+ * pointer in a lazy symbol pointer section.
181181+ *
182182+ * The implementation of marking nlist structures in the symbol table for
183183+ * undefined symbols will be to use some of the bits of the n_desc field as a
184184+ * reference type. The mask REFERENCE_TYPE will be applied to the n_desc field
185185+ * of an nlist structure for an undefined symbol to determine the type of
186186+ * undefined reference (lazy or non-lazy).
187187+ *
188188+ * The constants for the REFERENCE FLAGS are propagated to the reference table
189189+ * in a shared library file. In that case the constant for a defined symbol,
190190+ * REFERENCE_FLAG_DEFINED, is also used.
191191+ */
192192+/* Reference type bits of the n_desc field of undefined symbols */
193193+#define REFERENCE_TYPE 0x7
194194+/* types of references */
195195+#define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0
196196+#define REFERENCE_FLAG_UNDEFINED_LAZY 1
197197+#define REFERENCE_FLAG_DEFINED 2
198198+#define REFERENCE_FLAG_PRIVATE_DEFINED 3
199199+#define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4
200200+#define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5
201201+202202+/*
203203+ * To simplify stripping of objects that use are used with the dynamic link
204204+ * editor, the static link editor marks the symbols defined an object that are
205205+ * referenced by a dynamicly bound object (dynamic shared libraries, bundles).
206206+ * With this marking strip knows not to strip these symbols.
207207+ */
208208+#define REFERENCED_DYNAMICALLY 0x0010
209209+210210+/*
211211+ * For images created by the static link editor with the -twolevel_namespace
212212+ * option in effect the flags field of the mach header is marked with
213213+ * MH_TWOLEVEL. And the binding of the undefined references of the image are
214214+ * determined by the static link editor. Which library an undefined symbol is
215215+ * bound to is recorded by the static linker in the high 8 bits of the n_desc
216216+ * field using the SET_LIBRARY_ORDINAL macro below. The ordinal recorded
217217+ * references the libraries listed in the Mach-O's LC_LOAD_DYLIB,
218218+ * LC_LOAD_WEAK_DYLIB, LC_REEXPORT_DYLIB, LC_LOAD_UPWARD_DYLIB, and
219219+ * LC_LAZY_LOAD_DYLIB, etc. load commands in the order they appear in the
220220+ * headers. The library ordinals start from 1.
221221+ * For a dynamic library that is built as a two-level namespace image the
222222+ * undefined references from module defined in another use the same nlist struct
223223+ * an in that case SELF_LIBRARY_ORDINAL is used as the library ordinal. For
224224+ * defined symbols in all images they also must have the library ordinal set to
225225+ * SELF_LIBRARY_ORDINAL. The EXECUTABLE_ORDINAL refers to the executable
226226+ * image for references from plugins that refer to the executable that loads
227227+ * them.
228228+ *
229229+ * The DYNAMIC_LOOKUP_ORDINAL is for undefined symbols in a two-level namespace
230230+ * image that are looked up by the dynamic linker with flat namespace semantics.
231231+ * This ordinal was added as a feature in Mac OS X 10.3 by reducing the
232232+ * value of MAX_LIBRARY_ORDINAL by one. So it is legal for existing binaries
233233+ * or binaries built with older tools to have 0xfe (254) dynamic libraries. In
234234+ * this case the ordinal value 0xfe (254) must be treated as a library ordinal
235235+ * for compatibility.
236236+ */
237237+#define GET_LIBRARY_ORDINAL(n_desc) (((n_desc) >> 8) & 0xff)
238238+#define SET_LIBRARY_ORDINAL(n_desc,ordinal) \
239239+ (n_desc) = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8))
240240+#define SELF_LIBRARY_ORDINAL 0x0
241241+#define MAX_LIBRARY_ORDINAL 0xfd
242242+#define DYNAMIC_LOOKUP_ORDINAL 0xfe
243243+#define EXECUTABLE_ORDINAL 0xff
244244+245245+/*
246246+ * The bit 0x0020 of the n_desc field is used for two non-overlapping purposes
247247+ * and has two different symbolic names, N_NO_DEAD_STRIP and N_DESC_DISCARDED.
248248+ */
249249+250250+/*
251251+ * The N_NO_DEAD_STRIP bit of the n_desc field only ever appears in a
252252+ * relocatable .o file (MH_OBJECT filetype). And is used to indicate to the
253253+ * static link editor it is never to dead strip the symbol.
254254+ */
255255+#define N_NO_DEAD_STRIP 0x0020 /* symbol is not to be dead stripped */
256256+257257+/*
258258+ * The N_DESC_DISCARDED bit of the n_desc field never appears in linked image.
259259+ * But is used in very rare cases by the dynamic link editor to mark an in
260260+ * memory symbol as discared and longer used for linking.
261261+ */
262262+#define N_DESC_DISCARDED 0x0020 /* symbol is discarded */
263263+264264+/*
265265+ * The N_WEAK_REF bit of the n_desc field indicates to the dynamic linker that
266266+ * the undefined symbol is allowed to be missing and is to have the address of
267267+ * zero when missing.
268268+ */
269269+#define N_WEAK_REF 0x0040 /* symbol is weak referenced */
270270+271271+/*
272272+ * The N_WEAK_DEF bit of the n_desc field indicates to the static and dynamic
273273+ * linkers that the symbol definition is weak, allowing a non-weak symbol to
274274+ * also be used which causes the weak definition to be discared. Currently this
275275+ * is only supported for symbols in coalesed sections.
276276+ */
277277+#define N_WEAK_DEF 0x0080 /* coalesed symbol is a weak definition */
278278+279279+/*
280280+ * The N_REF_TO_WEAK bit of the n_desc field indicates to the dynamic linker
281281+ * that the undefined symbol should be resolved using flat namespace searching.
282282+ */
283283+#define N_REF_TO_WEAK 0x0080 /* reference to a weak symbol */
284284+285285+/*
286286+ * The N_ARM_THUMB_DEF bit of the n_desc field indicates that the symbol is
287287+ * a defintion of a Thumb function.
288288+ */
289289+#define N_ARM_THUMB_DEF 0x0008 /* symbol is a Thumb function (ARM) */
290290+291291+/*
292292+ * The N_SYMBOL_RESOLVER bit of the n_desc field indicates that the
293293+ * that the function is actually a resolver function and should
294294+ * be called to get the address of the real function to use.
295295+ * This bit is only available in .o files (MH_OBJECT filetype)
296296+ */
297297+#define N_SYMBOL_RESOLVER 0x0100
298298+299299+#ifndef __STRICT_BSD__
300300+#if __cplusplus
301301+extern "C" {
302302+#endif /* __cplusplus */
303303+/*
304304+ * The function nlist(3) from the C library.
305305+ */
306306+extern int nlist (const char *filename, struct nlist *list);
307307+#if __cplusplus
308308+}
309309+#endif /* __cplusplus */
310310+#endif /* __STRICT_BSD__ */
311311+312312+#endif /* _MACHO_LIST_H_ */
···88const char* locale_charset();
99int __darwin_sigsetjmp(sigjmp_buf b, int savesigs);
10101111+// atexit() is strange, it seems to be always inlined and cannot be resolved with dlsym()
1212+int __darwin_atexit(void (*function)(void));
1313+1114}
12151316#endif