Commits

Anonymous committed f55fdd1

Add more CFI directives in i386/amd64 assembly files in asmrun

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12674f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

  • Participants
  • Parent commits 0a112f0

Comments (0)

Files changed (2)

File asmrun/amd64.S

 /* Push global [label] on stack.  Clobbers %r11. */
 #define PUSH_VAR(srclabel) \
         movq    GREL(srclabel)(%rip), %r11 ; \
-        pushq   (%r11)
+        pushq   (%r11); CFI_ADJUST (8)
 
 /* Pop global [label] off stack.  Clobbers %r11. */
 #define POP_VAR(dstlabel) \
         movq    GREL(dstlabel)(%rip), %r11 ; \
-        popq    (%r11)
+        popq    (%r11);  CFI_ADJUST (-8)
 
 /* Record lowest stack address and return address.  Clobbers %rax. */
 #define RECORD_STACK_FRAME(OFFSET) \
-	pushq   %r11 ; \
+	pushq   %r11 ; CFI_ADJUST(8); \
         movq    8+OFFSET(%rsp), %rax ; \
 	STORE_VAR(%rax,caml_last_return_address) ; \
         leaq    16+OFFSET(%rsp), %rax ; \
 	STORE_VAR(%rax,caml_bottom_of_stack) ; \
-	popq    %r11
+	popq    %r11; CFI_ADJUST(-8)
 
 #else
 
         testl   imm, G(label)(%rip)
 
 #define PUSH_VAR(srclabel) \
-        pushq   G(srclabel)(%rip)
+        pushq   G(srclabel)(%rip) ; CFI_ADJUST(8)
 
 #define POP_VAR(dstlabel) \
-        popq    G(dstlabel)(%rip)
+        popq    G(dstlabel)(%rip); CFI_ADJUST(-8)
 
 #define RECORD_STACK_FRAME(OFFSET) \
         movq    OFFSET(%rsp), %rax ; \
 /* Win64 API: callee-save regs are rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15 */
 
 #define PUSH_CALLEE_SAVE_REGS \
-        pushq   %rbx; \
-        pushq   %rbp; \
-        pushq   %rsi; \
-        pushq   %rdi; \
-        pushq   %r12; \
-        pushq   %r13; \
-        pushq   %r14; \
-        pushq   %r15; \
-	subq	$(8+10*16), %rsp; \
+        pushq   %rbx; CFI_ADJUST (8); \
+        pushq   %rbp; CFI_ADJUST (8); \
+        pushq   %rsi; CFI_ADJUST (8); \
+        pushq   %rdi; CFI_ADJUST (8); \
+        pushq   %r12; CFI_ADJUST (8); \
+        pushq   %r13; CFI_ADJUST (8); \
+        pushq   %r14; CFI_ADJUST (8); \
+        pushq   %r15; CFI_ADJUST (8); \
+	subq	$(8+10*16), %rsp; CFI_ADJUST (8+10*16); \
 	movupd  %xmm6, 0*16(%rsp); \
         movupd  %xmm7, 1*16(%rsp); \
         movupd  %xmm8, 2*16(%rsp); \
         movupd  7*16(%rsp), %xmm13; \
         movupd  8*16(%rsp), %xmm14; \
         movupd  9*16(%rsp), %xmm15; \
-        addq    $(8+10*16), %rsp; \
-        popq    %r15; \
-        popq    %r14; \
-        popq    %r13; \
-        popq    %r12; \
-        popq    %rdi; \
-        popq    %rsi; \
-        popq    %rbp; \
-        popq    %rbx
+        addq    $(8+10*16), %rsp; CFI_ADJUST (-8-10*16); \
+        popq    %r15; CFI_ADJUST(-8); \
+        popq    %r14; CFI_ADJUST(-8); \
+        popq    %r13; CFI_ADJUST(-8); \
+        popq    %r12; CFI_ADJUST(-8); \
+        popq    %rdi; CFI_ADJUST(-8); \
+        popq    %rsi; CFI_ADJUST(-8); \
+        popq    %rbp; CFI_ADJUST(-8); \
+        popq    %rbx; CFI_ADJUST(-8)
 
 #else
 
 /* Unix API: callee-save regs are rbx, rbp, r12-r15 */
 
 #define PUSH_CALLEE_SAVE_REGS \
-        pushq   %rbx; \
-        pushq   %rbp; \
-        pushq   %r12; \
-        pushq   %r13; \
-        pushq   %r14; \
-        pushq   %r15; \
-	subq	$8, %rsp
+        pushq   %rbx; CFI_ADJUST(8); \
+        pushq   %rbp; CFI_ADJUST(8); \
+        pushq   %r12; CFI_ADJUST(8); \
+        pushq   %r13; CFI_ADJUST(8); \
+        pushq   %r14; CFI_ADJUST(8); \
+        pushq   %r15; CFI_ADJUST(8); \
+	subq	$8, %rsp; CFI_ADJUST(8)
 
 #define POP_CALLEE_SAVE_REGS \
