Commit e1f76d4b authored by Ross McIlroy's avatar Ross McIlroy Committed by V8 LUCI CQ

Ensure embedded constants aren't disassembled as instructions.

BUG=chromium:1228666

Change-Id: Id5ef86170d5be8db507da80202836558a2fa6eb1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3030703
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75742}
parent 6bf0b704
......@@ -5237,7 +5237,8 @@ void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
DCHECK(is_const_pool_blocked() || pending_32_bit_constants_.empty());
CheckBuffer();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
base::WriteUnalignedValue(reinterpret_cast<Address>(pc_), data);
......@@ -5250,7 +5251,8 @@ void Assembler::dq(uint64_t value, RelocInfo::Mode rmode) {
DCHECK(is_const_pool_blocked() || pending_32_bit_constants_.empty());
CheckBuffer();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
base::WriteUnalignedValue(reinterpret_cast<Address>(pc_), value);
......
......@@ -4345,12 +4345,14 @@ void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data,
(rmode == RelocInfo::CONST_POOL) || (rmode == RelocInfo::VENEER_POOL) ||
(rmode == RelocInfo::DEOPT_SCRIPT_OFFSET) ||
(rmode == RelocInfo::DEOPT_INLINING_ID) ||
(rmode == RelocInfo::DEOPT_REASON) || (rmode == RelocInfo::DEOPT_ID)) {
(rmode == RelocInfo::DEOPT_REASON) || (rmode == RelocInfo::DEOPT_ID) ||
(rmode == RelocInfo::LITERAL_CONSTANT)) {
// Adjust code for new modes.
DCHECK(RelocInfo::IsDeoptReason(rmode) || RelocInfo::IsDeoptId(rmode) ||
RelocInfo::IsDeoptPosition(rmode) ||
RelocInfo::IsInternalReference(rmode) ||
RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode) ||
RelocInfo::IsConstPool(rmode) || RelocInfo::IsVeneerPool(rmode));
// These modes do not need an entry in the constant pool.
} else if (constant_pool_mode == NEEDS_POOL_ENTRY) {
......
......@@ -2067,7 +2067,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
void dd(uint32_t data, RelocInfo::Mode rmode = RelocInfo::NONE) {
BlockPoolsScope no_pool_scope(this);
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
dc32(data);
......@@ -2075,7 +2076,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
void dq(uint64_t data, RelocInfo::Mode rmode = RelocInfo::NONE) {
BlockPoolsScope no_pool_scope(this);
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
dc64(data);
......@@ -2083,7 +2085,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
void dp(uintptr_t data, RelocInfo::Mode rmode = RelocInfo::NONE) {
BlockPoolsScope no_pool_scope(this);
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
dc64(data);
......
......@@ -404,6 +404,9 @@ class V8_EXPORT_PRIVATE AssemblerBase : public Malloced {
!options().record_reloc_info_for_serialization && !FLAG_debug_code) {
return false;
}
#ifndef ENABLE_DISASSEMBLER
if (RelocInfo::IsLiteralConstant(rmode)) return false;
#endif
return true;
}
......
......@@ -3494,7 +3494,8 @@ void Assembler::db(uint8_t data) {
void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
EnsureSpace ensure_space(this);
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
emit(data);
......
......@@ -3592,7 +3592,8 @@ void Assembler::db(uint8_t data) {
void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
CheckForEmitInForbiddenSlot();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uint32_t*>(pc_) = data;
......@@ -3602,7 +3603,8 @@ void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
void Assembler::dq(uint64_t data, RelocInfo::Mode rmode) {
CheckForEmitInForbiddenSlot();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uint64_t*>(pc_) = data;
......
......@@ -3790,7 +3790,8 @@ void Assembler::db(uint8_t data) {
void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
CheckForEmitInForbiddenSlot();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uint32_t*>(pc_) = data;
......@@ -3800,7 +3801,8 @@ void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
void Assembler::dq(uint64_t data, RelocInfo::Mode rmode) {
CheckForEmitInForbiddenSlot();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uint64_t*>(pc_) = data;
......
......@@ -2003,7 +2003,8 @@ void Assembler::db(uint8_t data) {
void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
CheckBuffer();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uint32_t*>(pc_) = data;
......@@ -2013,7 +2014,8 @@ void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
void Assembler::dq(uint64_t value, RelocInfo::Mode rmode) {
CheckBuffer();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uint64_t*>(pc_) = value;
......@@ -2023,7 +2025,8 @@ void Assembler::dq(uint64_t value, RelocInfo::Mode rmode) {
void Assembler::dp(uintptr_t data, RelocInfo::Mode rmode) {
CheckBuffer();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uintptr_t*>(pc_) = data;
......
......@@ -422,6 +422,8 @@ const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
return "deopt reason";
case DEOPT_ID:
return "deopt index";
case LITERAL_CONSTANT:
return "literal constant";
case CONST_POOL:
return "constant pool";
case VENEER_POOL:
......@@ -525,6 +527,7 @@ void RelocInfo::Verify(Isolate* isolate) {
case DEOPT_INLINING_ID:
case DEOPT_REASON:
case DEOPT_ID:
case LITERAL_CONSTANT:
case CONST_POOL:
case VENEER_POOL:
case WASM_CALL:
......
......@@ -89,6 +89,8 @@ class RelocInfo {
DEOPT_REASON, // Deoptimization reason index.
DEOPT_ID, // Deoptimization inlining id.
LITERAL_CONSTANT, // An constant embedded in the instruction stream.
// This is not an actual reloc mode, but used to encode a long pc jump that
// cannot be encoded as part of another record.
PC_JUMP,
......@@ -169,6 +171,9 @@ class RelocInfo {
return mode == DEOPT_REASON;
}
static constexpr bool IsDeoptId(Mode mode) { return mode == DEOPT_ID; }
static constexpr bool IsLiteralConstant(Mode mode) {
return mode == LITERAL_CONSTANT;
}
static constexpr bool IsExternalReference(Mode mode) {
return mode == EXTERNAL_REFERENCE;
}
......
......@@ -2809,7 +2809,8 @@ void Assembler::db(uint8_t data) {
void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
if (!is_buffer_growth_blocked()) CheckBuffer();
......@@ -2819,7 +2820,8 @@ void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
void Assembler::dq(uint64_t data, RelocInfo::Mode rmode) {
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
if (!is_buffer_growth_blocked()) CheckBuffer();
......
......@@ -799,7 +799,8 @@ void Assembler::db(uint8_t data) {
void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
CheckBuffer();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uint32_t*>(pc_) = data;
......@@ -809,7 +810,8 @@ void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
void Assembler::dq(uint64_t value, RelocInfo::Mode rmode) {
CheckBuffer();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uint64_t*>(pc_) = value;
......@@ -819,7 +821,8 @@ void Assembler::dq(uint64_t value, RelocInfo::Mode rmode) {
void Assembler::dp(uintptr_t data, RelocInfo::Mode rmode) {
CheckBuffer();
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
*reinterpret_cast<uintptr_t*>(pc_) = data;
......
......@@ -4302,7 +4302,8 @@ void Assembler::db(uint8_t data) {
void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
EnsureSpace ensure_space(this);
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
emitl(data);
......@@ -4311,7 +4312,8 @@ void Assembler::dd(uint32_t data, RelocInfo::Mode rmode) {
void Assembler::dq(uint64_t data, RelocInfo::Mode rmode) {
EnsureSpace ensure_space(this);
if (!RelocInfo::IsNone(rmode)) {
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode));
DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) ||
RelocInfo::IsLiteralConstant(rmode));
RecordRelocInfo(rmode);
}
emitq(data);
......
......@@ -171,7 +171,7 @@ void CodeGenerator::AssembleDeoptImmediateArgs(
switch (constant.type()) {
case Constant::kInt32:
tasm()->dp(constant.ToInt32());
tasm()->dp(constant.ToInt32(), RelocInfo::LITERAL_CONSTANT);
break;
#ifdef V8_TARGET_ARCH_64_BIT
case Constant::kInt64:
......@@ -181,7 +181,7 @@ void CodeGenerator::AssembleDeoptImmediateArgs(
case Constant::kFloat64: {
int smi;
CHECK(DoubleToSmiInteger(constant.ToFloat64().value(), &smi));
tasm()->dp(Smi::FromInt(smi).ptr());
tasm()->dp(Smi::FromInt(smi).ptr(), RelocInfo::LITERAL_CONSTANT);
break;
}
case Constant::kCompressedHeapObject:
......
......@@ -319,13 +319,24 @@ static int DecodeIt(Isolate* isolate, ExternalReferenceEncoder* ref_encoder,
pc += 4;
} else if (it != nullptr && !it->done() &&
it->rinfo()->pc() == reinterpret_cast<Address>(pc) &&
it->rinfo()->rmode() == RelocInfo::INTERNAL_REFERENCE) {
(it->rinfo()->rmode() == RelocInfo::INTERNAL_REFERENCE ||
it->rinfo()->rmode() == RelocInfo::LITERAL_CONSTANT ||
it->rinfo()->rmode() == RelocInfo::DATA_EMBEDDED_OBJECT)) {
// raw pointer embedded in code stream, e.g., jump table
byte* ptr =
base::ReadUnalignedValue<byte*>(reinterpret_cast<Address>(pc));
SNPrintF(decode_buffer, "%08" V8PRIxPTR " jump table entry %4zu",
reinterpret_cast<intptr_t>(ptr),
static_cast<size_t>(ptr - begin));
if (RelocInfo::IsInternalReference(it->rinfo()->rmode())) {
SNPrintF(decode_buffer, "%08" V8PRIxPTR " jump table entry %4zu",
reinterpret_cast<intptr_t>(ptr),
static_cast<size_t>(ptr - begin));
} else {
const char* kType = RelocInfo::IsLiteralConstant(it->rinfo()->rmode())
? " literal constant"
: "embedded data object";
SNPrintF(decode_buffer, "%08" V8PRIxPTR " %s 0x%08" V8PRIxPTR,
reinterpret_cast<intptr_t>(ptr), kType,
reinterpret_cast<intptr_t>(ptr));
}
pc += sizeof(ptr);
} else {
decode_buffer[0] = '\0';
......
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