Benches Uncategorized

3

AS complains about a backwards jump to la…

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

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.

3 replies

Sign in or join Beachball Help to reply.

  1. 0

    K T

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    one would assume that aside from platform/abi specific directives it should compile with Apple's AS.

    Apple Inc version cctools-698.1~1, GNU assembler version 1.38

    Might it help if you moved up, say to:

    Apple Inc version cctools-750~70, GNU assembler version 1.38

    ...?

  2. 0

    deadc0de

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  3. 0

    K T

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I'll be putting in a bug report for this one ...

    While I applaud such a move, AFAIK, this 'issue' goes back to 2002, so I wouldn't count on anything soon 🙂 Good luck in any case.