Assembly error on Sun Studio 11 - Solaris 10/amd64

Hi All

I am compiling my source code using cc. My cc version is

cc: Sun C 5.8 2005/10/13

I am using Sun Studio 11 and Solaris 10 on amd64 for my build.

I am getting following Assemply errors when compiling my code.

cc -xarch=amd64 -Kpic gptas.c

Assembler:

"/tmp/yabeAAALdaqGz", line 31 : Illegal mnemonic

"/tmp/yabeAAALdaqGz", line 34 : Syntax error

"/tmp/yabeAAALdaqGz", line 37 : Syntax error

"/tmp/yabeAAALdaqGz", line 50 : Illegal mnemonic

Failure in /opt/ss11/SUNWspro/prod/bin/fbe, status = 0x7f00

Fatal Error exec'ing /opt/ss11/SUNWspro/prod/bin/fbe

cc: acomp failed for gptas.c

The c code which I'm trying to compile:

/*ARGSUSED*/

int

#if defined(__STDC__) || defined(__cplusplus)

_gp_tas(unsigned *x, short flag)

#else

_gp_tas(x,flag)

unsigned *x;

short flag;

#endif

{

#ifdef __STDC__

volatile int r; /* volatile so optimizers won't get

* rid of variable - some assembly code

* depends on offsets with this on

* the stack.

*/

#else

int r; /* var to return explicitly */

#endif

r = 0; /* always set return to 0*/

asm("movl$1,%eax");/* this 1 inworking reg will set *x */

asm("pushl%ebx"); /* save the register; eax already saved */

asm("movl8(%ebp),%ebx"); /* move the address of x */

asm("xchg%eax,(%ebx)"); /* atomic swap a one with *x */

asm("cmp$0,%eax");/* test what was in *x */

asm("jnz.A9999");/* jump if *x was already set */

r = 1; /* indicate set occurred */

asm(".A9999:");

asm("popl%ebx"); /* restore the register */

return(r);

}

Can someone let me know if this is a Compiler issue or it has something to do with my code .

I'll Appreciate any help on this.

Thanks in Advance

Somak

[1911 byte] By [dsomak] at [2007-11-26 10:08:16]
# 1

If you specify -S compiler option, assembly file will be produced and it enables you to look at the code assembler is complaining about. For example:

/ASM

pushl %ebx <== line 31

/ASMEND

I'm not too familiar with AMD64 ABI, but it is possible that you can't use 32-bit registers in 64 bit mode with some operations like memory (including stack) access.

I was able to compile code with the following changes:

asm(" movl $1,%eax"); /* this 1 inworking reg will set *x */

asm(" pushl %rbx"); /* save the register; eax already saved */

asm(" movl 8(%rbp),%ebx"); /* move the address of x */

asm(" xchg %eax,(%rbx)"); /* atomic swap a one with *x */

asm(" cmp $0,%eax"); /* test what was in *x */

asm(" jnz .A9999"); /* jump if *x was already set */

r = 1; /* indicate set occurred */

asm(" .A9999:");

asm(" popl %rbx"); /* restore the register */

MaximKartashev at 2007-7-7 1:49:44 > top of Java-index,Development Tools,Solaris and Linux Development Tools...