Increase alignment when concatenating AOT runtime and ELF snapshots.
Allow for segment padding when testing that strip decreases snapshot size.
Cf. bc21edaf1719db02ebb4815e2f3bff9fef488d9d.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/42773
Change-Id: Icf533b2caa756488e17856495f3877fb779d2faf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196040
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
diff --git a/pkg/dart2native/lib/dart2native.dart b/pkg/dart2native/lib/dart2native.dart
index a6d1deb..3e51b53 100644
--- a/pkg/dart2native/lib/dart2native.dart
+++ b/pkg/dart2native/lib/dart2native.dart
@@ -5,7 +5,9 @@
import 'dart:io';
import 'dart:typed_data';
-const appSnapshotPageSize = 4096;
+// Maximum page size across all supported architectures (arm64 macOS has 16K
+// pages, the rest are all 4k pages).
+const elfPageSize = 16384;
const appjitMagicNumber = <int>[0xdc, 0xdc, 0xf6, 0xf6, 0, 0, 0, 0];
enum Kind { aot, exe }
@@ -15,8 +17,7 @@
final dartaotruntime = File(dartaotruntimePath);
final int dartaotruntimeLength = dartaotruntime.lengthSync();
- final padding =
- ((appSnapshotPageSize - dartaotruntimeLength) % appSnapshotPageSize);
+ final padding = ((elfPageSize - dartaotruntimeLength) % elfPageSize);
final padBytes = Uint8List(padding);
final offset = dartaotruntimeLength + padding;
diff --git a/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart b/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart
index 11abcb0..0520b9d 100644
--- a/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart
+++ b/runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart
@@ -135,7 +135,13 @@
stripPrefix = "externally stripped ";
}
- Expect.approxEquals(expected, actual, 0.03 * actual,
+ // See Elf::kPages in runtime/vm/elf.h.
+ final segmentAlignment = 16384;
+ // Not every byte is accounted for by the snapshot profile, and data and
+ // instruction segments are padded to an alignment boundary.
+ final tolerance = 0.03 * actual + 2 * segmentAlignment;
+
+ Expect.approxEquals(expected, actual, tolerance,
"failed on $bareUsed $stripPrefix$fileType snapshot type.");
});
}
diff --git a/runtime/tests/vm/dart_2/v8_snapshot_profile_writer_test.dart b/runtime/tests/vm/dart_2/v8_snapshot_profile_writer_test.dart
index 8778573..3d88b62 100644
--- a/runtime/tests/vm/dart_2/v8_snapshot_profile_writer_test.dart
+++ b/runtime/tests/vm/dart_2/v8_snapshot_profile_writer_test.dart
@@ -135,7 +135,13 @@
stripPrefix = "externally stripped ";
}
- Expect.approxEquals(expected, actual, 0.03 * actual,
+ // See Elf::kPages in runtime/vm/elf.h.
+ final segmentAlignment = 16384;
+ // Not every byte is accounted for by the snapshot profile, and data and
+ // instruction segments are padded to an alignment boundary.
+ final tolerance = 0.03 * actual + 2 * segmentAlignment;
+
+ Expect.approxEquals(expected, actual, tolerance,
"failed on $bareUsed $stripPrefix$fileType snapshot type.");
});
}