Skip to content

Commit

Permalink
flambda-backend: Resolve conflicts in runtime/ (ocaml-flambda#2794)
Browse files Browse the repository at this point in the history
* Initial state where runtime builds

* Review

(cherry picked from commit e41be34)

* Review of conflicts

* Remove XXX in memprof files

(cherry picked from commit 58e7b16)

* ptrdiff_t

(cherry picked from commit e4b4388)

* domain.c:778 to stay deleted

(cherry picked from commit f05df07)

* Fix memprof bit in domain.c:domain_create

(cherry picked from commit 34925f4)

* Revert to upstream compaction behaviour in gc_ctrl.c

(cherry picked from commit 7740dc4)

* Fix for gettimeofday

(cherry picked from commit d2f2330)

* Typo fix

(cherry picked from commit 2db34fd)

* Remove XXX in caml_enter_blocking_section

* Remove message in caml_enter_blocking_section for async exn raise

* Remove XXX in caml_ba_alloc

* adopt_orphaned_work

* caml_alloc_custom_mem

* Try to fix DEBUG code in platform.c

* Resurrect CHECK_STACK_ALIGNMENT macro

* Dune build fixes for the runtime - may need a bit more tidying

* git rm s390x.S win32.c power.S riscv.S
  • Loading branch information
mshinwell authored Aug 13, 2024
1 parent 175c4ea commit 3c5e816
Show file tree
Hide file tree
Showing 54 changed files with 206 additions and 9,553 deletions.
28 changes: 2 additions & 26 deletions runtime/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include "caml/alloc.h"
#include "caml/custom.h"
#include "caml/major_gc.h"
Expand Down Expand Up @@ -62,7 +63,6 @@ CAMLexport value caml_alloc_with_reserved (mlsize_t wosize, tag_t tag,
return result;
}

<<<<<<< HEAD
CAMLexport value caml_alloc (mlsize_t wosize, tag_t tag) {
return caml_alloc_with_reserved (wosize, tag, 0);
}
Expand Down Expand Up @@ -92,34 +92,10 @@ value caml_alloc_shr_reserved_check_gc (mlsize_t wosize, tag_t tag,
return result;
}

||||||| 121bedcfd2
/* This is used by the native compiler for large block allocations. */
=======
/* This is used by the native compiler for large block allocations.
The resulting block can be filled with [caml_modify], or [caml_initialize],
or direct writes for integer values and code pointers.
If [tag == Closure_tag], no GC must take place until field 1
of the block has been set to the correct "arity & start of environment"
information (issue #11482). */

#ifdef NATIVE_CODE
>>>>>>> 5.2.0
CAMLexport value caml_alloc_shr_check_gc (mlsize_t wosize, tag_t tag)
{
<<<<<<< HEAD
return caml_alloc_shr_reserved_check_gc(wosize, tag, 0);
||||||| 121bedcfd2
caml_check_urgent_gc (Val_unit);
return caml_alloc_shr (wosize, tag);
=======
CAMLassert(tag < No_scan_tag);
caml_check_urgent_gc (Val_unit);
value result = caml_alloc_shr (wosize, tag);
for (mlsize_t i = 0; i < wosize; i++) Field (result, i) = Val_unit;
return result;
>>>>>>> 5.2.0
}
#endif

CAMLexport value caml_alloc_mixed_shr_check_gc (mlsize_t wosize, tag_t tag,
mlsize_t scannable_prefix_len)
Expand Down Expand Up @@ -394,7 +370,7 @@ CAMLprim value caml_alloc_dummy_mixed (value size, value scannable_size)
always boxed), and for 64-bit native code (as the double record field is
stored flat, taking up 1 word).
*/
CAML_STATIC_ASSERT(Double_wosize == 1);
static_assert(Double_wosize == 1, "");
reserved_t reserved =
Reserved_mixed_block_scannable_wosize_native(scannable_wosize);
#else
Expand Down
75 changes: 6 additions & 69 deletions runtime/amd64.S
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@


#ifdef DEBUG
#define CHECK_STACK_ALIGNMENT \
test $0xf, %rsp; jz 9f; int3; 9:
#define IF_DEBUG(...) __VA_ARGS__
#else
#define CHECK_STACK_ALIGNMENT
#define IF_DEBUG(...)
#endif

