From cfda4e0d55830406ad19fe0085db60bde6049a68 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 10 May 2019 10:19:08 +0000 Subject: [PATCH] [Object] Move ELF specific ObjectFile::getBuildAttributes to ELFObjectFileBase Change the return type from std::error_code to Error and make the function protected. llvm-svn: 360416 --- include/llvm/Object/ELFObjectFile.h | 45 +++++++++++++++-------------- include/llvm/Object/ObjectFile.h | 5 ---- lib/Object/ELFObjectFile.cpp | 6 ++-- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 1d543fb4e53..6884763f661 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -64,6 +64,7 @@ protected: virtual uint64_t getSectionOffset(DataRefImpl Sec) const = 0; virtual Expected getRelocationAddend(DataRefImpl Rel) const = 0; + virtual Error getBuildAttributes(ARMAttributeParser &Attributes) const = 0; public: using elf_symbol_iterator_range = iterator_range; @@ -352,6 +353,28 @@ protected: (Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_PROTECTED)); } + Error getBuildAttributes(ARMAttributeParser &Attributes) const override { + auto SectionsOrErr = EF.sections(); + if (!SectionsOrErr) + return SectionsOrErr.takeError(); + + for (const Elf_Shdr &Sec : *SectionsOrErr) { + if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES) { + auto ErrorOrContents = EF.getSectionContents(&Sec); + if (!ErrorOrContents) + return ErrorOrContents.takeError(); + + auto Contents = ErrorOrContents.get(); + if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1) + return Error::success(); + + Attributes.Parse(Contents, ELFT::TargetEndianness == support::little); + break; + } + } + return Error::success(); + } + // This flag is used for classof, to distinguish ELFObjectFile from // its subclass. If more subclasses will be created, this flag will // have to become an enum. @@ -393,28 +416,6 @@ public: unsigned getPlatformFlags() const override { return EF.getHeader()->e_flags; } - std::error_code getBuildAttributes(ARMAttributeParser &Attributes) const override { - auto SectionsOrErr = EF.sections(); - if (!SectionsOrErr) - return errorToErrorCode(SectionsOrErr.takeError()); - - for (const Elf_Shdr &Sec : *SectionsOrErr) { - if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES) { - auto ErrorOrContents = EF.getSectionContents(&Sec); - if (!ErrorOrContents) - return errorToErrorCode(ErrorOrContents.takeError()); - - auto Contents = ErrorOrContents.get(); - if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1) - return std::error_code(); - - Attributes.Parse(Contents, ELFT::TargetEndianness == support::little); - break; - } - } - return std::error_code(); - } - const ELFFile *getELFFile() const { return &EF; } bool isDyldType() const { return isDyldELFObject; } diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index a3cd907684a..c1c2d833436 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -331,11 +331,6 @@ public: /// Create a triple from the data in this object file. Triple makeTriple() const; - virtual std::error_code - getBuildAttributes(ARMAttributeParser &Attributes) const { - return std::error_code(); - } - /// Maps a debug section name to a standard DWARF section name. virtual StringRef mapDebugSectionName(StringRef Name) const { return Name; } diff --git a/lib/Object/ELFObjectFile.cpp b/lib/Object/ELFObjectFile.cpp index 07851411fe6..cc1eeefec26 100644 --- a/lib/Object/ELFObjectFile.cpp +++ b/lib/Object/ELFObjectFile.cpp @@ -148,8 +148,7 @@ SubtargetFeatures ELFObjectFileBase::getMIPSFeatures() const { SubtargetFeatures ELFObjectFileBase::getARMFeatures() const { SubtargetFeatures Features; ARMAttributeParser Attributes; - std::error_code EC = getBuildAttributes(Attributes); - if (EC) + if (Error E = getBuildAttributes(Attributes)) return SubtargetFeatures(); // both ARMv7-M and R have to support thumb hardware div @@ -279,8 +278,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const { return; ARMAttributeParser Attributes; - std::error_code EC = getBuildAttributes(Attributes); - if (EC) + if (Error E = getBuildAttributes(Attributes)) return; std::string Triple;