llvm.org GIT mirror llvm / efdbec8
Simplify the handling of iterators in ObjectFile. None of the object file formats reported error on iterator increment. In retrospect, that is not too surprising: no object format stores symbols or sections in a linked list or other structure that requires chasing pointers. As a consequence, all error checking can be done on begin() and end(). This reduces the text segment of bin/llvm-readobj in my machine from 521233 to 518526 bytes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200442 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
25 changed file(s) with 147 addition(s) and 365 deletion(s). Raw diff Collapse all Expand all
270270 error_code initExportTablePtr();
271271
272272 protected:
273 error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const
274 LLVM_OVERRIDE;
273 void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE;
275274 error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
276275 LLVM_OVERRIDE;
277276 error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const
287286 LLVM_OVERRIDE;
288287 error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const
289288 LLVM_OVERRIDE;
290 error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const
291 LLVM_OVERRIDE;
289 void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE;
292290 error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
293291 LLVM_OVERRIDE;
294292 error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
312310 relocation_iterator section_rel_begin(DataRefImpl Sec) const LLVM_OVERRIDE;
313311 relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
314312
315 error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const
316 LLVM_OVERRIDE;
313 void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE;
317314 error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
318315 LLVM_OVERRIDE;
319316 error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
396393 : ImportTable(Table), Index(I), OwningObject(Owner) {}
397394
398395 bool operator==(const ImportDirectoryEntryRef &Other) const;
399 error_code getNext(ImportDirectoryEntryRef &Result) const;
396 void moveNext();
400397 error_code getName(StringRef &Result) const;
401398
402399 error_code
420417 : ExportTable(Table), Index(I), OwningObject(Owner) {}
421418
422419 bool operator==(const ExportDirectoryEntryRef &Other) const;
423 error_code getNext(ExportDirectoryEntryRef &Result) const;
420 void moveNext();
424421
425422 error_code getDllName(StringRef &Result) const;
426423 error_code getOrdinalBase(uint32_t &Result) const;
5454 protected:
5555 ELFFile EF;
5656
57 error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const
58 LLVM_OVERRIDE;
57 void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE;
5958 error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
6059 LLVM_OVERRIDE;
6160 error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const
7776 error_code getLibraryPath(DataRefImpl Data, StringRef &Res) const
7877 LLVM_OVERRIDE;
7978
80 error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const
81 LLVM_OVERRIDE;
79 void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE;
8280 error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
8381 LLVM_OVERRIDE;
8482 error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
10199 relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
102100 section_iterator getRelocatedSection(DataRefImpl Sec) const LLVM_OVERRIDE;
103101
104 error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const
105 LLVM_OVERRIDE;
102 void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE;
106103 error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
107104 LLVM_OVERRIDE;
108105 error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
221218 typedef ELFObjectFile > ELF64BEObjectFile;
222219
223220 template
224 error_code ELFObjectFile::getSymbolNext(DataRefImpl Symb,
225 SymbolRef &Result) const {
226 Result = SymbolRef(toDRI(++toELFSymIter(Symb)), this);
227 return object_error::success;
221 void ELFObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
222 Symb = toDRI(++toELFSymIter(Symb));
228223 }
229224
230225 template
438433 }
439434
440435 template
441 error_code ELFObjectFile::getSectionNext(DataRefImpl Sec,
442 SectionRef &Result) const {
443 Result = SectionRef(toDRI(++toELFShdrIter(Sec)), this);
444 return object_error::success;
436 void ELFObjectFile::moveSectionNext(DataRefImpl &Sec) const {
437 Sec = toDRI(++toELFShdrIter(Sec));
445438 }
446439
447440 template
593586
594587 // Relocations
595588 template
596 error_code ELFObjectFile::getRelocationNext(DataRefImpl Rel,
597 RelocationRef &Result) const {
589 void ELFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
598590 ++Rel.d.b;
599 Result = RelocationRef(Rel, this);
600 return object_error::success;
601591 }
602592
603593 template
3737 bool operator==(const DiceRef &Other) const;
3838 bool operator<(const DiceRef &Other) const;
3939
40 error_code getNext(DiceRef &Result) const;
40 void moveNext();
4141
4242 error_code getOffset(uint32_t &Result) const;
4343 error_code getLength(uint16_t &Result) const;
5858 MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits,
5959 error_code &EC, bool BufferOwned = true);
6060
61 error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const
62 LLVM_OVERRIDE;
61 void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE;
6362 error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
6463 LLVM_OVERRIDE;
6564 error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const
7877 error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const
7978 LLVM_OVERRIDE;
8079
81 error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const
82 LLVM_OVERRIDE;
80 void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE;
8381 error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
8482 LLVM_OVERRIDE;
8583 error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
103101 relocation_iterator section_rel_begin(DataRefImpl Sec) const LLVM_OVERRIDE;
104102 relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
105103
106 error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const
107 LLVM_OVERRIDE;
104 void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE;
108105 error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
109106 LLVM_OVERRIDE;
110107 error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
243240 return DicePimpl < Other.DicePimpl;
244241 }
245242
246 inline error_code DiceRef::getNext(DiceRef &Result) const {
247 DataRefImpl Rel = DicePimpl;
243 inline void DiceRef::moveNext() {
248244 const MachO::data_in_code_entry *P =
249 reinterpret_cast(Rel.p);
250 Rel.p = reinterpret_cast(P + 1);
251 Result = DiceRef(Rel, OwningObject);
252 return object_error::success;
245 reinterpret_cast(DicePimpl.p);
246 DicePimpl.p = reinterpret_cast(P + 1);
253247 }
254248
255249 // Since a Mach-O data in code reference, a DiceRef, can only be created when
6262 return !(*this == other);
6363 }
6464
65 content_iterator& increment(error_code &err) {
66 content_type next;
67 if (error_code ec = Current.getNext(next))
68 err = ec;
69 else
70 Current = next;
65 content_iterator &operator++() { // preincrement
66 Current.moveNext();
7167 return *this;
7268 }
7369 };
10096
10197 bool operator==(const RelocationRef &Other) const;
10298
103 error_code getNext(RelocationRef &Result) const;
99 void moveNext();
104100
105101 error_code getAddress(uint64_t &Result) const;
106102 error_code getOffset(uint64_t &Result) const;
145141 bool operator==(const SectionRef &Other) const;
146142 bool operator<(const SectionRef &Other) const;
147143
148 error_code getNext(SectionRef &Result) const;
144 void moveNext();
149145
150146 error_code getName(StringRef &Result) const;
151147 error_code getAddress(uint64_t &Result) const;
209205 bool operator==(const SymbolRef &Other) const;
210206 bool operator<(const SymbolRef &Other) const;
211207
212 error_code getNext(SymbolRef &Result) const;
208 void moveNext();
213209
214210 error_code getName(StringRef &Result) const;
215211 /// Returns the symbol virtual address (i.e. address at which it will be
284280 // Implementations assume that the DataRefImpl is valid and has not been
285281 // modified externally. It's UB otherwise.
286282 friend class SymbolRef;
287 virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const = 0;
283 virtual void moveSymbolNext(DataRefImpl &Symb) const = 0;
288284 virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0;
289285 virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const = 0;
290286 virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res)const=0;
300296
301297 // Same as above for SectionRef.
302298 friend class SectionRef;
303 virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const = 0;
299 virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
304300 virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const = 0;
305301 virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const =0;
306302 virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const = 0;
323319
324320 // Same as above for RelocationRef.
325321 friend class RelocationRef;
326 virtual error_code getRelocationNext(DataRefImpl Rel,
327 RelocationRef &Res) const = 0;
322 virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
328323 virtual error_code getRelocationAddress(DataRefImpl Rel,
329324 uint64_t &Res) const =0;
330325 virtual error_code getRelocationOffset(DataRefImpl Rel,
411406 return SymbolPimpl < Other.SymbolPimpl;
412407 }
413408
414 inline error_code SymbolRef::getNext(SymbolRef &Result) const {
415 return OwningObject->getSymbolNext(SymbolPimpl, Result);
409 inline void SymbolRef::moveNext() {
410 return OwningObject->moveSymbolNext(SymbolPimpl);
416411 }
417412
418413 inline error_code SymbolRef::getName(StringRef &Result) const {
470465 return SectionPimpl < Other.SectionPimpl;
471466 }
472467
473 inline error_code SectionRef::getNext(SectionRef &Result) const {
474 return OwningObject->getSectionNext(SectionPimpl, Result);
468 inline void SectionRef::moveNext() {
469 return OwningObject->moveSectionNext(SectionPimpl);
475470 }
476471
477472 inline error_code SectionRef::getName(StringRef &Result) const {
553548 return RelocationPimpl == Other.RelocationPimpl;
554549 }
555550
556 inline error_code RelocationRef::getNext(RelocationRef &Result) const {
557 return OwningObject->getRelocationNext(RelocationPimpl, Result);
551 inline void RelocationRef::moveNext() {
552 return OwningObject->moveRelocationNext(RelocationPimpl);
558553 }
559554
560555 inline error_code RelocationRef::getAddress(uint64_t &Result) const {
602602 DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
603603 IsLittleEndian(Obj->isLittleEndian()),
604604 AddressSize(Obj->getBytesInAddress()) {
605 error_code ec;
606605 for (object::section_iterator i = Obj->begin_sections(),
607 e = Obj->end_sections();
608 i != e; i.increment(ec)) {
606 e = Obj->end_sections();
607 i != e; ++i) {
609608 StringRef name;
610609 i->getName(name);
611610 StringRef data;
696695 uint64_t SectionSize;
697696 RelocatedSection->getSize(SectionSize);
698697 for (object::relocation_iterator reloc_i = i->begin_relocations(),
699 reloc_e = i->end_relocations();
700 reloc_i != reloc_e; reloc_i.increment(ec)) {
698 reloc_e = i->end_relocations();
699 reloc_i != reloc_e; ++reloc_i) {
701700 uint64_t Address;
702701 reloc_i->getOffset(Address);
703702 uint64_t Type;
114114 // Maximum required total memory to allocate all common symbols
115115 uint64_t CommonSize = 0;
116116
117 error_code err;
118117 // Parse symbols
119118 DEBUG(dbgs() << "Parse symbols:\n");
120 for (symbol_iterator i = obj->begin_symbols(), e = obj->end_symbols();
121 i != e; i.increment(err)) {
122 Check(err);
119 for (symbol_iterator i = obj->begin_symbols(), e = obj->end_symbols(); i != e;
120 ++i) {
123121 object::SymbolRef::Type SymType;
124122 StringRef Name;
125123 Check(i->getType(SymType));
172170
173171 // Parse and process relocations
174172 DEBUG(dbgs() << "Parse relocations:\n");
175 for (section_iterator si = obj->begin_sections(),
176 se = obj->end_sections(); si != se; si.increment(err)) {
177 Check(err);
173 for (section_iterator si = obj->begin_sections(), se = obj->end_sections();
174 si != se; ++si) {
178175 bool isFirstRelocation = true;
179176 unsigned SectionID = 0;
180177 StubMap Stubs;
181178 section_iterator RelocatedSection = si->getRelocatedSection();
182179
183180 for (relocation_iterator i = si->begin_relocations(),
184 e = si->end_relocations(); i != e; i.increment(err)) {
185 Check(err);
186
181 e = si->end_relocations();
182 i != e; ++i) {
187183 // If it's the first relocation in this section, find its SectionID
188184 if (isFirstRelocation) {
189185 SectionID =
250246
251247 unsigned StubBufSize = 0,
252248 StubSize = getMaxStubSize();
253 error_code err;
254249 const ObjectFile *ObjFile = Obj.getObjectFile();
255250 // FIXME: this is an inefficient way to handle this. We should computed the
256251 // necessary section allocation size in loadObject by walking all the sections
257252 // once.
258253 if (StubSize > 0) {
259254 for (section_iterator SI = ObjFile->begin_sections(),
260 SE = ObjFile->end_sections();
261 SI != SE; SI.increment(err), Check(err)) {
255 SE = ObjFile->end_sections();
256 SI != SE; ++SI) {
262257 section_iterator RelSecI = SI->getRelocatedSection();
263258 if (!(RelSecI == Section))
264259 continue;
265260
266261 for (relocation_iterator I = SI->begin_relocations(),
267 E = SI->end_relocations(); I != E; I.increment(err), Check(err)) {
262 E = SI->end_relocations();
263 I != E; ++I) {
268264 StubBufSize += StubSize;
269265 }
270266 }
620620 RelocationValueRef &Rel) {
621621 // Get the ELF symbol value (st_value) to compare with Relocation offset in
622622 // .opd entries
623
624 error_code err;
625 for (section_iterator si = Obj.begin_sections(),
626 se = Obj.end_sections(); si != se; si.increment(err)) {
623 for (section_iterator si = Obj.begin_sections(), se = Obj.end_sections();
624 si != se; ++si) {
627625 section_iterator RelSecI = si->getRelocatedSection();
628626 if (RelSecI == Obj.end_sections())
629627 continue;
635633
636634 for (relocation_iterator i = si->begin_relocations(),
637635 e = si->end_relocations(); i != e;) {
638 check(err);
639
640636 // The R_PPC64_ADDR64 relocation indicates the first field
641637 // of a .opd entry
642638 uint64_t TypeFunc;
643639 check(i->getType(TypeFunc));
644640 if (TypeFunc != ELF::R_PPC64_ADDR64) {
645 i.increment(err);
641 ++i;
646642 continue;
647643 }
648644
652648 int64_t Addend;
653649 check(getELFRelocationAddend(*i, Addend));
654650
655 i = i.increment(err);
651 ++i;
656652 if (i == e)
657653 break;
658 check(err);
659654
660655 // Just check if following relocation is a R_PPC64_TOC
661656 uint64_t TypeTOC;
3636 : Obj(Obj), Dis(Dis), MIA(MIA), MOS(0) {}
3737
3838 uint64_t MCObjectDisassembler::getEntrypoint() {
39 error_code ec;
4039 for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
41 SI != SE; SI.increment(ec)) {
42 if (ec)
43 break;
40 SI != SE; ++SI) {
4441 StringRef Name;
4542 SI->getName(Name);
4643 if (Name == "main" || Name == "_main") {
8986 }
9087
9188 void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
92 error_code ec;
93 for (section_iterator SI = Obj.begin_sections(),
94 SE = Obj.end_sections();
95 SI != SE;
96 SI.increment(ec)) {
97 if (ec) break;
98
89 for (section_iterator SI = Obj.begin_sections(), SE = Obj.end_sections();
90 SI != SE; ++SI) {
9991 bool isText; SI->isText(isText);
10092 bool isData; SI->isData(isData);
10193 if (!isData && !isText)
183175 AddressSetTy Splits;
184176 AddressSetTy Calls;
185177
186 error_code ec;
187178 for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
188 SI != SE; SI.increment(ec)) {
189 if (ec)
190 break;
179 SI != SE; ++SI) {
191180 SymbolRef::Type SymType;
192181 SI->getType(SymType);
193182 if (SymType == SymbolRef::ST_Function) {
505494 : MCObjectDisassembler(MOOF, Dis, MIA), MOOF(MOOF),
506495 VMAddrSlide(VMAddrSlide), HeaderLoadAddress(HeaderLoadAddress) {
507496
508 error_code ec;
509497 for (section_iterator SI = MOOF.begin_sections(), SE = MOOF.end_sections();
510 SI != SE; SI.increment(ec)) {
511 if (ec)
512 break;
498 SI != SE; ++SI) {
513499 StringRef Name;
514500 SI->getName(Name);
515501 // FIXME: We should use the S_ section type instead of the name.
5151 : MCObjectSymbolizer(Ctx, RelInfo, MOOF), MOOF(MOOF),
5252 StubsStart(0), StubsCount(0), StubSize(0), StubsIndSymIndex(0) {
5353
54 error_code ec;
5554 for (section_iterator SI = MOOF->begin_sections(), SE = MOOF->end_sections();
56 SI != SE; SI.increment(ec)) {
57 if (ec) break;
55 SI != SE; ++SI) {
5856 StringRef Name; SI->getName(Name);
5957 if (Name == "__stubs") {
6058 SectionRef StubsSec = *SI;
9088
9189 StringRef SymName;
9290 symbol_iterator SI = MOOF->begin_symbols();
93 error_code ec;
94 for (uint32_t i = 0; i != SymtabIdx; ++i) {
95 SI.increment(ec);
96 }
91 for (uint32_t i = 0; i != SymtabIdx; ++i)
92 ++SI;
9793 SI->getName(SymName);
9894 assert(SI != MOOF->end_symbols() && "Stub wasn't found in the symbol table!");
9995 assert(SymName.front() == '_' && "Mach-O symbol doesn't start with '_'!");
158154 return false;
159155 uint64_t UValue = Value;
160156 // FIXME: map instead of looping each time?
161 error_code ec;
162157 for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
163 SI != SE; SI.increment(ec)) {
164 if (ec) break;
158 SI != SE; ++SI) {
165159 uint64_t SymAddr; SI->getAddress(SymAddr);
166160 uint64_t SymSize; SI->getSize(SymSize);
167161 StringRef SymName; SI->getName(SymName);
238232 }
239233
240234 void MCObjectSymbolizer::buildSectionList() {
241 error_code ec;
242235 for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
243 SI != SE; SI.increment(ec)) {
244 if (ec) break;
245
236 SI != SE; ++SI) {
246237 bool RequiredForExec; SI->isRequiredForExecution(RequiredForExec);
247238 if (RequiredForExec == false)
248239 continue;
262253 }
263254
264255 void MCObjectSymbolizer::buildRelocationByAddrMap() {
265 error_code ec;
266256 for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
267 SI != SE; SI.increment(ec)) {
268 if (ec) break;
269
257 SI != SE; ++SI) {
270258 section_iterator RelSecI = SI->getRelocatedSection();
271259 if (RelSecI == Obj->end_sections())
272260 continue;
278266 continue;
279267 for (relocation_iterator RI = SI->begin_relocations(),
280268 RE = SI->end_relocations();
281 RI != RE;
282 RI.increment(ec)) {
283 if (ec) break;
269 RI != RE; ++RI) {
284270 // FIXME: libObject is inconsistent regarding error handling. The
285271 // overwhelming majority of methods always return object_error::success,
286272 // and assert for simple errors.. Here, ELFObjectFile::getRelocationOffset
8686 return Addr;
8787 }
8888
89 error_code COFFObjectFile::getSymbolNext(DataRefImpl Ref,
90 SymbolRef &Result) const {
89 void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const {
9190 const coff_symbol *Symb = toSymb(Ref);
9291 Symb += 1 + Symb->NumberOfAuxSymbols;
9392 Ref.p = reinterpret_cast(Symb);
94 Result = SymbolRef(Ref, this);
95 return object_error::success;
9693 }
9794
9895 error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
220217 report_fatal_error("getSymbolValue unimplemented in COFFObjectFile");
221218 }
222219
223 error_code COFFObjectFile::getSectionNext(DataRefImpl Ref,
224 SectionRef &Result) const {
220 void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const {
225221 const coff_section *Sec = toSec(Ref);
226222 Sec += 1;
227223 Ref.p = reinterpret_cast(Sec);
228 Result = SectionRef(Ref, this);
229 return object_error::success;
230224 }
231225
232226 error_code COFFObjectFile::getSectionName(DataRefImpl Ref,
385379
386380 // Returns the file offset for the given RVA.
387381 error_code COFFObjectFile::getRvaPtr(uint32_t Rva, uintptr_t &Res) const {
388 error_code EC;
389382 for (section_iterator I = begin_sections(), E = end_sections(); I != E;
390 I.increment(EC)) {
391 if (EC)
392 return EC;
383 ++I) {
393384 const coff_section *Section = getCOFFSection(I);
394385 uint32_t SectionStart = Section->VirtualAddress;
395386 uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
800791 return reinterpret_cast(Rel.p);
801792 }
802793
803 error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel,
804 RelocationRef &Res) const {
794 void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
805795 Rel.p = reinterpret_cast(
806796 reinterpret_cast(Rel.p) + 1);
807 Res = RelocationRef(Rel, this);
808 return object_error::success;
809797 }
810798
811799 error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
931919 return ImportTable == Other.ImportTable && Index == Other.Index;
932920 }
933921
934 error_code
935 ImportDirectoryEntryRef::getNext(ImportDirectoryEntryRef &Result) const {
936 Result = ImportDirectoryEntryRef(ImportTable, Index + 1, OwningObject);
937 return object_error::success;
922 void ImportDirectoryEntryRef::moveNext() {
923 ++Index;
938924 }
939925
940926 error_code ImportDirectoryEntryRef::
966952 return ExportTable == Other.ExportTable && Index == Other.Index;
967953 }
968954
969 error_code
970 ExportDirectoryEntryRef::getNext(ExportDirectoryEntryRef &Result) const {
971 Result = ExportDirectoryEntryRef(ExportTable, Index + 1, OwningObject);
972 return object_error::success;
955 void ExportDirectoryEntryRef::moveNext() {
956 ++Index;
973957 }
974958
975959 // Returns the name of the current export symbol. If the symbol is exported only
274274
275275 // Helper to advance a section or symbol iterator multiple increments at a time.
276276 template
277 static error_code advance(T &it, size_t Val) {
278 error_code ec;
279 while (Val--) {
280 it.increment(ec);
281 }
282 return ec;
283 }
284
285 template
286 static void advanceTo(T &it, size_t Val) {
287 if (error_code ec = advance(it, Val))
288 report_fatal_error(ec.message());
277 static void advance(T &it, size_t Val) {
278 while (Val--)
279 ++it;
289280 }
290281
291282 static unsigned getCPUType(const MachOObjectFile *O) {
304295 if (IsScattered) {
305296 uint32_t Val = O->getPlainRelocationSymbolNum(RE);
306297
307 error_code ec;
308298 for (symbol_iterator SI = O->begin_symbols(), SE = O->end_symbols();
309 SI != SE; SI.increment(ec)) {
310 if (ec) report_fatal_error(ec.message());
311
299 SI != SE; ++SI) {
300 error_code ec;
312301 uint64_t Addr;
313302 StringRef Name;
314303
324313 // If we couldn't find a symbol that this relocation refers to, try
325314 // to find a section beginning instead.
326315 for (section_iterator SI = O->begin_sections(), SE = O->end_sections();
327 SI != SE; SI.increment(ec)) {
328 if (ec) report_fatal_error(ec.message());
329
316 SI != SE; ++SI) {
317 error_code ec;
330318 uint64_t Addr;
331319 StringRef Name;
332320
349337
350338 if (isExtern) {
351339 symbol_iterator SI = O->begin_symbols();
352 advanceTo(SI, Val);
340 advance(SI, Val);
353341 SI->getName(S);
354342 } else {
355343 section_iterator SI = O->begin_sections();
356344 // Adjust for the fact that sections are 1-indexed.
357 advanceTo(SI, Val - 1);
345 advance(SI, Val - 1);
358346 SI->getName(S);
359347 }
360348
453441 }
454442 }
455443
456 error_code MachOObjectFile::getSymbolNext(DataRefImpl Symb,
457 SymbolRef &Res) const {
444 void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
458445 unsigned SymbolTableEntrySize = is64Bit() ?
459446 sizeof(MachO::nlist_64) :
460447 sizeof(MachO::nlist);
461448 Symb.p += SymbolTableEntrySize;
462 Res = SymbolRef(Symb, this);
463 return object_error::success;
464449 }
465450
466451 error_code MachOObjectFile::getSymbolName(DataRefImpl Symb,
544529 }
545530 // Unfortunately symbols are unsorted so we need to touch all
546531 // symbols from load command
547 error_code ec;
548 for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E;
549 I.increment(ec)) {
532 for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E; ++I) {
550533 DataRefImpl DRI = I->getRawDataRefImpl();
551534 Entry = getSymbolTableEntryBase(this, DRI);
552535 getSymbolAddress(DRI, Value);
647630 report_fatal_error("getSymbolValue unimplemented in MachOObjectFile");
648631 }
649632
650 error_code MachOObjectFile::getSectionNext(DataRefImpl Sec,
651 SectionRef &Res) const {
633 void MachOObjectFile::moveSectionNext(DataRefImpl &Sec) const {
652634 Sec.d.a++;
653 Res = SectionRef(Sec, this);
654 return object_error::success;
655635 }
656636
657637 error_code
833813 return relocation_iterator(RelocationRef(Ret, this));
834814 }
835815
836 error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel,
837 RelocationRef &Res) const {
816 void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
838817 const MachO::any_relocation_info *P =
839818 reinterpret_cast(Rel.p);
840819 Rel.p = reinterpret_cast(P + 1);
841 Res = RelocationRef(Rel, this);
842 return object_error::success;
843820 }
844821
845822 error_code
8383 }
8484
8585 void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) {
86 error_code ec;
87 unwrap(SI)->increment(ec);
88 if (ec) report_fatal_error("LLVMMoveToNextSection failed: " + ec.message());
86 ++(*unwrap(SI));
8987 }
9088
9189 void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
110108 }
111109
112110 void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) {
113 error_code ec;
114 unwrap(SI)->increment(ec);
115 if (ec) report_fatal_error("LLVMMoveToNextSymbol failed: " + ec.message());
111 ++(*unwrap(SI));
116112 }
117113
118114 // SectionRef accessors
168164 }
169165
170166 void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
171 error_code ec;
172 unwrap(SI)->increment(ec);
173 if (ec) report_fatal_error("LLVMMoveToNextRelocation failed: " +
174 ec.message());
167 ++(*unwrap(SI));
175168 }
176169
177170
7171 break;
7272 case X86_64_RELOC_SUBTRACTOR:
7373 {
74 RelocationRef RelNext;
75 Obj->getRelocationNext(Rel.getRawDataRefImpl(), RelNext);
76 any_relocation_info RENext = Obj->getRelocation(RelNext.getRawDataRefImpl());
74 Rel.moveNext();
75 any_relocation_info RENext =
76 Obj->getRelocation(Rel.getRawDataRefImpl());
7777
7878 // X86_64_SUBTRACTOR must be followed by a relocation of type
7979 // X86_64_RELOC_UNSIGNED.
8585
8686 const MCExpr *LHS = MCSymbolRefExpr::Create(Sym, Ctx);
8787
88 symbol_iterator RSymI = RelNext.getSymbol();
88 symbol_iterator RSymI = Rel.getSymbol();
8989 uint64_t RSymAddr;
9090 RSymI->getAddress(RSymAddr);
9191 StringRef RSymName;
715715 print32BE(Out, 0);
716716 }
717717
718 error_code Err;
719718 for (object::symbol_iterator I = Obj->begin_symbols(),
720719 E = Obj->end_symbols();
721 I != E; I.increment(Err), failIfError(Err)) {
720 I != E; ++I) {
722721 uint32_t Symflags;
723722 failIfError(I->getFlags(Symflags));
724723 if (Symflags & object::SymbolRef::SF_FormatSpecific)
531531 }
532532
533533 static void dumpSymbolNamesFromObject(ObjectFile *Obj) {
534 error_code EC;
535534 symbol_iterator IBegin = Obj->begin_symbols();
536535 symbol_iterator IEnd = Obj->end_symbols();
537536 if (DynamicSyms) {
538537 IBegin = Obj->begin_dynamic_symbols();
539538 IEnd = Obj->end_dynamic_symbols();
540539 }
541 for (symbol_iterator I = IBegin; I != IEnd; I.increment(EC)) {
542 if (error(EC))
543 break;
540 for (symbol_iterator I = IBegin; I != IEnd; ++I) {
544541 uint32_t SymFlags;
545542 if (error(I->getFlags(SymFlags)))
546543 break;
240240 if (I == E)
241241 return;
242242 outs() << "The Import Tables:\n";
243 error_code EC;
244 for (; I != E; I = I.increment(EC)) {
245 if (EC)
246 return;
247
243 for (; I != E; I = ++I) {
248244 const import_directory_table_entry *Dir;
249245 StringRef Name;
250246 if (I->getImportTableEntry(Dir)) return;
293289 outs() << " DLL name: " << DllName << "\n";
294290 outs() << " Ordinal base: " << OrdinalBase << "\n";
295291 outs() << " Ordinal RVA Name\n";
296 error_code EC;
297 for (; I != E; I = I.increment(EC)) {
298 if (EC)
299 return;
292 for (; I != E; I = ++I) {
300293 uint32_t Ordinal;
301294 if (I->getOrdinal(Ordinal))
302295 return;
326319
327320 const coff_section *Pdata = 0;
328321
329 error_code EC;
330 for (section_iterator SI = Obj->begin_sections(),
331 SE = Obj->end_sections();
332 SI != SE; SI.increment(EC)) {
333 if (error(EC)) return;
334
322 for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
323 SI != SE; ++SI) {
335324 StringRef Name;
336325 if (error(SI->getName(Name))) continue;
337326
341330 std::vector Rels;
342331 for (relocation_iterator RI = SI->begin_relocations(),
343332 RE = SI->end_relocations();
344 RI != RE; RI.increment(EC)) {
345 if (error(EC)) break;
333 RI != RE; ++RI)
346334 Rels.push_back(*RI);
347 }
348335
349336 // Sort relocations by address.
350337 std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
153153 std::vector &Symbols,
154154 SmallVectorImpl &FoundFns,
155155 uint64_t &BaseSegmentAddress) {
156 error_code ec;
157156 for (symbol_iterator SI = MachOObj->begin_symbols(),
158 SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec))
157 SE = MachOObj->end_symbols();
158 SI != SE; ++SI)
159159 Symbols.push_back(*SI);
160160
161161 for (section_iterator SI = MachOObj->begin_sections(),
162 SE = MachOObj->end_sections(); SI != SE; SI.increment(ec)) {
162 SE = MachOObj->end_sections();
163 SI != SE; ++SI) {
163164 SectionRef SR = *SI;
164165 StringRef SectName;
165166 SR.getName(SectName);
269270 else
270271 BaseAddress = BaseSegmentAddress;
271272 DiceTable Dices;
272 error_code ec;
273273 for (dice_iterator DI = MachOOF->begin_dices(), DE = MachOOF->end_dices();
274 DI != DE; DI.increment(ec)){
274 DI != DE; ++DI) {
275275 uint32_t Offset;
276276 DI->getOffset(Offset);
277277 Dices.push_back(std::make_pair(BaseAddress + Offset, *DI));
328328
329329 // Parse relocations.
330330 std::vector > Relocs;
331 error_code ec;
332331 for (relocation_iterator RI = Sections[SectIdx].begin_relocations(),
333 RE = Sections[SectIdx].end_relocations(); RI != RE; RI.increment(ec)) {
332 RE = Sections[SectIdx].end_relocations();
333 RI != RE; ++RI) {
334334 uint64_t RelocOffset, SectionAddress;
335335 RI->getOffset(RelocOffset);
336336 Sections[SectIdx].getAddress(SectionAddress);
386386 error_code EC;
387387 std::map > SectionRelocMap;
388388 for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
389 I != E; I.increment(EC)) {
390 if (error(EC))
391 break;
389 I != E; ++I) {
392390 section_iterator Sec2 = I->getRelocatedSection();
393391 if (Sec2 != Obj->end_sections())
394392 SectionRelocMap[*Sec2].push_back(*I);
395393 }
396394
397395 for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
398 I != E; I.increment(EC)) {
399 if (error(EC))
400 break;
396 I != E; ++I) {
401397 bool Text;
402398 if (error(I->isText(Text)))
403399 break;
411407 // Make a list of all the symbols in this section.
412408 std::vector > Symbols;
413409 for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
414 SI != SE; SI.increment(EC)) {
410 SI != SE; ++SI) {
415411 bool contains;
416412 if (!error(I->containsSymbol(*SI, contains)) && contains) {
417413 uint64_t Address;
440436 RelocSec != E; ++RelocSec) {
441437 for (relocation_iterator RI = RelocSec->begin_relocations(),
442438 RE = RelocSec->end_relocations();
443 RI != RE; RI.increment(EC)) {
444 if (error(EC))
445 break;
439 RI != RE; ++RI)
446440 Rels.push_back(*RI);
447 }
448441 }
449442 }
450443
558551 }
559552
560553 static void PrintRelocations(const ObjectFile *o) {
561 error_code EC;
562554 for (section_iterator si = o->begin_sections(), se = o->end_sections();
563 si != se; si.increment(EC)) {
564 if (error(EC))
565 return;
555 si != se; ++si) {
566556 if (si->begin_relocations() == si->end_relocations())
567557 continue;
568558 StringRef secname;
570560 outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
571561 for (relocation_iterator ri = si->begin_relocations(),
572562 re = si->end_relocations();
573 ri != re; ri.increment(EC)) {
574 if (error(EC))
575 return;
576
563 ri != re; ++ri) {
577564 bool hidden;
578565 uint64_t address;
579566 SmallString<32> relocname;
592579 static void PrintSectionHeaders(const ObjectFile *o) {
593580 outs() << "Sections:\n"
594581 "Idx Name Size Address Type\n";
595 error_code EC;
596582 unsigned i = 0;
597583 for (section_iterator si = o->begin_sections(), se = o->end_sections();
598 si != se; si.increment(EC)) {
599 if (error(EC))
600 return;
584 si != se; ++si) {
601585 StringRef Name;
602586 if (error(si->getName(Name)))
603587 return;
620604 static void PrintSectionContents(const ObjectFile *o) {
621605 error_code EC;
622606 for (section_iterator si = o->begin_sections(), se = o->end_sections();
623 si != se; si.increment(EC)) {
624 if (error(EC))
625 return;
607 si != se; ++si) {
626608 StringRef Name;
627609 StringRef Contents;
628610 uint64_t BaseAddr;
713695 if (const COFFObjectFile *coff = dyn_cast(o))
714696 PrintCOFFSymbolTable(coff);
715697 else {
716 error_code EC;
717698 for (symbol_iterator si = o->begin_symbols(), se = o->end_symbols();
718 si != se; si.increment(EC)) {
719 if (error(EC))
720 return;
699 si != se; ++si) {
721700 StringRef Name;
722701 uint64_t Address;
723702 SymbolRef::Type Type;
540540 }
541541
542542 void COFFDumper::cacheRelocations() {
543 error_code EC;
544543 for (section_iterator SecI = Obj->begin_sections(),
545544 SecE = Obj->end_sections();
546 SecI != SecE; SecI.increment(EC)) {
547 if (error(EC))
548 break;
549
545 SecI != SecE; ++SecI) {
550546 const coff_section *Section = Obj->getCOFFSection(SecI);
551547
552548 for (relocation_iterator RelI = SecI->begin_relocations(),
553549 RelE = SecI->end_relocations();
554 RelI != RelE; RelI.increment(EC)) {
555 if (error(EC))
556 break;
557
550 RelI != RelE; ++RelI)
558551 RelocMap[Section].push_back(*RelI);
559 }
560552
561553 // Sort relocations by address.
562554 std::sort(RelocMap[Section].begin(), RelocMap[Section].end(),
823815 }
824816
825817 void COFFDumper::printSections() {
826 error_code EC;
827
828818 ListScope SectionsD(W, "Sections");
829819 int SectionNumber = 0;
830820 for (section_iterator SecI = Obj->begin_sections(),
831821 SecE = Obj->end_sections();
832 SecI != SecE; SecI.increment(EC)) {
833 if (error(EC))
834 break;
835
822 SecI != SecE; ++SecI) {
836823 ++SectionNumber;
837824 const coff_section *Section = Obj->getCOFFSection(SecI);
838825
859846 ListScope D(W, "Relocations");
860847 for (relocation_iterator RelI = SecI->begin_relocations(),
861848 RelE = SecI->end_relocations();
862 RelI != RelE; RelI.increment(EC)) {
863 if (error(EC)) break;
864
849 RelI != RelE; ++RelI)
865850 printRelocation(SecI, RelI);
866 }
867851 }
868852
869853 if (opts::SectionSymbols) {
870854 ListScope D(W, "Symbols");
871855 for (symbol_iterator SymI = Obj->begin_symbols(),
872856 SymE = Obj->end_symbols();
873 SymI != SymE; SymI.increment(EC)) {
874 if (error(EC)) break;
875
857 SymI != SymE; ++SymI) {
876858 bool Contained = false;
877859 if (SecI->containsSymbol(*SymI, Contained) || !Contained)
878860 continue;
896878 void COFFDumper::printRelocations() {
897879 ListScope D(W, "Relocations");
898880
899 error_code EC;
900881 int SectionNumber = 0;
901882 for (section_iterator SecI = Obj->begin_sections(),
902883 SecE = Obj->end_sections();
903 SecI != SecE; SecI.increment(EC)) {
884 SecI != SecE; ++SecI) {
904885 ++SectionNumber;
905 if (error(EC))
906 break;
907
908886 StringRef Name;
909887 if (error(SecI->getName(Name)))
910888 continue;
912890 bool PrintedGroup = false;
913891 for (relocation_iterator RelI = SecI->begin_relocations(),
914892 RelE = SecI->end_relocations();
915 RelI != RelE; RelI.increment(EC)) {
916 if (error(EC)) break;
917
893 RelI != RelE; ++RelI) {
918894 if (!PrintedGroup) {
919895 W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
920896 W.indent();
962938 void COFFDumper::printSymbols() {
963939 ListScope Group(W, "Symbols");
964940
965 error_code EC;
966 for (symbol_iterator SymI = Obj->begin_symbols(),
967 SymE = Obj->end_symbols();
968 SymI != SymE; SymI.increment(EC)) {
969 if (error(EC)) break;
970
941 for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols();
942 SymI != SymE; ++SymI)
971943 printSymbol(SymI);
972 }
973944 }
974945
975946 void COFFDumper::printDynamicSymbols() {
11151086 }
11161087
11171088 void COFFDumper::printX64UnwindInfo() {
1118 error_code EC;
11191089 for (section_iterator SecI = Obj->begin_sections(),
11201090 SecE = Obj->end_sections();
1121 SecI != SecE; SecI.increment(EC)) {
1122 if (error(EC)) break;
1123
1091 SecI != SecE; ++SecI) {
11241092 StringRef Name;
11251093 if (error(SecI->getName(Name)))
11261094 continue;
221221 ListScope Group(W, "Sections");
222222
223223 int SectionIndex = -1;
224 error_code EC;
225224 for (section_iterator SecI = Obj->begin_sections(),
226225 SecE = Obj->end_sections();
227 SecI != SecE; SecI.increment(EC)) {
228 if (error(EC)) break;
229
226 SecI != SecE; ++SecI) {
230227 ++SectionIndex;
231228
232229 MachOSection Section;
262259 ListScope D(W, "Relocations");
263260 for (relocation_iterator RelI = SecI->begin_relocations(),
264261 RelE = SecI->end_relocations();
265 RelI != RelE; RelI.increment(EC)) {
266 if (error(EC)) break;
267
262 RelI != RelE; ++RelI)
268263 printRelocation(SecI, RelI);
269 }
270264 }
271265
272266 if (opts::SectionSymbols) {
273267 ListScope D(W, "Symbols");
274268 for (symbol_iterator SymI = Obj->begin_symbols(),
275269 SymE = Obj->end_symbols();
276 SymI != SymE; SymI.increment(EC)) {
277 if (error(EC)) break;
278
270 SymI != SymE; ++SymI) {
279271 bool Contained = false;
280272 if (SecI->containsSymbol(*SymI, Contained) || !Contained)
281273 continue;
299291 error_code EC;
300292 for (section_iterator SecI = Obj->begin_sections(),
301293 SecE = Obj->end_sections();
302 SecI != SecE; SecI.increment(EC)) {
303 if (error(EC)) break;
304
294 SecI != SecE; ++SecI) {
305295 StringRef Name;
306296 if (error(SecI->getName(Name)))
307297 continue;
309299 bool PrintedGroup = false;
310300 for (relocation_iterator RelI = SecI->begin_relocations(),
311301 RelE = SecI->end_relocations();
312 RelI != RelE; RelI.increment(EC)) {
313 if (error(EC)) break;
314
302 RelI != RelE; ++RelI) {
315303 if (!PrintedGroup) {
316304 W.startLine() << "Section " << Name << " {\n";
317305 W.indent();
381369 void MachODumper::printSymbols() {
382370 ListScope Group(W, "Symbols");
383371
384 error_code EC;
385 for (symbol_iterator SymI = Obj->begin_symbols(),
386 SymE = Obj->end_symbols();
387 SymI != SymE; SymI.increment(EC)) {
388 if (error(EC)) break;
389
372 for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols();
373 SymI != SymE; ++SymI) {
390374 printSymbol(SymI);
391375 }
392376 }
150150 OwningPtr Context(DIContext::getDWARFContext(LoadedObject->getObjectFile()));
151151
152152 // Use symbol info to iterate functions in the object.
153 error_code ec;
154153 for (object::symbol_iterator I = LoadedObject->begin_symbols(),
155154 E = LoadedObject->end_symbols();
156 I != E && !ec;
157 I.increment(ec)) {
155 I != E; ++I) {
158156 object::SymbolRef::Type SymType;
159157 if (I->getType(SymType)) continue;
160158 if (SymType == object::SymbolRef::ST_Function) {
110110 std::size_t max_name_len = strlen("section");
111111 std::size_t max_size_len = strlen("size");
112112 std::size_t max_addr_len = strlen("addr");
113 error_code ec;
114 for (section_iterator i = o->begin_sections(),
115 e = o->end_sections(); i != e;
116 i.increment(ec)) {
117 if (error(ec))
118 return;
113 for (section_iterator i = o->begin_sections(), e = o->end_sections();
114 i != e; ++i) {
119115 uint64_t size = 0;
120116 if (error(i->getSize(size)))
121117 return;
153149 << "%#" << max_addr_len << radix_fmt << "\n";
154150
155151 // Print each section.
156 for (section_iterator i = o->begin_sections(),
157 e = o->end_sections(); i != e;
158 i.increment(ec)) {
159 if (error(ec))
160 return;
161
152 for (section_iterator i = o->begin_sections(), e = o->end_sections();
153 i != e; ++i) {
162154 StringRef name;
163155 uint64_t size = 0;
164156 uint64_t addr = 0;
188180 uint64_t total_bss = 0;
189181
190182 // Make one pass over the section table to calculate sizes.
191 error_code ec;
192 for (section_iterator i = o->begin_sections(),
193 e = o->end_sections(); i != e;
194 i.increment(ec)) {
195 if (error(ec))
196 return;
197
183 for (section_iterator i = o->begin_sections(), e = o->end_sections();
184 i != e; ++i) {
198185 uint64_t size = 0;
199186 bool isText = false;
200187 bool isData = false;
5151
5252 ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
5353 : Module(Obj), DebugInfoContext(DICtx) {
54 error_code ec;
5554 for (symbol_iterator si = Module->begin_symbols(), se = Module->end_symbols();
56 si != se; si.increment(ec)) {
57 if (error(ec))
58 return;
55 si != se; ++si) {
5956 SymbolRef::Type SymbolType;
6057 if (error(si->getType(SymbolType)))
6158 continue;
267264 const ObjectFile *Obj = dyn_cast(Bin);
268265 if (!Obj)
269266 return false;
270 error_code EC;
271267 for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
272 I != E; I.increment(EC)) {
268 I != E; ++I) {
273269 StringRef Name;
274270 I->getName(Name);
275271 Name = Name.substr(Name.find_first_not_of("._"));
9595 // Dump the relocation entries.
9696 outs() << " ('_relocations', [\n";
9797 unsigned RelNum = 0;
98 error_code EC;
9998 for (relocation_iterator I = Obj.section_rel_begin(Index),
100 E = Obj.section_rel_end(Index); I != E; I.increment(EC), ++RelNum) {
99 E = Obj.section_rel_end(Index);
100 I != E; ++I, ++RelNum) {
101101 MachO::any_relocation_info RE = Obj.getRelocation(I->getRawDataRefImpl());
102102 outs() << " # Relocation " << RelNum << "\n";
103103 outs() << " (('word-0', " << format("0x%x", RE.r_word0) << "),\n";
200200
201201 // Dump the symbol table.
202202 outs() << " ('_symbols', [\n";
203 error_code EC;
204203 unsigned SymNum = 0;
205204 for (symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;
206 I.increment(EC), ++SymNum) {
205 ++I, ++SymNum) {
207206 DataRefImpl DRI = I->getRawDataRefImpl();
208207 if (Obj.is64Bit()) {
209208 MachO::nlist_64 STE = Obj.getSymbol64TableEntry(DRI);
5050
5151 void COFFDumper::dumpSections(unsigned NumSections) {
5252 std::vector &Sections = YAMLObj.Sections;
53 error_code ec;
5453 for (object::section_iterator iter = Obj.begin_sections();
55 iter != Obj.end_sections(); iter.increment(ec)) {
56 check(ec);
54 iter != Obj.end_sections(); ++iter) {
5755 const object::coff_section *Sect = Obj.getCOFFSection(iter);
5856 COFFYAML::Section Sec;
5957 Sec.Name = Sect->Name; // FIXME: check the null termination!
6765
6866 std::vector Relocations;
6967 for (object::relocation_iterator rIter = iter->begin_relocations();
70 rIter != iter->end_relocations(); rIter.increment(ec)) {
68 rIter != iter->end_relocations(); ++rIter) {
7169 const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
7270 COFFYAML::Relocation Rel;
7371 object::symbol_iterator Sym = rIter->getSymbol();
8280 }
8381
8482 void COFFDumper::dumpSymbols(unsigned NumSymbols) {
85 error_code ec;
8683 std::vector &Symbols = YAMLObj.Symbols;
8784 for (object::symbol_iterator iter = Obj.begin_symbols();
88 iter != Obj.end_symbols(); iter.increment(ec)) {
89 check(ec);
85 iter != Obj.end_symbols(); ++iter) {
9086 const object::coff_symbol *Symbol = Obj.getCOFFSymbol(iter);
9187 COFFYAML::Symbol Sym;
9288 Obj.getSymbolName(Symbol, Sym.Name);