Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bugs in Inline Assembly



I have discovered a few Inline Assembly bugs in XCode.
I have been porting a Codewarrior application to XCode and have found ways to workaround minor differences in Inline Assembly, but I am stuck without a workaround for a few items.
All of the items listed below work in Codewarrior but I can't get them to work in XCode.
I have provided some simple example code to illustrate these problems (see bottom).


1.) Non-volatile registers are clobbered in automatically generated stack frame for PowerPC.
Disassemble the example - functions disassemble1() and disassemble2() both write to r28 and r29 without first saving them.


2.) The "nofralloc" directive seems to be ignored both in PowerPC and Intel assembly.
Functions disassemble2() (PowerPC) and foo() (Intel) both have glue code generated.


3.) Member arrays can't be referenced in assembly code.
Function f1() works in Codewarrior but not in XCode. I found a workaround for the lwz instruction, but the same workaround does not work in other instructions such as addi. Function f2() shows the same problem and shows that the workaround does not work either.


4.) Nested member variables can't be referenced in assembly code.
Function f3() illustrates this. Note that this error seems to be generated at a later stage in compilation and you won't see this error until you eliminate all other errors.


5.) Intel register bp (ebp) can't be used at all.
Function foo2() shows this.

Does anyone know how to deal with these issues?

Thanks in advance,
Mark

--------------
Here is some sample code that shows these problems.
To use in XCode, create a new Carbon Application project, remove main.c and add main.cpp with the following contents.
Select Release as the Active Build Configuration to eliminate debug information shown in disassembled code. Edit the Active Target and set the Architectures setting to be "ppc" or "i386" depending on which processor you want to compile for. Comment out all functions except the one that you want to test.
Select Show Assembly Code from the menu to disassemble the file.


struct A
{
	int m1;
};

struct B
{
	A m2[10];
};

struct C
{
	A m3;
};

struct D
{
	C m4;
};

#if defined(__ppc__)

asm void f1()
{
	// works in Codewarrior, error in XCode
	lwz		r3, B.m2[5](r3)

	// here is a workaround
	lwz		r3, B.m2[0] + 5 * sizeof(A)(r3)
}

asm void f2()
{
	// works in Codewarrior, error in XCode
	addi	r3, r3, B.m2[5]

	// this does not work either
	addi	r3, r3, B.m2[0] + 5 * sizeof(A)
}

asm void f3()
{
	lwz		r3, D.m4.m3(r3)
}

asm int disassemble1(register int a, register int b, register int c, register int d, register int e, register int f)
{
add r4, a, b
add r6, r5, c
add r7, r6, d
add r8, r7, e
add r3, r8, f
}


asm int disassemble2(register int a, register int b, register int c, register int d, register int e, register int f)
{
nofralloc
add r4, a, b
add r6, r5, c
add r7, r6, d
add r8, r7, e
add r3, r8, f
bl
}


#endif

#if defined(__i386__)

asm void foo(int a, int b, int c)
{
	nofralloc
	mov		esi, a
	add		esi, b
	add		esi, c
	ret		(3 * 4)
}

// error: bp cannot be used in asm here
asm void foo2(register int a, register int b, register int c)
{
	// no automatic stack frame allocation, we will do this manually
	nofralloc

	// save registers
	push	ebp
	mov		ebp, esp
	push	esi
	push	edi

	// do something here
	// ...

	// restore registers
	pop		edi
	pop		esi
	pop		ebp
	ret		(3 * 4)
}

#endif

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.