Op 24-06-2025 om 22:18 schreef Herman ten Brugge:
The recent change to atomic functions has some problems.
I fixed one. See https://repo.or.cz/tinycc.git/commitdiff/32b597746c1c9da4656ef34e2930c604f6c13c81

Another problem is the arm code. It uses tumb code. But this should be armv6k.

The old code had:

#ifndef __TINYC__
        .arch armv6k
        .syntax unified
#endif

The new code is:

        .thumb
        .syntax unified

tcc does not support .thumb or  .syntax unified.
If I disassemble the tcc code for atomic_flag_clear I get:

00022a34 <atomic_flag_clear>:
   22a34:       f3bf2300        vsubw.u<illegal width 64>       q1, <illegal reg q7.5>, d0    22a38:       f3bf7003        vaddl.u<illegal width 64>       <illegal reg q3.5>, d15, d3
   22a3c:       Address 0x22a3c is out of bounds.

Also the windows code does not work. The endbr32 is not supported.
If I remove this the testcase 125_atomic_misc and testcase 136_atomic_gcc_style fail for i386.

I debugged the windows code some more and found that it was x86_64 failing instead of i386. The problems is that windows uses a different calling convention. See arg_regs in x86_64-gen.c.
I implemented the endbr32 in tcc. See attachment.

So arm code should use armv6k instead of thumb and x86_64 should use different calling
convention for windows.

    Herman

    Herman
diff --git a/i386-asm.c b/i386-asm.c
index 470b20e..022d4ab 100644
--- a/i386-asm.c
+++ b/i386-asm.c
@@ -1016,6 +1016,16 @@ again:
              tcc_error("bad MODR/M opcode without operands");
            goto modrm_found;
        }
+#else
+       if (!nb_ops) {
+           i = 0;
+           ops[i].type = OP_REG;
+           if (pa->sym == TOK_ASM_endbr32)
+             ops[i].reg = 3; // bx
+           else
+             tcc_error("bad MODR/M opcode without operands");
+           goto modrm_found;
+       }
 #endif
         /* first look for an ea operand */
         for(i = 0;i < nb_ops; i++) {
diff --git a/i386-asm.h b/i386-asm.h
index 0f99b28..107fd3d 100644
--- a/i386-asm.h
+++ b/i386-asm.h
@@ -37,7 +37,10 @@
      DEF_ASM_OP0(pause, 0xf390)
      DEF_ASM_OP0(xlat, 0xd7)
 
-     /* strings */
+    /* Control-Flow Enforcement */
+    DEF_ASM_OP0L(endbr32, 0xf30f1e, 7, OPC_MODRM)
+
+    /* strings */
 ALT(DEF_ASM_OP0L(cmpsb, 0xa6, 0, OPC_BWLX))
 ALT(DEF_ASM_OP0L(scmpb, 0xa6, 0, OPC_BWLX))
 
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to