Commit 4a9cf942 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[ubsan] A few alignment fixes

Found by combining dcheck_always_on with is_ubsan on x64.

Change-Id: Ie9bcf2402693aa3752be17421dd485533656df08
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1962271Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65417}
parent 70fd0686
...@@ -33,9 +33,9 @@ CodeCommentsIterator::CodeCommentsIterator(Address code_comments_start, ...@@ -33,9 +33,9 @@ CodeCommentsIterator::CodeCommentsIterator(Address code_comments_start,
code_comments_size_(code_comments_size), code_comments_size_(code_comments_size),
current_entry_(code_comments_start + kOffsetToFirstCommentEntry) { current_entry_(code_comments_start + kOffsetToFirstCommentEntry) {
DCHECK_NE(kNullAddress, code_comments_start); DCHECK_NE(kNullAddress, code_comments_start);
DCHECK_IMPLIES( DCHECK_IMPLIES(code_comments_size,
code_comments_size, code_comments_size ==
code_comments_size == *reinterpret_cast<uint32_t*>(code_comments_start_)); base::ReadUnalignedValue<uint32_t>(code_comments_start_));
} }
uint32_t CodeCommentsIterator::size() const { return code_comments_size_; } uint32_t CodeCommentsIterator::size() const { return code_comments_size_; }
......
...@@ -661,7 +661,8 @@ TNode<WordT> CodeAssembler::WordShl(SloppyTNode<WordT> left, ...@@ -661,7 +661,8 @@ TNode<WordT> CodeAssembler::WordShl(SloppyTNode<WordT> left,
bool is_right_constant = ToIntPtrConstant(right, &right_constant); bool is_right_constant = ToIntPtrConstant(right, &right_constant);
if (is_left_constant) { if (is_left_constant) {
if (is_right_constant) { if (is_right_constant) {
return IntPtrConstant(left_constant << right_constant); return IntPtrConstant(static_cast<uintptr_t>(left_constant)
<< right_constant);
} }
} else if (is_right_constant) { } else if (is_right_constant) {
if (right_constant == 0) { if (right_constant == 0) {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "src/base/memory.h"
#include "src/codegen/assembler-inl.h" #include "src/codegen/assembler-inl.h"
#include "src/codegen/code-comments.h" #include "src/codegen/code-comments.h"
#include "src/codegen/code-reference.h" #include "src/codegen/code-reference.h"
...@@ -291,23 +292,26 @@ static int DecodeIt(Isolate* isolate, ExternalReferenceEncoder* ref_encoder, ...@@ -291,23 +292,26 @@ static int DecodeIt(Isolate* isolate, ExternalReferenceEncoder* ref_encoder,
// First decode instruction so that we know its length. // First decode instruction so that we know its length.
byte* prev_pc = pc; byte* prev_pc = pc;
if (constants > 0) { if (constants > 0) {
SNPrintF(decode_buffer, "%08x constant", SNPrintF(
*reinterpret_cast<int32_t*>(pc)); decode_buffer, "%08x constant",
base::ReadUnalignedValue<int32_t>(reinterpret_cast<Address>(pc)));
constants--; constants--;
pc += 4; pc += 4;
} else { } else {
int num_const = d.ConstantPoolSizeAt(pc); int num_const = d.ConstantPoolSizeAt(pc);
if (num_const >= 0) { if (num_const >= 0) {
SNPrintF(decode_buffer, SNPrintF(
"%08x constant pool begin (num_const = %d)", decode_buffer, "%08x constant pool begin (num_const = %d)",
*reinterpret_cast<int32_t*>(pc), num_const); base::ReadUnalignedValue<int32_t>(reinterpret_cast<Address>(pc)),
num_const);
constants = num_const; constants = num_const;
pc += 4; pc += 4;
} else if (it != nullptr && !it->done() && } else if (it != nullptr && !it->done() &&
it->rinfo()->pc() == reinterpret_cast<Address>(pc) && it->rinfo()->pc() == reinterpret_cast<Address>(pc) &&
it->rinfo()->rmode() == RelocInfo::INTERNAL_REFERENCE) { it->rinfo()->rmode() == RelocInfo::INTERNAL_REFERENCE) {
// raw pointer embedded in code stream, e.g., jump table // raw pointer embedded in code stream, e.g., jump table
byte* ptr = *reinterpret_cast<byte**>(pc); byte* ptr =
base::ReadUnalignedValue<byte*>(reinterpret_cast<Address>(pc));
SNPrintF(decode_buffer, "%08" V8PRIxPTR " jump table entry %4zu", SNPrintF(decode_buffer, "%08" V8PRIxPTR " jump table entry %4zu",
reinterpret_cast<intptr_t>(ptr), reinterpret_cast<intptr_t>(ptr),
static_cast<size_t>(ptr - begin)); static_cast<size_t>(ptr - begin));
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "src/base/compiler-specific.h" #include "src/base/compiler-specific.h"
#include "src/base/lazy-instance.h" #include "src/base/lazy-instance.h"
#include "src/base/memory.h"
#include "src/base/v8-fallthrough.h" #include "src/base/v8-fallthrough.h"
#include "src/codegen/x64/register-x64.h" #include "src/codegen/x64/register-x64.h"
#include "src/codegen/x64/sse-instr.h" #include "src/codegen/x64/sse-instr.h"
...@@ -245,19 +246,24 @@ uint8_t Imm8_U(const uint8_t* data) { ...@@ -245,19 +246,24 @@ uint8_t Imm8_U(const uint8_t* data) {
return *reinterpret_cast<const uint8_t*>(data); return *reinterpret_cast<const uint8_t*>(data);
} }
int16_t Imm16(const uint8_t* data) { int16_t Imm16(const uint8_t* data) {
return *reinterpret_cast<const int16_t*>(data); return v8::base::ReadUnalignedValue<int16_t>(
reinterpret_cast<v8::internal::Address>(data));
} }
uint16_t Imm16_U(const uint8_t* data) { uint16_t Imm16_U(const uint8_t* data) {
return *reinterpret_cast<const uint16_t*>(data); return v8::base::ReadUnalignedValue<uint16_t>(
reinterpret_cast<v8::internal::Address>(data));
} }
int32_t Imm32(const uint8_t* data) { int32_t Imm32(const uint8_t* data) {
return *reinterpret_cast<const int32_t*>(data); return v8::base::ReadUnalignedValue<int32_t>(
reinterpret_cast<v8::internal::Address>(data));
} }
uint32_t Imm32_U(const uint8_t* data) { uint32_t Imm32_U(const uint8_t* data) {
return *reinterpret_cast<const uint32_t*>(data); return v8::base::ReadUnalignedValue<uint32_t>(
reinterpret_cast<v8::internal::Address>(data));
} }
int64_t Imm64(const uint8_t* data) { int64_t Imm64(const uint8_t* data) {
return *reinterpret_cast<const int64_t*>(data); return v8::base::ReadUnalignedValue<int64_t>(
reinterpret_cast<v8::internal::Address>(data));
} }
} // namespace } // namespace
......
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