diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-01-05 15:49:19 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-01-07 20:14:45 +0000 |
commit | 8d83267dced1b36145421ae1bf5eee6209400d76 (patch) | |
tree | 54b95c3a8efed8556438009f0b65e72ae66836cd /src/qml/compiler | |
parent | d1e7e5cd7d5eb601541dcc4860ce11a63048d35d (diff) |
Prospective fix for big endian and AOT
Ensure that the integer arguments for widely encoded instructions are
always encoded as little endian.
Change-Id: Iccd45aefb20b20d76fe1618d6706435142b202b9
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qv4bytecodegenerator.cpp | 16 | ||||
-rw-r--r-- | src/qml/compiler/qv4instr_moth_p.h | 4 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator.cpp b/src/qml/compiler/qv4bytecodegenerator.cpp index 0becabe95f..efa4b36f05 100644 --- a/src/qml/compiler/qv4bytecodegenerator.cpp +++ b/src/qml/compiler/qv4bytecodegenerator.cpp @@ -76,7 +76,9 @@ void BytecodeGenerator::packInstruction(I &i) type -= MOTH_NUM_INSTRUCTIONS(); int instructionsAsInts[sizeof(Instr)/sizeof(int)]; int nMembers = Moth::InstrInfo::argumentCount[static_cast<int>(i.type)]; - memcpy(instructionsAsInts, i.packed + 1, nMembers*sizeof(int)); + for (int j = 0; j < nMembers; ++j) { + instructionsAsInts[j] = qFromLittleEndian<qint32>(i.packed + 1 + j * sizeof(int)); + } enum { Normal, Wide @@ -122,7 +124,7 @@ void BytecodeGenerator::adjustJumpOffsets() uchar type = *reinterpret_cast<const uchar *>(i.packed); if (type >= MOTH_NUM_INSTRUCTIONS()) { Q_ASSERT(i.offsetForJump == i.size - 4); - memcpy(c, &jumpOffset, sizeof(int)); + qToLittleEndian<qint32>(jumpOffset, c); } else { Q_ASSERT(i.offsetForJump == i.size - 1); qint8 o = jumpOffset; @@ -198,7 +200,8 @@ QT_WARNING_POP const int pos = instructions.size(); - int s = Moth::InstrInfo::argumentCount[static_cast<int>(type)]*sizeof(int); + const int argCount = Moth::InstrInfo::argumentCount[static_cast<int>(type)]; + int s = argCount*sizeof(int); if (offsetOfOffset != -1) offsetOfOffset += 1; I instr{type, static_cast<short>(s + 1), 0, currentLine, offsetOfOffset, -1, "\0\0" }; @@ -206,7 +209,12 @@ QT_WARNING_POP *reinterpret_cast<uchar *>(code) = static_cast<uchar>(MOTH_NUM_INSTRUCTIONS() + static_cast<int>(type)); ++code; Q_ASSERT(MOTH_NUM_INSTRUCTIONS() + static_cast<int>(type) < 256); - memcpy(code, &i, s); + + for (int j = 0; j < argCount; ++j) { + qToLittleEndian<qint32>(i.argumentsAsInts[j], code); + code += sizeof(int); + } + instructions.append(instr); return pos; diff --git a/src/qml/compiler/qv4instr_moth_p.h b/src/qml/compiler/qv4instr_moth_p.h index 789f875ba7..eb25aad110 100644 --- a/src/qml/compiler/qv4instr_moth_p.h +++ b/src/qml/compiler/qv4instr_moth_p.h @@ -356,7 +356,7 @@ QT_BEGIN_NAMESPACE nargs, #define MOTH_DECODE_ARG(arg, type, nargs, offset) \ - arg = reinterpret_cast<const type *>(code)[-nargs + offset]; + arg = qFromLittleEndian<type>(reinterpret_cast<const type *>(code)[-nargs + offset]); #define MOTH_ADJUST_CODE(type, nargs) \ code += static_cast<quintptr>(nargs*sizeof(type) + 1) @@ -486,6 +486,8 @@ union Instr FOR_EACH_MOTH_INSTR(MOTH_EMIT_STRUCTS) FOR_EACH_MOTH_INSTR(MOTH_EMIT_INSTR_MEMBERS) + + int argumentsAsInts[4]; }; struct InstrInfo |