DynamoRIO / dynamorio

Dynamic Instrumentation Tool Platform
Other
2.57k stars 551 forks source link

AArch64 Regression: Failure to encode XPACI after PR #5835 #6276

Open derekbruening opened 10 months ago

derekbruening commented 10 months ago

We have a regression: hello,world (simple_app) used to run to completion on Mac M1 AArch64 but now it fails. I ran a git bisect and it found f646a632d5fe80c34210a3ee890502919f3443a9 == PR #5835 as the culprit.

Before PR #5835:

$ bin64/drrun -- suite/tests/bin/simple_app
...
<other logs including "Undefined HINT instruction found: encoding 0xd503245f (CRm:op2 0x22)">
Hello, world!
<Stopping application /Users/bruening/dr/git/build_m1_dbg/suite/tests/bin/simple_app (24493)>

After PR #5835:

$ bin64/drrun -- suite/tests/bin/simple_app
...
<Internal Error: Failed to encode instruction: 'xpaci  %x2 -> %x2'
>
<Application /Users/bruening/dr/git/build_m1_dbg/suite/tests/bin/simple_app (22028).  Internal Error: DynamoRIO debug check failure: /Users/bruening/dr/git/src/core/emit.c:363 pc != NULL

That XPACI is coming from DR itself I believe:

$ git grep -i xpaci
core/arch/aarchxx/mangle.c:        PRE(ilist, instr, INSTR_CREATE_xpaci(dcontext, opnd_create_reg(IBL_TARGET_REG)));
core/arch/aarchxx/mangle.c:        PRE(ilist, instr, INSTR_CREATE_xpaci(dcontext, opnd_create_reg(IBL_TARGET_REG)));
derekbruening commented 9 months ago

An action item is to add instances of XPACI to the api.ir tests so we can try to have regression tests of this.

derekbruening commented 9 months ago

From @AssadHashmi : since the culprit PR did not change codec.txt, maybe the problem comes from the feature change and now the encoder thinks that XPACI is not available.

An update to the api.ir tests comment https://github.com/DynamoRIO/dynamorio/issues/6276#issuecomment-1731634120: we do already have tests of XPACI, and presumably they never failed.

jackgallagher-arm commented 1 week ago

The problem here is that feature detection is not implemented for AArch64 on macOS. When we try to emit the XPACI instruction the encoder thinks that PAUTH is not supported by the processor so it fails to encode it.

The proper fix is to implement AArch64 feature detection on macOS, but in the mean time as a quick fix we could just hard-code enable PAUTH on macOS by adding

#if defined(MACOS)
proc_set_feature(FEATURE_PAUTH, true);
#endif

to get_processor_specific_info() in core/arch/aarch64/proc.c