llvm.org GIT mirror llvm / 899e01b
Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return Expected<>" It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368813 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar a month ago
40 changed file(s) with 244 addition(s) and 427 deletion(s). Raw diff Collapse all Expand all
460460 if (!SymStrTabOrErr)
461461 return SymStrTabOrErr.takeError();
462462 Expected Name = ESym->getName(*SymStrTabOrErr);
463 if (Name && !Name->empty())
464 return Name;
465463
466464 // If the symbol name is empty use the section name.
467 if (ESym->getType() == ELF::STT_SECTION) {
468 if (Expected SecOrErr = getSymbolSection(Sym)) {
469 consumeError(Name.takeError());
470 return (*SecOrErr)->getName();
471 }
465 if ((!Name || Name->empty()) && ESym->getType() == ELF::STT_SECTION) {
466 StringRef SecName;
467 Expected Sec = getSymbolSection(Sym);
468 if (Sec && !(*Sec)->getName(SecName))
469 return SecName;
472470 }
473471 return Name;
474472 }
9393
9494 void moveNext();
9595
96 Expected getName() const;
96 std::error_code getName(StringRef &Result) const;
9797 uint64_t getAddress() const;
9898 uint64_t getIndex() const;
9999 uint64_t getSize() const;
433433 return OwningObject->moveSectionNext(SectionPimpl);
434434 }
435435
436 inline Expected SectionRef::getName() const {
437 return OwningObject->getSectionName(SectionPimpl);
436 inline std::error_code SectionRef::getName(StringRef &Result) const {
437 Expected NameOrErr = OwningObject->getSectionName(SectionPimpl);
438 if (!NameOrErr)
439 return errorToErrorCode(NameOrErr.takeError());
440 Result = *NameOrErr;
441 return std::error_code();
438442 }
439443
440444 inline uint64_t SectionRef::getAddress() const {
15051505 StringMap SectionAmountMap;
15061506 for (const SectionRef &Section : Obj.sections()) {
15071507 StringRef Name;
1508 if (auto NameOrErr = Section.getName())
1509 Name = *NameOrErr;
1510 else
1511 consumeError(NameOrErr.takeError());
1512
1508 Section.getName(Name);
15131509 ++SectionAmountMap[Name];
15141510 SectionNames.push_back({ Name, true });
15151511
15741570 continue;
15751571
15761572 StringRef RelSecName;
1577 if (auto NameOrErr = RelocatedSection->getName())
1578 RelSecName = *NameOrErr;
1579 else
1580 consumeError(NameOrErr.takeError());
1573 StringRef RelSecData;
1574 RelocatedSection->getName(RelSecName);
15811575
15821576 // If the section we're relocating was relocated already by the JIT,
15831577 // then we used the relocated version above, so we do not need to process
15841578 // relocations for it now.
1585 StringRef RelSecData;
15861579 if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData))
15871580 continue;
15881581
5353 // PowerPC64 ELF.
5454 if (Obj->getArch() == Triple::ppc64) {
5555 for (section_iterator Section : Obj->sections()) {
56 Expected NameOrErr = Section->getName();
57 if (!NameOrErr)
58 return errorToErrorCode(NameOrErr.takeError());
59
60 if (*NameOrErr == ".opd") {
56 StringRef Name;
57 if (auto EC = Section->getName(Name))
58 return EC;
59 if (Name == ".opd") {
6160 Expected E = Section->getContents();
6261 if (!E)
6362 return errorToErrorCode(E.takeError());
258258 return false;
259259 for (const SectionRef &Section : Obj->sections()) {
260260 StringRef Name;
261 if (Expected NameOrErr = Section.getName())
262 Name = *NameOrErr;
263 else
264 consumeError(NameOrErr.takeError());
265
261 Section.getName(Name);
266262 Name = Name.substr(Name.find_first_not_of("._"));
267263 if (Name == "gnu_debuglink") {
268264 Expected ContentsOrErr = Section.getContents();
9595 assert((SecRef.getAlignment() <= std::numeric_limits::max()) &&
9696 "Section alignment does not fit in 32 bits");
9797
98 Expected NameOrErr = SecRef.getName();
99 if (!NameOrErr)
100 return NameOrErr.takeError();
101 StringRef Name = *NameOrErr;
98 StringRef Name;
99 if (auto EC = SecRef.getName(Name))
100 return errorCodeToError(EC);
102101
103102 unsigned SectionIndex = SecRef.getIndex() + 1;
104103
534534 bool IsCode = Section.isText();
535535 bool IsReadOnly = isReadOnlyData(Section);
536536
537 Expected NameOrErr = Section.getName();
538 if (!NameOrErr)
539 return NameOrErr.takeError();
540 StringRef Name = *NameOrErr;
537 StringRef Name;
538 if (auto EC = Section.getName(Name))
539 return errorCodeToError(EC);
541540
542541 uint64_t StubBufSize = computeSectionStubBufSize(Obj, Section);
543542
777776 // anyway, so we should guarantee that the alignment is always at least 1.
778777 Alignment = std::max(1u, Alignment);
779778
780 Expected NameOrErr = Section.getName();
781 if (!NameOrErr)
782 return NameOrErr.takeError();
783 StringRef Name = *NameOrErr;
779 StringRef Name;
780 if (auto EC = Section.getName(Name))
781 return errorCodeToError(EC);
784782
785783 StubBufSize = computeSectionStubBufSize(Obj, Section);
786784
159159 // Iterate over all sections in the object.
160160 auto SI = SourceObject.section_begin();
161161 for (const auto &Sec : Obj->sections()) {
162 Expected NameOrErr = Sec.getName();
163 if (!NameOrErr) {
164 consumeError(NameOrErr.takeError());
165 continue;
166 }
167
168 if (*NameOrErr != "") {
162 StringRef SectionName;
163 Sec.getName(SectionName);
164 if (SectionName != "") {
169165 DataRefImpl ShdrRef = Sec.getRawDataRefImpl();
170166 Elf_Shdr *shdr = const_cast(
171167 reinterpret_cast(ShdrRef.p));
570566
571567 // The TOC consists of sections .got, .toc, .tocbss, .plt in that
572568 // order. The TOC starts where the first of these sections starts.
573 for (auto &Section : Obj.sections()) {
574 Expected NameOrErr = Section.getName();
575 if (!NameOrErr)
576 return NameOrErr.takeError();
577 StringRef SectionName = *NameOrErr;
569 for (auto &Section: Obj.sections()) {
570 StringRef SectionName;
571 if (auto EC = Section.getName(SectionName))
572 return errorCodeToError(EC);
578573
579574 if (SectionName == ".got"
580575 || SectionName == ".toc"
609604 if (RelSecI == Obj.section_end())
610605 continue;
611606
612 Expected NameOrErr = RelSecI->getName();
613 if (!NameOrErr)
614 return NameOrErr.takeError();
615 StringRef RelSectionName = *NameOrErr;
607 StringRef RelSectionName;
608 if (auto EC = RelSecI->getName(RelSectionName))
609 return errorCodeToError(EC);
616610
617611 if (RelSectionName != ".opd")
618612 continue;
18841878 ObjSectionToIDMap::iterator i, e;
18851879 for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) {
18861880 const SectionRef &Section = i->first;
1887
18881881 StringRef Name;
1889 Expected NameOrErr = Section.getName();
1890 if (NameOrErr)
1891 Name = *NameOrErr;
1892 else
1893 consumeError(NameOrErr.takeError());
1894
1882 Section.getName(Name);
18951883 if (Name == ".eh_frame") {
18961884 UnregisteredEHFrameSections.push_back(i->second);
18971885 break;
232232
233233 for (const auto &Section : Obj.sections()) {
234234 StringRef Name;
235 if (Expected NameOrErr = Section.getName())
236 Name = *NameOrErr;
237 else
238 consumeError(NameOrErr.takeError());
235 Section.getName(Name);
239236
240237 // Force emission of the __text, __eh_frame, and __gcc_except_tab sections
241238 // if they're present. Otherwise call down to the impl to handle other
283283 // Look for and record the EH frame section IDs.
284284 for (const auto &SectionPair : SectionMap) {
285285 const object::SectionRef &Section = SectionPair.first;
286 Expected NameOrErr = Section.getName();
287 if (!NameOrErr)
288 return NameOrErr.takeError();
286 StringRef Name;
287 if (auto EC = Section.getName(Name))
288 return errorCodeToError(EC);
289289
290290 // Note unwind info is stored in .pdata but often points to .xdata
291291 // with an IMAGE_REL_AMD64_ADDR32NB relocation. Using a memory manager
292292 // that keeps sections ordered in relation to __ImageBase is necessary.
293 if ((*NameOrErr) == ".pdata")
293 if (Name == ".pdata")
294294 UnregisteredEHFrameSections.push_back(SectionPair.second);
295295 }
296296 return Error::success();
288288 Error finalizeSection(const ObjectFile &Obj, unsigned SectionID,
289289 const SectionRef &Section) {
290290 StringRef Name;
291 if (Expected NameOrErr = Section.getName())
292 Name = *NameOrErr;
293 else
294 consumeError(NameOrErr.takeError());
291 Section.getName(Name);
295292
296293 if (Name == "__nl_symbol_ptr")
297294 return populateIndirectSymbolPointersSection(cast(Obj),
127127 Error finalizeSection(const ObjectFile &Obj, unsigned SectionID,
128128 const SectionRef &Section) {
129129 StringRef Name;
130 if (Expected NameOrErr = Section.getName())
131 Name = *NameOrErr;
132 else
133 consumeError(NameOrErr.takeError());
130 Section.getName(Name);
134131
135132 if (Name == "__jump_table")
136133 return populateJumpTable(cast(Obj), Section, SectionID);
993993 std::error_code COFFObjectFile::getSection(StringRef SectionName,
994994 const coff_section *&Result) const {
995995 Result = nullptr;
996 StringRef SecName;
996997 for (const SectionRef &Section : sections()) {
997 auto NameOrErr = Section.getName();
998 if (!NameOrErr)
999 return errorToErrorCode(NameOrErr.takeError());
1000
1001 if (*NameOrErr == SectionName) {
998 if (std::error_code E = Section.getName(SecName))
999 return E;
1000 if (SecName == SectionName) {
10021001 Result = getCOFFSection(Section);
10031002 return std::error_code();
10041003 }
7676 }
7777
7878 bool Decompressor::isCompressed(const object::SectionRef &Section) {
79 if (Section.isCompressed())
80 return true;
81
82 Expected SecNameOrErr = Section.getName();
83 if (SecNameOrErr)
84 return isGnuStyle(*SecNameOrErr);
85
86 consumeError(SecNameOrErr.takeError());
87 return false;
79 StringRef Name;
80 if (Section.getName(Name))
81 return false;
82 return Section.isCompressed() || isGnuStyle(Name);
8883 }
8984
9085 bool Decompressor::isCompressedELFSection(uint64_t Flags, StringRef Name) {
391391 return {};
392392 Optional Plt = None, RelaPlt = None, GotPlt = None;
393393 for (const SectionRef &Section : sections()) {
394 Expected NameOrErr = Section.getName();
395 if (!NameOrErr) {
396 consumeError(NameOrErr.takeError());
394 StringRef Name;
395 if (Section.getName(Name))
397396 continue;
398 }
399 StringRef Name = *NameOrErr;
400
401397 if (Name == ".plt")
402398 Plt = Section;
403399 else if (Name == ".rela.plt" || Name == ".rel.plt")
19851985 }
19861986
19871987 Expected MachOObjectFile::getSection(StringRef SectionName) const {
1988 StringRef SecName;
19881989 for (const SectionRef &Section : sections()) {
1989 auto NameOrErr = Section.getName();
1990 if (!NameOrErr)
1991 return NameOrErr.takeError();
1992 if (*NameOrErr == SectionName)
1990 if (std::error_code E = Section.getName(SecName))
1991 return errorCodeToError(E);
1992 if (SecName == SectionName) {
19931993 return Section;
1994 }
19941995 }
19951996 return errorCodeToError(object_error::parse_failed);
19961997 }
39933994 uint64_t CurSegAddress;
39943995 for (const SectionRef &Section : Obj->sections()) {
39953996 SectionInfo Info;
3996 Expected NameOrErr = Section.getName();
3997 if (!NameOrErr)
3998 consumeError(NameOrErr.takeError());
3999 else
4000 Info.SectionName = *NameOrErr;
3997 Section.getName(Info.SectionName);
40013998 Info.Address = Section.getAddress();
40023999 Info.Size = Section.getSize();
40034000 Info.SegmentName =
250250
251251 // SectionRef accessors
252252 const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) {
253 auto NameOrErr = (*unwrap(SI))->getName();
254 if (!NameOrErr)
255 report_fatal_error(NameOrErr.takeError());
256 return NameOrErr->data();
253 StringRef ret;
254 if (std::error_code ec = (*unwrap(SI))->getName(ret))
255 report_fatal_error(ec.message());
256 return ret.data();
257257 }
258258
259259 uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) {
665665 };
666666 Name = stripSuffix(Name);
667667
668 StringRef FoundName;
668669 for (const auto &Section : OF.sections()) {
669 Expected NameOrErr = Section.getName();
670 if (!NameOrErr)
671 return NameOrErr.takeError();
672 if (stripSuffix(*NameOrErr) == Name)
670 if (auto EC = Section.getName(FoundName))
671 return errorCodeToError(EC);
672 if (stripSuffix(FoundName) == Name)
673673 return Section;
674674 }
675675 return make_error(coveragemap_error::no_data_found);
6666 StringRef Contents = "";
6767 const auto &Sections = ObjFile.getBinary()->sections();
6868 auto I = llvm::find_if(Sections, [&](object::SectionRef Section) {
69 Expected NameOrErr = Section.getName();
70 if (NameOrErr)
71 return *NameOrErr == "xray_instr_map";
72 consumeError(NameOrErr.takeError());
73 return false;
69 StringRef Name = "";
70 if (Section.getName(Name))
71 return false;
72 return Name == "xray_instr_map";
7473 });
7574
7675 if (I == Sections.end())
11 ## .shstrtab has an invalid type.
22
33 # RUN: yaml2obj %s --docnum=1 -o %t1
4 # RUN: not llvm-objdump -s %t1 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=INVALID-SHTYPE
5
6 # INVALID-SHTYPE: error: '[[FILE]]': invalid sh_type for string table section [index 1]: expected SHT_STRTAB, but got SHT_PROGBITS
4 # RUN: not llvm-objdump -s %t1 2>&1 | FileCheck %s --check-prefix=INVALIDERR
5
6 # INVALIDERR: error: reading file: Invalid data was encountered while parsing the file
77
88 --- !ELF
99 FileHeader:
1919 ## .shstrtab has an invalid zero-size.
2020
2121 # RUN: yaml2obj %s --docnum=2 -o %t2
22 # RUN: not llvm-objdump -s %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=STRTAB-EMPTY
23
24 # STRTAB-EMPTY: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is empty
22 # RUN: not llvm-objdump -s %t2 2>&1 | FileCheck %s --check-prefix=INVALIDERR
2523
2624 --- !ELF
2725 FileHeader:
3836 ## size that goes past the end of the file.
3937
4038 # RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-size.elf 2>&1 \
41 # RUN: | FileCheck %s -DFILE=%p/Inputs/invalid-strtab-size.elf --check-prefix=INVALID-STRTAB-SIZE
42
43 # INVALID-STRTAB-SIZE: error: '[[FILE]]': section [index 1] has a sh_offset (0x70) + sh_size (0x16777215) that cannot be represented
39 # RUN: | FileCheck %s --check-prefix=INVALIDERR
4440
4541 ## Check that llvm-dwarfdump reports an error during relocation resolution
4642 ## when instead of expected SHT_RELA section it locates a section of a different type.
7571 ## and .shstrtab is not null-terminated.
7672
7773 # RUN: yaml2obj %s --docnum=4 -o %t4
78 # RUN: not llvm-objdump -s %t4 2>&1 | FileCheck -DFILE=%t4 --check-prefix=SHSTRTAB-NON-TERM %s
79
80 # SHSTRTAB-NON-TERM: error: '[[FILE]]': SHT_STRTAB string table section [index 1] is non-null terminated
74 # RUN: not llvm-objdump -s %t4 2>&1 | FileCheck --check-prefix=INVALIDERR %s
8175
8276 --- !ELF
8377 FileHeader:
537537 // Find the debug_info section.
538538 for (const object::SectionRef &Section : Obj.sections()) {
539539 StringRef SectionName;
540 if (Expected NameOrErr = Section.getName())
541 SectionName = *NameOrErr;
542 else
543 consumeError(NameOrErr.takeError());
544
540 Section.getName(SectionName);
545541 SectionName = SectionName.substr(SectionName.find_first_not_of("._"));
546542 if (SectionName != "debug_info")
547543 continue;
3030 getSectionByName(const object::ObjectFile &Obj, StringRef SecName) {
3131 for (const object::SectionRef &Section : Obj.sections()) {
3232 StringRef SectionName;
33 if (Expected NameOrErr = Section.getName())
34 SectionName = *NameOrErr;
35 else
36 consumeError(NameOrErr.takeError());
37
33 Section.getName(SectionName);
3834 SectionName = SectionName.substr(SectionName.find_first_not_of("._"));
3935 if (SectionName != SecName)
4036 continue;
448448
449449 // Avoid checking the PLT since it produces spurious failures on AArch64
450450 // when ignoring DWARF data.
451 Expected NameOrErr = Section.getName();
452 if (NameOrErr && *NameOrErr == ".plt")
453 continue;
454 consumeError(NameOrErr.takeError());
451 StringRef SectionName;
452 if (!Section.getName(SectionName) && SectionName == ".plt")
453 continue;
455454
456455 Expected Contents = Section.getContents();
457456 if (!Contents)
4949 auto ObjFormat = OF->getTripleObjectFormat();
5050 for (const auto &Section : OF->sections()) {
5151 StringRef Name;
52 if (Expected NameOrErr = Section.getName()) {
53 Name = *NameOrErr;
54 } else {
55 consumeError(NameOrErr.takeError());
52 if (Section.getName(Name))
5653 return 1;
57 }
58
5954 if (Name == llvm::getInstrProfSectionName(IPSK_name, ObjFormat,
6055 /*AddSegmentInfo=*/false)) {
6156 ProfileNames = Section;
405405 if (Section.isVirtual())
406406 return Error::success();
407407
408 Expected NameOrErr = Section.getName();
409 if (!NameOrErr)
410 return NameOrErr.takeError();
411 StringRef Name = *NameOrErr;
408 StringRef Name;
409 if (std::error_code Err = Section.getName(Name))
410 return errorCodeToError(Err);
412411
413412 Expected ContentsOrErr = Section.getContents();
414413 if (!ContentsOrErr)
912912 if (Flags & ELF::SHF_ALLOC)
913913 return Flags & ELF::SHF_WRITE ? 'd' : 'r';
914914
915 auto NameOrErr = SecI->getName();
916 if (!NameOrErr) {
917 consumeError(NameOrErr.takeError());
915 StringRef SecName;
916 if (SecI->getName(SecName))
918917 return '?';
919 }
920 if ((*NameOrErr).startswith(".debug"))
918 if (SecName.startswith(".debug"))
921919 return 'N';
922920 if (!(Flags & ELF::SHF_WRITE))
923921 return 'n';
10911089 consumeError(SecIOrErr.takeError());
10921090 return '?';
10931091 }
1094
1095 Expected NameOrErr = (*SecIOrErr)->getName();
1096 if (!NameOrErr) {
1097 consumeError(SecIOrErr.takeError());
1098 return '?';
1099 }
1100 SecName = *NameOrErr;
1092 elf_section_iterator secT = *SecIOrErr;
1093 secT->getName(SecName);
11011094 }
11021095 }
11031096
13531346 StringRef SectionName = StringRef();
13541347 for (const SectionRef &Section : MachO->sections()) {
13551348 S.NSect++;
1356
1357 if (Expected NameOrErr = Section.getName())
1358 SectionName = *NameOrErr;
1359 else
1360 consumeError(NameOrErr.takeError());
1361
1349 Section.getName(SectionName);
13621350 SegmentName = MachO->getSectionFinalSegmentName(
13631351 Section.getRawDataRefImpl());
13641352 if (S.Address >= Section.getAddress() &&
16781666 StringRef SegmentName = StringRef();
16791667 StringRef SectionName = StringRef();
16801668 for (const SectionRef &Section : MachO->sections()) {
1681 if (Expected NameOrErr = Section.getName())
1682 SectionName = *NameOrErr;
1683 else
1684 consumeError(NameOrErr.takeError());
1685
1669 Section.getName(SectionName);
16861670 SegmentName = MachO->getSectionFinalSegmentName(
16871671 Section.getRawDataRefImpl());
16881672 F.NSect++;
441441 std::vector &Rels,
442442 const RuntimeFunction *&RFStart, int &NumRFs) {
443443 for (const SectionRef &Section : Obj->sections()) {
444 StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
444 StringRef Name;
445 error(Section.getName(Name));
445446 if (Name != ".pdata")
446447 continue;
447448
370370 Symbols.push_back(Symbol);
371371 }
372372
373 for (const SectionRef &Section : MachOObj->sections())
373 for (const SectionRef &Section : MachOObj->sections()) {
374 StringRef SectName;
375 Section.getName(SectName);
374376 Sections.push_back(Section);
377 }
375378
376379 bool BaseSegmentAddressSet = false;
377380 for (const auto &Command : MachOObj->load_commands()) {
445448 // If we couldn't find a symbol that this relocation refers to, try
446449 // to find a section beginning instead.
447450 for (const SectionRef &Section : ToolSectionFilter(*O)) {
451 StringRef Name;
448452 uint64_t Addr = Section.getAddress();
449453 if (Addr != Val)
450454 continue;
451 StringRef NameOrErr = unwrapOrError(Section.getName(), O->getFileName());
452 Fmt << NameOrErr;
455 if (std::error_code EC = Section.getName(Name))
456 report_error(errorCodeToError(EC), O->getFileName());
457 Fmt << Name;
453458 return;
454459 }
455460
482487 --I;
483488 advance(SI, 1);
484489 }
485 if (SI == O->section_end()) {
490 if (SI == O->section_end())
486491 Fmt << Val << " (?,?)";
487 } else {
488 if (Expected NameOrErr = SI->getName())
489 S = *NameOrErr;
490 else
491 consumeError(NameOrErr.takeError());
492 }
492 else
493 SI->getName(S);
493494 }
494495
495496 Fmt << S;
15291530 uint64_t SectSize = Sect->getSize();
15301531
15311532 StringRef SectName;
1532 Expected SectNameOrErr = Sect->getName();
1533 if (SectNameOrErr)
1534 SectName = *SectNameOrErr;
1535 else
1536 consumeError(SectNameOrErr.takeError());
1537
1533 Sect->getName(SectName);
15381534 DataRefImpl Ref = Sect->getRawDataRefImpl();
15391535 StringRef SegmentName = O->getSectionFinalSegmentName(Ref);
15401536 outs() << SegmentName << ":" << SectName << ":";
17461742 }
17471743 for (const SectionRef &Section : O->sections()) {
17481744 StringRef SectName;
1749 Expected SecNameOrErr = Section.getName();
1750 if (SecNameOrErr)
1751 SectName = *SecNameOrErr;
1752 else
1753 consumeError(SecNameOrErr.takeError());
1754
1745 Section.getName(SectName);
17551746 DataRefImpl Ref = Section.getRawDataRefImpl();
17561747 StringRef SegName = O->getSectionFinalSegmentName(Ref);
17571748 if ((DumpSegName.empty() || SegName == DumpSegName) &&
18471838 MachOObjectFile *O) {
18481839 for (const SectionRef &Section : O->sections()) {
18491840 StringRef SectName;
1850 Expected SecNameOrErr = Section.getName();
1851 if (SecNameOrErr)
1852 SectName = *SecNameOrErr;
1853 else
1854 consumeError(SecNameOrErr.takeError());
1855
1841 Section.getName(SectName);
18561842 DataRefImpl Ref = Section.getRawDataRefImpl();
18571843 StringRef SegName = O->getSectionFinalSegmentName(Ref);
18581844 if (SegName == "__TEXT" && SectName == "__info_plist") {
19491935 if (DisassembleAll) {
19501936 for (const SectionRef &Section : MachOOF->sections()) {
19511937 StringRef SectName;
1952 if (Expected NameOrErr = Section.getName())
1953 SectName = *NameOrErr;
1954 else
1955 consumeError(NameOrErr.takeError());
1956
1938 Section.getName(SectName);
19571939 if (SectName.equals("__text")) {
19581940 DataRefImpl Ref = Section.getRawDataRefImpl();
19591941 StringRef SegName = MachOOF->getSectionFinalSegmentName(Ref);
32643246 continue;
32653247 if (objc_only) {
32663248 StringRef SectName;
3267 Expected SecNameOrErr =
3268 ((*(info->Sections))[SectIdx]).getName();
3269 if (SecNameOrErr)
3270 SectName = *SecNameOrErr;
3271 else
3272 consumeError(SecNameOrErr.takeError());
3273
3249 ((*(info->Sections))[SectIdx]).getName(SectName);
32743250 DataRefImpl Ref = ((*(info->Sections))[SectIdx]).getRawDataRefImpl();
32753251 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
32763252 if (SegName != "__OBJC" && SectName != "__cstring")
40624038 const char *sectname) {
40634039 for (const SectionRef &Section : O->sections()) {
40644040 StringRef SectName;
4065 Expected SecNameOrErr = Section.getName();
4066 if (SecNameOrErr)
4067 SectName = *SecNameOrErr;
4068 else
4069 consumeError(SecNameOrErr.takeError());
4070
4041 Section.getName(SectName);
40714042 DataRefImpl Ref = Section.getRawDataRefImpl();
40724043 StringRef SegName = O->getSectionFinalSegmentName(Ref);
40734044 if (SegName == segname && SectName == sectname)
40844055 return;
40854056
40864057 StringRef SectName;
4087 Expected SecNameOrErr = S.getName();
4088 if (SecNameOrErr)
4089 SectName = *SecNameOrErr;
4090 else
4091 consumeError(SecNameOrErr.takeError());
4092
4058 S.getName(SectName);
40934059 DataRefImpl Ref = S.getRawDataRefImpl();
40944060 StringRef SegName = O->getSectionFinalSegmentName(Ref);
40954061 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
41384104 if (S == SectionRef())
41394105 return;
41404106
4141 StringRef SectName = unwrapOrError(S.getName(), O->getFileName());
4107 StringRef SectName;
4108 S.getName(SectName);
41424109 DataRefImpl Ref = S.getRawDataRefImpl();
41434110 StringRef SegName = O->getSectionFinalSegmentName(Ref);
41444111 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
58125779 return;
58135780
58145781 StringRef SectName;
5815 Expected SecNameOrErr = S.getName();
5816 if (SecNameOrErr)
5817 SectName = *SecNameOrErr;
5818 else
5819 consumeError(SecNameOrErr.takeError());
5820
5782 S.getName(SectName);
58215783 DataRefImpl Ref = S.getRawDataRefImpl();
58225784 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
58235785 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
58805842 return;
58815843
58825844 StringRef SectName;
5883 Expected SecNameOrErr = S.getName();
5884 if (SecNameOrErr)
5885 SectName = *SecNameOrErr;
5886 else
5887 consumeError(SecNameOrErr.takeError());
5888
5845 S.getName(SectName);
58895846 DataRefImpl Ref = S.getRawDataRefImpl();
58905847 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
58915848 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
59315888 return;
59325889
59335890 StringRef SectName;
5934 Expected SecNameOrErr = S.getName();
5935 if (SecNameOrErr)
5936 SectName = *SecNameOrErr;
5937 else
5938 consumeError(SecNameOrErr.takeError());
5939
5891 S.getName(SectName);
59405892 DataRefImpl Ref = S.getRawDataRefImpl();
59415893 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
59425894 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
59935945 return;
59945946
59955947 StringRef SectName;
5996 Expected SecNameOrErr = S.getName();
5997 if (SecNameOrErr)
5998 SectName = *SecNameOrErr;
5999 else
6000 consumeError(SecNameOrErr.takeError());
6001
5948 S.getName(SectName);
60025949 DataRefImpl Ref = S.getRawDataRefImpl();
60035950 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
60045951 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
60485995 const char *r;
60495996
60505997 StringRef SectName;
6051 Expected SecNameOrErr = S.getName();
6052 if (SecNameOrErr)
6053 SectName = *SecNameOrErr;
6054 else
6055 consumeError(SecNameOrErr.takeError());
6056
5998 S.getName(SectName);
60575999 DataRefImpl Ref = S.getRawDataRefImpl();
60586000 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
60596001 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
60886030 CreateSymbolAddressMap(O, &AddrMap);
60896031
60906032 std::vector Sections;
6091 for (const SectionRef &Section : O->sections())
6033 for (const SectionRef &Section : O->sections()) {
6034 StringRef SectName;
6035 Section.getName(SectName);
60926036 Sections.push_back(Section);
6037 }
60936038
60946039 struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
60956040
61706115 CreateSymbolAddressMap(O, &AddrMap);
61716116
61726117 std::vector Sections;
6173 for (const SectionRef &Section : O->sections())
6118 for (const SectionRef &Section : O->sections()) {
6119 StringRef SectName;
6120 Section.getName(SectName);
61746121 Sections.push_back(Section);
6122 }
61756123
61766124 struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
61776125
62656213 CreateSymbolAddressMap(O, &AddrMap);
62666214
62676215 std::vector Sections;
6268 for (const SectionRef &Section : O->sections())
6216 for (const SectionRef &Section : O->sections()) {
6217 StringRef SectName;
6218 Section.getName(SectName);
62696219 Sections.push_back(Section);
6220 }
62706221
62716222 struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
62726223
64236374 CreateSymbolAddressMap(O, &AddrMap);
64246375
64256376 std::vector Sections;
6426 for (const SectionRef &Section : O->sections())
6377 for (const SectionRef &Section : O->sections()) {
6378 StringRef SectName;
6379 Section.getName(SectName);
64276380 Sections.push_back(Section);
6381 }
64286382
64296383 struct DisassembleInfo info(O, &AddrMap, &Sections, true);
64306384
73897343 outs() << "(" << DisSegName << "," << DisSectName << ") section\n";
73907344
73917345 for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
7392 Expected SecNameOrErr = Sections[SectIdx].getName();
7393 if (!SecNameOrErr) {
7394 consumeError(SecNameOrErr.takeError());
7395 continue;
7396 }
7397 if (*SecNameOrErr != DisSectName)
7346 StringRef SectName;
7347 if (Sections[SectIdx].getName(SectName) || SectName != DisSectName)
73987348 continue;
73997349
74007350 DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
77917741 auto Sym = Symbols.upper_bound(Addr);
77927742 if (Sym == Symbols.begin()) {
77937743 // The first symbol in the object is after this reference, the best we can
7794 // do is section-relative notation.
7795 if (Expected NameOrErr = RelocSection.getName())
7796 Name = *NameOrErr;
7797 else
7798 consumeError(NameOrErr.takeError());
7799
7744 // do is section-relative notation.
7745 RelocSection.getName(Name);
78007746 Addend = Addr - SectionAddr;
78017747 return;
78027748 }
78157761
78167762 // There is a symbol before this reference, but it's in a different
78177763 // section. Probably not helpful to mention it, so use the section name.
7818 if (Expected NameOrErr = RelocSection.getName())
7819 Name = *NameOrErr;
7820 else
7821 consumeError(NameOrErr.takeError());
7822
7764 RelocSection.getName(Name);
78237765 Addend = Addr - SectionAddr;
78247766 }
78257767
81848126
81858127 for (const SectionRef &Section : Obj->sections()) {
81868128 StringRef SectName;
8187 if (Expected NameOrErr = Section.getName())
8188 SectName = *NameOrErr;
8189 else
8190 consumeError(NameOrErr.takeError());
8191
8129 Section.getName(SectName);
81928130 if (SectName == "__compact_unwind")
81938131 printMachOCompactUnwindSection(Obj, Symbols, Section);
81948132 else if (SectName == "__unwind_info")
343343 static bool shouldKeep(object::SectionRef S) {
344344 if (FilterSections.empty())
345345 return true;
346
347 Expected SecNameOrErr = S.getName();
348 if (!SecNameOrErr) {
349 consumeError(SecNameOrErr.takeError());
346 StringRef SecName;
347 std::error_code error = S.getName(SecName);
348 if (error)
350349 return false;
351 }
352 StringRef SecName = *SecNameOrErr;
353
354350 // StringSet does not allow empty key so avoid adding sections with
355351 // no name (such as the section with index 0) here.
356352 if (!SecName.empty())
923919 StringSaver &Saver) {
924920 Optional Plt = None;
925921 for (const SectionRef &Section : Obj->sections()) {
926 Expected SecNameOrErr = Section.getName();
927 if (!SecNameOrErr) {
928 consumeError(SecNameOrErr.takeError());
922 StringRef Name;
923 if (Section.getName(Name))
929924 continue;
930 }
931 if (*SecNameOrErr == ".plt")
925 if (Name == ".plt")
932926 Plt = Section;
933927 }
934928 if (!Plt)
12111205 DataRefImpl DR = Section.getRawDataRefImpl();
12121206 SegmentName = MachO->getSectionFinalSegmentName(DR);
12131207 }
1214
1215 StringRef SectionName = unwrapOrError(Section.getName(), Obj->getFileName());
1208 StringRef SectionName;
1209 error(Section.getName(SectionName));
1210
12161211 // If the section has no symbol at the start, just insert a dummy one.
12171212 if (Symbols.empty() || std::get<0>(Symbols[0]) != 0) {
12181213 Symbols.insert(
15851580 }
15861581
15871582 for (std::pair> &P : SecToRelSec) {
1588 StringRef SecName = unwrapOrError(P.first.getName(), Obj->getFileName());
1583 StringRef SecName;
1584 error(P.first.getName(SecName));
15891585 outs() << "RELOCATION RECORDS FOR [" << SecName << "]:\n";
15901586
15911587 for (SectionRef Section : P.second) {
16571653 "Idx Name Size VMA Type\n";
16581654
16591655 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
1660 StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
1656 StringRef Name;
1657 error(Section.getName(Name));
16611658 uint64_t VMA = Section.getAddress();
16621659 if (shouldAdjustVA(Section))
16631660 VMA += AdjustVMA;
16841681
16851682 void printSectionContents(const ObjectFile *Obj) {
16861683 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
1687 StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
1684 StringRef Name;
1685 error(Section.getName(Name));
16881686 uint64_t BaseAddr = Section.getAddress();
16891687 uint64_t Size = Section.getSize();
16901688 if (!Size)
17481746 section_iterator Section = unwrapOrError(Symbol.getSection(), ArchiveName,
17491747 FileName, ArchitectureName);
17501748 StringRef Name;
1751 if (Type == SymbolRef::ST_Debug && Section != O->section_end()) {
1752 if (Expected NameOrErr = Section->getName())
1753 Name = *NameOrErr;
1754 else
1755 consumeError(NameOrErr.takeError());
1756
1757 } else {
1749 if (Type == SymbolRef::ST_Debug && Section != O->section_end())
1750 Section->getName(Name);
1751 else
17581752 Name = unwrapOrError(Symbol.getName(), ArchiveName, FileName,
17591753 ArchitectureName);
1760 }
17611754
17621755 bool Global = Flags & SymbolRef::SF_Global;
17631756 bool Weak = Flags & SymbolRef::SF_Weak;
18031796 StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
18041797 outs() << SegmentName << ",";
18051798 }
1806 StringRef SectionName =
1807 unwrapOrError(Section->getName(), O->getFileName());
1799 StringRef SectionName;
1800 error(Section->getName(SectionName));
18081801 outs() << SectionName;
18091802 }
18101803
18771870 Optional ClangASTSection;
18781871 for (auto Sec : ToolSectionFilter(*Obj)) {
18791872 StringRef Name;
1880 if (Expected NameOrErr = Sec.getName())
1881 Name = *NameOrErr;
1882 else
1883 consumeError(NameOrErr.takeError());
1884
1873 Sec.getName(Name);
18851874 if (Name == ClangASTSectionName) {
18861875 ClangASTSection = Sec;
18871876 break;
19131902
19141903 for (auto Sec : ToolSectionFilter(*Obj)) {
19151904 StringRef Name;
1916 if (Expected NameOrErr = Sec.getName())
1917 Name = *NameOrErr;
1918 else
1919 consumeError(NameOrErr.takeError());
1920
1905 Sec.getName(Name);
19211906 if (Name == FaultMapSectionName) {
19221907 FaultMapSection = Sec;
19231908 break;
13681368 LazyRandomTypeCollection Types(100);
13691369
13701370 for (const auto &S : getObj().sections()) {
1371 Expected NameOrErr = S.getName();
1372 if (!NameOrErr)
1373 return NameOrErr.takeError();
1374 StringRef SectionName = *NameOrErr;
1371 StringRef SectionName;
1372 if (auto EC = S.getName(SectionName))
1373 return errorCodeToError(EC);
13751374
13761375 // .debug$T is a standard CodeView type section, while .debug$P is the same
13771376 // format but used for MSVC precompiled header object files.
6565 static inline bool isCodeViewDebugSubsection(object::SectionRef Section,
6666 StringRef Name,
6767 BinaryStreamReader &Reader) {
68 if (Expected NameOrErr = Section.getName()) {
69 if (*NameOrErr != Name)
70 return false;
71 } else {
72 consumeError(NameOrErr.takeError());
73 return false;
74 }
68 StringRef SectionName;
69 if (Section.getName(SectionName))
70 return false;
71
72 if (SectionName != Name)
73 return false;
7574
7675 Expected ContentsOrErr = Section.getContents();
7776 if (!ContentsOrErr) {
890890 void COFFDumper::printCodeViewDebugInfo() {
891891 // Print types first to build CVUDTNames, then print symbols.
892892 for (const SectionRef &S : Obj->sections()) {
893 StringRef SectionName = unwrapOrError(Obj->getFileName(), S.getName());
893 StringRef SectionName;
894 error(S.getName(SectionName));
894895 // .debug$T is a standard CodeView type section, while .debug$P is the same
895896 // format but used for MSVC precompiled header object files.
896897 if (SectionName == ".debug$T" || SectionName == ".debug$P")
897898 printCodeViewTypeSection(SectionName, S);
898899 }
899900 for (const SectionRef &S : Obj->sections()) {
900 StringRef SectionName = unwrapOrError(Obj->getFileName(), S.getName());
901 StringRef SectionName;
902 error(S.getName(SectionName));
901903 if (SectionName == ".debug$S")
902904 printCodeViewSymbolSection(SectionName, S);
903905 }
12391241 GlobalTypeTableBuilder &GlobalCVTypes,
12401242 bool GHash) {
12411243 for (const SectionRef &S : Obj->sections()) {
1242 StringRef SectionName = unwrapOrError(Obj->getFileName(), S.getName());
1244 StringRef SectionName;
1245 error(S.getName(SectionName));
12431246 if (SectionName == ".debug$T") {
12441247 StringRef Data = unwrapOrError(Obj->getFileName(), S.getContents());
12451248 uint32_t Magic;
13071310 ++SectionNumber;
13081311 const coff_section *Section = Obj->getCOFFSection(Sec);
13091312
1310 StringRef Name = unwrapOrError(Obj->getFileName(), Sec.getName());
1313 StringRef Name;
1314 error(Sec.getName(Name));
13111315
13121316 DictScope D(W, "Section");
13131317 W.printNumber("Number", SectionNumber);
13541358 int SectionNumber = 0;
13551359 for (const SectionRef &Section : Obj->sections()) {
13561360 ++SectionNumber;
1357 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
1361 StringRef Name;
1362 error(Section.getName(Name));
13581363
13591364 bool PrintedGroup = false;
13601365 for (const RelocationRef &Reloc : Section.relocations()) {
16831688
16841689 void COFFDumper::printCOFFDirectives() {
16851690 for (const SectionRef &Section : Obj->sections()) {
1686 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
1691 StringRef Name;
1692
1693 error(Section.getName(Name));
16871694 if (Name != ".drectve")
16881695 continue;
16891696
17221729 void COFFDumper::printCOFFResources() {
17231730 ListScope ResourcesD(W, "Resources");
17241731 for (const SectionRef &S : Obj->sections()) {
1725 StringRef Name = unwrapOrError(Obj->getFileName(), S.getName());
1732 StringRef Name;
1733 error(S.getName(Name));
17261734 if (!Name.startswith(".rsrc"))
17271735 continue;
17281736
18461854 object::SectionRef StackMapSection;
18471855 for (auto Sec : Obj->sections()) {
18481856 StringRef Name;
1849 if (Expected NameOrErr = Sec.getName())
1850 Name = *NameOrErr;
1851 else
1852 consumeError(NameOrErr.takeError());
1853
1857 Sec.getName(Name);
18541858 if (Name == ".llvm_stackmaps") {
18551859 StackMapSection = Sec;
18561860 break;
18771881 object::SectionRef AddrsigSection;
18781882 for (auto Sec : Obj->sections()) {
18791883 StringRef Name;
1880 if (Expected NameOrErr = Sec.getName())
1881 Name = *NameOrErr;
1882 else
1883 consumeError(NameOrErr.takeError());
1884
1884 Sec.getName(Name);
18851885 if (Name == ".llvm_addrsig") {
18861886 AddrsigSection = Sec;
18871887 break;
46684668 StringRef FileStr = Obj->getFileName();
46694669 for (const SectionRef &Sec : Obj->sections()) {
46704670 StringRef SectionName;
4671 if (Expected NameOrErr = Sec.getName())
4672 SectionName = *NameOrErr;
4673 else
4674 consumeError(NameOrErr.takeError());
4675
4671 Sec.getName(SectionName);
46764672 const Elf_Shdr *ElfSec = Obj->getSection(Sec.getRawDataRefImpl());
46774673 if (!SectionName.startswith(".stack_sizes"))
46784674 continue;
47204716
47214717 for (const SectionRef &Sec : Obj->sections()) {
47224718 StringRef SectionName;
4723 if (Expected NameOrErr = Sec.getName())
4724 SectionName = *NameOrErr;
4725 else
4726 consumeError(NameOrErr.takeError());
4727
4719 Sec.getName(SectionName);
47284720 // A stack size section that we haven't encountered yet is mapped to the
47294721 // null section until we find its corresponding relocation section.
47304722 if (SectionName.startswith(".stack_sizes"))
47614753
47624754 // Warn about stack size sections without a relocation section.
47634755 StringRef StackSizeSectionName;
4764 if (Expected NameOrErr = StackSizesSec.getName())
4765 StackSizeSectionName = *NameOrErr;
4766 else
4767 consumeError(NameOrErr.takeError());
4768
4756 StackSizesSec.getName(StackSizeSectionName);
47694757 if (RelocSec == NullSection) {
47704758 reportWarning(" '" + FileStr + "': section " + StackSizeSectionName +
47714759 " does not have a corresponding "
47934781 for (const RelocationRef &Reloc : RelocSec.relocations()) {
47944782 if (!IsSupportedFn(Reloc.getType())) {
47954783 StringRef RelocSectionName;
4796 Expected NameOrErr = RelocSec.getName();
4797 if (NameOrErr)
4798 RelocSectionName = *NameOrErr;
4799 else
4800 consumeError(NameOrErr.takeError());
4801
4784 RelocSec.getName(RelocSectionName);
48024785 StringRef RelocName = EF->getRelocationTypeName(Reloc.getType());
48034786 reportError(
48044787 createStringError(object_error::parse_failed,
439439 MachOSection MOSection;
440440 getSection(Obj, Section.getRawDataRefImpl(), MOSection);
441441 DataRefImpl DR = Section.getRawDataRefImpl();
442 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
442
443 StringRef Name;
444 error(Section.getName(Name));
445
443446 ArrayRef RawName = Obj->getSectionRawName(DR);
444447 StringRef SegmentName = Obj->getSectionFinalSegmentName(DR);
445448 ArrayRef RawSegmentName = Obj->getSectionRawFinalSegmentName(DR);
490493
491494 std::error_code EC;
492495 for (const SectionRef &Section : Obj->sections()) {
493 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
496 StringRef Name;
497 error(Section.getName(Name));
498
494499 bool PrintedGroup = false;
495500 for (const RelocationRef &Reloc : Section.relocations()) {
496501 if (!PrintedGroup) {
535540 }
536541 } else if (!IsScattered) {
537542 section_iterator SecI = Obj->getRelocationSection(DR);
538 if (SecI != Obj->section_end())
539 TargetName = unwrapOrError(Obj->getFileName(), SecI->getName());
543 if (SecI != Obj->section_end()) {
544 error(SecI->getName(TargetName));
545 }
540546 }
541547 if (TargetName.empty())
542548 TargetName = "-";
607613 error(errorToErrorCode(SecIOrErr.takeError()));
608614 section_iterator SecI = *SecIOrErr;
609615 if (SecI != Obj->section_end())
610 SectionName = unwrapOrError(Obj->getFileName(), SecI->getName());
616 error(SecI->getName(SectionName));
611617
612618 DictScope D(W, "Symbol");
613619 W.printNumber("Name", SymbolName, MOSymbol.StringIndex);
637643 object::SectionRef StackMapSection;
638644 for (auto Sec : Obj->sections()) {
639645 StringRef Name;
640 if (Expected NameOrErr = Sec.getName())
641 Name = *NameOrErr;
642 else
643 consumeError(NameOrErr.takeError());
644
646 Sec.getName(Name);
645647 if (Name == "__llvm_stackmaps") {
646648 StackMapSection = Sec;
647649 break;
4848
4949 SecIndex = Obj->isELF() ? 0 : 1;
5050 for (object::SectionRef SecRef : Obj->sections()) {
51 StringRef SecName = unwrapOrError(Obj->getFileName(), SecRef.getName());
51 StringRef SecName;
52 error(SecRef.getName(SecName));
5253 auto NameIt = SecNames.find(SecName);
5354 if (NameIt != SecNames.end())
5455 NameIt->second = true;
7576 bool First = true;
7677 for (object::SectionRef Section :
7778 getSectionRefsByNameOrIndex(Obj, Sections)) {
78 StringRef SectionName =
79 unwrapOrError(Obj->getFileName(), Section.getName());
80
79 StringRef SectionName;
80 error(Section.getName(SectionName));
8181 if (!First)
8282 W.startLine() << '\n';
8383 First = false;
110110 bool First = true;
111111 for (object::SectionRef Section :
112112 getSectionRefsByNameOrIndex(Obj, Sections)) {
113 StringRef SectionName =
114 unwrapOrError(Obj->getFileName(), Section.getName());
115
113 StringRef SectionName;
114 error(Section.getName(SectionName));
116115 if (!First)
117116 W.startLine() << '\n';
118117 First = false;
132132 int SectionNumber = 0;
133133 for (const SectionRef &Section : Obj->sections()) {
134134 bool PrintedGroup = false;
135 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
136
135 StringRef Name;
136 error(Section.getName(Name));
137137 ++SectionNumber;
138138
139139 for (const RelocationRef &Reloc : Section.relocations()) {
305305 void Dumper::printData(const Context &Ctx) {
306306 for (const auto &Section : Ctx.COFF.sections()) {
307307 StringRef Name;
308 if (Expected NameOrErr = Section.getName())
309 Name = *NameOrErr;
310 else
311 consumeError(NameOrErr.takeError());
308 Section.getName(Name);
312309
313310 if (Name != ".pdata" && !Name.startswith(".pdata$"))
314311 continue;
440440 continue;
441441 }
442442 object::section_iterator Sec = *SecOrErr;
443 StringRef SecName;
444 Sec->getName(SecName);
443445 Address.SectionIndex = Sec->getIndex();
444446 uint64_t SectionLoadAddress =
445447 LoadedObjInfo->getSectionLoadAddress(*Sec);
104104 static bool HadError = false;
105105
106106 static std::string ToolName;
107
108 /// If ec is not success, print the error and return true.
109 static bool error(std::error_code ec) {
110 if (!ec)
111 return false;
112
113 HadError = true;
114 errs() << ToolName << ": error reading file: " << ec.message() << ".\n";
115 errs().flush();
116 return true;
117 }
107118
108119 static bool error(Twine Message) {
109120 HadError = true;
385396 uint64_t size = Section.getSize();
386397 total += size;
387398
388 Expected name_or_err = Section.getName();
389 if (!name_or_err) {
390 error(name_or_err.takeError(), Obj->getFileName());
399 StringRef name;
400 if (error(Section.getName(name)))
391401 return;
392 }
393
394402 uint64_t addr = Section.getAddress();
395 max_name_len = std::max(max_name_len, name_or_err->size());
403 max_name_len = std::max(max_name_len, name.size());
396404 max_size_len = std::max(max_size_len, getNumLengthAsString(size));
397405 max_addr_len = std::max(max_addr_len, getNumLengthAsString(addr));
398406 }
422430 for (const SectionRef &Section : Obj->sections()) {
423431 if (!considerForSize(Obj, Section))
424432 continue;
425
426 Expected name_or_err = Section.getName();
427 if (!name_or_err) {
428 error(name_or_err.takeError(), Obj->getFileName());
433 StringRef name;
434 if (error(Section.getName(name)))
429435 return;
430 }
431
432436 uint64_t size = Section.getSize();
433437 uint64_t addr = Section.getAddress();
434 outs() << format(fmt.str().c_str(), name_or_err->str().c_str(), size, addr);
438 std::string namestr = name;
439
440 outs() << format(fmt.str().c_str(), namestr.c_str(), size, addr);
435441 }
436442
437443 if (ELFCommons) {
111111 if (SC.hasStrings() && SC.hasChecksums())
112112 break;
113113
114 Expected SectionNameOrErr = S.getName();
115 if (!SectionNameOrErr) {
116 consumeError(SectionNameOrErr.takeError());
117 continue;
118 }
119
114 StringRef SectionName;
115 S.getName(SectionName);
120116 ArrayRef sectionData;
121 if ((*SectionNameOrErr) != ".debug$S")
117 if (SectionName != ".debug$S")
122118 continue;
123119
124120 const object::coff_section *COFFSection = Obj.getCOFFSection(S);
158154 for (const auto &ObjSection : Obj.sections()) {
159155 const object::coff_section *COFFSection = Obj.getCOFFSection(ObjSection);
160156 COFFYAML::Section NewYAMLSection;
161
162 if (Expected NameOrErr = ObjSection.getName())
163 NewYAMLSection.Name = *NameOrErr;
164 else
165 consumeError(NameOrErr.takeError());
166
157 ObjSection.getName(NewYAMLSection.Name);
167158 NewYAMLSection.Header.Characteristics = COFFSection->Characteristics;
168159 NewYAMLSection.Header.VirtualAddress = COFFSection->VirtualAddress;
169160 NewYAMLSection.Header.VirtualSize = COFFSection->VirtualSize;