Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "[SDK] Adds an SDK hash to kernels and the VM."
Note: This is a reland of https://dart-review.googlesource.com/c/sdk/+/150343 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. This also bumps the min. and current ABI version. Bug: #41802 Change-Id: I2f85945045a603eb9dcfd1f2c0d0d024bd84a956 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152802 Commit-Queue: Clement Skau <cskau@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
- Loading branch information
Clement Skau
authored and
commit-bot@chromium.org
committed
Jul 7, 2020
1 parent
315ecf2
commit 0ce8398
Showing
28 changed files
with
511 additions
and
198 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!', result.stdout.trim()); | ||
} | ||
|
||
// 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.', result.stderr.trim()); | ||
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!', result.stdout.trim()); | ||
} | ||
}); | ||
} |
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.