]>
Commit | Line | Data |
---|---|---|
a645023d A |
1 | /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*- |
2 | * | |
3 | * Copyright (c) 2009 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 | namespace classic { | |
28 | ||
29 | ||
30 | class LazyPointerAtom : public ld::Atom { | |
31 | public: | |
32 | LazyPointerAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo, | |
33 | bool forLazyDylib, bool weakImport) | |
34 | : ld::Atom(forLazyDylib ? _s_sectionLazy : _s_section, ld::Atom::definitionRegular, | |
35 | ld::Atom::combineNever, ld::Atom::scopeLinkageUnit, ld::Atom::typeLazyPointer, | |
36 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
37 | _stubTo(stubTo), | |
38 | _fixup1(0, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressLittleEndian32, | |
39 | forLazyDylib ? pass.internal()->lazyBindingHelper : pass.internal()->classicBindingHelper), | |
40 | _fixup2(0, ld::Fixup::k1of1, ld::Fixup::kindLazyTarget, &stubTo) | |
41 | { _fixup2.weakImport = weakImport; pass.addAtom(*this); } | |
42 | ||
43 | virtual const ld::File* file() const { return _stubTo.file(); } | |
a645023d A |
44 | virtual const char* name() const { return _stubTo.name(); } |
45 | virtual uint64_t size() const { return 4; } | |
46 | virtual uint64_t objectAddress() const { return 0; } | |
47 | virtual void copyRawContent(uint8_t buffer[]) const { } | |
48 | virtual void setScope(Scope) { } | |
49 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } | |
50 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } | |
51 | ||
52 | private: | |
53 | const ld::Atom& _stubTo; | |
54 | ld::Fixup _fixup1; | |
55 | ld::Fixup _fixup2; | |
56 | ||
57 | static ld::Section _s_section; | |
58 | static ld::Section _s_sectionLazy; | |
59 | }; | |
60 | ||
61 | ld::Section LazyPointerAtom::_s_section("__DATA", "__la_symbol_ptr", ld::Section::typeLazyPointer); | |
62 | ld::Section LazyPointerAtom::_s_sectionLazy("__DATA", "__ld_symbol_ptr", ld::Section::typeLazyDylibPointer); | |
63 | ||
64 | ||
65 | class StubPICAtom : public ld::Atom { | |
66 | public: | |
67 | StubPICAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo, | |
68 | bool forLazyDylib, bool weakImport) | |
69 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
70 | ld::Atom::scopeLinkageUnit, ld::Atom::typeStub, | |
71 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
72 | _stubTo(stubTo), | |
73 | _lazyPointer(pass, stubTo, forLazyDylib, weakImport), | |
74 | _fixup1(12, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, &_lazyPointer), | |
75 | _fixup2(12, ld::Fixup::k2of4, ld::Fixup::kindSubtractTargetAddress, this), | |
76 | _fixup3(12, ld::Fixup::k3of4, ld::Fixup::kindSubtractAddend, 12), | |
77 | _fixup4(12, ld::Fixup::k4of4, ld::Fixup::kindStoreLittleEndian32) | |
78 | { pass.addAtom(*this); } | |
79 | ||
80 | virtual const ld::File* file() const { return _stubTo.file(); } | |
a645023d A |
81 | virtual const char* name() const { return _stubTo.name(); } |
82 | virtual uint64_t size() const { return 16; } | |
83 | virtual uint64_t objectAddress() const { return 0; } | |
84 | virtual void copyRawContent(uint8_t buffer[]) const { | |
85 | OSWriteLittleInt32(&buffer[ 0], 0, 0xe59fc004); // ldr ip, pc + 12 | |
86 | OSWriteLittleInt32(&buffer[ 4], 0, 0xe08fc00c); // add ip, pc, ip | |
87 | OSWriteLittleInt32(&buffer[ 8], 0, 0xe59cf000); // ldr pc, [ip] | |
88 | OSWriteLittleInt32(&buffer[12], 0, 0x00000000); // .long L_foo$lazy_ptr - (L1$scv + 8) | |
89 | } | |
90 | virtual void setScope(Scope) { } | |
91 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } | |
92 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } | |
93 | ||
94 | private: | |
95 | const ld::Atom& _stubTo; | |
96 | LazyPointerAtom _lazyPointer; | |
97 | ld::Fixup _fixup1; | |
98 | ld::Fixup _fixup2; | |
99 | ld::Fixup _fixup3; | |
100 | ld::Fixup _fixup4; | |
101 | ||
102 | static ld::Section _s_section; | |
103 | }; | |
104 | ||
105 | ld::Section StubPICAtom::_s_section("__TEXT", "__picsymbolstub4", ld::Section::typeStub); | |
106 | ||
107 | ||
108 | ||
109 | class StubNoPICAtom : public ld::Atom { | |
110 | public: | |
111 | StubNoPICAtom(ld::passes::stubs::Pass& pass, const ld::Atom& stubTo, | |
112 | bool forLazyDylib, bool weakImport) | |
113 | : ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever, | |
114 | ld::Atom::scopeLinkageUnit, ld::Atom::typeStub, | |
115 | symbolTableNotIn, false, false, false, ld::Atom::Alignment(2)), | |
116 | _stubTo(stubTo), | |
117 | _lazyPointer(pass, stubTo, forLazyDylib, weakImport), | |
118 | _fixup(8, ld::Fixup::k1of1, ld::Fixup::kindStoreTargetAddressLittleEndian32, &_lazyPointer) | |
119 | { pass.addAtom(*this); } | |
120 | ||
121 | virtual const ld::File* file() const { return _stubTo.file(); } | |
a645023d A |
122 | virtual const char* name() const { return _stubTo.name(); } |
123 | virtual uint64_t size() const { return 12; } | |
124 | virtual uint64_t objectAddress() const { return 0; } | |
125 | virtual void copyRawContent(uint8_t buffer[]) const { | |
126 | OSWriteLittleInt32(&buffer[ 0], 0, 0xe59fc000); // ldr ip, [pc, #0] | |
127 | OSWriteLittleInt32(&buffer[ 4], 0, 0xe59cf000); // ldr pc, [ip] | |
128 | OSWriteLittleInt32(&buffer[ 8], 0, 0x00000000); // .long L_foo$lazy_ptr | |
129 | } | |
130 | virtual void setScope(Scope) { } | |
131 | virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } | |
132 | virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } | |
133 | ||
134 | private: | |
135 | const ld::Atom& _stubTo; | |
136 | LazyPointerAtom _lazyPointer; | |
137 | ld::Fixup _fixup; | |
138 | ||
139 | static ld::Section _s_section; | |
140 | }; | |
141 | ||
142 | ld::Section StubNoPICAtom::_s_section("__TEXT", "__symbol_stub4", ld::Section::typeStub); | |
143 | ||
144 | ||
145 | ||
146 | ||
147 | } // namespace classic | |
148 | } // namespace arm | |
149 |