Permalink
Browse files

Lots of fixes: now opt.opt can be built on i386 and other non-multiru…

…ntime architectures
  • Loading branch information...
1 parent 24b551e commit 21eab0f79f02d653f64e8993e98baee7ad604412 @lucasaiu committed Sep 18, 2013
View
65 asmcomp/cmmgen.ml
@@ -1848,6 +1848,66 @@ let emit_all_constants cont =
(* Translate a compilation unit *)
+(* let compunit size ulam = *)
+(* if Config.multicontext_supported then *)
+(* let glob = Compilenv.make_symbol None in *)
+(* let register_module_code = *)
+(* Cop(Cextcall("caml_register_module_r", *)
+(* typ_void, *)
+(* (\*FIXME: no idea; what are these booleans for? --Luca Saiu REENTRANTRUNTIME*\)true, *)
+(* (\*FIXME: no idea; what are these booleans for? --Luca Saiu REENTRANTRUNTIME*\)true, *)
+(* Debuginfo.none), *)
+(* [Cconst_int (size * size_addr); *)
+(* Cconst_symbol((Compilenv.make_symbol None), Cconstant_kind)]) in *)
+(* let actual_init_code = transl ulam in *)
+(* let after_module_initialization_code = *)
+(* Cop(Cextcall("caml_after_module_initialization_r", *)
+(* typ_void, *)
+(* (\*FIXME: no idea; what are these booleans for? --Luca Saiu REENTRANTRUNTIME*\)true, *)
+(* (\*FIXME: no idea; what are these booleans for? --Luca Saiu REENTRANTRUNTIME*\)true, *)
+(* Debuginfo.none), *)
+(* [Cconst_int (size * size_addr); *)
+(* Cconst_symbol((Compilenv.make_symbol None), Cconstant_kind)]) in *)
+(* let init_code = Csequence(register_module_code, *)
+(* Csequence(actual_init_code, *)
+(* after_module_initialization_code)) in *)
+(* let c1 = [Cfunction {fun_name = Compilenv.make_symbol (Some "entry_r"); *)
+(* fun_args = []; *)
+(* fun_body = init_code; fun_fast = false; *)
+(* fun_dbg = Debuginfo.none }] in *)
+(* let c2 = transl_all_functions StringSet.empty c1 in *)
+(* let c3 = emit_all_constants c2 in *)
+(* (\* --Luca Saiu REENTRANTRUNTIME DEBUG *\) *)
+(* (\* Printf.printf "!!!!!!!!!!! size: %i; size_addr: %i\n" size size_addr; *\) *)
+(* (\* Printf.printf "[[[[[[[[[[[[[[[[[\n"; *\) *)
+(* (\* Printcmm.expression (Format.formatter_of_out_channel stdout) (\\* actual_ *\\)init_code; *\) *)
+(* (\* Printf.printf "\n]]]]]]]]]]]]]]]]]\n"; *\) *)
+(* Cdata [Cint(block_header 0 size); *)
+(* Cglobal_symbol glob; *)
+(* Cdefine_symbol glob; *)
+(* (\* Cskip(size * size_addr) *\) (\* This was the original solution --Luca Saiu REENTRANTRUNTIME *\) *)
+(* Cint(Nativeint.minus_one); (\* generate only one word which will store the offset, initializing it with *)
+(* -1, an invalid value recognized as a special "uninitialized" marker. *)
+(* --Luca Saiu REENTRANTRUNTIME *\) *)
+(* Cstring glob; (\* useful for debugging --Luca Saiu REENTRANTRUNTIME *\) *)
+(* Cint8 0; (\* '\0'-terminate the string *\) *)
+(* Calign 8; (\* Don't break the alignment of what follows because of the string*\) *)
+(* ] :: c3 *)
+(* else *)
+(* (\* non-contextual version *\) *)
+(* let glob = Compilenv.make_symbol None in *)
+(* let init_code = transl ulam in *)
+(* let c1 = [Cfunction {fun_name = Compilenv.make_symbol (Some "entry"); *)
+(* fun_args = []; *)
+(* fun_body = init_code; fun_fast = false; *)
+(* fun_dbg = Debuginfo.none }] in *)
+(* let c2 = transl_all_functions StringSet.empty c1 in *)
+(* let c3 = emit_all_constants c2 in *)
+(* Cdata [Cint(block_header 0 size); *)
+(* Cglobal_symbol glob; *)
+(* Cdefine_symbol glob; *)
+(* Cskip(size * size_addr)] :: c3 *)
+
let compunit size ulam =
if Config.multicontext_supported then
let glob = Compilenv.make_symbol None in
@@ -1897,7 +1957,7 @@ let compunit size ulam =
(* non-contextual version *)
let glob = Compilenv.make_symbol None in
let init_code = transl ulam in
- let c1 = [Cfunction {fun_name = Compilenv.make_symbol (Some "entry");
+ let c1 = [Cfunction {fun_name = Compilenv.make_symbol (Some "entry_r");
fun_args = [];
fun_body = init_code; fun_fast = false;
fun_dbg = Debuginfo.none }] in
@@ -2239,7 +2299,8 @@ let entry_point namelist =
let body =
List.fold_right
(fun name next ->
- let entry_sym = Compilenv.make_symbol ~unitname:name (Some "entry") in
+ (* let entry_sym = Compilenv.make_symbol ~unitname:name (Some "entry") in *) (*!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
+ let entry_sym = Compilenv.make_symbol ~unitname:name (Some "entry_r") in
Csequence(Cop(Capply(typ_void, Debuginfo.none),
[Cconst_symbol(entry_sym, Cmm.Cglobal_kind(*FIXME: Cglobal_kind?*))]),
Csequence(incr_global_inited, next)))
View
42 asmrun/roots.c
@@ -149,17 +149,20 @@ void caml_oldify_local_roots_r (CAML_R)
struct caml__roots_block *lr;
caml_link *lnk;
- // Disabled: roots are now in a contextual extensible buffer
- /* The global roots */
- /* for (i = caml_globals_scanned; */
- /* i <= caml_globals_inited && caml_globals[i] != 0; */
- /* i++) { */
- /* glob = caml_globals[i]; */
- /* for (j = 0; j < Wosize_val(glob); j++){ */
- /* Oldify (&Field (glob, j)); */
- /* } */
- /* } */
- /* caml_globals_scanned = caml_globals_inited; */
+#ifndef SUPPORTS_MULTICONTEXT
+ /* The global Caml roots */
+ for (i = caml_globals_scanned;
+ i <= caml_globals_inited && caml_globals[i] != 0;
+ i++) {
+ glob = caml_globals[i];
+ for (j = 0; j < Wosize_val(glob); j++){
+ Oldify (&Field (glob, j));
+ }
+ }
+ QDUMP("Scanned %i non-contextual Caml globals", (int)(i - caml_globals_scanned));
+ caml_globals_scanned = caml_globals_inited;
+ // ???????????????
+#endif // #ifndef SUPPORTS_MULTICONTEXT
/* Dynamic global roots */
iter_list(caml_dyn_globals, lnk) {
@@ -250,16 +253,19 @@ void caml_darken_all_roots_r (CAML_R)
void caml_do_roots_r (CAML_R, scanning_action f)
{
//caml_acquire_global_lock(); // FIXME: is this really needed? I strongly suspect not !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- int /*i,*/ j;
+ int i, j;
value glob;
caml_link *lnk;
- /* /\* The global roots *\/ */
- /* for (i = 0; caml_globals[i] != 0; i++) { */
- /* glob = caml_globals[i]; */
- /* for (j = 0; j < Wosize_val(glob); j++) */
- /* f (ctx, Field (glob, j), &Field (glob, j)); */
- /* } */
+#ifndef SUPPORTS_MULTICONTEXT
+ /* The global roots */
+ for (i = 0; caml_globals[i] != 0; i++) {
+ glob = caml_globals[i];
+ for (j = 0; j < Wosize_val(glob); j++)
+ f (ctx, Field (glob, j), &Field (glob, j));
+ }
+ //?????????
+#endif // #ifndef SUPPORTS_MULTICONTEXT
/* Dynamic global roots */
iter_list(caml_dyn_globals, lnk) {
View
9 asmrun/stack.h
@@ -99,8 +99,13 @@ extern uintnat caml_stack_usage_r (CAML_R);
/* extern uintnat caml_last_return_address; */
/* extern value * caml_gc_regs; */
/* extern char * caml_exception_pointer; */
-/* extern value caml_globals[]; */ // This is now a resizable_buffer, in the context
-/* extern intnat caml_globals_inited; */
+
+#ifndef SUPPORTS_MULTICONTEXT
+/* Generated by the Caml linker, only used for non-multicontext runtimes: */
+extern value caml_globals[];
+extern intnat caml_globals_inited;
+#endif // #ifndef SUPPORTS_MULTICONTEXT
+
extern intnat * caml_frametable[];
#endif /* CAML_STACK_H */
View
BIN boot/myocamlbuild
Binary file not shown.
View
BIN boot/ocamlrun
Binary file not shown.
View
BIN boot/ocamlrun.boot
Binary file not shown.
View
BIN boot/ocamlyacc
Binary file not shown.
View
BIN boot/stdlib.cma
Binary file not shown.
View
17 byterun/context.c
@@ -653,6 +653,7 @@ void* caml_context_local_c_variable_r(CAML_R, caml_c_global_id id){
void caml_scan_caml_globals_r(CAML_R, scanning_action f){
#ifdef NATIVE_CODE
int i, caml_global_no = ctx->caml_globals.used_size / sizeof(value);
+ QDUMP("scanning %i contextual Caml globals", caml_global_no);
if(ctx != caml_get_thread_local_context())
{fprintf(stderr, "Context %p: it's different from the thread-local context %p !!!\n", ctx, caml_get_thread_local_context()); fflush(stderr);};
@@ -810,7 +811,7 @@ void caml_finalize_context_r(CAML_R){
//fprintf(stderr, "caml_finalize_context_r [context %p] [thread %p]: OK-4\n", ctx, (void*)(pthread_self())); fflush(stderr);
//fprintf(stderr, "caml_finalize_context_r [context %p] [thread %p]: OK-5: finalized %p\n", ctx, (void*)(pthread_self()), ctx); fflush(stderr);
- // FIXME: really destroy stuff
+ // FIXME: really destroy fields
}
#ifdef HAS_MULTICONTEXT
@@ -822,7 +823,10 @@ void caml_destroy_context_r(CAML_R){
}
#endif // #ifdef HAS_MULTICONTEXT
-#ifdef NATIVE_CODE
+/* Let's not add this when not needed: calling it by mistake non
+ non-multicontext architectures will make a difficult-to-debug
+ mess: */
+#if defined(NATIVE_CODE) && defined(SUPPORTS_MULTICONTEXT)
/* The index of the first word in caml_globals which is not used yet.
This variable is shared by all contexts, and accessed in mutual
exclusion. */
@@ -848,7 +852,7 @@ void caml_register_module_r(CAML_R, size_t size_in_bytes, long *offset_pointer){
first_unused_word_offset += size_in_words;
caml_allocate_caml_globals_r(ctx, size_in_words);
//caml_resize_global_array_r(ctx, first_unused_word_offset);
- /* fprintf(stderr, "The new first_unused_word_offset is %i\n", (int)first_unused_word_offset); */
+ DUMP("The new first_unused_word_offset is %i\n", (int)first_unused_word_offset);
/* fprintf(stderr, "The global vector is now at %p\n", (void*)ctx->caml_globals.array); */
}
/* else */
@@ -859,11 +863,13 @@ void caml_register_module_r(CAML_R, size_t size_in_bytes, long *offset_pointer){
/* fprintf(stderr, "Globals are at %p\n", (void*)ctx->caml_globals.array); */
//fprintf(stderr, "caml_register_module_r [context %p]: registered %s@%p. END (still alive)\n", ctx, module_name, offset_pointer); fflush(stderr);
}
-#endif /* #ifdef NATIVE_CODE */
void caml_after_module_initialization_r(CAML_R, size_t size_in_bytes, long *offset_pointer){
/* We keep the module name right after the offset pointer, as a read-only string: */
- char *module_name __attribute__ (( unused )) = (char*)offset_pointer + sizeof(long);
+ char *module_name __attribute__ (( unused )) = (char*)offset_pointer - size_in_bytes + sizeof(long);
+
+ DUMP("Initialized the module %s", module_name);
+
//fprintf(stderr, "caml_after_module_initialization_r [context %p]: %s@%p: still alive.\n", ctx, module_name, offset_pointer); fflush(stderr);
/*
fprintf(stderr, "caml_after_module_initialization_r: BEGIN [%lu bytes at %p]\n",
@@ -887,6 +893,7 @@ void caml_after_module_initialization_r(CAML_R, size_t size_in_bytes, long *offs
fprintf(stderr, "caml_after_module_initialization_r: END (still alive)\n\n");
*/
}
+#endif /* #if defined(NATIVE_CODE) && defined(SUPPORTS_MULTICONTEXT) */
/* FIXME: use a custom value instead. However this in practice works
fine on 64-bit architectures: */
View
16 myocamlbuild_config.ml
@@ -1,4 +1,4 @@
-(* # generated by ./configure --prefix /home/luca/usr-patched-ocaml --with-debug-runtime --no-multicontext *)
+(* # generated by ./configure --with-debug-runtime --prefix /home/luca/usr-patched-ocaml *)
let prefix = "/home/luca/usr-patched-ocaml";;
let bindir = prefix^"/bin";;
let libdir = prefix^"/lib/ocaml";;
@@ -9,18 +9,18 @@ let ranlib = "ranlib";;
let ranlibcmd = "ranlib";;
let arcmd = "ar";;
let sharpbangscripts = true;;
-let bng_arch = "amd64";;
-let bng_asm_level = "1";;
+let bng_arch = "ia32";;
+let bng_asm_level = "2";;
let pthread_link = "-cclib -lpthread";;
let x11_includes = "not found";;
let x11_link = "not found";;
let tk_defs = "";;
let tk_link = "";;
-let libbfd_link = "-lbfd -ldl -liberty -lz";;
+let libbfd_link = "";;
let bytecc = "gcc";;
let bytecccompopts = "-fno-defer-pop -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT";;
let bytecclinkopts = " -Wl,-E";;
-let bytecclibs = " -lm -ldl -lcurses -lpthread";;
+let bytecclibs = " -lm -ldl -lpthread";;
let byteccrpath = "-Wl,-rpath,";;
let exe = "";;
let supports_shared_libraries = true;;
@@ -33,9 +33,9 @@ let syslib x = "-l"^x;;
(* ## *)
(* MKLIB=ar rc "^1^" "^2^"; ranlib "^1^" *)
let mklib out files opts = Printf.sprintf "ar rc %s %s %s; ranlib %s" out opts files out;;
-let arch = "amd64";;
+let arch = "i386";;
let model = "default";;
-let system = "linux";;
+let system = "linux_elf";;
let nativecc = "gcc";;
let nativecccompopts = "-Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT";;
let nativeccprofopts = "-Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT";;
@@ -74,5 +74,5 @@ let mkmaindll = "gcc -shared";;
let runtimed = "runtimed";;
let camlp4 = "camlp4";;
let asm_cfi_supported = true;;
-let multicontext_supported = true;;
+let multicontext_supported = false;;
let multicontext_enabled = false;;
View
16 tools/myocamlbuild_config.ml
@@ -1,4 +1,4 @@
-(* # generated by ./configure --prefix /home/luca/usr-patched-ocaml --with-debug-runtime --no-multicontext *)
+(* # generated by ./configure --with-debug-runtime --prefix /home/luca/usr-patched-ocaml *)
let prefix = "/home/luca/usr-patched-ocaml";;
let bindir = prefix^"/bin";;
let libdir = prefix^"/lib/ocaml";;
@@ -9,18 +9,18 @@ let ranlib = "ranlib";;
let ranlibcmd = "ranlib";;
let arcmd = "ar";;
let sharpbangscripts = true;;
-let bng_arch = "amd64";;
-let bng_asm_level = "1";;
+let bng_arch = "ia32";;
+let bng_asm_level = "2";;
let pthread_link = "-cclib -lpthread";;
let x11_includes = "not found";;
let x11_link = "not found";;
let tk_defs = "";;
let tk_link = "";;
-let libbfd_link = "-lbfd -ldl -liberty -lz";;
+let libbfd_link = "";;
let bytecc = "gcc";;
let bytecccompopts = "-fno-defer-pop -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT";;
let bytecclinkopts = " -Wl,-E";;
-let bytecclibs = " -lm -ldl -lcurses -lpthread";;
+let bytecclibs = " -lm -ldl -lpthread";;
let byteccrpath = "-Wl,-rpath,";;
let exe = "";;
let supports_shared_libraries = true;;
@@ -33,9 +33,9 @@ let syslib x = "-l"^x;;
(* ## *)
(* MKLIB=ar rc "^1^" "^2^"; ranlib "^1^" *)
let mklib out files opts = Printf.sprintf "ar rc %s %s %s; ranlib %s" out opts files out;;
-let arch = "amd64";;
+let arch = "i386";;
let model = "default";;
-let system = "linux";;
+let system = "linux_elf";;
let nativecc = "gcc";;
let nativecccompopts = "-Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT";;
let nativeccprofopts = "-Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT";;
@@ -74,5 +74,5 @@ let mkmaindll = "gcc -shared";;
let runtimed = "runtimed";;
let camlp4 = "camlp4";;
let asm_cfi_supported = true;;
-let multicontext_supported = true;;
+let multicontext_supported = false;;
let multicontext_enabled = false;;

0 comments on commit 21eab0f

Please sign in to comment.