~mpu/qbe

Fix IBT/BTI by instrumenting function calls v1 APPLIED

Tobias Heider: 1
 Fix IBT/BTI by instrumenting function calls

 2 files changed, 4 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mpu/qbe/patches/47321/mbox | git am -3
Learn more about email & git

[PATCH] Fix IBT/BTI by instrumenting function calls Export this patch

---
This is needed to work with struct BTI enforcement as is the default
now on OpenBSD. The instructions should evaluate to nops on non-supported
hardware.

The reason I use hint #34 instead of bti c for arm64 is that the gnu
assembler doesn't like bti instructions unless it is explicitly enabled,
see https://reviews.llvm.org/D81257

 amd64/emit.c | 2 ++
 arm64/emit.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/amd64/emit.c b/amd64/emit.c
index 297cc76..a39b1b6 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -581,6 +581,8 @@ amd64_emitfn(Fn *fn, FILE *f)
	uint64_t fs;

	emitfnlnk(fn->name, &fn->lnk, f);
	/* ibt */
	fputs("\tendbr64\n", f);
	fputs("\tpushq %rbp\n\tmovq %rsp, %rbp\n", f);
	fs = framesz(fn);
	if (fs)
diff --git a/arm64/emit.c b/arm64/emit.c
index 78a0358..0c121cb 100644
--- a/arm64/emit.c
+++ b/arm64/emit.c
@@ -514,6 +514,8 @@ arm64_emitfn(Fn *fn, FILE *out)
	if (T.apple)
		e->fn->lnk.align = 4;
	emitfnlnk(e->fn->name, &e->fn->lnk, e->f);
	/* bti */
	fputs("\thint\t#34\n", e->f);
	framelayout(e);

	if (e->fn->vararg && !T.apple) {
-- 
2.43.0
Thanks, it's applied and pushed to master.