mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-29 06:10:48 +00:00
[llvm-readobj] - Simplify findSectionByName(). NFCI.
It turns out that findSectionByName can return const Elf_Shdr * instead of Expected<>, because its code never returns an error currently (it reports warnings instead). Differential revision: https://reviews.llvm.org/D85135
This commit is contained in:
parent
a76b464318
commit
16a78424ed
@ -353,7 +353,7 @@ public:
|
||||
void printSymbolsHelper(bool IsDynamic) const;
|
||||
std::string getDynamicEntry(uint64_t Type, uint64_t Value) const;
|
||||
|
||||
Expected<const typename ELFT::Shdr *> findSectionByName(StringRef Name) const;
|
||||
const Elf_Shdr *findSectionByName(StringRef Name) const;
|
||||
|
||||
const Elf_Shdr *getDotSymtabSec() const { return DotSymtabSec; }
|
||||
const Elf_Shdr *getDotCGProfileSec() const { return DotCGProfileSec; }
|
||||
@ -2454,7 +2454,7 @@ void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) {
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
Expected<const typename ELFT::Shdr *>
|
||||
const typename ELFT::Shdr *
|
||||
ELFDumper<ELFT>::findSectionByName(StringRef Name) const {
|
||||
const ELFFile<ELFT> *Obj = ObjF->getELFFile();
|
||||
for (const Elf_Shdr &Shdr : cantFail(Obj->sections())) {
|
||||
@ -3009,12 +3009,7 @@ Error MipsGOTParser<ELFT>::findGOT(Elf_Dyn_Range DynTable,
|
||||
|
||||
// Find static GOT secton.
|
||||
if (IsStatic) {
|
||||
Expected<const Elf_Shdr *> GotOrErr = Dumper.findSectionByName(".got");
|
||||
if (!GotOrErr)
|
||||
return GotOrErr.takeError();
|
||||
else
|
||||
GotSec = *GotOrErr;
|
||||
|
||||
GotSec = Dumper.findSectionByName(".got");
|
||||
if (!GotSec)
|
||||
return Error::success();
|
||||
|
||||
@ -3333,19 +3328,14 @@ static void printMipsReginfoData(ScopedPrinter &W,
|
||||
|
||||
template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() {
|
||||
const ELFFile<ELFT> *Obj = ObjF->getELFFile();
|
||||
Expected<const Elf_Shdr *> RegInfoOrErr = findSectionByName(".reginfo");
|
||||
if (!RegInfoOrErr) {
|
||||
reportUniqueWarning(RegInfoOrErr.takeError());
|
||||
return;
|
||||
}
|
||||
|
||||
if ((*RegInfoOrErr) == nullptr) {
|
||||
const Elf_Shdr *RegInfo = findSectionByName(".reginfo");
|
||||
if (!RegInfo) {
|
||||
W.startLine() << "There is no .reginfo section in the file.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayRef<uint8_t> Sec = unwrapOrError(ObjF->getFileName(),
|
||||
Obj->getSectionContents(*RegInfoOrErr));
|
||||
Obj->getSectionContents(RegInfo));
|
||||
if (Sec.size() != sizeof(Elf_Mips_RegInfo<ELFT>)) {
|
||||
W.startLine() << "The .reginfo section has a wrong size.\n";
|
||||
return;
|
||||
@ -3358,21 +3348,16 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() {
|
||||
|
||||
template <class ELFT> void ELFDumper<ELFT>::printMipsOptions() {
|
||||
const ELFFile<ELFT> *Obj = ObjF->getELFFile();
|
||||
Expected<const Elf_Shdr *> MipsOptOrErr = findSectionByName(".MIPS.options");
|
||||
if (!MipsOptOrErr) {
|
||||
reportUniqueWarning(MipsOptOrErr.takeError());
|
||||
return;
|
||||
}
|
||||
|
||||
if ((*MipsOptOrErr) == nullptr) {
|
||||
const Elf_Shdr *MipsOpts = findSectionByName(".MIPS.options");
|
||||
if (!MipsOpts) {
|
||||
W.startLine() << "There is no .MIPS.options section in the file.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
DictScope GS(W, "MIPS Options");
|
||||
|
||||
ArrayRef<uint8_t> Sec = unwrapOrError(ObjF->getFileName(),
|
||||
Obj->getSectionContents(*MipsOptOrErr));
|
||||
ArrayRef<uint8_t> Sec =
|
||||
unwrapOrError(ObjF->getFileName(), Obj->getSectionContents(MipsOpts));
|
||||
while (!Sec.empty()) {
|
||||
if (Sec.size() < sizeof(Elf_Mips_Options<ELFT>)) {
|
||||
W.startLine() << "The .MIPS.options section has a wrong size.\n";
|
||||
@ -5982,16 +5967,13 @@ template <class ELFT>
|
||||
Expected<const Elf_Mips_ABIFlags<ELFT> *>
|
||||
getMipsAbiFlagsSection(const ELFObjectFile<ELFT> *ObjF,
|
||||
const ELFDumper<ELFT> &Dumper) {
|
||||
Expected<const typename ELFT::Shdr *> SecOrErr =
|
||||
Dumper.findSectionByName(".MIPS.abiflags");
|
||||
if (!SecOrErr)
|
||||
return SecOrErr.takeError();
|
||||
if (*SecOrErr == nullptr)
|
||||
const typename ELFT::Shdr *Sec = Dumper.findSectionByName(".MIPS.abiflags");
|
||||
if (Sec == nullptr)
|
||||
return nullptr;
|
||||
|
||||
const ELFFile<ELFT> *Obj = ObjF->getELFFile();
|
||||
constexpr StringRef ErrPrefix = "unable to read the .MIPS.abiflags section: ";
|
||||
Expected<ArrayRef<uint8_t>> DataOrErr = Obj->getSectionContents(*SecOrErr);
|
||||
Expected<ArrayRef<uint8_t>> DataOrErr = Obj->getSectionContents(Sec);
|
||||
if (!DataOrErr)
|
||||
return createError(ErrPrefix + toString(DataOrErr.takeError()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user