1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[DWARF] Do not pass Version to DWARFExpression. NFCI.

The Version was used only to determine the size of an operand of
DW_OP_call_ref. The size was 4 for all versions apart from 2, but
the DW_OP_call_ref operation was introduced only in DWARF3. Thus,
the code may be simplified and using of Version may be eliminated.

Differential Revision: https://reviews.llvm.org/D73264
This commit is contained in:
Igor Kudrin 2020-01-23 09:24:00 +07:00
parent b22a094351
commit 70ab7c2444
10 changed files with 62 additions and 41 deletions

View File

@ -87,8 +87,7 @@ public:
uint64_t getRawOperand(unsigned Idx) { return Operands[Idx]; } uint64_t getRawOperand(unsigned Idx) { return Operands[Idx]; }
uint64_t getOperandEndOffset(unsigned Idx) { return OperandEndOffsets[Idx]; } uint64_t getOperandEndOffset(unsigned Idx) { return OperandEndOffsets[Idx]; }
uint64_t getEndOffset() { return EndOffset; } uint64_t getEndOffset() { return EndOffset; }
bool extract(DataExtractor Data, uint16_t Version, uint8_t AddressSize, bool extract(DataExtractor Data, uint8_t AddressSize, uint64_t Offset);
uint64_t Offset);
bool isError() { return Error; } bool isError() { return Error; }
bool print(raw_ostream &OS, const DWARFExpression *Expr, bool print(raw_ostream &OS, const DWARFExpression *Expr,
const MCRegisterInfo *RegInfo, DWARFUnit *U, bool isEH); const MCRegisterInfo *RegInfo, DWARFUnit *U, bool isEH);
@ -107,7 +106,7 @@ public:
: Expr(Expr), Offset(Offset) { : Expr(Expr), Offset(Offset) {
Op.Error = Op.Error =
Offset >= Expr->Data.getData().size() || Offset >= Expr->Data.getData().size() ||
!Op.extract(Expr->Data, Expr->Version, Expr->AddressSize, Offset); !Op.extract(Expr->Data, Expr->AddressSize, Offset);
} }
public: public:
@ -115,7 +114,7 @@ public:
Offset = Op.isError() ? Expr->Data.getData().size() : Op.EndOffset; Offset = Op.isError() ? Expr->Data.getData().size() : Op.EndOffset;
Op.Error = Op.Error =
Offset >= Expr->Data.getData().size() || Offset >= Expr->Data.getData().size() ||
!Op.extract(Expr->Data, Expr->Version, Expr->AddressSize, Offset); !Op.extract(Expr->Data, Expr->AddressSize, Offset);
return Op; return Op;
} }
@ -127,8 +126,8 @@ public:
friend bool operator==(const iterator &, const iterator &); friend bool operator==(const iterator &, const iterator &);
}; };
DWARFExpression(DataExtractor Data, uint16_t Version, uint8_t AddressSize) DWARFExpression(DataExtractor Data, uint8_t AddressSize)
: Data(Data), Version(Version), AddressSize(AddressSize) { : Data(Data), AddressSize(AddressSize) {
assert(AddressSize == 8 || AddressSize == 4 || AddressSize == 2); assert(AddressSize == 8 || AddressSize == 4 || AddressSize == 2);
} }
@ -142,7 +141,6 @@ public:
private: private:
DataExtractor Data; DataExtractor Data;
uint16_t Version;
uint8_t AddressSize; uint8_t AddressSize;
}; };

View File

@ -2210,7 +2210,7 @@ void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer,
DWARFDataExtractor Data(StringRef(DebugLocs.getBytes(Entry).data(), DWARFDataExtractor Data(StringRef(DebugLocs.getBytes(Entry).data(),
DebugLocs.getBytes(Entry).size()), DebugLocs.getBytes(Entry).size()),
Asm->getDataLayout().isLittleEndian(), PtrSize); Asm->getDataLayout().isLittleEndian(), PtrSize);
DWARFExpression Expr(Data, getDwarfVersion(), PtrSize); DWARFExpression Expr(Data, PtrSize);
using Encoding = DWARFExpression::Operation::Encoding; using Encoding = DWARFExpression::Operation::Encoding;
uint64_t Offset = 0; uint64_t Offset = 0;

