~mpu/qbe

Revert "revert 5af33410" v1 PROPOSED

Chenguang Wang: 1
 Revert "revert 5af33410"

 2 files changed, 2 insertions(+), 1 deletions(-)
I don't think so:

    qbe $ ./qbe test/tls.ssa | tail -n17
    
    .text
    xvalcnt:
            .cfi_startproc
            pushq %rbp
            movq %rsp, %rbp
            movq %fs:0, %rax
            leaq x@tpoff(%rax), %rax
            movl (%rax, %rdi, 4), %eax
            leave
            ret
    .type xvalcnt, @function
    .size xvalcnt, .-xvalcnt
            .cfi_endproc
    /* end function xvalcnt */
    
    .section .note.GNU-stack,"",@progbits

    qbe $ ./tools/test.sh test/tls.ssa
    tls.ssa...                                   --- -      Sun Apr 28 15:53:11 2024
    +++ /tmp/qbe.zzzz.out   Sun Apr 28 15:53:11 2024
    @@ -0,0 +1,6 @@
    +i0==42
    +i1==402653226
    +*(x+0)==1
    +*(x+4)==2
    +*(x+8)==3
    +*(x+12)==4
    Illegal instruction 
    [output fail]

Same error as without .cfi_{start,end}proc.
If code size is a concern, maybe emit endbr64 on OpenBSD only?
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/51142/mbox | git am -3
Learn more about email & git

[PATCH] Revert "revert 5af33410" Export this patch

This reverts commit 4bc4c9584a13736c20855cdea2203d3bd0a259a3.

We can re-enable BTI now, since the stock `as` in OpenBSD 7.5 seems to
support it:

    qbe $ ./qbe test/tls.ssa > /tmp/tls.s
    qbe $ grep endbr64 /tmp/tls.s | uniq -c
       6    endbr64
    qbe $ as /tmp/tls.s -o /tmp/tls.o
    qbe $ ls -al /tmp/tls.o
    -rw-r--r--  1 w  wheel  2312 Apr 19 06:57 /tmp/tls.o

isel4.ssa and tls.ssa currently fail with SIGILL on my machine. This
commit fixes that.
---
 amd64/emit.c | 2 +-
 arm64/emit.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/amd64/emit.c b/amd64/emit.c
index 9636209..65fc9dc 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -581,7 +581,7 @@ amd64_emitfn(Fn *fn, FILE *f)
	uint64_t fs;

	emitfnlnk(fn->name, &fn->lnk, f);
	fputs("\tpushq %rbp\n\tmovq %rsp, %rbp\n", f);
	fputs("\tendbr64\n\tpushq %rbp\n\tmovq %rsp, %rbp\n", f);
	fs = framesz(fn);
	if (fs)
		fprintf(f, "\tsubq $%"PRIu64", %%rsp\n", fs);
diff --git a/arm64/emit.c b/arm64/emit.c
index 990d839..6363271 100644
--- a/arm64/emit.c
+++ b/arm64/emit.c
@@ -514,6 +514,7 @@ arm64_emitfn(Fn *fn, FILE *out)
	if (T.apple)
		e->fn->lnk.align = 4;
	emitfnlnk(e->fn->name, &e->fn->lnk, e->f);
	fputs("\thint\t#34\n", e->f);
	framelayout(e);

	if (e->fn->vararg && !T.apple) {
-- 
2.44.0