--- /dev/null
+# $OpenBSD: Makefile,v 1.1 2024/02/23 21:33:51 kettenis Exp $
+
+.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "aarch64"
+
+PROG= foobar
+OBJS= foo.o
+
+.if ${MACHINE_ARCH} == "aarch64"
+NOBTCFI_CFLAGS= -mbranch-protection=none
+.else
+NOBTCFI_CFLAGS= -fcf-protection=none
+.endif
+
+foo.o: foo.c
+ ${COMPILE.c} ${NOBTCFI_CFLAGS} ${.CURDIR}/foo.c -o foo.o
+
+.elif make(regress) || make(all)
+regress:
+ @echo Cannot run on ${MACHINE_ARCH}.
+ @echo SKIPPED
+.endif
+.include <bsd.regress.mk>
--- /dev/null
+/* Public domain */
+
+#include <signal.h>
+#include <stdlib.h>
+
+extern void foo(void);
+void (*foobar)(void) = foo;
+
+void
+bar(void)
+{
+ foobar();
+}
+
+void
+handler(int sig, siginfo_t *si, void *context)
+{
+ if (si->si_signo == SIGILL && si->si_code == ILL_BTCFI)
+ exit(0);
+}
+
+int
+main(void)
+{
+ struct sigaction sa;
+
+ sa.sa_sigaction = handler;
+ sa.sa_mask = 0;
+ sa.sa_flags = SA_SIGINFO;
+ sigaction(SIGILL, &sa, NULL);
+
+ bar();
+ exit(1);
+}