Skip to content

Commit bb8d145

Browse files
a-sivacommit-bot@chromium.org
authored andcommitted
Revert "[SDK] Adds an SDK hash to kernels and the VM."
This reverts commit edde575. 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: #41802 > Change-Id: I3cbb2d481239ee64dafdaa0e4aac36c80281931b > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150343 > Commit-Queue: Clement Skau <[email protected]> > Reviewed-by: Jens Johansen <[email protected]> > Reviewed-by: Martin Kustermann <[email protected]> [email protected],[email protected],[email protected] Change-Id: I34cc7d378e2babdaaca4d932d19c19d0f35422fc No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: #41802 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152703 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent a558d57 commit bb8d145

27 files changed

+184
-478
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ deps = {
512512
"packages": [
513513
{
514514
"package": "dart/cfe/dart2js_dills",
515-
"version": "binary_version:43_2",
515+
"version": "binary_version:42",
516516
}
517517
],
518518
"dep_type": "cipd",

pkg/front_end/test/binary_md_dill_reader.dart

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -473,33 +473,31 @@ class BinaryMdDillReader {
473473
type = type.substring(0, type.indexOf("["));
474474
type = _lookupGenericType(typeNames, type, types);
475475

476-
int intCount = int.tryParse(count) ?? -1;
477-
if (intCount == -1) {
478-
if (vars[count] != null && vars[count] is int) {
479-
intCount = vars[count];
480-
} else if (count.contains(".")) {
481-
List<String> countData =
482-
count.split(regExpSplit).map((s) => s.trim()).toList();
483-
if (vars[countData[0]] != null) {
484-
dynamic v = vars[countData[0]];
485-
if (v is Map &&
486-
countData[1] == "last" &&
487-
v["items"] is List &&
488-
v["items"].last is int) {
489-
intCount = v["items"].last;
490-
} else if (v is Map && v[countData[1]] != null) {
491-
v = v[countData[1]];
492-
if (v is Map && v[countData[2]] != null) {
493-
v = v[countData[2]];
494-
if (v is int) intCount = v;
495-
} else if (v is int &&
496-
countData.length == 4 &&
497-
countData[2] == "+") {
498-
intCount = v + int.parse(countData[3]);
499-
}
500-
} else {
501-
throw "Unknown dot to int ($count)";
476+
int intCount = -1;
477+
if (vars[count] != null && vars[count] is int) {
478+
intCount = vars[count];
479+
} else if (count.contains(".")) {
480+
List<String> countData =
481+
count.split(regExpSplit).map((s) => s.trim()).toList();
482+
if (vars[countData[0]] != null) {
483+
dynamic v = vars[countData[0]];
484+
if (v is Map &&
485+
countData[1] == "last" &&
486+
v["items"] is List &&
487+
v["items"].last is int) {
488+
intCount = v["items"].last;
489+
} else if (v is Map && v[countData[1]] != null) {
490+
v = v[countData[1]];
491+
if (v is Map && v[countData[2]] != null) {
492+
v = v[countData[2]];
493+
if (v is int) intCount = v;
494+
} else if (v is int &&
495+
countData.length == 4 &&
496+
countData[2] == "+") {
497+
intCount = v + int.parse(countData[3]);
502498
}
499+
} else {
500+
throw "Unknown dot to int ($count)";
503501
}
504502
}
505503
}

pkg/front_end/test/spell_checking_list_code.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ disallow
313313
disambiguator
314314
disjoint
315315
dispatched
316-
distribute
317316
divided
318317
dmitryas
319318
doc
@@ -326,7 +325,6 @@ downloaded
326325
downloading
327326
dq
328327
dquote
329-
dsdk
330328
dst
331329
dummy
332330
dupdate
@@ -437,14 +435,12 @@ futured
437435
futureor
438436
g
439437
gardening
440-
gen
441438
generation
442439
gets
443440
getter1a
444441
getter1b
445442
getting
446443
gft
447-
git
448444
github
449445
glb
450446
glob

pkg/kernel/binary.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ type CanonicalName {
143143

144144
type ComponentFile {
145145
UInt32 magic = 0x90ABCDEF;
146-
UInt32 formatVersion = 43;
147-
Byte[10] shortSdkHash;
146+
UInt32 formatVersion = 42;
148147
List<String> problemsAsJson; // Described in problems.md.
149148
Library[] libraries;
150149
UriSource sourceMap;

pkg/kernel/lib/binary/ast_from_binary.dart

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ library kernel.ast_from_binary;
55

66
import 'dart:core' hide MapEntry;
77
import 'dart:developer';
8-
import 'dart:convert';
98
import 'dart:typed_data';
109

1110
import '../ast.dart';
@@ -29,22 +28,11 @@ class InvalidKernelVersionError {
2928
InvalidKernelVersionError(this.version);
3029

3130
String toString() {
32-
return 'Unexpected Kernel Format Version ${version} '
31+
return 'Unexpected Kernel version ${version} '
3332
'(expected ${Tag.BinaryFormatVersion}).';
3433
}
3534
}
3635

37-
class InvalidKernelSdkVersionError {
38-
final String version;
39-
40-
InvalidKernelSdkVersionError(this.version);
41-
42-
String toString() {
43-
return 'Unexpected Kernel SDK Version ${version} '
44-
'(expected ${expectedSdkHash}).';
45-
}
46-
}
47-
4836
class CompilationModeError {
4937
final String message;
5038

@@ -496,13 +484,6 @@ class BinaryBuilder {
496484
if (_bytes.length == 0) throw new StateError("Empty input given.");
497485
}
498486

499-
void _readAndVerifySdkHash() {
500-
final sdkHash = ascii.decode(readBytes(sdkHashLength));
501-
if (!isValidSdkHash(sdkHash)) {
502-
throw InvalidKernelSdkVersionError(sdkHash);
503-
}
504-
}
505-
506487
/// Deserializes a kernel component and stores it in [component].
507488
///
508489
/// When linking with a non-empty component, canonical names must have been
@@ -530,9 +511,6 @@ class BinaryBuilder {
530511
if (version != Tag.BinaryFormatVersion) {
531512
throw InvalidKernelVersionError(version);
532513
}
533-
534-
_readAndVerifySdkHash();
535-
536514
_byteOffset = offset;
537515
List<int> componentFileSizes = _indexComponents();
538516
if (componentFileSizes.length > 1) {
@@ -716,8 +694,6 @@ class BinaryBuilder {
716694
throw InvalidKernelVersionError(formatVersion);
717695
}
718696

719-
_readAndVerifySdkHash();
720-
721697
// Read component index from the end of this ComponentFiles serialized data.
722698
_ComponentIndex index = _readComponentIndex(componentFileSize);
723699

@@ -742,8 +718,6 @@ class BinaryBuilder {
742718
throw InvalidKernelVersionError(formatVersion);
743719
}
744720

745-
_readAndVerifySdkHash();
746-
747721
List<String> problemsAsJson = readListOfStrings();
748722
if (problemsAsJson != null) {
749723
component.problemsAsJson ??= <String>[];

pkg/kernel/lib/binary/ast_to_binary.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
library kernel.ast_to_binary;
55

66
import 'dart:core' hide MapEntry;
7-
import 'dart:convert';
87
import 'dart:developer';
98
import 'dart:io' show BytesBuilder;
109
import 'dart:typed_data';
@@ -538,7 +537,6 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
538537
final componentOffset = getBufferOffset();
539538
writeUInt32(Tag.ComponentFile);
540539
writeUInt32(Tag.BinaryFormatVersion);
541-
writeBytes(ascii.encode(expectedSdkHash));
542540
writeListOfStrings(component.problemsAsJson);
543541
indexLinkTable(component);
544542
_collectMetadata(component);

pkg/kernel/lib/binary/tag.dart

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class Tag {
149149
/// Internal version of kernel binary format.
150150
/// Bump it when making incompatible changes in kernel binaries.
151151
/// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md.
152-
static const int BinaryFormatVersion = 43;
152+
static const int BinaryFormatVersion = 42;
153153
}
154154

155155
abstract class ConstantTag {
@@ -169,27 +169,3 @@ abstract class ConstantTag {
169169
static const int UnevaluatedConstant = 12;
170170
// 13 is occupied by [SetConstant]
171171
}
172-
173-
const int sdkHashLength = 10; // Bytes, a Git "short hash".
174-
175-
const String sdkHashNull = '0000000000';
176-
177-
// Will be correct hash for Flutter SDK / Dart SDK we distribute.
178-
// If non-null we will validate when consuming kernel, will use when producing
179-
// kernel.
180-
// If null, local development setting (e.g. run gen_kernel.dart from source),
181-
// we put 0x00..00 into when producing, do not validate when consuming.
182-
String get expectedSdkHash {
183-
final sdkHash =
184-
const String.fromEnvironment('sdk_hash', defaultValue: sdkHashNull);
185-
if (sdkHash.length != 10) {
186-
throw '-Dsdk_hash=<hash> must be a 10 byte string!';
187-
}
188-
return sdkHash;
189-
}
190-
191-
bool isValidSdkHash(String sdkHash) {
192-
return (sdkHash == sdkHashNull ||
193-
expectedSdkHash == sdkHashNull ||
194-
sdkHash == expectedSdkHash);
195-
}

runtime/bin/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,9 @@ prebuilt_dart_action("gen_kernel_bytecode_dill") {
964964

965965
abs_depfile = rebase_path(depfile)
966966
rebased_output = rebase_path(output, root_build_dir)
967-
968967
vm_args = [
969968
"--depfile=$abs_depfile",
970969
"--depfile_output_filename=$rebased_output",
971-
"-Dsdk_hash=$sdk_hash",
972970
]
973971

974972
args = [

runtime/tests/vm/dart/sdk_hash_test.dart

Lines changed: 0 additions & 88 deletions
This file was deleted.

runtime/tests/vm/dart/snapshot_test_helper.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ final String executableSuffix = Platform.isWindows ? ".exe" : "";
4848
final String buildDir = p.dirname(Platform.executable);
4949
final String platformDill = p.join(buildDir, "vm_platform_strong.dill");
5050
final String genSnapshot = p.join(buildDir, "gen_snapshot${executableSuffix}");
51-
final String dart = p.join(buildDir, "dart${executableSuffix}");
5251
final String dartPrecompiledRuntime =
5352
p.join(buildDir, "dart_precompiled_runtime${executableSuffix}");
5453
final String genKernel = p.join("pkg", "vm", "bin", "gen_kernel.dart");

0 commit comments

Comments
 (0)