aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2017-05-04 16:21:27 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2017-05-04 16:48:20 +0000
commit8696993c4c3a92f2099e6160d516007a543f0116 (patch)
treedda345d385aad120ac7f687b95dfb72f3b192463
parent1af055c68544d86a1beb2dda1fb9be6eeffe0a7f (diff)
Fix crash in pre-cross-compiled ARMv7 code when host was 64-bit
When encoding negative offsets for relative jumps, we must stay within signed 32-bit range to correctly perform all the different thumb offset encodings correctly. Task-number: QTBUG-60441 Change-Id: I0a7243debbcbc4d557710dddbd39cb97bd702da4 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/3rdparty/masm/assembler/ARMv7Assembler.h22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/3rdparty/masm/assembler/ARMv7Assembler.h b/src/3rdparty/masm/assembler/ARMv7Assembler.h
index 615c72fc15..d57e5a7c78 100644
--- a/src/3rdparty/masm/assembler/ARMv7Assembler.h
+++ b/src/3rdparty/masm/assembler/ARMv7Assembler.h
@@ -2531,12 +2531,18 @@ private:
return (instruction[0] == OP_NOP_T2a) && (instruction[1] == OP_NOP_T2b);
}
+ static int32_t makeRelative(const void *target, const void *source)
+ {
+ intptr_t difference = reinterpret_cast<intptr_t>(target) - reinterpret_cast<intptr_t>(source);
+ return static_cast<int32_t>(difference);
+ }
+
static bool canBeJumpT1(const uint16_t* instruction, const void* target)
{
ASSERT(!(reinterpret_cast<intptr_t>(instruction) & 1));
ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
- intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
+ auto relative = makeRelative(target, instruction);
// It does not appear to be documented in the ARM ARM (big surprise), but
// for OP_B_T1 the branch displacement encoded in the instruction is 2
// less than the actual displacement.
@@ -2549,7 +2555,7 @@ private:
ASSERT(!(reinterpret_cast<intptr_t>(instruction) & 1));
ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
- intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
+ auto relative = makeRelative(target, instruction);
// It does not appear to be documented in the ARM ARM (big surprise), but
// for OP_B_T2 the branch displacement encoded in the instruction is 2
// less than the actual displacement.
@@ -2562,7 +2568,7 @@ private:
ASSERT(!(reinterpret_cast<intptr_t>(instruction) & 1));
ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
- intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
+ auto relative = makeRelative(target, instruction);
return ((relative << 11) >> 11) == relative;
}
@@ -2571,7 +2577,7 @@ private:
ASSERT(!(reinterpret_cast<intptr_t>(instruction) & 1));
ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
- intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
+ auto relative = makeRelative(target, instruction);
return ((relative << 7) >> 7) == relative;
}
@@ -2582,7 +2588,7 @@ private:
ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
ASSERT(canBeJumpT1(instruction, target));
- intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
+ auto relative = makeRelative(target, instruction);
// It does not appear to be documented in the ARM ARM (big surprise), but
// for OP_B_T1 the branch displacement encoded in the instruction is 2
// less than the actual displacement.
@@ -2600,7 +2606,7 @@ private:
ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
ASSERT(canBeJumpT2(instruction, target));
- intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
+ auto relative = makeRelative(target, instruction);
// It does not appear to be documented in the ARM ARM (big surprise), but
// for OP_B_T2 the branch displacement encoded in the instruction is 2
// less than the actual displacement.
@@ -2618,7 +2624,7 @@ private:
ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
ASSERT(canBeJumpT3(instruction, target));
- intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
+ auto relative = makeRelative(target, instruction);
// All branch offsets should be an even distance.
ASSERT(!(relative & 1));
@@ -2633,7 +2639,7 @@ private:
ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
ASSERT(canBeJumpT4(instruction, target));
- intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
+ auto relative = makeRelative(target, instruction);
// ARM encoding for the top two bits below the sign bit is 'peculiar'.
if (relative >= 0)
relative ^= 0xC00000;