llvm.org GIT mirror llvm / a40b352
Change the begin and end methods in ObjectFile to match the style guide. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201108 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
24 changed file(s) with 191 addition(s) and 191 deletion(s). Raw diff Collapse all Expand all
331331
332332 public:
333333 COFFObjectFile(MemoryBuffer *Object, error_code &EC, bool BufferOwned = true);
334 symbol_iterator begin_symbols() const LLVM_OVERRIDE;
335 symbol_iterator end_symbols() const LLVM_OVERRIDE;
336 library_iterator begin_libraries_needed() const LLVM_OVERRIDE;
337 library_iterator end_libraries_needed() const LLVM_OVERRIDE;
338 section_iterator begin_sections() const LLVM_OVERRIDE;
339 section_iterator end_sections() const LLVM_OVERRIDE;
334 symbol_iterator symbol_begin() const LLVM_OVERRIDE;
335 symbol_iterator symbol_end() const LLVM_OVERRIDE;
336 library_iterator needed_library_begin() const LLVM_OVERRIDE;
337 library_iterator needed_library_end() const LLVM_OVERRIDE;
338 section_iterator section_begin() const LLVM_OVERRIDE;
339 section_iterator section_end() const LLVM_OVERRIDE;
340340
341341 const coff_section *getCOFFSection(section_iterator &It) const;
342342 const coff_symbol *getCOFFSymbol(symbol_iterator &It) const;
179179
180180 const Elf_Sym *getSymbol(DataRefImpl Symb) const;
181181
182 symbol_iterator begin_symbols() const LLVM_OVERRIDE;
183 symbol_iterator end_symbols() const LLVM_OVERRIDE;
184
185 symbol_iterator begin_dynamic_symbols() const;
186 symbol_iterator end_dynamic_symbols() const;
187
188 section_iterator begin_sections() const LLVM_OVERRIDE;
189 section_iterator end_sections() const LLVM_OVERRIDE;
190
191 library_iterator begin_libraries_needed() const LLVM_OVERRIDE;
192 library_iterator end_libraries_needed() const LLVM_OVERRIDE;
182 symbol_iterator symbol_begin() const LLVM_OVERRIDE;
183 symbol_iterator symbol_end() const LLVM_OVERRIDE;
184
185 symbol_iterator dynamic_symbol_begin() const;
186 symbol_iterator dynamic_symbol_end() const;
187
188 section_iterator section_begin() const LLVM_OVERRIDE;
189 section_iterator section_end() const LLVM_OVERRIDE;
190
191 library_iterator needed_library_begin() const LLVM_OVERRIDE;
192 library_iterator needed_library_end() const LLVM_OVERRIDE;
193193
194194 error_code getRelocationAddend(DataRefImpl Rel, int64_t &Res) const;
195195 error_code getSymbolVersion(SymbolRef Symb, StringRef &Version,
412412 const Elf_Sym *ESym = getSymbol(Symb);
413413 const Elf_Shdr *ESec = EF.getSection(ESym);
414414 if (!ESec)
415 Res = end_sections();
415 Res = section_end();
416416 else {
417417 DataRefImpl Sec;
418418 Sec.p = reinterpret_cast(ESec);
570570 section_iterator
571571 ELFObjectFile::getRelocatedSection(DataRefImpl Sec) const {
572572 if (EF.getHeader()->e_type != ELF::ET_REL)
573 return end_sections();
573 return section_end();
574574
575575 Elf_Shdr_Iter EShdr = toELFShdrIter(Sec);
576576 uintX_t Type = EShdr->sh_type;
577577 if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA)
578 return end_sections();
578 return section_end();
579579
580580 const Elf_Shdr *R = EF.getSection(EShdr->sh_info);
581581 return section_iterator(SectionRef(toDRI(R), this));
605605 }
606606 }
607607 if (!symbolIdx)
608 return end_symbols();
608 return symbol_end();
609609
610610 const Elf_Shdr *SymSec = EF.getSection(sec->sh_link);
611611
823823 EF(Object, ec) {}
824824
825825 template
826 symbol_iterator ELFObjectFile::begin_symbols() const {
826 symbol_iterator ELFObjectFile::symbol_begin() const {
827827 return symbol_iterator(SymbolRef(toDRI(EF.begin_symbols()), this));
828828 }
829829
830830 template
831 symbol_iterator ELFObjectFile::end_symbols() const {
831 symbol_iterator ELFObjectFile::symbol_end() const {
832832 return symbol_iterator(SymbolRef(toDRI(EF.end_symbols()), this));
833833 }
834834
835835 template
836 symbol_iterator ELFObjectFile::begin_dynamic_symbols() const {
836 symbol_iterator ELFObjectFile::dynamic_symbol_begin() const {
837837 return symbol_iterator(SymbolRef(toDRI(EF.begin_dynamic_symbols()), this));
838838 }
839839
840840 template
841 symbol_iterator ELFObjectFile::end_dynamic_symbols() const {
841 symbol_iterator ELFObjectFile::dynamic_symbol_end() const {
842842 return symbol_iterator(SymbolRef(toDRI(EF.end_dynamic_symbols()), this));
843843 }
844844
845845 template
846 section_iterator ELFObjectFile::begin_sections() const {
846 section_iterator ELFObjectFile::section_begin() const {
847847 return section_iterator(SectionRef(toDRI(EF.begin_sections()), this));
848848 }
849849
850850 template
851 section_iterator ELFObjectFile::end_sections() const {
851 section_iterator ELFObjectFile::section_end() const {
852852 return section_iterator(SectionRef(toDRI(EF.end_sections()), this));
853853 }
854854
866866 }
867867
868868 template
869 library_iterator ELFObjectFile::begin_libraries_needed() const {
869 library_iterator ELFObjectFile::needed_library_begin() const {
870870 Elf_Dyn_Iter DI = EF.begin_dynamic_table();
871871 Elf_Dyn_Iter DE = EF.end_dynamic_table();
872872
899899 }
900900
901901 template
902 library_iterator ELFObjectFile::end_libraries_needed() const {
902 library_iterator ELFObjectFile::needed_library_end() const {
903903 return library_iterator(LibraryRef(toDRI(EF.end_dynamic_table()), this));
904904 }
905905
125125 // TODO: Would be useful to have an iterator based version
126126 // of the load command interface too.
127127
128 symbol_iterator begin_symbols() const LLVM_OVERRIDE;
129 symbol_iterator end_symbols() const LLVM_OVERRIDE;
130
131 section_iterator begin_sections() const LLVM_OVERRIDE;
132 section_iterator end_sections() const LLVM_OVERRIDE;
133
134 library_iterator begin_libraries_needed() const LLVM_OVERRIDE;
135 library_iterator end_libraries_needed() const LLVM_OVERRIDE;
128 symbol_iterator symbol_begin() const LLVM_OVERRIDE;
129 symbol_iterator symbol_end() const LLVM_OVERRIDE;
130
131 section_iterator section_begin() const LLVM_OVERRIDE;
132 section_iterator section_end() const LLVM_OVERRIDE;
133
134 library_iterator needed_library_begin() const LLVM_OVERRIDE;
135 library_iterator needed_library_end() const LLVM_OVERRIDE;
136136
137137 uint8_t getBytesInAddress() const LLVM_OVERRIDE;
138138
162162
163163 error_code containsSymbol(SymbolRef S, bool &Result) const;
164164
165 relocation_iterator begin_relocations() const;
166 relocation_iterator end_relocations() const;
165 relocation_iterator relocation_begin() const;
166 relocation_iterator relocation_end() const;
167167 section_iterator getRelocatedSection() const;
168168
169169 DataRefImpl getRawDataRefImpl() const;
341341
342342 public:
343343
344 virtual symbol_iterator begin_symbols() const = 0;
345 virtual symbol_iterator end_symbols() const = 0;
346
347 virtual section_iterator begin_sections() const = 0;
348 virtual section_iterator end_sections() const = 0;
349
350 virtual library_iterator begin_libraries_needed() const = 0;
351 virtual library_iterator end_libraries_needed() const = 0;
344 virtual symbol_iterator symbol_begin() const = 0;
345 virtual symbol_iterator symbol_end() const = 0;
346
347 virtual section_iterator section_begin() const = 0;
348 virtual section_iterator section_end() const = 0;
349
350 virtual library_iterator needed_library_begin() const = 0;
351 virtual library_iterator needed_library_end() const = 0;
352352
353353 /// @brief The number of bytes used to represent an address in this object
354354 /// file format.
517517 Result);
518518 }
519519
520 inline relocation_iterator SectionRef::begin_relocations() const {
520 inline relocation_iterator SectionRef::relocation_begin() const {
521521 return OwningObject->section_rel_begin(SectionPimpl);
522522 }
523523
524 inline relocation_iterator SectionRef::end_relocations() const {
524 inline relocation_iterator SectionRef::relocation_end() const {
525525 return OwningObject->section_rel_end(SectionPimpl);
526526 }
527527
602602 DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
603603 IsLittleEndian(Obj->isLittleEndian()),
604604 AddressSize(Obj->getBytesInAddress()) {
605 for (object::section_iterator i = Obj->begin_sections(),
606 e = Obj->end_sections();
605 for (object::section_iterator i = Obj->section_begin(),
606 e = Obj->section_end();
607607 i != e; ++i) {
608608 StringRef name;
609609 i->getName(name);
664664 }
665665
666666 section_iterator RelocatedSection = i->getRelocatedSection();
667 if (RelocatedSection == Obj->end_sections())
667 if (RelocatedSection == Obj->section_end())
668668 continue;
669669
670670 StringRef RelSecName;
691691 continue;
692692 }
693693
694 if (i->begin_relocations() != i->end_relocations()) {
694 if (i->relocation_begin() != i->relocation_end()) {
695695 uint64_t SectionSize;
696696 RelocatedSection->getSize(SectionSize);
697 for (object::relocation_iterator reloc_i = i->begin_relocations(),
698 reloc_e = i->end_relocations();
697 for (object::relocation_iterator reloc_i = i->relocation_begin(),
698 reloc_e = i->relocation_end();
699699 reloc_i != reloc_e; ++reloc_i) {
700700 uint64_t Address;
701701 reloc_i->getOffset(Address);
5151 virtual ~ObjectImageCommon() { delete ObjFile; }
5252
5353 virtual object::symbol_iterator begin_symbols() const
54 { return ObjFile->begin_symbols(); }
54 { return ObjFile->symbol_begin(); }
5555 virtual object::symbol_iterator end_symbols() const
56 { return ObjFile->end_symbols(); }
56 { return ObjFile->symbol_end(); }
5757
5858 virtual object::section_iterator begin_sections() const
59 { return ObjFile->begin_sections(); }
59 { return ObjFile->section_begin(); }
6060 virtual object::section_iterator end_sections() const
61 { return ObjFile->end_sections(); }
61 { return ObjFile->section_end(); }
6262
6363 virtual /* Triple::ArchType */ unsigned getArch() const
6464 { return ObjFile->getArch(); }
176176 StubMap Stubs;
177177 section_iterator RelocatedSection = si->getRelocatedSection();
178178
179 for (relocation_iterator i = si->begin_relocations(),
180 e = si->end_relocations();
179 for (relocation_iterator i = si->relocation_begin(),
180 e = si->relocation_end();
181181 i != e; ++i) {
182182 // If it's the first relocation in this section, find its SectionID
183183 if (isFirstRelocation) {
250250 // necessary section allocation size in loadObject by walking all the sections
251251 // once.
252252 if (StubSize > 0) {
253 for (section_iterator SI = ObjFile->begin_sections(),
254 SE = ObjFile->end_sections();
253 for (section_iterator SI = ObjFile->section_begin(),
254 SE = ObjFile->section_end();
255255 SI != SE; ++SI) {
256256 section_iterator RelSecI = SI->getRelocatedSection();
257257 if (!(RelSecI == Section))
258258 continue;
259259
260 for (relocation_iterator I = SI->begin_relocations(),
261 E = SI->end_relocations();
260 for (relocation_iterator I = SI->relocation_begin(),
261 E = SI->relocation_end();
262262 I != E; ++I) {
263263 StubBufSize += StubSize;
264264 }
631631 if (RelSectionName != ".opd")
632632 continue;
633633
634 for (relocation_iterator i = si->begin_relocations(),
635 e = si->end_relocations(); i != e;) {
634 for (relocation_iterator i = si->relocation_begin(),
635 e = si->relocation_end(); i != e;) {
636636 // The R_PPC64_ADDR64 relocation indicates the first field
637637 // of a .opd entry
638638 uint64_t TypeFunc;
3636 : Obj(Obj), Dis(Dis), MIA(MIA), MOS(0) {}
3737
3838 uint64_t MCObjectDisassembler::getEntrypoint() {
39 for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
39 for (symbol_iterator SI = Obj.symbol_begin(), SE = Obj.symbol_end();
4040 SI != SE; ++SI) {
4141 StringRef Name;
4242 SI->getName(Name);
8686 }
8787
8888 void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
89 for (section_iterator SI = Obj.begin_sections(), SE = Obj.end_sections();
89 for (section_iterator SI = Obj.section_begin(), SE = Obj.section_end();
9090 SI != SE; ++SI) {
9191 bool isText; SI->isText(isText);
9292 bool isData; SI->isData(isData);
175175 AddressSetTy Splits;
176176 AddressSetTy Calls;
177177
178 for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
178 for (symbol_iterator SI = Obj.symbol_begin(), SE = Obj.symbol_end();
179179 SI != SE; ++SI) {
180180 SymbolRef::Type SymType;
181181 SI->getType(SymType);
494494 : MCObjectDisassembler(MOOF, Dis, MIA), MOOF(MOOF),
495495 VMAddrSlide(VMAddrSlide), HeaderLoadAddress(HeaderLoadAddress) {
496496
497 for (section_iterator SI = MOOF.begin_sections(), SE = MOOF.end_sections();
497 for (section_iterator SI = MOOF.section_begin(), SE = MOOF.section_end();
498498 SI != SE; ++SI) {
499499 StringRef Name;
500500 SI->getName(Name);
5151 : MCObjectSymbolizer(Ctx, RelInfo, MOOF), MOOF(MOOF),
5252 StubsStart(0), StubsCount(0), StubSize(0), StubsIndSymIndex(0) {
5353
54 for (section_iterator SI = MOOF->begin_sections(), SE = MOOF->end_sections();
54 for (section_iterator SI = MOOF->section_begin(), SE = MOOF->section_end();
5555 SI != SE; ++SI) {
5656 StringRef Name; SI->getName(Name);
5757 if (Name == "__stubs") {
8787 MOOF->getIndirectSymbolTableEntry(MOOF->getDysymtabLoadCommand(), StubIdx);
8888
8989 StringRef SymName;
90 symbol_iterator SI = MOOF->begin_symbols();
90 symbol_iterator SI = MOOF->symbol_begin();
9191 for (uint32_t i = 0; i != SymtabIdx; ++i)
9292 ++SI;
9393 SI->getName(SymName);
94 assert(SI != MOOF->end_symbols() && "Stub wasn't found in the symbol table!");
94 assert(SI != MOOF->symbol_end() && "Stub wasn't found in the symbol table!");
9595 assert(SymName.front() == '_' && "Mach-O symbol doesn't start with '_'!");
9696 return SymName.substr(1);
9797 }
154154 return false;
155155 uint64_t UValue = Value;
156156 // FIXME: map instead of looping each time?
157 for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
157 for (symbol_iterator SI = Obj->symbol_begin(), SE = Obj->symbol_end();
158158 SI != SE; ++SI) {
159159 uint64_t SymAddr; SI->getAddress(SymAddr);
160160 uint64_t SymSize; SI->getSize(SymSize);
232232 }
233233
234234 void MCObjectSymbolizer::buildSectionList() {
235 for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
235 for (section_iterator SI = Obj->section_begin(), SE = Obj->section_end();
236236 SI != SE; ++SI) {
237237 bool RequiredForExec; SI->isRequiredForExecution(RequiredForExec);
238238 if (RequiredForExec == false)
253253 }
254254
255255 void MCObjectSymbolizer::buildRelocationByAddrMap() {
256 for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
256 for (section_iterator SI = Obj->section_begin(), SE = Obj->section_end();
257257 SI != SE; ++SI) {
258258 section_iterator RelSecI = SI->getRelocatedSection();
259 if (RelSecI == Obj->end_sections())
259 if (RelSecI == Obj->section_end())
260260 continue;
261261
262262 uint64_t StartAddr; RelSecI->getAddress(StartAddr);
264264 bool RequiredForExec; RelSecI->isRequiredForExecution(RequiredForExec);
265265 if (RequiredForExec == false || Size == 0)
266266 continue;
267 for (relocation_iterator RI = SI->begin_relocations(),
268 RE = SI->end_relocations();
267 for (relocation_iterator RI = SI->relocation_begin(),
268 RE = SI->relocation_end();
269269 RI != RE; ++RI) {
270270 // FIXME: libObject is inconsistent regarding error handling. The
271271 // overwhelming majority of methods always return object_error::success,
204204 section_iterator &Result) const {
205205 const coff_symbol *Symb = toSymb(Ref);
206206 if (Symb->SectionNumber <= COFF::IMAGE_SYM_UNDEFINED)
207 Result = end_sections();
207 Result = section_end();
208208 else {
209209 const coff_section *Sec = 0;
210210 if (error_code EC = getSection(Symb->SectionNumber, Sec)) return EC;
382382
383383 // Returns the file offset for the given RVA.
384384 error_code COFFObjectFile::getRvaPtr(uint32_t Rva, uintptr_t &Res) const {
385 for (section_iterator I = begin_sections(), E = end_sections(); I != E;
385 for (section_iterator I = section_begin(), E = section_end(); I != E;
386386 ++I) {
387387 const coff_section *Section = getCOFFSection(I);
388388 uint32_t SectionStart = Section->VirtualAddress;
539539 EC = object_error::success;
540540 }
541541
542 symbol_iterator COFFObjectFile::begin_symbols() const {
542 symbol_iterator COFFObjectFile::symbol_begin() const {
543543 DataRefImpl Ret;
544544 Ret.p = reinterpret_cast(SymbolTable);
545545 return symbol_iterator(SymbolRef(Ret, this));
546546 }
547547
548 symbol_iterator COFFObjectFile::end_symbols() const {
548 symbol_iterator COFFObjectFile::symbol_end() const {
549549 // The symbol table ends where the string table begins.
550550 DataRefImpl Ret;
551551 Ret.p = reinterpret_cast(StringTable);
552552 return symbol_iterator(SymbolRef(Ret, this));
553553 }
554554
555 library_iterator COFFObjectFile::begin_libraries_needed() const {
555 library_iterator COFFObjectFile::needed_library_begin() const {
556556 // TODO: implement
557557 report_fatal_error("Libraries needed unimplemented in COFFObjectFile");
558558 }
559559
560 library_iterator COFFObjectFile::end_libraries_needed() const {
560 library_iterator COFFObjectFile::needed_library_end() const {
561561 // TODO: implement
562562 report_fatal_error("Libraries needed unimplemented in COFFObjectFile");
563563 }
590590 return export_directory_iterator(Ref);
591591 }
592592
593 section_iterator COFFObjectFile::begin_sections() const {
593 section_iterator COFFObjectFile::section_begin() const {
594594 DataRefImpl Ret;
595595 Ret.p = reinterpret_cast(SectionTable);
596596 return section_iterator(SectionRef(Ret, this));
597597 }
598598
599 section_iterator COFFObjectFile::end_sections() const {
599 section_iterator COFFObjectFile::section_end() const {
600600 DataRefImpl Ret;
601601 int NumSections = COFFHeader->isImportLibrary()
602602 ? 0 : COFFHeader->NumberOfSections;
295295 if (IsScattered) {
296296 uint32_t Val = O->getPlainRelocationSymbolNum(RE);
297297
298 for (symbol_iterator SI = O->begin_symbols(), SE = O->end_symbols();
298 for (symbol_iterator SI = O->symbol_begin(), SE = O->symbol_end();
299299 SI != SE; ++SI) {
300300 error_code ec;
301301 uint64_t Addr;
312312
313313 // If we couldn't find a symbol that this relocation refers to, try
314314 // to find a section beginning instead.
315 for (section_iterator SI = O->begin_sections(), SE = O->end_sections();
315 for (section_iterator SI = O->section_begin(), SE = O->section_end();
316316 SI != SE; ++SI) {
317317 error_code ec;
318318 uint64_t Addr;
336336 uint64_t Val = O->getPlainRelocationSymbolNum(RE);
337337
338338 if (isExtern) {
339 symbol_iterator SI = O->begin_symbols();
339 symbol_iterator SI = O->symbol_begin();
340340 advance(SI, Val);
341341 SI->getName(S);
342342 } else {
343 section_iterator SI = O->begin_sections();
343 section_iterator SI = O->section_begin();
344344 // Adjust for the fact that sections are 1-indexed.
345345 advance(SI, Val - 1);
346346 SI->getName(S);
527527 }
528528 // Unfortunately symbols are unsorted so we need to touch all
529529 // symbols from load command
530 for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E; ++I) {
530 for (symbol_iterator I = symbol_begin(), E = symbol_end(); I != E; ++I) {
531531 DataRefImpl DRI = I->getRawDataRefImpl();
532532 Entry = getSymbolTableEntryBase(this, DRI);
533533 getSymbolAddress(DRI, Value);
611611 uint8_t index = Entry.n_sect;
612612
613613 if (index == 0) {
614 Res = end_sections();
614 Res = section_end();
615615 } else {
616616 DataRefImpl DRI;
617617 DRI.d.a = index - 1;
833833 uint32_t SymbolIdx = getPlainRelocationSymbolNum(RE);
834834 bool isExtern = getPlainRelocationExternal(RE);
835835 if (!isExtern)
836 return end_symbols();
836 return symbol_end();
837837
838838 MachO::symtab_command S = getSymtabLoadCommand();
839839 unsigned SymbolTableEntrySize = is64Bit() ?
11621162 report_fatal_error("Needed libraries unimplemented in MachOObjectFile");
11631163 }
11641164
1165 symbol_iterator MachOObjectFile::begin_symbols() const {
1165 symbol_iterator MachOObjectFile::symbol_begin() const {
11661166 DataRefImpl DRI;
11671167 if (!SymtabLoadCmd)
11681168 return symbol_iterator(SymbolRef(DRI, this));
11721172 return symbol_iterator(SymbolRef(DRI, this));
11731173 }
11741174
1175 symbol_iterator MachOObjectFile::end_symbols() const {
1175 symbol_iterator MachOObjectFile::symbol_end() const {
11761176 DataRefImpl DRI;
11771177 if (!SymtabLoadCmd)
11781178 return symbol_iterator(SymbolRef(DRI, this));
11871187 return symbol_iterator(SymbolRef(DRI, this));
11881188 }
11891189
1190 section_iterator MachOObjectFile::begin_sections() const {
1190 section_iterator MachOObjectFile::section_begin() const {
11911191 DataRefImpl DRI;
11921192 return section_iterator(SectionRef(DRI, this));
11931193 }
11941194
1195 section_iterator MachOObjectFile::end_sections() const {
1195 section_iterator MachOObjectFile::section_end() const {
11961196 DataRefImpl DRI;
11971197 DRI.d.a = Sections.size();
11981198 return section_iterator(SectionRef(DRI, this));
11991199 }
12001200
1201 library_iterator MachOObjectFile::begin_libraries_needed() const {
1201 library_iterator MachOObjectFile::needed_library_begin() const {
12021202 // TODO: implement
12031203 report_fatal_error("Needed libraries unimplemented in MachOObjectFile");
12041204 }
12051205
1206 library_iterator MachOObjectFile::end_libraries_needed() const {
1206 library_iterator MachOObjectFile::needed_library_end() const {
12071207 // TODO: implement
12081208 report_fatal_error("Needed libraries unimplemented in MachOObjectFile");
12091209 }
13881388 MachOObjectFile::getRelocationSection(
13891389 const MachO::any_relocation_info &RE) const {
13901390 if (isRelocationScattered(RE) || getPlainRelocationExternal(RE))
1391 return *end_sections();
1391 return *section_end();
13921392 unsigned SecNum = getPlainRelocationSymbolNum(RE) - 1;
13931393 DataRefImpl DRI;
13941394 DRI.d.a = SecNum;
6969
7070 // ObjectFile Section iterators
7171 LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile) {
72 section_iterator SI = unwrap(ObjectFile)->begin_sections();
72 section_iterator SI = unwrap(ObjectFile)->section_begin();
7373 return wrap(new section_iterator(SI));
7474 }
7575
7979
8080 LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
8181 LLVMSectionIteratorRef SI) {
82 return (*unwrap(SI) == unwrap(ObjectFile)->end_sections()) ? 1 : 0;
82 return (*unwrap(SI) == unwrap(ObjectFile)->section_end()) ? 1 : 0;
8383 }
8484
8585 void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) {
9494
9595 // ObjectFile Symbol iterators
9696 LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile) {
97 symbol_iterator SI = unwrap(ObjectFile)->begin_symbols();
97 symbol_iterator SI = unwrap(ObjectFile)->symbol_begin();
9898 return wrap(new symbol_iterator(SI));
9999 }
100100
104104
105105 LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
106106 LLVMSymbolIteratorRef SI) {
107 return (*unwrap(SI) == unwrap(ObjectFile)->end_symbols()) ? 1 : 0;
107 return (*unwrap(SI) == unwrap(ObjectFile)->symbol_end()) ? 1 : 0;
108108 }
109109
110110 void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) {
150150
151151 // Section Relocation iterators
152152 LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section) {
153 relocation_iterator SI = (*unwrap(Section))->begin_relocations();
153 relocation_iterator SI = (*unwrap(Section))->relocation_begin();
154154 return wrap(new relocation_iterator(SI));
155155 }
156156
160160
161161 LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
162162 LLVMRelocationIteratorRef SI) {
163 return (*unwrap(SI) == (*unwrap(Section))->end_relocations()) ? 1 : 0;
163 return (*unwrap(SI) == (*unwrap(Section))->relocation_end()) ? 1 : 0;
164164 }
165165
166166 void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
715715 print32BE(Out, 0);
716716 }
717717
718 for (object::symbol_iterator I = Obj->begin_symbols(),
719 E = Obj->end_symbols();
718 for (object::symbol_iterator I = Obj->symbol_begin(),
719 E = Obj->symbol_end();
720720 I != E; ++I) {
721721 uint32_t Symflags = I->getFlags();;
722722 if (Symflags & object::SymbolRef::SF_FormatSpecific)
364364
365365 uint32_t Characteristics = 0;
366366 if (Symb->SectionNumber > 0) {
367 section_iterator SecI = Obj.end_sections();
367 section_iterator SecI = Obj.section_end();
368368 if (error(I->getSection(SecI)))
369369 return '?';
370370 const coff_section *Section = Obj.getCOFFSection(SecI);
414414 case MachO::N_ABS:
415415 return 's';
416416 case MachO::N_SECT: {
417 section_iterator Sec = Obj.end_sections();
417 section_iterator Sec = Obj.section_end();
418418 Obj.getSymbolSection(Symb, Sec);
419419 DataRefImpl Ref = Sec->getRawDataRefImpl();
420420 StringRef SectionName;
492492 static void getDynamicSymbolIterators(ObjectFile *Obj, symbol_iterator &Begin,
493493 symbol_iterator &End) {
494494 if (ELF32LEObjectFile *ELF = dyn_cast(Obj)) {
495 Begin = ELF->begin_dynamic_symbols();
496 End = ELF->end_dynamic_symbols();
495 Begin = ELF->dynamic_symbol_begin();
496 End = ELF->dynamic_symbol_end();
497497 return;
498498 }
499499 if (ELF64LEObjectFile *ELF = dyn_cast(Obj)) {
500 Begin = ELF->begin_dynamic_symbols();
501 End = ELF->end_dynamic_symbols();
500 Begin = ELF->dynamic_symbol_begin();
501 End = ELF->dynamic_symbol_end();
502502 return;
503503 }
504504 if (ELF32BEObjectFile *ELF = dyn_cast(Obj)) {
505 Begin = ELF->begin_dynamic_symbols();
506 End = ELF->end_dynamic_symbols();
505 Begin = ELF->dynamic_symbol_begin();
506 End = ELF->dynamic_symbol_end();
507507 return;
508508 }
509509 ELF64BEObjectFile *ELF = cast(Obj);
510 Begin = ELF->begin_dynamic_symbols();
511 End = ELF->end_dynamic_symbols();
510 Begin = ELF->dynamic_symbol_begin();
511 End = ELF->dynamic_symbol_end();
512512 return;
513513 }
514514
515515 static void dumpSymbolNamesFromObject(ObjectFile *Obj) {
516 symbol_iterator IBegin = Obj->begin_symbols();
517 symbol_iterator IEnd = Obj->end_symbols();
516 symbol_iterator IBegin = Obj->symbol_begin();
517 symbol_iterator IEnd = Obj->symbol_end();
518518 if (DynamicSyms) {
519519 if (!Obj->isELF()) {
520520 error("File format has no dynamic symbol table", Obj->getFileName());
162162 uint64_t &ResolvedAddr) {
163163 if (error_code EC = Sym.getAddress(ResolvedAddr))
164164 return EC;
165 section_iterator iter(Obj->begin_sections());
165 section_iterator iter(Obj->section_begin());
166166 if (error_code EC = Sym.getSection(iter))
167167 return EC;
168168 ResolvedSection = Obj->getCOFFSection(iter);
319319
320320 const coff_section *Pdata = 0;
321321
322 for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
322 for (section_iterator SI = Obj->section_begin(), SE = Obj->section_end();
323323 SI != SE; ++SI) {
324324 StringRef Name;
325325 if (error(SI->getName(Name))) continue;
328328
329329 Pdata = Obj->getCOFFSection(SI);
330330 std::vector Rels;
331 for (relocation_iterator RI = SI->begin_relocations(),
332 RE = SI->end_relocations();
331 for (relocation_iterator RI = SI->relocation_begin(),
332 RE = SI->relocation_end();
333333 RI != RE; ++RI)
334334 Rels.push_back(*RI);
335335
153153 std::vector &Symbols,
154154 SmallVectorImpl &FoundFns,
155155 uint64_t &BaseSegmentAddress) {
156 for (symbol_iterator SI = MachOObj->begin_symbols(),
157 SE = MachOObj->end_symbols();
156 for (symbol_iterator SI = MachOObj->symbol_begin(),
157 SE = MachOObj->symbol_end();
158158 SI != SE; ++SI)
159159 Symbols.push_back(*SI);
160160
161 for (section_iterator SI = MachOObj->begin_sections(),
162 SE = MachOObj->end_sections();
161 for (section_iterator SI = MachOObj->section_begin(),
162 SE = MachOObj->section_end();
163163 SI != SE; ++SI) {
164164 SectionRef SR = *SI;
165165 StringRef SectName;
328328
329329 // Parse relocations.
330330 std::vector > Relocs;
331 for (relocation_iterator RI = Sections[SectIdx].begin_relocations(),
332 RE = Sections[SectIdx].end_relocations();
331 for (relocation_iterator RI = Sections[SectIdx].relocation_begin(),
332 RE = Sections[SectIdx].relocation_end();
333333 RI != RE; ++RI) {
334334 uint64_t RelocOffset, SectionAddress;
335335 RI->getOffset(RelocOffset);
385385 // in RelocSecs contain the relocations for section S.
386386 error_code EC;
387387 std::map > SectionRelocMap;
388 for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
388 for (section_iterator I = Obj->section_begin(), E = Obj->section_end();
389389 I != E; ++I) {
390390 section_iterator Sec2 = I->getRelocatedSection();
391 if (Sec2 != Obj->end_sections())
391 if (Sec2 != Obj->section_end())
392392 SectionRelocMap[*Sec2].push_back(*I);
393393 }
394394
395 for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
395 for (section_iterator I = Obj->section_begin(), E = Obj->section_end();
396396 I != E; ++I) {
397397 bool Text;
398398 if (error(I->isText(Text)))
406406
407407 // Make a list of all the symbols in this section.
408408 std::vector > Symbols;
409 for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
409 for (symbol_iterator SI = Obj->symbol_begin(), SE = Obj->symbol_end();
410410 SI != SE; ++SI) {
411411 bool contains;
412412 if (!error(I->containsSymbol(*SI, contains)) && contains) {
434434 for (SmallVectorImpl::iterator RelocSec = RelocSecs->begin(),
435435 E = RelocSecs->end();
436436 RelocSec != E; ++RelocSec) {
437 for (relocation_iterator RI = RelocSec->begin_relocations(),
438 RE = RelocSec->end_relocations();
437 for (relocation_iterator RI = RelocSec->relocation_begin(),
438 RE = RelocSec->relocation_end();
439439 RI != RE; ++RI)
440440 Rels.push_back(*RI);
441441 }
551551 }
552552
553553 static void PrintRelocations(const ObjectFile *o) {
554 for (section_iterator si = o->begin_sections(), se = o->end_sections();
554 for (section_iterator si = o->section_begin(), se = o->section_end();
555555 si != se; ++si) {
556 if (si->begin_relocations() == si->end_relocations())
556 if (si->relocation_begin() == si->relocation_end())
557557 continue;
558558 StringRef secname;
559559 if (error(si->getName(secname))) continue;
560560 outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
561 for (relocation_iterator ri = si->begin_relocations(),
562 re = si->end_relocations();
561 for (relocation_iterator ri = si->relocation_begin(),
562 re = si->relocation_end();
563563 ri != re; ++ri) {
564564 bool hidden;
565565 uint64_t address;
580580 outs() << "Sections:\n"
581581 "Idx Name Size Address Type\n";
582582 unsigned i = 0;
583 for (section_iterator si = o->begin_sections(), se = o->end_sections();
583 for (section_iterator si = o->section_begin(), se = o->section_end();
584584 si != se; ++si) {
585585 StringRef Name;
586586 if (error(si->getName(Name)))
603603
604604 static void PrintSectionContents(const ObjectFile *o) {
605605 error_code EC;
606 for (section_iterator si = o->begin_sections(), se = o->end_sections();
606 for (section_iterator si = o->section_begin(), se = o->section_end();
607607 si != se; ++si) {
608608 StringRef Name;
609609 StringRef Contents;
695695 if (const COFFObjectFile *coff = dyn_cast(o))
696696 PrintCOFFSymbolTable(coff);
697697 else {
698 for (symbol_iterator si = o->begin_symbols(), se = o->end_symbols();
698 for (symbol_iterator si = o->symbol_begin(), se = o->symbol_end();
699699 si != se; ++si) {
700700 StringRef Name;
701701 uint64_t Address;
702702 SymbolRef::Type Type;
703703 uint64_t Size;
704704 uint32_t Flags = si->getFlags();
705 section_iterator Section = o->end_sections();
705 section_iterator Section = o->section_end();
706706 if (error(si->getName(Name))) continue;
707707 if (error(si->getAddress(Address))) continue;
708708 if (error(si->getType(Type))) continue;
742742 << ' ';
743743 if (Absolute)
744744 outs() << "*ABS*";
745 else if (Section == o->end_sections())
745 else if (Section == o->section_end())
746746 outs() << "*UND*";
747747 else {
748748 if (const MachOObjectFile *MachO =
184184 if (error_code EC = Sym.getAddress(ResolvedAddr))
185185 return EC;
186186
187 section_iterator iter(Obj->begin_sections());
187 section_iterator iter(Obj->section_begin());
188188 if (error_code EC = Sym.getSection(iter))
189189 return EC;
190190
540540 }
541541
542542 void COFFDumper::cacheRelocations() {
543 for (section_iterator SecI = Obj->begin_sections(),
544 SecE = Obj->end_sections();
543 for (section_iterator SecI = Obj->section_begin(),
544 SecE = Obj->section_end();
545545 SecI != SecE; ++SecI) {
546546 const coff_section *Section = Obj->getCOFFSection(SecI);
547547
548 for (relocation_iterator RelI = SecI->begin_relocations(),
549 RelE = SecI->end_relocations();
548 for (relocation_iterator RelI = SecI->relocation_begin(),
549 RelE = SecI->relocation_end();
550550 RelI != RelE; ++RelI)
551551 RelocMap[Section].push_back(*RelI);
552552
817817 void COFFDumper::printSections() {
818818 ListScope SectionsD(W, "Sections");
819819 int SectionNumber = 0;
820 for (section_iterator SecI = Obj->begin_sections(),
821 SecE = Obj->end_sections();
820 for (section_iterator SecI = Obj->section_begin(),
821 SecE = Obj->section_end();
822822 SecI != SecE; ++SecI) {
823823 ++SectionNumber;
824824 const coff_section *Section = Obj->getCOFFSection(SecI);
844844
845845 if (opts::SectionRelocations) {
846846 ListScope D(W, "Relocations");
847 for (relocation_iterator RelI = SecI->begin_relocations(),
848 RelE = SecI->end_relocations();
847 for (relocation_iterator RelI = SecI->relocation_begin(),
848 RelE = SecI->relocation_end();
849849 RelI != RelE; ++RelI)
850850 printRelocation(SecI, RelI);
851851 }
852852
853853 if (opts::SectionSymbols) {
854854 ListScope D(W, "Symbols");
855 for (symbol_iterator SymI = Obj->begin_symbols(),
856 SymE = Obj->end_symbols();
855 for (symbol_iterator SymI = Obj->symbol_begin(),
856 SymE = Obj->symbol_end();
857857 SymI != SymE; ++SymI) {
858858 bool Contained = false;
859859 if (SecI->containsSymbol(*SymI, Contained) || !Contained)
879879 ListScope D(W, "Relocations");
880880
881881 int SectionNumber = 0;
882 for (section_iterator SecI = Obj->begin_sections(),
883 SecE = Obj->end_sections();
882 for (section_iterator SecI = Obj->section_begin(),
883 SecE = Obj->section_end();
884884 SecI != SecE; ++SecI) {
885885 ++SectionNumber;
886886 StringRef Name;
888888 continue;
889889
890890 bool PrintedGroup = false;
891 for (relocation_iterator RelI = SecI->begin_relocations(),
892 RelE = SecI->end_relocations();
891 for (relocation_iterator RelI = SecI->relocation_begin(),
892 RelE = SecI->relocation_end();
893893 RelI != RelE; ++RelI) {
894894 if (!PrintedGroup) {
895895 W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
938938 void COFFDumper::printSymbols() {
939939 ListScope Group(W, "Symbols");
940940
941 for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols();
941 for (symbol_iterator SymI = Obj->symbol_begin(), SymE = Obj->symbol_end();
942942 SymI != SymE; ++SymI)
943943 printSymbol(SymI);
944944 }
10861086 }
10871087
10881088 void COFFDumper::printX64UnwindInfo() {
1089 for (section_iterator SecI = Obj->begin_sections(),
1090 SecE = Obj->end_sections();
1089 for (section_iterator SecI = Obj->section_begin(),
1090 SecE = Obj->section_end();
10911091 SecI != SecE; ++SecI) {
10921092 StringRef Name;
10931093 if (error(SecI->getName(Name)))
221221 ListScope Group(W, "Sections");
222222
223223 int SectionIndex = -1;
224 for (section_iterator SecI = Obj->begin_sections(),
225 SecE = Obj->end_sections();
224 for (section_iterator SecI = Obj->section_begin(),
225 SecE = Obj->section_end();
226226 SecI != SecE; ++SecI) {
227227 ++SectionIndex;
228228
257257
258258 if (opts::SectionRelocations) {
259259 ListScope D(W, "Relocations");
260 for (relocation_iterator RelI = SecI->begin_relocations(),
261 RelE = SecI->end_relocations();
260 for (relocation_iterator RelI = SecI->relocation_begin(),
261 RelE = SecI->relocation_end();
262262 RelI != RelE; ++RelI)
263263 printRelocation(SecI, RelI);
264264 }
265265
266266 if (opts::SectionSymbols) {
267267 ListScope D(W, "Symbols");
268 for (symbol_iterator SymI = Obj->begin_symbols(),
269 SymE = Obj->end_symbols();
268 for (symbol_iterator SymI = Obj->symbol_begin(),
269 SymE = Obj->symbol_end();
270270 SymI != SymE; ++SymI) {
271271 bool Contained = false;
272272 if (SecI->containsSymbol(*SymI, Contained) || !Contained)
289289 ListScope D(W, "Relocations");
290290
291291 error_code EC;
292 for (section_iterator SecI = Obj->begin_sections(),
293 SecE = Obj->end_sections();
292 for (section_iterator SecI = Obj->section_begin(),
293 SecE = Obj->section_end();
294294 SecI != SecE; ++SecI) {
295295 StringRef Name;
296296 if (error(SecI->getName(Name)))
297297 continue;
298298
299299 bool PrintedGroup = false;
300 for (relocation_iterator RelI = SecI->begin_relocations(),
301 RelE = SecI->end_relocations();
300 for (relocation_iterator RelI = SecI->relocation_begin(),
301 RelE = SecI->relocation_end();
302302 RelI != RelE; ++RelI) {
303303 if (!PrintedGroup) {
304304 W.startLine() << "Section " << Name << " {\n";
330330 if (error(RelI->getOffset(Offset))) return;
331331 if (error(RelI->getTypeName(RelocName))) return;
332332 symbol_iterator Symbol = RelI->getSymbol();
333 if (Symbol != Obj->end_symbols() &&
333 if (Symbol != Obj->symbol_end() &&
334334 error(Symbol->getName(SymbolName)))
335335 return;
336336
369369 void MachODumper::printSymbols() {
370370 ListScope Group(W, "Symbols");
371371
372 for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols();
372 for (symbol_iterator SymI = Obj->symbol_begin(), SymE = Obj->symbol_end();
373373 SymI != SymE; ++SymI) {
374374 printSymbol(SymI);
375375 }
388388 getSymbol(Obj, SymI->getRawDataRefImpl(), Symbol);
389389
390390 StringRef SectionName = "";
391 section_iterator SecI(Obj->end_sections());
391 section_iterator SecI(Obj->section_begin());
392392 if (!error(SymI->getSection(SecI)) &&
393 SecI != Obj->end_sections())
393 SecI != Obj->section_end())
394394 error(SecI->getName(SectionName));
395395
396396 DictScope D(W, "Symbol");
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 for (section_iterator i = o->begin_sections(), e = o->end_sections();
113 for (section_iterator i = o->section_begin(), e = o->section_end();
114114 i != e; ++i) {
115115 uint64_t size = 0;
116116 if (error(i->getSize(size)))
149149 << "%#" << max_addr_len << radix_fmt << "\n";
150150
151151 // Print each section.
152 for (section_iterator i = o->begin_sections(), e = o->end_sections();
152 for (section_iterator i = o->section_begin(), e = o->section_end();
153153 i != e; ++i) {
154154 StringRef name;
155155 uint64_t size = 0;
180180 uint64_t total_bss = 0;
181181
182182 // Make one pass over the section table to calculate sizes.
183 for (section_iterator i = o->begin_sections(), e = o->end_sections();
183 for (section_iterator i = o->section_begin(), e = o->section_end();
184184 i != e; ++i) {
185185 uint64_t size = 0;
186186 bool isText = false;
5151
5252 ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
5353 : Module(Obj), DebugInfoContext(DICtx) {
54 for (symbol_iterator si = Module->begin_symbols(), se = Module->end_symbols();
54 for (symbol_iterator si = Module->symbol_begin(), se = Module->symbol_end();
5555 si != se; ++si) {
5656 SymbolRef::Type SymbolType;
5757 if (error(si->getType(SymbolType)))
264264 const ObjectFile *Obj = dyn_cast(Bin);
265265 if (!Obj)
266266 return false;
267 for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
267 for (section_iterator I = Obj->section_begin(), E = Obj->section_end();
268268 I != E; ++I) {
269269 StringRef Name;
270270 I->getName(Name);
201201 // Dump the symbol table.
202202 outs() << " ('_symbols', [\n";
203203 unsigned SymNum = 0;
204 for (symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;
204 for (symbol_iterator I = Obj.symbol_begin(), E = Obj.symbol_end(); I != E;
205205 ++I, ++SymNum) {
206206 DataRefImpl DRI = I->getRawDataRefImpl();
207207 if (Obj.is64Bit()) {
5050
5151 void COFFDumper::dumpSections(unsigned NumSections) {
5252 std::vector &Sections = YAMLObj.Sections;
53 for (object::section_iterator iter = Obj.begin_sections();
54 iter != Obj.end_sections(); ++iter) {
53 for (object::section_iterator iter = Obj.section_begin();
54 iter != Obj.section_end(); ++iter) {
5555 const object::coff_section *Sect = Obj.getCOFFSection(iter);
5656 COFFYAML::Section Sec;
5757 Sec.Name = Sect->Name; // FIXME: check the null termination!
6464 Sec.SectionData = object::yaml::BinaryRef(sectionData);
6565
6666 std::vector Relocations;
67 for (object::relocation_iterator rIter = iter->begin_relocations();
68 rIter != iter->end_relocations(); ++rIter) {
67 for (object::relocation_iterator rIter = iter->relocation_begin();
68 rIter != iter->relocation_end(); ++rIter) {
6969 const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
7070 COFFYAML::Relocation Rel;
7171 object::symbol_iterator Sym = rIter->getSymbol();
8181
8282 void COFFDumper::dumpSymbols(unsigned NumSymbols) {
8383 std::vector &Symbols = YAMLObj.Symbols;
84 for (object::symbol_iterator iter = Obj.begin_symbols();
85 iter != Obj.end_symbols(); ++iter) {
84 for (object::symbol_iterator iter = Obj.symbol_begin();
85 iter != Obj.symbol_end(); ++iter) {
8686 const object::coff_symbol *Symbol = Obj.getCOFFSymbol(iter);
8787 COFFYAML::Symbol Sym;
8888 Obj.getSymbolName(Symbol, Sym.Name);