7d073b03c7
the .eh_frame format as part of the jitdump generated when FLAG_perf_prof is enabled. The final goal is allowing precise unwinding of callchains that include JITted code when profiling V8 using perf. Unwinding information is stored in the body of code objects after the code itself, prefixed with its length and aligned to a 8-byte boundary. A boolean flag in the header signals its presence, resulting in zero memory overhead when the generation of unwinding info is disabled or no such information was attached to the code object. A new jitdump record type (with id 4) is introduced for specifying optional unwinding information for code load records. The EhFrameHdr struct is also introduced, together with a constructor to initialise it from the associated code object. At this stage no unwinding information is written to the jitdump, but the infrastructure for doing so is ready in place. BUG=v8:4899 LOG=N Review-Url: https://codereview.chromium.org/1993653003 Cr-Commit-Position: refs/heads/master@{#37296}
101 lines
3.4 KiB
C++
101 lines
3.4 KiB
C++
// 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);
|
|
}
|