@@ -4749,11 +4749,14 @@ void DumpStyle<ELFT>::printStackSize(const ELFObjectFile<ELFT> *Obj,
4749
4749
Data, &Offset);
4750
4750
}
4751
4751
4752
- template <class ELFT >
4753
- SectionRef toSectionRef (const ObjectFile *Obj, const typename ELFT::Shdr *Sec) {
4754
- DataRefImpl DRI;
4755
- DRI.p = reinterpret_cast <uintptr_t >(Sec);
4756
- return SectionRef (DRI, Obj);
4752
+ // Used for printing section names in places where possible errors can be
4753
+ // ignored.
4754
+ static StringRef getSectionName (const SectionRef &Sec) {
4755
+ Expected<StringRef> NameOrErr = Sec.getName ();
4756
+ if (NameOrErr)
4757
+ return *NameOrErr;
4758
+ consumeError (NameOrErr.takeError ());
4759
+ return " <?>" ;
4757
4760
}
4758
4761
4759
4762
template <class ELFT >
@@ -4764,16 +4767,11 @@ void DumpStyle<ELFT>::printNonRelocatableStackSizes(
4764
4767
const ELFFile<ELFT> *EF = Obj->getELFFile ();
4765
4768
StringRef FileStr = Obj->getFileName ();
4766
4769
for (const SectionRef &Sec : Obj->sections ()) {
4767
- StringRef SectionName;
4768
- if (Expected<StringRef> NameOrErr = Sec.getName ())
4769
- SectionName = *NameOrErr;
4770
- else
4771
- consumeError (NameOrErr.takeError ());
4772
-
4773
- const Elf_Shdr *ElfSec = Obj->getSection (Sec.getRawDataRefImpl ());
4770
+ StringRef SectionName = getSectionName (Sec);
4774
4771
if (!SectionName.startswith (" .stack_sizes" ))
4775
4772
continue ;
4776
4773
PrintHeader ();
4774
+ const Elf_Shdr *ElfSec = Obj->getSection (Sec.getRawDataRefImpl ());
4777
4775
ArrayRef<uint8_t > Contents =
4778
4776
unwrapOrError (this ->FileName , EF->getSectionContents (ElfSec));
4779
4777
DataExtractor Data (
@@ -4798,8 +4796,7 @@ void DumpStyle<ELFT>::printNonRelocatableStackSizes(
4798
4796
FileStr);
4799
4797
}
4800
4798
uint64_t SymValue = Data.getAddress (&Offset);
4801
- printFunctionStackSize (Obj, SymValue,
4802
- toSectionRef<ELFT>(Obj, FunctionELFSec),
4799
+ printFunctionStackSize (Obj, SymValue, Obj->toSectionRef (FunctionELFSec),
4803
4800
SectionName, Data, &Offset);
4804
4801
}
4805
4802
}
@@ -4848,7 +4845,7 @@ void DumpStyle<ELFT>::printRelocatableStackSizes(
4848
4845
if (!ContentsSectionNameOrErr->startswith (" .stack_sizes" ))
4849
4846
continue ;
4850
4847
// Insert a mapping from the stack sizes section to its relocation section.
4851
- StackSizeRelocMap[toSectionRef<ELFT>(Obj, ContentsSec)] = Sec;
4848
+ StackSizeRelocMap[Obj-> toSectionRef ( ContentsSec)] = Sec;
4852
4849
}
4853
4850
4854
4851
for (const auto &StackSizeMapEntry : StackSizeRelocMap) {
@@ -4857,12 +4854,7 @@ void DumpStyle<ELFT>::printRelocatableStackSizes(
4857
4854
const SectionRef &RelocSec = StackSizeMapEntry.second ;
4858
4855
4859
4856
// Warn about stack size sections without a relocation section.
4860
- StringRef StackSizeSectionName;
4861
- if (Expected<StringRef> NameOrErr = StackSizesSec.getName ())
4862
- StackSizeSectionName = *NameOrErr;
4863
- else
4864
- consumeError (NameOrErr.takeError ());
4865
-
4857
+ StringRef StackSizeSectionName = getSectionName (StackSizesSec);
4866
4858
if (RelocSec == NullSection) {
4867
4859
reportWarning (createError (" section " + StackSizeSectionName +
4868
4860
" does not have a corresponding "
@@ -4876,9 +4868,8 @@ void DumpStyle<ELFT>::printRelocatableStackSizes(
4876
4868
// described in it.
4877
4869
const Elf_Shdr *StackSizesELFSec =
4878
4870
Obj->getSection (StackSizesSec.getRawDataRefImpl ());
4879
- const SectionRef FunctionSec = toSectionRef<ELFT>(
4880
- Obj, unwrapOrError (this ->FileName ,
4881
- EF->getSection (StackSizesELFSec->sh_link )));
4871
+ const SectionRef FunctionSec = Obj->toSectionRef (unwrapOrError (
4872
+ this ->FileName , EF->getSection (StackSizesELFSec->sh_link )));
4882
4873
4883
4874
bool (*IsSupportedFn)(uint64_t );
4884
4875
RelocationResolver Resolver;
@@ -4889,21 +4880,13 @@ void DumpStyle<ELFT>::printRelocatableStackSizes(
4889
4880
Contents.size ()),
4890
4881
Obj->isLittleEndian (), sizeof (Elf_Addr));
4891
4882
for (const RelocationRef &Reloc : RelocSec.relocations ()) {
4892
- if (!IsSupportedFn (Reloc.getType ())) {
4893
- StringRef RelocSectionName;
4894
- Expected<StringRef> NameOrErr = RelocSec.getName ();
4895
- if (NameOrErr)
4896
- RelocSectionName = *NameOrErr;
4897
- else
4898
- consumeError (NameOrErr.takeError ());
4899
-
4900
- StringRef RelocName = EF->getRelocationTypeName (Reloc.getType ());
4901
- reportError (
4902
- createStringError (object_error::parse_failed,
4903
- " unsupported relocation type in section %s: %s" ,
4904
- RelocSectionName.data (), RelocName.data ()),
4905
- Obj->getFileName ());
4906
- }
4883
+ if (!IsSupportedFn (Reloc.getType ()))
4884
+ reportError (createStringError (
4885
+ object_error::parse_failed,
4886
+ " unsupported relocation type in section %s: %s" ,
4887
+ getSectionName (RelocSec).data (),
4888
+ EF->getRelocationTypeName (Reloc.getType ()).data ()),
4889
+ Obj->getFileName ());
4907
4890
this ->printStackSize (Obj, Reloc, FunctionSec, StackSizeSectionName,
4908
4891
Resolver, Data);
4909
4892
}
0 commit comments