llvm.org GIT mirror llvm / 8175be5
Remove bogus std::error_code returns form SectionRef. There are two methods in SectionRef that can fail: * getName: The index into the string table can be invalid. * getContents: The section might point to invalid contents. Every other method will always succeed and returning and std::error_code just complicates the code. For example, a section can have an invalid alignment, but if we are able to get to the section structure at all and create a SectionRef, we will always be able to read that invalid alignment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219314 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
22 changed file(s) with 336 addition(s) and 554 deletion(s). Raw diff Collapse all Expand all
545545 void moveSectionNext(DataRefImpl &Sec) const override;
546546 std::error_code getSectionName(DataRefImpl Sec,
547547 StringRef &Res) const override;
548 std::error_code getSectionAddress(DataRefImpl Sec,
549 uint64_t &Res) const override;
550 std::error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const override;
548 uint64_t getSectionAddress(DataRefImpl Sec) const override;
549 uint64_t getSectionSize(DataRefImpl Sec) const override;
551550 std::error_code getSectionContents(DataRefImpl Sec,
552551 StringRef &Res) const override;
553 std::error_code getSectionAlignment(DataRefImpl Sec,
554 uint64_t &Res) const override;
555 std::error_code isSectionText(DataRefImpl Sec, bool &Res) const override;
556 std::error_code isSectionData(DataRefImpl Sec, bool &Res) const override;
557 std::error_code isSectionBSS(DataRefImpl Sec, bool &Res) const override;
558 std::error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const override;
559 std::error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const override;
560 std::error_code isSectionReadOnlyData(DataRefImpl Sec,
561 bool &Res) const override;
562 std::error_code isSectionRequiredForExecution(DataRefImpl Sec,
563 bool &Res) const override;
564 std::error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb,
565 bool &Result) const override;
552 uint64_t getSectionAlignment(DataRefImpl Sec) const override;
553 bool isSectionText(DataRefImpl Sec) const override;
554 bool isSectionData(DataRefImpl Sec) const override;
555 bool isSectionBSS(DataRefImpl Sec) const override;
556 bool isSectionVirtual(DataRefImpl Sec) const override;
557 bool isSectionZeroInit(DataRefImpl Sec) const override;
558 bool isSectionReadOnlyData(DataRefImpl Sec) const override;
559 bool isSectionRequiredForExecution(DataRefImpl Sec) const override;
560 bool sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb) const override;
566561 relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
567562 relocation_iterator section_rel_end(DataRefImpl Sec) const override;
568563
8888 void moveSectionNext(DataRefImpl &Sec) const override;
8989 std::error_code getSectionName(DataRefImpl Sec,
9090 StringRef &Res) const override;
91 std::error_code getSectionAddress(DataRefImpl Sec,
92 uint64_t &Res) const override;
93 std::error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const override;
91 uint64_t getSectionAddress(DataRefImpl Sec) const override;
92 uint64_t getSectionSize(DataRefImpl Sec) const override;
9493 std::error_code getSectionContents(DataRefImpl Sec,
9594 StringRef &Res) const override;
96 std::error_code getSectionAlignment(DataRefImpl Sec,
97 uint64_t &Res) const override;
98 std::error_code isSectionText(DataRefImpl Sec, bool &Res) const override;
99 std::error_code isSectionData(DataRefImpl Sec, bool &Res) const override;
100 std::error_code isSectionBSS(DataRefImpl Sec, bool &Res) const override;
101 std::error_code isSectionRequiredForExecution(DataRefImpl Sec,
102 bool &Res) const override;
103 std::error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const override;
104 std::error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const override;
105 std::error_code isSectionReadOnlyData(DataRefImpl Sec,
106 bool &Res) const override;
107 std::error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb,
108 bool &Result) const override;
95 uint64_t getSectionAlignment(DataRefImpl Sec) const override;
96 bool isSectionText(DataRefImpl Sec) const override;
97 bool isSectionData(DataRefImpl Sec) const override;
98 bool isSectionBSS(DataRefImpl Sec) const override;
99 bool isSectionRequiredForExecution(DataRefImpl Sec) const override;
100 bool isSectionVirtual(DataRefImpl Sec) const override;
101 bool isSectionZeroInit(DataRefImpl Sec) const override;
102 bool isSectionReadOnlyData(DataRefImpl Sec) const override;
103 bool sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb) const override;
109104 relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
110105 relocation_iterator section_rel_end(DataRefImpl Sec) const override;
111106 section_iterator getRelocatedSection(DataRefImpl Sec) const override;
412407 }
413408
414409 template
415 std::error_code ELFObjectFile::getSectionAddress(DataRefImpl Sec,
416 uint64_t &Result) const {
417 Result = toELFShdrIter(Sec)->sh_addr;
418 return object_error::success;
419 }
420
421 template
422 std::error_code ELFObjectFile::getSectionSize(DataRefImpl Sec,
423 uint64_t &Result) const {
424 Result = toELFShdrIter(Sec)->sh_size;
425 return object_error::success;
410 uint64_t ELFObjectFile::getSectionAddress(DataRefImpl Sec) const {
411 return toELFShdrIter(Sec)->sh_addr;
412 }
413
414 template
415 uint64_t ELFObjectFile::getSectionSize(DataRefImpl Sec) const {
416 return toELFShdrIter(Sec)->sh_size;
426417 }
427418
428419 template
435426 }
436427
437428 template
438 std::error_code
439 ELFObjectFile::getSectionAlignment(DataRefImpl Sec,
440 uint64_t &Result) const {
441 Result = toELFShdrIter(Sec)->sh_addralign;
442 return object_error::success;
443 }
444
445 template
446 std::error_code ELFObjectFile::isSectionText(DataRefImpl Sec,
447 bool &Result) const {
448 Result = toELFShdrIter(Sec)->sh_flags & ELF::SHF_EXECINSTR;
449 return object_error::success;
450 }
451
452 template
453 std::error_code ELFObjectFile::isSectionData(DataRefImpl Sec,
454 bool &Result) const {
429 uint64_t ELFObjectFile::getSectionAlignment(DataRefImpl Sec) const {
430 return toELFShdrIter(Sec)->sh_addralign;
431 }
432
433 template
434 bool ELFObjectFile::isSectionText(DataRefImpl Sec) const {
435 return toELFShdrIter(Sec)->sh_flags & ELF::SHF_EXECINSTR;
436 }
437
438 template
439 bool ELFObjectFile::isSectionData(DataRefImpl Sec) const {
455440 Elf_Shdr_Iter EShdr = toELFShdrIter(Sec);
456 Result = EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
457 EShdr->sh_type == ELF::SHT_PROGBITS;
458 return object_error::success;
459 }
460
461 template
462 std::error_code ELFObjectFile::isSectionBSS(DataRefImpl Sec,
463 bool &Result) const {
441 return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
442 EShdr->sh_type == ELF::SHT_PROGBITS;
443 }
444
445 template
446 bool ELFObjectFile::isSectionBSS(DataRefImpl Sec) const {
464447 Elf_Shdr_Iter EShdr = toELFShdrIter(Sec);
465 Result = EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
466 EShdr->sh_type == ELF::SHT_NOBITS;
467 return object_error::success;
468 }
469
470 template
471 std::error_code
472 ELFObjectFile::isSectionRequiredForExecution(DataRefImpl Sec,
473 bool &Result) const {
474 Result = toELFShdrIter(Sec)->sh_flags & ELF::SHF_ALLOC;
475 return object_error::success;
476 }
477
478 template
479 std::error_code ELFObjectFile::isSectionVirtual(DataRefImpl Sec,
480 bool &Result) const {
481 Result = toELFShdrIter(Sec)->sh_type == ELF::SHT_NOBITS;
482 return object_error::success;
483 }
484
485 template
486 std::error_code ELFObjectFile::isSectionZeroInit(DataRefImpl Sec,
487 bool &Result) const {
488 Result = toELFShdrIter(Sec)->sh_type == ELF::SHT_NOBITS;
489 return object_error::success;
490 }
491
492 template
493 std::error_code ELFObjectFile::isSectionReadOnlyData(DataRefImpl Sec,
494 bool &Result) const {
448 return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
449 EShdr->sh_type == ELF::SHT_NOBITS;
450 }
451
452 template
453 bool ELFObjectFile::isSectionRequiredForExecution(DataRefImpl Sec) const {
454 return toELFShdrIter(Sec)->sh_flags & ELF::SHF_ALLOC;
455 }
456
457 template
458 bool ELFObjectFile::isSectionVirtual(DataRefImpl Sec) const {
459 return toELFShdrIter(Sec)->sh_type == ELF::SHT_NOBITS;
460 }
461
462 template
463 bool ELFObjectFile::isSectionZeroInit(DataRefImpl Sec) const {
464 return toELFShdrIter(Sec)->sh_type == ELF::SHT_NOBITS;
465 }
466
467 template
468 bool ELFObjectFile::isSectionReadOnlyData(DataRefImpl Sec) const {
495469 Elf_Shdr_Iter EShdr = toELFShdrIter(Sec);
496 Result = !(EShdr->sh_flags & (ELF::SHF_WRITE | ELF::SHF_EXECINSTR));
497 return object_error::success;
498 }
499
500 template
501 std::error_code ELFObjectFile::sectionContainsSymbol(DataRefImpl Sec,
502 DataRefImpl Symb,
503 bool &Result) const {
470 return !(EShdr->sh_flags & (ELF::SHF_WRITE | ELF::SHF_EXECINSTR));
471 }
472
473 template
474 bool ELFObjectFile::sectionContainsSymbol(DataRefImpl Sec,
475 DataRefImpl Symb) const {
504476 Elf_Sym_Iter ESym = toELFSymIter(Symb);
505477
506478 uintX_t Index = ESym->st_shndx;
507479 bool Reserved = Index >= ELF::SHN_LORESERVE && Index <= ELF::SHN_HIRESERVE;
508480
509 Result = !Reserved && (&*toELFShdrIter(Sec) == EF.getSection(ESym->st_shndx));
510 return object_error::success;
481 return !Reserved && (&*toELFShdrIter(Sec) == EF.getSection(ESym->st_shndx));
511482 }
512483
513484 template
214214 void moveSectionNext(DataRefImpl &Sec) const override;
215215 std::error_code getSectionName(DataRefImpl Sec,
216216 StringRef &Res) const override;
217 std::error_code getSectionAddress(DataRefImpl Sec,
218 uint64_t &Res) const override;
219 std::error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const override;
217 uint64_t getSectionAddress(DataRefImpl Sec) const override;
218 uint64_t getSectionSize(DataRefImpl Sec) const override;
220219 std::error_code getSectionContents(DataRefImpl Sec,
221220 StringRef &Res) const override;
222 std::error_code getSectionAlignment(DataRefImpl Sec,
223 uint64_t &Res) const override;
224 std::error_code isSectionText(DataRefImpl Sec, bool &Res) const override;
225 std::error_code isSectionData(DataRefImpl Sec, bool &Res) const override;
226 std::error_code isSectionBSS(DataRefImpl Sec, bool &Res) const override;
227 std::error_code isSectionRequiredForExecution(DataRefImpl Sec,
228 bool &Res) const override;
229 std::error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const override;
230 std::error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const override;
231 std::error_code isSectionReadOnlyData(DataRefImpl Sec,
232 bool &Res) const override;
233 std::error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb,
234 bool &Result) const override;
221 uint64_t getSectionAlignment(DataRefImpl Sec) const override;
222 bool isSectionText(DataRefImpl Sec) const override;
223 bool isSectionData(DataRefImpl Sec) const override;
224 bool isSectionBSS(DataRefImpl Sec) const override;
225 bool isSectionRequiredForExecution(DataRefImpl Sec) const override;
226 bool isSectionVirtual(DataRefImpl Sec) const override;
227 bool isSectionZeroInit(DataRefImpl Sec) const override;
228 bool isSectionReadOnlyData(DataRefImpl Sec) const override;
229 bool sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb) const override;
235230 relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
236231 relocation_iterator section_rel_end(DataRefImpl Sec) const override;
237232
9494 void moveNext();
9595
9696 std::error_code getName(StringRef &Result) const;
97 std::error_code getAddress(uint64_t &Result) const;
98 std::error_code getSize(uint64_t &Result) const;
97 uint64_t getAddress() const;
98 uint64_t getSize() const;
9999 std::error_code getContents(StringRef &Result) const;
100100
101101 /// @brief Get the alignment of this section as the actual value (not log 2).
102 std::error_code getAlignment(uint64_t &Result) const;
103
104 std::error_code isText(bool &Result) const;
105 std::error_code isData(bool &Result) const;
106 std::error_code isBSS(bool &Result) const;
107 std::error_code isRequiredForExecution(bool &Result) const;
108 std::error_code isVirtual(bool &Result) const;
109 std::error_code isZeroInit(bool &Result) const;
110 std::error_code isReadOnlyData(bool &Result) const;
111
112 std::error_code containsSymbol(SymbolRef S, bool &Result) const;
102 uint64_t getAlignment() const;
103
104 bool isText() const;
105 bool isData() const;
106 bool isBSS() const;
107 bool isRequiredForExecution() const;
108 bool isVirtual() const;
109 bool isZeroInit() const;
110 bool isReadOnlyData() const;
111
112 bool containsSymbol(SymbolRef S) const;
113113
114114 relocation_iterator relocation_begin() const;
115115 relocation_iterator relocation_end() const;
224224 virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
225225 virtual std::error_code getSectionName(DataRefImpl Sec,
226226 StringRef &Res) const = 0;
227 virtual std::error_code getSectionAddress(DataRefImpl Sec,
228 uint64_t &Res) const = 0;
229 virtual std::error_code getSectionSize(DataRefImpl Sec,
230 uint64_t &Res) const = 0;
227 virtual uint64_t getSectionAddress(DataRefImpl Sec) const = 0;
228 virtual uint64_t getSectionSize(DataRefImpl Sec) const = 0;
231229 virtual std::error_code getSectionContents(DataRefImpl Sec,
232230 StringRef &Res) const = 0;
233 virtual std::error_code getSectionAlignment(DataRefImpl Sec,
234 uint64_t &Res) const = 0;
235 virtual std::error_code isSectionText(DataRefImpl Sec, bool &Res) const = 0;
236 virtual std::error_code isSectionData(DataRefImpl Sec, bool &Res) const = 0;
237 virtual std::error_code isSectionBSS(DataRefImpl Sec, bool &Res) const = 0;
238 virtual std::error_code isSectionRequiredForExecution(DataRefImpl Sec,
239 bool &Res) const = 0;
231 virtual uint64_t getSectionAlignment(DataRefImpl Sec) const = 0;
232 virtual bool isSectionText(DataRefImpl Sec) const = 0;
233 virtual bool isSectionData(DataRefImpl Sec) const = 0;
234 virtual bool isSectionBSS(DataRefImpl Sec) const = 0;
235 virtual bool isSectionRequiredForExecution(DataRefImpl Sec) const = 0;
240236 // A section is 'virtual' if its contents aren't present in the object image.
241 virtual std::error_code isSectionVirtual(DataRefImpl Sec,
242 bool &Res) const = 0;
243 virtual std::error_code isSectionZeroInit(DataRefImpl Sec,
244 bool &Res) const = 0;
245 virtual std::error_code isSectionReadOnlyData(DataRefImpl Sec,
246 bool &Res) const = 0;
247 virtual std::error_code sectionContainsSymbol(DataRefImpl Sec,
248 DataRefImpl Symb,
249 bool &Result) const = 0;
237 virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
238 virtual bool isSectionZeroInit(DataRefImpl Sec) const = 0;
239 virtual bool isSectionReadOnlyData(DataRefImpl Sec) const = 0;
240 virtual bool sectionContainsSymbol(DataRefImpl Sec,
241 DataRefImpl Symb) const = 0;
250242 virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
251243 virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
252244 virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
396388 return OwningObject->getSectionName(SectionPimpl, Result);
397389 }
398390
399 inline std::error_code SectionRef::getAddress(uint64_t &Result) const {
400 return OwningObject->getSectionAddress(SectionPimpl, Result);
401 }
402
403 inline std::error_code SectionRef::getSize(uint64_t &Result) const {
404 return OwningObject->getSectionSize(SectionPimpl, Result);
391 inline uint64_t SectionRef::getAddress() const {
392 return OwningObject->getSectionAddress(SectionPimpl);
393 }
394
395 inline uint64_t SectionRef::getSize() const {
396 return OwningObject->getSectionSize(SectionPimpl);
405397 }
406398
407399 inline std::error_code SectionRef::getContents(StringRef &Result) const {
408400 return OwningObject->getSectionContents(SectionPimpl, Result);
409401 }
410402
411 inline std::error_code SectionRef::getAlignment(uint64_t &Result) const {
412 return OwningObject->getSectionAlignment(SectionPimpl, Result);
413 }
414
415 inline std::error_code SectionRef::isText(bool &Result) const {
416 return OwningObject->isSectionText(SectionPimpl, Result);
417 }
418
419 inline std::error_code SectionRef::isData(bool &Result) const {
420 return OwningObject->isSectionData(SectionPimpl, Result);
421 }
422
423 inline std::error_code SectionRef::isBSS(bool &Result) const {
424 return OwningObject->isSectionBSS(SectionPimpl, Result);
425 }
426
427 inline std::error_code SectionRef::isRequiredForExecution(bool &Result) const {
428 return OwningObject->isSectionRequiredForExecution(SectionPimpl, Result);
429 }
430
431 inline std::error_code SectionRef::isVirtual(bool &Result) const {
432 return OwningObject->isSectionVirtual(SectionPimpl, Result);
433 }
434
435 inline std::error_code SectionRef::isZeroInit(bool &Result) const {
436 return OwningObject->isSectionZeroInit(SectionPimpl, Result);
437 }
438
439 inline std::error_code SectionRef::isReadOnlyData(bool &Result) const {
440 return OwningObject->isSectionReadOnlyData(SectionPimpl, Result);
441 }
442
443 inline std::error_code SectionRef::containsSymbol(SymbolRef S,
444 bool &Result) const {
403 inline uint64_t SectionRef::getAlignment() const {
404 return OwningObject->getSectionAlignment(SectionPimpl);
405 }
406
407 inline bool SectionRef::isText() const {
408 return OwningObject->isSectionText(SectionPimpl);
409 }
410
411 inline bool SectionRef::isData() const {
412 return OwningObject->isSectionData(SectionPimpl);
413 }
414
415 inline bool SectionRef::isBSS() const {
416 return OwningObject->isSectionBSS(SectionPimpl);
417 }
418
419 inline bool SectionRef::isRequiredForExecution() const {
420 return OwningObject->isSectionRequiredForExecution(SectionPimpl);
421 }
422
423 inline bool SectionRef::isVirtual() const {
424 return OwningObject->isSectionVirtual(SectionPimpl);
425 }
426
427 inline bool SectionRef::isZeroInit() const {
428 return OwningObject->isSectionZeroInit(SectionPimpl);
429 }
430
431 inline bool SectionRef::isReadOnlyData() const {
432 return OwningObject->isSectionReadOnlyData(SectionPimpl);
433 }
434
435 inline bool SectionRef::containsSymbol(SymbolRef S) const {
445436 return OwningObject->sectionContainsSymbol(SectionPimpl,
446 S.getRawDataRefImpl(), Result);
437 S.getRawDataRefImpl());
447438 }
448439
449440 inline relocation_iterator SectionRef::relocation_begin() const {
515515 StringRef name;
516516 Section.getName(name);
517517 // Skip BSS and Virtual sections, they aren't interesting.
518 bool IsBSS;
519 Section.isBSS(IsBSS);
518 bool IsBSS = Section.isBSS();
520519 if (IsBSS)
521520 continue;
522 bool IsVirtual;
523 Section.isVirtual(IsVirtual);
521 bool IsVirtual = Section.isVirtual();
524522 if (IsVirtual)
525523 continue;
526524 StringRef data;
611609 }
612610
613611 if (Section.relocation_begin() != Section.relocation_end()) {
614 uint64_t SectionSize;
615 RelocatedSection->getSize(SectionSize);
612 uint64_t SectionSize = RelocatedSection->getSize();
616613 for (const RelocationRef &Reloc : Section.relocations()) {
617614 uint64_t Address;
618615 Reloc.getOffset(Address);
133133 return object_error::success;
134134 }
135135
136 uint64_t SectionAddress;
137 if (std::error_code EC = SecI->getAddress(SectionAddress))
138 return EC;
139
136 uint64_t SectionAddress = SecI->getAddress();
140137 Result = Address - SectionAddress;
141138 return object_error::success;
142139 }
198195 SymType == object::SymbolRef::ST_Unknown) {
199196 uint64_t SectOffset;
200197 StringRef SectionData;
201 bool IsCode;
202198 section_iterator SI = Obj->end_sections();
203199 Check(getOffset(*I, SectOffset));
204200 Check(I->getSection(SI));
205201 if (SI == Obj->end_sections())
206202 continue;
207203 Check(SI->getContents(SectionData));
208 Check(SI->isText(IsCode));
204 bool IsCode = SI->isText();
209205 unsigned SectionID =
210206 findOrEmitSection(*Obj, *SI, IsCode, LocalSections);
211207 LocalSymbols[Name.data()] = SymbolLoc(SectionID, SectOffset);
235231 if (I == E && !ProcessAllSections)
236232 continue;
237233
238 bool IsCode = false;
239 Check(RelocatedSection->isText(IsCode));
234 bool IsCode = RelocatedSection->isText();
240235 SectionID =
241236 findOrEmitSection(*Obj, *RelocatedSection, IsCode, LocalSections);
242237 DEBUG(dbgs() << "\tSectionID: " << SectionID << "\n");
290285 SI != SE; ++SI) {
291286 const SectionRef &Section = *SI;
292287
293 bool IsRequired;
294 Check(Section.isRequiredForExecution(IsRequired));
288 bool IsRequired = Section.isRequiredForExecution();
295289
296290 // Consider only the sections that are required to be loaded for execution
297291 if (IsRequired) {
298 uint64_t DataSize = 0;
299 uint64_t Alignment64 = 0;
300 bool IsCode = false;
301 bool IsReadOnly = false;
302292 StringRef Name;
303 Check(Section.getSize(DataSize));
304 Check(Section.getAlignment(Alignment64));
305 Check(Section.isText(IsCode));
306 Check(Section.isReadOnlyData(IsReadOnly));
293 uint64_t DataSize = Section.getSize();
294 uint64_t Alignment64 = Section.getAlignment();
295 bool IsCode = Section.isText();
296 bool IsReadOnly = Section.isReadOnlyData();
307297 Check(Section.getName(Name));
308298 unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL;
309299
385375 }
386376
387377 // Get section data size and alignment
388 uint64_t Alignment64;
389 uint64_t DataSize;
390 Check(Section.getSize(DataSize));
391 Check(Section.getAlignment(Alignment64));
378 uint64_t DataSize = Section.getSize();
379 uint64_t Alignment64 = Section.getAlignment();
392380
393381 // Add stubbuf size alignment
394382 unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL;
472460 const SectionRef &Section, bool IsCode) {
473461
474462 StringRef data;
475 uint64_t Alignment64;
476463 Check(Section.getContents(data));
477 Check(Section.getAlignment(Alignment64));
464 uint64_t Alignment64 = Section.getAlignment();
478465
479466 unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL;
480 bool IsRequired;
481 bool IsVirtual;
482 bool IsZeroInit;
483 bool IsReadOnly;
484 uint64_t DataSize;
485467 unsigned PaddingSize = 0;
486468 unsigned StubBufSize = 0;
487469 StringRef Name;
488 Check(Section.isRequiredForExecution(IsRequired));
489 Check(Section.isVirtual(IsVirtual));
490 Check(Section.isZeroInit(IsZeroInit));
491 Check(Section.isReadOnlyData(IsReadOnly));
492 Check(Section.getSize(DataSize));
470 bool IsRequired = Section.isRequiredForExecution();
471 bool IsVirtual = Section.isVirtual();
472 bool IsZeroInit = Section.isZeroInit();
473 bool IsReadOnly = Section.isReadOnlyData();
474 uint64_t DataSize = Section.getSize();
493475 Check(Section.getName(Name));
494476
495477 StubBufSize = computeSectionStubBufSize(Obj, Section);
701701
702702 section_iterator tsi(Obj.end_sections());
703703 check(TargetSymbol->getSection(tsi));
704 bool IsCode = false;
705 tsi->isText(IsCode);
704 bool IsCode = tsi->isText();
706705 Rel.SectionID = findOrEmitSection(Obj, (*tsi), IsCode, LocalSections);
707706 Rel.Addend = (intptr_t)Addend;
708707 return;
982981 if (si == Obj.end_sections())
983982 llvm_unreachable("Symbol section not found, bad object file format!");
984983 DEBUG(dbgs() << "\t\tThis is section symbol\n");
985 // Default to 'true' in case isText fails (though it never does).
986 bool isCode = true;
987 si->isText(isCode);
984 bool isCode = si->isText();
988985 Value.SectionID = findOrEmitSection(Obj, (*si), isCode, ObjSectionToID);
989986 Value.Addend = Addend;
990987 break;
6565 }
6666 } else {
6767 SectionRef Sec = Obj.getRelocationSection(RelInfo);
68 bool IsCode = false;
69 Sec.isText(IsCode);
68 bool IsCode = Sec.isText();
7069 Value.SectionID = findOrEmitSection(ObjImg, Sec, IsCode, ObjSectionToID);
71 uint64_t Addr;
72 Sec.getAddress(Addr);
70 uint64_t Addr = Sec.getAddress();
7371 Value.Offset = RE.Addend - Addr;
7472 }
7573
114112 section_iterator SE = Obj.section_end();
115113
116114 for (; SI != SE; ++SI) {
117 uint64_t SAddr, SSize;
118 SI->getAddress(SAddr);
119 SI->getSize(SSize);
115 uint64_t SAddr = SI->getAddress();
116 uint64_t SSize = SI->getSize();
120117 if ((Addr >= SAddr) && (Addr < SAddr + SSize))
121118 return SI;
122119 }
231231 uint32_t AddrA = MachO->getScatteredRelocationValue(RE);
232232 section_iterator SAI = getSectionByAddress(*MachO, AddrA);
233233 assert(SAI != MachO->section_end() && "Can't find section for address A");
234 uint64_t SectionABase;
235 SAI->getAddress(SectionABase);
234 uint64_t SectionABase = SAI->getAddress();
236235 uint64_t SectionAOffset = AddrA - SectionABase;
237236 SectionRef SectionA = *SAI;
238 bool IsCode;
239 SectionA.isText(IsCode);
237 bool IsCode = SectionA.isText();
240238 uint32_t SectionAID =
241239 findOrEmitSection(Obj, SectionA, IsCode, ObjSectionToID);
242240
243241 uint32_t AddrB = MachO->getScatteredRelocationValue(RE2);
244242 section_iterator SBI = getSectionByAddress(*MachO, AddrB);
245243 assert(SBI != MachO->section_end() && "Can't find section for address B");
246 uint64_t SectionBBase;
247 SBI->getAddress(SectionBBase);
244 uint64_t SectionBBase = SBI->getAddress();
248245 uint64_t SectionBOffset = AddrB - SectionBBase;
249246 SectionRef SectionB = *SBI;
250247 uint32_t SectionBID =
151151 uint32_t AddrA = MachO->getScatteredRelocationValue(RE);
152152 section_iterator SAI = getSectionByAddress(*MachO, AddrA);
153153 assert(SAI != MachO->section_end() && "Can't find section for address A");
154 uint64_t SectionABase;
155 SAI->getAddress(SectionABase);
154 uint64_t SectionABase = SAI->getAddress();
156155 uint64_t SectionAOffset = AddrA - SectionABase;
157156 SectionRef SectionA = *SAI;
158 bool IsCode;
159 SectionA.isText(IsCode);
157 bool IsCode = SectionA.isText();
160158 uint32_t SectionAID =
161159 findOrEmitSection(Obj, SectionA, IsCode, ObjSectionToID);
162160
163161 uint32_t AddrB = MachO->getScatteredRelocationValue(RE2);
164162 section_iterator SBI = getSectionByAddress(*MachO, AddrB);
165163 assert(SBI != MachO->section_end() && "Can't find section for address B");
166 uint64_t SectionBBase;
167 SBI->getAddress(SectionBBase);
164 uint64_t SectionBBase = SBI->getAddress();
168165 uint64_t SectionBOffset = AddrB - SectionBBase;
169166 SectionRef SectionB = *SBI;
170167 uint32_t SectionBID =
210207 unsigned SymbolBaseAddr = MachO->getScatteredRelocationValue(RE);
211208 section_iterator TargetSI = getSectionByAddress(*MachO, SymbolBaseAddr);
212209 assert(TargetSI != MachO->section_end() && "Can't find section for symbol");
213 uint64_t SectionBaseAddr;
214 TargetSI->getAddress(SectionBaseAddr);
210 uint64_t SectionBaseAddr = TargetSI->getAddress();
215211 SectionRef TargetSection = *TargetSI;
216 bool IsCode;
217 TargetSection.isText(IsCode);
212 bool IsCode = TargetSection.isText();
218213 uint32_t TargetSectionID =
219214 findOrEmitSection(Obj, TargetSection, IsCode, ObjSectionToID);
220215
259259 return getSectionName(Sec, Result);
260260 }
261261
262 std::error_code COFFObjectFile::getSectionAddress(DataRefImpl Ref,
263 uint64_t &Result) const {
262 uint64_t COFFObjectFile::getSectionAddress(DataRefImpl Ref) const {
264263 const coff_section *Sec = toSec(Ref);
265 Result = Sec->VirtualAddress;
266 return object_error::success;
267 }
268
269 std::error_code COFFObjectFile::getSectionSize(DataRefImpl Ref,
270 uint64_t &Result) const {
264 return Sec->VirtualAddress;
265 }
266
267 uint64_t COFFObjectFile::getSectionSize(DataRefImpl Ref) const {
271268 const coff_section *Sec = toSec(Ref);
272 Result = Sec->SizeOfRawData;
273 return object_error::success;
269 return Sec->SizeOfRawData;
274270 }
275271
276272 std::error_code COFFObjectFile::getSectionContents(DataRefImpl Ref,
282278 return EC;
283279 }
284280
285 std::error_code COFFObjectFile::getSectionAlignment(DataRefImpl Ref,
286 uint64_t &Res) const {
281 uint64_t COFFObjectFile::getSectionAlignment(DataRefImpl Ref) const {
287282 const coff_section *Sec = toSec(Ref);
288 Res = uint64_t(1) << (((Sec->Characteristics & 0x00F00000) >> 20) - 1);
289 return object_error::success;
290 }
291
292 std::error_code COFFObjectFile::isSectionText(DataRefImpl Ref,
293 bool &Result) const {
283 return uint64_t(1) << (((Sec->Characteristics & 0x00F00000) >> 20) - 1);
284 }
285
286 bool COFFObjectFile::isSectionText(DataRefImpl Ref) const {
294287 const coff_section *Sec = toSec(Ref);
295 Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_CODE;
296 return object_error::success;
297 }
298
299 std::error_code COFFObjectFile::isSectionData(DataRefImpl Ref,
300 bool &Result) const {
288 return Sec->Characteristics & COFF::IMAGE_SCN_CNT_CODE;
289 }
290
291 bool COFFObjectFile::isSectionData(DataRefImpl Ref) const {
301292 const coff_section *Sec = toSec(Ref);
302 Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
303 return object_error::success;
304 }
305
306 std::error_code COFFObjectFile::isSectionBSS(DataRefImpl Ref,
307 bool &Result) const {
293 return Sec->Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
294 }
295
296 bool COFFObjectFile::isSectionBSS(DataRefImpl Ref) const {
308297 const coff_section *Sec = toSec(Ref);
309 Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
310 return object_error::success;
311 }
312
313 std::error_code
314 COFFObjectFile::isSectionRequiredForExecution(DataRefImpl Ref,
315 bool &Result) const {
298 return Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
299 }
300
301 bool COFFObjectFile::isSectionRequiredForExecution(DataRefImpl Ref) const {
316302 // FIXME: Unimplemented
317 Result = true;
318 return object_error::success;
319 }
320
321 std::error_code COFFObjectFile::isSectionVirtual(DataRefImpl Ref,
322 bool &Result) const {
303 return true;
304 }
305
306 bool COFFObjectFile::isSectionVirtual(DataRefImpl Ref) const {
323307 const coff_section *Sec = toSec(Ref);
324 Result = Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
325 return object_error::success;
326 }
327
328 std::error_code COFFObjectFile::isSectionZeroInit(DataRefImpl Ref,
329 bool &Result) const {
308 return Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
309 }
310
311 bool COFFObjectFile::isSectionZeroInit(DataRefImpl Ref) const {
330312 // FIXME: Unimplemented.
331 Result = false;
332 return object_error::success;
333 }
334
335 std::error_code COFFObjectFile::isSectionReadOnlyData(DataRefImpl Ref,
336 bool &Result) const {
313 return false;
314 }
315
316 bool COFFObjectFile::isSectionReadOnlyData(DataRefImpl Ref) const {
337317 // FIXME: Unimplemented.
338 Result = false;
339 return object_error::success;
340 }
341
342 std::error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef,
343 DataRefImpl SymbRef,
344 bool &Result) const {
318 return false;
319 }
320
321 bool COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef,
322 DataRefImpl SymbRef) const {
345323 const coff_section *Sec = toSec(SecRef);
346324 COFFSymbolRef Symb = getCOFFSymbol(SymbRef);
347325 int32_t SecNumber = (Sec - SectionTable) + 1;
348 Result = SecNumber == Symb.getSectionNumber();
349 return object_error::success;
326 return SecNumber == Symb.getSectionNumber();
350327 }
351328
352329 relocation_iterator COFFObjectFile::section_rel_begin(DataRefImpl Ref) const {
143143 // to find a section beginning instead.
144144 for (const SectionRef &Section : O->sections()) {
145145 std::error_code ec;
146 uint64_t Addr;
146
147147 StringRef Name;
148
149 if ((ec = Section.getAddress(Addr)))
150 report_fatal_error(ec.message());
148 uint64_t Addr = Section.getAddress();
151149 if (Addr != Val)
152150 continue;
153151 if ((ec = Section.getName(Name)))
393391 EndOffset = Value;
394392 }
395393 if (!EndOffset) {
396 uint64_t Size;
397394 DataRefImpl Sec;
398395 Sec.d.a = SectionIndex-1;
399 getSectionSize(Sec, Size);
400 getSectionAddress(Sec, EndOffset);
396 uint64_t Size = getSectionSize(Sec);
397 EndOffset = getSectionAddress(Sec);
401398 EndOffset += Size;
402399 }
403400 Result = EndOffset - BeginOffset;
494491 return object_error::success;
495492 }
496493
497 std::error_code MachOObjectFile::getSectionAddress(DataRefImpl Sec,
498 uint64_t &Res) const {
499 if (is64Bit()) {
500 MachO::section_64 Sect = getSection64(Sec);
501 Res = Sect.addr;
502 } else {
503 MachO::section Sect = getSection(Sec);
504 Res = Sect.addr;
505 }
506 return object_error::success;
507 }
508
509 std::error_code MachOObjectFile::getSectionSize(DataRefImpl Sec,
510 uint64_t &Res) const {
511 if (is64Bit()) {
512 MachO::section_64 Sect = getSection64(Sec);
513 Res = Sect.size;
514 } else {
515 MachO::section Sect = getSection(Sec);
516 Res = Sect.size;
517 }
518
519 return object_error::success;
494 uint64_t MachOObjectFile::getSectionAddress(DataRefImpl Sec) const {
495 if (is64Bit())
496 return getSection64(Sec).addr;
497 return getSection(Sec).addr;
498 }
499
500 uint64_t MachOObjectFile::getSectionSize(DataRefImpl Sec) const {
501 if (is64Bit())
502 return getSection64(Sec).size;
503 return getSection(Sec).size;
520504 }
521505
522506 std::error_code MachOObjectFile::getSectionContents(DataRefImpl Sec,
538522 return object_error::success;
539523 }
540524
541 std::error_code MachOObjectFile::getSectionAlignment(DataRefImpl Sec,
542 uint64_t &Res) const {
525 uint64_t MachOObjectFile::getSectionAlignment(DataRefImpl Sec) const {
543526 uint32_t Align;
544527 if (is64Bit()) {
545528 MachO::section_64 Sect = getSection64(Sec);
549532 Align = Sect.align;
550533 }
551534
552 Res = uint64_t(1) << Align;
553 return object_error::success;
554 }
555
556 std::error_code MachOObjectFile::isSectionText(DataRefImpl Sec,
557 bool &Res) const {
535 return uint64_t(1) << Align;
536 }
537
538 bool MachOObjectFile::isSectionText(DataRefImpl Sec) const {
558539 uint32_t Flags = getSectionFlags(this, Sec);
559 Res = Flags & MachO::S_ATTR_PURE_INSTRUCTIONS;
560 return object_error::success;
561 }
562
563 std::error_code MachOObjectFile::isSectionData(DataRefImpl Sec,
564 bool &Result) const {
540 return Flags & MachO::S_ATTR_PURE_INSTRUCTIONS;
541 }
542
543 bool MachOObjectFile::isSectionData(DataRefImpl Sec) const {
565544 uint32_t Flags = getSectionFlags(this, Sec);
566545 unsigned SectionType = Flags & MachO::SECTION_TYPE;
567 Result = !(Flags & MachO::S_ATTR_PURE_INSTRUCTIONS) &&
568 !(SectionType == MachO::S_ZEROFILL ||
569 SectionType == MachO::S_GB_ZEROFILL);
570 return object_error::success;
571 }
572
573 std::error_code MachOObjectFile::isSectionBSS(DataRefImpl Sec,
574 bool &Result) const {
546 return !(Flags & MachO::S_ATTR_PURE_INSTRUCTIONS) &&
547 !(SectionType == MachO::S_ZEROFILL ||
548 SectionType == MachO::S_GB_ZEROFILL);
549 }
550
551 bool MachOObjectFile::isSectionBSS(DataRefImpl Sec) const {
575552 uint32_t Flags = getSectionFlags(this, Sec);
576553 unsigned SectionType = Flags & MachO::SECTION_TYPE;
577 Result = !(Flags & MachO::S_ATTR_PURE_INSTRUCTIONS) &&
578 (SectionType == MachO::S_ZEROFILL ||
579 SectionType == MachO::S_GB_ZEROFILL);
580 return object_error::success;
581 }
582
583 std::error_code
584 MachOObjectFile::isSectionRequiredForExecution(DataRefImpl Sec,
585 bool &Result) const {
554 return !(Flags & MachO::S_ATTR_PURE_INSTRUCTIONS) &&
555 (SectionType == MachO::S_ZEROFILL ||
556 SectionType == MachO::S_GB_ZEROFILL);
557 }
558
559 bool MachOObjectFile::isSectionRequiredForExecution(DataRefImpl Sect) const {
586560 // FIXME: Unimplemented.
587 Result = true;
588 return object_error::success;
589 }
590
591 std::error_code MachOObjectFile::isSectionVirtual(DataRefImpl Sec,
592 bool &Result) const {
561 return true;
562 }
563
564 bool MachOObjectFile::isSectionVirtual(DataRefImpl Sec) const {
593565 // FIXME: Unimplemented.
594 Result = false;
595 return object_error::success;
596 }
597
598 std::error_code MachOObjectFile::isSectionZeroInit(DataRefImpl Sec,
599 bool &Res) const {
566 return false;
567 }
568
569 bool MachOObjectFile::isSectionZeroInit(DataRefImpl Sec) const {
600570 uint32_t Flags = getSectionFlags(this, Sec);
601571 unsigned SectionType = Flags & MachO::SECTION_TYPE;
602 Res = SectionType == MachO::S_ZEROFILL ||
603 SectionType == MachO::S_GB_ZEROFILL;
604 return object_error::success;
605 }
606
607 std::error_code MachOObjectFile::isSectionReadOnlyData(DataRefImpl Sec,
608 bool &Result) const {
572 return SectionType == MachO::S_ZEROFILL ||
573 SectionType == MachO::S_GB_ZEROFILL;
574 }
575
576 bool MachOObjectFile::isSectionReadOnlyData(DataRefImpl Sec) const {
609577 // Consider using the code from isSectionText to look for __const sections.
610578 // Alternately, emit S_ATTR_PURE_INSTRUCTIONS and/or S_ATTR_SOME_INSTRUCTIONS
611579 // to use section attributes to distinguish code from data.
612580
613581 // FIXME: Unimplemented.
614 Result = false;
615 return object_error::success;
616 }
617
618 std::error_code MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
619 DataRefImpl Symb,
620 bool &Result) const {
582 return false;
583 }
584
585 bool MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
586 DataRefImpl Symb) const {
621587 SymbolRef::Type ST;
622588 this->getSymbolType(Symb, ST);
623 if (ST == SymbolRef::ST_Unknown) {
624 Result = false;
625 return object_error::success;
626 }
627
628 uint64_t SectBegin, SectEnd;
629 getSectionAddress(Sec, SectBegin);
630 getSectionSize(Sec, SectEnd);
589 if (ST == SymbolRef::ST_Unknown)
590 return false;
591
592 uint64_t SectBegin = getSectionAddress(Sec);
593 uint64_t SectEnd = getSectionSize(Sec);
631594 SectEnd += SectBegin;
632595
633596 uint64_t SymAddr;
634597 getSymbolAddress(Symb, SymAddr);
635 Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
636
637 return object_error::success;
598 return (SymAddr >= SectBegin) && (SymAddr < SectEnd);
638599 }
639600
640601 relocation_iterator MachOObjectFile::section_rel_begin(DataRefImpl Sec) const {
672633
673634 DataRefImpl Sec;
674635 Sec.d.a = Rel.d.a;
675 uint64_t SecAddress;
676 getSectionAddress(Sec, SecAddress);
636 uint64_t SecAddress = getSectionAddress(Sec);
677637 Res = SecAddress + Offset;
678638 return object_error::success;
679639 }
131131 }
132132
133133 uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) {
134 uint64_t ret;
135 if (std::error_code ec = (*unwrap(SI))->getSize(ret))
136 report_fatal_error(ec.message());
137 return ret;
134 return (*unwrap(SI))->getSize();
138135 }
139136
140137 const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) {
145142 }
146143
147144 uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI) {
148 uint64_t ret;
149 if (std::error_code ec = (*unwrap(SI))->getAddress(ret))
150 report_fatal_error(ec.message());
151 return ret;
145 return (*unwrap(SI))->getAddress();
152146 }
153147
154148 LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
155149 LLVMSymbolIteratorRef Sym) {
156 bool ret;
157 if (std::error_code ec = (*unwrap(SI))->containsSymbol(**unwrap(Sym), ret))
158 report_fatal_error(ec.message());
159 return ret;
150 return (*unwrap(SI))->containsSymbol(**unwrap(Sym));
160151 }
161152
162153 // Section Relocation iterators
332332 std::error_code load(SectionRef &Section) {
333333 if (auto Err = Section.getContents(Data))
334334 return Err;
335 return Section.getAddress(Address);
335 Address = Section.getAddress();
336 return instrprof_error::success;
336337 }
337338
338339 std::error_code get(uint64_t Pointer, size_t Size, StringRef &Result) {
6666 return 1;
6767
6868 // Get the contents of the given sections.
69 uint64_t ProfileNamesAddress = ProfileNames.getAddress();
6970 StringRef CoverageMappingData;
70 uint64_t ProfileNamesAddress;
7171 StringRef ProfileNamesData;
7272 if (CoverageMapping.getContents(CoverageMappingData) ||
73 ProfileNames.getAddress(ProfileNamesAddress) ||
7473 ProfileNames.getContents(ProfileNamesData))
7574 return 1;
7675
282282 return 0;
283283 // First search the section's relocation entries (if any) for an entry
284284 // for this section offset.
285 uint64_t sect_addr;
286 info->S.getAddress(sect_addr);
285 uint64_t sect_addr = info->S.getAddress();
287286 uint64_t sect_offset = (Pc + Offset) - sect_addr;
288287 bool reloc_found = false;
289288 DataRefImpl Rel;
521520 return nullptr;
522521
523522 // First see if there is an external relocation entry at the ReferencePC.
524 uint64_t sect_addr;
525 info->S.getAddress(sect_addr);
523 uint64_t sect_addr = info->S.getAddress();
526524 uint64_t sect_offset = ReferencePC - sect_addr;
527525 bool reloc_found = false;
528526 DataRefImpl Rel;
819817 // Build a data in code table that is sorted on by the address of each entry.
820818 uint64_t BaseAddress = 0;
821819 if (Header.filetype == MachO::MH_OBJECT)
822 Sections[0].getAddress(BaseAddress);
820 BaseAddress = Sections[0].getAddress();
823821 else
824822 BaseAddress = BaseSegmentAddress;
825823 DiceTable Dices;
862860
863861 for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
864862
865 bool SectIsText = false;
866 Sections[SectIdx].isText(SectIsText);
863 bool SectIsText = Sections[SectIdx].isText();
867864 if (SectIsText == false)
868865 continue;
869866
880877
881878 StringRef Bytes;
882879 Sections[SectIdx].getContents(Bytes);
883 uint64_t SectAddress = 0;
884 Sections[SectIdx].getAddress(SectAddress);
880 uint64_t SectAddress = Sections[SectIdx].getAddress();
885881 DisasmMemoryObject MemoryObject((const uint8_t *)Bytes.data(), Bytes.size(),
886882 SectAddress);
887883 bool symbolTableWorked = false;
889885 // Parse relocations.
890886 std::vector> Relocs;
891887 for (const RelocationRef &Reloc : Sections[SectIdx].relocations()) {
892 uint64_t RelocOffset, SectionAddress;
888 uint64_t RelocOffset;
893889 Reloc.getOffset(RelocOffset);
894 Sections[SectIdx].getAddress(SectionAddress);
890 uint64_t SectionAddress = Sections[SectIdx].getAddress();
895891 RelocOffset -= SectionAddress;
896892
897893 symbol_iterator RelocSym = Reloc.getSymbol();
932928 continue;
933929
934930 // Make sure the symbol is defined in this section.
935 bool containsSym = false;
936 Sections[SectIdx].containsSymbol(Symbols[SymIdx], containsSym);
931 bool containsSym = Sections[SectIdx].containsSymbol(Symbols[SymIdx]);
937932 if (!containsSym)
938933 continue;
939934
940935 // Start at the address of the symbol relative to the section's address.
941 uint64_t SectionAddress = 0;
942936 uint64_t Start = 0;
943 Sections[SectIdx].getAddress(SectionAddress);
937 uint64_t SectionAddress = Sections[SectIdx].getAddress();
944938 Symbols[SymIdx].getAddress(Start);
945939 Start -= SectionAddress;
946940
953947 SymbolRef::Type NextSymType;
954948 Symbols[NextSymIdx].getType(NextSymType);
955949 if (NextSymType == SymbolRef::ST_Function) {
956 Sections[SectIdx].containsSymbol(Symbols[NextSymIdx],
957 containsNextSym);
950 containsNextSym =
951 Sections[SectIdx].containsSymbol(Symbols[NextSymIdx]);
958952 Symbols[NextSymIdx].getAddress(NextSym);
959953 NextSym -= SectionAddress;
960954 break;
962956 ++NextSymIdx;
963957 }
964958
965 uint64_t SectSize;
966 Sections[SectIdx].getSize(SectSize);
959 uint64_t SectSize = Sections[SectIdx].getSize();
967960 uint64_t End = containsNextSym ? NextSym : SectSize;
968961 uint64_t Size;
969962
10491042 }
10501043 }
10511044 if (!symbolTableWorked) {
1052 // Reading the symbol table didn't work, disassemble the whole section.
1053 uint64_t SectAddress;
1054 Sections[SectIdx].getAddress(SectAddress);
1055 uint64_t SectSize;
1056 Sections[SectIdx].getSize(SectSize);
1045 // Reading the symbol table didn't work, disassemble the whole section.
1046 uint64_t SectAddress = Sections[SectIdx].getAddress();
1047 uint64_t SectSize = Sections[SectIdx].getSize();
10571048 uint64_t InstSize;
10581049 for (uint64_t Index = 0; Index < SectSize; Index += InstSize) {
10591050 MCInst Inst;
11581149 auto RE = Obj->getRelocation(Reloc.getRawDataRefImpl());
11591150 SectionRef RelocSection = Obj->getRelocationSection(RE);
11601151
1161 uint64_t SectionAddr;
1162 RelocSection.getAddress(SectionAddr);
1152 uint64_t SectionAddr = RelocSection.getAddress();
11631153
11641154 auto Sym = Symbols.upper_bound(Addr);
11651155 if (Sym == Symbols.begin()) {
27302720 SectionInfo Info;
27312721 if (error(Section.getName(Info.SectionName)))
27322722 return;
2733 if (error(Section.getAddress(Info.Address)))
2734 return;
2735 if (error(Section.getSize(Info.Size)))
2736 return;
2723 Info.Address = Section.getAddress();
2724 Info.Size = Section.getSize();
27372725 Info.SegmentName =
27382726 Obj->getSectionFinalSegmentName(Section.getRawDataRefImpl());
27392727 if (!Info.SegmentName.equals(CurSegName)) {
306306 }
307307
308308 for (const SectionRef &Section : Obj->sections()) {
309 bool Text;
310 if (error(Section.isText(Text)))
311 break;
309 bool Text = Section.isText();
312310 if (!Text)
313311 continue;
314312
315 uint64_t SectionAddr;
316 if (error(Section.getAddress(SectionAddr)))
317 break;
318
319 uint64_t SectSize;
320 if (error(Section.getSize(SectSize)))
321 break;
313 uint64_t SectionAddr = Section.getAddress();
314 uint64_t SectSize = Section.getSize();
322315
323316 // Make a list of all the symbols in this section.
324317 std::vector> Symbols;
325318 for (const SymbolRef &Symbol : Obj->symbols()) {
326 bool contains;
327 if (!error(Section.containsSymbol(Symbol, contains)) && contains) {
319 if (Section.containsSymbol(Symbol)) {
328320 uint64_t Address;
329321 if (error(Symbol.getAddress(Address)))
330322 break;
500492 StringRef Name;
501493 if (error(Section.getName(Name)))
502494 return;
503 uint64_t Address;
504 if (error(Section.getAddress(Address)))
505 return;
506 uint64_t Size;
507 if (error(Section.getSize(Size)))
508 return;
509 bool Text, Data, BSS;
510 if (error(Section.isText(Text)))
511 return;
512 if (error(Section.isData(Data)))
513 return;
514 if (error(Section.isBSS(BSS)))
515 return;
495 uint64_t Address = Section.getAddress();
496 uint64_t Size = Section.getSize();
497 bool Text = Section.isText();
498 bool Data = Section.isData();
499 bool BSS = Section.isBSS();
516500 std::string Type = (std::string(Text ? "TEXT " : "") +
517501 (Data ? "DATA " : "") + (BSS ? "BSS" : ""));
518502 outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n", i,
526510 for (const SectionRef &Section : Obj->sections()) {
527511 StringRef Name;
528512 StringRef Contents;
529 uint64_t BaseAddr;
530 bool BSS;
531513 if (error(Section.getName(Name)))
532514 continue;
533 if (error(Section.getAddress(BaseAddr)))
534 continue;
535 if (error(Section.isBSS(BSS)))
536 continue;
515 uint64_t BaseAddr = Section.getAddress();
516 bool BSS = Section.isBSS();
537517
538518 outs() << "Contents of section " << Name << ":\n";
539519 if (BSS) {
540 uint64_t Size;
541 if (error(Section.getSize(Size)))
542 continue;
520 uint64_t Size = Section.getSize();
543521 outs() << format("
544522 ", %04" PRIx64 ")>\n",
545523 BaseAddr, BaseAddr + Size);
185185 ErrorOr
186186 Decoder::getSectionContaining(const COFFObjectFile &COFF, uint64_t VA) {
187187 for (const auto &Section : COFF.sections()) {
188 uint64_t Address;
189 uint64_t Size;
190
191 if (std::error_code EC = Section.getAddress(Address))
192 return EC;
193 if (std::error_code EC = Section.getSize(Size))
194 return EC;
188 uint64_t Address = Section.getAddress();
189 uint64_t Size = Section.getSize();
195190
196191 if (VA >= Address && (VA - Address) <= Size)
197192 return Section;
524519 if (COFF.getSectionContents(COFF.getCOFFSection(Section), Contents))
525520 return false;
526521
527 uint64_t SectionVA;
528 if (Section.getAddress(SectionVA))
529 return false;
530
522 uint64_t SectionVA = Section.getAddress();
531523 uint64_t Offset = VA - SectionVA;
532524 const ulittle32_t *Data =
533525 reinterpret_cast(Contents.data() + Offset);
628628 if (opts::SectionSymbols) {
629629 ListScope D(W, "Symbols");
630630 for (const SymbolRef &Symbol : Obj->symbols()) {
631 bool Contained = false;
632 if (Sec.containsSymbol(Symbol, Contained) || !Contained)
631 if (!Sec.containsSymbol(Symbol))
633632 continue;
634633
635634 printSymbol(Symbol);
256256 if (opts::SectionSymbols) {
257257 ListScope D(W, "Symbols");
258258 for (const SymbolRef &Symbol : Obj->symbols()) {
259 bool Contained = false;
260 if (Section.containsSymbol(Symbol, Contained) || !Contained)
259 if (!Section.containsSymbol(Symbol))
261260 continue;
262261
263262 printSymbol(Symbol);
265264 }
266265
267266 if (opts::SectionData) {
268 bool IsBSS;
269 if (error(Section.isBSS(IsBSS)))
270 break;
267 bool IsBSS = Section.isBSS();
271268 if (!IsBSS) {
272269 StringRef Data;
273270 if (error(Section.getContents(Data)))
296296 std::size_t max_size_len = strlen("size");
297297 std::size_t max_addr_len = strlen("addr");
298298 for (const SectionRef &Section : Obj->sections()) {
299 uint64_t size = 0;
300 if (error(Section.getSize(size)))
301 return;
299 uint64_t size = Section.getSize();
302300 total += size;
303301
304302 StringRef name;
305 uint64_t addr = 0;
306303 if (error(Section.getName(name)))
307304 return;
308 if (error(Section.getAddress(addr)))
309 return;
305 uint64_t addr = Section.getAddress();
310306 max_name_len = std::max(max_name_len, name.size());
311307 max_size_len = std::max(max_size_len, getNumLengthAsString(size));
312308 max_addr_len = std::max(max_addr_len, getNumLengthAsString(addr));
336332 // Print each section.
337333 for (const SectionRef &Section : Obj->sections()) {
338334 StringRef name;
339 uint64_t size = 0;
340 uint64_t addr = 0;
341335 if (error(Section.getName(name)))
342336 return;
343 if (error(Section.getSize(size)))
344 return;
345 if (error(Section.getAddress(addr)))
346 return;
337 uint64_t size = Section.getSize();
338 uint64_t addr = Section.getAddress();
347339 std::string namestr = name;
348340
349341 outs() << format(fmt.str().c_str(), namestr.c_str(), size, addr);
364356
365357 // Make one pass over the section table to calculate sizes.
366358 for (const SectionRef &Section : Obj->sections()) {
367 uint64_t size = 0;
368 bool isText = false;
369 bool isData = false;
370 bool isBSS = false;
371 if (error(Section.getSize(size)))
372 return;
373 if (error(Section.isText(isText)))
374 return;
375 if (error(Section.isData(isData)))
376 return;
377 if (error(Section.isBSS(isBSS)))
378 return;
359 uint64_t size = Section.getSize();
360 bool isText = Section.isText();
361 bool isData = Section.isData();
362 bool isBSS = Section.isBSS();
379363 if (isText)
380364 total_text += size;
381365 else if (isData)
138138 // Skip external symbols.
139139 if (SecI == Obj->section_end())
140140 continue;
141 bool IsBSS, IsVirtual;
142 if (error(SecI->isBSS(IsBSS)) || error(SecI->isVirtual(IsVirtual)))
143 break;
141 bool IsBSS = SecI->isBSS();
142 bool IsVirtual = SecI->isVirtual();
144143 // Skip virtual or BSS sections.
145144 if (IsBSS || IsVirtual)
146145 continue;