-	addq	$8, %rsp; \
-        popq    %r15; \
-        popq    %r14; \
-        popq    %r13; \
-        popq    %r12; \
-        popq    %rbp; \
-        popq    %rbx
+	addq	$8, %rsp; CFI_ADJUST(-8); \
+        popq    %r15; CFI_ADJUST(-8); \
+        popq    %r14; CFI_ADJUST(-8); \
+        popq    %r13; CFI_ADJUST(-8); \
+        popq    %r12; CFI_ADJUST(-8); \
+        popq    %rbp; CFI_ADJUST(-8); \
+        popq    %rbx; CFI_ADJUST(-8)
 
 #endif
 
 #ifdef SYS_mingw64
    /* Calls from OCaml to C must reserve 32 bytes of extra stack space */
-#  define PREPARE_FOR_C_CALL subq $32, %rsp
-#  define CLEANUP_AFTER_C_CALL addq $32, %rsp
+#  define PREPARE_FOR_C_CALL subq $32, %rsp; CFI_ADJUST(32)
+#  define CLEANUP_AFTER_C_CALL addq $32, %rsp; CFI_ADJUST(-32)
 #else
 #  define PREPARE_FOR_C_CALL
 #  define CLEANUP_AFTER_C_CALL
         addq    $32768, %rsp
 #endif
     /* Build array of registers, save it into caml_gc_regs */
-        pushq   %r13
-        pushq   %r12
-        pushq   %rbp
-        pushq   %r11
-        pushq   %r10
-        pushq   %r9
-        pushq   %r8
-        pushq   %rcx
-        pushq   %rdx
-        pushq   %rsi
-        pushq   %rdi
-        pushq   %rbx
-        pushq   %rax
+        pushq   %r13; CFI_ADJUST (8);
+        pushq   %r12; CFI_ADJUST (8);
+        pushq   %rbp; CFI_ADJUST (8);
+        pushq   %r11; CFI_ADJUST (8);
+        pushq   %r10; CFI_ADJUST (8);
+        pushq   %r9; CFI_ADJUST (8);
+        pushq   %r8; CFI_ADJUST (8);
+        pushq   %rcx; CFI_ADJUST (8);
+        pushq   %rdx; CFI_ADJUST (8);
+        pushq   %rsi; CFI_ADJUST (8);
+        pushq   %rdi; CFI_ADJUST (8);
+        pushq   %rbx; CFI_ADJUST (8);
+        pushq   %rax; CFI_ADJUST (8);
         STORE_VAR(%rsp, caml_gc_regs)
     /* Save caml_young_ptr, caml_exception_pointer */
 	STORE_VAR(%r15, caml_young_ptr)
 	STORE_VAR(%r14, caml_exception_pointer)
     /* Save floating-point registers */
-        subq    $(16*8), %rsp
-        CFI_ADJUST(232)
+        subq    $(16*8), %rsp; CFI_ADJUST (16*8);
         movsd   %xmm0, 0*8(%rsp)
         movsd   %xmm1, 1*8(%rsp)
         movsd   %xmm2, 2*8(%rsp)
         movsd   13*8(%rsp), %xmm13
         movsd   14*8(%rsp), %xmm14
         movsd   15*8(%rsp), %xmm15
-        addq    $(16*8), %rsp
-        popq    %rax
-        popq    %rbx
-        popq    %rdi
-        popq    %rsi
-        popq    %rdx
-        popq    %rcx
-        popq    %r8
-        popq    %r9
-        popq    %r10
-        popq    %r11
-        popq    %rbp
-        popq    %r12
-        popq    %r13
-        CFI_ADJUST(-232)
+        addq    $(16*8), %rsp; CFI_ADJUST(-16*8)
+        popq    %rax; CFI_ADJUST(-8)
+        popq    %rbx; CFI_ADJUST(-8)
+        popq    %rdi; CFI_ADJUST(-8)
+        popq    %rsi; CFI_ADJUST(-8)
+        popq    %rdx; CFI_ADJUST(-8)
+        popq    %rcx; CFI_ADJUST(-8)
+        popq    %r8; CFI_ADJUST(-8)
+        popq    %r9; CFI_ADJUST(-8)
+        popq    %r10; CFI_ADJUST(-8)
+        popq    %r11; CFI_ADJUST(-8)
+        popq    %rbp; CFI_ADJUST(-8)
+        popq    %r12; CFI_ADJUST(-8)
+        popq    %r13; CFI_ADJUST(-8)
     /* Return to caller */
         ret
