| Index: src/eh-frame.cc
|
| diff --git a/src/eh-frame.cc b/src/eh-frame.cc
|
| index af85e0b8d5f7143beb3c5243513a69fef0f5f919..e6aeb67d3d96acb47ee61e135ba0a03bdc2477a0 100644
|
| --- a/src/eh-frame.cc
|
| +++ b/src/eh-frame.cc
|
| @@ -3,21 +3,506 @@
|
| // found in the LICENSE file.
|
|
|
| #include "src/eh-frame.h"
|
| -#include "src/objects-inl.h"
|
| -#include "src/objects.h"
|
| +
|
| +#include <iomanip>
|
| +#include <ostream>
|
| +
|
| +#if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_ARM) && \
|
| + !defined(V8_TARGET_ARCH_ARM64)
|
| +
|
| +// Placeholders for unsupported architectures.
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +
|
| +STATIC_CONST_MEMBER_DEFINITION const int EhFrameWriter::kDataAlignmentFactor =
|
| + 1;
|
| +
|
| +void EhFrameWriter::WriteReturnAddressRegisterCode() { UNIMPLEMENTED(); }
|
| +
|
| +void EhFrameWriter::WriteInitialStateInCIE() { UNIMPLEMENTED(); }
|
| +
|
| +int EhFrameWriter::RegisterToDwarfCode(Register) {
|
| + UNIMPLEMENTED();
|
| + return -1;
|
| +}
|
| +
|
| +#ifdef ENABLE_DISASSEMBLER
|
| +
|
| +const char* EhFrameDisassembler::DwarfRegisterCodeToString(int) {
|
| + UNIMPLEMENTED();
|
| + return nullptr;
|
| +}
|
| +
|
| +#endif
|
| +
|
| +} // namespace internal
|
| +} // namespace v8
|
| +
|
| +#endif
|
|
|
| namespace v8 {
|
| namespace internal {
|
|
|
| -static const int DW_EH_PE_pcrel = 0x10;
|
| -static const int DW_EH_PE_datarel = 0x30;
|
| -static const int DW_EH_PE_udata4 = 0x03;
|
| -static const int DW_EH_PE_sdata4 = 0x0b;
|
| +STATIC_CONST_MEMBER_DEFINITION const int EhFrameWriter::kEhFrameTerminatorSize;
|
| +STATIC_CONST_MEMBER_DEFINITION const uint32_t EhFrameWriter::kInt32Placeholder;
|
| +
|
| +EhFrameWriter::EhFrameWriter()
|
| + : cie_size_(0),
|
| + last_pc_offset_(0),
|
| + eh_frame_finalised_(false),
|
| + base_register_(no_reg),
|
| + base_offset_(0) {
|
| + eh_frame_buffer_.reserve(100);
|
| + WriteCIE();
|
| + WriteFDEHeader();
|
| +}
|
| +
|
| +void EhFrameWriter::WriteCIE() {
|
| + static const int kCIEIdentifier = 0;
|
| + static const int kCIEVersion = 3;
|
| + static const int kCodeAlignmentFactor = 1;
|
| + static const int kAugmentationDataSize = 2;
|
| + static const byte kAugmentationString[] = {'z', 'L', 'R', 0};
|
| +
|
| + int size_offset = eh_frame_offset();
|
| + WriteInt32(kInt32Placeholder);
|
| +
|
| + int record_start_offset = eh_frame_offset();
|
| + WriteInt32(kCIEIdentifier);
|
| + WriteByte(kCIEVersion);
|
| +
|
| + WriteBytes(&kAugmentationString[0], sizeof(kAugmentationString));
|
| +
|
| + WriteSLEB128(kCodeAlignmentFactor);
|
| + WriteSLEB128(kDataAlignmentFactor);
|
| +
|
| + WriteReturnAddressRegisterCode();
|
| +
|
| + WriteByte(kAugmentationDataSize);
|
| + WriteByte(kOmit);
|
| + WriteByte(kSData4 | kPcRel);
|
| +
|
| + DCHECK_EQ(eh_frame_offset() - size_offset, kInitialStateOffsetInCIE);
|
| + WriteInitialStateInCIE();
|
| +
|
| + WritePaddingTo8ByteAlignment();
|
| +
|
| + int record_end_offset = eh_frame_offset();
|
| + int encoded_cie_size = record_end_offset - record_start_offset;
|
| + cie_size_ = record_end_offset - size_offset;
|
| +
|
| + PatchInt32(size_offset, encoded_cie_size);
|
| +}
|
| +
|
| +void EhFrameWriter::WriteFDEHeader() {
|
| + DCHECK_NE(cie_size_, 0);
|
| +
|
| + // Placeholder for size of the FDE.
|
| + DCHECK_EQ(eh_frame_offset(), fde_offset());
|
| + WriteInt32(kInt32Placeholder);
|
| +
|
| + // Backwards offset to the CIE.
|
| + WriteInt32(cie_size_ + kInt32Size);
|
| +
|
| + // Placeholder for pointer to procedure.
|
| + DCHECK_EQ(eh_frame_offset(), procedure_address_offset());
|
| + WriteInt32(kInt32Placeholder);
|
| +
|
| + // Placeholder for size of the procedure.
|
| + DCHECK_EQ(eh_frame_offset(), procedure_size_offset());
|
| + WriteInt32(kInt32Placeholder);
|
| +
|
| + // No augmentation data.
|
| + WriteByte(0);
|
| +}
|
| +
|
| +void EhFrameWriter::WritePaddingTo8ByteAlignment() {
|
| + DCHECK(!eh_frame_finalised_);
|
| +
|
| + int unpadded_size = eh_frame_offset();
|
| + int padded_size = RoundUp(unpadded_size, 8);
|
| + int padding_size = padded_size - unpadded_size;
|
| +
|
| + byte nop = static_cast<byte>(DwarfOpcodes::kNop);
|
| + static const byte kPadding[] = {nop, nop, nop, nop, nop, nop, nop, nop};
|
| + DCHECK_LE(padding_size, static_cast<int>(sizeof(kPadding)));
|
| + WriteBytes(&kPadding[0], padding_size);
|
| +}
|
| +
|
| +void EhFrameWriter::AdvanceLocation(int pc_offset) {
|
| + DCHECK(!eh_frame_finalised_);
|
| + DCHECK_GE(pc_offset, last_pc_offset_);
|
| + uint32_t delta = pc_offset - last_pc_offset_;
|
| +
|
| + if (delta <= kLocationMask) {
|
| + WriteByte((kLocationTag << kLocationMaskSize) | (delta & kLocationMask));
|
| + } else if (delta <= kMaxUInt8) {
|
| + WriteOpcode(DwarfOpcodes::kAdvanceLoc1);
|
| + WriteByte(delta);
|
| + } else if (delta <= kMaxUInt16) {
|
| + WriteOpcode(DwarfOpcodes::kAdvanceLoc2);
|
| + WriteInt16(delta);
|
| + } else {
|
| + WriteOpcode(DwarfOpcodes::kAdvanceLoc4);
|
| + WriteInt32(delta);
|
| + }
|
| +
|
| + last_pc_offset_ = pc_offset;
|
| +}
|
| +
|
| +void EhFrameWriter::SetBaseAddressOffset(int base_offset) {
|
| + DCHECK(!eh_frame_finalised_);
|
| + DCHECK_GE(base_offset, 0);
|
| + WriteOpcode(DwarfOpcodes::kDefCfaOffset);
|
| + WriteULEB128(base_offset);
|
| + base_offset_ = base_offset;
|
| +}
|
| +
|
| +void EhFrameWriter::SetBaseAddressRegister(Register base_register) {
|
| + DCHECK(!eh_frame_finalised_);
|
| + int code = RegisterToDwarfCode(base_register);
|
| + WriteOpcode(DwarfOpcodes::kDefCfaRegister);
|
| + WriteULEB128(code);
|
| + base_register_ = base_register;
|
| +}
|
| +
|
| +void EhFrameWriter::SetBaseAddressRegisterAndOffset(Register base_register,
|
| + int base_offset) {
|
| + DCHECK(!eh_frame_finalised_);
|
| + int code = RegisterToDwarfCode(base_register);
|
| + WriteOpcode(DwarfOpcodes::kDefCfa);
|
| + WriteULEB128(code);
|
| + WriteULEB128(base_offset);
|
| + base_offset_ = base_offset;
|
| + base_register_ = base_register;
|
| +}
|
| +
|
| +void EhFrameWriter::RecordRegisterSavedToStack(int register_code, int offset) {
|
| + DCHECK(!eh_frame_finalised_);
|
| + DCHECK_EQ(offset % kDataAlignmentFactor, 0);
|
| + int factored_offset = offset / std::abs(kDataAlignmentFactor);
|
| + if (factored_offset >= 0) {
|
| + DCHECK_LE(register_code, kSavedRegisterMask);
|
| + WriteByte((kSavedRegisterTag << kSavedRegisterMaskSize) |
|
| + (register_code & kSavedRegisterMask));
|
| + WriteULEB128(factored_offset);
|
| + } else {
|
| + WriteOpcode(DwarfOpcodes::kOffsetExtendedSf);
|
| + WriteULEB128(register_code);
|
| + WriteSLEB128(factored_offset);
|
| + }
|
| +}
|
| +
|
| +void EhFrameWriter::RecordRegisterIsValid(Register name) {
|
| + DCHECK(!eh_frame_finalised_);
|
| + WriteOpcode(DwarfOpcodes::kSameValue);
|
| + WriteULEB128(RegisterToDwarfCode(name));
|
| +}
|
| +
|
| +void EhFrameWriter::RecordRegisterFollowsInitialRule(Register name) {
|
| + DCHECK(!eh_frame_finalised_);
|
| + int code = RegisterToDwarfCode(name);
|
| + DCHECK_LE(code, kFollowInitialRuleMask);
|
| + WriteByte((kFollowInitialRuleTag << kFollowInitialRuleMaskSize) |
|
| + (code & kFollowInitialRuleMask));
|
| +}
|
| +
|
| +void EhFrameWriter::Finish(int code_size) {
|
| + DCHECK(!eh_frame_finalised_);
|
| + DCHECK_GE(eh_frame_offset(), cie_size_);
|
| +
|
| + WritePaddingTo8ByteAlignment();
|
| +
|
| + // Write the size of the FDE now that we know it.
|
| + // The encoded size does not include the size field itself.
|
| + int fde_size = eh_frame_offset() - fde_offset() - kInt32Size;
|
| + PatchInt32(fde_offset(), fde_size);
|
| +
|
| + // Write the size and offset to procedure.
|
| + PatchInt32(procedure_address_offset(),
|
| + -(RoundUp(code_size, 8) + procedure_address_offset()));
|
| + PatchInt32(procedure_size_offset(), code_size);
|
| +
|
| + // Terminate the .eh_frame.
|
| + static const byte kTerminator[kEhFrameTerminatorSize] = {0};
|
| + WriteBytes(&kTerminator[0], kEhFrameTerminatorSize);
|
| +
|
| + // Write .eh_frame_hdr
|
| + EhFrameHdr eh_frame_hdr(code_size, eh_frame_offset(), cie_size_);
|
| + WriteBytes(reinterpret_cast<const byte*>(&eh_frame_hdr),
|
| + EhFrameHdr::kRecordSize);
|
| +
|
| + eh_frame_finalised_ = true;
|
| +}
|
| +
|
| +void EhFrameWriter::GetEhFrame(CodeDesc* desc) {
|
| + DCHECK(eh_frame_finalised_);
|
| + desc->unwinding_info_size = static_cast<int>(eh_frame_buffer_.size());
|
| + desc->unwinding_info = eh_frame_buffer_.data();
|
| +}
|
| +
|
| +void EhFrameWriter::WriteULEB128(uint32_t value) {
|
| + do {
|
| + byte chunk = value & 0x7f;
|
| + value >>= 7;
|
| + if (value != 0) chunk |= 0x80;
|
| + eh_frame_buffer_.push_back(chunk);
|
| + } while (value != 0);
|
| +}
|
| +
|
| +void EhFrameWriter::WriteSLEB128(int32_t value) {
|
| + static const int kSignBitMask = 0x40;
|
| + bool done;
|
| + do {
|
| + byte chunk = value & 0x7f;
|
| + value >>= 7;
|
| + done = ((value == 0) && ((chunk & kSignBitMask) == 0)) ||
|
| + ((value == -1) && ((chunk & kSignBitMask) != 0));
|
| + if (!done) chunk |= 0x80;
|
| + eh_frame_buffer_.push_back(chunk);
|
| + } while (!done);
|
| +}
|
| +
|
| +EhFrameIterator::EhFrameIterator(EhFrameWriter* writer) {
|
| + CodeDesc desc;
|
| + writer->GetEhFrame(&desc);
|
| + start_ = desc.unwinding_info;
|
| + end_ = start_ + desc.unwinding_info_size;
|
| + next_ = start_;
|
| +}
|
| +
|
| +uint32_t EhFrameIterator::GetNextULEB128() {
|
| + int size = 0;
|
| + uint32_t result = DecodeULEB128(next_, &size);
|
| + DCHECK_LE(next_ + size, end_);
|
| + next_ += size;
|
| + return result;
|
| +}
|
| +
|
| +int32_t EhFrameIterator::GetNextSLEB128() {
|
| + int size = 0;
|
| + int32_t result = DecodeSLEB128(next_, &size);
|
| + DCHECK_LE(next_ + size, end_);
|
| + next_ += size;
|
| + return result;
|
| +}
|
| +
|
| +// static
|
| +uint32_t EhFrameIterator::DecodeULEB128(const byte* encoded,
|
| + int* encoded_size) {
|
| + const byte* current = encoded;
|
| + uint32_t result = 0;
|
| + int shift = 0;
|
| +
|
| + do {
|
| + DCHECK_LT(shift, 8 * static_cast<int>(sizeof(result)));
|
| + result |= (*current & 0x7f) << shift;
|
| + shift += 7;
|
| + } while (*current++ >= 128);
|
| +
|
| + DCHECK_NOT_NULL(encoded_size);
|
| + *encoded_size = static_cast<int>(current - encoded);
|
| +
|
| + return result;
|
| +}
|
| +
|
| +// static
|
| +int32_t EhFrameIterator::DecodeSLEB128(const byte* encoded, int* encoded_size) {
|
| + static const byte kSignBitMask = 0x40;
|
| +
|
| + const byte* current = encoded;
|
| + int32_t result = 0;
|
| + int shift = 0;
|
| + byte chunk;
|
| +
|
| + do {
|
| + chunk = *current++;
|
| + DCHECK_LT(shift, 8 * static_cast<int>(sizeof(result)));
|
| + result |= (chunk & 0x7f) << shift;
|
| + shift += 7;
|
| + } while (chunk >= 128);
|
| +
|
| + // Sign extend the result if the last chunk has the sign bit set.
|
| + if (chunk & kSignBitMask) result |= (~0ull) << shift;
|
| +
|
| + DCHECK_NOT_NULL(encoded_size);
|
| + *encoded_size = static_cast<int>(current - encoded);
|
| +
|
| + return result;
|
| +}
|
| +
|
| +#ifdef ENABLE_DISASSEMBLER
|
| +
|
| +namespace {
|
| +
|
| +class StreamModifiersScope final {
|
| + public:
|
| + explicit StreamModifiersScope(std::ostream* stream)
|
| + : stream_(stream), flags_(stream->flags()) {}
|
| + ~StreamModifiersScope() { stream_->flags(flags_); }
|
| +
|
| + private:
|
| + std::ostream* stream_;
|
| + std::ios::fmtflags flags_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +void EhFrameDisassembler::DumpDWARFDirectives(std::ostream& stream, // NOLINT
|
| + const byte* start,
|
| + const byte* end) {
|
| + StreamModifiersScope modifiers_scope(&stream);
|
| +
|
| + EhFrameIterator eh_frame_iterator(start, end);
|
| + uint32_t offset_in_procedure = 0;
|
| +
|
| + while (!eh_frame_iterator.ReachedEnd()) {
|
| + stream << eh_frame_iterator.current_address() << " ";
|
| +
|
| + byte bytecode = eh_frame_iterator.GetNextByte();
|
| +
|
| + if (((bytecode >> EhFrameWriter::kLocationMaskSize) & 0xff) ==
|
| + EhFrameWriter::kLocationTag) {
|
| + int value = bytecode & EhFrameWriter::kLocationMask;
|
| + offset_in_procedure += value;
|
| + stream << "| pc_offset=" << std::dec << offset_in_procedure
|
| + << " (delta=0x" << std::hex << value << ")\n";
|
| + continue;
|
| + }
|
| +
|
| + if (((bytecode >> EhFrameWriter::kSavedRegisterMaskSize) & 0xff) ==
|
| + EhFrameWriter::kSavedRegisterTag) {
|
| + int decoded_offset = static_cast<int>(eh_frame_iterator.GetNextULEB128());
|
| + stream << "| " << DwarfRegisterCodeToString(bytecode &
|
| + EhFrameWriter::kLocationMask)
|
| + << " saved at base" << std::showpos << std::dec
|
| + << decoded_offset * EhFrameWriter::kDataAlignmentFactor << '\n';
|
| + continue;
|
| + }
|
| +
|
| + if (((bytecode >> EhFrameWriter::kFollowInitialRuleMaskSize) & 0xff) ==
|
| + EhFrameWriter::kFollowInitialRuleTag) {
|
| + stream << "| " << DwarfRegisterCodeToString(bytecode &
|
| + EhFrameWriter::kLocationMask)
|
| + << " follows initial rule\n";
|
| + continue;
|
| + }
|
| +
|
| + switch (static_cast<EhFrameWriter::DwarfOpcodes>(bytecode)) {
|
| + case EhFrameWriter::DwarfOpcodes::kOffsetExtendedSf: {
|
| + stream << "| "
|
| + << DwarfRegisterCodeToString(eh_frame_iterator.GetNextULEB128());
|
| + int32_t decoded_offset = eh_frame_iterator.GetNextSLEB128();
|
| + stream << " saved at base" << std::showpos << std::dec
|
| + << decoded_offset * EhFrameWriter::kDataAlignmentFactor << '\n';
|
| + }
|
| + case EhFrameWriter::DwarfOpcodes::kAdvanceLoc1: {
|
| + unsigned value = eh_frame_iterator.GetNextByte();
|
| + offset_in_procedure += value;
|
| + stream << "| pc_offset=" << std::dec << offset_in_procedure
|
| + << " (delta=0x" << std::hex << value << ")\n";
|
| + break;
|
| + }
|
| + case EhFrameWriter::DwarfOpcodes::kAdvanceLoc2: {
|
| + uint16_t value = eh_frame_iterator.GetNextUInt16();
|
| + offset_in_procedure += value;
|
| + stream << "| pc_offset=" << std::dec << offset_in_procedure
|
| + << " (delta=0x" << std::hex << value << ")\n";
|
| + break;
|
| + }
|
| + case EhFrameWriter::DwarfOpcodes::kAdvanceLoc4: {
|
| + uint32_t value = eh_frame_iterator.GetNextUInt32();
|
| + offset_in_procedure += value;
|
| + stream << "| pc_offset=" << std::dec << offset_in_procedure
|
| + << " (delta=0x" << std::hex << value << ")\n";
|
| + break;
|
| + }
|
| + case EhFrameWriter::DwarfOpcodes::kDefCfa: {
|
| + int base_register = eh_frame_iterator.GetNextULEB128();
|
| + int base_offset = eh_frame_iterator.GetNextULEB128();
|
| + stream << "| base_register=" << DwarfRegisterCodeToString(base_register)
|
| + << ", base_offset=0x" << std::hex << base_offset << '\n';
|
| + break;
|
| + }
|
| + case EhFrameWriter::DwarfOpcodes::kDefCfaOffset: {
|
| + stream << "| base_offset=0x" << std::hex
|
| + << eh_frame_iterator.GetNextULEB128() << '\n';
|
| + break;
|
| + }
|
| + case EhFrameWriter::DwarfOpcodes::kDefCfaRegister: {
|
| + stream << "| base_register="
|
| + << DwarfRegisterCodeToString(eh_frame_iterator.GetNextULEB128())
|
| + << '\n';
|
| + break;
|
| + }
|
| + case EhFrameWriter::DwarfOpcodes::kSameValue: {
|
| + stream << "| "
|
| + << DwarfRegisterCodeToString(eh_frame_iterator.GetNextULEB128())
|
| + << " to initial value\n";
|
| + break;
|
| + }
|
| + case EhFrameWriter::DwarfOpcodes::kNop:
|
| + stream << "| nop\n";
|
| + break;
|
| + default:
|
| + UNREACHABLE();
|
| + return;
|
| + }
|
| + }
|
| +}
|
| +
|
| +// static
|
| +void EhFrameDisassembler::DisassembleToStream(std::ostream& stream) { // NOLINT
|
| + // The encoded CIE size does not include the size field itself.
|
| + const int cie_size = ReadUnalignedUInt32(start_) + kInt32Size;
|
| + const int fde_offset = cie_size;
|
|
|
| -const int EhFrameHdr::kCIESize = 0;
|
| + const byte* cie_directives_start =
|
| + start_ + EhFrameWriter::kInitialStateOffsetInCIE;
|
| + const byte* cie_directives_end = start_ + cie_size;
|
| + DCHECK_LE(cie_directives_start, cie_directives_end);
|
|
|
| -static const int kVersionSize = 1;
|
| -static const int kEncodingSpecifiersSize = 3;
|
| + stream << reinterpret_cast<const void*>(start_) << " .eh_frame: CIE\n";
|
| + DumpDWARFDirectives(stream, cie_directives_start, cie_directives_end);
|
| +
|
| + const byte* procedure_offset_address =
|
| + start_ + fde_offset + EhFrameWriter::kProcedureAddressOffsetInFde;
|
| + int32_t procedure_offset =
|
| + ReadUnalignedValue<int32_t>(procedure_offset_address);
|
| +
|
| + const byte* procedure_size_address =
|
| + start_ + fde_offset + EhFrameWriter::kProcedureSizeOffsetInFde;
|
| + uint32_t procedure_size = ReadUnalignedUInt32(procedure_size_address);
|
| +
|
| + const byte* fde_start = start_ + fde_offset;
|
| + stream << reinterpret_cast<const void*>(fde_start) << " .eh_frame: FDE\n"
|
| + << reinterpret_cast<const void*>(procedure_offset_address)
|
| + << " | procedure offset=" << procedure_offset << '\n'
|
| + << reinterpret_cast<const void*>(procedure_size_address)
|
| + << " | procedure size=" << procedure_size << '\n';
|
| +
|
| + const int fde_directives_offset = fde_offset + 4 * kInt32Size + 1;
|
| +
|
| + const byte* fde_directives_start = start_ + fde_directives_offset;
|
| + const byte* fde_directives_end =
|
| + end_ - EhFrameHdr::kRecordSize - EhFrameWriter::kEhFrameTerminatorSize;
|
| + DCHECK_LE(fde_directives_start, fde_directives_end);
|
| +
|
| + DumpDWARFDirectives(stream, fde_directives_start, fde_directives_end);
|
| +
|
| + const byte* fde_terminator_start = fde_directives_end;
|
| + stream << reinterpret_cast<const void*>(fde_terminator_start)
|
| + << " .eh_frame: terminator\n";
|
| +
|
| + const byte* eh_frame_hdr_start =
|
| + fde_terminator_start + EhFrameWriter::kEhFrameTerminatorSize;
|
| + stream << reinterpret_cast<const void*>(eh_frame_hdr_start)
|
| + << " .eh_frame_hdr: placeholder\n";
|
| +}
|
| +
|
| +#endif
|
|
|
| //
|
| // In order to calculate offsets in the .eh_frame_hdr, we must know the layout
|
| @@ -51,45 +536,51 @@ static const int kEncodingSpecifiersSize = 3;
|
| // +---------------+ |
|
| // | ... | ...
|
| //
|
| -// (F) is aligned at a 16-byte boundary.
|
| -// (D) is aligned at a 8-byte boundary.
|
| -// (B) is aligned at a 4-byte boundary.
|
| -// (E), (C) and (A) have no alignment requirements.
|
| +// (F) is aligned to a 16-byte boundary.
|
| +// (D) is aligned to a 8-byte boundary.
|
| +// (B) is aligned to a 4-byte boundary.
|
| +// (C) is aligned to an addressing unit size boundary.
|
| +// (E) and (A) have no alignment requirements.
|
| //
|
| // The distance between (A) and (B) is 4 bytes.
|
| //
|
| -// The size of the .eh_frame is required to be a multiple of the pointer size,
|
| -// which means that (B) will be naturally aligned to a 4-byte boundary on all
|
| -// the architectures we support.
|
| +// The size of the FDE is required to be a multiple of the pointer size, which
|
| +// means that (B) will be naturally aligned to a 4-byte boundary on all the
|
| +// architectures we support.
|
| //
|
| // Because (E) has no alignment requirements, there is padding between (E) and
|
| // (D). (F) is aligned at a 16-byte boundary, thus to a 8-byte one as well.
|
| //
|
| -EhFrameHdr::EhFrameHdr(Code* code) {
|
| - int code_size = code->is_crankshafted() ? code->safepoint_table_offset()
|
| - : code->instruction_size();
|
| - version_ = 1;
|
| - eh_frame_ptr_encoding_ = DW_EH_PE_sdata4 | DW_EH_PE_pcrel;
|
| - lut_size_encoding_ = DW_EH_PE_udata4;
|
| - lut_entries_encoding_ = DW_EH_PE_sdata4 | DW_EH_PE_datarel;
|
| -
|
| - // .eh_frame pointer and LUT
|
| - if (code->has_unwinding_info()) {
|
| - DCHECK_GE(code->unwinding_info_size(), EhFrameHdr::kRecordSize);
|
| - int eh_frame_size = code->unwinding_info_size() - EhFrameHdr::kRecordSize;
|
| -
|
| - offset_to_eh_frame_ =
|
| - -(eh_frame_size + kVersionSize + kEncodingSpecifiersSize); // A -> D
|
| - lut_entries_number_ = 1;
|
| - offset_to_procedure_ = -(RoundUp(code_size, 8) + eh_frame_size); // B -> F
|
| - offset_to_fde_ = -(eh_frame_size - kCIESize); // B -> C
|
| - } else {
|
| - // Create a dummy table
|
| - offset_to_eh_frame_ = 0;
|
| - lut_entries_number_ = 0;
|
| - offset_to_procedure_ = 0;
|
| - offset_to_fde_ = 0;
|
| - }
|
| +EhFrameHdr::EhFrameHdr(int code_size, int eh_frame_size, int cie_size) {
|
| + static const int kFdeVersionSize = 1;
|
| + static const int kFdeEncodingSpecifiersSize = 3;
|
| +
|
| + version_ = kEhFrameHdrVersion;
|
| +
|
| + eh_frame_ptr_encoding_ = EhFrameWriter::kSData4 | EhFrameWriter::kPcRel;
|
| + lut_size_encoding_ = EhFrameWriter::kUData4;
|
| + lut_entries_encoding_ = EhFrameWriter::kSData4 | EhFrameWriter::kDataRel;
|
| + offset_to_eh_frame_ = -(eh_frame_size + kFdeVersionSize +
|
| + kFdeEncodingSpecifiersSize); // A -> D
|
| + lut_entries_number_ = 1;
|
| + offset_to_procedure_ = -(RoundUp(code_size, 8) + eh_frame_size); // B -> F
|
| + offset_to_fde_ = -(eh_frame_size - cie_size); // B -> C
|
| +}
|
| +
|
| +// static
|
| +EhFrameHdr EhFrameHdr::CreateEmptyHeader() {
|
| + EhFrameHdr dummy_frame;
|
| + dummy_frame.version_ = kEhFrameHdrVersion;
|
| + dummy_frame.eh_frame_ptr_encoding_ =
|
| + EhFrameWriter::kSData4 | EhFrameWriter::kPcRel;
|
| + dummy_frame.lut_size_encoding_ = EhFrameWriter::kUData4;
|
| + dummy_frame.lut_entries_encoding_ =
|
| + EhFrameWriter::kSData4 | EhFrameWriter::kDataRel;
|
| + dummy_frame.offset_to_eh_frame_ = 0;
|
| + dummy_frame.lut_entries_number_ = 0;
|
| + dummy_frame.offset_to_procedure_ = 0;
|
| + dummy_frame.offset_to_fde_ = 0;
|
| + return dummy_frame;
|
| }
|
|
|
| } // namespace internal
|
|
|