From 6ed9a0817a5ab30e8f32aed0ecfa9c6c47071551 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Fri, 7 Sep 2018 12:47:06 +0200 Subject: properly align string table in compiled data Change-Id: Ie6534d5443ad046211620c4e0b586d189d0adbef Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4compiler.cpp | 4 +++- src/qml/compiler/qv4compiler_p.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index ede0f5cb86..f2e3aaedb5 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -92,13 +92,14 @@ void QV4::Compiler::StringTableGenerator::serialize(CompiledData::Unit *unit) { char *dataStart = reinterpret_cast(unit); quint32_le *stringTable = reinterpret_cast(dataStart + unit->offsetToStringTable); - char *stringData = reinterpret_cast(stringTable) + unit->stringTableSize * sizeof(uint); + char *stringData = reinterpret_cast(stringTable) + WTF::roundUpToMultipleOf(8, unit->stringTableSize * sizeof(uint)); for (int i = backingUnitTableSize ; i < strings.size(); ++i) { const int index = i - backingUnitTableSize; stringTable[index] = stringData - dataStart; const QString &qstr = strings.at(i); QV4::CompiledData::String *s = reinterpret_cast(stringData); + Q_ASSERT(reinterpret_cast(s) % alignof(QV4::CompiledData::String) == 0); s->refcount = -1; s->size = qstr.length(); s->allocAndCapacityReservedFlag = 0; @@ -664,6 +665,7 @@ QV4::CompiledData::Unit QV4::Compiler::JSUnitGenerator::generateHeader(QV4::Comp if (option == GenerateWithStringTable) { unit.stringTableSize = stringTable.stringCount(); + nextOffset = static_cast(WTF::roundUpToMultipleOf(8, nextOffset)); unit.offsetToStringTable = nextOffset; nextOffset += stringTable.sizeOfTableAndData(); } else { diff --git a/src/qml/compiler/qv4compiler_p.h b/src/qml/compiler/qv4compiler_p.h index a7520c0117..c4c886ffad 100644 --- a/src/qml/compiler/qv4compiler_p.h +++ b/src/qml/compiler/qv4compiler_p.h @@ -82,7 +82,7 @@ struct Q_QML_PRIVATE_EXPORT StringTableGenerator { QString stringForIndex(int index) const { return strings.at(index); } uint stringCount() const { return strings.size() - backingUnitTableSize; } - uint sizeOfTableAndData() const { return stringDataSize + stringCount() * sizeof(uint); } + uint sizeOfTableAndData() const { return stringDataSize + ((stringCount() * sizeof(uint) + 7) & ~7); } void freeze() { frozen = true; } -- cgit v1.2.3