2 * Copyright (c) 2007-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@
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_relocator KXLDRelocator
;
43 typedef struct kxld_reloc KXLDReloc
;
45 typedef boolean_t (*RelocHasPair
)(u_int r_type
);
46 typedef boolean_t (*RelocIsPair
)(u_int r_type
, u_int prev_r_type
);
47 typedef boolean_t (*RelocHasGot
)(u_int r_type
);
48 typedef kern_return_t(*ProcessReloc
)(u_char
*instruction
, u_int length
, u_int pcrel
,
49 kxld_addr_t base_pc
, kxld_addr_t link_pc
, kxld_addr_t link_disp
, u_int type
,
50 kxld_addr_t target
, kxld_addr_t pair_target
, boolean_t swap
);
52 struct kxld_relocator
{
53 RelocHasPair reloc_has_pair
;
54 RelocIsPair reloc_is_pair
;
55 RelocHasGot reloc_has_got
;
56 ProcessReloc process_reloc
;
66 u_int pair_target_type
:3;
76 struct relocation_info
;
78 /*******************************************************************************
79 * Constructors and Destructors
80 *******************************************************************************/
82 kern_return_t
kxld_relocator_init(KXLDRelocator
*relocator
, cpu_type_t cputype
,
83 cpu_subtype_t cpusubtype
, boolean_t swap
)
84 __attribute__((nonnull
,visibility("hidden")));
86 kern_return_t
kxld_reloc_create_macho(struct kxld_array
*relocarray
,
87 const KXLDRelocator
*relocator
, const struct relocation_info
*srcs
,
88 u_int nsrcs
) __attribute__((nonnull
, visibility("hidden")));
90 void kxld_relocator_clear(KXLDRelocator
*relocator
)
91 __attribute__((nonnull
, visibility("hidden")));
93 /*******************************************************************************
95 *******************************************************************************/
97 boolean_t
kxld_relocator_has_pair(const KXLDRelocator
*relocator
, u_int r_type
)
98 __attribute__((pure
, nonnull
,visibility("hidden")));
100 boolean_t
kxld_relocator_is_pair(const KXLDRelocator
*relocator
, u_int r_type
,
102 __attribute__((pure
, nonnull
,visibility("hidden")));
104 boolean_t
kxld_relocator_has_got(const KXLDRelocator
*relocator
, u_int r_type
)
105 __attribute__((pure
, nonnull
,visibility("hidden")));
107 struct kxld_sym
* kxld_reloc_get_symbol(const KXLDRelocator
*relocator
,
108 const KXLDReloc
*reloc
, u_char
*data
,
109 const struct kxld_symtab
*symtab
)
110 __attribute__((pure
, nonnull(1,2,4), visibility("hidden")));
112 kern_return_t
kxld_reloc_get_reloc_index_by_offset(const struct kxld_array
*relocs
,
113 kxld_size_t offset
, u_int
*idx
)
114 __attribute__((nonnull
, visibility("hidden")));
116 KXLDReloc
* kxld_reloc_get_reloc_by_offset(const struct kxld_array
*relocs
,
118 __attribute__((pure
, nonnull
, visibility("hidden")));
120 /*******************************************************************************
122 *******************************************************************************/
124 kern_return_t
kxld_reloc_update_symindex(KXLDReloc
*reloc
, u_int symindex
)
125 __attribute__((nonnull
,visibility("hidden")));
127 kern_return_t
kxld_relocator_process_sect_reloc(const KXLDRelocator
*relocator
,
128 const KXLDReloc
*reloc
, const struct kxld_sect
*sect
,
129 const struct kxld_array
*sectarray
, const struct kxld_symtab
*symtab
)
130 __attribute__((nonnull
,visibility("hidden")));
132 kern_return_t
kxld_relocator_process_table_reloc(const KXLDRelocator
*relocator
,
133 const KXLDReloc
*reloc
, const struct kxld_seg
*seg
, u_char
*file
,
134 const struct kxld_array
*sectarray
,
135 const struct kxld_symtab
*symtab
)
136 __attribute__((nonnull
,visibility("hidden")));
138 #endif /* _KXLD_RELOC_H */