-        CFI_ENDPROC
+CFI_ENDPROC
 
 FUNCTION(G(caml_alloc1))
+CFI_STARTPROC
 LBL(caml_alloc1):
         subq    $16, %r15
         CMP_VAR(caml_young_limit, %r15)
         ret
 LBL(100):
         RECORD_STACK_FRAME(0)
-	subq	$8, %rsp
+	subq	$8, %rsp; CFI_ADJUST (8);
         call    LBL(caml_call_gc)
-	addq	$8, %rsp
+	addq	$8, %rsp; CFI_ADJUST (-8);
         jmp     LBL(caml_alloc1)
+CFI_ENDPROC
 
 FUNCTION(G(caml_alloc2))
+CFI_STARTPROC
 LBL(caml_alloc2):
         subq    $24, %r15
         CMP_VAR(caml_young_limit, %r15)
         ret
 LBL(101):
         RECORD_STACK_FRAME(0)
-	subq	$8, %rsp
+	subq	$8, %rsp; CFI_ADJUST (8);
         call    LBL(caml_call_gc)
-	addq	$8, %rsp
+	addq	$8, %rsp; CFI_ADJUST (-8);
         jmp     LBL(caml_alloc2)
+CFI_ENDPROC
 
 FUNCTION(G(caml_alloc3))
+CFI_STARTPROC
 LBL(caml_alloc3):
         subq    $32, %r15
         CMP_VAR(caml_young_limit, %r15)
         ret
 LBL(102):
         RECORD_STACK_FRAME(0)
-	subq	$8, %rsp
+	subq	$8, %rsp; CFI_ADJUST (8)
         call    LBL(caml_call_gc)
-	addq	$8, %rsp
+	addq	$8, %rsp; CFI_ADJUST (-8)
         jmp     LBL(caml_alloc3)
+CFI_ENDPROC
 
 FUNCTION(G(caml_allocN))
+CFI_STARTPROC
 LBL(caml_allocN):
-        pushq   %rax                       /* save desired size */
+        pushq   %rax; CFI_ADJUST(8)        /* save desired size */
         subq    %rax, %r15
         CMP_VAR(caml_young_limit, %r15)
         jb      LBL(103)
-        addq    $8, %rsp                  /* drop desired size */
+        addq    $8, %rsp; CFI_ADJUST (-8)  /* drop desired size */
         ret
 LBL(103):
         RECORD_STACK_FRAME(8)
         call    LBL(caml_call_gc)
-        popq    %rax                      /* recover desired size */
+        popq    %rax; CFI_ADJUST(-8)       /* recover desired size */
         jmp     LBL(caml_allocN)
+CFI_ENDPROC
 
 /* Call a C function from OCaml */
 
 FUNCTION(G(caml_c_call))
+CFI_STARTPROC
 LBL(caml_c_call):
     /* Record lowest stack address and return address */
-        popq    %r12
+        popq    %r12; CFI_ADJUST(-8)
         STORE_VAR(%r12, caml_last_return_address)
         STORE_VAR(%rsp, caml_bottom_of_stack)
-        pushq    %r12
+        subq    $8, %rsp; CFI_ADJUST(8) /* equivalent to pushq %r12 */
 #ifndef SYS_mingw64
     /* Touch the stack to trigger a recoverable segfault
        if insufficient space remains */
     /* No need to PREPARE_FOR_C_CALL since the caller already
        reserved the stack space if needed (cf. amd64/proc.ml) */
         jmp    *%rax
+CFI_ENDPROC
 
 /* Start the OCaml program */
 
 FUNCTION(G(caml_start_program))
-        CFI_STARTPROC
+       CFI_STARTPROC
     /* Save callee-save registers */
         PUSH_CALLEE_SAVE_REGS
-        CFI_ADJUST(56)
     /* Initial entry point is G(caml_program) */
         leaq    GCALL(caml_program)(%rip), %r12
     /* Common code for caml_start_program and caml_callback* */
 LBL(caml_start_program):
     /* Build a callback link */
-	subq	$8, %rsp	/* stack 16-aligned */
+	subq	$8, %rsp; CFI_ADJUST (8)	/* stack 16-aligned */
         PUSH_VAR(caml_gc_regs)
         PUSH_VAR(caml_last_return_address)
         PUSH_VAR(caml_bottom_of_stack)
-        CFI_ADJUST(32)
     /* Setup alloc ptr and exception ptr */
 	LOAD_VAR(caml_young_ptr, %r15)
 	LOAD_VAR(caml_exception_pointer, %r14)
     /* Build an exception handler */
         lea     LBL(108)(%rip), %r13
