]>
Commit | Line | Data |
---|---|---|
a645023d A |
1 | /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*- |
2 | * | |
3 | * Copyright (c) 2009-2010 Apple Inc. All rights reserved. | |
4 | * | |
5 | * @APPLE_LICENSE_HEADER_START@ | |
6 | * | |
7 | * This file contains Original Code and/or Modifications of Original Code | |
8 | * as defined in and that are subject to the Apple Public Source License | |
9 | * Version 2.0 (the 'License'). You may not use this file except in | |
10 | * compliance with the License. Please obtain a copy of the License at | |
11 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
12 | * file. | |
13 | * | |
14 | * The Original Code and all software distributed under the License are | |
15 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
19 | * Please see the License for the specific language governing rights and | |
20 | * limitations under the License. | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | ||
25 | // already in ld::passes::stubs namespace | |
26 | namespace arm { | |
27 | ||
28 | ||
29 | class FastBindingPointerAtom : public ld::Atom { | |
30 | public: | |
31 | FastBindingPointerAtom(ld::passes::stubs::Pass& pass) | |
32 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
33 | ld::Atom::scopeLinkageUnit, ld::Atom::typeNonLazyPointer, | |
34 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
35 | _fixup(0, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressLittleEndian32, pass.internal()->compressedFastBinderProxy) | |
36 | { pass.addAtom(*this); } | |
37 | ||
38 | virtual const ld::File* file() const { return NULL; } | |
a645023d A |
39 | virtual const char* name() const { return "fast binder pointer"; } |
40 | virtual uint64_t size() const { return 4; } | |
41 | virtual uint64_t objectAddress() const { return 0; } | |
42 | virtual void copyRawContent(uint8_t buffer[]) const { } | |
43 | virtual void setScope(Scope) { } | |
44 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } | |
45 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } | |
46 | ||
47 | private: | |
48 | ld::Fixup _fixup; | |
49 | ||
50 | static ld::Section _s_section; | |
51 | }; | |
52 | ||
53 | ld::Section FastBindingPointerAtom::_s_section("__DATA", "__nl_symbol_ptr", ld::Section::typeNonLazyPointer); | |
54 | ||
55 | ||
56 | class ImageCachePointerAtom : public ld::Atom { | |
57 | public: | |
58 | ImageCachePointerAtom(ld::passes::stubs::Pass& pass) | |
59 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
60 | ld::Atom::scopeLinkageUnit, ld::Atom::typeNonLazyPointer, | |
61 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)) { pass.addAtom(*this); } | |
62 | ||
63 | virtual const ld::File* file() const { return NULL; } | |
a645023d A |
64 | virtual const char* name() const { return "non-lazy pointer"; } |
65 | virtual uint64_t size() const { return 4; } | |
66 | virtual uint64_t objectAddress() const { return 0; } | |
67 | virtual void copyRawContent(uint8_t buffer[]) const { } | |
68 | virtual void setScope(Scope) { } | |
69 | ||
70 | private: | |
71 | ||
72 | static ld::Section _s_section; | |
73 | }; | |
74 | ||
75 | ld::Section ImageCachePointerAtom::_s_section("__DATA", "__nl_symbol_ptr", ld::Section::typeNonLazyPointer); | |
76 | ||
77 | ||
78 | ||
79 | class StubHelperHelperAtom : public ld::Atom { | |
80 | public: | |
81 | StubHelperHelperAtom(ld::passes::stubs::Pass& pass) | |
82 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
83 | ld::Atom::scopeLinkageUnit, ld::Atom::typeStubHelper, | |
84 | ld::Atom::symbolTableIn, false, false, false, ld::Atom::Alignment(2)), | |
85 | _fixup1(28, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, compressedImageCache(pass)), | |
86 | _fixup2(28, ld::Fixup::k2of4, ld::Fixup::kindSubtractTargetAddress, this), | |
87 | _fixup3(28, ld::Fixup::k3of4, ld::Fixup::kindSubtractAddend, 16), | |
88 | _fixup4(28, ld::Fixup::k4of4, ld::Fixup::kindStoreLittleEndian32), | |
89 | _fixup5(32, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, compressedFastBinder(pass)), | |
90 | _fixup6(32, ld::Fixup::k2of4, ld::Fixup::kindSubtractTargetAddress, this), | |
91 | _fixup7(32, ld::Fixup::k3of4, ld::Fixup::kindSubtractAddend, 28), | |
92 | _fixup8(32, ld::Fixup::k4of4, ld::Fixup::kindStoreLittleEndian32) | |
93 | { pass.addAtom(*this); } | |
94 | ||
95 | virtual ld::File* file() const { return NULL; } | |
a645023d A |
96 | virtual const char* name() const { return " stub helpers"; } |
97 | virtual uint64_t size() const { return 36; } | |
98 | virtual uint64_t objectAddress() const { return 0; } | |
99 | virtual void copyRawContent(uint8_t buffer[]) const { | |
100 | // push lazy-info-offset | |
101 | OSWriteLittleInt32(&buffer[ 0], 0, 0xe52dc004); // str ip, [sp, #-4]! | |
102 | // push address of dyld_mageLoaderCache | |
103 | OSWriteLittleInt32(&buffer[ 4], 0, 0xe59fc010); // ldr ip, L1 | |
104 | OSWriteLittleInt32(&buffer[ 8], 0, 0xe08fc00c); // add ip, pc, ip | |
105 | OSWriteLittleInt32(&buffer[12], 0, 0xe52dc004); // str ip, [sp, #-4]! | |
106 | // jump through _fast_lazy_bind | |
107 | OSWriteLittleInt32(&buffer[16], 0, 0xe59fc008); // ldr ip, L2 | |
108 | OSWriteLittleInt32(&buffer[20], 0, 0xe08fc00c); // add ip, pc, ip | |
109 | OSWriteLittleInt32(&buffer[24], 0, 0xe59cf000); // ldr pc, [ip] | |
110 | OSWriteLittleInt32(&buffer[28], 0, 0x00000000); // L1: .long fFastStubGOTAtom - (helperhelper+16) | |
111 | OSWriteLittleInt32(&buffer[32], 0, 0x00000000); // L2: .long _fast_lazy_bind - (helperhelper+28) | |
112 | } | |
113 | virtual void setScope(Scope) { } | |
114 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } | |
115 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup8)[1]; } | |
116 | ||
117 | private: | |
118 | static ld::Atom* compressedImageCache(ld::passes::stubs::Pass& pass) { | |
119 | if ( pass.compressedImageCache == NULL ) | |
120 | pass.compressedImageCache = new ImageCachePointerAtom(pass); | |
121 | return pass.compressedImageCache; | |
122 | } | |
123 | static ld::Atom* compressedFastBinder(ld::passes::stubs::Pass& pass) { | |
124 | if ( pass.compressedFastBinderPointer == NULL ) | |
125 | pass.compressedFastBinderPointer = new FastBindingPointerAtom(pass); | |
126 | return pass.compressedFastBinderPointer; | |
127 | } | |
128 | ||
129 | ld::Fixup _fixup1; | |
130 | ld::Fixup _fixup2; | |
131 | ld::Fixup _fixup3; | |
132 | ld::Fixup _fixup4; | |
133 | ld::Fixup _fixup5; | |
134 | ld::Fixup _fixup6; | |
135 | ld::Fixup _fixup7; | |
136 | ld::Fixup _fixup8; | |
137 | ||
138 | static ld::Section _s_section; | |
139 | }; | |
140 | ||
141 | ld::Section StubHelperHelperAtom::_s_section("__TEXT", "__stub_helper", ld::Section::typeStubHelper); | |
142 | ||
143 | ||
144 | class StubHelperAtom : public ld::Atom { | |
145 | public: | |
146 | StubHelperAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo, | |
147 | const ld::Atom* lazyPointer) | |
148 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
149 | ld::Atom::scopeLinkageUnit, ld::Atom::typeStubHelper, | |
150 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
151 | _stubTo(stubTo), | |
152 | _fixup1(4, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARMBranch24, helperHelper(pass)), | |
153 | _fixup2(8, ld::Fixup::k1of2, ld::Fixup::kindSetLazyOffset, lazyPointer), | |
154 | _fixup3(8, ld::Fixup::k2of2, ld::Fixup::kindStoreLittleEndian32) { } | |
155 | ||
156 | virtual const ld::File* file() const { return _stubTo.file(); } | |
a645023d A |
157 | virtual const char* name() const { return _stubTo.name(); } |
158 | virtual uint64_t size() const { return 12; } | |
159 | virtual uint64_t objectAddress() const { return 0; } | |
160 | virtual void copyRawContent(uint8_t buffer[]) const { | |
161 | OSWriteLittleInt32(&buffer[0], 0, 0xe59fc000); // ldr ip, [pc, #0] | |
162 | OSWriteLittleInt32(&buffer[4], 0, 0xea000000); // b _helperhelper | |
163 | OSWriteLittleInt32(&buffer[8], 0, 0); // .long lazy-info-offset | |
164 | } | |
165 | virtual void setScope(Scope) { } | |
166 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } | |
167 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } | |
168 | ||
169 | private: | |
170 | static ld::Atom* helperHelper(ld::passes::stubs::Pass& pass) { | |
171 | if ( pass.compressedHelperHelper == NULL ) | |
172 | pass.compressedHelperHelper = new StubHelperHelperAtom(pass); | |
173 | return pass.compressedHelperHelper; | |
174 | } | |
175 | const ld::Atom& _stubTo; | |
176 | ld::Fixup _fixup1; | |
177 | ld::Fixup _fixup2; | |
178 | ld::Fixup _fixup3; | |
179 | ||
180 | static ld::Section _s_section; | |
181 | }; | |
182 | ||
183 | ld::Section StubHelperAtom::_s_section("__TEXT", "__stub_helper", ld::Section::typeStubHelper); | |
184 | ||
185 | ||
186 | class ResolverHelperAtom : public ld::Atom { | |
187 | public: | |
188 | ResolverHelperAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo, | |
189 | const ld::Atom* lazyPointer) | |
190 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
191 | ld::Atom::scopeLinkageUnit, ld::Atom::typeStubHelper, | |
192 | ld::Atom::symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
193 | _stubTo(stubTo), | |
194 | _fixup1( 4, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARMBranch24, &stubTo), | |
195 | _fixup2(32, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, lazyPointer), | |
196 | _fixup3(32, ld::Fixup::k2of4, ld::Fixup::kindSubtractTargetAddress, this), | |
197 | _fixup4(32, ld::Fixup::k3of4, ld::Fixup::kindSubtractAddend, 20), | |
198 | _fixup5(32, ld::Fixup::k4of4, ld::Fixup::kindStoreLittleEndian32) { } | |
199 | ||
200 | virtual const ld::File* file() const { return _stubTo.file(); } | |
a645023d A |
201 | virtual const char* name() const { return _stubTo.name(); } |
202 | virtual uint64_t size() const { return 36; } | |
203 | virtual uint64_t objectAddress() const { return 0; } | |
204 | virtual void copyRawContent(uint8_t buffer[]) const { | |
205 | OSWriteLittleInt32(&buffer[ 0], 0, 0xe92d400f); // push {r0, r1, r2, r3, lr} | |
206 | OSWriteLittleInt32(&buffer[ 4], 0, 0xebfffffd); // bl _foo | |
207 | OSWriteLittleInt32(&buffer[ 8], 0, 0xe59fc010); // ldr ip, [pc, #16] | |
208 | OSWriteLittleInt32(&buffer[12], 0, 0xe08fc00c); // add ip, pc, ip | |
209 | OSWriteLittleInt32(&buffer[16], 0, 0xe58c0000); // str r0, [ip] | |
210 | OSWriteLittleInt32(&buffer[20], 0, 0xe1a0c000); // mov ip, r0 | |
211 | OSWriteLittleInt32(&buffer[24], 0, 0xe8bd400f); // pop {r0, r1, r2, r3, lr} | |
212 | OSWriteLittleInt32(&buffer[28], 0, 0xe12fff1c); // bx ip | |
213 | OSWriteLittleInt32(&buffer[32], 0, 0x00000000); // .long foo$lazyptr - helper + 20 | |
214 | } | |
215 | virtual void setScope(Scope) { } | |
216 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } | |
217 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup5)[1]; } | |
218 | ||
219 | private: | |
220 | const ld::Atom& _stubTo; | |
221 | ld::Fixup _fixup1; | |
222 | ld::Fixup _fixup2; | |
223 | ld::Fixup _fixup3; | |
224 | ld::Fixup _fixup4; | |
225 | ld::Fixup _fixup5; | |
226 | ||
227 | static ld::Section _s_section; | |
228 | }; | |
229 | ||
230 | ld::Section ResolverHelperAtom::_s_section("__TEXT", "__stub_helper", ld::Section::typeStubHelper); | |
231 | ||
232 | ||
233 | class LazyPointerAtom : public ld::Atom { | |
234 | public: | |
235 | LazyPointerAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo, | |
236 | bool stubToGlobalWeakDef, bool stubToResolver, | |
237 | bool weakImport, bool close) | |
238 | : ld::Atom(close ? _s_sectionClose : _s_section, ld::Atom::definitionRegular, | |
239 | ld::Atom::combineNever, ld::Atom::scopeLinkageUnit, ld::Atom::typeLazyPointer, | |
240 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
241 | _stubTo(stubTo), | |
242 | _helper(pass, stubTo, this), | |
243 | _resolverHelper(pass, stubTo, this), | |
244 | _fixup1(0, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressLittleEndian32, | |
245 | stubToResolver ? &_resolverHelper : (stubToGlobalWeakDef ? &stubTo : &_helper)), | |
246 | _fixup2(0, ld::Fixup::k1of1, ld::Fixup::kindLazyTarget, &stubTo) { | |
247 | _fixup2.weakImport = weakImport; pass.addAtom(*this); | |
248 | if ( stubToResolver ) | |
249 | pass.addAtom(_resolverHelper); | |
250 | else if ( !stubToGlobalWeakDef ) | |
251 | pass.addAtom(_helper); | |
252 | } | |
253 | ||
254 | virtual const ld::File* file() const { return _stubTo.file(); } | |
a645023d A |
255 | virtual const char* name() const { return _stubTo.name(); } |
256 | virtual uint64_t size() const { return 4; } | |
257 | virtual uint64_t objectAddress() const { return 0; } | |
258 | virtual void copyRawContent(uint8_t buffer[]) const { } | |
259 | virtual void setScope(Scope) { } | |
260 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } | |
261 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } | |
262 | ||
263 | private: | |
264 | const ld::Atom& _stubTo; | |
265 | StubHelperAtom _helper; | |
266 | ResolverHelperAtom _resolverHelper; | |
267 | ld::Fixup _fixup1; | |
268 | ld::Fixup _fixup2; | |
269 | ||
270 | static ld::Section _s_section; | |
271 | static ld::Section _s_sectionClose; | |
272 | }; | |
273 | ||
274 | ld::Section LazyPointerAtom::_s_section("__DATA", "__la_symbol_ptr", ld::Section::typeLazyPointer); | |
275 | ld::Section LazyPointerAtom::_s_sectionClose("__DATA", "__lazy_symbol", ld::Section::typeLazyPointerClose); | |
276 | ||
277 | ||
ebf6f434 A |
278 | class NonLazyPointerAtom : public ld::Atom { |
279 | public: | |
280 | NonLazyPointerAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo) | |
281 | : ld::Atom(_s_section, ld::Atom::definitionRegular, | |
282 | ld::Atom::combineNever, ld::Atom::scopeLinkageUnit, ld::Atom::typeLazyPointer, | |
283 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
284 | _stubTo(stubTo), | |
285 | _fixup1(0, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressLittleEndian32, &stubTo) { | |
286 | pass.addAtom(*this); | |
287 | } | |
288 | ||
289 | virtual const ld::File* file() const { return _stubTo.file(); } | |
ebf6f434 A |
290 | virtual const char* name() const { return _stubTo.name(); } |
291 | virtual uint64_t size() const { return 4; } | |
292 | virtual uint64_t objectAddress() const { return 0; } | |
293 | virtual void copyRawContent(uint8_t buffer[]) const { } | |
294 | virtual void setScope(Scope) { } | |
295 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } | |
296 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } | |
297 | ||
298 | private: | |
299 | const ld::Atom& _stubTo; | |
300 | ld::Fixup _fixup1; | |
301 | ||
302 | static ld::Section _s_section; | |
303 | static ld::Section _s_sectionClose; | |
304 | }; | |
305 | ||
306 | ld::Section NonLazyPointerAtom::_s_section("__DATA", "__nl_symbol_ptr", ld::Section::typeNonLazyPointer); | |
307 | ||
308 | ||
309 | class StubPICKextAtom : public ld::Atom { | |
310 | public: | |
311 | StubPICKextAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo) | |
312 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
313 | ld::Atom::scopeLinkageUnit, ld::Atom::typeStub, | |
314 | symbolTableIn, false, true, false, ld::Atom::Alignment(2)), | |
315 | _stubTo(stubTo), | |
316 | _nonLazyPointer(pass, stubTo), | |
317 | _fixup1(0, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, &_nonLazyPointer), | |
318 | _fixup2(0, ld::Fixup::k2of4, ld::Fixup::kindSubtractTargetAddress, this), | |
319 | _fixup3(0, ld::Fixup::k3of4, ld::Fixup::kindSubtractAddend, 12), | |
320 | _fixup4(0, ld::Fixup::k4of4, ld::Fixup::kindStoreThumbLow16), | |
321 | _fixup5(4, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, &_nonLazyPointer), | |
322 | _fixup6(4, ld::Fixup::k2of4, ld::Fixup::kindSubtractTargetAddress, this), | |
323 | _fixup7(4, ld::Fixup::k3of4, ld::Fixup::kindSubtractAddend, 12), | |
324 | _fixup8(4, ld::Fixup::k4of4, ld::Fixup::kindStoreThumbHigh16) { | |
325 | pass.addAtom(*this); | |
326 | asprintf((char**)&_name, "%s.stub", _stubTo.name()); | |
327 | } | |
328 | ||
329 | virtual const ld::File* file() const { return _stubTo.file(); } | |
ebf6f434 A |
330 | virtual const char* name() const { return _name; } |
331 | virtual uint64_t size() const { return 16; } | |
332 | virtual uint64_t objectAddress() const { return 0; } | |
333 | virtual void copyRawContent(uint8_t buffer[]) const { | |
334 | OSWriteLittleInt32(&buffer[ 0], 0, 0x0c00f240); // movw ip, #lo(nlp - L1) | |
335 | OSWriteLittleInt32(&buffer[ 4], 0, 0x0c00f2c0); // movt ip, #hi(nlp - L1) | |
336 | OSWriteLittleInt16(&buffer[ 8], 0, 0x44fc); // add ip, pc | |
337 | OSWriteLittleInt32(&buffer[10], 0, 0xc000f8dc); // ldr.w ip, [ip] | |
338 | OSWriteLittleInt16(&buffer[14], 0, 0x4760); // bx ip | |
339 | } | |
340 | virtual void setScope(Scope) { } | |
341 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } | |
342 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup8)[1]; } | |
343 | ||
344 | private: | |
345 | const ld::Atom& _stubTo; | |
346 | const char* _name; | |
347 | NonLazyPointerAtom _nonLazyPointer; | |
348 | ld::Fixup _fixup1; | |
349 | ld::Fixup _fixup2; | |
350 | ld::Fixup _fixup3; | |
351 | ld::Fixup _fixup4; | |
352 | ld::Fixup _fixup5; | |
353 | ld::Fixup _fixup6; | |
354 | ld::Fixup _fixup7; | |
355 | ld::Fixup _fixup8; | |
356 | ||
357 | static ld::Section _s_section; | |
358 | }; | |
359 | ||
360 | ld::Section StubPICKextAtom::_s_section("__TEXT", "__stub", ld::Section::typeCode); | |
361 | ||
362 | ||
a645023d A |
363 | |
364 | class StubPICAtom : public ld::Atom { | |
365 | public: | |
366 | StubPICAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo, | |
367 | bool stubToGlobalWeakDef, bool stubToResolver, bool weakImport) | |
368 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
369 | ld::Atom::scopeLinkageUnit, ld::Atom::typeStub, | |
370 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
371 | _stubTo(stubTo), | |
372 | _lazyPointer(pass, stubTo, stubToGlobalWeakDef, stubToResolver, weakImport, false), | |
373 | _fixup1(12, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, &_lazyPointer), | |
374 | _fixup2(12, ld::Fixup::k2of4, ld::Fixup::kindSubtractTargetAddress, this), | |
375 | _fixup3(12, ld::Fixup::k3of4, ld::Fixup::kindSubtractAddend, 12), | |
376 | _fixup4(12, ld::Fixup::k4of4, ld::Fixup::kindStoreLittleEndian32) | |
377 | { pass.addAtom(*this); } | |
378 | ||
379 | virtual const ld::File* file() const { return _stubTo.file(); } | |
a645023d A |
380 | virtual const char* name() const { return _stubTo.name(); } |
381 | virtual uint64_t size() const { return 16; } | |
382 | virtual uint64_t objectAddress() const { return 0; } | |
383 | virtual void copyRawContent(uint8_t buffer[]) const { | |
384 | OSWriteLittleInt32(&buffer[ 0], 0, 0xe59fc004); // ldr ip, pc + 12 | |
385 | OSWriteLittleInt32(&buffer[ 4], 0, 0xe08fc00c); // add ip, pc, ip | |
386 | OSWriteLittleInt32(&buffer[ 8], 0, 0xe59cf000); // ldr pc, [ip] | |
387 | OSWriteLittleInt32(&buffer[12], 0, 0x00000000); // .long L_foo$lazy_ptr - (L1$scv + 8) | |
388 | } | |
389 | virtual void setScope(Scope) { } | |
390 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } | |
391 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } | |
392 | ||
393 | private: | |
394 | const ld::Atom& _stubTo; | |
395 | LazyPointerAtom _lazyPointer; | |
396 | ld::Fixup _fixup1; | |
397 | ld::Fixup _fixup2; | |
398 | ld::Fixup _fixup3; | |
399 | ld::Fixup _fixup4; | |
400 | ||
401 | static ld::Section _s_section; | |
402 | }; | |
403 | ||
404 | ld::Section StubPICAtom::_s_section("__TEXT", "__picsymbolstub4", ld::Section::typeStub); | |
405 | ||
406 | ||
407 | ||
408 | class StubNoPICAtom : public ld::Atom { | |
409 | public: | |
410 | StubNoPICAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo, | |
411 | bool stubToGlobalWeakDef, bool stubToResolver, bool weakImport) | |
412 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
413 | ld::Atom::scopeLinkageUnit, ld::Atom::typeStub, | |
414 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
415 | _stubTo(stubTo), | |
416 | _lazyPointer(pass, stubTo, stubToGlobalWeakDef, stubToResolver, weakImport, false), | |
417 | _fixup(8, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressLittleEndian32, &_lazyPointer) | |
418 | { pass.addAtom(*this); } | |
419 | ||
420 | virtual const ld::File* file() const { return _stubTo.file(); } | |
a645023d A |
421 | virtual const char* name() const { return _stubTo.name(); } |
422 | virtual uint64_t size() const { return 12; } | |
423 | virtual uint64_t objectAddress() const { return 0; } | |
424 | virtual void copyRawContent(uint8_t buffer[]) const { | |
425 | OSWriteLittleInt32(&buffer[ 0], 0, 0xe59fc000); // ldr ip, [pc, #0] | |
426 | OSWriteLittleInt32(&buffer[ 4], 0, 0xe59cf000); // ldr pc, [ip] | |
427 | OSWriteLittleInt32(&buffer[ 8], 0, 0x00000000); // .long L_foo$lazy_ptr | |
428 | } | |
429 | virtual void setScope(Scope) { } | |
430 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } | |
431 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } | |
432 | ||
433 | private: | |
434 | const ld::Atom& _stubTo; | |
435 | LazyPointerAtom _lazyPointer; | |
436 | ld::Fixup _fixup; | |
437 | ||
438 | static ld::Section _s_section; | |
439 | }; | |
440 | ||
441 | ld::Section StubNoPICAtom::_s_section("__TEXT", "__symbol_stub4", ld::Section::typeStub); | |
442 | ||
443 | ||
444 | ||
445 | ||
446 | class StubCloseAtom : public ld::Atom { | |
447 | public: | |
448 | StubCloseAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo, | |
449 | bool stubToGlobalWeakDef, bool stubToResolver, bool weakImport) | |
450 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
451 | ld::Atom::scopeLinkageUnit, ld::Atom::typeStub, | |
452 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
453 | _stubTo(stubTo), | |
454 | _lazyPointer(pass, stubTo, stubToGlobalWeakDef, stubToResolver, weakImport, true), | |
455 | _fixup(0, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressARMLoad12, &_lazyPointer) | |
456 | { pass.addAtom(*this); } | |
457 | ||
458 | virtual const ld::File* file() const { return _stubTo.file(); } | |
a645023d A |
459 | virtual const char* name() const { return _stubTo.name(); } |
460 | virtual uint64_t size() const { return 4; } | |
461 | virtual uint64_t objectAddress() const { return 0; } | |
462 | virtual void copyRawContent(uint8_t buffer[]) const { | |
463 | OSWriteLittleInt32(&buffer[ 0], 0, 0xE59FF000); // ldr pc, [pc, #foo$lazy_ptr] | |
464 | } | |
465 | virtual void setScope(Scope) { } | |
466 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } | |
467 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } | |
468 | ||
469 | private: | |
470 | const ld::Atom& _stubTo; | |
471 | LazyPointerAtom _lazyPointer; | |
472 | ld::Fixup _fixup; | |
473 | ||
474 | static ld::Section _s_section; | |
475 | }; | |
476 | ||
477 | ld::Section StubCloseAtom::_s_section("__TEXT", "__symbolstub1", ld::Section::typeStubClose); | |
478 | ||
479 | ||
480 | ||
481 | ||
482 | } // namespace arm | |
483 |