-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <cskau@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
- Loading branch information
Clement Skau
authored and
commit-bot@chromium.org
committed
Jun 26, 2020
1 parent
d512020
commit edde575
Showing
27 changed files
with
478 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:path/path.dart' as path; | ||
import 'package:expect/expect.dart'; | ||
|
||
import 'snapshot_test_helper.dart'; | ||
|
||
// Keep in sync with pkg/kernel/lib/binary/tag.dart: | ||
const tagComponentFile = [0x90, 0xAB, 0xCD, 0xEF]; | ||
const tagBinaryFormatVersion = [0x00, 0x00, 0x00, 43]; | ||
|
||
Future<void> main(List<String> args) async { | ||
if (args.length == 1 && args[0] == '--child') { | ||
print('Hello, SDK Hash!'); | ||
return; | ||
} | ||
|
||
final String sourcePath = | ||
path.join('runtime', 'tests', 'vm', 'dart_2', 'sdk_hash_test.dart'); | ||
|
||
await withTempDir((String tmp) async { | ||
final String dillPath = path.join(tmp, 'test.dill'); | ||
|
||
{ | ||
final result = await Process.run(dart, [ | ||
genKernel, | ||
'--platform', | ||
platformDill, | ||
'-o', | ||
dillPath, | ||
sourcePath, | ||
]); | ||
Expect.equals('', result.stderr); | ||
Expect.equals(0, result.exitCode); | ||
Expect.equals('', result.stdout); | ||
} | ||
|
||
{ | ||
final result = await Process.run(dart, [dillPath, '--child']); | ||
Expect.equals('', result.stderr); | ||
Expect.equals(0, result.exitCode); | ||
Expect.equals('Hello, SDK Hash!\n', result.stdout); | ||
} | ||
|
||
// Invalidate the SDK hash in the kernel dill: | ||
{ | ||
final myFile = File(dillPath); | ||
Uint8List bytes = myFile.readAsBytesSync(); | ||
// The SDK Hash is located after the ComponentFile and BinaryFormatVersion | ||
// tags (both UInt32). | ||
Expect.listEquals(tagComponentFile, bytes.sublist(0, 4)); | ||
Expect.listEquals(tagBinaryFormatVersion, bytes.sublist(4, 8)); | ||
// Flip the first byte in the hash: | ||
bytes[8] ^= bytes[8]; | ||
myFile.writeAsBytesSync(bytes); | ||
} | ||
|
||
{ | ||
final result = await Process.run(dart, [dillPath, '--child']); | ||
Expect.equals( | ||
'Can\'t load Kernel binary: Invalid SDK hash.\n', result.stderr); | ||
Expect.equals(253, result.exitCode); | ||
Expect.equals('', result.stdout); | ||
} | ||
|
||
// Zero out the SDK hash in the kernel dill to disable the check: | ||
{ | ||
final myFile = File(dillPath); | ||
Uint8List bytes = myFile.readAsBytesSync(); | ||
bytes.setRange(8, 18, ascii.encode('0000000000')); | ||
myFile.writeAsBytesSync(bytes); | ||
} | ||
|
||
{ | ||
final result = await Process.run(dart, [dillPath, '--child']); | ||
Expect.equals('', result.stderr); | ||
Expect.equals(0, result.exitCode); | ||
Expect.equals('Hello, SDK Hash!\n', result.stdout); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.