View File

@ -953,8 +953,7 @@ unsigned DWARFLinker::DIECloner::cloneBlockAttribute(
DWARFUnit &OrigUnit = Unit.getOrigUnit(); DWARFUnit &OrigUnit = Unit.getOrigUnit();
DataExtractor Data(StringRef((const char *)Bytes.data(), Bytes.size()), DataExtractor Data(StringRef((const char *)Bytes.data(), Bytes.size()),
IsLittleEndian, OrigUnit.getAddressByteSize()); IsLittleEndian, OrigUnit.getAddressByteSize());
DWARFExpression Expr(Data, OrigUnit.getVersion(), DWARFExpression Expr(Data, OrigUnit.getAddressByteSize());
OrigUnit.getAddressByteSize());
cloneExpression(Data, Expr, OF, Unit, Buffer); cloneExpression(Data, Expr, OF, Unit, Buffer);
Bytes = Buffer; Bytes = Buffer;
} }
@ -2059,8 +2058,7 @@ void DWARFLinker::DIECloner::cloneAllCompileUnits(DWARFContext &DwarfContext,
DataExtractor Data(Bytes, IsLittleEndian, DataExtractor Data(Bytes, IsLittleEndian,
OrigUnit.getAddressByteSize()); OrigUnit.getAddressByteSize());
cloneExpression(Data, cloneExpression(Data,
DWARFExpression(Data, OrigUnit.getVersion(), DWARFExpression(Data, OrigUnit.getAddressByteSize()),
OrigUnit.getAddressByteSize()),
OF, *CurrentUnit, Buffer); OF, *CurrentUnit, Buffer);
}; };
Emitter->emitLocationsForUnit(*CurrentUnit, DwarfContext, ProcessExpr); Emitter->emitLocationsForUnit(*CurrentUnit, DwarfContext, ProcessExpr);

View File

@ -130,8 +130,8 @@ Error CFIProgram::parse(DWARFDataExtractor Data, uint64_t *Offset,
DataExtractor Extractor( DataExtractor Extractor(
Data.getData().slice(*Offset, *Offset + ExprLength), Data.getData().slice(*Offset, *Offset + ExprLength),
Data.isLittleEndian(), Data.getAddressSize()); Data.isLittleEndian(), Data.getAddressSize());
Instructions.back().Expression = DWARFExpression( Instructions.back().Expression =
Extractor, Data.getAddressSize(), dwarf::DWARF_VERSION); DWARFExpression(Extractor, Data.getAddressSize());
*Offset += ExprLength; *Offset += ExprLength;
break; break;
} }
@ -143,8 +143,8 @@ Error CFIProgram::parse(DWARFDataExtractor Data, uint64_t *Offset,
DataExtractor Extractor( DataExtractor Extractor(
Data.getData().slice(*Offset, *Offset + BlockLength), Data.getData().slice(*Offset, *Offset + BlockLength),
Data.isLittleEndian(), Data.getAddressSize()); Data.isLittleEndian(), Data.getAddressSize());
Instructions.back().Expression = DWARFExpression( Instructions.back().Expression =
Extractor, Data.getAddressSize(), dwarf::DWARF_VERSION); DWARFExpression(Extractor, Data.getAddressSize());
*Offset += BlockLength; *Offset += BlockLength;
break; break;
} }

View File

