You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AS complains about a backwards jump to label

Greetings. I am currently porting some x86 assembly code from another platform and running into an odd problem where the assembler will not accept a backwards jump to a label. This only happens when assembling in Intel syntax mode.

As far as I am aware the source was assembled using GAS, so one would assume that aside from platform/abi specific directives it should compile with Apple's AS.


cat source.s
.intel_syntax
fooA: jmp wtfA
wtfA: ret
barA: jmp wtfA
.att_syntax
fooB: jmp wtfB
wtfB: ret
barB: jmp wtfB
as source.s
source.s:4:suffix or operands invalid for `jmp'
as -v
Apple Inc version cctools-698.1~1, GNU assembler version 1.38


Does anyone have any idea on whats going on here? Thanks.

Posted on Sep 8, 2009 5:08 PM

Reply
3 replies

Sep 9, 2009 2:00 PM in response to K T

After reading the source code for the tool it turns out that it just doesn't handle textual labels correctly in intel_syntax mode. The intel parser logic will interpret all previously defined symbols as a 'memory' operand and then refuse to accept the jmp instruction because it requires a 'displacement' operand.

The forward jumps happen to work because the type of an operand with undefined symbols are resolved in the backend which is shared for both intel and att modes. At that point all labels in the source code have been defined so it can correctly distinguish between a memory and displacement operand.

The good news is that I did find a way to get the get the assembler to jump backwards correctly by using local labels as described in 'Mac OS X Assembler Reference' and the latest GAS documentation. You can specify numeric labels and jump to them using #b and #f. The intel parser explicitly checks for this suffix and treats it as a displacement.

<pre>
.intel_syntax
fooA: jmp wtfA
0: wtfA: ret
barA: jmp 0b
</pre>

I'll be putting in a bug report for this one since it is not fixed in cctools-750~70.

Thanks.

AS complains about a backwards jump to label

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.