2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef _KXLD_SYMBOL_H_
29 #define _KXLD_SYMBOL_H_
31 #include <mach/machine.h>
32 #include <sys/types.h>
34 #include <libkern/kxld_types.h>
36 #include "kxld_types.h"
42 typedef struct kxld_sym KXLDSym
;
43 typedef boolean_t (*KXLDSymPredicateTest
)(const KXLDSym
*sym
);
46 char *name
; // The symbol's name
47 char *alias
; // The indirect symbol's alias name
48 kxld_addr_t base_addr
; // The symbol's base address
49 kxld_addr_t link_addr
; // The relocated address
50 kxld_addr_t got_addr
; // The address of this symbol's GOT entry
53 uint8_t sectnum
; // The symbol's section number
54 uint8_t relocated_sectnum
;
55 u_int is_absolute
:1, // Set for absolute symbols
56 is_section
:1, // Set for section symbols
57 is_undefined
:1, // Set for undefined symbols
58 is_indirect
:1, // Set for indirect symbols
59 is_common
:1, // Set for common symbols
60 is_external
:1, // Set for external symbols
61 is_stab
:1, // Set for stab symbols
62 is_weak
:1, // Set for weak definition symbols
63 is_resolved
:1, // For symbols that have been resolved
64 // externally and should not be exported
65 is_obsolete
:1, // For symbols marked as obsolete
66 is_replaced
:1, // Set for symbols replaced by patching
67 is_got
:1, // Has an entry in the GOT
68 is_cxx
:1, // Set for C++ symbols
69 is_pure_virtual
:1, // Set for pure virtual symbols
70 is_class_vtable
:1, // Set for vtable symbols of classes
71 is_meta_vtable
:1, // Set for vtable symbols of MetaClasses
72 is_padslot
:1, // Set for pad slot symbols
73 is_metaclass
:1, // Set for metaclass symbols
74 is_super_metaclass_pointer
:1, // Set for super metaclass pointer syms
75 is_thumb
:1; // Set for thumb symbols (ARM only)
78 /*******************************************************************************
79 * Constructors and destructors
80 *******************************************************************************/
82 #if KXLD_USER_OR_ILP32
83 kern_return_t
kxld_sym_init_from_macho32(KXLDSym
*sym
, char *strtab
,
84 const struct nlist
*src
) __attribute__((nonnull
, visibility("hidden")));
88 kern_return_t
kxld_sym_init_from_macho64(KXLDSym
*sym
, char *strtab
,
89 const struct nlist_64
*src
) __attribute__((nonnull
, visibility("hidden")));
92 void kxld_sym_init_absolute(KXLDSym
*sym
, char *name
, kxld_addr_t link_addr
)
93 __attribute__((nonnull
, visibility("hidden")));
95 void kxld_sym_deinit(KXLDSym
*sym
)
96 __attribute__((nonnull
, visibility("hidden")));
98 void kxld_sym_destroy(KXLDSym
*sym
)
99 __attribute__((nonnull
, visibility("hidden")));
101 /*******************************************************************************
103 *******************************************************************************/
105 boolean_t
kxld_sym_is_absolute(const KXLDSym
*sym
)
106 __attribute__((pure
, nonnull
, visibility("hidden")));
108 boolean_t
kxld_sym_is_section(const KXLDSym
*sym
)
109 __attribute__((pure
, nonnull
, visibility("hidden")));
111 boolean_t
kxld_sym_is_defined(const KXLDSym
*sym
)
112 __attribute__((pure
, nonnull
, visibility("hidden")));
114 boolean_t
kxld_sym_is_defined_locally(const KXLDSym
*sym
)
115 __attribute__((pure
, nonnull
, visibility("hidden")));
117 boolean_t
kxld_sym_is_external(const KXLDSym
*sym
)
118 __attribute__((pure
, nonnull
, visibility("hidden")));
120 boolean_t
kxld_sym_is_exported(const KXLDSym
*sym
)
121 __attribute__((pure
, nonnull
, visibility("hidden")));
123 boolean_t
kxld_sym_is_undefined(const KXLDSym
*sym
)
124 __attribute__((pure
, nonnull
, visibility("hidden")));
126 boolean_t
kxld_sym_is_indirect(const KXLDSym
*sym
)
127 __attribute__((pure
, nonnull
, visibility("hidden")));
129 boolean_t
kxld_sym_is_replaced(const KXLDSym
*sym
)
130 __attribute__((pure
, nonnull
, visibility("hidden")));
132 /* We don't wrap this in KXLD_USER_OR_COMMON because even though common symbols
133 * aren't always supported, we always need to be able to detect them.
135 boolean_t
kxld_sym_is_common(const KXLDSym
*sym
)
136 __attribute__((pure
, nonnull
, visibility("hidden")));
138 boolean_t
kxld_sym_is_unresolved(const KXLDSym
*sym
)
139 __attribute__((pure
, nonnull
, visibility("hidden")));
141 boolean_t
kxld_sym_is_obsolete(const KXLDSym
*sym
)
142 __attribute__((pure
, nonnull
, visibility("hidden")));
145 boolean_t
kxld_sym_is_got(const KXLDSym
*sym
)
146 __attribute__((pure
, nonnull
, visibility("hidden")));
147 #endif /* KXLD_USER_OR_GOT */
149 boolean_t
kxld_sym_is_stab(const KXLDSym
*sym
)
150 __attribute__((pure
, nonnull
, visibility("hidden")));
152 boolean_t
kxld_sym_is_weak(const KXLDSym
*sym
)
153 __attribute__((pure
, nonnull
, visibility("hidden")));
155 boolean_t
kxld_sym_is_cxx(const KXLDSym
*sym
)
156 __attribute__((pure
, nonnull
, visibility("hidden")));
158 boolean_t
kxld_sym_is_pure_virtual(const KXLDSym
*sym
)
159 __attribute__((pure
, nonnull
, visibility("hidden")));
161 boolean_t
kxld_sym_is_vtable(const KXLDSym
*sym
)
162 __attribute__((pure
, nonnull
, visibility("hidden")));
164 boolean_t
kxld_sym_is_class_vtable(const KXLDSym
*sym
)
165 __attribute__((pure
, nonnull
, visibility("hidden")));
167 boolean_t
kxld_sym_is_metaclass_vtable(const KXLDSym
*sym
)
168 __attribute__((pure
, nonnull
, visibility("hidden")));
170 boolean_t
kxld_sym_is_padslot(const KXLDSym
*sym
)
171 __attribute__((pure
, nonnull
, visibility("hidden")));
173 boolean_t
kxld_sym_is_metaclass(const KXLDSym
*sym
)
174 __attribute__((pure
, nonnull
, visibility("hidden")));
176 boolean_t
kxld_sym_is_super_metaclass_pointer(const KXLDSym
*sym
)
177 __attribute__((pure
, nonnull
, visibility("hidden")));
179 boolean_t
kxld_sym_name_is_pure_virtual(const char *name
)
180 __attribute__((pure
, nonnull
, visibility("hidden")));
182 boolean_t
kxld_sym_name_is_padslot(const char *name
)
183 __attribute__((pure
, nonnull
, visibility("hidden")));
185 u_int
kxld_sym_get_section_offset(const KXLDSym
*sym
,
186 const struct kxld_sect
*sect
)
187 __attribute__((pure
, nonnull
, visibility("hidden")));
189 #if KXLD_USER_OR_COMMON
190 kxld_size_t
kxld_sym_get_common_size(const KXLDSym
*sym
)
191 __attribute__((pure
, nonnull
, visibility("hidden")));
193 u_int
kxld_sym_get_common_align(const KXLDSym
*sym
)
194 __attribute__((pure
, nonnull
, visibility("hidden")));
195 #endif /* KXLD_USER_OR_COMMON */
197 kern_return_t
kxld_sym_get_class_name_from_metaclass(const KXLDSym
*sym
,
198 char class_name
[], u_long class_name_len
)
199 __attribute__((nonnull
, visibility("hidden")));
201 kern_return_t
kxld_sym_get_class_name_from_super_metaclass_pointer(
202 const KXLDSym
*sym
, char class_name
[], u_long class_name_len
)
203 __attribute__((nonnull
, visibility("hidden")));
205 kern_return_t
kxld_sym_get_class_name_from_vtable(const KXLDSym
*sym
,
206 char class_name
[], u_long class_name_len
)
207 __attribute__((nonnull
, visibility("hidden")));
209 kern_return_t
kxld_sym_get_class_name_from_vtable_name(const char *vtable_name
,
210 char class_name
[], u_long class_name_len
)
211 __attribute__((nonnull
, visibility("hidden")));
213 kern_return_t
kxld_sym_get_vtable_name_from_class_name(const char *class_name
,
214 char vtable_name
[], u_long vtable_name_len
)
215 __attribute__((nonnull
, visibility("hidden")));
217 kern_return_t
kxld_sym_get_meta_vtable_name_from_class_name(const char *class_name
,
218 char meta_vtable_name
[], u_long meta_vtable_name_len
)
219 __attribute__((nonnull
, visibility("hidden")));
221 kern_return_t
kxld_sym_get_final_sym_name_from_class_name(const char *class_name
,
222 char final_sym_name
[], u_long final_sym_name_len
)
223 __attribute__((nonnull
, visibility("hidden")));
225 u_long
kxld_sym_get_function_prefix_from_class_name(const char *class_name
,
226 char function_prefix
[], u_long function_prefix_len
)
227 __attribute__((nonnull
, visibility("hidden")));
229 #if KXLD_USER_OR_ILP32
230 kern_return_t
kxld_sym_export_macho_32(const KXLDSym
*sym
, u_char
*nl
,
231 char *strtab
, u_long
*stroff
, u_long strsize
)
232 __attribute__((nonnull
, visibility("hidden")));
235 #if KXLD_USER_OR_LP64
236 kern_return_t
kxld_sym_export_macho_64(const KXLDSym
*sym
, u_char
*nl
,
237 char *strtab
, u_long
*stroff
, u_long strsize
)
238 __attribute__((nonnull
, visibility("hidden")));
241 /*******************************************************************************
243 *******************************************************************************/
245 void kxld_sym_relocate(KXLDSym
*sym
, const struct kxld_sect
*sect
)
246 __attribute__((nonnull
, visibility("hidden")));
249 void kxld_sym_set_got(KXLDSym
*sym
)
250 __attribute__((nonnull
, visibility("hidden")));
251 #endif /* KXLD_USER_OR_GOT */
253 kern_return_t
kxld_sym_resolve(KXLDSym
*sym
, const kxld_addr_t addr
)
254 __attribute__((nonnull
, visibility("hidden")));
256 #if KXLD_USER_OR_COMMON
257 kern_return_t
kxld_sym_resolve_common(KXLDSym
*sym
, u_int sectnum
,
258 kxld_addr_t base_addr
)
259 __attribute__((nonnull
, visibility("hidden")));
260 #endif /* KXLD_USER_OR_COMMON */
262 void kxld_sym_delete(KXLDSym
*sym
)
263 __attribute__((nonnull
, visibility("hidden")));
265 void kxld_sym_patch(KXLDSym
*sym
)
266 __attribute__((nonnull
, visibility("hidden")));
268 void kxld_sym_mark_private(KXLDSym
*sym
)
269 __attribute__((nonnull
, visibility("hidden")));
271 #endif /* _KXLD_SYMBOL_H_ */