Revert "[SDK] Adds an SDK hash to kernels and the VM."

This reverts commit edde575dcd.

Reason for revert: Breaks the Dart to Flutter roll and golem

Original change's description:
> [SDK] Adds an SDK hash to kernels and the VM.
>
> Adds a new SDK hash to kernels and the VM which is optionally checked
> to verify kernels are built for the same SDK as the VM.
> This helps catch incompatibilities that are currently causing
> subtle bugs and (not so subtle) crashes.
>
> The SDK hash is encoded in kernels as a new field in components.
> The hash is derived from the 10 byte git short hash.
>
> This new check can be disabled via:
>   tools/gn.py ... --no-verify-sdk-hash
>
> This CL bumps the min. (and max.) supported kernel format version,
> making the VM backwards incompatible from this point back.
>
> Bug: https://github.com/dart-lang/sdk/issues/41802
> Change-Id: I3cbb2d481239ee64dafdaa0e4aac36c80281931b
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150343
> Commit-Queue: Clement Skau <cskau@google.com>
> Reviewed-by: Jens Johansen <jensj@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

TBR=kustermann@google.com,jensj@google.com,cskau@google.com

Change-Id: I34cc7d378e2babdaaca4d932d19c19d0f35422fc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/41802
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152703
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
This commit is contained in:
asiva
2020-06-26 18:54:17 +00:00
committed by commit-bot@chromium.org
parent a558d576b7
commit bb8d145616
27 changed files with 180 additions and 474 deletions
+16 -22
View File
@@ -15,7 +15,6 @@
#include "vm/kernel.h"
#include "vm/object.h"
#include "vm/os.h"
#include "vm/version.h"
namespace dart {
@@ -85,14 +84,12 @@ const char* kKernelInvalidBinaryFormatVersion =
"Invalid kernel binary format version";
const char* kKernelInvalidSizeIndicated =
"Invalid kernel binary: Indicated size is invalid";
const char* kKernelInvalidSdkHash = "Invalid SDK hash";
std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
if (reader->size() < 70) {
// A kernel file (v43) currently contains at least the following:
if (reader->size() < 60) {
// A kernel file (v41) currently contains at least the following:
// * Magic number (32)
// * Kernel version (32)
// * SDK Hash (10 * 8)
// * List of problems (8)
// * Length of source map (32)
// * Length of canonical name table (8)
@@ -101,7 +98,7 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
// * Length of constant table (8)
// * Component index (11 * 32)
//
// so is at least 74 bytes.
// so is at least 64 bytes.
// (Technically it will also contain an empty entry in both source map and
// string table, taking up another 8 bytes.)
if (error != nullptr) {
@@ -127,18 +124,6 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
return nullptr;
}
uint8_t sdkHash[11];
reader->ReadBytes(sdkHash, 10);
sdkHash[10] = 0; // Null terminate.
if (strcmp(Version::SdkHash(), "0000000000") != 0 &&
strcmp((const char*)sdkHash, "0000000000") != 0 &&
strcmp((const char*)sdkHash, Version::SdkHash()) != 0) {
if (error != nullptr) {
*error = kKernelInvalidSdkHash;
}
return nullptr;
}
std::unique_ptr<Program> program(new Program());
program->binary_version_ = formatVersion;
program->typed_data_ = reader->typed_data();
@@ -167,8 +152,13 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
// Read backwards at the end.
program->library_count_ = reader->ReadFromIndexNoReset(
reader->size_, LibraryCountFieldCountFromEnd, 1, 0);
static_assert(kMinSupportedKernelFormatVersion < 41, "cleanup this code");
intptr_t count_from_first_library_offset =
SourceTableFieldCountFromFirstLibraryOffset41Plus;
SourceTableFieldCountFromFirstLibraryOffsetPre41;
if (formatVersion >= 41) {
count_from_first_library_offset =
SourceTableFieldCountFromFirstLibraryOffset41Plus;
}
program->source_table_offset_ = reader->ReadFromIndexNoReset(
reader->size_,
LibraryCountFieldCountFromEnd + 1 + program->library_count_ + 1 +
@@ -181,9 +171,13 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
program->constant_table_offset_ = reader->ReadUInt32();
program->main_method_reference_ = NameIndex(reader->ReadUInt32() - 1);
NNBDCompiledMode compilation_mode =
static_cast<NNBDCompiledMode>(reader->ReadUInt32());
program->compilation_mode_ = compilation_mode;
if (formatVersion >= 41) {
NNBDCompiledMode compilation_mode =
static_cast<NNBDCompiledMode>(reader->ReadUInt32());
program->compilation_mode_ = compilation_mode;
} else {
program->compilation_mode_ = NNBDCompiledMode::kDisabled;
}
return program;
}