-        pushq   %r13
-        pushq   %r14
+        pushq   %r13; CFI_ADJUST(8)
+        pushq   %r14; CFI_ADJUST(8)
         CFI_ADJUST(16)
         movq    %rsp, %r14
     /* Call the OCaml code */
         call    *%r12
 LBL(107):
     /* Pop the exception handler */
-        popq    %r14
-        popq    %r12    /* dummy register */
+        popq    %r14; CFI_ADJUST(-8)
+        popq    %r12; CFI_ADJUST(-8)   /* dummy register */
         CFI_ADJUST(-16)
 LBL(109):
     /* Update alloc ptr and exception ptr */
 	POP_VAR(caml_bottom_of_stack)
         POP_VAR(caml_last_return_address)
         POP_VAR(caml_gc_regs)
-	addq	$8, %rsp
+	addq	$8, %rsp; CFI_ADJUST (-8);
     /* Restore callee-save registers. */
         POP_CALLEE_SAVE_REGS
     /* Return to caller. */
     /* Mark the bucket as an exception result and return it */
         orq     $2, %rax
         jmp     LBL(109)
-        CFI_ENDPROC
+CFI_ENDPROC
 
 /* Registers holding arguments of C functions. */
 
 /* Raise an exception from OCaml */
 
 FUNCTION(G(caml_raise_exn))
+CFI_STARTPROC
         TESTL_VAR($1, caml_backtrace_active)
         jne     LBL(110)
         movq    %r14, %rsp
-        popq    %r14
+        popq    %r14; CFI_ADJUST(-8)
         ret
 LBL(110):
         movq    %rax, %r12            /* Save exception bucket */
         call    GCALL(caml_stash_backtrace)
         movq    %r12, %rax            /* Recover exception bucket */
         movq    %r14, %rsp
-        popq    %r14
+        popq    %r14; CFI_ADJUST(-8)
         ret
+CFI_ENDPROC
 
 /* Raise an exception from C */
 
 FUNCTION(G(caml_raise_exception))
+CFI_STARTPROC
         TESTL_VAR($1, caml_backtrace_active)
         jne     LBL(111)
         movq    C_ARG_1, %rax
         LOAD_VAR(caml_exception_pointer, %rsp)  /* Cut stack */
-        popq    %r14                  /* Recover previous exception handler */
+        popq    %r14; CFI_ADJUST(-8)   /* Recover previous exception handler */
         LOAD_VAR(caml_young_ptr, %r15) /* Reload alloc ptr */
         ret
 LBL(111):
         call    GCALL(caml_stash_backtrace)
         movq    %r12, %rax            /* Recover exception bucket */
 	LOAD_VAR(caml_exception_pointer,%rsp)
-        popq    %r14                  /* Recover previous exception handler */
+        popq    %r14; CFI_ADJUST(-8)   /* Recover previous exception handler */
 	LOAD_VAR(caml_young_ptr,%r15)  /* Reload alloc ptr */
         ret
+CFI_ENDPROC
 
 /* Callback from C to OCaml */
 
 FUNCTION(G(caml_callback_exn))
+CFI_STARTPROC
     /* Save callee-save registers */
         PUSH_CALLEE_SAVE_REGS
     /* Initial loading of arguments */
         movq    C_ARG_2, %rax      /* argument */
         movq    0(%rbx), %r12      /* code pointer */
         jmp     LBL(caml_start_program)
+CFI_ENDPROC
 
 FUNCTION(G(caml_callback2_exn))
+CFI_STARTPROC
     /* Save callee-save registers */
         PUSH_CALLEE_SAVE_REGS
     /* Initial loading of arguments */
         movq    C_ARG_3, %rbx      /* second argument */
         leaq    GCALL(caml_apply2)(%rip), %r12  /* code pointer */
         jmp     LBL(caml_start_program)
+CFI_ENDPROC
 
 FUNCTION(G(caml_callback3_exn))
+CFI_STARTPROC
     /* Save callee-save registers */
         PUSH_CALLEE_SAVE_REGS
     /* Initial loading of arguments */
         movq    C_ARG_4, %rdi      /* third argument */
         leaq    GCALL(caml_apply3)(%rip), %r12  /* code pointer */
         jmp     LBL(caml_start_program)
+CFI_ENDPROC
 
 FUNCTION(G(caml_ml_array_bound_error))
+CFI_STARTPROC
         leaq    GCALL(caml_array_bound_error)(%rip), %rax
         jmp     LBL(caml_c_call)
+CFI_ENDPROC
 
         .globl  G(caml_system__code_end)
 G(caml_system__code_end):

File asmrun/i386.S

 #define FUNCTION_ALIGN 2
 #endif
 
