From 5edce1b22802ad661cbcbbafbc0a158adbf02393 Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Tue, 19 Jul 2022 15:07:54 +0200 Subject: [PATCH] [ext-code-space] Fix Code::constant_pool() after refactoring The Code::constant_pool() segfaulted on configurations with disabled external code space when it was called on mallocced copy of a Code object. Bug: v8:11880 Change-Id: I86919002ef080486f1e4532c3a2d3352f4526508 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3772004 Auto-Submit: Igor Sheludko Reviewed-by: Patrick Thier Commit-Queue: Patrick Thier Cr-Commit-Position: refs/heads/main@{#81811} --- src/objects/code-inl.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/objects/code-inl.h b/src/objects/code-inl.h index 6880bac732..e299f7401d 100644 --- a/src/objects/code-inl.h +++ b/src/objects/code-inl.h @@ -587,7 +587,10 @@ bool CodeDataContainer::has_handler_table() const { int Code::constant_pool_size() const { const int size = code_comments_offset() - constant_pool_offset(); - DCHECK_IMPLIES(!FLAG_enable_embedded_constant_pool, size == 0); + if (!FLAG_enable_embedded_constant_pool) { + DCHECK_EQ(size, 0); + return 0; + } DCHECK_GE(size, 0); return size; } @@ -977,6 +980,7 @@ Address Code::raw_constant_pool() const { } Address Code::constant_pool() const { + if (!has_constant_pool()) return kNullAddress; return V8_UNLIKELY(is_off_heap_trampoline()) ? OffHeapConstantPoolAddress(*this, builtin_id()) : raw_constant_pool(); @@ -984,6 +988,7 @@ Address Code::constant_pool() const { #ifdef V8_EXTERNAL_CODE_SPACE Address CodeDataContainer::constant_pool() const { + if (!has_constant_pool()) return kNullAddress; return V8_UNLIKELY(is_off_heap_trampoline()) ? OffHeapConstantPoolAddress(*this, builtin_id()) : code().raw_constant_pool();