@ -106,16 +106,11 @@ DWARFLocationInterpreter::Interpret(const DWARFLocationEntry &E) {
} }
} }
// When directly dumping the .debug_loc without a compile unit, we have to guess
// at the DWARF version. This only affects DW_OP_call_ref, which is a rare
// expression that LLVM doesn't produce. Guessing the wrong version means we
// won't be able to pretty print expressions in DWARF2 binaries produced by
// non-LLVM tools.
static void dumpExpression(raw_ostream &OS, ArrayRef<uint8_t> Data, static void dumpExpression(raw_ostream &OS, ArrayRef<uint8_t> Data,
bool IsLittleEndian, unsigned AddressSize, bool IsLittleEndian, unsigned AddressSize,
const MCRegisterInfo *MRI, DWARFUnit *U) { const MCRegisterInfo *MRI, DWARFUnit *U) {
DWARFDataExtractor Extractor(toStringRef(Data), IsLittleEndian, AddressSize); DWARFDataExtractor Extractor(toStringRef(Data), IsLittleEndian, AddressSize);
DWARFExpression(Extractor, dwarf::DWARF_VERSION, AddressSize).print(OS, MRI, U); DWARFExpression(Extractor, AddressSize).print(OS, MRI, U);
} }
bool DWARFLocationTable::dumpLocationList(uint64_t *Offset, raw_ostream &OS, bool DWARFLocationTable::dumpLocationList(uint64_t *Offset, raw_ostream &OS,

View File

@ -79,8 +79,7 @@ static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
ArrayRef<uint8_t> Expr = *FormValue.getAsBlock(); ArrayRef<uint8_t> Expr = *FormValue.getAsBlock();
DataExtractor Data(StringRef((const char *)Expr.data(), Expr.size()), DataExtractor Data(StringRef((const char *)Expr.data(), Expr.size()),
Ctx.isLittleEndian(), 0); Ctx.isLittleEndian(), 0);
DWARFExpression(Data, U->getVersion(), U->getAddressByteSize()) DWARFExpression(Data, U->getAddressByteSize()).print(OS, MRI, U);
.print(OS, MRI, U);
return; return;
} }

View File

