diff options
| author | Fangrui Song <maskray@google.com> | 2020-02-21 10:55:12 -0800 |
|---|---|---|
| committer | Fangrui Song <maskray@google.com> | 2020-02-21 11:05:33 -0800 |
| commit | 73d8d83a6d9adac3216ea8a39eb502b2a5c4d083 (patch) | |
| tree | 6e904a00d1592c3925aeabb5169cf62affcd2832 | |
| parent | 00955a62e4333c7ca889043d6a9033cb8cbf800d (diff) | |
[ARM] Change ARMAttributeParser::Parse to use support::endianness and simplify
| -rw-r--r-- | lld/ELF/InputFiles.cpp | 3 | ||||
| -rw-r--r-- | llvm/include/llvm/Object/ELFObjectFile.h | 2 | ||||
| -rw-r--r-- | llvm/include/llvm/Support/ARMAttributeParser.h | 3 | ||||
| -rw-r--r-- | llvm/lib/Support/ARMAttributeParser.cpp | 8 | ||||
| -rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 2 | ||||
| -rw-r--r-- | llvm/unittests/Support/ARMAttributeParser.cpp | 2 |
6 files changed, 11 insertions, 9 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index b3f8984240d2..c37436e43738 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -842,7 +842,8 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) { break; ARMAttributeParser attributes; ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(&sec)); - attributes.Parse(contents, /*isLittle*/ config->ekind == ELF32LEKind); + attributes.parse(contents, config->ekind == ELF32LEKind ? support::little + : support::big); updateSupportedARMFeatures(attributes); updateARMVFPArgs(attributes, this); diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h index 8a68e49477fd..7effce6ab6c7 100644 --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/llvm/include/llvm/Object/ELFObjectFile.h @@ -380,7 +380,7 @@ protected: if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1) return Error::success(); - Attributes.Parse(Contents, ELFT::TargetEndianness == support::little); + Attributes.parse(Contents, ELFT::TargetEndianness); break; } } diff --git a/llvm/include/llvm/Support/ARMAttributeParser.h b/llvm/include/llvm/Support/ARMAttributeParser.h index f6c39abb4f21..df7417f7a383 100644 --- a/llvm/include/llvm/Support/ARMAttributeParser.h +++ b/llvm/include/llvm/Support/ARMAttributeParser.h @@ -11,6 +11,7 @@ #include "ARMBuildAttributes.h" #include "ScopedPrinter.h" +#include "llvm/Support/Endian.h" #include <map> @@ -124,7 +125,7 @@ public: ARMAttributeParser() : SW(nullptr) { } - void Parse(ArrayRef<uint8_t> Section, bool isLittle); + void parse(ArrayRef<uint8_t> Section, support::endianness E); bool hasAttribute(unsigned Tag) const { return Attributes.count(Tag); diff --git a/llvm/lib/Support/ARMAttributeParser.cpp b/llvm/lib/Support/ARMAttributeParser.cpp index 8a89f4c45fb9..812b160c2e33 100644 --- a/llvm/lib/Support/ARMAttributeParser.cpp +++ b/llvm/lib/Support/ARMAttributeParser.cpp @@ -695,14 +695,14 @@ void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) { } } -void ARMAttributeParser::Parse(ArrayRef<uint8_t> Section, bool isLittle) { +void ARMAttributeParser::parse(ArrayRef<uint8_t> Section, + support::endianness E) { uint64_t Offset = 1; unsigned SectionNumber = 0; while (Offset < Section.size()) { - uint32_t SectionLength = isLittle ? - support::endian::read32le(Section.data() + Offset) : - support::endian::read32be(Section.data() + Offset); + uint32_t SectionLength = + support::endian::read32(Section.data() + Offset, E); if (SW) { SW->startLine() << "Section " << ++SectionNumber << " {\n"; diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 794c4630699a..93ec47751b6b 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -2688,7 +2688,7 @@ template <> void ELFDumper<ELF32LE>::printAttributes() { if (Contents.size() == 1) continue; - ARMAttributeParser(&W).Parse(Contents, true); + ARMAttributeParser(&W).parse(Contents, support::little); } } diff --git a/llvm/unittests/Support/ARMAttributeParser.cpp b/llvm/unittests/Support/ARMAttributeParser.cpp index 6781acc59a72..adb36de8e66b 100644 --- a/llvm/unittests/Support/ARMAttributeParser.cpp +++ b/llvm/unittests/Support/ARMAttributeParser.cpp @@ -34,7 +34,7 @@ bool testBuildAttr(unsigned Tag, unsigned Value, reinterpret_cast<const uint8_t*>(OS.str().c_str()), OS.str().size()); ARMAttributeParser Parser; - Parser.Parse(Bytes, true); + Parser.parse(Bytes, support::little); return (Parser.hasAttribute(ExpectedTag) && Parser.getAttributeValue(ExpectedTag) == ExpectedValue); |
