llvm.org GIT mirror llvm / c7f424d
Remove getters now that we can specialize structs on the host endianness. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179534 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
2 changed file(s) with 91 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
147147 }
148148 };
149149
150 template<endianness TargetEndianness>
150 template<bool HostIsLittleEndian, endianness TargetEndianness>
151151 struct RelocationEntry;
152152
153153 template<>
154 struct RelocationEntry<support::little> {
154 struct RelocationEntry<true, support::little> {
155155 LLVM_MACHOB_IMPORT_TYPES(support::little)
156156 MachOInt32 Address;
157157 MachOInt24 SymbolNum;
158 uint8_t Bits;
159
160 unsigned getPCRel() const {
161 return Bits & 0x1;
162 }
163 unsigned getLength() const {
164 return (Bits >> 1) & 0x3;
165 }
166 unsigned getExternal() const {
167 return (Bits >> 3) & 0x1;
168 }
169 unsigned getType() const {
170 return Bits >> 4;
171 }
158 unsigned PCRel : 1;
159 unsigned Length : 2;
160 unsigned External : 1;
161 unsigned Type : 4;
172162 };
173163
174164 template<>
175 struct RelocationEntry<support::big> {
165 struct RelocationEntry<false, support::little> {
166 LLVM_MACHOB_IMPORT_TYPES(support::little)
167 MachOInt32 Address;
168 MachOInt24 SymbolNum;
169 unsigned Type : 4;
170 unsigned External : 1;
171 unsigned Length : 2;
172 unsigned PCRel : 1;
173 };
174
175 template<>
176 struct RelocationEntry {
176177 LLVM_MACHOB_IMPORT_TYPES(support::big)
177178 MachOInt32 Address;
178179 MachOInt24 SymbolNum;
179 uint8_t Bits;
180
181 unsigned getType() const {
182 return Bits &0xf;
183 }
184 unsigned getExternal() const {
185 return (Bits >> 4) & 0x1;
186 }
187 unsigned getLength() const {
188 return (Bits >> 5) & 0x3;
189 }
190 unsigned getPCRel() const {
191 return Bits >> 7;
192 }
193 };
194
195 template
180 unsigned Type : 4;
181 unsigned External : 1;
182 unsigned Length : 2;
183 unsigned PCRel : 1;
184 };
185
186 template<>
187 struct RelocationEntry {
188 LLVM_MACHOB_IMPORT_TYPES(support::big)
189 MachOInt32 Address;
190 MachOInt24 SymbolNum;
191 unsigned PCRel : 1;
192 unsigned Length : 2;
193 unsigned External : 1;
194 unsigned Type : 4;
195 };
196
197 template
196198 struct ScatteredRelocationEntry;
197199
198200 template<>
199 struct ScatteredRelocationEntry<support::little> {
201 struct ScatteredRelocationEntry<true, support::little> {
200202 LLVM_MACHOB_IMPORT_TYPES(support::little)
201203 MachOInt24 Address;
202 uint8_t Bits;
204 unsigned Type : 4;
205 unsigned Length : 2;
206 unsigned PCRel : 1;
207 unsigned Scattered : 1;
203208 MachOInt32 Value;
204
205 unsigned getType() const {
206 return Bits & 0xf;
207 }
208 unsigned getLength() const {
209 return (Bits >> 4) & 0x3;
210 }
211 unsigned getPCRel() const {
212 return (Bits >> 6) & 0x1;
213 }
214 unsigned getScattered() const {
215 return Bits >> 7;
216 }
217209 };
218210
219211 template<>
220 struct ScatteredRelocationEntry<support::big> {
212 struct ScatteredRelocationEntry<false, support::little> {
213 LLVM_MACHOB_IMPORT_TYPES(support::little)
214 MachOInt24 Address;
215 unsigned Scattered : 1;
216 unsigned PCRel : 1;
217 unsigned Length : 2;
218 unsigned Type : 4;
219 MachOInt32 Value;
220 };
221
222 template<>
223 struct ScatteredRelocationEntry {
221224 LLVM_MACHOB_IMPORT_TYPES(support::big)
222 uint8_t Bits;
223 unsigned getType() const {
224 return Bits & 0xf;
225 }
226 unsigned getLength() const {
227 return (Bits >> 4) & 0x3;
228 }
229 unsigned getPCRel() const {
230 return (Bits >> 6) & 0x1;
231 }
232 unsigned getScattered() const {
233 return Bits >> 7;
234 }
225 unsigned Type : 4;
226 unsigned Length : 2;
227 unsigned PCRel : 1;
228 unsigned Scattered : 1;
229 MachOInt24 Address;
230 MachOInt32 Value;
231 };
232
233 template<>
234 struct ScatteredRelocationEntry {
235 LLVM_MACHOB_IMPORT_TYPES(support::big)
236 unsigned Scattered : 1;
237 unsigned PCRel : 1;
238 unsigned Length : 2;
239 unsigned Type : 4;
235240 MachOInt24 Address;
236241 MachOInt32 Value;
237242 };
377382 LinkeditDataLoadCommand;
378383 typedef MachOFormat::Header Header;
379384 typedef MachOFormat::SymtabLoadCommand SymtabLoadCommand;
380 typedef MachOFormat::RelocationEntry RelocationEntry;
381 typedef MachOFormat::ScatteredRelocationEntry
385 typedef MachOFormat::RelocationEntry RelocationEntry;
386 typedef MachOFormat::ScatteredRelocationEntry
382387 ScatteredRelocationEntry;
383388 typedef MachOFormat::LoadCommand LoadCommand;
384389
605610 if (isRelocationScattered(RE)) {
606611 const typename MachOObjectFileMiddle::ScatteredRelocationEntry *SRE =
607612 reinterpret_cast(RE);
608 return SRE->getPCRel();
609 }
610 return RE->getPCRel();
613 return SRE->PCRel;
614 }
615 return RE->PCRel;
611616 }
612617
613618 template
617622 if (isRelocationScattered(RE)) {
618623 const typename ObjType::ScatteredRelocationEntry *SRE =
619624 reinterpret_cast(RE);
620 return SRE->getLength();
621 }
622 return RE->getLength();
625 return SRE->Length;
626 }
627 return RE->Length;
623628 }
624629
625630 template
630635 if (isRelocationScattered(RE)) {
631636 const typename ObjType::ScatteredRelocationEntry *SRE =
632637 reinterpret_cast(RE);
633 return SRE->getType();
634 }
635 return RE->getType();
638 return SRE->Type;
639 }
640 return RE->Type;
636641 }
637642
638643 // Helper to advance a section or symbol iterator multiple increments at a time.
706711 }
707712
708713 StringRef S;
709 bool isExtern = RE->getExternal();
714 bool isExtern = RE->External;
710715 uint64_t Val = RE->Address;
711716
712717 if (isExtern) {
11361141 SymbolRef &Res) const {
11371142 const RelocationEntry *RE = getRelocation(Rel);
11381143 uint32_t SymbolIdx = RE->SymbolNum;
1139 bool isExtern = RE->getExternal();
1144 bool isExtern = RE->External;
11401145
11411146 DataRefImpl Sym;
11421147 this->moveToNextSymbol(Sym);
12761281
12771282 // X86_64 has entirely custom relocation types.
12781283 if (Arch == Triple::x86_64) {
1279 bool isPCRel = RE->getPCRel();
1284 bool isPCRel = RE->PCRel;
12801285
12811286 switch (Type) {
12821287 case macho::RIT_X86_64_GOTLoad: // X86_64_RELOC_GOT_LOAD
12941299 // X86_64_SUBTRACTOR must be followed by a relocation of type
12951300 // X86_64_RELOC_UNSIGNED.
12961301 // NOTE: Scattered relocations don't exist on x86_64.
1297 unsigned RType = RENext->getType();
1302 unsigned RType = RENext->Type;
12981303 if (RType != 0)
12991304 report_fatal_error("Expected X86_64_RELOC_UNSIGNED after "
13001305 "X86_64_RELOC_SUBTRACTOR.");
13461351 if (isNextScattered)
13471352 RType = (RENext->Address >> 24) & 0xF;
13481353 else
1349 RType = RENext->getType();
1354 RType = RENext->Type;
13501355 if (RType != 1)
13511356 report_fatal_error("Expected GENERIC_RELOC_PAIR after "
13521357 "GENERIC_RELOC_SECTDIFF.");
13751380 if (isNextScattered)
13761381 RType = (RENext->Address >> 24) & 0xF;
13771382 else
1378 RType = RENext->getType();
1383 RType = RENext->Type;
13791384 if (RType != 1)
13801385 report_fatal_error("Expected GENERIC_RELOC_PAIR after "
13811386 "GENERIC_RELOC_LOCAL_SECTDIFF.");
14041409 if (IsScattered)
14051410 isUpper = (RE->Address >> 28) & 1;
14061411 else
1407 isUpper = (RE->getLength() >> 1) & 1;
1412 isUpper = (RE->Length >> 1) & 1;
14081413
14091414 if (isUpper)
14101415 fmt << ":upper16:(";
14241429 if (isNextScattered)
14251430 RType = (RENext->Address >> 24) & 0xF;
14261431 else
1427 RType = RENext->getType();
1432 RType = RENext->Type;
14281433
14291434 if (RType != 1)
14301435 report_fatal_error("Expected ARM_RELOC_PAIR after "
14801485 RelPrev.d.a--;
14811486 const RelocationEntry *REPrev = this->getRelocation(RelPrev);
14821487
1483 unsigned PrevType = REPrev->getType();
1488 unsigned PrevType = REPrev->Type;
14841489
14851490 if (PrevType == macho::RIT_X86_64_Subtractor) Result = true;
14861491 }
375375 if (IsScattered)
376376 W.printString("Extern", StringRef("N/A"));
377377 else
378 W.printNumber("Extern", RE->getExternal());
379 W.printNumber("Type", RelocName, RE->getType());
378 W.printNumber("Extern", RE->External);
379 W.printNumber("Type", RelocName, RE->Type);
380380 W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
381381 W.printNumber("Scattered", IsScattered);
382382 } else {
387387 if (IsScattered)
388388 OS << " n/a";
389389 else
390 OS << " " << RE->getExternal();
390 OS << " " << RE->External;
391391 OS << " " << RelocName
392392 << " " << IsScattered
393393 << " " << (SymbolName.size() > 0 ? SymbolName : "-")