Commit 739bdd1c authored by Georgia Kouveli's avatar Georgia Kouveli Committed by V8 LUCI CQ

[builtins] Remove indirection for pointers to code and data blobs

Mark the labels to the code and data global, which removes the need
for having separate pointers to these labels in the .data section.

This means that `v8_Default_embedded_blob_code_` and
`v8_Default_embedded_blob_data_` can now actually be read-only when
RELRO is enabled.

The actual contents of `v8_Default_embedded_blob_code_` remain
potentially non-readable for platforms where code is marked as
execute-only, but these changes do not attempt to read them.

Bug: v8:12850

Change-Id: Ic1bc8e68fe44a9ce45380c83b0be5fa94e7da267
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3616510
Commit-Queue: Georgia Kouveli <georgia.kouveli@arm.com>
Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80331}
parent 6fecf48a
...@@ -141,9 +141,9 @@ ...@@ -141,9 +141,9 @@
#include "src/execution/simulator-base.h" #include "src/execution/simulator-base.h"
#endif #endif
extern "C" const uint8_t* v8_Default_embedded_blob_code_; extern "C" const uint8_t v8_Default_embedded_blob_code_[];
extern "C" uint32_t v8_Default_embedded_blob_code_size_; extern "C" uint32_t v8_Default_embedded_blob_code_size_;
extern "C" const uint8_t* v8_Default_embedded_blob_data_; extern "C" const uint8_t v8_Default_embedded_blob_data_[];
extern "C" uint32_t v8_Default_embedded_blob_data_size_; extern "C" uint32_t v8_Default_embedded_blob_data_size_;
namespace v8 { namespace v8 {
...@@ -3696,8 +3696,8 @@ void Isolate::InitializeDefaultEmbeddedBlob() { ...@@ -3696,8 +3696,8 @@ void Isolate::InitializeDefaultEmbeddedBlob() {
} }
} }
if (code == nullptr) { if (code_size == 0) {
CHECK_EQ(0, code_size); CHECK_EQ(0, data_size);
} else { } else {
SetEmbeddedBlob(code, code_size, data, data_size); SetEmbeddedBlob(code, code_size, data, data_size);
} }
......
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
#include "src/base/macros.h" #include "src/base/macros.h"
extern "C" const uint8_t* v8_Default_embedded_blob_code_; extern "C" const uint8_t v8_Default_embedded_blob_code_[];
extern "C" uint32_t v8_Default_embedded_blob_code_size_; extern "C" uint32_t v8_Default_embedded_blob_code_size_;
extern "C" const uint8_t* v8_Default_embedded_blob_data_; extern "C" const uint8_t v8_Default_embedded_blob_data_[];
extern "C" uint32_t v8_Default_embedded_blob_data_size_; extern "C" uint32_t v8_Default_embedded_blob_data_size_;
const uint8_t* v8_Default_embedded_blob_code_ = nullptr; const uint8_t v8_Default_embedded_blob_code_[1] = {0};
uint32_t v8_Default_embedded_blob_code_size_ = 0; uint32_t v8_Default_embedded_blob_code_size_ = 0;
const uint8_t* v8_Default_embedded_blob_data_ = nullptr; const uint8_t v8_Default_embedded_blob_data_[1] = {0};
uint32_t v8_Default_embedded_blob_data_size_ = 0; uint32_t v8_Default_embedded_blob_data_size_ = 0;
...@@ -157,7 +157,8 @@ void EmbeddedFileWriter::WriteCodeSection(PlatformEmbeddedFileWriterBase* w, ...@@ -157,7 +157,8 @@ void EmbeddedFileWriter::WriteCodeSection(PlatformEmbeddedFileWriterBase* w,
#endif #endif
w->AlignToCodeAlignment(); w->AlignToCodeAlignment();
w->DeclareLabel(EmbeddedBlobCodeDataSymbol().c_str()); w->DeclareSymbolGlobal(EmbeddedBlobCodeSymbol().c_str());
w->DeclareLabel(EmbeddedBlobCodeSymbol().c_str());
STATIC_ASSERT(Builtins::kAllBuiltinsAreIsolateIndependent); STATIC_ASSERT(Builtins::kAllBuiltinsAreIsolateIndependent);
for (Builtin builtin = Builtins::kFirst; builtin <= Builtins::kLast; for (Builtin builtin = Builtins::kFirst; builtin <= Builtins::kLast;
...@@ -170,31 +171,6 @@ void EmbeddedFileWriter::WriteCodeSection(PlatformEmbeddedFileWriterBase* w, ...@@ -170,31 +171,6 @@ void EmbeddedFileWriter::WriteCodeSection(PlatformEmbeddedFileWriterBase* w,
void EmbeddedFileWriter::WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w, void EmbeddedFileWriter::WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w,
const i::EmbeddedData* blob) const { const i::EmbeddedData* blob) const {
{
base::EmbeddedVector<char, kTemporaryStringLength>
embedded_blob_code_symbol;
base::SNPrintF(embedded_blob_code_symbol, "v8_%s_embedded_blob_code_",
embedded_variant_);
w->Comment("Pointer to the beginning of the embedded blob code.");
w->SectionData();
w->AlignToDataAlignment();
w->DeclarePointerToSymbol(embedded_blob_code_symbol.begin(),
EmbeddedBlobCodeDataSymbol().c_str());
w->Newline();
base::EmbeddedVector<char, kTemporaryStringLength>
embedded_blob_data_symbol;
base::SNPrintF(embedded_blob_data_symbol, "v8_%s_embedded_blob_data_",
embedded_variant_);
w->Comment("Pointer to the beginning of the embedded blob data section.");
w->AlignToDataAlignment();
w->DeclarePointerToSymbol(embedded_blob_data_symbol.begin(),
EmbeddedBlobDataDataSymbol().c_str());
w->Newline();
}
{ {
base::EmbeddedVector<char, kTemporaryStringLength> base::EmbeddedVector<char, kTemporaryStringLength>
embedded_blob_code_size_symbol; embedded_blob_code_size_symbol;
...@@ -224,7 +200,7 @@ void EmbeddedFileWriter::WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w, ...@@ -224,7 +200,7 @@ void EmbeddedFileWriter::WriteFileEpilogue(PlatformEmbeddedFileWriterBase* w,
embedded_variant_); embedded_variant_);
w->MaybeEmitUnwindData(unwind_info_symbol.begin(), w->MaybeEmitUnwindData(unwind_info_symbol.begin(),
EmbeddedBlobCodeDataSymbol().c_str(), blob, EmbeddedBlobCodeSymbol().c_str(), blob,
reinterpret_cast<const void*>(&unwind_infos_[0])); reinterpret_cast<const void*>(&unwind_infos_[0]));
} }
#endif // V8_OS_WIN64 #endif // V8_OS_WIN64
......
...@@ -125,20 +125,20 @@ class EmbeddedFileWriter : public EmbeddedFileWriterInterface { ...@@ -125,20 +125,20 @@ class EmbeddedFileWriter : public EmbeddedFileWriterInterface {
// Fairly arbitrary but should fit all symbol names. // Fairly arbitrary but should fit all symbol names.
static constexpr int kTemporaryStringLength = 256; static constexpr int kTemporaryStringLength = 256;
std::string EmbeddedBlobCodeDataSymbol() const { std::string EmbeddedBlobCodeSymbol() const {
base::EmbeddedVector<char, kTemporaryStringLength> base::EmbeddedVector<char, kTemporaryStringLength>
embedded_blob_code_data_symbol; embedded_blob_code_symbol;
base::SNPrintF(embedded_blob_code_data_symbol, base::SNPrintF(embedded_blob_code_symbol, "v8_%s_embedded_blob_code_",
"v8_%s_embedded_blob_code_data_", embedded_variant_); embedded_variant_);
return std::string{embedded_blob_code_data_symbol.begin()}; return std::string{embedded_blob_code_symbol.begin()};
} }
std::string EmbeddedBlobDataDataSymbol() const { std::string EmbeddedBlobDataSymbol() const {
base::EmbeddedVector<char, kTemporaryStringLength> base::EmbeddedVector<char, kTemporaryStringLength>
embedded_blob_data_data_symbol; embedded_blob_data_symbol;
base::SNPrintF(embedded_blob_data_data_symbol, base::SNPrintF(embedded_blob_data_symbol, "v8_%s_embedded_blob_data_",
"v8_%s_embedded_blob_data_data_", embedded_variant_); embedded_variant_);
return std::string{embedded_blob_data_data_symbol.begin()}; return std::string{embedded_blob_data_symbol.begin()};
} }
void WriteDataSection(PlatformEmbeddedFileWriterBase* w, void WriteDataSection(PlatformEmbeddedFileWriterBase* w,
...@@ -146,7 +146,8 @@ class EmbeddedFileWriter : public EmbeddedFileWriterInterface { ...@@ -146,7 +146,8 @@ class EmbeddedFileWriter : public EmbeddedFileWriterInterface {
w->Comment("The embedded blob data section starts here."); w->Comment("The embedded blob data section starts here.");
w->SectionRoData(); w->SectionRoData();
w->AlignToDataAlignment(); w->AlignToDataAlignment();
w->DeclareLabel(EmbeddedBlobDataDataSymbol().c_str()); w->DeclareSymbolGlobal(EmbeddedBlobDataSymbol().c_str());
w->DeclareLabel(EmbeddedBlobDataSymbol().c_str());
WriteBinaryContentsAsInlineAssembly(w, blob->data(), blob->data_size()); WriteBinaryContentsAsInlineAssembly(w, blob->data(), blob->data_size());
} }
......
...@@ -32,10 +32,6 @@ void PlatformEmbeddedFileWriterAIX::SectionText() { ...@@ -32,10 +32,6 @@ void PlatformEmbeddedFileWriterAIX::SectionText() {
fprintf(fp_, ".csect [GL], 6\n"); fprintf(fp_, ".csect [GL], 6\n");
} }
void PlatformEmbeddedFileWriterAIX::SectionData() {
fprintf(fp_, ".csect .data[RW]\n");
}
void PlatformEmbeddedFileWriterAIX::SectionRoData() { void PlatformEmbeddedFileWriterAIX::SectionRoData() {
fprintf(fp_, ".csect[RO]\n"); fprintf(fp_, ".csect[RO]\n");
} }
...@@ -50,14 +46,6 @@ void PlatformEmbeddedFileWriterAIX::DeclareUint32(const char* name, ...@@ -50,14 +46,6 @@ void PlatformEmbeddedFileWriterAIX::DeclareUint32(const char* name,
Newline(); Newline();
} }
void PlatformEmbeddedFileWriterAIX::DeclarePointerToSymbol(const char* name,
const char* target) {
AlignToCodeAlignment();
DeclareLabel(name);
fprintf(fp_, " %s %s\n", DirectiveAsString(PointerSizeDirective()), target);
Newline();
}
void PlatformEmbeddedFileWriterAIX::DeclareSymbolGlobal(const char* name) { void PlatformEmbeddedFileWriterAIX::DeclareSymbolGlobal(const char* name) {
// These symbols are not visible outside of the final binary, this allows for // These symbols are not visible outside of the final binary, this allows for
// reduced binary size, and less work for the dynamic linker. // reduced binary size, and less work for the dynamic linker.
......
...@@ -22,14 +22,12 @@ class PlatformEmbeddedFileWriterAIX : public PlatformEmbeddedFileWriterBase { ...@@ -22,14 +22,12 @@ class PlatformEmbeddedFileWriterAIX : public PlatformEmbeddedFileWriterBase {
} }
void SectionText() override; void SectionText() override;
void SectionData() override;
void SectionRoData() override; void SectionRoData() override;
void AlignToCodeAlignment() override; void AlignToCodeAlignment() override;
void AlignToDataAlignment() override; void AlignToDataAlignment() override;
void DeclareUint32(const char* name, uint32_t value) override; void DeclareUint32(const char* name, uint32_t value) override;
void DeclarePointerToSymbol(const char* name, const char* target) override;
void DeclareSymbolGlobal(const char* name) override; void DeclareSymbolGlobal(const char* name) override;
void DeclareLabel(const char* name) override; void DeclareLabel(const char* name) override;
......
...@@ -54,7 +54,6 @@ class PlatformEmbeddedFileWriterBase { ...@@ -54,7 +54,6 @@ class PlatformEmbeddedFileWriterBase {
FILE* fp() const { return fp_; } FILE* fp() const { return fp_; }
virtual void SectionText() = 0; virtual void SectionText() = 0;
virtual void SectionData() = 0;
virtual void SectionRoData() = 0; virtual void SectionRoData() = 0;
virtual void AlignToCodeAlignment() = 0; virtual void AlignToCodeAlignment() = 0;
...@@ -62,7 +61,6 @@ class PlatformEmbeddedFileWriterBase { ...@@ -62,7 +61,6 @@ class PlatformEmbeddedFileWriterBase {
virtual void AlignToDataAlignment() = 0; virtual void AlignToDataAlignment() = 0;
virtual void DeclareUint32(const char* name, uint32_t value) = 0; virtual void DeclareUint32(const char* name, uint32_t value) = 0;
virtual void DeclarePointerToSymbol(const char* name, const char* target) = 0;
virtual void DeclareSymbolGlobal(const char* name) = 0; virtual void DeclareSymbolGlobal(const char* name) = 0;
virtual void DeclareLabel(const char* name) = 0; virtual void DeclareLabel(const char* name) = 0;
......
...@@ -41,10 +41,6 @@ void PlatformEmbeddedFileWriterGeneric::SectionText() { ...@@ -41,10 +41,6 @@ void PlatformEmbeddedFileWriterGeneric::SectionText() {
} }
} }
void PlatformEmbeddedFileWriterGeneric::SectionData() {
fprintf(fp_, ".section .data\n");
}
void PlatformEmbeddedFileWriterGeneric::SectionRoData() { void PlatformEmbeddedFileWriterGeneric::SectionRoData() {
fprintf(fp_, ".section .rodata\n"); fprintf(fp_, ".section .rodata\n");
} }
...@@ -58,14 +54,6 @@ void PlatformEmbeddedFileWriterGeneric::DeclareUint32(const char* name, ...@@ -58,14 +54,6 @@ void PlatformEmbeddedFileWriterGeneric::DeclareUint32(const char* name,
Newline(); Newline();
} }
void PlatformEmbeddedFileWriterGeneric::DeclarePointerToSymbol(
const char* name, const char* target) {
DeclareSymbolGlobal(name);
DeclareLabel(name);
fprintf(fp_, " %s %s%s\n", DirectiveAsString(PointerSizeDirective()),
SYMBOL_PREFIX, target);
}
void PlatformEmbeddedFileWriterGeneric::DeclareSymbolGlobal(const char* name) { void PlatformEmbeddedFileWriterGeneric::DeclareSymbolGlobal(const char* name) {
fprintf(fp_, ".global %s%s\n", SYMBOL_PREFIX, name); fprintf(fp_, ".global %s%s\n", SYMBOL_PREFIX, name);
// These symbols are not visible outside of the final binary, this allows for // These symbols are not visible outside of the final binary, this allows for
......
...@@ -24,7 +24,6 @@ class PlatformEmbeddedFileWriterGeneric ...@@ -24,7 +24,6 @@ class PlatformEmbeddedFileWriterGeneric
} }
void SectionText() override; void SectionText() override;
void SectionData() override;
void SectionRoData() override; void SectionRoData() override;
void AlignToCodeAlignment() override; void AlignToCodeAlignment() override;
...@@ -32,7 +31,6 @@ class PlatformEmbeddedFileWriterGeneric ...@@ -32,7 +31,6 @@ class PlatformEmbeddedFileWriterGeneric
void AlignToDataAlignment() override; void AlignToDataAlignment() override;
void DeclareUint32(const char* name, uint32_t value) override; void DeclareUint32(const char* name, uint32_t value) override;
void DeclarePointerToSymbol(const char* name, const char* target) override;
void DeclareSymbolGlobal(const char* name) override; void DeclareSymbolGlobal(const char* name) override;
void DeclareLabel(const char* name) override; void DeclareLabel(const char* name) override;
......
...@@ -29,8 +29,6 @@ const char* DirectiveAsString(DataDirective directive) { ...@@ -29,8 +29,6 @@ const char* DirectiveAsString(DataDirective directive) {
void PlatformEmbeddedFileWriterMac::SectionText() { fprintf(fp_, ".text\n"); } void PlatformEmbeddedFileWriterMac::SectionText() { fprintf(fp_, ".text\n"); }
void PlatformEmbeddedFileWriterMac::SectionData() { fprintf(fp_, ".data\n"); }
void PlatformEmbeddedFileWriterMac::SectionRoData() { void PlatformEmbeddedFileWriterMac::SectionRoData() {
fprintf(fp_, ".const_data\n"); fprintf(fp_, ".const_data\n");
} }
...@@ -44,13 +42,6 @@ void PlatformEmbeddedFileWriterMac::DeclareUint32(const char* name, ...@@ -44,13 +42,6 @@ void PlatformEmbeddedFileWriterMac::DeclareUint32(const char* name,
Newline(); Newline();
} }
void PlatformEmbeddedFileWriterMac::DeclarePointerToSymbol(const char* name,
const char* target) {
DeclareSymbolGlobal(name);
DeclareLabel(name);
fprintf(fp_, " %s _%s\n", DirectiveAsString(PointerSizeDirective()), target);
}
void PlatformEmbeddedFileWriterMac::DeclareSymbolGlobal(const char* name) { void PlatformEmbeddedFileWriterMac::DeclareSymbolGlobal(const char* name) {
// TODO(jgruber): Investigate switching to .globl. Using .private_extern // TODO(jgruber): Investigate switching to .globl. Using .private_extern
// prevents something along the compilation chain from messing with the // prevents something along the compilation chain from messing with the
......
...@@ -22,7 +22,6 @@ class PlatformEmbeddedFileWriterMac : public PlatformEmbeddedFileWriterBase { ...@@ -22,7 +22,6 @@ class PlatformEmbeddedFileWriterMac : public PlatformEmbeddedFileWriterBase {
} }
void SectionText() override; void SectionText() override;
void SectionData() override;
void SectionRoData() override; void SectionRoData() override;
void AlignToCodeAlignment() override; void AlignToCodeAlignment() override;
...@@ -30,7 +29,6 @@ class PlatformEmbeddedFileWriterMac : public PlatformEmbeddedFileWriterBase { ...@@ -30,7 +29,6 @@ class PlatformEmbeddedFileWriterMac : public PlatformEmbeddedFileWriterBase {
void AlignToDataAlignment() override; void AlignToDataAlignment() override;
void DeclareUint32(const char* name, uint32_t value) override; void DeclareUint32(const char* name, uint32_t value) override;
void DeclarePointerToSymbol(const char* name, const char* target) override;
void DeclareSymbolGlobal(const char* name) override; void DeclareSymbolGlobal(const char* name) override;
void DeclareLabel(const char* name) override; void DeclareLabel(const char* name) override;
......
...@@ -364,15 +364,6 @@ void PlatformEmbeddedFileWriterWin::SectionText() { ...@@ -364,15 +364,6 @@ void PlatformEmbeddedFileWriterWin::SectionText() {
} }
} }
void PlatformEmbeddedFileWriterWin::SectionData() {
if (target_arch_ == EmbeddedTargetArch::kArm64) {
fprintf(fp_, " AREA |.data|, DATA, ALIGN=%d, READWRITE\n",
ARM64_DATA_ALIGNMENT_POWER);
} else {
fprintf(fp_, ".DATA\n");
}
}
void PlatformEmbeddedFileWriterWin::SectionRoData() { void PlatformEmbeddedFileWriterWin::SectionRoData() {
if (target_arch_ == EmbeddedTargetArch::kArm64) { if (target_arch_ == EmbeddedTargetArch::kArm64) {
fprintf(fp_, " AREA |.rodata|, DATA, ALIGN=%d, READONLY\n", fprintf(fp_, " AREA |.rodata|, DATA, ALIGN=%d, READONLY\n",
...@@ -389,13 +380,6 @@ void PlatformEmbeddedFileWriterWin::DeclareUint32(const char* name, ...@@ -389,13 +380,6 @@ void PlatformEmbeddedFileWriterWin::DeclareUint32(const char* name,
value); value);
} }
void PlatformEmbeddedFileWriterWin::DeclarePointerToSymbol(const char* name,
const char* target) {
DeclareSymbolGlobal(name);
fprintf(fp_, "%s%s %s %s%s\n", SYMBOL_PREFIX, name,
DirectiveAsString(PointerSizeDirective()), SYMBOL_PREFIX, target);
}
void PlatformEmbeddedFileWriterWin::StartPdataSection() { void PlatformEmbeddedFileWriterWin::StartPdataSection() {
if (target_arch_ == EmbeddedTargetArch::kArm64) { if (target_arch_ == EmbeddedTargetArch::kArm64) {
fprintf(fp_, " AREA |.pdata|, DATA, ALIGN=%d, READONLY\n", fprintf(fp_, " AREA |.pdata|, DATA, ALIGN=%d, READONLY\n",
...@@ -584,10 +568,6 @@ void PlatformEmbeddedFileWriterWin::SectionText() { ...@@ -584,10 +568,6 @@ void PlatformEmbeddedFileWriterWin::SectionText() {
fprintf(fp_, ".section .text$hot,\"xr\"\n"); fprintf(fp_, ".section .text$hot,\"xr\"\n");
} }
void PlatformEmbeddedFileWriterWin::SectionData() {
fprintf(fp_, ".section .data\n");
}
void PlatformEmbeddedFileWriterWin::SectionRoData() { void PlatformEmbeddedFileWriterWin::SectionRoData() {
fprintf(fp_, ".section .rdata\n"); fprintf(fp_, ".section .rdata\n");
} }
...@@ -601,14 +581,6 @@ void PlatformEmbeddedFileWriterWin::DeclareUint32(const char* name, ...@@ -601,14 +581,6 @@ void PlatformEmbeddedFileWriterWin::DeclareUint32(const char* name,
Newline(); Newline();
} }
void PlatformEmbeddedFileWriterWin::DeclarePointerToSymbol(const char* name,
const char* target) {
DeclareSymbolGlobal(name);
DeclareLabel(name);
fprintf(fp_, " %s %s%s\n", DirectiveAsString(PointerSizeDirective()),
SYMBOL_PREFIX, target);
}
void PlatformEmbeddedFileWriterWin::StartPdataSection() { void PlatformEmbeddedFileWriterWin::StartPdataSection() {
fprintf(fp_, ".section .pdata\n"); fprintf(fp_, ".section .pdata\n");
} }
......
...@@ -21,14 +21,12 @@ class PlatformEmbeddedFileWriterWin : public PlatformEmbeddedFileWriterBase { ...@@ -21,14 +21,12 @@ class PlatformEmbeddedFileWriterWin : public PlatformEmbeddedFileWriterBase {
} }
void SectionText() override; void SectionText() override;
void SectionData() override;
void SectionRoData() override; void SectionRoData() override;
void AlignToCodeAlignment() override; void AlignToCodeAlignment() override;
void AlignToDataAlignment() override; void AlignToDataAlignment() override;
void DeclareUint32(const char* name, uint32_t value) override; void DeclareUint32(const char* name, uint32_t value) override;
void DeclarePointerToSymbol(const char* name, const char* target) override;
void DeclareSymbolGlobal(const char* name) override; void DeclareSymbolGlobal(const char* name) override;
void DeclareLabel(const char* name) override; void DeclareLabel(const char* name) override;
......
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