View Issue Details

IDProjectCategoryView StatusLast Update
0018052FPCCompilerpublic2010-11-26 10:20
ReporterFVI Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Platformi386OSMac OS X 
Product Version2.5.1 
Summary0018052: Intel asm compiled in unusual way under Mac OS X (i386)
DescriptionI got asm procedure:

procedure FillMem64(var Ptr; Count: PtrInt; const Value: UInt64);
asm
  CMP EDX, 16
  JL @SmallFill

  //some code

  //my exit point
  LEAVE
  RET 8


  //some code

end;



content of .s file, compiled undex windows (i386)

CORE_MEMORY_FILLMEM64$formal$LONGINT$QWORD:
# Temps allocated between ebp+0 and ebp+0
# [3936] end;
    pushl %ebp
    movl %esp,%ebp
# Var Ptr located in register eax
# Var Count located in register edx
# Var Value located at ebp+8
# [3085] CMP EDX, 16
    cmpl $16,%edx
# [3086] JL @SmallFill
    jl .Lj129

  //some code

  //my exit point
# [3177] LEAVE
    leave
# [3178] RET 8
    ret $8

  //some code

.Lj130:
    leave
    ret $8



content of .s file, compiled undex mac os x (i386)

_CORE_MEMORY_FILLMEM64$formal$LONGINT$QWORD:
# Temps allocated between ebp+0 and ebp+0
    .stabs "/Volumes/programming/units_new/anvil_core/core_memory.pas",132,0,0,Lf18
Lf18:
    .stabd 68,0,3936
# [3936] end;
    pushl %ebp
    movl %esp,%ebp
    subl $8,%esp
# Var Ptr located in register eax
# Var Count located in register edx
# Var Value located at ebp+8
    .stabd 68,0,3085
# [3085] CMP EDX, 16
    cmpl $16,%edx
    .stabd 68,0,3086
# [3086] JL @SmallFill
    jl Lj119

  //some code

  //my exit point
# [3293] LEAVE
    leave
    .stabd 68,0,3294
# [3294] RET 8
    ret $8

  //some code

Lj136:
    .stabd 68,0,3936
    leave
    ret

This difference (instructions subl $8,%esp ... ret, in place of ret 8) makes
impossible of writing asm code with exit point in it.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Jonas Maebe

2010-11-26 10:20

manager   ~0043542

Last edited: 2010-11-26 11:10

The Mac OS X/i386 abi requires that the stack is always 16-byte aligned after the prologue of any function in case it may perform a subroutine call. Since the compiler has no idea about what the assembler code may do and since it's fairly hard for a programmer to guess how much stack space the compiler may allocate in the prologue, the compiler does that even in case of assembler routines.

If you want to do everything yourself, use the "nostackframe" procedure modifier.

In the future, please use the mailing lists to ask why one platform behaves differently from others in case you are not very familiar with that platform, not the bug reporting form.

Issue History

Date Modified Username Field Change
2010-11-25 21:02 FVI New Issue
2010-11-26 10:20 Jonas Maebe Status new => resolved
2010-11-26 10:20 Jonas Maebe Resolution open => no change required
2010-11-26 10:20 Jonas Maebe Assigned To => Jonas Maebe
2010-11-26 10:20 Jonas Maebe Note Added: 0043542
2010-11-26 10:20 Jonas Maebe Note Edited: 0043542
2010-11-26 11:10 Jonas Maebe Note Edited: 0043542