summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-05-10 10:19:08 +0000
committerFangrui Song <maskray@google.com>2019-05-10 10:19:08 +0000
commit93b6aa07519753beab6e7410700e4d0c569d5890 (patch)
treec137e8b94f68e167fed4af7d0588c445a9f2c138
parenta2b780b731969f63e2e9e9ea76e43cf86d47a5d3 (diff)
downloadbcm5719-llvm-93b6aa07519753beab6e7410700e4d0c569d5890.tar.gz
bcm5719-llvm-93b6aa07519753beab6e7410700e4d0c569d5890.zip
[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
-rw-r--r--llvm/include/llvm/Object/ELFObjectFile.h45
-rw-r--r--llvm/include/llvm/Object/ObjectFile.h5
-rw-r--r--llvm/lib/Object/ELFObjectFile.cpp6
3 files changed, 25 insertions, 31 deletions
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 1d543fb4e53..6884763f661 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -64,6 +64,7 @@ protected:
virtual uint64_t getSectionOffset(DataRefImpl Sec) const = 0;
virtual Expected<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
+ virtual Error getBuildAttributes(ARMAttributeParser &Attributes) const = 0;
public:
using elf_symbol_iterator_range = iterator_range<elf_symbol_iterator>;
@@ -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<ELFT> *getELFFile() const { return &EF; }
bool isDyldType() const { return isDyldELFObject; }
diff --git a/llvm/include/llvm/Object/ObjectFile.h b/llvm/include/llvm/Object/ObjectFile.h
index a3cd907684a..c1c2d833436 100644
--- a/llvm/include/llvm/Object/ObjectFile.h
+++ b/llvm/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/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp
index 07851411fe6..cc1eeefec26 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/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;
OpenPOWER on IntegriCloud