+#define FUNCTION(name) \
+        .globl G(name); \
+        .align FUNCTION_ALIGN; \
+        G(name):
+
 #ifdef ASM_CFI_SUPPORTED
 #define CFI_STARTPROC .cfi_startproc
 #define CFI_ENDPROC .cfi_endproc
 #if defined(PROFILING)
 #if defined(SYS_linux_elf) || defined(SYS_gnu)
 #define PROFILE_CAML \
-        pushl %ebp; movl %esp, %ebp; pushl %eax; pushl %ecx; pushl %edx; \
+        pushl %ebp; CFI_ADJUST(4); \
+        movl %esp, %ebp; \
+        pushl %eax; CFI_ADJUST(4); \
+        pushl %ecx; CFI_ADJUST(4); \
+        pushl %edx; CFI_ADJUST(4); \
         call mcount; \
-        popl %edx; popl %ecx; popl %eax; popl %ebp
+        popl %edx; CFI_ADJUST(-4); \
+        popl %ecx; CFI_ADJUST(-4); \
+        popl %eax; CFI_ADJUST(-4); \
+        popl %ebp; CFI_ADJUST(-4)
 #define PROFILE_C \
-        pushl %ebp; movl %esp, %ebp; call mcount; popl %ebp
+        pushl %ebp; CFI_ADJUST(4); \
+        movl %esp, %ebp; \
+        call mcount; \
+        popl %ebp; CFI_ADJUST(-4)
 #elif defined(SYS_bsd_elf)
 #define PROFILE_CAML \
-        pushl %ebp; movl %esp, %ebp; pushl %eax; pushl %ecx; pushl %edx; \
+        pushl %ebp; CFI_ADJUST(4); \
+        movl %esp, %ebp; \
+        pushl %eax; CFI_ADJUST(4); \
+        pushl %ecx; CFI_ADJUST(4); \
+        pushl %edx; CFI_ADJUST(4); \
         call .mcount; \
-        popl %edx; popl %ecx; popl %eax; popl %ebp
+        popl %edx; CFI_ADJUST(-4); \
+        popl %ecx; CFI_ADJUST(-4); \
+        popl %eax; CFI_ADJUST(-4); \
+        popl %ebp; CFI_ADJUST(-4)
 #define PROFILE_C \
-        pushl %ebp; movl %esp, %ebp; call .mcount; popl %ebp
+        pushl %ebp; CFI_ADJUST(4); \
+        movl %esp, %ebp; \
+        call .mcount; \
+        popl %ebp; CFI_ADJUST(-4)
 #elif defined(SYS_macosx)
 #define PROFILE_CAML \
-        pushl %ebp; movl %esp, %ebp; pushl %eax; pushl %ecx; pushl %edx; \
+        pushl %ebp; CFI_ADJUST(4); \
+        movl %esp, %ebp; \
+        pushl %eax; CFI_ADJUST(4); \
+        pushl %ecx; CFI_ADJUST(4); \
+        pushl %edx; CFI_ADJUST(4); \
         call Lmcount$stub;  \
-        popl %edx; popl %ecx; popl %eax; popl %ebp
+        popl %edx; CFI_ADJUST(-4); \
+        popl %ecx; CFI_ADJUST(-4); \
+        popl %eax; CFI_ADJUST(-4); \
+        popl %ebp; CFI_ADJUST(-4)
 #define PROFILE_C \
-        pushl %ebp; movl %esp, %ebp; call Lmcount$stub; popl %ebp
+        pushl %ebp; CFI_ADJUST(4); \
+        movl %esp, %ebp; \
+        call Lmcount$stub; \
+        popl %ebp; CFI_ADJUST(-4)
 #endif
 #else
 #define PROFILE_CAML
 #endif
 
 #ifdef SYS_macosx
-#define ALIGN_STACK(amount) subl $ amount, %esp
-#define UNDO_ALIGN_STACK(amount) addl $ amount, %esp
+#define ALIGN_STACK(amount) subl $ amount, %esp ; CFI_ADJUST(amount)
+#define UNDO_ALIGN_STACK(amount) addl $ amount, %esp ; CFI_ADJUST(-amount)
 #else
 #define ALIGN_STACK(amount)
 #define UNDO_ALIGN_STACK(amount)
         .globl  G(caml_system__code_begin)
 G(caml_system__code_begin):
 
-        .globl  G(caml_call_gc)
-        .globl  G(caml_alloc1)
-        .globl  G(caml_alloc2)
-        .globl  G(caml_alloc3)
-        .globl  G(caml_allocN)
-
-        .align  FUNCTION_ALIGN
-G(caml_call_gc):
+FUNCTION(caml_call_gc)
         CFI_STARTPROC
         PROFILE_CAML
     /* Record lowest stack address and return address */
         addl    $16384, %esp
 #endif
     /* Build array of registers, save it into caml_gc_regs */
-        pushl   %ebp
-        pushl   %edi
-        pushl   %esi
-        pushl   %edx
-        pushl   %ecx
-        pushl   %ebx
-        pushl   %eax
-        CFI_ADJUST(28)
+        pushl   %ebp; CFI_ADJUST(4)
+        pushl   %edi; CFI_ADJUST(4)
+        pushl   %esi; CFI_ADJUST(4)
+        pushl   %edx; CFI_ADJUST(4)
+        pushl   %ecx; CFI_ADJUST(4)
+        pushl   %ebx; CFI_ADJUST(4)
+        pushl   %eax; CFI_ADJUST(4)
         movl    %esp, G(caml_gc_regs)
         /* MacOSX note: 16-alignment of stack preserved at this point */
     /* Call the garbage collector */
         call    G(caml_garbage_collection)
     /* Restore all regs used by the code generator */
-        popl    %eax
-        popl    %ebx
-        popl    %ecx
-        popl    %edx
-        popl    %esi
-        popl    %edi
-        popl    %ebp
-        CFI_ADJUST(-28)
+        popl    %eax; CFI_ADJUST(-4)
+        popl    %ebx; CFI_ADJUST(-4)
+        popl    %ecx; CFI_ADJUST(-4)
+        popl    %edx; CFI_ADJUST(-4)
+        popl    %esi; CFI_ADJUST(-4)
+        popl    %edi; CFI_ADJUST(-4)
+        popl    %ebp; CFI_ADJUST(-4)
     /* Return to caller */
         ret
         CFI_ENDPROC
 
-        .align  FUNCTION_ALIGN
-G(caml_alloc1):
+FUNCTION(caml_alloc1)
+        CFI_STARTPROC
         PROFILE_CAML
         movl    G(caml_young_ptr), %eax
         subl    $8, %eax
         call    LBL(105)
         UNDO_ALIGN_STACK(12)
         jmp     G(caml_alloc1)
+        CFI_ENDPROC
 
-        .align  FUNCTION_ALIGN
-G(caml_alloc2):
+FUNCTION(caml_alloc2)
+        CFI_STARTPROC
         PROFILE_CAML
         movl    G(caml_young_ptr), %eax
         subl    $12, %eax
         call    LBL(105)
         UNDO_ALIGN_STACK(12)
         jmp     G(caml_alloc2)
+        CFI_ENDPROC
 
-        .align  FUNCTION_ALIGN
-G(caml_alloc3):
+FUNCTION(caml_alloc3)
+        CFI_STARTPROC
         PROFILE_CAML
         movl    G(caml_young_ptr), %eax
         subl    $16, %eax
         call    LBL(105)
         UNDO_ALIGN_STACK(12)
         jmp     G(caml_alloc3)
+        CFI_ENDPROC
 
-        .align  FUNCTION_ALIGN
-G(caml_allocN):
+FUNCTION(caml_allocN)
+        CFI_STARTPROC
         PROFILE_CAML
         subl    G(caml_young_ptr), %eax /* eax = size - caml_young_ptr */
         negl    %eax                    /* eax = caml_young_ptr - size */
 LBL(103):
         subl    G(caml_young_ptr), %eax /* eax = - size */
         negl    %eax                    /* eax = size */
-        pushl   %eax                    /* save desired size */
+        pushl   %eax; CFI_ADJUST(4)     /* save desired size */
         subl    %eax, G(caml_young_ptr) /* must update young_ptr */
         movl    4(%esp), %eax
         movl    %eax, G(caml_last_return_address)
         ALIGN_STACK(8)
         call    LBL(105)
         UNDO_ALIGN_STACK(8)
-        popl    %eax                    /* recover desired size */
+        popl    %eax; CFI_ADJUST(-4)    /* recover desired size */
         jmp     G(caml_allocN)
+        CFI_ENDPROC
 
 /* Call a C function from OCaml */
 
-        .globl  G(caml_c_call)
-        .align  FUNCTION_ALIGN
-G(caml_c_call):
+FUNCTION(caml_c_call)
+        CFI_STARTPROC
         PROFILE_CAML
     /* Record lowest stack address and return address */
         movl    (%esp), %edx
 #endif
     /* Call the function (address in %eax) */
         jmp     *%eax
+        CFI_ENDPROC
 
 /* Start the OCaml program */
 
-        .globl  G(caml_start_program)
-        .align  FUNCTION_ALIGN
-G(caml_start_program):
+FUNCTION(caml_start_program)
         CFI_STARTPROC
         PROFILE_C
     /* Save callee-save registers */
