Rust asm! xpaci

unsafe { asm!("xpaci {0}", out(reg) p); }

error: invalid instruction mnemonic 'xpaci'

how to do ? Is xpaci incorrectly used?

in c lang :

/*
 * xpaci
 *
 * Description:
 * 	Strip a PACIx code from a pointer.
 */
static uint64_t
xpaci(uint64_t pointer) {
	asm("xpaci %[value]\n" : [value] "+r"(pointer));
	return pointer;
}

and in rust, "+r" how to do ?

Assuming you are working on a x86 machine, of course it isn't valid. You'll need to specify an ARM target first.

1 Like

thanks for your answer.

error: instruction requires: paut

you didn't show the full error message, but since it's related to inline assembler, I would assume the error is from the backend (i.e. llvm), and probably due to the specific instruction not available on the default (generic) target cpu.

after some searching, I think it's referring to the FEAT_PAUTH extension.

and I think it translates to either paca, pacg, or pauth-lr, or some combination of them, of the rust target feature names, based on the description of the output of rustc --print target-features --target aarch64-unknown-linux-gnu.

so try to apply rustc code gen flags to enable the specific features, something like:

RUSTFLAGS='-C target-feature=+paca,+pacg,+pauth-lr' cargo build --target aarch64-unknown-linux-gnu

or alternatively, maybe specify target-cpu instead of target-feature if you know exactly which cpu model you are targeting.

PS: your godbolt link doesn't work: it direct me to the home page (it might be working on your browser because of browser history though). to create a link with code, you should use the "Share" button on the upper right corner.


DISCLAIMER

I have not worked with aarch systems, the above information may not be accurate, it is purely based on searching result and my understanding of the documentation. aarch64 experts please correct me where it is wrong.

2 Likes

thanks for your answer.

Do you know the relationship between “-C target-feature=+pauth” and “-Z branch-protection=bti,pac-ret,leaf”?

according to branch_protection - The Rust Unstable Book, these are for the AArch64 target only, I have no idea what they mean.

1 Like