Problem with inline assembly on RS6000/PowerPC

Gary Thomas g.thomas@opengroup.org
Wed Feb 18 23:05:00 GMT 1998


The following sequence generates different (i.e. incorrect) code on EGCS
than was generated by GCC-2.7.  Is this a bug or am I doing something
wrong?

#define _NR(n) #n
#define _lisc(n) "li 0," _NR(n)
#define __NR_write                4
#define __PPC_ERRNO                                                    
\
        "lis 9,errno@ha\n\t"                                           
\
        "stw 3,errno@l(9)"

#define __PPC_ERRNO_CLOBBER , "r9"

#define __PPC_SYSCALL(name,arg1,arg2,arg3,arg4,arg5)                   
\
do {                                                                   
\
  int result;                                                          
\
  __asm__ volatile (_lisc(__NR_##name)
"\n\t"                                   
\
           "sc\n\t"                                                    
\
           "bns+ 1f\n\t"                                               
\
           __PPC_ERRNO "\n\t"                                          
\
           "li 3,-1\n"                                                 
\
           "1:\t"                                                      
\
           : "=b" (result)                                             
\
           : "ri" (arg1), "ri" (arg2), "ri" (arg3), "ri" (arg4), "ri"
(arg5) \
           : "r3" __PPC_ERRNO_CLOBBER);                                
\
  return result;                                                       
\
} while (0)

#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
type name(type1 arg1,type2 arg2,type3 arg3) \
{ \
  __PPC_SYSCALL(name,arg1,arg2,arg3,0,0); \
}

static /*inline*/ _syscall3(int,write,int,fd,const char *,buf,int,count)


GCC-2.7.2 generated this output:

        .file   "good_sc.c"
gcc2_compiled.:
        .section ".text"
        .align 2
        .type    write,@function
write:
        mr 0,3
        li 0,4
        sc
        bns+ 1f
        lis 9,errno@ha
        stw 3,errno@l(9)
        li 3,-1
1:      
        blr

EGCS generates this:
        .file   "bad_sc.c"

 # rs6000/powerpc options: -msdata=data -G 8
 # GNU C version egcs-2.90.22 971220 (egcs-1.01 beta)
(powerpc-unknown-linux-gnu
libc1) compiled by GNU C version 2.8.0.
 # options passed:  -O2
 # options enabled:  -fdefer-pop -fomit-frame-pointer -fcse-follow-jumps
 # -fcse-skip-blocks -fexpensive-optimizations -fthread-jumps
 # -fstrength-reduce -fpeephole -fforce-mem -ffunction-cse -finline
 # -fkeep-static-consts -fcaller-saves -fpcc-struct-return
 # -frerun-cse-after-loop -frerun-loop-opt -fschedule-insns
 # -fschedule-insns2 -fsched-interblock -fsched-spec -fsjlj-exceptions
 # -fcommon -fverbose-asm -fgnu-linker -fregmove -falias-check
 # -fargument-alias -mpowerpc -mnew-mnemonics -mcall-sysv -msdata=data

gcc2_compiled.:
        .section ".text"
        .align 2
        .type    write,@function
write:
        mr 0,3
        li 0,4
        sc
        bns+ 1f
        lis 9,errno@ha
        stw 3,errno@l(9)
        li 3,-1
1:      
        mr 3,11
        blr
.Lfe1:
        .size    write,.Lfe1-write
        .ident  "GCC: (GNU) egcs-2.90.22 971220 (egcs-1.01 beta)"

Notice the 'mr 3,11' near the end.  This is the key difference; it makes
the function
return the wrong (totally bogus) value.


------------------------------------------------------------------------
Gary Thomas                              |
The Open Group / Research Institute      | "Fine wine is a necessity of
2 Avenue de Vignate                      |        life for me"
38610 Gieres - FRANCE                    |
+33 4 76 63 48 74                        |      Thomas Jefferson
email: g.thomas@opengroup.org            |
< http://www.opengroup.org/~gdt >          |
   ... opinions expressed here are mine  |
       and no one else would claim them! |
------------------------------------------------------------------------



More information about the Gcc-bugs mailing list