-        pushl   %ebx
-        pushl   %esi
-        pushl   %edi
-        pushl   %ebp
-        CFI_ADJUST(16)
+        pushl   %ebx; CFI_ADJUST(4)
+        pushl   %esi; CFI_ADJUST(4)
+        pushl   %edi; CFI_ADJUST(4)
+        pushl   %ebp; CFI_ADJUST(4)
     /* Initial entry point is caml_program */
         movl    $ G(caml_program), %esi
     /* Common code for caml_start_program and caml_callback* */
 LBL(106):
     /* Build a callback link */
-        pushl   G(caml_gc_regs)
-        pushl   G(caml_last_return_address)
-        pushl   G(caml_bottom_of_stack)
+        pushl   G(caml_gc_regs); CFI_ADJUST(4)
+        pushl   G(caml_last_return_address); CFI_ADJUST(4)
+        pushl   G(caml_bottom_of_stack); CFI_ADJUST(4)
         /* Note: 16-alignment preserved on MacOSX at this point */
     /* Build an exception handler */
-        pushl   $ LBL(108)
+        pushl   $ LBL(108); CFI_ADJUST(4)
         ALIGN_STACK(8)
-        pushl   G(caml_exception_pointer)
-        CFI_ADJUST(20)
+        pushl   G(caml_exception_pointer); CFI_ADJUST(4)
         movl    %esp, G(caml_exception_pointer)
     /* Call the OCaml code */
         call    *%esi
 LBL(107):
     /* Pop the exception handler */
-        popl    G(caml_exception_pointer)
+        popl    G(caml_exception_pointer); CFI_ADJUST(-4)
 #ifdef SYS_macosx
-        addl	$12, %esp
+        addl	$12, %esp       ; CFI_ADJUST(-12)
 #else
-        addl	$4, %esp
+        addl	$4, %esp        ; CFI_ADJUST(-4)
 #endif
-        CFI_ADJUST(-8)
 LBL(109):
     /* Pop the callback link, restoring the global variables */
-        popl    G(caml_bottom_of_stack)
-        popl    G(caml_last_return_address)
-        popl    G(caml_gc_regs)
+        popl    G(caml_bottom_of_stack); CFI_ADJUST(-4)
+        popl    G(caml_last_return_address); CFI_ADJUST(-4)
+        popl    G(caml_gc_regs); CFI_ADJUST(-4)
     /* Restore callee-save registers. */
-        popl    %ebp
-        popl    %edi
-        popl    %esi
-        popl    %ebx
+        popl    %ebp; CFI_ADJUST(-4)
+        popl    %edi; CFI_ADJUST(-4)
+        popl    %esi; CFI_ADJUST(-4)
+        popl    %ebx; CFI_ADJUST(-4)
     /* Return to caller. */
         ret
 LBL(108):
 
 /* Raise an exception from OCaml */
 
-        .globl  G(caml_raise_exn)
-        .align  FUNCTION_ALIGN
-G(caml_raise_exn):
+FUNCTION(caml_raise_exn)
+        CFI_STARTPROC
         testl   $1, G(caml_backtrace_active)
         jne     LBL(110)
         movl    G(caml_exception_pointer), %esp
-        popl    G(caml_exception_pointer)
+        popl    G(caml_exception_pointer); CFI_ADJUST(-4)
         UNDO_ALIGN_STACK(8)
         ret
 LBL(110):
         movl    0(%esp), %eax       /* PC of raise */
         leal    4(%esp), %edx       /* SP of raise */
         ALIGN_STACK(12)
-        pushl   %edi                        /* arg 4: sp of handler */
-        pushl   %edx                        /* arg 3: sp of raise */
-        pushl   %eax                        /* arg 2: pc of raise */
-        pushl   %esi                        /* arg 1: exception bucket */
+        pushl   %edi; CFI_ADJUST(4)         /* arg 4: sp of handler */
+        pushl   %edx; CFI_ADJUST(4)         /* arg 3: sp of raise */
+        pushl   %eax; CFI_ADJUST(4)         /* arg 2: pc of raise */
+        pushl   %esi; CFI_ADJUST(4)         /* arg 1: exception bucket */
         call    G(caml_stash_backtrace)
         movl    %esi, %eax              /* Recover exception bucket */
         movl    %edi, %esp
-        popl    G(caml_exception_pointer)
+        popl    G(caml_exception_pointer); CFI_ADJUST(-4)
         UNDO_ALIGN_STACK(8)
         ret
+        CFI_ENDPROC
 
 /* Raise an exception from C */
 
-        .globl  G(caml_raise_exception)
-        .align  FUNCTION_ALIGN
-G(caml_raise_exception):
+FUNCTION(caml_raise_exception)
+        CFI_STARTPROC
         PROFILE_C
 	testl   $1, G(caml_backtrace_active)
         jne     LBL(111)
         movl    4(%esp), %eax
         movl    G(caml_exception_pointer), %esp
