Commit b413f0eb authored by ssanfilippo's avatar ssanfilippo Committed by Commit bot

Reland Implement .eh_frame writer and disassembler.

Original commit message:

  Also, CodeGenerator::MakeCodeEpilogue now accepts an optional pointer
  to a EhFrameWriter and will attach unwinding information to the code
  object when passed one.

Reason for reverting:

  The STATIC_CONST_MEMBER_DEFINITION in eh-frame-writer-unittest.cc
  causes a compiler error on V8 Win64 - clang buildbot.

  Removing that bit.

BUG=v8:4899
LOG=N

Review-Url: https://codereview.chromium.org/2023503002
Cr-Commit-Position: refs/heads/master@{#37707}
parent 35e501bf
......@@ -1635,6 +1635,7 @@ v8_source_set("v8_base") {
"src/x64/cpu-x64.cc",
"src/x64/deoptimizer-x64.cc",
"src/x64/disasm-x64.cc",
"src/x64/eh-frame-x64.cc",
"src/x64/frames-x64.cc",
"src/x64/frames-x64.h",
"src/x64/interface-descriptors-x64.cc",
......@@ -1656,6 +1657,7 @@ v8_source_set("v8_base") {
"src/arm/cpu-arm.cc",
"src/arm/deoptimizer-arm.cc",
"src/arm/disasm-arm.cc",
"src/arm/eh-frame-arm.cc",
"src/arm/frames-arm.cc",
"src/arm/frames-arm.h",
"src/arm/interface-descriptors-arm.cc",
......@@ -1702,6 +1704,7 @@ v8_source_set("v8_base") {
"src/arm64/deoptimizer-arm64.cc",
"src/arm64/disasm-arm64.cc",
"src/arm64/disasm-arm64.h",
"src/arm64/eh-frame-arm64.cc",
"src/arm64/frames-arm64.cc",
"src/arm64/frames-arm64.h",
"src/arm64/instructions-arm64.cc",
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/eh-frame.h"
namespace v8 {
namespace internal {
static const int kR0DwarfCode = 0;
static const int kFpDwarfCode = 11;
static const int kSpDwarfCode = 13;
static const int kLrDwarfCode = 14;
STATIC_CONST_MEMBER_DEFINITION const int
EhFrameConstants::kCodeAlignmentFactor = 4;
STATIC_CONST_MEMBER_DEFINITION const int
EhFrameConstants::kDataAlignmentFactor = -4;
void EhFrameWriter::WriteReturnAddressRegisterCode() {
WriteULeb128(kLrDwarfCode);
}
void EhFrameWriter::WriteInitialStateInCie() {
SetBaseAddressRegisterAndOffset(fp, 0);
RecordRegisterNotModified(lr);
}
// static
int EhFrameWriter::RegisterToDwarfCode(Register name) {
switch (name.code()) {
case Register::kCode_fp:
return kFpDwarfCode;
case Register::kCode_sp:
return kSpDwarfCode;
case Register::kCode_lr:
return kLrDwarfCode;
case Register::kCode_r0:
return kR0DwarfCode;
default:
UNIMPLEMENTED();
return -1;
}
}
#ifdef ENABLE_DISASSEMBLER
// static
const char* EhFrameDisassembler::DwarfRegisterCodeToString(int code) {
switch (code) {
case kFpDwarfCode:
return "fp";
case kSpDwarfCode:
return "sp";
case kLrDwarfCode:
return "lr";
default:
UNIMPLEMENTED();
return nullptr;
}
}
#endif
} // namespace internal
} // namespace v8
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/eh-frame.h"
namespace v8 {
namespace internal {
static const int kX0DwarfCode = 0;
static const int kJsSpDwarfCode = 28;
static const int kFpDwarfCode = 29;
static const int kLrDwarfCode = 30;
static const int kCSpDwarfCode = 31;
STATIC_CONST_MEMBER_DEFINITION const int
EhFrameConstants::kCodeAlignmentFactor = 4;
STATIC_CONST_MEMBER_DEFINITION const int
EhFrameConstants::kDataAlignmentFactor = -8;
void EhFrameWriter::WriteReturnAddressRegisterCode() {
WriteULeb128(kLrDwarfCode);
}
void EhFrameWriter::WriteInitialStateInCie() {
SetBaseAddressRegisterAndOffset(x29, 0);
RecordRegisterNotModified(x30);
}
// static
int EhFrameWriter::RegisterToDwarfCode(Register name) {
switch (name.code()) {
case Register::kCode_x28:
return kJsSpDwarfCode;
case Register::kCode_x29:
return kFpDwarfCode;
case Register::kCode_x30:
return kLrDwarfCode;
case Register::kCode_x31:
return kCSpDwarfCode;
case Register::kCode_x0:
return kX0DwarfCode;
default:
UNIMPLEMENTED();
return -1;
}
}
#ifdef ENABLE_DISASSEMBLER
// static
const char* EhFrameDisassembler::DwarfRegisterCodeToString(int code) {
switch (code) {
case kFpDwarfCode:
return "fp";
case kLrDwarfCode:
return "lr";
case kJsSpDwarfCode:
return "jssp";
case kCSpDwarfCode:
return "csp"; // This could be zr as well
default:
UNIMPLEMENTED();
return nullptr;
}
}
#endif
} // namespace internal
} // namespace v8
......@@ -11,6 +11,7 @@
#include "src/bootstrapper.h"
#include "src/compiler.h"
#include "src/debug/debug.h"
#include "src/eh-frame.h"
#include "src/parsing/parser.h"
#include "src/runtime/runtime.h"
......@@ -117,8 +118,8 @@ void CodeGenerator::MakeCodePrologue(CompilationInfo* info, const char* kind) {
#endif // DEBUG
}
Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm,
EhFrameWriter* eh_frame_writer,
CompilationInfo* info) {
Isolate* isolate = info->isolate();
......@@ -129,6 +130,7 @@ Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm,
Code::ExtractKindFromFlags(flags) == Code::OPTIMIZED_FUNCTION ||
info->IsStub();
masm->GetCode(&desc);
if (eh_frame_writer) eh_frame_writer->GetEhFrame(&desc);
Handle<Code> code =
isolate->factory()->NewCode(desc, flags, masm->CodeObject(),
false, is_crankshafted,
......
......@@ -69,7 +69,7 @@ namespace internal {
class CompilationInfo;
class EhFrameWriter;
class CodeGenerator {
public:
......@@ -78,6 +78,7 @@ class CodeGenerator {
// Allocate and install the code.
static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
EhFrameWriter* unwinding,
CompilationInfo* info);
// Print the code after compiling it.
......
......@@ -204,7 +204,7 @@ Handle<Code> CodeGenerator::GenerateCode() {
safepoints()->Emit(masm(), frame()->GetTotalFrameSlotCount());
Handle<Code> result =
v8::internal::CodeGenerator::MakeCodeEpilogue(masm(), info);
v8::internal::CodeGenerator::MakeCodeEpilogue(masm(), nullptr, info);
result->set_is_turbofanned(true);
result->set_stack_slots(frame()->GetTotalFrameSlotCount());
result->set_safepoint_table_offset(safepoints()->GetCodeOffset());
......
......@@ -457,7 +457,8 @@ Handle<Code> LChunk::Codegen() {
if (generator.GenerateCode()) {
generator.CheckEnvironmentUsage();
CodeGenerator::MakeCodePrologue(info(), "optimized");
Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&assembler, info());
Handle<Code> code =
CodeGenerator::MakeCodeEpilogue(&assembler, nullptr, info());
generator.FinishCode(code);
CommitDependencies(code);
generator.source_position_table_builder()->EndJitLogging(
......
This diff is collapsed.
......@@ -5,36 +5,292 @@
#ifndef V8_EH_FRAME_H_
#define V8_EH_FRAME_H_
#include <cstdint>
#include "src/macro-assembler.h"
namespace v8 {
namespace internal {
class Code;
class EhFrameConstants final {
public:
enum class DwarfOpcodes : byte {
kNop = 0x00,
kAdvanceLoc1 = 0x02,
kAdvanceLoc2 = 0x03,
kAdvanceLoc4 = 0x04,
kSameValue = 0x08,
kDefCfa = 0x0c,
kDefCfaRegister = 0x0d,
kDefCfaOffset = 0x0e,
kOffsetExtendedSf = 0x11,
};
enum DwarfEncodingSpecifiers : byte {
kUData4 = 0x03,
kSData4 = 0x0b,
kPcRel = 0x10,
kDataRel = 0x30,
kOmit = 0xff,
};
static const int kLocationTag = 1;
static const int kLocationMask = 0x3f;
static const int kLocationMaskSize = 6;
static const int kSavedRegisterTag = 2;
static const int kSavedRegisterMask = 0x3f;
static const int kSavedRegisterMaskSize = 6;
static const int kFollowInitialRuleTag = 3;
static const int kFollowInitialRuleMask = 0x3f;
static const int kFollowInitialRuleMaskSize = 6;
static const int kProcedureAddressOffsetInFde = 2 * kInt32Size;
static const int kProcedureSizeOffsetInFde = 3 * kInt32Size;
static const int kInitialStateOffsetInCie = 19;
static const int kEhFrameTerminatorSize = 4;
// Defined in eh-writer-<arch>.cc
static const int kCodeAlignmentFactor;
static const int kDataAlignmentFactor;
static const int kFdeVersionSize = 1;
static const int kFdeEncodingSpecifiersSize = 3;
static const int kEhFrameHdrVersion = 1;
static const int kEhFrameHdrSize = 20;
};
class EhFrameWriter {
public:
explicit EhFrameWriter(Zone* zone);
// The empty frame is a hack to trigger fp-based unwinding in Linux perf
// compiled with libunwind support when processing DWARF-based call graphs.
//
// It is effectively a valid eh_frame_hdr with an empty look up table.
//
static void WriteEmptyEhFrame(std::ostream& stream); // NOLINT
// Write the CIE and FDE header. Call it before any other method.
void Initialize();
void AdvanceLocation(int pc_offset);
// The <base_address> is the one to which all <offset>s in SaveRegisterToStack
// directives are relative. It is given by <base_register> + <base_offset>.
//
// The <base_offset> must be positive or 0.
//
void SetBaseAddressRegister(Register base_register);
void SetBaseAddressOffset(int base_offset);
void IncreaseBaseAddressOffset(int base_delta) {
SetBaseAddressOffset(base_offset_ + base_delta);
}
void SetBaseAddressRegisterAndOffset(Register base_register, int base_offset);
// Register saved at location <base_address> + <offset>.
// The <offset> must be a multiple of EhFrameConstants::kDataAlignment.
void RecordRegisterSavedToStack(Register name, int offset) {
RecordRegisterSavedToStack(RegisterToDwarfCode(name), offset);
}
// The register has not been modified from the previous frame.
void RecordRegisterNotModified(Register name);
// The register follows the rule defined in the CIE.
void RecordRegisterFollowsInitialRule(Register name);
void Finish(int code_size);
// Remember to call Finish() before GetEhFrame().
//
// The EhFrameWriter instance owns the buffer pointed by
// CodeDesc::unwinding_info, and must outlive any use of the CodeDesc.
//
void GetEhFrame(CodeDesc* desc);
int last_pc_offset() const { return last_pc_offset_; }
Register base_register() const { return base_register_; }
int base_offset() const { return base_offset_; }
private:
enum class InternalState { kUndefined, kInitialized, kFinalized };
static const uint32_t kInt32Placeholder = 0xdeadc0de;
void WriteSLeb128(int32_t value);
void WriteULeb128(uint32_t value);
void WriteByte(byte value) { eh_frame_buffer_.push_back(value); }
void WriteOpcode(EhFrameConstants::DwarfOpcodes opcode) {
WriteByte(static_cast<byte>(opcode));
}
void WriteBytes(const byte* start, int size) {
eh_frame_buffer_.insert(eh_frame_buffer_.end(), start, start + size);
}
void WriteInt16(uint16_t value) {
WriteBytes(reinterpret_cast<const byte*>(&value), sizeof(value));
}
void WriteInt32(uint32_t value) {
WriteBytes(reinterpret_cast<const byte*>(&value), sizeof(value));
}
void PatchInt32(int base_offset, uint32_t value) {
DCHECK_EQ(ReadUnalignedUInt32(eh_frame_buffer_.data() + base_offset),
kInt32Placeholder);
DCHECK_LT(base_offset + kInt32Size, eh_frame_offset());
WriteUnalignedUInt32(eh_frame_buffer_.data() + base_offset, value);
}
// Write the common information entry, which includes encoding specifiers,
// alignment factors, the return address (pseudo) register code and the
// directives to construct the initial state of the unwinding table.
void WriteCie();
// Write the header of the function data entry, containing a pointer to the
// correspondent CIE and the position and size of the associated routine.
void WriteFdeHeader();
// Write the contents of the .eh_frame_hdr section, including encoding
// specifiers and the routine => FDE lookup table.
void WriteEhFrameHdr(int code_size);
// Write nops to the buffer until the size reaches a multiple of 8 bytes.
void WritePaddingTo8ByteAlignment();
// Internal version that directly accepts a DWARF register code, needed for
// handling pseudo-registers on some platforms.
void RecordRegisterSavedToStack(int register_code, int offset);
class EhFrameHdr final {
int GetProcedureAddressOffset() const {
return fde_offset() + EhFrameConstants::kProcedureAddressOffsetInFde;
}
int GetProcedureSizeOffset() const {
return fde_offset() + EhFrameConstants::kProcedureSizeOffsetInFde;
}
int eh_frame_offset() const {
return static_cast<int>(eh_frame_buffer_.size());
}
int fde_offset() const { return cie_size_; }
// Platform specific functions implemented in eh-frame-<arch>.cc
static int RegisterToDwarfCode(Register name);
// Write directives to build the initial state in the CIE.
void WriteInitialStateInCie();
// Write the return address (pseudo) register code.
void WriteReturnAddressRegisterCode();
int cie_size_;
int last_pc_offset_;
InternalState writer_state_;
Register base_register_;
int base_offset_;
ZoneVector<byte> eh_frame_buffer_;
DISALLOW_COPY_AND_ASSIGN(EhFrameWriter);
};
class EhFrameIterator {
public:
static const int kRecordSize = 20;
static const int kCIESize;
EhFrameIterator(const byte* start, const byte* end)
: start_(start), next_(start), end_(end) {
DCHECK_LE(start, end);
}
void SkipCie() {
DCHECK_EQ(next_, start_);
next_ += ReadUnalignedUInt32(next_) + kInt32Size;
}
void SkipToFdeDirectives() {
SkipCie();
// Skip the FDE header.
Skip(kDirectivesOffsetInFde);
}
void Skip(int how_many) {
DCHECK_GE(how_many, 0);
next_ += how_many;
DCHECK_LE(next_, end_);
}
uint32_t GetNextUInt32() { return GetNextValue<uint32_t>(); }
uint16_t GetNextUInt16() { return GetNextValue<uint16_t>(); }
byte GetNextByte() { return GetNextValue<byte>(); }
EhFrameConstants::DwarfOpcodes GetNextOpcode() {
return static_cast<EhFrameConstants::DwarfOpcodes>(GetNextByte());
}
uint32_t GetNextULeb128();
int32_t GetNextSLeb128();
bool Done() const {
DCHECK_LE(next_, end_);
return next_ == end_;
}
explicit EhFrameHdr(Code* code);
int GetCurrentOffset() const {
DCHECK_GE(next_, start_);
return static_cast<int>(next_ - start_);
}
int32_t offset_to_eh_frame() const { return offset_to_eh_frame_; }
uint32_t lut_entries_number() const { return lut_entries_number_; }
int32_t offset_to_procedure() const { return offset_to_procedure_; }
int32_t offset_to_fde() const { return offset_to_fde_; }
int GetBufferSize() { return static_cast<int>(end_ - start_); }
const void* current_address() const {
return reinterpret_cast<const void*>(next_);
}
private:
static const int kDirectivesOffsetInFde = 4 * kInt32Size + 1;
static uint32_t DecodeULeb128(const byte* encoded, int* encoded_size);
static int32_t DecodeSLeb128(const byte* encoded, int* encoded_size);
template <typename T>
T GetNextValue() {
T result;
DCHECK_LE(next_ + sizeof(result), end_);
result = ReadUnalignedValue<T>(next_);
next_ += sizeof(result);
return result;
}
const byte* start_;
const byte* next_;
const byte* end_;
};
#ifdef ENABLE_DISASSEMBLER
class EhFrameDisassembler final {
public:
EhFrameDisassembler(const byte* start, const byte* end)
: start_(start), end_(end) {
DCHECK_LT(start, end);
}
void DisassembleToStream(std::ostream& stream); // NOLINT
private:
uint8_t version_;
uint8_t eh_frame_ptr_encoding_;
uint8_t lut_size_encoding_;
uint8_t lut_entries_encoding_;
int32_t offset_to_eh_frame_;
uint32_t lut_entries_number_;
int32_t offset_to_procedure_;
int32_t offset_to_fde_;
static void DumpDwarfDirectives(std::ostream& stream, // NOLINT
const byte* start, const byte* end);
static const char* DwarfRegisterCodeToString(int code);
const byte* start_;
const byte* end_;
DISALLOW_COPY_AND_ASSIGN(EhFrameDisassembler);
};
#endif
} // namespace internal
} // namespace v8
......
......@@ -54,7 +54,7 @@ bool FullCodeGenerator::MakeCode(CompilationInfo* info) {
}
unsigned table_offset = cgen.EmitBackEdgeTable();
Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, info);
Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, nullptr, info);
cgen.PopulateDeoptimizationData(code);
cgen.PopulateTypeFeedbackInfo(code);
cgen.PopulateHandlerTable(code);
......
......@@ -61,6 +61,7 @@
#ifdef ENABLE_DISASSEMBLER
#include "src/disasm.h"
#include "src/disassembler.h"
#include "src/eh-frame.h"
#endif
namespace v8 {
......@@ -14372,6 +14373,14 @@ void Code::Disassemble(const char* name, std::ostream& os) { // NOLINT
it.rinfo()->Print(GetIsolate(), os);
}
os << "\n";
if (has_unwinding_info()) {
os << "UnwindingInfo (size = " << unwinding_info_size() << ")\n";
EhFrameDisassembler eh_frame_disassembler(unwinding_info_start(),
unwinding_info_end());
eh_frame_disassembler.DisassembleToStream(os);
os << "\n";
}
}
#endif // ENABLE_DISASSEMBLER
......
......@@ -324,18 +324,16 @@ void PerfJitLogger::LogWriteDebugInfo(Code* code, SharedFunctionInfo* shared) {
}
void PerfJitLogger::LogWriteUnwindingInfo(Code* code) {
EhFrameHdr eh_frame_hdr(code);
PerfJitCodeUnwindingInfo unwinding_info_header;
unwinding_info_header.event_ = PerfJitCodeLoad::kUnwindingInfo;
unwinding_info_header.time_stamp_ = GetTimestamp();
unwinding_info_header.eh_frame_hdr_size_ = EhFrameHdr::kRecordSize;
unwinding_info_header.eh_frame_hdr_size_ = EhFrameConstants::kEhFrameHdrSize;
if (code->has_unwinding_info()) {
unwinding_info_header.unwinding_size_ = code->unwinding_info_size();
unwinding_info_header.mapped_size_ = unwinding_info_header.unwinding_size_;
} else {
unwinding_info_header.unwinding_size_ = EhFrameHdr::kRecordSize;
unwinding_info_header.unwinding_size_ = EhFrameConstants::kEhFrameHdrSize;
unwinding_info_header.mapped_size_ = 0;
}
......@@ -348,16 +346,13 @@ void PerfJitLogger::LogWriteUnwindingInfo(Code* code) {
sizeof(unwinding_info_header));
if (code->has_unwinding_info()) {
// The last EhFrameHdr::kRecordSize bytes were a placeholder for the header.
// Discard them and write the actual eh_frame_hdr (below).
DCHECK_GE(code->unwinding_info_size(), EhFrameHdr::kRecordSize);
LogWriteBytes(reinterpret_cast<const char*>(code->unwinding_info_start()),
code->unwinding_info_size() - EhFrameHdr::kRecordSize);
code->unwinding_info_size());
} else {
OFStream perf_output_stream(perf_output_handle_);
EhFrameWriter::WriteEmptyEhFrame(perf_output_stream);
}
LogWriteBytes(reinterpret_cast<const char*>(&eh_frame_hdr),
EhFrameHdr::kRecordSize);
char padding_bytes[] = "\0\0\0\0\0\0\0\0";
DCHECK_LT(padding_size, sizeof(padding_bytes));
LogWriteBytes(padding_bytes, padding_size);
......
......@@ -1231,6 +1231,7 @@
'arm/macro-assembler-arm.h',
'arm/simulator-arm.cc',
'arm/simulator-arm.h',
'arm/eh-frame-arm.cc',
'compiler/arm/code-generator-arm.cc',
'compiler/arm/instruction-codes-arm.h',
'compiler/arm/instruction-scheduler-arm.cc',
......@@ -1285,6 +1286,7 @@
'arm64/simulator-arm64.h',
'arm64/utils-arm64.cc',
'arm64/utils-arm64.h',
'arm64/eh-frame-arm64.cc',
'compiler/arm64/code-generator-arm64.cc',
'compiler/arm64/instruction-codes-arm64.h',
'compiler/arm64/instruction-scheduler-arm64.cc',
......@@ -1514,6 +1516,7 @@
'compiler/x64/instruction-codes-x64.h',
'compiler/x64/instruction-scheduler-x64.cc',
'compiler/x64/instruction-selector-x64.cc',
'x64/eh-frame-x64.cc',
],
}],
['v8_target_arch=="ppc" or v8_target_arch=="ppc64"', {
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/eh-frame.h"
namespace v8 {
namespace internal {
static const int kRaxDwarfCode = 0;
static const int kRbpDwarfCode = 6;
static const int kRspDwarfCode = 7;
static const int kRipDwarfCode = 16;
STATIC_CONST_MEMBER_DEFINITION const int
EhFrameConstants::kCodeAlignmentFactor = 1;
STATIC_CONST_MEMBER_DEFINITION const int
EhFrameConstants::kDataAlignmentFactor = -8;
void EhFrameWriter::WriteReturnAddressRegisterCode() {
WriteULeb128(kRipDwarfCode);
}
void EhFrameWriter::WriteInitialStateInCie() {
SetBaseAddressRegisterAndOffset(rsp, kPointerSize);
// x64 rip (r16) has no Register instance associated.
RecordRegisterSavedToStack(kRipDwarfCode, -kPointerSize);
}
// static
int EhFrameWriter::RegisterToDwarfCode(Register name) {
switch (name.code()) {
case Register::kCode_rbp:
return kRbpDwarfCode;
case Register::kCode_rsp:
return kRspDwarfCode;
case Register::kCode_rax:
return kRaxDwarfCode;
default:
UNIMPLEMENTED();
return -1;
}
}
#ifdef ENABLE_DISASSEMBLER
// static
const char* EhFrameDisassembler::DwarfRegisterCodeToString(int code) {
switch (code) {
case kRbpDwarfCode:
return "rbp";
case kRspDwarfCode:
return "rsp";
case kRipDwarfCode:
return "rip";
default:
UNIMPLEMENTED();
return nullptr;
}
}
#endif
} // namespace internal
} // namespace v8
......@@ -138,7 +138,6 @@
'test-double.cc',
'test-dtoa.cc',
'test-elements-kind.cc',
'test-eh-frame-hdr.cc',
'test-fast-dtoa.cc',
'test-feedback-vector.cc',
'test-field-type-tracking.cc',
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/eh-frame.h"
#include "src/objects.h"
#include "test/cctest/cctest.h"
using namespace v8::internal;
TEST(EhFrameHdr) {
CcTest::InitializeVM();
HandleScope handle_scope(CcTest::i_isolate());
// The content is not relevant in this test
byte buffer[10] = {0};
byte unwinding_info[30 + EhFrameHdr::kRecordSize] = {0};
CodeDesc code_desc;
code_desc.buffer = &buffer[0];
code_desc.buffer_size = sizeof(buffer);
code_desc.constant_pool_size = 0;
code_desc.instr_size = sizeof(buffer);
code_desc.reloc_size = 0;
code_desc.origin = nullptr;
code_desc.unwinding_info = &unwinding_info[0];
code_desc.unwinding_info_size = sizeof(unwinding_info);
Handle<Code> code = CcTest::i_isolate()->factory()->NewCode(
code_desc, 0, Handle<Object>::null());
EhFrameHdr eh_frame_hdr(*code);
CHECK_EQ(eh_frame_hdr.lut_entries_number(), 1);
//
// Plugging some numbers in the DSO layout shown in eh-frame.cc:
//
// | ... |
// +---------------+ <-- (E) --------
// | | ^
// | Instructions | 10 bytes | .text
// | | v
// +---------------+ <---------------
// |///////////////|
// |////Padding////| 6 bytes
// |///////////////|
// +---------------+ <---(D)---------
// | | ^
// | CIE | N bytes* |
// | | |
// +---------------+ <-- (C) | .eh_frame
// | | |
// | FDE | 30 - N bytes |
// | | v
// +---------------+ <-- (B) --------
// | version | ^
// +---------------+ 4 bytes |
// | encoding | |
// | specifiers | |
// +---------------+ <---(A) | .eh_frame_hdr
// | offset to | |
// | .eh_frame | |
// +---------------+ |
// | ... | ...
//
// (*) the size of the CIE is platform dependent.
//
CHECK_EQ(eh_frame_hdr.offset_to_eh_frame(), -(4 + 30)); // A -> D
CHECK_EQ(eh_frame_hdr.offset_to_procedure(), -(30 + 6 + 10)); // B -> E
CHECK_EQ(eh_frame_hdr.offset_to_fde(),
-(30 - EhFrameHdr::kCIESize)); // B -> C
}
TEST(DummyEhFrameHdr) {
CcTest::InitializeVM();
HandleScope handle_scope(CcTest::i_isolate());
byte buffer[10] = {0}; // The content is not relevant in this test
CodeDesc code_desc;
code_desc.buffer = &buffer[0];
code_desc.buffer_size = sizeof(buffer);
code_desc.constant_pool_size = 0;
code_desc.instr_size = sizeof(buffer);
code_desc.reloc_size = 0;
code_desc.origin = nullptr;
code_desc.unwinding_info = nullptr;
code_desc.unwinding_info_size = 0;
Handle<Code> code = CcTest::i_isolate()->factory()->NewCode(
code_desc, 0, Handle<Object>::null());
EhFrameHdr eh_frame_hdr(*code);
// A dummy header has an empty LUT
CHECK_EQ(eh_frame_hdr.lut_entries_number(), 0);
// These values should be irrelevant, but check that they have been zeroed.
CHECK_EQ(eh_frame_hdr.offset_to_eh_frame(), 0);
CHECK_EQ(eh_frame_hdr.offset_to_procedure(), 0);
CHECK_EQ(eh_frame_hdr.offset_to_fde(), 0);
}
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/eh-frame.h"
#include "testing/gtest/include/gtest/gtest.h"
// Test enabled only on supported architectures.
#if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_ARM) || \
defined(V8_TARGET_ARCH_ARM64)
using namespace v8::internal;
namespace {
class EhFrameIteratorTest : public testing::Test {};
} // namespace
TEST_F(EhFrameIteratorTest, Values) {
// Assuming little endian.
static const byte kEncoded[] = {0xde, 0xc0, 0xad, 0xde, 0xef, 0xbe, 0xff};
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
EXPECT_EQ(0xdeadc0de, iterator.GetNextUInt32());
EXPECT_EQ(0xbeef, iterator.GetNextUInt16());
EXPECT_EQ(0xff, iterator.GetNextByte());
EXPECT_TRUE(iterator.Done());
}
TEST_F(EhFrameIteratorTest, Skip) {
static const byte kEncoded[] = {0xde, 0xad, 0xc0, 0xde};
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
iterator.Skip(2);
EXPECT_EQ(2, iterator.GetCurrentOffset());
EXPECT_EQ(0xc0, iterator.GetNextByte());
iterator.Skip(1);
EXPECT_TRUE(iterator.Done());
}
TEST_F(EhFrameIteratorTest, ULEB128Decoding) {
static const byte kEncoded[] = {0xe5, 0x8e, 0x26};
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
EXPECT_EQ(624485, iterator.GetNextULeb128());
EXPECT_TRUE(iterator.Done());
}
TEST_F(EhFrameIteratorTest, SLEB128DecodingPositive) {
static const byte kEncoded[] = {0xe5, 0x8e, 0x26};
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
EXPECT_EQ(624485, iterator.GetNextSLeb128());
EXPECT_TRUE(iterator.Done());
}
TEST_F(EhFrameIteratorTest, SLEB128DecodingNegative) {
static const byte kEncoded[] = {0x9b, 0xf1, 0x59};
EhFrameIterator iterator(&kEncoded[0], &kEncoded[0] + sizeof(kEncoded));
EXPECT_EQ(-624485, iterator.GetNextSLeb128());
EXPECT_TRUE(iterator.Done());
}
#endif
This diff is collapsed.
......@@ -79,6 +79,8 @@
'compiler/value-numbering-reducer-unittest.cc',
'compiler/zone-pool-unittest.cc',
'counters-unittest.cc',
'eh-frame-iterator-unittest.cc',
'eh-frame-writer-unittest.cc',
'interpreter/bytecodes-unittest.cc',
'interpreter/bytecode-array-builder-unittest.cc',
'interpreter/bytecode-array-iterator-unittest.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment