dinuxbg / gnupru

GCC and Binutils port for the TI PRU I/O processor
92 stars 11 forks source link

Inline ASM clobber for SP is not honored #31

Closed dinuxbg closed 5 years ago

dinuxbg commented 6 years ago

r2 (stack pointer) is special and the clobber is not honored by the compiler.

dinuxbg commented 6 years ago

Issue is also reproduced for x86. Reduced test case:

extern void abort (void);

int
test1 (void)
{
  int res;

#ifdef __PRU__
  asm volatile(
           "ldi %[res], 101     \n\t"
           "ldi32   sp, 0xaa55aa55      \n\t"
           : [res] "=r" (res)
           :
           : "sp");
#else
  asm volatile(
           "movl    $101, %[res]        \n\t"
           "movq    $0xaa55aa55, %%rsp  \n\t"
           "movq    $0xaa55aa55, %%rbp  \n\t"
           : [res] "=r" (res)
           :
           : "%rsp", "%rbp");
#endif

  return res;
}

int
main (int argc, char** argv)
{
  if (test1 () != 101)
    abort();

  return 0;
}
dinuxbg commented 6 years ago

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52813

dinuxbg commented 5 years ago

https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00532.html