@ -116,11 +116,7 @@ static DWARFExpression::Operation::Description getOpDesc(unsigned OpCode) {
return Descriptions[OpCode]; return Descriptions[OpCode];
} }
static uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) { bool DWARFExpression::Operation::extract(DataExtractor Data,
return (Version == 2) ? AddrSize : 4;
}
bool DWARFExpression::Operation::extract(DataExtractor Data, uint16_t Version,
uint8_t AddressSize, uint64_t Offset) { uint8_t AddressSize, uint64_t Offset) {
Opcode = Data.getU8(&Offset); Opcode = Data.getU8(&Offset);
@ -160,14 +156,8 @@ bool DWARFExpression::Operation::extract(DataExtractor Data, uint16_t Version,
Operands[Operand] = Data.getUnsigned(&Offset, AddressSize); Operands[Operand] = Data.getUnsigned(&Offset, AddressSize);
break; break;
case Operation::SizeRefAddr: case Operation::SizeRefAddr:
if (getRefAddrSize(AddressSize, Version) == 8) { // TODO: Add support for 64-bit DWARF format.
Operands[Operand] = Data.getU64(&Offset); Operands[Operand] = Data.getU32(&Offset);
} else if (getRefAddrSize(AddressSize, Version) == 4) {
Operands[Operand] = Data.getU32(&Offset);
} else {
assert(getRefAddrSize(AddressSize, Version) == 2);
Operands[Operand] = Data.getU16(&Offset);
}
break; break;
case Operation::SizeLEB: case Operation::SizeLEB:
if (Signed) if (Signed)

View File

@ -481,8 +481,7 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
DWARFUnit *U = Die.getDwarfUnit(); DWARFUnit *U = Die.getDwarfUnit();
for (const auto &Entry : *Loc) { for (const auto &Entry : *Loc) {
DataExtractor Data(toStringRef(Entry.Expr), DCtx.isLittleEndian(), 0); DataExtractor Data(toStringRef(Entry.Expr), DCtx.isLittleEndian(), 0);
DWARFExpression Expression(Data, U->getVersion(), DWARFExpression Expression(Data, U->getAddressByteSize());
U->getAddressByteSize());
bool Error = any_of(Expression, [](DWARFExpression::Operation &Op) { bool Error = any_of(Expression, [](DWARFExpression::Operation &Op) {
return Op.isError(); return Op.isError();
}); });
@ -1290,7 +1289,7 @@ static bool isVariableIndexable(const DWARFDie &Die, DWARFContext &DCtx) {
for (const auto &Entry : *Loc) { for (const auto &Entry : *Loc) {
DataExtractor Data(toStringRef(Entry.Expr), DCtx.isLittleEndian(), DataExtractor Data(toStringRef(Entry.Expr), DCtx.isLittleEndian(),
U->getAddressByteSize()); U->getAddressByteSize());
DWARFExpression Expression(Data, U->getVersion(), U->getAddressByteSize()); DWARFExpression Expression(Data, U->getAddressByteSize());
bool IsInteresting = any_of(Expression, [](DWARFExpression::Operation &Op) { bool IsInteresting = any_of(Expression, [](DWARFExpression::Operation &Op) {
return !Op.isError() && (Op.getCode() == DW_OP_addr || return !Op.isError() && (Op.getCode() == DW_OP_addr ||
Op.getCode() == DW_OP_form_tls_address || Op.getCode() == DW_OP_form_tls_address ||

View File

@ -0,0 +1,42 @@
# RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj | \
# RUN: llvm-dwarfdump - | \
# RUN: FileCheck %s
# This checks that the operand of DW_OP_call_ref is always parsed corresponding
# to the DWARF format of CU. Our code used to have an exception for verson == 2,
# where it treated the operand like it had the size of address, but since
# DW_OP_call_ref was introduced only in DWARF3, the code could be simplified.
# CHECK: DW_TAG_variable
# CHECK-NEXT: DW_AT_location (DW_OP_call_ref 0x11223344)
.section .debug_abbrev,"",@progbits
.byte 1 # Abbreviation Code
.byte 17 # DW_TAG_compile_unit
.byte 1 # DW_CHILDREN_yes
.byte 0 # EOM(1)
.byte 0 # EOM(2)
.byte 5 # Abbreviation Code
.byte 52 # DW_TAG_variable
.byte 0 # DW_CHILDREN_no
.byte 2 # DW_AT_location
.byte 10 # DW_FORM_block1
.byte 0 # EOM(1)
.byte 0 # EOM(2)
.byte 0 # EOM(3)
.section .debug_info,"",@progbits
.long .Lcu_end-.Lcu_start # Length of Unit
.Lcu_start:
.short 2 # DWARF version number
.long .debug_abbrev # Offset Into Abbrev. Section
.byte 8 # Address Size (in bytes)
.byte 1 # Abbrev [1] DW_TAG_compile_unit
.byte 5 # Abbrev [5] DW_TAG_variable
.byte .Lloc_end-.Lloc_begin # DW_AT_location
.Lloc_begin:
.byte 154 # DW_OP_call_ref
.long 0x11223344 # Offset
.Lloc_end:
.byte 0 # End Of Children Mark
.Lcu_end:

View File

@ -206,7 +206,7 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
DWARFUnit *U = Die.getDwarfUnit(); DWARFUnit *U = Die.getDwarfUnit();
DataExtractor Data(toStringRef(D), DataExtractor Data(toStringRef(D),
Die.getDwarfUnit()->getContext().isLittleEndian(), 0); Die.getDwarfUnit()->getContext().isLittleEndian(), 0);
DWARFExpression Expression(Data, U->getVersion(), U->getAddressByteSize()); DWARFExpression Expression(Data, U->getAddressByteSize());
// Consider the expression containing the DW_OP_entry_value as // Consider the expression containing the DW_OP_entry_value as
// an entry value. // an entry value.
return llvm::any_of(Expression, [](DWARFExpression::Operation &Op) { return llvm::any_of(Expression, [](DWARFExpression::Operation &Op) {