@@ -268,14 +268,129 @@ typedef int vm_prot_t;
268268#define SEG_UNIXSTACK " __UNIXSTACK"
269269#define SEG_IMPORT " __IMPORT"
270270
271- // Symbol Types (N_TYPE)
272- #define N_UNDF 0x0
273- #define N_ABS 0x2
274- #define N_SECT 0xe
275- #define N_PBUD 0xc
276- #define N_INDR 0xa
277-
278- #define N_ARM_THUMB_DEF 0x0008
271+ /*
272+ * Symbols with a index into the string table of zero (n_un.n_strx == 0) are
273+ * defined to have a null, "", name. Therefore all string indexes to non null
274+ * names must not have a zero string index. This is bit historical information
275+ * that has never been well documented.
276+ */
277+
278+ /*
279+ * The n_type field really contains four fields:
280+ * unsigned char N_STAB:3,
281+ * N_PEXT:1,
282+ * N_TYPE:3,
283+ * N_EXT:1;
284+ * which are used via the following masks.
285+ */
286+ #define N_STAB 0xe0 /* if any of these bits set, a symbolic debugging entry */
287+ #define N_PEXT 0x10 /* private external symbol bit */
288+ #define N_TYPE 0x0e /* mask for the type bits */
289+ #define N_EXT 0x01 /* external symbol bit, set for external symbols */
290+
291+ /*
292+ * Only symbolic debugging entries have some of the N_STAB bits set and if any
293+ * of these bits are set then it is a symbolic debugging entry (a stab). In
294+ * which case then the values of the n_type field (the entire field) are given
295+ * in <mach-o/stab.h>
296+ */
297+
298+ /*
299+ * Values for N_TYPE bits of the n_type field.
300+ */
301+ #define N_UNDF 0x0 /* undefined, n_sect == NO_SECT */
302+ #define N_ABS 0x2 /* absolute, n_sect == NO_SECT */
303+ #define N_SECT 0xe /* defined in section number n_sect */
304+ #define N_PBUD 0xc /* prebound undefined (defined in a dylib) */
305+ #define N_INDR 0xa /* indirect */
306+
307+ /*
308+ * If the type is N_INDR then the symbol is defined to be the same as another
309+ * symbol. In this case the n_value field is an index into the string table
310+ * of the other symbol's name. When the other symbol is defined then they both
311+ * take on the defined type and value.
312+ */
313+
314+ /*
315+ * If the type is N_SECT then the n_sect field contains an ordinal of the
316+ * section the symbol is defined in. The sections are numbered from 1 and
317+ * refer to sections in order they appear in the load commands for the file
318+ * they are in. This means the same ordinal may very well refer to different
319+ * sections in different files.
320+ *
321+ * The n_value field for all symbol table entries (including N_STAB's) gets
322+ * updated by the link editor based on the value of it's n_sect field and where
323+ * the section n_sect references gets relocated. If the value of the n_sect
324+ * field is NO_SECT then it's n_value field is not changed by the link editor.
325+ */
326+ #define NO_SECT 0 /* symbol is not in any section */
327+ #define MAX_SECT 255 /* 1 thru 255 inclusive */
328+
329+ /*
330+ * The bit 0x0020 of the n_desc field is used for two non-overlapping purposes
331+ * and has two different symbolic names, N_NO_DEAD_STRIP and N_DESC_DISCARDED.
332+ */
333+
334+ /*
335+ * The N_NO_DEAD_STRIP bit of the n_desc field only ever appears in a
336+ * relocatable .o file (MH_OBJECT filetype). And is used to indicate to the
337+ * static link editor it is never to dead strip the symbol.
338+ */
339+ #define N_NO_DEAD_STRIP 0x0020 /* symbol is not to be dead stripped */
340+
341+ /*
342+ * The N_DESC_DISCARDED bit of the n_desc field never appears in linked image.
343+ * But is used in very rare cases by the dynamic link editor to mark an in
344+ * memory symbol as discared and longer used for linking.
345+ */
346+ #define N_DESC_DISCARDED 0x0020 /* symbol is discarded */
347+
348+ /*
349+ * The N_WEAK_REF bit of the n_desc field indicates to the dynamic linker that
350+ * the undefined symbol is allowed to be missing and is to have the address of
351+ * zero when missing.
352+ */
353+ #define N_WEAK_REF 0x0040 /* symbol is weak referenced */
354+
355+ /*
356+ * The N_WEAK_DEF bit of the n_desc field indicates to the static and dynamic
357+ * linkers that the symbol definition is weak, allowing a non-weak symbol to
358+ * also be used which causes the weak definition to be discared. Currently this
359+ * is only supported for symbols in coalesed sections.
360+ */
361+ #define N_WEAK_DEF 0x0080 /* coalesed symbol is a weak definition */
362+
363+ /*
364+ * The N_REF_TO_WEAK bit of the n_desc field indicates to the dynamic linker
365+ * that the undefined symbol should be resolved using flat namespace searching.
366+ */
367+ #define N_REF_TO_WEAK 0x0080 /* reference to a weak symbol */
368+
369+ /*
370+ * The N_ARM_THUMB_DEF bit of the n_desc field indicates that the symbol is
371+ * a defintion of a Thumb function.
372+ */
373+ #define N_ARM_THUMB_DEF 0x0008 /* symbol is a Thumb function (ARM) */
374+
375+ /*
376+ * The N_SYMBOL_RESOLVER bit of the n_desc field indicates that the
377+ * that the function is actually a resolver function and should
378+ * be called to get the address of the real function to use.
379+ * This bit is only available in .o files (MH_OBJECT filetype)
380+ */
381+ #define N_SYMBOL_RESOLVER 0x0100
382+
383+ /*
384+ * The N_ALT_ENTRY bit of the n_desc field indicates that the
385+ * symbol is pinned to the previous content.
386+ */
387+ #define N_ALT_ENTRY 0x0200
388+
389+ /*
390+ * The N_COLD_FUNC bit of the n_desc field indicates that the symbol is used
391+ * infrequently and the linker should order it towards the end of the section.
392+ */
393+ #define N_COLD_FUNC 0x0400
279394
280395/*
281396 * An indirect symbol table entry is simply a 32bit index into the symbol table
0 commit comments