tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] asmtest problem


From: grischka
Subject: [Tinycc-devel] asmtest problem
Date: Wed, 19 Oct 2016 21:58:41 +0200
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Hi, well Michael (who else ;)

There seems to be a asm problem in tcctest.c with the bts
instruction on x86-64, which crashes it under circumstances.

Simple version:

#include <stdio.h>
int main (int argc, char **argv)
{
    unsigned set = 0;
    unsigned *pset = &set;
    unsigned _sig = 21;

    __asm__("bts %1,%0" : "=m"(*pset) : "Ir"(_sig - 1) : "cc");

    printf("set %08x\n", set);
    return 0;
}

From dump:
  3d:   8b 45 d0                mov    -0x30(%rbp),%eax <-- address
  Here it should load the addres into %rax, not %eax

  40:   8b 4d c8                mov    -0x38(%rbp),%ecx <-- bit number

  Here it shoud not use the '67' prefix
  43:   67 0f ab 08             addr32 bts %ecx,(%eax)

Please help,

--- grischka


./tcc -B. -g -c test.c && objdump -S test.o
test.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <main>:

#include <stdio.h>
int main (int argc, char **argv)
{
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 81 ec 40 00 00 00    sub    $0x40,%rsp
   b:   48 89 7d f8             mov    %rdi,-0x8(%rbp)
   f:   48 89 75 f0             mov    %rsi,-0x10(%rbp)
  13:   b8 00 00 00 00          mov    $0x0,%eax
  18:   89 45 ec                mov    %eax,-0x14(%rbp)
  1b:   48 8d 45 ec             lea    -0x14(%rbp),%rax
  1f:   48 89 45 e0             mov    %rax,-0x20(%rbp)
  23:   b8 15 00 00 00          mov    $0x15,%eax
  28:   89 45 dc                mov    %eax,-0x24(%rbp)
    unsigned set = 0;
    unsigned *pset = &set;
    unsigned _sig = 21;

    __asm__("bts %1,%0" : "=m"(*pset) : "Ir"(_sig - 1) : "cc");
  2b:   48 8b 45 e0             mov    -0x20(%rbp),%rax
  2f:   8b 4d dc                mov    -0x24(%rbp),%ecx
  32:   83 e9 01                sub    $0x1,%ecx
  35:   48 89 45 d0             mov    %rax,-0x30(%rbp)
  39:   48 89 4d c8             mov    %rcx,-0x38(%rbp)
  3d:   8b 45 d0                mov    -0x30(%rbp),%eax
  40:   8b 4d c8                mov    -0x38(%rbp),%ecx
  43:   67 0f ab 08             addr32 bts %ecx,(%eax)

    printf("set %08x\n", set);
  47:   8b 45 ec                mov    -0x14(%rbp),%eax
  4a:   48 89 c6                mov    %rax,%rsi
  4d:   48 8d 05 00 00 00 00    lea    0x0(%rip),%rax
  54:   48 89 c7                mov    %rax,%rdi
  57:   b8 00 00 00 00          mov    $0x0,%eax
  5c:   e8 00 00 00 00          callq  61 <main+0x61>
    return 0;
  61:   b8 00 00 00 00          mov    $0x0,%eax
  66:   c9                      leaveq
  67:   c3                      retq




reply via email to

[Prev in Thread] Current Thread [Next in Thread]