llvm.org GIT mirror llvm / 1bfa43d
Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return Expected<>" Changes: no changes. A fix for the clang code will be landed right on top. Original commit message: SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368826 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar a month ago
40 changed file(s) with 427 addition(s) and 244 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;
463465
464466 // If the symbol name is empty use the section name.
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;
467 if (ESym->getType() == ELF::STT_SECTION) {
468 if (Expected SecOrErr = getSymbolSection(Sym)) {
469 consumeError(Name.takeError());
470 return (*SecOrErr)->getName();
471 }
470472 }
471473 return Name;
472474 }
9393
9494 void moveNext();
9595
96 std::error_code getName(StringRef &Result) const;
96 Expected getName() 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 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();
436 inline Expected SectionRef::getName() const {
437 return OwningObject->getSectionName(SectionPimpl);
442438 }
443439
444440 inline uint64_t SectionRef::getAddress() const {
15051505 StringMap SectionAmountMap;
15061506 for (const SectionRef &Section : Obj.sections()) {
15071507 StringRef Name;
1508 Section.getName(Name);
1508 if (auto NameOrErr = Section.getName())
1509 Name = *NameOrErr;
1510 else
1511 consumeError(NameOrErr.takeError());
1512
15091513 ++SectionAmountMap[Name];
15101514 SectionNames.push_back({ Name, true });
15111515
15701574 continue;
15711575
15721576 StringRef RelSecName;
1573 StringRef RelSecData;
1574 RelocatedSection->getName(RelSecName);
1577 if (auto NameOrErr = RelocatedSection->getName())
1578 RelSecName = *NameOrErr;
1579 else
1580 consumeError(NameOrErr.takeError());
15751581
15761582 // If the section we're relocating was relocated already by the JIT,
15771583 // then we used the relocated version above, so we do not need to process
15781584 // relocations for it now.
1585 StringRef RelSecData;
15791586 if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData))
15801587 continue;
15811588
5353 // PowerPC64 ELF.
5454 if (Obj->getArch() == Triple::ppc64) {
5555 for (section_iterator Section : Obj->sections()) {
56 StringRef Name;
57 if (auto EC = Section->getName(Name))
58 return EC;
59 if (Name == ".opd") {
56 Expected NameOrErr = Section->getName();
57 if (!NameOrErr)
58 return errorToErrorCode(NameOrErr.takeError());
59
60 if (*NameOrErr == ".opd") {
6061 Expected E = Section->getContents();
6162 if (!E)
6263 return errorToErrorCode(E.takeError());
258258 return false;
259259 for (const SectionRef &Section : Obj->sections()) {
260260 StringRef Name;
261 Section.getName(Name);
261 if (Expected NameOrErr = Section.getName())
262 Name = *NameOrErr;
263 else
264 consumeError(NameOrErr.takeError());
265
262266 Name = Name.substr(Name.find_first_not_of("._"));
263267 if (Name == "gnu_debuglink") {
264268 Expected ContentsOrErr = Section.getContents();
9595 assert((SecRef.getAlignment() <= std::numeric_limits::max()) &&
9696 "Section alignment does not fit in 32 bits");
9797
98 StringRef Name;
99 if (auto EC = SecRef.getName(Name))
100 return errorCodeToError(EC);
98 Expected NameOrErr = SecRef.getName();
99 if (!NameOrErr)
100 return NameOrErr.takeError();
101 StringRef Name = *NameOrErr;
101102
102103 unsigned SectionIndex = SecRef.getIndex() + 1;
103104
534534 bool IsCode = Section.isText();
535535 bool IsReadOnly = isReadOnlyData(Section);
536536
537 StringRef Name;
538 if (auto EC = Section.getName(Name))
539 return errorCodeToError(EC);
537 Expected NameOrErr = Section.getName();
538 if (!NameOrErr)
539 return NameOrErr.takeError();
540 StringRef Name = *NameOrErr;
540541
541542 uint64_t StubBufSize = computeSectionStubBufSize(Obj, Section);
542543
776777 // anyway, so we should guarantee that the alignment is always at least 1.
777778 Alignment = std::max(1u, Alignment);
778779
779 StringRef Name;
780 if (auto EC = Section.getName(Name))
781 return errorCodeToError(EC);
780 Expected NameOrErr = Section.getName();
781 if (!NameOrErr)
782 return NameOrErr.takeError();
783 StringRef Name = *NameOrErr;
782784
783785 StubBufSize = computeSectionStubBufSize(Obj, Section);
784786
159159 // Iterate over all sections in the object.
160160 auto SI = SourceObject.section_begin();
161161 for (const auto &Sec : Obj->sections()) {
162 StringRef SectionName;
163 Sec.getName(SectionName);
164 if (SectionName != "") {
162 Expected NameOrErr = Sec.getName();
163 if (!NameOrErr) {
164 consumeError(NameOrErr.takeError());
165 continue;
166 }
167
168 if (*NameOrErr != "") {
165169 DataRefImpl ShdrRef = Sec.getRawDataRefImpl();
166170 Elf_Shdr *shdr = const_cast(
167171 reinterpret_cast(ShdrRef.p));
566570
567571 // The TOC consists of sections .got, .toc, .tocbss, .plt in that
568572 // order. The TOC starts where the first of these sections starts.
569 for (auto &Section: Obj.sections()) {
570 StringRef SectionName;
571 if (auto EC = Section.getName(SectionName))
572 return errorCodeToError(EC);
573 for (auto &Section : Obj.sections()) {
574 Expected NameOrErr = Section.getName();
575 if (!NameOrErr)
576 return NameOrErr.takeError();
577 StringRef SectionName = *NameOrErr;
573578
574579 if (SectionName == ".got"
575580 || SectionName == ".toc"
604609 if (RelSecI == Obj.section_end())
605610 continue;
606611
607 StringRef RelSectionName;
608 if (auto EC = RelSecI->getName(RelSectionName))
609 return errorCodeToError(EC);
612 Expected NameOrErr = RelSecI->getName();
613 if (!NameOrErr)
614 return NameOrErr.takeError();
615 StringRef RelSectionName = *NameOrErr;
610616
611617 if (RelSectionName != ".opd")
612618 continue;
18781884 ObjSectionToIDMap::iterator i, e;
18791885 for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) {
18801886 const SectionRef &Section = i->first;
1887
18811888 StringRef Name;
1882 Section.getName(Name);
1889 Expected NameOrErr = Section.getName();
1890 if (NameOrErr)
1891 Name = *NameOrErr;
1892 else
1893 consumeError(NameOrErr.takeError());
1894
18831895 if (Name == ".eh_frame") {
18841896 UnregisteredEHFrameSections.push_back(i->second);
18851897 break;
232232
233233 for (const auto &Section : Obj.sections()) {
234234 StringRef Name;
235 Section.getName(Name);
235 if (Expected NameOrErr = Section.getName())
236 Name = *NameOrErr;
237 else
238 consumeError(NameOrErr.takeError());
236239
237240 // Force emission of the __text, __eh_frame, and __gcc_except_tab sections
238241 // 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 StringRef Name;
287 if (auto EC = Section.getName(Name))
288 return errorCodeToError(EC);
286 Expected NameOrErr = Section.getName();
287 if (!NameOrErr)
288 return NameOrErr.takeError();
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 (Name == ".pdata")
293 if ((*NameOrErr) == ".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 Section.getName(Name);
291 if (Expected NameOrErr = Section.getName())
292 Name = *NameOrErr;
293 else
294 consumeError(NameOrErr.takeError());
292295
293296 if (Name == "__nl_symbol_ptr")
294297 return populateIndirectSymbolPointersSection(cast(Obj),
127127 Error finalizeSection(const ObjectFile &Obj, unsigned SectionID,
128128 const SectionRef &Section) {
129129 StringRef Name;
130 Section.getName(Name);
130 if (Expected NameOrErr = Section.getName())
131 Name = *NameOrErr;
132 else
133 consumeError(NameOrErr.takeError());
131134
132135 if (Name == "__jump_table")
133136 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;
997996 for (const SectionRef &Section : sections()) {
998 if (std::error_code E = Section.getName(SecName))
999 return E;
1000 if (SecName == SectionName) {
997 auto NameOrErr = Section.getName();
998 if (!NameOrErr)
999 return errorToErrorCode(NameOrErr.takeError());
1000
1001 if (*NameOrErr == SectionName) {
10011002 Result = getCOFFSection(Section);
10021003 return std::error_code();
10031004 }
7676 }
7777
7878 bool Decompressor::isCompressed(const object::SectionRef &Section) {
79 StringRef Name;
80 if (Section.getName(Name))
81 return false;
82 return Section.isCompressed() || isGnuStyle(Name);
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;
8388 }
8489
8590 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 StringRef Name;
395 if (Section.getName(Name))
394 Expected NameOrErr = Section.getName();
395 if (!NameOrErr) {
396 consumeError(NameOrErr.takeError());
396397 continue;
398 }
399 StringRef Name = *NameOrErr;
400
397401 if (Name == ".plt")
398402 Plt = Section;
399403 else if (Name == ".rela.plt" || Name == ".rel.plt")
19851985 }
19861986
19871987 Expected MachOObjectFile::getSection(StringRef SectionName) const {
1988 StringRef SecName;
19891988 for (const SectionRef &Section : sections()) {
1990 if (std::error_code E = Section.getName(SecName))
1991 return errorCodeToError(E);
1992 if (SecName == SectionName) {
1989 auto NameOrErr = Section.getName();
1990 if (!NameOrErr)
1991 return NameOrErr.takeError();
1992 if (*NameOrErr == SectionName)
19931993 return Section;
1994 }
19951994 }
19961995 return errorCodeToError(object_error::parse_failed);
19971996 }
39943993 uint64_t CurSegAddress;
39953994 for (const SectionRef &Section : Obj->sections()) {
39963995 SectionInfo Info;
3997 Section.getName(Info.SectionName);
3996 Expected NameOrErr = Section.getName();
3997 if (!NameOrErr)
3998 consumeError(NameOrErr.takeError());
3999 else
4000 Info.SectionName = *NameOrErr;
39984001 Info.Address = Section.getAddress();
39994002 Info.Size = Section.getSize();
40004003 Info.SegmentName =
250250
251251 // SectionRef accessors
252252 const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) {
253 StringRef ret;
254 if (std::error_code ec = (*unwrap(SI))->getName(ret))
255 report_fatal_error(ec.message());
256 return ret.data();
253 auto NameOrErr = (*unwrap(SI))->getName();
254 if (!NameOrErr)
255 report_fatal_error(NameOrErr.takeError());
256 return NameOrErr->data();
257257 }
258258
259259 uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) {
665665 };
666666 Name = stripSuffix(Name);
667667
668 StringRef FoundName;
669668 for (const auto &Section : OF.sections()) {
670 if (auto EC = Section.getName(FoundName))
671 return errorCodeToError(EC);
672 if (stripSuffix(FoundName) == Name)
669 Expected NameOrErr = Section.getName();
670 if (!NameOrErr)
671 return NameOrErr.takeError();
672 if (stripSuffix(*NameOrErr) == 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 StringRef Name = "";
70 if (Section.getName(Name))
71 return false;
72 return Name == "xray_instr_map";
69 Expected NameOrErr = Section.getName();
70 if (NameOrErr)
71 return *NameOrErr == "xray_instr_map";
72 consumeError(NameOrErr.takeError());
73 return false;
7374 });
7475
7576 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 --check-prefix=INVALIDERR
5
6 # INVALIDERR: error: reading file: Invalid data was encountered while parsing the file
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
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 --check-prefix=INVALIDERR
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
2325
2426 --- !ELF
2527 FileHeader:
3638 ## size that goes past the end of the file.
3739
3840 # RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-size.elf 2>&1 \
39 # RUN: | FileCheck %s --check-prefix=INVALIDERR
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
4044
4145 ## Check that llvm-dwarfdump reports an error during relocation resolution
4246 ## when instead of expected SHT_RELA section it locates a section of a different type.
7175 ## and .shstrtab is not null-terminated.
7276
7377 # RUN: yaml2obj %s --docnum=4 -o %t4
74 # RUN: not llvm-objdump -s %t4 2>&1 | FileCheck --check-prefix=INVALIDERR %s
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
7581
7682 --- !ELF
7783 FileHeader:
537537 // Find the debug_info section.
538538 for (const object::SectionRef &Section : Obj.sections()) {
539539 StringRef SectionName;
540 Section.getName(SectionName);
540 if (Expected NameOrErr = Section.getName())
541 SectionName = *NameOrErr;
542 else
543 consumeError(NameOrErr.takeError());
544
541545 SectionName = SectionName.substr(SectionName.find_first_not_of("._"));
542546 if (SectionName != "debug_info")
543547 continue;
3030 getSectionByName(const object::ObjectFile &Obj, StringRef SecName) {
3131 for (const object::SectionRef &Section : Obj.sections()) {
3232 StringRef SectionName;
33 Section.getName(SectionName);
33 if (Expected NameOrErr = Section.getName())
34 SectionName = *NameOrErr;
35 else
36 consumeError(NameOrErr.takeError());
37
3438 SectionName = SectionName.substr(SectionName.find_first_not_of("._"));
3539 if (SectionName != SecName)
3640 continue;
448448
449449 // Avoid checking the PLT since it produces spurious failures on AArch64
450450 // when ignoring DWARF data.
451 StringRef SectionName;
452 if (!Section.getName(SectionName) && SectionName == ".plt")
453 continue;
451 Expected NameOrErr = Section.getName();
452 if (NameOrErr && *NameOrErr == ".plt")
453 continue;
454 consumeError(NameOrErr.takeError());
454455
455456 Expected Contents = Section.getContents();
456457 if (!Contents)
4949 auto ObjFormat = OF->getTripleObjectFormat();
5050 for (const auto &Section : OF->sections()) {
5151 StringRef Name;
52 if (Section.getName(Name))
52 if (Expected NameOrErr = Section.getName()) {
53 Name = *NameOrErr;
54 } else {
55 consumeError(NameOrErr.takeError());
5356 return 1;
57 }
58
5459 if (Name == llvm::getInstrProfSectionName(IPSK_name, ObjFormat,
5560 /*AddSegmentInfo=*/false)) {
5661 ProfileNames = Section;
405405 if (Section.isVirtual())
406406 return Error::success();
407407
408 StringRef Name;
409 if (std::error_code Err = Section.getName(Name))
410 return errorCodeToError(Err);
408 Expected NameOrErr = Section.getName();
409 if (!NameOrErr)
410 return NameOrErr.takeError();
411 StringRef Name = *NameOrErr;
411412
412413 Expected ContentsOrErr = Section.getContents();
413414 if (!ContentsOrErr)
912912 if (Flags & ELF::SHF_ALLOC)
913913 return Flags & ELF::SHF_WRITE ? 'd' : 'r';
914914
915 StringRef SecName;
916 if (SecI->getName(SecName))
915 auto NameOrErr = SecI->getName();
916 if (!NameOrErr) {
917 consumeError(NameOrErr.takeError());
917918 return '?';
918 if (SecName.startswith(".debug"))
919 }
920 if ((*NameOrErr).startswith(".debug"))
919921 return 'N';
920922 if (!(Flags & ELF::SHF_WRITE))
921923 return 'n';
10891091 consumeError(SecIOrErr.takeError());
10901092 return '?';
10911093 }
1092 elf_section_iterator secT = *SecIOrErr;
1093 secT->getName(SecName);
1094
1095 Expected NameOrErr = (*SecIOrErr)->getName();
1096 if (!NameOrErr) {
1097 consumeError(SecIOrErr.takeError());
1098 return '?';
1099 }
1100 SecName = *NameOrErr;
10941101 }
10951102 }
10961103
13461353 StringRef SectionName = StringRef();
13471354 for (const SectionRef &Section : MachO->sections()) {
13481355 S.NSect++;
1349 Section.getName(SectionName);
1356
1357 if (Expected NameOrErr = Section.getName())
1358 SectionName = *NameOrErr;
1359 else
1360 consumeError(NameOrErr.takeError());
1361
13501362 SegmentName = MachO->getSectionFinalSegmentName(
13511363 Section.getRawDataRefImpl());
13521364 if (S.Address >= Section.getAddress() &&
16661678 StringRef SegmentName = StringRef();
16671679 StringRef SectionName = StringRef();
16681680 for (const SectionRef &Section : MachO->sections()) {
1669 Section.getName(SectionName);
1681 if (Expected NameOrErr = Section.getName())
1682 SectionName = *NameOrErr;
1683 else
1684 consumeError(NameOrErr.takeError());
1685
16701686 SegmentName = MachO->getSectionFinalSegmentName(
16711687 Section.getRawDataRefImpl());
16721688 F.NSect++;
441441 std::vector &Rels,
442442 const RuntimeFunction *&RFStart, int &NumRFs) {
443443 for (const SectionRef &Section : Obj->sections()) {
444 StringRef Name;
445 error(Section.getName(Name));
444 StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
446445 if (Name != ".pdata")
447446 continue;
448447
370370 Symbols.push_back(Symbol);
371371 }
372372
373 for (const SectionRef &Section : MachOObj->sections()) {
374 StringRef SectName;
375 Section.getName(SectName);
373 for (const SectionRef &Section : MachOObj->sections())
376374 Sections.push_back(Section);
377 }
378375
379376 bool BaseSegmentAddressSet = false;
380377 for (const auto &Command : MachOObj->load_commands()) {
448445 // If we couldn't find a symbol that this relocation refers to, try
449446 // to find a section beginning instead.
450447 for (const SectionRef &Section : ToolSectionFilter(*O)) {
451 StringRef Name;
452448 uint64_t Addr = Section.getAddress();
453449 if (Addr != Val)
454450 continue;
455 if (std::error_code EC = Section.getName(Name))
456 report_error(errorCodeToError(EC), O->getFileName());
457 Fmt << Name;
451 StringRef NameOrErr = unwrapOrError(Section.getName(), O->getFileName());
452 Fmt << NameOrErr;
458453 return;
459454 }
460455
487482 --I;
488483 advance(SI, 1);
489484 }
490 if (SI == O->section_end())
485 if (SI == O->section_end()) {
491486 Fmt << Val << " (?,?)";
492 else
493 SI->getName(S);
487 } else {
488 if (Expected NameOrErr = SI->getName())
489 S = *NameOrErr;
490 else
491 consumeError(NameOrErr.takeError());
492 }
494493 }
495494
496495 Fmt << S;
15301529 uint64_t SectSize = Sect->getSize();
15311530
15321531 StringRef SectName;
1533 Sect->getName(SectName);
1532 Expected SectNameOrErr = Sect->getName();
1533 if (SectNameOrErr)
1534 SectName = *SectNameOrErr;
1535 else
1536 consumeError(SectNameOrErr.takeError());
1537
15341538 DataRefImpl Ref = Sect->getRawDataRefImpl();
15351539 StringRef SegmentName = O->getSectionFinalSegmentName(Ref);
15361540 outs() << SegmentName << ":" << SectName << ":";
17421746 }
17431747 for (const SectionRef &Section : O->sections()) {
17441748 StringRef SectName;
1745 Section.getName(SectName);
1749 Expected SecNameOrErr = Section.getName();
1750 if (SecNameOrErr)
1751 SectName = *SecNameOrErr;
1752 else
1753 consumeError(SecNameOrErr.takeError());
1754
17461755 DataRefImpl Ref = Section.getRawDataRefImpl();
17471756 StringRef SegName = O->getSectionFinalSegmentName(Ref);
17481757 if ((DumpSegName.empty() || SegName == DumpSegName) &&
18381847 MachOObjectFile *O) {
18391848 for (const SectionRef &Section : O->sections()) {
18401849 StringRef SectName;
1841 Section.getName(SectName);
1850 Expected SecNameOrErr = Section.getName();
1851 if (SecNameOrErr)
1852 SectName = *SecNameOrErr;
1853 else
1854 consumeError(SecNameOrErr.takeError());
1855
18421856 DataRefImpl Ref = Section.getRawDataRefImpl();
18431857 StringRef SegName = O->getSectionFinalSegmentName(Ref);
18441858 if (SegName == "__TEXT" && SectName == "__info_plist") {
19351949 if (DisassembleAll) {
19361950 for (const SectionRef &Section : MachOOF->sections()) {
19371951 StringRef SectName;
1938 Section.getName(SectName);
1952 if (Expected NameOrErr = Section.getName())
1953 SectName = *NameOrErr;
1954 else
1955 consumeError(NameOrErr.takeError());
1956
19391957 if (SectName.equals("__text")) {
19401958 DataRefImpl Ref = Section.getRawDataRefImpl();
19411959 StringRef SegName = MachOOF->getSectionFinalSegmentName(Ref);
32463264 continue;
32473265 if (objc_only) {
32483266 StringRef SectName;
3249 ((*(info->Sections))[SectIdx]).getName(SectName);
3267 Expected SecNameOrErr =
3268 ((*(info->Sections))[SectIdx]).getName();
3269 if (SecNameOrErr)
3270 SectName = *SecNameOrErr;
3271 else
3272 consumeError(SecNameOrErr.takeError());
3273
32503274 DataRefImpl Ref = ((*(info->Sections))[SectIdx]).getRawDataRefImpl();
32513275 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
32523276 if (SegName != "__OBJC" && SectName != "__cstring")
40384062 const char *sectname) {
40394063 for (const SectionRef &Section : O->sections()) {
40404064 StringRef SectName;
4041 Section.getName(SectName);
4065 Expected SecNameOrErr = Section.getName();
4066 if (SecNameOrErr)
4067 SectName = *SecNameOrErr;
4068 else
4069 consumeError(SecNameOrErr.takeError());
4070
40424071 DataRefImpl Ref = Section.getRawDataRefImpl();
40434072 StringRef SegName = O->getSectionFinalSegmentName(Ref);
40444073 if (SegName == segname && SectName == sectname)
40554084 return;
40564085
40574086 StringRef SectName;
4058 S.getName(SectName);
4087 Expected SecNameOrErr = S.getName();
4088 if (SecNameOrErr)
4089 SectName = *SecNameOrErr;
4090 else
4091 consumeError(SecNameOrErr.takeError());
4092
40594093 DataRefImpl Ref = S.getRawDataRefImpl();
40604094 StringRef SegName = O->getSectionFinalSegmentName(Ref);
40614095 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
41044138 if (S == SectionRef())
41054139 return;
41064140
4107 StringRef SectName;
4108 S.getName(SectName);
4141 StringRef SectName = unwrapOrError(S.getName(), O->getFileName());
41094142 DataRefImpl Ref = S.getRawDataRefImpl();
41104143 StringRef SegName = O->getSectionFinalSegmentName(Ref);
41114144 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
57795812 return;
57805813
57815814 StringRef SectName;
5782 S.getName(SectName);
5815 Expected SecNameOrErr = S.getName();
5816 if (SecNameOrErr)
5817 SectName = *SecNameOrErr;
5818 else
5819 consumeError(SecNameOrErr.takeError());
5820
57835821 DataRefImpl Ref = S.getRawDataRefImpl();
57845822 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
57855823 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
58425880 return;
58435881
58445882 StringRef SectName;
5845 S.getName(SectName);
5883 Expected SecNameOrErr = S.getName();
5884 if (SecNameOrErr)
5885 SectName = *SecNameOrErr;
5886 else
5887 consumeError(SecNameOrErr.takeError());
5888
58465889 DataRefImpl Ref = S.getRawDataRefImpl();
58475890 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
58485891 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
58885931 return;
58895932
58905933 StringRef SectName;
5891 S.getName(SectName);
5934 Expected SecNameOrErr = S.getName();
5935 if (SecNameOrErr)
5936 SectName = *SecNameOrErr;
5937 else
5938 consumeError(SecNameOrErr.takeError());
5939
58925940 DataRefImpl Ref = S.getRawDataRefImpl();
58935941 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
58945942 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
59455993 return;
59465994
59475995 StringRef SectName;
5948 S.getName(SectName);
5996 Expected SecNameOrErr = S.getName();
5997 if (SecNameOrErr)
5998 SectName = *SecNameOrErr;
5999 else
6000 consumeError(SecNameOrErr.takeError());
6001
59496002 DataRefImpl Ref = S.getRawDataRefImpl();
59506003 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
59516004 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
59956048 const char *r;
59966049
59976050 StringRef SectName;
5998 S.getName(SectName);
6051 Expected SecNameOrErr = S.getName();
6052 if (SecNameOrErr)
6053 SectName = *SecNameOrErr;
6054 else
6055 consumeError(SecNameOrErr.takeError());
6056
59996057 DataRefImpl Ref = S.getRawDataRefImpl();
60006058 StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
60016059 outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
60306088 CreateSymbolAddressMap(O, &AddrMap);
60316089
60326090 std::vector Sections;
6033 for (const SectionRef &Section : O->sections()) {
6034 StringRef SectName;
6035 Section.getName(SectName);
6091 for (const SectionRef &Section : O->sections())
60366092 Sections.push_back(Section);
6037 }
60386093
60396094 struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
60406095
61156170 CreateSymbolAddressMap(O, &AddrMap);
61166171
61176172 std::vector Sections;
6118 for (const SectionRef &Section : O->sections()) {
6119 StringRef SectName;
6120 Section.getName(SectName);
6173 for (const SectionRef &Section : O->sections())
61216174 Sections.push_back(Section);
6122 }
61236175
61246176 struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
61256177
62136265 CreateSymbolAddressMap(O, &AddrMap);
62146266
62156267 std::vector Sections;
6216 for (const SectionRef &Section : O->sections()) {
6217 StringRef SectName;
6218 Section.getName(SectName);
6268 for (const SectionRef &Section : O->sections())
62196269 Sections.push_back(Section);
6220 }
62216270
62226271 struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
62236272
63746423 CreateSymbolAddressMap(O, &AddrMap);
63756424
63766425 std::vector Sections;
6377 for (const SectionRef &Section : O->sections()) {
6378 StringRef SectName;
6379 Section.getName(SectName);
6426 for (const SectionRef &Section : O->sections())
63806427 Sections.push_back(Section);
6381 }
63826428
63836429 struct DisassembleInfo info(O, &AddrMap, &Sections, true);
63846430
73437389 outs() << "(" << DisSegName << "," << DisSectName << ") section\n";
73447390
73457391 for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
7346 StringRef SectName;
7347 if (Sections[SectIdx].getName(SectName) || SectName != DisSectName)
7392 Expected SecNameOrErr = Sections[SectIdx].getName();
7393 if (!SecNameOrErr) {
7394 consumeError(SecNameOrErr.takeError());
7395 continue;
7396 }
7397 if (*SecNameOrErr != DisSectName)
73487398 continue;
73497399
73507400 DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
77417791 auto Sym = Symbols.upper_bound(Addr);
77427792 if (Sym == Symbols.begin()) {
77437793 // The first symbol in the object is after this reference, the best we can
7744 // do is section-relative notation.
7745 RelocSection.getName(Name);
7794 // do is section-relative notation.
7795 if (Expected NameOrErr = RelocSection.getName())
7796 Name = *NameOrErr;
7797 else
7798 consumeError(NameOrErr.takeError());
7799
77467800 Addend = Addr - SectionAddr;
77477801 return;
77487802 }
77617815
77627816 // There is a symbol before this reference, but it's in a different
77637817 // section. Probably not helpful to mention it, so use the section name.
7764 RelocSection.getName(Name);
7818 if (Expected NameOrErr = RelocSection.getName())
7819 Name = *NameOrErr;
7820 else
7821 consumeError(NameOrErr.takeError());
7822
77657823 Addend = Addr - SectionAddr;
77667824 }
77677825
81268184
81278185 for (const SectionRef &Section : Obj->sections()) {
81288186 StringRef SectName;
8129 Section.getName(SectName);
8187 if (Expected NameOrErr = Section.getName())
8188 SectName = *NameOrErr;
8189 else
8190 consumeError(NameOrErr.takeError());
8191
81308192 if (SectName == "__compact_unwind")
81318193 printMachOCompactUnwindSection(Obj, Symbols, Section);
81328194 else if (SectName == "__unwind_info")
343343 static bool shouldKeep(object::SectionRef S) {
344344 if (FilterSections.empty())
345345 return true;
346 StringRef SecName;
347 std::error_code error = S.getName(SecName);
348 if (error)
346
347 Expected SecNameOrErr = S.getName();
348 if (!SecNameOrErr) {
349 consumeError(SecNameOrErr.takeError());
349350 return false;
351 }
352 StringRef SecName = *SecNameOrErr;
353
350354 // StringSet does not allow empty key so avoid adding sections with
351355 // no name (such as the section with index 0) here.
352356 if (!SecName.empty())
919923 StringSaver &Saver) {
920924 Optional Plt = None;
921925 for (const SectionRef &Section : Obj->sections()) {
922 StringRef Name;
923 if (Section.getName(Name))
926 Expected SecNameOrErr = Section.getName();
927 if (!SecNameOrErr) {
928 consumeError(SecNameOrErr.takeError());
924929 continue;
925 if (Name == ".plt")
930 }
931 if (*SecNameOrErr == ".plt")
926932 Plt = Section;
927933 }
928934 if (!Plt)
12051211 DataRefImpl DR = Section.getRawDataRefImpl();
12061212 SegmentName = MachO->getSectionFinalSegmentName(DR);
12071213 }
1208 StringRef SectionName;
1209 error(Section.getName(SectionName));
1210
1214
1215 StringRef SectionName = unwrapOrError(Section.getName(), Obj->getFileName());
12111216 // If the section has no symbol at the start, just insert a dummy one.
12121217 if (Symbols.empty() || std::get<0>(Symbols[0]) != 0) {
12131218 Symbols.insert(
15801585 }
15811586
15821587 for (std::pair> &P : SecToRelSec) {
1583 StringRef SecName;
1584 error(P.first.getName(SecName));
1588 StringRef SecName = unwrapOrError(P.first.getName(), Obj->getFileName());
15851589 outs() << "RELOCATION RECORDS FOR [" << SecName << "]:\n";
15861590
15871591 for (SectionRef Section : P.second) {
16531657 "Idx Name Size VMA Type\n";
16541658
16551659 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
1656 StringRef Name;
1657 error(Section.getName(Name));
1660 StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
16581661 uint64_t VMA = Section.getAddress();
16591662 if (shouldAdjustVA(Section))
16601663 VMA += AdjustVMA;
16811684
16821685 void printSectionContents(const ObjectFile *Obj) {
16831686 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
1684 StringRef Name;
1685 error(Section.getName(Name));
1687 StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
16861688 uint64_t BaseAddr = Section.getAddress();
16871689 uint64_t Size = Section.getSize();
16881690 if (!Size)
17461748 section_iterator Section = unwrapOrError(Symbol.getSection(), ArchiveName,
17471749 FileName, ArchitectureName);
17481750 StringRef Name;
1749 if (Type == SymbolRef::ST_Debug && Section != O->section_end())
1750 Section->getName(Name);
1751 else
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 {
17521758 Name = unwrapOrError(Symbol.getName(), ArchiveName, FileName,
17531759 ArchitectureName);
1760 }
17541761
17551762 bool Global = Flags & SymbolRef::SF_Global;
17561763 bool Weak = Flags & SymbolRef::SF_Weak;
17961803 StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
17971804 outs() << SegmentName << ",";
17981805 }
1799 StringRef SectionName;
1800 error(Section->getName(SectionName));
1806 StringRef SectionName =
1807 unwrapOrError(Section->getName(), O->getFileName());
18011808 outs() << SectionName;
18021809 }
18031810
18701877 Optional ClangASTSection;
18711878 for (auto Sec : ToolSectionFilter(*Obj)) {
18721879 StringRef Name;
1873 Sec.getName(Name);
1880 if (Expected NameOrErr = Sec.getName())
1881 Name = *NameOrErr;
1882 else
1883 consumeError(NameOrErr.takeError());
1884
18741885 if (Name == ClangASTSectionName) {
18751886 ClangASTSection = Sec;
18761887 break;
19021913
19031914 for (auto Sec : ToolSectionFilter(*Obj)) {
19041915 StringRef Name;
1905 Sec.getName(Name);
1916 if (Expected NameOrErr = Sec.getName())
1917 Name = *NameOrErr;
1918 else
1919 consumeError(NameOrErr.takeError());
1920
19061921 if (Name == FaultMapSectionName) {
19071922 FaultMapSection = Sec;
19081923 break;
13681368 LazyRandomTypeCollection Types(100);
13691369
13701370 for (const auto &S : getObj().sections()) {
1371 StringRef SectionName;
1372 if (auto EC = S.getName(SectionName))
1373 return errorCodeToError(EC);
1371 Expected NameOrErr = S.getName();
1372 if (!NameOrErr)
1373 return NameOrErr.takeError();
1374 StringRef SectionName = *NameOrErr;
13741375
13751376 // .debug$T is a standard CodeView type section, while .debug$P is the same
13761377 // format but used for MSVC precompiled header object files.
6565 static inline bool isCodeViewDebugSubsection(object::SectionRef Section,
6666 StringRef Name,
6767 BinaryStreamReader &Reader) {
68 StringRef SectionName;
69 if (Section.getName(SectionName))
70 return false;
71
72 if (SectionName != Name)
73 return false;
68 if (Expected NameOrErr = Section.getName()) {
69 if (*NameOrErr != Name)
70 return false;
71 } else {
72 consumeError(NameOrErr.takeError());
73 return false;
74 }
7475
7576 Expected ContentsOrErr = Section.getContents();
7677 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;
894 error(S.getName(SectionName));
893 StringRef SectionName = unwrapOrError(Obj->getFileName(), S.getName());
895894 // .debug$T is a standard CodeView type section, while .debug$P is the same
896895 // format but used for MSVC precompiled header object files.
897896 if (SectionName == ".debug$T" || SectionName == ".debug$P")
898897 printCodeViewTypeSection(SectionName, S);
899898 }
900899 for (const SectionRef &S : Obj->sections()) {
901 StringRef SectionName;
902 error(S.getName(SectionName));
900 StringRef SectionName = unwrapOrError(Obj->getFileName(), S.getName());
903901 if (SectionName == ".debug$S")
904902 printCodeViewSymbolSection(SectionName, S);
905903 }
12411239 GlobalTypeTableBuilder &GlobalCVTypes,
12421240 bool GHash) {
12431241 for (const SectionRef &S : Obj->sections()) {
1244 StringRef SectionName;
1245 error(S.getName(SectionName));
1242 StringRef SectionName = unwrapOrError(Obj->getFileName(), S.getName());
12461243 if (SectionName == ".debug$T") {
12471244 StringRef Data = unwrapOrError(Obj->getFileName(), S.getContents());
12481245 uint32_t Magic;
13101307 ++SectionNumber;
13111308 const coff_section *Section = Obj->getCOFFSection(Sec);
13121309
1313 StringRef Name;
1314 error(Sec.getName(Name));
1310 StringRef Name = unwrapOrError(Obj->getFileName(), Sec.getName());
13151311
13161312 DictScope D(W, "Section");
13171313 W.printNumber("Number", SectionNumber);
13581354 int SectionNumber = 0;
13591355 for (const SectionRef &Section : Obj->sections()) {
13601356 ++SectionNumber;
1361 StringRef Name;
1362 error(Section.getName(Name));
1357 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
13631358
13641359 bool PrintedGroup = false;
13651360 for (const RelocationRef &Reloc : Section.relocations()) {
16881683
16891684 void COFFDumper::printCOFFDirectives() {
16901685 for (const SectionRef &Section : Obj->sections()) {
1691 StringRef Name;
1692
1693 error(Section.getName(Name));
1686 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
16941687 if (Name != ".drectve")
16951688 continue;
16961689
17291722 void COFFDumper::printCOFFResources() {
17301723 ListScope ResourcesD(W, "Resources");
17311724 for (const SectionRef &S : Obj->sections()) {
1732 StringRef Name;
1733 error(S.getName(Name));
1725 StringRef Name = unwrapOrError(Obj->getFileName(), S.getName());
17341726 if (!Name.startswith(".rsrc"))
17351727 continue;
17361728
18541846 object::SectionRef StackMapSection;
18551847 for (auto Sec : Obj->sections()) {
18561848 StringRef Name;
1857 Sec.getName(Name);
1849 if (Expected NameOrErr = Sec.getName())
1850 Name = *NameOrErr;
1851 else
1852 consumeError(NameOrErr.takeError());
1853
18581854 if (Name == ".llvm_stackmaps") {
18591855 StackMapSection = Sec;
18601856 break;
18811877 object::SectionRef AddrsigSection;
18821878 for (auto Sec : Obj->sections()) {
18831879 StringRef Name;
1884 Sec.getName(Name);
1880 if (Expected NameOrErr = Sec.getName())
1881 Name = *NameOrErr;
1882 else
1883 consumeError(NameOrErr.takeError());
1884
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 Sec.getName(SectionName);
4671 if (Expected NameOrErr = Sec.getName())
4672 SectionName = *NameOrErr;
4673 else
4674 consumeError(NameOrErr.takeError());
4675
46724676 const Elf_Shdr *ElfSec = Obj->getSection(Sec.getRawDataRefImpl());
46734677 if (!SectionName.startswith(".stack_sizes"))
46744678 continue;
47164720
47174721 for (const SectionRef &Sec : Obj->sections()) {
47184722 StringRef SectionName;
4719 Sec.getName(SectionName);
4723 if (Expected NameOrErr = Sec.getName())
4724 SectionName = *NameOrErr;
4725 else
4726 consumeError(NameOrErr.takeError());
4727
47204728 // A stack size section that we haven't encountered yet is mapped to the
47214729 // null section until we find its corresponding relocation section.
47224730 if (SectionName.startswith(".stack_sizes"))
47534761
47544762 // Warn about stack size sections without a relocation section.
47554763 StringRef StackSizeSectionName;
4756 StackSizesSec.getName(StackSizeSectionName);
4764 if (Expected NameOrErr = StackSizesSec.getName())
4765 StackSizeSectionName = *NameOrErr;
4766 else
4767 consumeError(NameOrErr.takeError());
4768
47574769 if (RelocSec == NullSection) {
47584770 reportWarning(" '" + FileStr + "': section " + StackSizeSectionName +
47594771 " does not have a corresponding "
47814793 for (const RelocationRef &Reloc : RelocSec.relocations()) {
47824794 if (!IsSupportedFn(Reloc.getType())) {
47834795 StringRef RelocSectionName;
4784 RelocSec.getName(RelocSectionName);
4796 Expected NameOrErr = RelocSec.getName();
4797 if (NameOrErr)
4798 RelocSectionName = *NameOrErr;
4799 else
4800 consumeError(NameOrErr.takeError());
4801
47854802 StringRef RelocName = EF->getRelocationTypeName(Reloc.getType());
47864803 reportError(
47874804 createStringError(object_error::parse_failed,
439439 MachOSection MOSection;
440440 getSection(Obj, Section.getRawDataRefImpl(), MOSection);
441441 DataRefImpl DR = Section.getRawDataRefImpl();
442
443 StringRef Name;
444 error(Section.getName(Name));
445
442 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
446443 ArrayRef RawName = Obj->getSectionRawName(DR);
447444 StringRef SegmentName = Obj->getSectionFinalSegmentName(DR);
448445 ArrayRef RawSegmentName = Obj->getSectionRawFinalSegmentName(DR);
493490
494491 std::error_code EC;
495492 for (const SectionRef &Section : Obj->sections()) {
496 StringRef Name;
497 error(Section.getName(Name));
498
493 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
499494 bool PrintedGroup = false;
500495 for (const RelocationRef &Reloc : Section.relocations()) {
501496 if (!PrintedGroup) {
540535 }
541536 } else if (!IsScattered) {
542537 section_iterator SecI = Obj->getRelocationSection(DR);
543 if (SecI != Obj->section_end()) {
544 error(SecI->getName(TargetName));
545 }
538 if (SecI != Obj->section_end())
539 TargetName = unwrapOrError(Obj->getFileName(), SecI->getName());
546540 }
547541 if (TargetName.empty())
548542 TargetName = "-";
613607 error(errorToErrorCode(SecIOrErr.takeError()));
614608 section_iterator SecI = *SecIOrErr;
615609 if (SecI != Obj->section_end())
616 error(SecI->getName(SectionName));
610 SectionName = unwrapOrError(Obj->getFileName(), SecI->getName());
617611
618612 DictScope D(W, "Symbol");
619613 W.printNumber("Name", SymbolName, MOSymbol.StringIndex);
643637 object::SectionRef StackMapSection;
644638 for (auto Sec : Obj->sections()) {
645639 StringRef Name;
646 Sec.getName(Name);
640 if (Expected NameOrErr = Sec.getName())
641 Name = *NameOrErr;
642 else
643 consumeError(NameOrErr.takeError());
644
647645 if (Name == "__llvm_stackmaps") {
648646 StackMapSection = Sec;
649647 break;
4848
4949 SecIndex = Obj->isELF() ? 0 : 1;
5050 for (object::SectionRef SecRef : Obj->sections()) {
51 StringRef SecName;
52 error(SecRef.getName(SecName));
51 StringRef SecName = unwrapOrError(Obj->getFileName(), SecRef.getName());
5352 auto NameIt = SecNames.find(SecName);
5453 if (NameIt != SecNames.end())
5554 NameIt->second = true;
7675 bool First = true;
7776 for (object::SectionRef Section :
7877 getSectionRefsByNameOrIndex(Obj, Sections)) {
79 StringRef SectionName;
80 error(Section.getName(SectionName));
78 StringRef SectionName =
79 unwrapOrError(Obj->getFileName(), Section.getName());
80
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 error(Section.getName(SectionName));
113 StringRef SectionName =
114 unwrapOrError(Obj->getFileName(), Section.getName());
115
115116 if (!First)
116117 W.startLine() << '\n';
117118 First = false;
132132 int SectionNumber = 0;
133133 for (const SectionRef &Section : Obj->sections()) {
134134 bool PrintedGroup = false;
135 StringRef Name;
136 error(Section.getName(Name));
135 StringRef Name = unwrapOrError(Obj->getFileName(), Section.getName());
136
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 Section.getName(Name);
308 if (Expected NameOrErr = Section.getName())
309 Name = *NameOrErr;
310 else
311 consumeError(NameOrErr.takeError());
309312
310313 if (Name != ".pdata" && !Name.startswith(".pdata$"))
311314 continue;
440440 continue;
441441 }
442442 object::section_iterator Sec = *SecOrErr;
443 StringRef SecName;
444 Sec->getName(SecName);
445443 Address.SectionIndex = Sec->getIndex();
446444 uint64_t SectionLoadAddress =
447445 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 }
118107
119108 static bool error(Twine Message) {
120109 HadError = true;
396385 uint64_t size = Section.getSize();
397386 total += size;
398387
399 StringRef name;
400 if (error(Section.getName(name)))
388 Expected name_or_err = Section.getName();
389 if (!name_or_err) {
390 error(name_or_err.takeError(), Obj->getFileName());
401391 return;
392 }
393
402394 uint64_t addr = Section.getAddress();
403 max_name_len = std::max(max_name_len, name.size());
395 max_name_len = std::max(max_name_len, name_or_err->size());
404396 max_size_len = std::max(max_size_len, getNumLengthAsString(size));
405397 max_addr_len = std::max(max_addr_len, getNumLengthAsString(addr));
406398 }
430422 for (const SectionRef &Section : Obj->sections()) {
431423 if (!considerForSize(Obj, Section))
432424 continue;
433 StringRef name;
434 if (error(Section.getName(name)))
425
426 Expected name_or_err = Section.getName();
427 if (!name_or_err) {
428 error(name_or_err.takeError(), Obj->getFileName());
435429 return;
430 }
431
436432 uint64_t size = Section.getSize();
437433 uint64_t addr = Section.getAddress();
438 std::string namestr = name;
439
440 outs() << format(fmt.str().c_str(), namestr.c_str(), size, addr);
434 outs() << format(fmt.str().c_str(), name_or_err->str().c_str(), size, addr);
441435 }
442436
443437 if (ELFCommons) {
111111 if (SC.hasStrings() && SC.hasChecksums())
112112 break;
113113
114 StringRef SectionName;
115 S.getName(SectionName);
114 Expected SectionNameOrErr = S.getName();
115 if (!SectionNameOrErr) {
116 consumeError(SectionNameOrErr.takeError());
117 continue;
118 }
119
116120 ArrayRef sectionData;
117 if (SectionName != ".debug$S")
121 if ((*SectionNameOrErr) != ".debug$S")
118122 continue;
119123
120124 const object::coff_section *COFFSection = Obj.getCOFFSection(S);
154158 for (const auto &ObjSection : Obj.sections()) {
155159 const object::coff_section *COFFSection = Obj.getCOFFSection(ObjSection);
156160 COFFYAML::Section NewYAMLSection;
157 ObjSection.getName(NewYAMLSection.Name);
161
162 if (Expected NameOrErr = ObjSection.getName())
163 NewYAMLSection.Name = *NameOrErr;
164 else
165 consumeError(NameOrErr.takeError());
166
158167 NewYAMLSection.Header.Characteristics = COFFSection->Characteristics;
159168 NewYAMLSection.Header.VirtualAddress = COFFSection->VirtualAddress;
160169 NewYAMLSection.Header.VirtualSize = COFFSection->VirtualSize;