-        popl    G(caml_exception_pointer)
+        popl    G(caml_exception_pointer); CFI_ADJUST(-4)
         UNDO_ALIGN_STACK(8)
         ret
 LBL(111):
         movl    4(%esp), %esi          /* Save exception bucket in esi */
         ALIGN_STACK(12)
-        pushl   G(caml_exception_pointer)   /* arg 4: sp of handler */
-        pushl   G(caml_bottom_of_stack)     /* arg 3: sp of raise */
-        pushl   G(caml_last_return_address) /* arg 2: pc of raise */
-        pushl   %esi                        /* arg 1: exception bucket */
+        pushl   G(caml_exception_pointer); CFI_ADJUST(4)   /* arg 4: sp of handler */
+        pushl   G(caml_bottom_of_stack);   CFI_ADJUST(4)     /* arg 3: sp of raise */
+        pushl   G(caml_last_return_address); CFI_ADJUST(4) /* arg 2: pc of raise */
+        pushl   %esi; CFI_ADJUST(4)                        /* arg 1: exception bucket */
         call    G(caml_stash_backtrace)
         movl    %esi, %eax              /* Recover exception bucket */
         movl    G(caml_exception_pointer), %esp
-        popl    G(caml_exception_pointer)
+        popl    G(caml_exception_pointer); CFI_ADJUST(-4)
         UNDO_ALIGN_STACK(8)
         ret
+        CFI_ENDPROC
 
 /* Callback from C to OCaml */
 
-        .globl  G(caml_callback_exn)
-        .align  FUNCTION_ALIGN
-G(caml_callback_exn):
+FUNCTION(caml_callback_exn)
+        CFI_STARTPROC
         PROFILE_C
     /* Save callee-save registers */
-        pushl   %ebx
-        pushl   %esi
-        pushl   %edi
-        pushl   %ebp
+        pushl   %ebx; CFI_ADJUST(4)
+        pushl   %esi; CFI_ADJUST(4)
+        pushl   %edi; CFI_ADJUST(4)
+        pushl   %ebp; CFI_ADJUST(4)
     /* Initial loading of arguments */
         movl    20(%esp), %ebx   /* closure */
         movl    24(%esp), %eax   /* argument */
         movl    0(%ebx), %esi    /* code pointer */
         jmp     LBL(106)
+        CFI_ENDPROC
 
-        .globl  G(caml_callback2_exn)
-        .align  FUNCTION_ALIGN
-G(caml_callback2_exn):
+FUNCTION(caml_callback2_exn)
+        CFI_STARTPROC
         PROFILE_C
     /* Save callee-save registers */
-        pushl   %ebx
-        pushl   %esi
-        pushl   %edi
-        pushl   %ebp
+        pushl   %ebx; CFI_ADJUST(4)
+        pushl   %esi; CFI_ADJUST(4)
+        pushl   %edi; CFI_ADJUST(4)
+        pushl   %ebp; CFI_ADJUST(4)
     /* Initial loading of arguments */
         movl    20(%esp), %ecx   /* closure */
         movl    24(%esp), %eax   /* first argument */
         movl    28(%esp), %ebx   /* second argument */
         movl    $ G(caml_apply2), %esi   /* code pointer */
         jmp     LBL(106)
+        CFI_ENDPROC
 
-        .globl  G(caml_callback3_exn)
-        .align  FUNCTION_ALIGN
-G(caml_callback3_exn):
+FUNCTION(caml_callback3_exn)
+        CFI_STARTPROC
         PROFILE_C
     /* Save callee-save registers */
-        pushl   %ebx
-        pushl   %esi
-        pushl   %edi
-        pushl   %ebp
+        pushl   %ebx; CFI_ADJUST(4)
+        pushl   %esi; CFI_ADJUST(4)
+        pushl   %edi; CFI_ADJUST(4)
+        pushl   %ebp; CFI_ADJUST(4)
     /* Initial loading of arguments */
         movl    20(%esp), %edx   /* closure */
         movl    24(%esp), %eax   /* first argument */
         movl    32(%esp), %ecx   /* third argument */
         movl    $ G(caml_apply3), %esi   /* code pointer */
         jmp     LBL(106)
+        CFI_ENDPROC
 
-        .globl  G(caml_ml_array_bound_error)
-        .align  FUNCTION_ALIGN
-G(caml_ml_array_bound_error):
+FUNCTION(caml_ml_array_bound_error)
+        CFI_STARTPROC
     /* Empty the floating-point stack */
         ffree   %st(0)
         ffree   %st(1)
 #endif
     /* Branch to [caml_array_bound_error] (never returns) */
         call    G(caml_array_bound_error)
+        CFI_ENDPROC
 
         .globl  G(caml_system__code_end)
 G(caml_system__code_end):