Reland "[snapshot] Align internal snapshot data"

This is a reland of 4f9d7a94a1

Original change's description:
> [snapshot] Align internal snapshot data
>
> When the snapshot blob is not aligned properly, loading it can cause a
> crash on platforms such as arm.
>
> This was exposed by a SIGBUS/BUS_ADRALN crash on arm when accessing
> the blob_data symbol (declared as a byte array) through a reinterpret
> cast to uintptr_t in an internal snapshot build.
>
> Thanks to florian.dold@gmail.com for the initial patch.
>
> Bug: v8:9171
> Change-Id: I99b071dec3733416f2f01b58a770e30d8f2dcdf2
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1582402
> Commit-Queue: Dan Elphick <delphick@chromium.org>
> Auto-Submit: Jakob Gruber <jgruber@chromium.org>
> Reviewed-by: Dan Elphick <delphick@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#61000}

Tbr: delphick@chromium.org
Bug: v8:9171
Change-Id: I36f53647ff5c45bcc512147f082fdd069723175d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1587377
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61062}
This commit is contained in:
Jakob Gruber 2019-04-29 08:46:37 +02:00 committed by Commit Bot
parent 411fd9cfd6
commit dd8e820cc7
2 changed files with 9 additions and 2 deletions

View File

@ -87,7 +87,8 @@ class SnapshotFileWriter {
static void WriteSnapshotFileData(FILE* fp,
const i::Vector<const i::byte>& blob) {
fprintf(fp, "static const byte blob_data[] = {\n");
fprintf(fp,
"alignas(kPointerAlignment) static const byte blob_data[] = {\n");
WriteBinaryContentsAsCArray(fp, blob);
fprintf(fp, "};\n");
fprintf(fp, "static const int blob_size = %d;\n", blob.length());

View File

@ -375,8 +375,14 @@ class Checksum {
// Fletcher's checksum. Modified to reduce 64-bit sums to 32-bit.
uintptr_t a = 1;
uintptr_t b = 0;
const uintptr_t* cur = reinterpret_cast<const uintptr_t*>(payload.start());
// TODO(jgruber, v8:9171): The following DCHECK should ideally hold since we
// access payload through an uintptr_t pointer later on; and some
// architectures, e.g. arm, may generate instructions that expect correct
// alignment. However, we do not control alignment for external snapshots.
// DCHECK(IsAligned(reinterpret_cast<intptr_t>(payload.start()),
// kIntptrSize));
DCHECK(IsAligned(payload.length(), kIntptrSize));
const uintptr_t* cur = reinterpret_cast<const uintptr_t*>(payload.start());
const uintptr_t* end = cur + payload.length() / kIntptrSize;
while (cur < end) {
// Unsigned overflow expected and intended.