Expand All @@ -149,7 +152,6 @@
#define Handler_parent 24

/* struct c_stack_link */
<<<<<<< HEAD
#if defined(SYS_mingw64) || defined (SYS_cygwin)
#define Cstack_stack 32
#define Cstack_sp 40
Expand All @@ -165,23 +167,6 @@
/* 8 bytes are left empty to ensure the stack is 16-aligned */
#define SIZEOF_C_STACK_LINK 40
#endif
||||||| 121bedcfd2
#define Cstack_stack 0
#define Cstack_sp 8
#define Cstack_prev 16
=======
#if defined(SYS_mingw64) || defined (SYS_cygwin)
#define Cstack_stack 32
#define Cstack_sp 40
#define Cstack_prev 48
#define SIZEOF_C_STACK_LINK 56
#else
#define Cstack_stack 0
#define Cstack_sp 8
#define Cstack_prev 16
#define SIZEOF_C_STACK_LINK 24
#endif
>>>>>>> 5.2.0

/******************************************************************************/
/* DWARF */
Expand Down Expand Up @@ -437,26 +422,7 @@

#endif

<<<<<<< HEAD
#define C_call(target) CHECK_STACK_ALIGNMENT; call target
||||||| 121bedcfd2
#if defined(SYS_mingw64) || defined (SYS_cygwin)
/* Calls from OCaml to C must reserve 32 bytes of extra stack space */
# define PREPARE_FOR_C_CALL subq $32, %rsp; CFI_ADJUST(32)
# define CLEANUP_AFTER_C_CALL addq $32, %rsp; CFI_ADJUST(-32)
/* Stack probing mustn't be larger than the page size */
# define STACK_PROBE_SIZE 4096
#else
# define PREPARE_FOR_C_CALL
# define CLEANUP_AFTER_C_CALL
# define STACK_PROBE_SIZE 4096
#endif

#define C_call(target) \
PREPARE_FOR_C_CALL; CHECK_STACK_ALIGNMENT; call target; CLEANUP_AFTER_C_CALL
=======
#define C_call(target) call target
>>>>>>> 5.2.0

/******************************************************************************/
/* Registers holding arguments of C functions. */
Expand Down Expand Up @@ -583,6 +549,8 @@ G(caml_system__code_begin):
movupd (15*16 + 13*8)(%r15),%xmm15; \
movq Caml_state(young_ptr), %r15

// CR mshinwell: the below probably needs fixing for SIMD

/* Save non-callee saved registers that may be in use to a free gc_regs
bucket, except for %xmm8 to %xmm15 as they are not used to pass
arguments and return values in the System V amd64 ABI.
Expand Down Expand Up @@ -971,11 +939,6 @@ LBL(108):
movq %r10, Caml_state(async_exn_handler)
movq Cstack_prev(%rsp), %r10
movq %r10, Caml_state(c_stack)
<<<<<<< HEAD
addq $SIZEOF_C_STACK_LINK, %rsp; CFI_ADJUST(-SIZEOF_C_STACK_LINK)
||||||| 121bedcfd2
addq $24, %rsp; CFI_ADJUST(-24)
=======
addq $SIZEOF_C_STACK_LINK, %rsp; CFI_ADJUST(-SIZEOF_C_STACK_LINK)
#if defined(WITH_THREAD_SANITIZER)
/* We can't use the TSAN_EXIT_FUNCTION macro as it assumes an OCaml stack,
Expand All @@ -986,7 +949,6 @@ LBL(108):
C_call (GCALL(__tsan_func_exit))
popq %rax; CFI_ADJUST(-8)
#endif
>>>>>>> 5.2.0
/* Restore callee-save registers. */
POP_CALLEE_SAVE_REGS
/* Return to caller. */
Expand Down Expand Up @@ -1021,41 +983,17 @@ LBL(117):
movq %rsp, %r13 /* Save OCaml stack pointer */
movq %rax, %r12 /* Save exception bucket */
movq Caml_state(c_stack), %rsp
<<<<<<< HEAD
movq %rax, C_ARG_1 /* arg 1: exception bucket */
movq %r10, C_ARG_2 /* arg 2: passed rsp */
movq %r13, C_ARG_2 /* arg 2: passed rsp */
movq Caml_state(exn_handler), C_ARG_3
/* arg 3: sp of handler */
C_call (GCALL(caml_stash_backtrace_wrapper))
||||||| 121bedcfd2
movq %rax, C_ARG_1 /* arg 1: exception bucket */
#ifdef WITH_FRAME_POINTERS
movq 8(%r10), C_ARG_2 /* arg 2: pc of raise */
leaq 16(%r10), C_ARG_3 /* arg 3: sp at raise */
#else
movq (%r10), C_ARG_2 /* arg 2: pc of raise */
leaq 8(%r10), C_ARG_3 /* arg 3: sp at raise */
#endif
movq Caml_state(exn_handler), C_ARG_4
/* arg 4: sp of handler */
C_call (GCALL(caml_stash_backtrace))
=======
movq %rax, C_ARG_1 /* arg 1: exception bucket */
movq STACK_RETADDR(%r13), C_ARG_2 /* arg 2: pc of raise */
leaq STACK_ARG_1(%r13), C_ARG_3 /* arg 3: sp at raise */
movq Caml_state(exn_handler), C_ARG_4 /* arg 4: sp of handler */
C_call (GCALL(caml_stash_backtrace))
>>>>>>> 5.2.0
movq %r12, %rax /* Recover exception bucket */
RESTORE_EXN_HANDLER_OCAML
ret
CFI_ENDPROC
ENDFUNCTION(G(caml_raise_exn))

