From 7dfea234215e0ca4ff7bbd47c4a6b19d78eb2909 Mon Sep 17 00:00:00 2001 From: Igor Kudrin Date: Wed, 7 Aug 2019 11:44:47 +0000 Subject: [PATCH] Remove support for 32-bit offsets in utility classes (5/5) Differential Revision: https://reviews.llvm.org/D65641 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368156 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../DebugInfo/DWARF/DWARFAcceleratorTable.h | 4 - include/llvm/DebugInfo/DWARF/DWARFFormValue.h | 22 ----- include/llvm/Support/DataExtractor.h | 23 ----- lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp | 10 --- lib/DebugInfo/DWARF/DWARFFormValue.cpp | 37 -------- lib/Support/DataExtractor.cpp | 85 ------------------- tools/llvm-readobj/ELFDumper.cpp | 15 +--- unittests/Support/DataExtractorTest.cpp | 30 +++---- 8 files changed, 14 insertions(+), 212 deletions(-) diff --git a/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h b/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h index 84e08a016fa..c9042e59326 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h +++ b/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h @@ -453,10 +453,6 @@ public: Expected getEntry(uint64_t *Offset) const; - // A temporarily method to preserve compatibility with existing code. - // Will be removed when the migration to 64-bit offsets is finished. - Expected getEntry(uint32_t *Offset) const; - /// Look up all entries in this Name Index matching \c Key. iterator_range equal_range(StringRef Key) const; diff --git a/include/llvm/DebugInfo/DWARF/DWARFFormValue.h b/include/llvm/DebugInfo/DWARF/DWARFFormValue.h index 31ea0c34fac..6fec6fcb6b3 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFFormValue.h +++ b/include/llvm/DebugInfo/DWARF/DWARFFormValue.h @@ -147,28 +147,6 @@ public: uint64_t *OffsetPtr, const dwarf::FormParams FormParams); - // The following methods are temporarily kept in order to preserve - // compatibility with existing code and migrate to 64-bit offsets smoothly. - // They will be removed when the migration is finished. - // Please do not use them in new code. - static DWARFFormValue createFromUnit(dwarf::Form F, const DWARFUnit *Unit, - uint32_t *OffsetPtr); - bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, - dwarf::FormParams FormParams, - const DWARFContext *Context = nullptr, - const DWARFUnit *Unit = nullptr); - bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, - dwarf::FormParams FormParams, const DWARFUnit *U) { - return extractValue(Data, OffsetPtr, FormParams, nullptr, U); - } - bool skipValue(DataExtractor DebugInfoData, uint32_t *OffsetPtr, - const dwarf::FormParams Params) const { - return DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, Params); - } - static bool skipValue(dwarf::Form Form, DataExtractor DebugInfoData, - uint32_t *OffsetPtr, - const dwarf::FormParams FormParams); - private: void dumpString(raw_ostream &OS) const; }; diff --git a/include/llvm/Support/DataExtractor.h b/include/llvm/Support/DataExtractor.h index dfe745ada5b..7c458aaf1ca 100644 --- a/include/llvm/Support/DataExtractor.h +++ b/include/llvm/Support/DataExtractor.h @@ -420,29 +420,6 @@ public: bool isValidOffsetForAddress(uint64_t offset) const { return isValidOffsetForDataOfSize(offset, AddressSize); } - - // The following methods are temporarily kept in order to preserve - // compatibility with existing code and migrate to 64-bit offsets smoothly. - // They will be removed when the migration is finished. - // Please do not use them in new code. - const char *getCStr(uint32_t *offset_ptr) const; - StringRef getCStrRef(uint32_t *offset_ptr) const; - uint64_t getUnsigned(uint32_t *offset_ptr, uint32_t byte_size) const; - int64_t getSigned(uint32_t *offset_ptr, uint32_t size) const; - uint64_t getAddress(uint32_t *offset_ptr) const { - return getUnsigned(offset_ptr, AddressSize); - } - uint8_t getU8(uint32_t *offset_ptr) const; - uint8_t *getU8(uint32_t *offset_ptr, uint8_t *dst, uint32_t count) const; - uint16_t getU16(uint32_t *offset_ptr) const; - uint16_t *getU16(uint32_t *offset_ptr, uint16_t *dst, uint32_t count) const; - uint32_t getU24(uint32_t *offset_ptr) const; - uint32_t getU32(uint32_t *offset_ptr) const; - uint32_t *getU32(uint32_t *offset_ptr, uint32_t *dst, uint32_t count) const; - uint64_t getU64(uint32_t *offset_ptr) const; - uint64_t *getU64(uint32_t *offset_ptr, uint64_t *dst, uint32_t count) const; - int64_t getSLEB128(uint32_t *offset_ptr) const; - uint64_t getULEB128(uint32_t *offset_ptr) const; }; } // namespace llvm diff --git a/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp index b836c795187..875f5e9989a 100644 --- a/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ b/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -622,16 +622,6 @@ DWARFDebugNames::NameIndex::getEntry(uint64_t *Offset) const { return std::move(E); } -// A temporarily method to preserve compatibility with existing code. -// Will be removed when the migration to 64-bit offsets is finished. -Expected -DWARFDebugNames::NameIndex::getEntry(uint32_t *Offset) const { - uint64_t Offset64 = *Offset; - auto Result = getEntry(&Offset64); - *Offset = Offset64; - return Result; -} - DWARFDebugNames::NameTableEntry DWARFDebugNames::NameIndex::getNameTableEntry(uint32_t Index) const { assert(0 < Index && Index <= Hdr.NameCount); diff --git a/lib/DebugInfo/DWARF/DWARFFormValue.cpp b/lib/DebugInfo/DWARF/DWARFFormValue.cpp index 5abae7f3725..26090638b34 100644 --- a/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ b/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -718,40 +718,3 @@ Optional DWARFFormValue::getAsReferenceUVal() const { return None; return Value.uval; } - -// The following is temporary code aimed to preserve compatibility with -// existing code which uses 32-bit offsets. -// It will be removed when migration to 64-bit offsets is finished. - -namespace { - -class WrapOffset { - uint64_t Offset64; - uint32_t *Offset32; - -public: - WrapOffset(uint32_t *Offset) - : Offset64(*Offset), Offset32(Offset) {} - ~WrapOffset() { *Offset32 = Offset64; } - operator uint64_t *() { return &Offset64; } -}; - -} - -DWARFFormValue DWARFFormValue::createFromUnit(dwarf::Form F, const DWARFUnit *U, - uint32_t *OffsetPtr) { - return createFromUnit(F, U, WrapOffset(OffsetPtr)); -} - -bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData, - uint32_t *OffsetPtr, - const dwarf::FormParams Params) { - return skipValue(Form, DebugInfoData, WrapOffset(OffsetPtr), Params); -} - -bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data, - uint32_t *OffsetPtr, dwarf::FormParams FP, - const DWARFContext *Ctx, - const DWARFUnit *CU) { - return extractValue(Data, WrapOffset(OffsetPtr), FP, Ctx, CU); -} diff --git a/lib/Support/DataExtractor.cpp b/lib/Support/DataExtractor.cpp index 73c215ea05a..1d88ec06151 100644 --- a/lib/Support/DataExtractor.cpp +++ b/lib/Support/DataExtractor.cpp @@ -171,88 +171,3 @@ int64_t DataExtractor::getSLEB128(uint64_t *offset_ptr) const { *offset_ptr += bytes_read; return result; } - -// The following is temporary code aimed to preserve compatibility with -// existing code which uses 32-bit offsets. -// It will be removed when migration to 64-bit offsets is finished. - -namespace { - -class WrapOffset { - uint64_t offset64; - uint32_t *offset32_ptr; - -public: - WrapOffset(uint32_t *offset_ptr) - : offset64(*offset_ptr), offset32_ptr(offset_ptr) {} - ~WrapOffset() { *offset32_ptr = offset64; } - operator uint64_t *() { return &offset64; } -}; - -} - -uint8_t DataExtractor::getU8(uint32_t *offset_ptr) const { - return getU8(WrapOffset(offset_ptr)); -} - -uint8_t * -DataExtractor::getU8(uint32_t *offset_ptr, uint8_t *dst, uint32_t count) const { - return getU8(WrapOffset(offset_ptr), dst, count); -} - -uint16_t DataExtractor::getU16(uint32_t *offset_ptr) const { - return getU16(WrapOffset(offset_ptr)); -} - -uint16_t *DataExtractor::getU16(uint32_t *offset_ptr, uint16_t *dst, - uint32_t count) const { - return getU16(WrapOffset(offset_ptr), dst, count); -} - -uint32_t DataExtractor::getU24(uint32_t *offset_ptr) const { - return getU24(WrapOffset(offset_ptr)); -} - -uint32_t DataExtractor::getU32(uint32_t *offset_ptr) const { - return getU32(WrapOffset(offset_ptr)); -} - -uint32_t *DataExtractor::getU32(uint32_t *offset_ptr, uint32_t *dst, - uint32_t count) const { - return getU32(WrapOffset(offset_ptr), dst, count); -} - -uint64_t DataExtractor::getU64(uint32_t *offset_ptr) const { - return getU64(WrapOffset(offset_ptr)); -} - -uint64_t *DataExtractor::getU64(uint32_t *offset_ptr, uint64_t *dst, - uint32_t count) const { - return getU64(WrapOffset(offset_ptr), dst, count); -} - -uint64_t -DataExtractor::getUnsigned(uint32_t *offset_ptr, uint32_t byte_size) const { - return getUnsigned(WrapOffset(offset_ptr), byte_size); -} - -int64_t -DataExtractor::getSigned(uint32_t *offset_ptr, uint32_t byte_size) const { - return getSigned(WrapOffset(offset_ptr), byte_size); -} - -const char *DataExtractor::getCStr(uint32_t *offset_ptr) const { - return getCStr(WrapOffset(offset_ptr)); -} - -StringRef DataExtractor::getCStrRef(uint32_t *offset_ptr) const { - return getCStrRef(WrapOffset(offset_ptr)); -} - -uint64_t DataExtractor::getULEB128(uint32_t *offset_ptr) const { - return getULEB128(WrapOffset(offset_ptr)); -} - -int64_t DataExtractor::getSLEB128(uint32_t *offset_ptr) const { - return getSLEB128(WrapOffset(offset_ptr)); -} diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 3a68245d264..0f33ecd58cd 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -4383,15 +4383,6 @@ void GNUStyle::printELFLinkerOptions(const ELFFile *Obj) { OS << "printELFLinkerOptions not implemented!\n"; } -// FIXME: As soon as the DataExtractor interface handles uint64_t *, this -// should be eliminated. See upstream review https://reviews.llvm.org/D64006. -inline uint32_t *AdjustPtr(uint64_t *Offset) { - uint32_t *Ptr = reinterpret_cast(Offset); - if (sys::IsBigEndianHost) - Ptr++; - return Ptr; -} - template void DumpStyle::printFunctionStackSize( const ELFObjectFile *Obj, uint64_t SymValue, SectionRef FunctionSec, @@ -4431,7 +4422,7 @@ void DumpStyle::printFunctionStackSize( // Extract the size. The expectation is that Offset is pointing to the right // place, i.e. past the function address. uint64_t PrevOffset = *Offset; - uint64_t StackSize = Data.getULEB128(AdjustPtr(Offset)); + uint64_t StackSize = Data.getULEB128(Offset); // getULEB128() does not advance Offset if it is not able to extract a valid // integer. if (*Offset == PrevOffset) @@ -4504,7 +4495,7 @@ void DumpStyle::printStackSize(const ELFObjectFile *Obj, "while trying to extract a stack size entry", StackSizeSectionName.data())); - uint64_t Addend = Data.getAddress(AdjustPtr(&Offset)); + uint64_t Addend = Data.getAddress(&Offset); uint64_t SymValue = Resolver(Reloc, RelocSymValue, Addend); this->printFunctionStackSize(Obj, SymValue, FunctionSec, StackSizeSectionName, Data, &Offset); @@ -4553,7 +4544,7 @@ void DumpStyle::printNonRelocatableStackSizes( "section %s ended while trying to extract a stack size entry", SectionName.data())); } - uint64_t SymValue = Data.getAddress(AdjustPtr(&Offset)); + uint64_t SymValue = Data.getAddress(&Offset); printFunctionStackSize(Obj, SymValue, toSectionRef(Obj, FunctionELFSec), SectionName, Data, &Offset); diff --git a/unittests/Support/DataExtractorTest.cpp b/unittests/Support/DataExtractorTest.cpp index 4d63439621d..d1c23cd15e5 100644 --- a/unittests/Support/DataExtractorTest.cpp +++ b/unittests/Support/DataExtractorTest.cpp @@ -12,27 +12,19 @@ using namespace llvm; namespace { -// Test fixture -template -class DataExtractorTest : public ::testing::Test { }; - -// Test DataExtractor with both types which can be used for offsets. -typedef ::testing::Types TestTypes; -TYPED_TEST_CASE(DataExtractorTest, TestTypes); - const char numberData[] = "\x80\x90\xFF\xFF\x80\x00\x00\x00"; const char stringData[] = "hellohello\0hello"; const char leb128data[] = "\xA6\x49"; const char bigleb128data[] = "\xAA\xA9\xFF\xAA\xFF\xAA\xFF\x4A"; -TYPED_TEST(DataExtractorTest, OffsetOverflow) { +TEST(DataExtractorTest, OffsetOverflow) { DataExtractor DE(StringRef(numberData, sizeof(numberData)-1), false, 8); EXPECT_FALSE(DE.isValidOffsetForDataOfSize(-2U, 5)); } -TYPED_TEST(DataExtractorTest, UnsignedNumbers) { +TEST(DataExtractorTest, UnsignedNumbers) { DataExtractor DE(StringRef(numberData, sizeof(numberData)-1), false, 8); - TypeParam offset = 0; + uint64_t offset = 0; EXPECT_EQ(0x80U, DE.getU8(&offset)); EXPECT_EQ(1U, offset); @@ -78,9 +70,9 @@ TYPED_TEST(DataExtractorTest, UnsignedNumbers) { EXPECT_EQ(8U, offset); } -TYPED_TEST(DataExtractorTest, SignedNumbers) { +TEST(DataExtractorTest, SignedNumbers) { DataExtractor DE(StringRef(numberData, sizeof(numberData)-1), false, 8); - TypeParam offset = 0; + uint64_t offset = 0; EXPECT_EQ(-128, DE.getSigned(&offset, 1)); EXPECT_EQ(1U, offset); @@ -95,9 +87,9 @@ TYPED_TEST(DataExtractorTest, SignedNumbers) { EXPECT_EQ(8U, offset); } -TYPED_TEST(DataExtractorTest, Strings) { +TEST(DataExtractorTest, Strings) { DataExtractor DE(StringRef(stringData, sizeof(stringData)-1), false, 8); - TypeParam offset = 0; + uint64_t offset = 0; EXPECT_EQ(stringData, DE.getCStr(&offset)); EXPECT_EQ(11U, offset); @@ -105,9 +97,9 @@ TYPED_TEST(DataExtractorTest, Strings) { EXPECT_EQ(11U, offset); } -TYPED_TEST(DataExtractorTest, LEB128) { +TEST(DataExtractorTest, LEB128) { DataExtractor DE(StringRef(leb128data, sizeof(leb128data)-1), false, 8); - TypeParam offset = 0; + uint64_t offset = 0; EXPECT_EQ(9382ULL, DE.getULEB128(&offset)); EXPECT_EQ(2U, offset); @@ -124,9 +116,9 @@ TYPED_TEST(DataExtractorTest, LEB128) { EXPECT_EQ(8U, offset); } -TYPED_TEST(DataExtractorTest, LEB128_error) { +TEST(DataExtractorTest, LEB128_error) { DataExtractor DE(StringRef("\x81"), false, 8); - TypeParam Offset = 0; + uint64_t Offset = 0; EXPECT_EQ(0U, DE.getULEB128(&Offset)); EXPECT_EQ(0U, Offset); -- 2.40.0