OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/eh-frame.h" | 5 #include "src/eh-frame.h" |
6 #include "src/objects-inl.h" | 6 |
7 #include "src/objects.h" | 7 #include <iomanip> |
| 8 #include <ostream> |
| 9 |
| 10 #if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_ARM) && \ |
| 11 !defined(V8_TARGET_ARCH_ARM64) |
| 12 |
| 13 // Placeholders for unsupported architectures. |
8 | 14 |
9 namespace v8 { | 15 namespace v8 { |
10 namespace internal { | 16 namespace internal { |
11 | 17 |
12 static const int DW_EH_PE_pcrel = 0x10; | 18 STATIC_CONST_MEMBER_DEFINITION const int EhFrameWriter::kDataAlignmentFactor = |
13 static const int DW_EH_PE_datarel = 0x30; | 19 1; |
14 static const int DW_EH_PE_udata4 = 0x03; | 20 |
15 static const int DW_EH_PE_sdata4 = 0x0b; | 21 void EhFrameWriter::WriteReturnAddressRegisterCode() { UNIMPLEMENTED(); } |
16 | 22 |
17 const int EhFrameHdr::kCIESize = 0; | 23 void EhFrameWriter::WriteInitialStateInCIE() { UNIMPLEMENTED(); } |
18 | 24 |
19 static const int kVersionSize = 1; | 25 int EhFrameWriter::RegisterToDwarfCode(Register) { |
20 static const int kEncodingSpecifiersSize = 3; | 26 UNIMPLEMENTED(); |
| 27 return -1; |
| 28 } |
| 29 |
| 30 #ifdef ENABLE_DISASSEMBLER |
| 31 |
| 32 const char* EhFrameDisassembler::DwarfRegisterCodeToString(int) { |
| 33 UNIMPLEMENTED(); |
| 34 return nullptr; |
| 35 } |
| 36 |
| 37 #endif |
| 38 |
| 39 } // namespace internal |
| 40 } // namespace v8 |
| 41 |
| 42 #endif |
| 43 |
| 44 namespace v8 { |
| 45 namespace internal { |
| 46 |
| 47 STATIC_CONST_MEMBER_DEFINITION const int EhFrameWriter::kEhFrameTerminatorSize; |
| 48 STATIC_CONST_MEMBER_DEFINITION const uint32_t EhFrameWriter::kInt32Placeholder; |
| 49 |
| 50 EhFrameWriter::EhFrameWriter() |
| 51 : cie_size_(0), |
| 52 last_pc_offset_(0), |
| 53 eh_frame_finalised_(false), |
| 54 base_register_(no_reg), |
| 55 base_offset_(0) { |
| 56 eh_frame_buffer_.reserve(100); |
| 57 WriteCIE(); |
| 58 WriteFDEHeader(); |
| 59 } |
| 60 |
| 61 void EhFrameWriter::WriteCIE() { |
| 62 static const int kCIEIdentifier = 0; |
| 63 static const int kCIEVersion = 3; |
| 64 static const int kCodeAlignmentFactor = 1; |
| 65 static const int kAugmentationDataSize = 2; |
| 66 static const byte kAugmentationString[] = {'z', 'L', 'R', 0}; |
| 67 |
| 68 int size_offset = eh_frame_offset(); |
| 69 WriteInt32(kInt32Placeholder); |
| 70 |
| 71 int record_start_offset = eh_frame_offset(); |
| 72 WriteInt32(kCIEIdentifier); |
| 73 WriteByte(kCIEVersion); |
| 74 |
| 75 WriteBytes(&kAugmentationString[0], sizeof(kAugmentationString)); |
| 76 |
| 77 WriteSLEB128(kCodeAlignmentFactor); |
| 78 WriteSLEB128(kDataAlignmentFactor); |
| 79 |
| 80 WriteReturnAddressRegisterCode(); |
| 81 |
| 82 WriteByte(kAugmentationDataSize); |
| 83 WriteByte(kOmit); |
| 84 WriteByte(kSData4 | kPcRel); |
| 85 |
| 86 DCHECK_EQ(eh_frame_offset() - size_offset, kInitialStateOffsetInCIE); |
| 87 WriteInitialStateInCIE(); |
| 88 |
| 89 WritePaddingTo8ByteAlignment(); |
| 90 |
| 91 int record_end_offset = eh_frame_offset(); |
| 92 int encoded_cie_size = record_end_offset - record_start_offset; |
| 93 cie_size_ = record_end_offset - size_offset; |
| 94 |
| 95 PatchInt32(size_offset, encoded_cie_size); |
| 96 } |
| 97 |
| 98 void EhFrameWriter::WriteFDEHeader() { |
| 99 DCHECK_NE(cie_size_, 0); |
| 100 |
| 101 // Placeholder for size of the FDE. |
| 102 DCHECK_EQ(eh_frame_offset(), fde_offset()); |
| 103 WriteInt32(kInt32Placeholder); |
| 104 |
| 105 // Backwards offset to the CIE. |
| 106 WriteInt32(cie_size_ + kInt32Size); |
| 107 |
| 108 // Placeholder for pointer to procedure. |
| 109 DCHECK_EQ(eh_frame_offset(), procedure_address_offset()); |
| 110 WriteInt32(kInt32Placeholder); |
| 111 |
| 112 // Placeholder for size of the procedure. |
| 113 DCHECK_EQ(eh_frame_offset(), procedure_size_offset()); |
| 114 WriteInt32(kInt32Placeholder); |
| 115 |
| 116 // No augmentation data. |
| 117 WriteByte(0); |
| 118 } |
| 119 |
| 120 void EhFrameWriter::WritePaddingTo8ByteAlignment() { |
| 121 DCHECK(!eh_frame_finalised_); |
| 122 |
| 123 int unpadded_size = eh_frame_offset(); |
| 124 int padded_size = RoundUp(unpadded_size, 8); |
| 125 int padding_size = padded_size - unpadded_size; |
| 126 |
| 127 byte nop = static_cast<byte>(DwarfOpcodes::kNop); |
| 128 static const byte kPadding[] = {nop, nop, nop, nop, nop, nop, nop, nop}; |
| 129 DCHECK_LE(padding_size, static_cast<int>(sizeof(kPadding))); |
| 130 WriteBytes(&kPadding[0], padding_size); |
| 131 } |
| 132 |
| 133 void EhFrameWriter::AdvanceLocation(int pc_offset) { |
| 134 DCHECK(!eh_frame_finalised_); |
| 135 DCHECK_GE(pc_offset, last_pc_offset_); |
| 136 uint32_t delta = pc_offset - last_pc_offset_; |
| 137 |
| 138 if (delta <= kLocationMask) { |
| 139 WriteByte((kLocationTag << kLocationMaskSize) | (delta & kLocationMask)); |
| 140 } else if (delta <= kMaxUInt8) { |
| 141 WriteOpcode(DwarfOpcodes::kAdvanceLoc1); |
| 142 WriteByte(delta); |
| 143 } else if (delta <= kMaxUInt16) { |
| 144 WriteOpcode(DwarfOpcodes::kAdvanceLoc2); |
| 145 WriteInt16(delta); |
| 146 } else { |
| 147 WriteOpcode(DwarfOpcodes::kAdvanceLoc4); |
| 148 WriteInt32(delta); |
| 149 } |
| 150 |
| 151 last_pc_offset_ = pc_offset; |
| 152 } |
| 153 |
| 154 void EhFrameWriter::SetBaseAddressOffset(int base_offset) { |
| 155 DCHECK(!eh_frame_finalised_); |
| 156 DCHECK_GE(base_offset, 0); |
| 157 WriteOpcode(DwarfOpcodes::kDefCfaOffset); |
| 158 WriteULEB128(base_offset); |
| 159 base_offset_ = base_offset; |
| 160 } |
| 161 |
| 162 void EhFrameWriter::SetBaseAddressRegister(Register base_register) { |
| 163 DCHECK(!eh_frame_finalised_); |
| 164 int code = RegisterToDwarfCode(base_register); |
| 165 WriteOpcode(DwarfOpcodes::kDefCfaRegister); |
| 166 WriteULEB128(code); |
| 167 base_register_ = base_register; |
| 168 } |
| 169 |
| 170 void EhFrameWriter::SetBaseAddressRegisterAndOffset(Register base_register, |
| 171 int base_offset) { |
| 172 DCHECK(!eh_frame_finalised_); |
| 173 int code = RegisterToDwarfCode(base_register); |
| 174 WriteOpcode(DwarfOpcodes::kDefCfa); |
| 175 WriteULEB128(code); |
| 176 WriteULEB128(base_offset); |
| 177 base_offset_ = base_offset; |
| 178 base_register_ = base_register; |
| 179 } |
| 180 |
| 181 void EhFrameWriter::RecordRegisterSavedToStack(int register_code, int offset) { |
| 182 DCHECK(!eh_frame_finalised_); |
| 183 DCHECK_EQ(offset % kDataAlignmentFactor, 0); |
| 184 int factored_offset = offset / std::abs(kDataAlignmentFactor); |
| 185 if (factored_offset >= 0) { |
| 186 DCHECK_LE(register_code, kSavedRegisterMask); |
| 187 WriteByte((kSavedRegisterTag << kSavedRegisterMaskSize) | |
| 188 (register_code & kSavedRegisterMask)); |
| 189 WriteULEB128(factored_offset); |
| 190 } else { |
| 191 WriteOpcode(DwarfOpcodes::kOffsetExtendedSf); |
| 192 WriteULEB128(register_code); |
| 193 WriteSLEB128(factored_offset); |
| 194 } |
| 195 } |
| 196 |
| 197 void EhFrameWriter::RecordRegisterIsValid(Register name) { |
| 198 DCHECK(!eh_frame_finalised_); |
| 199 WriteOpcode(DwarfOpcodes::kSameValue); |
| 200 WriteULEB128(RegisterToDwarfCode(name)); |
| 201 } |
| 202 |
| 203 void EhFrameWriter::RecordRegisterFollowsInitialRule(Register name) { |
| 204 DCHECK(!eh_frame_finalised_); |
| 205 int code = RegisterToDwarfCode(name); |
| 206 DCHECK_LE(code, kFollowInitialRuleMask); |
| 207 WriteByte((kFollowInitialRuleTag << kFollowInitialRuleMaskSize) | |
| 208 (code & kFollowInitialRuleMask)); |
| 209 } |
| 210 |
| 211 void EhFrameWriter::Finish(int code_size) { |
| 212 DCHECK(!eh_frame_finalised_); |
| 213 DCHECK_GE(eh_frame_offset(), cie_size_); |
| 214 |
| 215 WritePaddingTo8ByteAlignment(); |
| 216 |
| 217 // Write the size of the FDE now that we know it. |
| 218 // The encoded size does not include the size field itself. |
| 219 int fde_size = eh_frame_offset() - fde_offset() - kInt32Size; |
| 220 PatchInt32(fde_offset(), fde_size); |
| 221 |
| 222 // Write the size and offset to procedure. |
| 223 PatchInt32(procedure_address_offset(), |
| 224 -(RoundUp(code_size, 8) + procedure_address_offset())); |
| 225 PatchInt32(procedure_size_offset(), code_size); |
| 226 |
| 227 // Terminate the .eh_frame. |
| 228 static const byte kTerminator[kEhFrameTerminatorSize] = {0}; |
| 229 WriteBytes(&kTerminator[0], kEhFrameTerminatorSize); |
| 230 |
| 231 // Write .eh_frame_hdr |
| 232 EhFrameHdr eh_frame_hdr(code_size, eh_frame_offset(), cie_size_); |
| 233 WriteBytes(reinterpret_cast<const byte*>(&eh_frame_hdr), |
| 234 EhFrameHdr::kRecordSize); |
| 235 |
| 236 eh_frame_finalised_ = true; |
| 237 } |
| 238 |
| 239 void EhFrameWriter::GetEhFrame(CodeDesc* desc) { |
| 240 DCHECK(eh_frame_finalised_); |
| 241 desc->unwinding_info_size = static_cast<int>(eh_frame_buffer_.size()); |
| 242 desc->unwinding_info = eh_frame_buffer_.data(); |
| 243 } |
| 244 |
| 245 void EhFrameWriter::WriteULEB128(uint32_t value) { |
| 246 do { |
| 247 byte chunk = value & 0x7f; |
| 248 value >>= 7; |
| 249 if (value != 0) chunk |= 0x80; |
| 250 eh_frame_buffer_.push_back(chunk); |
| 251 } while (value != 0); |
| 252 } |
| 253 |
| 254 void EhFrameWriter::WriteSLEB128(int32_t value) { |
| 255 static const int kSignBitMask = 0x40; |
| 256 bool done; |
| 257 do { |
| 258 byte chunk = value & 0x7f; |
| 259 value >>= 7; |
| 260 done = ((value == 0) && ((chunk & kSignBitMask) == 0)) || |
| 261 ((value == -1) && ((chunk & kSignBitMask) != 0)); |
| 262 if (!done) chunk |= 0x80; |
| 263 eh_frame_buffer_.push_back(chunk); |
| 264 } while (!done); |
| 265 } |
| 266 |
| 267 EhFrameIterator::EhFrameIterator(EhFrameWriter* writer) { |
| 268 CodeDesc desc; |
| 269 writer->GetEhFrame(&desc); |
| 270 start_ = desc.unwinding_info; |
| 271 end_ = start_ + desc.unwinding_info_size; |
| 272 next_ = start_; |
| 273 } |
| 274 |
| 275 uint32_t EhFrameIterator::GetNextULEB128() { |
| 276 int size = 0; |
| 277 uint32_t result = DecodeULEB128(next_, &size); |
| 278 DCHECK_LE(next_ + size, end_); |
| 279 next_ += size; |
| 280 return result; |
| 281 } |
| 282 |
| 283 int32_t EhFrameIterator::GetNextSLEB128() { |
| 284 int size = 0; |
| 285 int32_t result = DecodeSLEB128(next_, &size); |
| 286 DCHECK_LE(next_ + size, end_); |
| 287 next_ += size; |
| 288 return result; |
| 289 } |
| 290 |
| 291 // static |
| 292 uint32_t EhFrameIterator::DecodeULEB128(const byte* encoded, |
| 293 int* encoded_size) { |
| 294 const byte* current = encoded; |
| 295 uint32_t result = 0; |
| 296 int shift = 0; |
| 297 |
| 298 do { |
| 299 DCHECK_LT(shift, 8 * static_cast<int>(sizeof(result))); |
| 300 result |= (*current & 0x7f) << shift; |
| 301 shift += 7; |
| 302 } while (*current++ >= 128); |
| 303 |
| 304 DCHECK_NOT_NULL(encoded_size); |
| 305 *encoded_size = static_cast<int>(current - encoded); |
| 306 |
| 307 return result; |
| 308 } |
| 309 |
| 310 // static |
| 311 int32_t EhFrameIterator::DecodeSLEB128(const byte* encoded, int* encoded_size) { |
| 312 static const byte kSignBitMask = 0x40; |
| 313 |
| 314 const byte* current = encoded; |
| 315 int32_t result = 0; |
| 316 int shift = 0; |
| 317 byte chunk; |
| 318 |
| 319 do { |
| 320 chunk = *current++; |
| 321 DCHECK_LT(shift, 8 * static_cast<int>(sizeof(result))); |
| 322 result |= (chunk & 0x7f) << shift; |
| 323 shift += 7; |
| 324 } while (chunk >= 128); |
| 325 |
| 326 // Sign extend the result if the last chunk has the sign bit set. |
| 327 if (chunk & kSignBitMask) result |= (~0ull) << shift; |
| 328 |
| 329 DCHECK_NOT_NULL(encoded_size); |
| 330 *encoded_size = static_cast<int>(current - encoded); |
| 331 |
| 332 return result; |
| 333 } |
| 334 |
| 335 #ifdef ENABLE_DISASSEMBLER |
| 336 |
| 337 namespace { |
| 338 |
| 339 class StreamModifiersScope final { |
| 340 public: |
| 341 explicit StreamModifiersScope(std::ostream* stream) |
| 342 : stream_(stream), flags_(stream->flags()) {} |
| 343 ~StreamModifiersScope() { stream_->flags(flags_); } |
| 344 |
| 345 private: |
| 346 std::ostream* stream_; |
| 347 std::ios::fmtflags flags_; |
| 348 }; |
| 349 |
| 350 } // namespace |
| 351 |
| 352 // static |
| 353 void EhFrameDisassembler::DumpDWARFDirectives(std::ostream& stream, // NOLINT |
| 354 const byte* start, |
| 355 const byte* end) { |
| 356 StreamModifiersScope modifiers_scope(&stream); |
| 357 |
| 358 EhFrameIterator eh_frame_iterator(start, end); |
| 359 uint32_t offset_in_procedure = 0; |
| 360 |
| 361 while (!eh_frame_iterator.ReachedEnd()) { |
| 362 stream << eh_frame_iterator.current_address() << " "; |
| 363 |
| 364 byte bytecode = eh_frame_iterator.GetNextByte(); |
| 365 |
| 366 if (((bytecode >> EhFrameWriter::kLocationMaskSize) & 0xff) == |
| 367 EhFrameWriter::kLocationTag) { |
| 368 int value = bytecode & EhFrameWriter::kLocationMask; |
| 369 offset_in_procedure += value; |
| 370 stream << "| pc_offset=" << std::dec << offset_in_procedure |
| 371 << " (delta=0x" << std::hex << value << ")\n"; |
| 372 continue; |
| 373 } |
| 374 |
| 375 if (((bytecode >> EhFrameWriter::kSavedRegisterMaskSize) & 0xff) == |
| 376 EhFrameWriter::kSavedRegisterTag) { |
| 377 int decoded_offset = static_cast<int>(eh_frame_iterator.GetNextULEB128()); |
| 378 stream << "| " << DwarfRegisterCodeToString(bytecode & |
| 379 EhFrameWriter::kLocationMask) |
| 380 << " saved at base" << std::showpos << std::dec |
| 381 << decoded_offset * EhFrameWriter::kDataAlignmentFactor << '\n'; |
| 382 continue; |
| 383 } |
| 384 |
| 385 if (((bytecode >> EhFrameWriter::kFollowInitialRuleMaskSize) & 0xff) == |
| 386 EhFrameWriter::kFollowInitialRuleTag) { |
| 387 stream << "| " << DwarfRegisterCodeToString(bytecode & |
| 388 EhFrameWriter::kLocationMask) |
| 389 << " follows initial rule\n"; |
| 390 continue; |
| 391 } |
| 392 |
| 393 switch (static_cast<EhFrameWriter::DwarfOpcodes>(bytecode)) { |
| 394 case EhFrameWriter::DwarfOpcodes::kOffsetExtendedSf: { |
| 395 stream << "| " |
| 396 << DwarfRegisterCodeToString(eh_frame_iterator.GetNextULEB128()); |
| 397 int32_t decoded_offset = eh_frame_iterator.GetNextSLEB128(); |
| 398 stream << " saved at base" << std::showpos << std::dec |
| 399 << decoded_offset * EhFrameWriter::kDataAlignmentFactor << '\n'; |
| 400 } |
| 401 case EhFrameWriter::DwarfOpcodes::kAdvanceLoc1: { |
| 402 unsigned value = eh_frame_iterator.GetNextByte(); |
| 403 offset_in_procedure += value; |
| 404 stream << "| pc_offset=" << std::dec << offset_in_procedure |
| 405 << " (delta=0x" << std::hex << value << ")\n"; |
| 406 break; |
| 407 } |
| 408 case EhFrameWriter::DwarfOpcodes::kAdvanceLoc2: { |
| 409 uint16_t value = eh_frame_iterator.GetNextUInt16(); |
| 410 offset_in_procedure += value; |
| 411 stream << "| pc_offset=" << std::dec << offset_in_procedure |
| 412 << " (delta=0x" << std::hex << value << ")\n"; |
| 413 break; |
| 414 } |
| 415 case EhFrameWriter::DwarfOpcodes::kAdvanceLoc4: { |
| 416 uint32_t value = eh_frame_iterator.GetNextUInt32(); |
| 417 offset_in_procedure += value; |
| 418 stream << "| pc_offset=" << std::dec << offset_in_procedure |
| 419 << " (delta=0x" << std::hex << value << ")\n"; |
| 420 break; |
| 421 } |
| 422 case EhFrameWriter::DwarfOpcodes::kDefCfa: { |
| 423 int base_register = eh_frame_iterator.GetNextULEB128(); |
| 424 int base_offset = eh_frame_iterator.GetNextULEB128(); |
| 425 stream << "| base_register=" << DwarfRegisterCodeToString(base_register) |
| 426 << ", base_offset=0x" << std::hex << base_offset << '\n'; |
| 427 break; |
| 428 } |
| 429 case EhFrameWriter::DwarfOpcodes::kDefCfaOffset: { |
| 430 stream << "| base_offset=0x" << std::hex |
| 431 << eh_frame_iterator.GetNextULEB128() << '\n'; |
| 432 break; |
| 433 } |
| 434 case EhFrameWriter::DwarfOpcodes::kDefCfaRegister: { |
| 435 stream << "| base_register=" |
| 436 << DwarfRegisterCodeToString(eh_frame_iterator.GetNextULEB128()) |
| 437 << '\n'; |
| 438 break; |
| 439 } |
| 440 case EhFrameWriter::DwarfOpcodes::kSameValue: { |
| 441 stream << "| " |
| 442 << DwarfRegisterCodeToString(eh_frame_iterator.GetNextULEB128()) |
| 443 << " to initial value\n"; |
| 444 break; |
| 445 } |
| 446 case EhFrameWriter::DwarfOpcodes::kNop: |
| 447 stream << "| nop\n"; |
| 448 break; |
| 449 default: |
| 450 UNREACHABLE(); |
| 451 return; |
| 452 } |
| 453 } |
| 454 } |
| 455 |
| 456 // static |
| 457 void EhFrameDisassembler::DisassembleToStream(std::ostream& stream) { // NOLINT |
| 458 // The encoded CIE size does not include the size field itself. |
| 459 const int cie_size = ReadUnalignedUInt32(start_) + kInt32Size; |
| 460 const int fde_offset = cie_size; |
| 461 |
| 462 const byte* cie_directives_start = |
| 463 start_ + EhFrameWriter::kInitialStateOffsetInCIE; |
| 464 const byte* cie_directives_end = start_ + cie_size; |
| 465 DCHECK_LE(cie_directives_start, cie_directives_end); |
| 466 |
| 467 stream << reinterpret_cast<const void*>(start_) << " .eh_frame: CIE\n"; |
| 468 DumpDWARFDirectives(stream, cie_directives_start, cie_directives_end); |
| 469 |
| 470 const byte* procedure_offset_address = |
| 471 start_ + fde_offset + EhFrameWriter::kProcedureAddressOffsetInFde; |
| 472 int32_t procedure_offset = |
| 473 ReadUnalignedValue<int32_t>(procedure_offset_address); |
| 474 |
| 475 const byte* procedure_size_address = |
| 476 start_ + fde_offset + EhFrameWriter::kProcedureSizeOffsetInFde; |
| 477 uint32_t procedure_size = ReadUnalignedUInt32(procedure_size_address); |
| 478 |
| 479 const byte* fde_start = start_ + fde_offset; |
| 480 stream << reinterpret_cast<const void*>(fde_start) << " .eh_frame: FDE\n" |
| 481 << reinterpret_cast<const void*>(procedure_offset_address) |
| 482 << " | procedure offset=" << procedure_offset << '\n' |
| 483 << reinterpret_cast<const void*>(procedure_size_address) |
| 484 << " | procedure size=" << procedure_size << '\n'; |
| 485 |
| 486 const int fde_directives_offset = fde_offset + 4 * kInt32Size + 1; |
| 487 |
| 488 const byte* fde_directives_start = start_ + fde_directives_offset; |
| 489 const byte* fde_directives_end = |
| 490 end_ - EhFrameHdr::kRecordSize - EhFrameWriter::kEhFrameTerminatorSize; |
| 491 DCHECK_LE(fde_directives_start, fde_directives_end); |
| 492 |
| 493 DumpDWARFDirectives(stream, fde_directives_start, fde_directives_end); |
| 494 |
| 495 const byte* fde_terminator_start = fde_directives_end; |
| 496 stream << reinterpret_cast<const void*>(fde_terminator_start) |
| 497 << " .eh_frame: terminator\n"; |
| 498 |
| 499 const byte* eh_frame_hdr_start = |
| 500 fde_terminator_start + EhFrameWriter::kEhFrameTerminatorSize; |
| 501 stream << reinterpret_cast<const void*>(eh_frame_hdr_start) |
| 502 << " .eh_frame_hdr: placeholder\n"; |
| 503 } |
| 504 |
| 505 #endif |
21 | 506 |
22 // | 507 // |
23 // In order to calculate offsets in the .eh_frame_hdr, we must know the layout | 508 // In order to calculate offsets in the .eh_frame_hdr, we must know the layout |
24 // of the DSO generated by perf inject, which is assumed to be the following: | 509 // of the DSO generated by perf inject, which is assumed to be the following: |
25 // | 510 // |
26 // | ... | | | 511 // | ... | | |
27 // +---------------+ <-- (F) --- | Larger offsets in file | 512 // +---------------+ <-- (F) --- | Larger offsets in file |
28 // | | ^ | | 513 // | | ^ | |
29 // | Instructions | | .text v | 514 // | Instructions | | .text v |
30 // | | v | 515 // | | v |
(...skipping 13 matching lines...) Expand all Loading... |
44 // | version | ^ | 529 // | version | ^ |
45 // +---------------+ | | 530 // +---------------+ | |
46 // | encoding | | | 531 // | encoding | | |
47 // | specifiers | | | 532 // | specifiers | | |
48 // +---------------+ <---(A) | .eh_frame_hdr | 533 // +---------------+ <---(A) | .eh_frame_hdr |
49 // | offset to | | | 534 // | offset to | | |
50 // | .eh_frame | | | 535 // | .eh_frame | | |
51 // +---------------+ | | 536 // +---------------+ | |
52 // | ... | ... | 537 // | ... | ... |
53 // | 538 // |
54 // (F) is aligned at a 16-byte boundary. | 539 // (F) is aligned to a 16-byte boundary. |
55 // (D) is aligned at a 8-byte boundary. | 540 // (D) is aligned to a 8-byte boundary. |
56 // (B) is aligned at a 4-byte boundary. | 541 // (B) is aligned to a 4-byte boundary. |
57 // (E), (C) and (A) have no alignment requirements. | 542 // (C) is aligned to an addressing unit size boundary. |
| 543 // (E) and (A) have no alignment requirements. |
58 // | 544 // |
59 // The distance between (A) and (B) is 4 bytes. | 545 // The distance between (A) and (B) is 4 bytes. |
60 // | 546 // |
61 // The size of the .eh_frame is required to be a multiple of the pointer size, | 547 // The size of the FDE is required to be a multiple of the pointer size, which |
62 // which means that (B) will be naturally aligned to a 4-byte boundary on all | 548 // means that (B) will be naturally aligned to a 4-byte boundary on all the |
63 // the architectures we support. | 549 // architectures we support. |
64 // | 550 // |
65 // Because (E) has no alignment requirements, there is padding between (E) and | 551 // Because (E) has no alignment requirements, there is padding between (E) and |
66 // (D). (F) is aligned at a 16-byte boundary, thus to a 8-byte one as well. | 552 // (D). (F) is aligned at a 16-byte boundary, thus to a 8-byte one as well. |
67 // | 553 // |
68 EhFrameHdr::EhFrameHdr(Code* code) { | 554 EhFrameHdr::EhFrameHdr(int code_size, int eh_frame_size, int cie_size) { |
69 int code_size = code->is_crankshafted() ? code->safepoint_table_offset() | 555 static const int kFdeVersionSize = 1; |
70 : code->instruction_size(); | 556 static const int kFdeEncodingSpecifiersSize = 3; |
71 version_ = 1; | |
72 eh_frame_ptr_encoding_ = DW_EH_PE_sdata4 | DW_EH_PE_pcrel; | |
73 lut_size_encoding_ = DW_EH_PE_udata4; | |
74 lut_entries_encoding_ = DW_EH_PE_sdata4 | DW_EH_PE_datarel; | |
75 | 557 |
76 // .eh_frame pointer and LUT | 558 version_ = kEhFrameHdrVersion; |
77 if (code->has_unwinding_info()) { | |
78 DCHECK_GE(code->unwinding_info_size(), EhFrameHdr::kRecordSize); | |
79 int eh_frame_size = code->unwinding_info_size() - EhFrameHdr::kRecordSize; | |
80 | 559 |
81 offset_to_eh_frame_ = | 560 eh_frame_ptr_encoding_ = EhFrameWriter::kSData4 | EhFrameWriter::kPcRel; |
82 -(eh_frame_size + kVersionSize + kEncodingSpecifiersSize); // A -> D | 561 lut_size_encoding_ = EhFrameWriter::kUData4; |
83 lut_entries_number_ = 1; | 562 lut_entries_encoding_ = EhFrameWriter::kSData4 | EhFrameWriter::kDataRel; |
84 offset_to_procedure_ = -(RoundUp(code_size, 8) + eh_frame_size); // B -> F | 563 offset_to_eh_frame_ = -(eh_frame_size + kFdeVersionSize + |
85 offset_to_fde_ = -(eh_frame_size - kCIESize); // B -> C | 564 kFdeEncodingSpecifiersSize); // A -> D |
86 } else { | 565 lut_entries_number_ = 1; |
87 // Create a dummy table | 566 offset_to_procedure_ = -(RoundUp(code_size, 8) + eh_frame_size); // B -> F |
88 offset_to_eh_frame_ = 0; | 567 offset_to_fde_ = -(eh_frame_size - cie_size); // B -> C |
89 lut_entries_number_ = 0; | 568 } |
90 offset_to_procedure_ = 0; | 569 |
91 offset_to_fde_ = 0; | 570 // static |
92 } | 571 EhFrameHdr EhFrameHdr::CreateEmptyHeader() { |
| 572 EhFrameHdr dummy_frame; |
| 573 dummy_frame.version_ = kEhFrameHdrVersion; |
| 574 dummy_frame.eh_frame_ptr_encoding_ = |
| 575 EhFrameWriter::kSData4 | EhFrameWriter::kPcRel; |
| 576 dummy_frame.lut_size_encoding_ = EhFrameWriter::kUData4; |
| 577 dummy_frame.lut_entries_encoding_ = |
| 578 EhFrameWriter::kSData4 | EhFrameWriter::kDataRel; |
| 579 dummy_frame.offset_to_eh_frame_ = 0; |
| 580 dummy_frame.lut_entries_number_ = 0; |
| 581 dummy_frame.offset_to_procedure_ = 0; |
| 582 dummy_frame.offset_to_fde_ = 0; |
| 583 return dummy_frame; |
93 } | 584 } |
94 | 585 |
95 } // namespace internal | 586 } // namespace internal |
96 } // namespace v8 | 587 } // namespace v8 |
OLD | NEW |