diff --git a/src/code-comments.cc b/src/code-comments.cc index 6e64eb7fa1..12b9f7c3a8 100644 --- a/src/code-comments.cc +++ b/src/code-comments.cc @@ -45,11 +45,11 @@ const char* CodeCommentsIterator::GetComment() const { } uint32_t CodeCommentsIterator::GetCommentSize() const { - return *reinterpret_cast(current_entry_ + kOffsetToCommentSize); + return ReadUnalignedValue(current_entry_ + kOffsetToCommentSize); } uint32_t CodeCommentsIterator::GetPCOffset() const { - return *reinterpret_cast(current_entry_ + kOffsetToPCOffset); + return ReadUnalignedValue(current_entry_ + kOffsetToPCOffset); } void CodeCommentsIterator::Next() { diff --git a/src/deoptimizer.cc b/src/deoptimizer.cc index 2f34733b61..98f99a1b24 100644 --- a/src/deoptimizer.cc +++ b/src/deoptimizer.cc @@ -2642,7 +2642,11 @@ int TranslatedValue::GetChildrenCount() const { } uint64_t TranslatedState::GetUInt64Slot(Address fp, int slot_offset) { +#if V8_TARGET_ARCH_32_BIT + return ReadUnalignedValue(fp + slot_offset); +#else return Memory(fp + slot_offset); +#endif } uint32_t TranslatedState::GetUInt32Slot(Address fp, int slot_offset) { diff --git a/src/ia32/assembler-ia32-inl.h b/src/ia32/assembler-ia32-inl.h index dabeabb41b..241bae3efb 100644 --- a/src/ia32/assembler-ia32-inl.h +++ b/src/ia32/assembler-ia32-inl.h @@ -91,19 +91,19 @@ int RelocInfo::target_address_size() { HeapObject RelocInfo::target_object() { DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); - return HeapObject::cast(Object(Memory
(pc_))); + return HeapObject::cast(Object(ReadUnalignedValue
(pc_))); } Handle RelocInfo::target_object_handle(Assembler* origin) { DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); - return Handle::cast(Memory>(pc_)); + return Handle::cast(ReadUnalignedValue>(pc_)); } void RelocInfo::set_target_object(Heap* heap, HeapObject target, WriteBarrierMode write_barrier_mode, ICacheFlushMode icache_flush_mode) { DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); - Memory
(pc_) = target->ptr(); + WriteUnalignedValue(pc_, target->ptr()); if (icache_flush_mode != SKIP_ICACHE_FLUSH) { Assembler::FlushICache(pc_, sizeof(Address)); } @@ -114,13 +114,13 @@ void RelocInfo::set_target_object(Heap* heap, HeapObject target, Address RelocInfo::target_external_reference() { DCHECK(rmode_ == RelocInfo::EXTERNAL_REFERENCE); - return Memory
(pc_); + return ReadUnalignedValue
(pc_); } void RelocInfo::set_target_external_reference( Address target, ICacheFlushMode icache_flush_mode) { DCHECK(rmode_ == RelocInfo::EXTERNAL_REFERENCE); - Memory
(pc_) = target; + WriteUnalignedValue(pc_, target); if (icache_flush_mode != SKIP_ICACHE_FLUSH) { Assembler::FlushICache(pc_, sizeof(Address)); } @@ -128,7 +128,7 @@ void RelocInfo::set_target_external_reference( Address RelocInfo::target_internal_reference() { DCHECK(rmode_ == INTERNAL_REFERENCE); - return Memory
(pc_); + return ReadUnalignedValue
(pc_); } @@ -139,7 +139,7 @@ Address RelocInfo::target_internal_reference_address() { Address RelocInfo::target_runtime_entry(Assembler* origin) { DCHECK(IsRuntimeEntry(rmode_)); - return static_cast
(*reinterpret_cast(pc_)); + return ReadUnalignedValue
(pc_); } void RelocInfo::set_target_runtime_entry(Address target, @@ -159,7 +159,7 @@ Address RelocInfo::target_off_heap_target() { void RelocInfo::WipeOut() { if (IsEmbeddedObject(rmode_) || IsExternalReference(rmode_) || IsInternalReference(rmode_)) { - Memory
(pc_) = kNullAddress; + WriteUnalignedValue(pc_, kNullAddress); } else if (IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) || IsOffHeapTarget(rmode_)) { // Effectively write zero into the relocation. @@ -190,13 +190,13 @@ void RelocInfo::Visit(ObjectVisitor* visitor) { } void Assembler::emit(uint32_t x) { - *reinterpret_cast(pc_) = x; + WriteUnalignedValue(reinterpret_cast
(pc_), x); pc_ += sizeof(uint32_t); } void Assembler::emit_q(uint64_t x) { - *reinterpret_cast(pc_) = x; + WriteUnalignedValue(reinterpret_cast
(pc_), x); pc_ += sizeof(uint64_t); } @@ -251,19 +251,19 @@ void Assembler::emit_b(Immediate x) { void Assembler::emit_w(const Immediate& x) { DCHECK(RelocInfo::IsNone(x.rmode_)); uint16_t value = static_cast(x.immediate()); - reinterpret_cast(pc_)[0] = value; + WriteUnalignedValue(reinterpret_cast
(pc_), value); pc_ += sizeof(uint16_t); } Address Assembler::target_address_at(Address pc, Address constant_pool) { - return pc + sizeof(int32_t) + *reinterpret_cast(pc); + return pc + sizeof(int32_t) + ReadUnalignedValue(pc); } void Assembler::set_target_address_at(Address pc, Address constant_pool, Address target, ICacheFlushMode icache_flush_mode) { - *reinterpret_cast(pc) = target - (pc + sizeof(int32_t)); + WriteUnalignedValue(pc, target - (pc + sizeof(int32_t))); if (icache_flush_mode != SKIP_ICACHE_FLUSH) { Assembler::FlushICache(pc, sizeof(int32_t)); } @@ -315,7 +315,7 @@ void Assembler::emit_near_disp(Label* L) { void Assembler::deserialization_set_target_internal_reference_at( Address pc, Address target, RelocInfo::Mode mode) { - Memory
(pc) = target; + WriteUnalignedValue(pc, target); } diff --git a/src/ia32/assembler-ia32.cc b/src/ia32/assembler-ia32.cc index b0c359034a..43fe74a280 100644 --- a/src/ia32/assembler-ia32.cc +++ b/src/ia32/assembler-ia32.cc @@ -207,7 +207,7 @@ bool RelocInfo::IsInConstantPool() { uint32_t RelocInfo::wasm_call_tag() const { DCHECK(rmode_ == WASM_CALL || rmode_ == WASM_STUB_CALL); - return Memory(pc_); + return ReadUnalignedValue(pc_); } // ----------------------------------------------------------------------------- @@ -297,7 +297,7 @@ void Assembler::AllocateAndInstallRequestedHeapObjects(Isolate* isolate) { } } Address pc = reinterpret_cast
(buffer_start_) + request.offset(); - Memory>(pc) = object; + WriteUnalignedValue(pc, object); } } @@ -3199,8 +3199,8 @@ void Assembler::GrowBuffer() { // Relocate internal references. for (auto pos : internal_reference_positions_) { - int32_t* p = reinterpret_cast(buffer_start_ + pos); - *p += pc_delta; + Address p = reinterpret_cast
(buffer_start_ + pos); + WriteUnalignedValue(p, ReadUnalignedValue(p) + pc_delta); } // Relocate pc-relative references. @@ -3277,7 +3277,7 @@ void Assembler::emit_operand(int code, Operand adr) { pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 RecordRelocInfo(adr.rmode_); if (adr.rmode_ == RelocInfo::INTERNAL_REFERENCE) { // Fixup for labels - emit_label(*reinterpret_cast(pc_)); + emit_label(ReadUnalignedValue(reinterpret_cast
(pc_))); } else { pc_ += sizeof(int32_t); } diff --git a/src/ia32/assembler-ia32.h b/src/ia32/assembler-ia32.h index 96bf2c7eeb..5d460c360c 100644 --- a/src/ia32/assembler-ia32.h +++ b/src/ia32/assembler-ia32.h @@ -275,8 +275,8 @@ class V8_EXPORT_PRIVATE Operand { inline void set_disp8(int8_t disp); inline void set_dispr(int32_t disp, RelocInfo::Mode rmode) { DCHECK(len_ == 1 || len_ == 2); - int32_t* p = reinterpret_cast(&buf_[len_]); - *p = disp; + Address p = reinterpret_cast
(&buf_[len_]); + WriteUnalignedValue(p, disp); len_ += sizeof(int32_t); rmode_ = rmode; } @@ -1650,14 +1650,16 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase { void emit_sse_operand(Register dst, XMMRegister src); void emit_sse_operand(XMMRegister dst, Register src); - byte* addr_at(int pos) { return buffer_start_ + pos; } + Address addr_at(int pos) { + return reinterpret_cast
(buffer_start_ + pos); + } private: uint32_t long_at(int pos) { - return *reinterpret_cast(addr_at(pos)); + return ReadUnalignedValue(addr_at(pos)); } void long_at_put(int pos, uint32_t x) { - *reinterpret_cast(addr_at(pos)) = x; + WriteUnalignedValue(addr_at(pos), x); } // code emission diff --git a/src/v8memory.h b/src/v8memory.h index bf62e3b9e6..e927962296 100644 --- a/src/v8memory.h +++ b/src/v8memory.h @@ -16,6 +16,8 @@ namespace internal { // proposal (http://wg21.link/p0593r2) to make it defined behaviour though. template T& Memory(Address addr) { + // {addr} must be aligned. + DCHECK_EQ(0, addr & (alignof(T) - 1)); return *reinterpret_cast(addr); } template @@ -26,23 +28,15 @@ T& Memory(byte* addr) { template static inline V ReadUnalignedValue(Address p) { ASSERT_TRIVIALLY_COPYABLE(V); -#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM) - return *reinterpret_cast(p); -#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM V r; - memmove(&r, reinterpret_cast(p), sizeof(V)); + memcpy(&r, reinterpret_cast(p), sizeof(V)); return r; -#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM } template static inline void WriteUnalignedValue(Address p, V value) { ASSERT_TRIVIALLY_COPYABLE(V); -#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM) - *(reinterpret_cast(p)) = value; -#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM - memmove(reinterpret_cast(p), &value, sizeof(V)); -#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM + memcpy(reinterpret_cast(p), &value, sizeof(V)); } static inline double ReadFloatValue(Address p) { diff --git a/src/wasm/wasm-serialization.cc b/src/wasm/wasm-serialization.cc index a31e414687..565c0f319c 100644 --- a/src/wasm/wasm-serialization.cc +++ b/src/wasm/wasm-serialization.cc @@ -135,12 +135,12 @@ void WriteVersion(Writer* writer) { void SetWasmCalleeTag(RelocInfo* rinfo, uint32_t tag) { #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 DCHECK(rinfo->HasTargetAddressAddress()); - *(reinterpret_cast(rinfo->target_address_address())) = tag; + WriteUnalignedValue(rinfo->target_address_address(), tag); #elif V8_TARGET_ARCH_ARM64 Instruction* instr = reinterpret_cast(rinfo->pc()); if (instr->IsLdrLiteralX()) { - Memory
(rinfo->constant_pool_entry_address()) = - static_cast
(tag); + WriteUnalignedValue(rinfo->constant_pool_entry_address(), + static_cast
(tag)); } else { DCHECK(instr->IsBranchAndLink() || instr->IsUnconditionalBranch()); instr->SetBranchImmTarget( @@ -160,12 +160,11 @@ void SetWasmCalleeTag(RelocInfo* rinfo, uint32_t tag) { uint32_t GetWasmCalleeTag(RelocInfo* rinfo) { #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 - return *(reinterpret_cast(rinfo->target_address_address())); + return ReadUnalignedValue(rinfo->target_address_address()); #elif V8_TARGET_ARCH_ARM64 Instruction* instr = reinterpret_cast(rinfo->pc()); if (instr->IsLdrLiteralX()) { - return static_cast( - Memory
(rinfo->constant_pool_entry_address())); + return ReadUnalignedValue(rinfo->constant_pool_entry_address()); } else { DCHECK(instr->IsBranchAndLink() || instr->IsUnconditionalBranch()); return static_cast(instr->ImmPCOffset() / kInstrSize); diff --git a/src/x64/assembler-x64-inl.h b/src/x64/assembler-x64-inl.h index 0dcd84da79..54d8603d27 100644 --- a/src/x64/assembler-x64-inl.h +++ b/src/x64/assembler-x64-inl.h @@ -24,12 +24,12 @@ bool CpuFeatures::SupportsWasmSimd128() { return IsSupported(SSE4_1); } void Assembler::emitl(uint32_t x) { - Memory(pc_) = x; + WriteUnalignedValue(reinterpret_cast
(pc_), x); pc_ += sizeof(uint32_t); } void Assembler::emitp(Address x, RelocInfo::Mode rmode) { - Memory(pc_) = x; + WriteUnalignedValue(reinterpret_cast
(pc_), x); if (!RelocInfo::IsNone(rmode)) { RecordRelocInfo(rmode, x); } @@ -38,13 +38,13 @@ void Assembler::emitp(Address x, RelocInfo::Mode rmode) { void Assembler::emitq(uint64_t x) { - Memory(pc_) = x; + WriteUnalignedValue(reinterpret_cast
(pc_), x); pc_ += sizeof(uint64_t); } void Assembler::emitw(uint16_t x) { - Memory(pc_) = x; + WriteUnalignedValue(reinterpret_cast
(pc_), x); pc_ += sizeof(uint16_t); } @@ -233,13 +233,13 @@ void Assembler::emit_vex_prefix(Register reg, Register vreg, Operand rm, Address Assembler::target_address_at(Address pc, Address constant_pool) { - return Memory(pc) + pc + 4; + return ReadUnalignedValue(pc) + pc + 4; } void Assembler::set_target_address_at(Address pc, Address constant_pool, Address target, ICacheFlushMode icache_flush_mode) { - Memory(pc) = static_cast(target - pc - 4); + WriteUnalignedValue(pc, static_cast(target - pc - 4)); if (icache_flush_mode != SKIP_ICACHE_FLUSH) { Assembler::FlushICache(pc, sizeof(int32_t)); } @@ -247,7 +247,7 @@ void Assembler::set_target_address_at(Address pc, Address constant_pool, void Assembler::deserialization_set_target_internal_reference_at( Address pc, Address target, RelocInfo::Mode mode) { - Memory
(pc) = target; + WriteUnalignedValue(pc, target); } @@ -268,11 +268,11 @@ int Assembler::deserialization_special_target_size( } Handle Assembler::code_target_object_handle_at(Address pc) { - return GetCodeTarget(Memory(pc)); + return GetCodeTarget(ReadUnalignedValue(pc)); } Address Assembler::runtime_entry_at(Address pc) { - return Memory(pc) + options().code_range_start; + return ReadUnalignedValue(pc) + options().code_range_start; } // ----------------------------------------------------------------------------- @@ -281,10 +281,11 @@ Address Assembler::runtime_entry_at(Address pc) { // The modes possibly affected by apply must be in kApplyMask. void RelocInfo::apply(intptr_t delta) { if (IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)) { - Memory(pc_) -= static_cast(delta); + WriteUnalignedValue( + pc_, ReadUnalignedValue(pc_) - static_cast(delta)); } else if (IsInternalReference(rmode_)) { - // absolute code pointer inside code object moves with the code object. - Memory
(pc_) += delta; + // Absolute code pointer inside code object moves with the code object. + WriteUnalignedValue(pc_, ReadUnalignedValue
(pc_) + delta); } } @@ -317,13 +318,13 @@ int RelocInfo::target_address_size() { HeapObject RelocInfo::target_object() { DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); - return HeapObject::cast(Object(Memory
(pc_))); + return HeapObject::cast(Object(ReadUnalignedValue
(pc_))); } Handle RelocInfo::target_object_handle(Assembler* origin) { DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); if (rmode_ == EMBEDDED_OBJECT) { - return Handle::cast(Memory>(pc_)); + return Handle::cast(ReadUnalignedValue>(pc_)); } else { return origin->code_target_object_handle_at(pc_); } @@ -331,13 +332,13 @@ Handle RelocInfo::target_object_handle(Assembler* origin) { Address RelocInfo::target_external_reference() { DCHECK(rmode_ == RelocInfo::EXTERNAL_REFERENCE); - return Memory
(pc_); + return ReadUnalignedValue
(pc_); } void RelocInfo::set_target_external_reference( Address target, ICacheFlushMode icache_flush_mode) { DCHECK(rmode_ == RelocInfo::EXTERNAL_REFERENCE); - Memory
(pc_) = target; + WriteUnalignedValue(pc_, target); if (icache_flush_mode != SKIP_ICACHE_FLUSH) { Assembler::FlushICache(pc_, sizeof(Address)); } @@ -345,7 +346,7 @@ void RelocInfo::set_target_external_reference( Address RelocInfo::target_internal_reference() { DCHECK(rmode_ == INTERNAL_REFERENCE); - return Memory
(pc_); + return ReadUnalignedValue
(pc_); } @@ -358,7 +359,7 @@ void RelocInfo::set_target_object(Heap* heap, HeapObject target, WriteBarrierMode write_barrier_mode, ICacheFlushMode icache_flush_mode) { DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); - Memory
(pc_) = target->ptr(); + WriteUnalignedValue(pc_, target->ptr()); if (icache_flush_mode != SKIP_ICACHE_FLUSH) { Assembler::FlushICache(pc_, sizeof(Address)); } @@ -383,13 +384,13 @@ void RelocInfo::set_target_runtime_entry(Address target, Address RelocInfo::target_off_heap_target() { DCHECK(IsOffHeapTarget(rmode_)); - return Memory
(pc_); + return ReadUnalignedValue
(pc_); } void RelocInfo::WipeOut() { if (IsEmbeddedObject(rmode_) || IsExternalReference(rmode_) || IsInternalReference(rmode_) || IsOffHeapTarget(rmode_)) { - Memory
(pc_) = kNullAddress; + WriteUnalignedValue(pc_, kNullAddress); } else if (IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)) { // Effectively write zero into the relocation. Assembler::set_target_address_at(pc_, constant_pool_, diff --git a/src/x64/assembler-x64.cc b/src/x64/assembler-x64.cc index 5cf944a697..163862eecd 100644 --- a/src/x64/assembler-x64.cc +++ b/src/x64/assembler-x64.cc @@ -126,7 +126,7 @@ void CpuFeatures::PrintFeatures() { uint32_t RelocInfo::wasm_call_tag() const { DCHECK(rmode_ == WASM_CALL || rmode_ == WASM_STUB_CALL); - return Memory(pc_); + return ReadUnalignedValue(pc_); } // ----------------------------------------------------------------------------- @@ -200,7 +200,8 @@ class OperandBuilder { int32_t disp_value = 0; if (mode == 0x80 || is_baseless) { // Mode 2 or mode 0 with rbp/r13 as base: Word displacement. - disp_value = *bit_cast(&operand.data().buf[disp_offset]); + disp_value = ReadUnalignedValue( + reinterpret_cast
(&operand.data().buf[disp_offset])); } else if (mode == 0x40) { // Mode 1: Byte displacement. disp_value = static_cast(operand.data().buf[disp_offset]); @@ -215,8 +216,8 @@ class OperandBuilder { // Need 32 bits of displacement, mode 2 or mode 1 with register rbp/r13. data_.buf[0] = (modrm & 0x3F) | (is_baseless ? 0x00 : 0x80); data_.len = disp_offset + 4; - Memory(reinterpret_cast
(&data_.buf[disp_offset])) = - disp_value; + WriteUnalignedValue(reinterpret_cast
(&data_.buf[disp_offset]), + disp_value); } else if (disp_value != 0 || (base_reg == 0x05)) { // Need 8 bits of displacement. data_.buf[0] = (modrm & 0x3F) | 0x40; // Mode 1. @@ -260,15 +261,15 @@ class OperandBuilder { void set_disp32(int disp) { DCHECK(data_.len == 1 || data_.len == 2); - int32_t* p = reinterpret_cast(&data_.buf[data_.len]); - *p = disp; + Address p = reinterpret_cast
(&data_.buf[data_.len]); + WriteUnalignedValue(p, disp); data_.len += sizeof(int32_t); } void set_disp64(int64_t disp) { DCHECK_EQ(1, data_.len); - int64_t* p = reinterpret_cast(&data_.buf[data_.len]); - *p = disp; + Address p = reinterpret_cast
(&data_.buf[data_.len]); + WriteUnalignedValue(p, disp); data_.len += sizeof(disp); } @@ -328,14 +329,14 @@ void Assembler::AllocateAndInstallRequestedHeapObjects(Isolate* isolate) { case HeapObjectRequest::kHeapNumber: { Handle object = isolate->factory()->NewHeapNumber(request.heap_number(), TENURED); - Memory>(pc) = object; + WriteUnalignedValue(pc, object); break; } case HeapObjectRequest::kStringConstant: { const StringConstantBase* str = request.string(); CHECK_NOT_NULL(str); Handle allocated = str->AllocateStringConstant(isolate); - Memory>(pc) = allocated; + WriteUnalignedValue(pc, allocated); break; } } @@ -372,11 +373,9 @@ bool ConstPool::TryRecordEntry(intptr_t data, RelocInfo::Mode mode) { return AddSharedEntry(raw_data, offset); } -bool ConstPool::IsMoveRipRelative(byte* instr) { - if ((*reinterpret_cast(instr) & kMoveRipRelativeMask) == - kMoveRipRelativeInstr) - return true; - return false; +bool ConstPool::IsMoveRipRelative(Address instr) { + return (ReadUnalignedValue(instr) & kMoveRipRelativeMask) == + kMoveRipRelativeInstr; } void ConstPool::Clear() { entries_.clear(); } @@ -397,13 +396,13 @@ void ConstPool::PatchEntries() { DCHECK_LT(constant_entry_offset, it->second); int32_t disp32 = constant_entry_offset - (it->second + kRipRelativeDispSize); - byte* disp_addr = assm_->addr_at(it->second); + Address disp_addr = assm_->addr_at(it->second); // Check if the instruction is actually a rip-relative move. DCHECK(IsMoveRipRelative(disp_addr - kMoveRipRelativeDispOffset)); // The displacement of the rip-relative move should be 0 before patching. - DCHECK(*reinterpret_cast(disp_addr) == 0); - *reinterpret_cast(disp_addr) = disp32; + DCHECK(ReadUnalignedValue(disp_addr) == 0); + WriteUnalignedValue(disp_addr, disp32); } } Clear(); @@ -518,7 +517,7 @@ void Assembler::bind_to(Label* L, int pos) { if (current >= 4 && long_at(current - 4) == 0) { // Absolute address. intptr_t imm64 = reinterpret_cast(buffer_start_ + pos); - *reinterpret_cast(addr_at(current - 4)) = imm64; + WriteUnalignedValue(addr_at(current - 4), imm64); internal_reference_positions_.push_back(current - 4); } else { // Relative address, relative to point after address. @@ -532,7 +531,7 @@ void Assembler::bind_to(Label* L, int pos) { if (current >= 4 && long_at(current - 4) == 0) { // Absolute address. intptr_t imm64 = reinterpret_cast(buffer_start_ + pos); - *reinterpret_cast(addr_at(current - 4)) = imm64; + WriteUnalignedValue(addr_at(current - 4), imm64); internal_reference_positions_.push_back(current - 4); } else { // Relative address, relative to point after address. @@ -629,8 +628,8 @@ void Assembler::GrowBuffer() { // Relocate internal references. for (auto pos : internal_reference_positions_) { - intptr_t* p = reinterpret_cast(buffer_start_ + pos); - *p += pc_delta; + Address p = reinterpret_cast
(buffer_start_ + pos); + WriteUnalignedValue(p, ReadUnalignedValue(p) + pc_delta); } DCHECK(!buffer_overflow()); @@ -648,7 +647,8 @@ void Assembler::emit_operand(int code, Operand adr) { // Recognize RIP relative addressing. if (adr.data().buf[0] == 5) { DCHECK_EQ(9u, length); - Label* label = *bit_cast(&adr.data().buf[1]); + Label* label = ReadUnalignedValue( + reinterpret_cast
(&adr.data().buf[1])); if (label->is_bound()) { int offset = label->pos() - pc_offset() - sizeof(int32_t) + adr.data().addend; diff --git a/src/x64/assembler-x64.h b/src/x64/assembler-x64.h index 4f16dc0fd3..17f52cda57 100644 --- a/src/x64/assembler-x64.h +++ b/src/x64/assembler-x64.h @@ -268,7 +268,7 @@ class ConstPool { bool AddSharedEntry(uint64_t data, int offset); // Check if the instruction is a rip-relative move. - bool IsMoveRipRelative(byte* instr); + bool IsMoveRipRelative(Address instr); Assembler* assm_; @@ -1806,12 +1806,14 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase { void call(Operand operand); private: - byte* addr_at(int pos) { return buffer_start_ + pos; } - uint32_t long_at(int pos) { - return *reinterpret_cast(addr_at(pos)); + Address addr_at(int pos) { + return reinterpret_cast
(buffer_start_ + pos); + } + uint32_t long_at(int pos) { + return ReadUnalignedValue(addr_at(pos)); } void long_at_put(int pos, uint32_t x) { - *reinterpret_cast(addr_at(pos)) = x; + WriteUnalignedValue(addr_at(pos), x); } // code emission