From 8d83267dced1b36145421ae1bf5eee6209400d76 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 5 Jan 2018 15:49:19 +0100 Subject: 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 --- src/qml/compiler/qv4bytecodegenerator.cpp | 16 ++++++++++++---- src/qml/compiler/qv4instr_moth_p.h | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/qml/compiler') 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(i.type)]; - memcpy(instructionsAsInts, i.packed + 1, nMembers*sizeof(int)); + for (int j = 0; j < nMembers; ++j) { + instructionsAsInts[j] = qFromLittleEndian(i.packed + 1 + j * sizeof(int)); + } enum { Normal, Wide @@ -122,7 +124,7 @@ void BytecodeGenerator::adjustJumpOffsets() uchar type = *reinterpret_cast(i.packed); if (type >= MOTH_NUM_INSTRUCTIONS()) { Q_ASSERT(i.offsetForJump == i.size - 4); - memcpy(c, &jumpOffset, sizeof(int)); + qToLittleEndian(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(type)]*sizeof(int); + const int argCount = Moth::InstrInfo::argumentCount[static_cast(type)]; + int s = argCount*sizeof(int); if (offsetOfOffset != -1) offsetOfOffset += 1; I instr{type, static_cast(s + 1), 0, currentLine, offsetOfOffset, -1, "\0\0" }; @@ -206,7 +209,12 @@ QT_WARNING_POP *reinterpret_cast(code) = static_cast(MOTH_NUM_INSTRUCTIONS() + static_cast(type)); ++code; Q_ASSERT(MOTH_NUM_INSTRUCTIONS() + static_cast(type) < 256); - memcpy(code, &i, s); + + for (int j = 0; j < argCount; ++j) { + qToLittleEndian(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(code)[-nargs + offset]; + arg = qFromLittleEndian(reinterpret_cast(code)[-nargs + offset]); #define MOTH_ADJUST_CODE(type, nargs) \ code += static_cast(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 -- cgit v1.2.3