<<<<<<< HEAD

||||||| 121bedcfd2
=======
#if defined(WITH_THREAD_SANITIZER)
/* When TSan support is enabled, this routine should be called just before
raising an exception. It calls __tsan_func_exit for every OCaml frame about
Expand All @@ -1077,7 +1015,6 @@ CFI_ENDPROC
ENDFUNCTION(G(caml_tsan_exit_on_raise_asm))
#endif

>>>>>>> 5.2.0
FUNCTION(G(caml_reraise_exn))
CFI_STARTPROC
ENTER_FUNCTION
Expand Down
6 changes: 0 additions & 6 deletions runtime/amd64nt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@
EXTRN caml_apply3: NEAR
EXTRN caml_program: NEAR
EXTRN caml_array_bound_error_asm: NEAR
<<<<<<< HEAD
EXTRN caml_array_align_error: NEAR
EXTRN caml_stash_backtrace: NEAR
||||||| 121bedcfd2
EXTRN caml_stash_backtrace: NEAR
=======
EXTRN caml_stash_backtrace: NEAR
>>>>>>> 5.2.0

; Load caml/domain_state.tbl (via domain_state.inc, to remove C-style comments)
domain_curr_field = 0
Expand Down
27 changes: 0 additions & 27 deletions runtime/backtrace_byt.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,32 +380,6 @@ static value alloc_callstack(backtrace_slot *trace, size_t slots)
CAMLreturn(callstack);
}

<<<<<<< HEAD
/* Obtain up to [max_slots] of the callstack of the current domain,
* including parent fibers. The callstack is written into [*buffer_p],
* current size [*alloc_size_p], which should be reallocated (on the C
* heap) if required. Returns the number of slots obtained.
*
* [alloc_idx] is ignored, and must be negative (this interface is
* also used by the native-code runtime, in which [alloc_idx] is
* meaningful.
*/

size_t caml_get_callstack(size_t max_slots,
backtrace_slot **buffer_p,
size_t *alloc_size_p,
ssize_t alloc_idx)
{
CAMLassert(alloc_idx < 1); /* allocation indexes not used in bytecode */
return get_callstack(Caml_state->current_stack->sp,
Caml_state->trap_sp_off,
Caml_state->current_stack,
max_slots,
buffer_p, alloc_size_p);
}

||||||| 121bedcfd2
=======
/* Obtain up to [max_slots] of the callstack of the current domain,
* including parent fibers. The callstack is written into [*buffer_p],
* current size [*alloc_size_p], which should be reallocated (on the C
Expand All @@ -429,7 +403,6 @@ size_t caml_get_callstack(size_t max_slots,
buffer_p, alloc_size_p);
}

>>>>>>> 5.2.0
CAMLprim value caml_get_current_callstack (value max_frames_value)
{
backtrace_slot *backtrace = NULL;
Expand Down
Loading

0 comments on commit 3c5e816

Please sign in to comment.