Skip to content

Commit e59a1f3

Browse files
committed
Introduce helper function for loading LowTCA
In facebook#117, I changed back the hardcoded `loadzlq` instructions added by 1702bae to `emitLdPackedPtr` as it was before. That was wrong because LowTCA will be 64 bits on PIE builds but 32 bits otherwise, whereas `emitLdPackedPtr` uses the size of `PackedPtr` which is always 64 bits in non-lowptr builds. Pandemonium ensues as a result. So, introduce a new helper here that uses the correct size of LowTCA.
1 parent e4c19e0 commit e59a1f3

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

hphp/runtime/vm/jit/code-gen-helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ void emitLdPackedPtr(Vout& v, Vptr mem, Vreg reg) {
6363
ldLowPtrImpl(v, mem, reg, PackedPtr<T>::bits);
6464
}
6565

66+
inline void emitLdTCAPtr(Vout& v, Vptr mem, Vreg reg) {
67+
ldLowPtrImpl(v, mem, reg, LowTCA::bits);
68+
}
69+
6670
/*
6771
* Store the LowPtr<T> in `reg' into `mem', with storage size `size'.
6872
*/

hphp/runtime/vm/jit/irlower-call.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void cgCall(IRLS& env, const IRInstruction* inst) {
156156
auto const pTabOff = safe_cast<int32_t>(Func::prologueTableOff());
157157
auto const ptrSize = safe_cast<int32_t>(sizeof(LowTCA));
158158
auto const dest = v.makeReg();
159-
emitLdPackedPtr<uint8_t>(v, r_func_prologue_callee()[numArgsInclUnpack * ptrSize + pTabOff], dest);
159+
emitLdTCAPtr(v, r_func_prologue_callee()[numArgsInclUnpack * ptrSize + pTabOff], dest);
160160
v << callphpr{dest, func_prologue_regs(withCtx)};
161161
} else {
162162
// It was not statically determined that the arguments are passed in a way
@@ -236,7 +236,7 @@ void cgCallFuncEntry(IRLS& env, const IRInstruction* inst) {
236236
// Load the FuncEntry address dynamically from the function.
237237
auto dest = v.makeReg();
238238
auto const funcEntryOff = safe_cast<int32_t>(Func::funcEntryOff());
239-
emitLdPackedPtr<uint8_t>(v, callee[funcEntryOff], dest);
239+
emitLdTCAPtr(v, callee[funcEntryOff], dest);
240240
// We have to use an ifdef instead of `if (use_lowptr)` here due to
241241
// funcIdOffset only being defined in non-lowptr mode.
242242
#ifdef USE_LOWPTR

hphp/runtime/vm/jit/unique-stubs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ TCA emitFuncPrologueRedispatch(CodeBlock& cb, DataBlock& data, const char* name)
300300
ifThen(v, CC_LE, sf, [&] (Vout& v) {
301301
// Fast path (numArgs <= numNonVariadicParams). Call the numArgs prologue.
302302
auto const dest = v.makeReg();
303-
emitLdPackedPtr<uint8_t>(v, callee[numArgs * ptrSize + pTabOff], dest);
303+
emitLdTCAPtr(v, callee[numArgs * ptrSize + pTabOff], dest);
304304
v << jmpr{dest, func_prologue_regs(true)};
305305
});
306306

@@ -364,7 +364,7 @@ TCA emitFuncPrologueRedispatch(CodeBlock& cb, DataBlock& data, const char* name)
364364

365365
// Call the numNonVariadicParams + 1 prologue.
366366
auto const dest = v.makeReg();
367-
emitLdPackedPtr<uint8_t>(
367+
emitLdTCAPtr(
368368
v,
369369
Vreg(r_func_prologue_callee())[numNewArgs * ptrSize + pTabOff],
370370
dest
@@ -426,7 +426,7 @@ TCA emitFuncPrologueRedispatchUnpack(CodeBlock& main, CodeBlock& cold,
426426
auto const pTabOff = safe_cast<int32_t>(Func::prologueTableOff());
427427
auto const ptrSize = safe_cast<int32_t>(sizeof(LowTCA));
428428
auto const dest = v.makeReg();
429-
emitLdPackedPtr<uint8_t>(v, callee[numNewArgs * ptrSize + pTabOff], dest);
429+
emitLdTCAPtr(v, callee[numNewArgs * ptrSize + pTabOff], dest);
430430
v << tailcallstubr{dest, func_prologue_regs(true)};
431431
}, name);
432432

0 commit comments

Comments
 (0)