From abfa48bedcb498f0100797512cfd09a2c99305c8 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 10:45:33 +0100 Subject: [PATCH 01/42] Add -Wl,--start-group & -Wl,--end-group It's probably a better way to add libraries when we link objects from OCaml. With these options, we allow the linker to resolve all symbols regardless the order of these libraries. Indeed, the linker will repeatly lookup on these libraries until all symbols are resolved. However, it seems that these options can have an impact about performances of the linker. If we need to improve this situation, we must recalculate a topological order of libraries. But for our purpose, that's probably fine. Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e819259a..41b35481 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ LOCAL_CFLAGS=$(MAKECONF_CFLAGS) -I$(TOP)/nolibc/include -include _solo5/override # CFLAGS used by the OCaml compiler to build C stubs GLOBAL_CFLAGS=$(MAKECONF_CFLAGS) -I$(MAKECONF_PREFIX)/solo5-sysroot/include/nolibc/ -include _solo5/overrides.h # LIBS used by the OCaml compiler to link executables -GLOBAL_LIBS=-L$(MAKECONF_PREFIX)/solo5-sysroot/lib/nolibc/ -lnolibc -lopenlibm $(MAKECONF_EXTRA_LIBS) +GLOBAL_LIBS=-L$(MAKECONF_PREFIX)/solo5-sysroot/lib/nolibc/ -Wl,--start-group -lnolibc -lopenlibm $(MAKECONF_EXTRA_LIBS) -Wl,--end-group # NOLIBC NOLIBC_CFLAGS=$(LOCAL_CFLAGS) -I$(TOP)/openlibm/src -I$(TOP)/openlibm/include @@ -45,7 +45,7 @@ ocaml/Makefile: # configure link test # - We override OCAML_OS_TYPE since configure just hardcodes it to "Unix". OC_CFLAGS=$(LOCAL_CFLAGS) -I$(TOP)/openlibm/include -I$(TOP)/openlibm/src -nostdlib -OC_LIBS=-L$(TOP)/nolibc -lnolibc -L$(TOP)/openlibm -lopenlibm -nostdlib $(MAKECONF_EXTRA_LIBS) +OC_LIBS=-L$(TOP)/nolibc -lnolibc -L$(TOP)/openlibm -Wl,--start-group -lopenlibm -nostdlib $(MAKECONF_EXTRA_LIBS) -Wl,--end-group ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a # configure: Do not build dynlink sed -i -e 's/otherlibraries="dynlink"/otherlibraries=""/g' ocaml/configure From 32633a86ff7d358e8b3c34c505e55cb8e49ae737 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 11:32:31 +0100 Subject: [PATCH 02/42] Delete the usage of `sed -i` (and replace it by `sed && mv`) `sed -i` is not POSIX, it's better to generate a `*.sed` file and move it to the real destination. Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 41b35481..2b65e6ac 100644 --- a/Makefile +++ b/Makefile @@ -48,22 +48,32 @@ OC_CFLAGS=$(LOCAL_CFLAGS) -I$(TOP)/openlibm/include -I$(TOP)/openlibm/src -nostd OC_LIBS=-L$(TOP)/nolibc -lnolibc -L$(TOP)/openlibm -Wl,--start-group -lopenlibm -nostdlib $(MAKECONF_EXTRA_LIBS) -Wl,--end-group ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a # configure: Do not build dynlink - sed -i -e 's/otherlibraries="dynlink"/otherlibraries=""/g' ocaml/configure + sed -e 's/otherlibraries="dynlink"/otherlibraries=""/g' ocaml/configure > ocaml/configure.sed && \ + mv ocaml/configure.sed ocaml/configure # configure: Allow precise input of flags and libs - sed -i -e 's/oc_cflags="/oc_cflags="$$OC_CFLAGS /g' ocaml/configure - sed -i -e 's/ocamlc_cflags="/ocamlc_cflags="$$OCAMLC_CFLAGS /g' ocaml/configure - sed -i -e 's/nativecclibs="$$cclibs $$DLLIBS"/nativecclibs="$$GLOBAL_LIBS"/g' ocaml/configure + sed -e 's/oc_cflags="/oc_cflags="$$OC_CFLAGS /g' ocaml/configure > ocaml/configure.sed && \ + mv ocaml/configure.sed ocaml/configure + sed -e 's/ocamlc_cflags="/ocamlc_cflags="$$OCAMLC_CFLAGS /g' ocaml/configure > ocaml/configure.sed && \ + mv ocaml/configure.sed ocaml/configure + sed -e 's/nativecclibs="$$cclibs $$DLLIBS"/nativecclibs="$$GLOBAL_LIBS"/g' ocaml/configure > ocaml/configure.sed && \ + mv ocaml/configure.sed ocaml/configure + chmod +x ocaml/configure # runtime/Makefile: Runtime rules: don't build libcamlrun.a and import ocamlrun from the system - sed -i -e 's/^all: $$(BYTECODE_STATIC_LIBRARIES) $$(BYTECODE_SHARED_LIBRARIES)/all: primitives ld.conf/' ocaml/runtime/Makefile - sed -i -e 's/^ocamlrun$$(EXE):.*/dummy:/g' ocaml/runtime/Makefile - sed -i -e 's/^ocamlruni$$(EXE):.*/dummyi:/g' ocaml/runtime/Makefile - sed -i -e 's/^ocamlrund$$(EXE):.*/dummyd:/g' ocaml/runtime/Makefile + sed -e 's/^all: $$(BYTECODE_STATIC_LIBRARIES) $$(BYTECODE_SHARED_LIBRARIES)/all: primitives ld.conf/' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ + mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile + sed -e 's/^ocamlrun$$(EXE):.*/dummy:/g' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ + mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile + sed -e 's/^ocamlruni$$(EXE):.*/dummyi:/g' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ + mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile + sed -e 's/^ocamlrund$$(EXE):.*/dummyd:/g' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ + mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile echo -e "ocamlrun:\n\tcp $(shell which ocamlrun) .\n" >> ocaml/runtime/Makefile echo -e "ocamlrund:\n\tcp $(shell which ocamlrund) .\n" >> ocaml/runtime/Makefile echo -e "ocamlruni:\n\tcp $(shell which ocamlruni) .\n" >> ocaml/runtime/Makefile touch ocaml/runtime/libcamlrun.a ocaml/runtime/libcamlrund.a ocaml/runtime/libcamlruni.a # yacc/Makefile: import ocamlyacc from the system - sed -i -e 's/^ocamlyacc$$(EXE):.*/dummy:/g' ocaml/yacc/Makefile + sed -e 's/^ocamlyacc$$(EXE):.*/dummy:/g' ocaml/yacc/Makefile > ocaml/yacc/Makefile.sed && \ + mv ocaml/yacc/Makefile.sed ocaml/yacc/Makefile echo -e "ocamlyacc:\n\tcp $(shell which ocamlyacc) .\n" >> ocaml/yacc/Makefile # tools/Makefile: stub out objinfo_helper echo -e "objinfo_helper:\n\ttouch objinfo_helper\n" >> ocaml/tools/Makefile From d2e4a0bca39de33c682019f28b3684068361d8b2 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 11:36:40 +0100 Subject: [PATCH 03/42] Specify the architecture into the OCaml's `./configure` script Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2b65e6ac..3fba2c2d 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,8 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a mv ocaml/configure.sed ocaml/configure sed -e 's/nativecclibs="$$cclibs $$DLLIBS"/nativecclibs="$$GLOBAL_LIBS"/g' ocaml/configure > ocaml/configure.sed && \ mv ocaml/configure.sed ocaml/configure + sed -e 's/^arch=none$$/arch=$(MAKECONF_OCAML_BUILD_ARCH)/' ocaml/configure > ocaml/configure.sed && \ + mv ocaml/configure.sed ocaml/configure chmod +x ocaml/configure # runtime/Makefile: Runtime rules: don't build libcamlrun.a and import ocamlrun from the system sed -e 's/^all: $$(BYTECODE_STATIC_LIBRARIES) $$(BYTECODE_SHARED_LIBRARIES)/all: primitives ld.conf/' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ @@ -102,7 +104,6 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a -disable-ocamltest\ -disable-ocamldoc\ $(MAKECONF_OCAML_CONFIGURE_OPTIONS) - echo "ARCH=$(MAKECONF_OCAML_BUILD_ARCH)" >> ocaml/Makefile.config echo 'SAK_CC=cc' >> ocaml/Makefile.config echo 'SAK_CFLAGS=' >> ocaml/Makefile.config echo 'SAK_LINK=cc $(SAK_CFLAGS) $$(OUTPUTEXE)$$(1) $$(2)' >> ocaml/Makefile.config From 0f97e4dd3d58ba5e811cd7fbd6109f79d7439d80 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 11:38:14 +0100 Subject: [PATCH 04/42] Add $$PTHREAD_LIB into our pattern to modify nativecclibs With OCaml 5, the pattern was updated and has $$PTHREAD_LIB. We update accordingly. Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3fba2c2d..a9e771fd 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a mv ocaml/configure.sed ocaml/configure sed -e 's/ocamlc_cflags="/ocamlc_cflags="$$OCAMLC_CFLAGS /g' ocaml/configure > ocaml/configure.sed && \ mv ocaml/configure.sed ocaml/configure - sed -e 's/nativecclibs="$$cclibs $$DLLIBS"/nativecclibs="$$GLOBAL_LIBS"/g' ocaml/configure > ocaml/configure.sed && \ + sed -e 's/nativecclibs="$$cclibs $$DLLIBS $$PTHREAD_LIBS"/nativecclibs="$$GLOBAL_LIBS"/g' ocaml/configure > ocaml/configure.sed && \ mv ocaml/configure.sed ocaml/configure sed -e 's/^arch=none$$/arch=$(MAKECONF_OCAML_BUILD_ARCH)/' ocaml/configure > ocaml/configure.sed && \ mv ocaml/configure.sed ocaml/configure From 6a0fc20457589be569a1fbe9d71e453109d49a7c Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 11:41:36 +0100 Subject: [PATCH 05/42] Add runtime/primitives as a dependency for the coldstart rule Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index a9e771fd..440fc89f 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,8 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile sed -e 's/^ocamlrund$$(EXE):.*/dummyd:/g' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile + sed -e 's,^coldstart: $(COLDSTART_DEPS)$$,coldstart: runtime/primitives $$(COLDSTART_DEPS),' ocaml/Makefile > ocaml/Makefile.sed && \ + mv ocaml/Makefile.sed ocaml/Makefile echo -e "ocamlrun:\n\tcp $(shell which ocamlrun) .\n" >> ocaml/runtime/Makefile echo -e "ocamlrund:\n\tcp $(shell which ocamlrund) .\n" >> ocaml/runtime/Makefile echo -e "ocamlruni:\n\tcp $(shell which ocamlruni) .\n" >> ocaml/runtime/Makefile From 453e289ea09c831678ebcc59bb0563869cc2c724 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 13:31:14 +0100 Subject: [PATCH 06/42] ocamlrun{,d,i} are located into the runtime directory Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 440fc89f..b0c73b17 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,9 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a echo -e "ocamlrun:\n\tcp $(shell which ocamlrun) .\n" >> ocaml/runtime/Makefile echo -e "ocamlrund:\n\tcp $(shell which ocamlrund) .\n" >> ocaml/runtime/Makefile echo -e "ocamlruni:\n\tcp $(shell which ocamlruni) .\n" >> ocaml/runtime/Makefile + echo -e "runtime/ocamlrun\$$(EXE):\n\tcp $(shell which ocamlrun) runtime/\n" >> ocaml/Makefile + echo -e "runtime/ocamlrund\$$(EXE):\n\tcp $(shell which ocamlrund) runtime/\n" >> ocaml/Makefile + echo -e "runtime/ocamlruni\$$(EXE):\n\tcp $(shell which ocamlruni) runtime/\n" >> ocaml/Makefile touch ocaml/runtime/libcamlrun.a ocaml/runtime/libcamlrund.a ocaml/runtime/libcamlruni.a # yacc/Makefile: import ocamlyacc from the system sed -e 's/^ocamlyacc$$(EXE):.*/dummy:/g' ocaml/yacc/Makefile > ocaml/yacc/Makefile.sed && \ From 10f2f9b44777668eeabe6716583153c30f18028c Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 13:31:58 +0100 Subject: [PATCH 07/42] Delete fake libcamlrun{,d,i}.a from the Makefile Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index b0c73b17..fff0336f 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,6 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a echo -e "runtime/ocamlrun\$$(EXE):\n\tcp $(shell which ocamlrun) runtime/\n" >> ocaml/Makefile echo -e "runtime/ocamlrund\$$(EXE):\n\tcp $(shell which ocamlrund) runtime/\n" >> ocaml/Makefile echo -e "runtime/ocamlruni\$$(EXE):\n\tcp $(shell which ocamlruni) runtime/\n" >> ocaml/Makefile - touch ocaml/runtime/libcamlrun.a ocaml/runtime/libcamlrund.a ocaml/runtime/libcamlruni.a # yacc/Makefile: import ocamlyacc from the system sed -e 's/^ocamlyacc$$(EXE):.*/dummy:/g' ocaml/yacc/Makefile > ocaml/yacc/Makefile.sed && \ mv ocaml/yacc/Makefile.sed ocaml/yacc/Makefile From 7975a11c0988e69cbce6e1f011eeebb9258a4f49 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 13:12:48 +0100 Subject: [PATCH 08/42] /runtime/Makefile was deleted (OCaml 5.0) and everything is into /Makefile Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index fff0336f..ca3733ca 100644 --- a/Makefile +++ b/Makefile @@ -60,20 +60,18 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a sed -e 's/^arch=none$$/arch=$(MAKECONF_OCAML_BUILD_ARCH)/' ocaml/configure > ocaml/configure.sed && \ mv ocaml/configure.sed ocaml/configure chmod +x ocaml/configure -# runtime/Makefile: Runtime rules: don't build libcamlrun.a and import ocamlrun from the system - sed -e 's/^all: $$(BYTECODE_STATIC_LIBRARIES) $$(BYTECODE_SHARED_LIBRARIES)/all: primitives ld.conf/' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ - mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile - sed -e 's/^ocamlrun$$(EXE):.*/dummy:/g' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ - mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile - sed -e 's/^ocamlruni$$(EXE):.*/dummyi:/g' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ - mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile - sed -e 's/^ocamlrund$$(EXE):.*/dummyd:/g' ocaml/runtime/Makefile > ocaml/runtime/Makefile.sed && \ - mv ocaml/runtime/Makefile.sed ocaml/runtime/Makefile +# Makefile: Runtime rules: don't build libcamlrun.a and import ocamlrun from the system + sed -e 's/^ocamlrun$$(EXE):.*/dummy:/g' ocaml/Makefile > ocaml/Makefile.sed && \ + mv ocaml/Makefile.sed ocaml/Makefile + sed -e 's/^ocamlruni$$(EXE):.*/dummyi:/g' ocaml/Makefile > ocaml/Makefile.sed && \ + mv ocaml/Makefile.sed ocaml/Makefile + sed -e 's/^ocamlrund$$(EXE):.*/dummyd:/g' ocaml/Makefile > ocaml/Makefile.sed && \ + mv ocaml/Makefile.sed ocaml/Makefile sed -e 's,^coldstart: $(COLDSTART_DEPS)$$,coldstart: runtime/primitives $$(COLDSTART_DEPS),' ocaml/Makefile > ocaml/Makefile.sed && \ mv ocaml/Makefile.sed ocaml/Makefile - echo -e "ocamlrun:\n\tcp $(shell which ocamlrun) .\n" >> ocaml/runtime/Makefile - echo -e "ocamlrund:\n\tcp $(shell which ocamlrund) .\n" >> ocaml/runtime/Makefile - echo -e "ocamlruni:\n\tcp $(shell which ocamlruni) .\n" >> ocaml/runtime/Makefile + echo -e "ocamlrun:\n\tcp $(shell which ocamlrun) .\n" >> ocaml/Makefile + echo -e "ocamlrund:\n\tcp $(shell which ocamlrund) .\n" >> ocaml/Makefile + echo -e "ocamlruni:\n\tcp $(shell which ocamlruni) .\n" >> ocaml/Makefile echo -e "runtime/ocamlrun\$$(EXE):\n\tcp $(shell which ocamlrun) runtime/\n" >> ocaml/Makefile echo -e "runtime/ocamlrund\$$(EXE):\n\tcp $(shell which ocamlrund) runtime/\n" >> ocaml/Makefile echo -e "runtime/ocamlruni\$$(EXE):\n\tcp $(shell which ocamlruni) runtime/\n" >> ocaml/Makefile From 54806110c2bd655bf98dd1fdef5e73163e06e8e9 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 13:33:39 +0100 Subject: [PATCH 09/42] Replace ocamlyacc by $$(ocamlyacc_PROGRAM) Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ca3733ca..109bfc76 100644 --- a/Makefile +++ b/Makefile @@ -76,9 +76,9 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a echo -e "runtime/ocamlrund\$$(EXE):\n\tcp $(shell which ocamlrund) runtime/\n" >> ocaml/Makefile echo -e "runtime/ocamlruni\$$(EXE):\n\tcp $(shell which ocamlruni) runtime/\n" >> ocaml/Makefile # yacc/Makefile: import ocamlyacc from the system - sed -e 's/^ocamlyacc$$(EXE):.*/dummy:/g' ocaml/yacc/Makefile > ocaml/yacc/Makefile.sed && \ - mv ocaml/yacc/Makefile.sed ocaml/yacc/Makefile - echo -e "ocamlyacc:\n\tcp $(shell which ocamlyacc) .\n" >> ocaml/yacc/Makefile + sed -e 's,^$$(ocamlyacc_PROGRAM)$$(EXE):.*,dummy_yacc:,g' ocaml/Makefile > ocaml/Makefile.sed && \ + mv ocaml/Makefile.sed ocaml/Makefile + echo -e "\$$(ocamlyacc_PROGRAM)\$$(EXE):\n\tcp $(shell which ocamlyacc) yacc/\n" >> ocaml/Makefile # tools/Makefile: stub out objinfo_helper echo -e "objinfo_helper:\n\ttouch objinfo_helper\n" >> ocaml/tools/Makefile # av_cv_libm_cos=no is passed to configure to prevent -lm being used (which From b45acbd1795e72b195508c24e7e4916b2f910213 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 13:34:57 +0100 Subject: [PATCH 10/42] Replace the number of domains into our OCaml runtime Currently, OCaml 5.0 wants to create 128 domains which requires a big allocation. We decided to allow the usage of only 1 domain. Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 109bfc76..6f9983b3 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,9 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a sed -e 's,^$$(ocamlyacc_PROGRAM)$$(EXE):.*,dummy_yacc:,g' ocaml/Makefile > ocaml/Makefile.sed && \ mv ocaml/Makefile.sed ocaml/Makefile echo -e "\$$(ocamlyacc_PROGRAM)\$$(EXE):\n\tcp $(shell which ocamlyacc) yacc/\n" >> ocaml/Makefile +# patch ocaml 5.0.0 runtime for single domain/thread solo5 + sed -e 's/#define Max_domains 128/#define Max_domains 1/' ocaml/runtime/caml/domain.h > ocaml/runtime/caml/domain.h.sed && \ + mv ocaml/runtime/caml/domain.h.sed ocaml/runtime/caml/domain.h # tools/Makefile: stub out objinfo_helper echo -e "objinfo_helper:\n\ttouch objinfo_helper\n" >> ocaml/tools/Makefile # av_cv_libm_cos=no is passed to configure to prevent -lm being used (which From a87ca82a6870e866c0927e1a1b6a3936ff3e5510 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 13:37:11 +0100 Subject: [PATCH 11/42] Disable debug runtime Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 6f9983b3..8d7baac8 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,7 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a -disable-systhreads\ -disable-unix-lib\ -disable-instrumented-runtime\ + -disable-debug-runtime\ -disable-ocamltest\ -disable-ocamldoc\ $(MAKECONF_OCAML_CONFIGURE_OPTIONS) From a817e26b81839e66272bd6d24ea173c44f19eb58 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 13:22:26 +0100 Subject: [PATCH 12/42] Delete unecessary tweak Makefile rule about objinfo_helper Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 8d7baac8..28642b3d 100644 --- a/Makefile +++ b/Makefile @@ -82,8 +82,6 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a # patch ocaml 5.0.0 runtime for single domain/thread solo5 sed -e 's/#define Max_domains 128/#define Max_domains 1/' ocaml/runtime/caml/domain.h > ocaml/runtime/caml/domain.h.sed && \ mv ocaml/runtime/caml/domain.h.sed ocaml/runtime/caml/domain.h -# tools/Makefile: stub out objinfo_helper - echo -e "objinfo_helper:\n\ttouch objinfo_helper\n" >> ocaml/tools/Makefile # av_cv_libm_cos=no is passed to configure to prevent -lm being used (which # would use the host system libm instead of the freestanding openlibm, see # https://github.com/mirage/ocaml-solo5/issues/101 From 0c86e1a5e726f3c0abb2422dbaba247a4999ca2b Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 13:38:20 +0100 Subject: [PATCH 13/42] Add a missing / into our nolibc's test-include/%.c rule Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nolibc/Makefile b/nolibc/Makefile index 4294f2cf..4dd36d45 100644 --- a/nolibc/Makefile +++ b/nolibc/Makefile @@ -42,15 +42,15 @@ TEST_H_OBJS=$(patsubst %.h,test-%.o,$(HEADERS)) # For each HEADER we want to test, generate a C source file including only # that HEADER. As above, HEADER may include subdirectories. -test-include/%.c: include/%.h | test-include/sys +test-include/%.c: include/%.h | test-include/sys/ echo "#include \"../$<\"" >$@ .PRECIOUS: test-include/%.c -test-include: +test-include/: mkdir $@ -test-include/sys: test-include +test-include/sys/: test-include/ mkdir $@ test-headers: $(TEST_H_OBJS) From 9f946179b98e596514121938c94a18fa342e3895 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 13:39:25 +0100 Subject: [PATCH 14/42] Add the -p option when we use mkdir (nolibc's Makefile) Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nolibc/Makefile b/nolibc/Makefile index 4dd36d45..0d262393 100644 --- a/nolibc/Makefile +++ b/nolibc/Makefile @@ -48,9 +48,9 @@ test-include/%.c: include/%.h | test-include/sys/ .PRECIOUS: test-include/%.c test-include/: - mkdir $@ + mkdir -p $@ test-include/sys/: test-include/ - mkdir $@ + mkdir -p $@ test-headers: $(TEST_H_OBJS) From b89d736657f1e2da19f2a22e26c2f3e27d520495 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 13:40:43 +0100 Subject: [PATCH 15/42] Set NATIVE_COMPILER to true into the OCaml's Makefile.config Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 28642b3d..dbe1e869 100644 --- a/Makefile +++ b/Makefile @@ -108,6 +108,7 @@ ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a -disable-ocamltest\ -disable-ocamldoc\ $(MAKECONF_OCAML_CONFIGURE_OPTIONS) + echo 'NATIVE_COMPILER=true' >> ocaml/Makefile.config echo 'SAK_CC=cc' >> ocaml/Makefile.config echo 'SAK_CFLAGS=' >> ocaml/Makefile.config echo 'SAK_LINK=cc $(SAK_CFLAGS) $$(OUTPUTEXE)$$(1) $$(2)' >> ocaml/Makefile.config From 230213d965043b84e79aa7d95bb7e05c63ed172d Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:11:59 +0100 Subject: [PATCH 16/42] Add test-include/sys/ as a dependency for test-headers (nolibc's Makefile) Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nolibc/Makefile b/nolibc/Makefile index 0d262393..cbeb5d78 100644 --- a/nolibc/Makefile +++ b/nolibc/Makefile @@ -53,4 +53,4 @@ test-include/: test-include/sys/: test-include/ mkdir -p $@ -test-headers: $(TEST_H_OBJS) +test-headers: test-include/sys/ $(TEST_H_OBJS) From d912fb096d158b5240032a97514c6bcab165a625 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:18:13 +0100 Subject: [PATCH 17/42] Define EBUSY Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/errno.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nolibc/include/errno.h b/nolibc/include/errno.h index 67c3b760..fedbe481 100644 --- a/nolibc/include/errno.h +++ b/nolibc/include/errno.h @@ -10,5 +10,9 @@ extern int errno; #define EINVAL 6 #define ENOMEM 7 #define EMFILE 8 +#define EBUSY 9 +/* TODO(dinosaure): we probably should follow the Cosmopolitan + * project about these constants and use values where we have + * an {unix,bsd} consensus. */ #endif From a0b57c0ca5483d9aba43d400261d0c9b76661e66 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:19:29 +0100 Subject: [PATCH 18/42] Define O_RDWR Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/fcntl.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nolibc/include/fcntl.h b/nolibc/include/fcntl.h index a291d292..fd45d996 100644 --- a/nolibc/include/fcntl.h +++ b/nolibc/include/fcntl.h @@ -9,5 +9,9 @@ int open(const char *, int, ...); #define O_CREAT (1<<3) #define O_TRUNC (1<<4) #define O_EXCL (1<<5) +#define O_RDWR (1<<6) +/* TODO(dinosaure): same as errno values, we should take a + * look on the Cosmopolitan project and set values when + * we can find an {unix,bsd} consensus. */ #endif From 81b73f9c908cc5db8aa5a032c1b9c1e12054b0ec Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:28:32 +0100 Subject: [PATCH 19/42] Define SIG_BLOCK/SIG_SETMASK Initially, we used NULL and it seems that these values are used by GMP. We probably break something here if NULL <> 0 but conventionally, NULL = 0. Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/signal.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nolibc/include/signal.h b/nolibc/include/signal.h index 53fa89f3..f5479046 100644 --- a/nolibc/include/signal.h +++ b/nolibc/include/signal.h @@ -4,12 +4,19 @@ typedef int jmp_buf; int setjmp(jmp_buf); void (*signal(int sig, void (*func)(int)))(int); -#define SIG_DFL NULL -#define SIG_IGN NULL -#define SIG_ERR NULL +#define SIG_DFL 0 +#define SIG_IGN 0 +#define SIG_ERR 0 +#define SIG_BLOCK 0 +#define SIG_SETMASK 0 /* * The following definitions are not required by the OCaml runtime, but are * needed to build the freestanding version of GMP used by Mirage. + * For OCaml 5.0.0, it's not totally true. SIG_{BLOCK,SETMASK,IGN,DFL) are + * needed by the OCaml runtime. + * + * NOTE: Solo5 does not implement signals, but we should not trigger + * a situation where these values are really used. */ #define SIGFPE 1 int raise(int); From 7d021b89fe1be0d30b09474978fcbbebddc3ce39 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 14:08:22 +0100 Subject: [PATCH 20/42] Define S_{IR,IW}USR Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/sys/stat.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nolibc/include/sys/stat.h b/nolibc/include/sys/stat.h index 3f0ddffb..ab9b00b5 100644 --- a/nolibc/include/sys/stat.h +++ b/nolibc/include/sys/stat.h @@ -11,6 +11,8 @@ struct stat { #define S_IFMT 0 #define S_IFREG 0 #define S_ISREG(x) (0) +#define S_IRUSR 0 +#define S_IWUSR 0 int stat(const char *, struct stat *); int mkdir(const char *, mode_t); From d96e15706bef008026cf597056f0fe8c2b228eff Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:20:24 +0100 Subject: [PATCH 21/42] Stub pthread Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/pthread.h | 57 ++++++++++++++++++++++++++++++++++++++++ nolibc/stubs.c | 42 +++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 nolibc/include/pthread.h diff --git a/nolibc/include/pthread.h b/nolibc/include/pthread.h new file mode 100644 index 00000000..ea7b5651 --- /dev/null +++ b/nolibc/include/pthread.h @@ -0,0 +1,57 @@ +#ifndef _PTHREAD_H +#define _PTHREAD_H + +#include +#include + +typedef unsigned long int pthread_t; +typedef int cpu_set_t; + +int pthread_getaffinity_np(pthread_t, size_t, cpu_set_t *); + +pthread_t pthread_self(void); + +typedef int pthread_attr_t; + +int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *); +int pthread_join(pthread_t, void **); +int pthread_attr_init(pthread_attr_t *); +void pthread_cleanup_push(void (*)(void *), void *); +void pthread_cleanup_pop(int); + +typedef int pthread_mutex_t; +typedef int pthread_cond_t; + +int pthread_mutex_lock(pthread_mutex_t *); +int pthread_mutex_trylock(pthread_mutex_t *); +int pthread_mutex_unlock(pthread_mutex_t *); + +#define PTHREAD_MUTEX_INITIALIZER 0 +#define PTHREAD_COND_INITIALIZER 0 + +int pthread_sigmask(int, const sigset_t *, sigset_t *); +int pthread_detach(pthread_t); +int pthread_equal(pthread_t, pthread_t); + +typedef int pthread_mutexattr_t; + +int pthread_mutexattr_init(pthread_mutexattr_t *); +int pthread_mutexattr_settype(pthread_mutexattr_t *, int); + +#define PTHREAD_MUTEX_ERRORCHECK 0 + +int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); +int pthread_mutexattr_destroy(pthread_mutexattr_t *); +int pthread_mutex_destroy(pthread_mutex_t *); + +typedef int pthread_condattr_t; + +int pthread_condattr_init(pthread_condattr_t *); +int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *); + +int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); +int pthread_cond_broadcast(pthread_cond_t *); +int pthread_cond_signal(pthread_cond_t *); +int pthread_cond_destroy(pthread_cond_t *); + +#endif diff --git a/nolibc/stubs.c b/nolibc/stubs.c index 5f951b0a..e444f2a5 100644 --- a/nolibc/stubs.c +++ b/nolibc/stubs.c @@ -100,3 +100,45 @@ STUB_ABORT(strerror); /* sys/stat.h */ STUB_WARN_ONCE(int, stat, -1); STUB_ABORT(mkdir); + +/* pthread.h */ +STUB_IGNORE(int, pthread_join, 0); +STUB_IGNORE(int, pthread_create, 0); +STUB_IGNORE(int, pthread_attr_init, 0); +STUB_ABORT(pthread_cleanup_push); +STUB_ABORT(pthread_cleanup_pop); + +STUB_IGNORE(int, munmap, 0); /* TODO: Implement munmap correctly and avoid memory leaks */ + +int memory_order_release; +int memory_order_acquire; +int memory_order_relaxed; + +STUB_ABORT(atomic_store_explicit); +STUB_ABORT(atomic_exchange); + +/* above that line, for OCaml 5, those are only required (i guess) for the configure step */ +STUB_IGNORE(int, pthread_mutex_lock, 0); +STUB_IGNORE(int, pthread_mutex_trylock, 0); +STUB_IGNORE(int, pthread_mutex_unlock, 0); +STUB_IGNORE(int, pthread_mutex_destroy, 0); +STUB_IGNORE(int, pthread_mutex_init, 0); + +STUB_IGNORE(int, pthread_mutexattr_init, 0); +STUB_IGNORE(int, pthread_mutexattr_destroy, 0); +STUB_IGNORE(int, pthread_mutexattr_settype, 0); + +STUB_IGNORE(int, pthread_sigmask, 0); + +STUB_IGNORE(int, pthread_equal, 1); + +STUB_IGNORE(int, pthread_condattr_init, 0); +/* TODO: Is there a memory leak in OCaml? Shouldn't there be a call to pthread_condattr_destroy? */ + +STUB_IGNORE(int, pthread_cond_init, 0); +STUB_ABORT(pthread_cond_destroy); +STUB_ABORT(pthread_cond_wait); +STUB_ABORT(pthread_cond_signal); +STUB_IGNORE(int, pthread_cond_broadcast, 0); +STUB_ABORT(pthread_self); +STUB_ABORT(pthread_detach); From 5dab641f533ed49a6725eac08a1e7175dfbf748d Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:30:52 +0100 Subject: [PATCH 22/42] Stub sigfillset Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/signal.h | 3 +++ nolibc/stubs.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/nolibc/include/signal.h b/nolibc/include/signal.h index f5479046..5d0a9d55 100644 --- a/nolibc/include/signal.h +++ b/nolibc/include/signal.h @@ -21,4 +21,7 @@ void (*signal(int sig, void (*func)(int)))(int); #define SIGFPE 1 int raise(int); +typedef int sigset_t; +int sigfillset(sigset_t *); + #endif diff --git a/nolibc/stubs.c b/nolibc/stubs.c index e444f2a5..c20451a4 100644 --- a/nolibc/stubs.c +++ b/nolibc/stubs.c @@ -142,3 +142,5 @@ STUB_ABORT(pthread_cond_signal); STUB_IGNORE(int, pthread_cond_broadcast, 0); STUB_ABORT(pthread_self); STUB_ABORT(pthread_detach); + +STUB_ABORT(sigfillset); From 8188ff91cd87618cefdbaeec4ca092446d1a8c76 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Fri, 13 Jan 2023 12:27:02 +0100 Subject: [PATCH 23/42] Stub fputs, fopen and fclose and implement puts and putchar As usual, we stub fputs, fopen and fclose which manipulate file description (and they don't exist with Solo5). However, puts and putchar use stdout and we decided to implement them (they will write _via_ Solo5 into stderr). Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/Makefile | 2 +- nolibc/assert.c | 8 +------- nolibc/include/stdio.h | 5 +++++ nolibc/puts.c | 17 +++++++++++++++++ nolibc/stubs.c | 3 +++ 5 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 nolibc/puts.c diff --git a/nolibc/Makefile b/nolibc/Makefile index cbeb5d78..571add12 100644 --- a/nolibc/Makefile +++ b/nolibc/Makefile @@ -21,7 +21,7 @@ OBJS=assert.o \ dtoa.o \ memchr.o memcmp.o memcpy.o memmove.o memset.o \ strcmp.o strlen.o strtol.o strchr.o strchrnul.o strncpy.o stpncpy.o \ - strstr.o strncmp.o \ + strstr.o strncmp.o puts.o \ stubs.o \ vfprintf.o vsnprintf.o snprintf.o fprintf.o printf.o diff --git a/nolibc/assert.c b/nolibc/assert.c index dcdcd1fc..ae89be31 100644 --- a/nolibc/assert.c +++ b/nolibc/assert.c @@ -1,17 +1,11 @@ #include -#include -#include +#include /* * These functions deliberately do not call printf() or malloc() in order to * abort as quickly as possible without triggering further errors. */ -static void puts(const char *s) -{ - (void)write(2, s, strlen(s)); -} - void _assert_fail(const char *file, const char *line, const char *e) { puts(file); diff --git a/nolibc/include/stdio.h b/nolibc/include/stdio.h index 43b959e0..0754a18e 100644 --- a/nolibc/include/stdio.h +++ b/nolibc/include/stdio.h @@ -33,5 +33,10 @@ size_t fwrite(const void *, size_t, size_t, FILE *); int fputc(int, FILE *); int putc(int, FILE *); int ferror(FILE *); +int fputs(const char *, FILE *); +FILE *fopen(const char *, const char *); +int fclose(FILE *); +int puts(const char *); +int putchar(int); #endif diff --git a/nolibc/puts.c b/nolibc/puts.c new file mode 100644 index 00000000..a8c366a0 --- /dev/null +++ b/nolibc/puts.c @@ -0,0 +1,17 @@ +#include +#include + +extern void solo5_console_write(const char *, size_t); + +int puts(const char *s) +{ + size_t len = strlen(s); + solo5_console_write(s, len); + return (len); +} + +int putchar(int chr) +{ + solo5_console_write((char *) &chr, 1); + return (1); +} diff --git a/nolibc/stubs.c b/nolibc/stubs.c index c20451a4..4ae7260b 100644 --- a/nolibc/stubs.c +++ b/nolibc/stubs.c @@ -55,8 +55,11 @@ STUB_WARN_ONCE(int, getc, EOF); STUB_WARN_ONCE(int, ungetc, EOF); STUB_WARN_ONCE(int, fwrite, 0); STUB_WARN_ONCE(int, fputc, EOF); +STUB_WARN_ONCE(int, fputs, EOF); STUB_WARN_ONCE(int, putc, EOF); STUB_WARN_ONCE(int, ferror, 1); +STUB_WARN_ONCE(int, fopen, 1); +STUB_WARN_ONCE(int, fclose, 1); /* stdlib.h */ STUB_WARN_ONCE(char *, getenv, NULL); From 57cea736ba54fb8ee0c2b71ac8706f736cb310ed Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 14:01:15 +0100 Subject: [PATCH 24/42] Stub strerror_r Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/string.h | 4 ++++ nolibc/stubs.c | 1 + 2 files changed, 5 insertions(+) diff --git a/nolibc/include/string.h b/nolibc/include/string.h index 10fb3619..9f16cb47 100644 --- a/nolibc/include/string.h +++ b/nolibc/include/string.h @@ -23,4 +23,8 @@ char *strstr(const char *, const char *); */ int strncmp(const char*, const char*, size_t); +/* TODO(dinosaure): we must track where they are used to know if we need + * to implement them or not. */ +int strerror_r(int errnum, char *buf, size_t buflen); + #endif diff --git a/nolibc/stubs.c b/nolibc/stubs.c index 4ae7260b..8c4bc1b4 100644 --- a/nolibc/stubs.c +++ b/nolibc/stubs.c @@ -147,3 +147,4 @@ STUB_ABORT(pthread_self); STUB_ABORT(pthread_detach); STUB_ABORT(sigfillset); +STUB_ABORT(strerror_r); From 2e94e8c42d3bcbf2ba70dbfb3834182c0b0a5028 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 12:34:43 +0100 Subject: [PATCH 25/42] Stub ftruncate Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/unistd.h | 1 + nolibc/stubs.c | 1 + 2 files changed, 2 insertions(+) diff --git a/nolibc/include/unistd.h b/nolibc/include/unistd.h index 479e6fcf..8240ba65 100644 --- a/nolibc/include/unistd.h +++ b/nolibc/include/unistd.h @@ -15,5 +15,6 @@ ssize_t write(int, const void *, size_t); ssize_t readlink(const char *, char *, size_t); int unlink(const char *); int rmdir(const char *); +int ftruncate(int, off_t); #endif diff --git a/nolibc/stubs.c b/nolibc/stubs.c index 8c4bc1b4..0402e532 100644 --- a/nolibc/stubs.c +++ b/nolibc/stubs.c @@ -78,6 +78,7 @@ STUB_ABORT(read); STUB_IGNORE(int, readlink, -1); STUB_ABORT(unlink); STUB_ABORT(rmdir); +STUB_ABORT(ftruncate); /* dirent.h */ STUB_WARN_ONCE(int, closedir, -1); From d2704ed54bbfbdda8d6ef97e24b0a09bb4985fda Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 13:54:03 +0100 Subject: [PATCH 26/42] Stub usleep Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/sys/types.h | 1 + nolibc/include/unistd.h | 1 + nolibc/stubs.c | 1 + 3 files changed, 3 insertions(+) diff --git a/nolibc/include/sys/types.h b/nolibc/include/sys/types.h index a916f597..af8bcacb 100644 --- a/nolibc/include/sys/types.h +++ b/nolibc/include/sys/types.h @@ -8,5 +8,6 @@ typedef int pid_t; typedef int off_t; typedef int ssize_t; typedef int mode_t; +typedef int useconds_t; #endif diff --git a/nolibc/include/unistd.h b/nolibc/include/unistd.h index 8240ba65..60a112fd 100644 --- a/nolibc/include/unistd.h +++ b/nolibc/include/unistd.h @@ -15,6 +15,7 @@ ssize_t write(int, const void *, size_t); ssize_t readlink(const char *, char *, size_t); int unlink(const char *); int rmdir(const char *); +int usleep(useconds_t); int ftruncate(int, off_t); #endif diff --git a/nolibc/stubs.c b/nolibc/stubs.c index 0402e532..155c0e6e 100644 --- a/nolibc/stubs.c +++ b/nolibc/stubs.c @@ -148,4 +148,5 @@ STUB_ABORT(pthread_self); STUB_ABORT(pthread_detach); STUB_ABORT(sigfillset); +STUB_ABORT(usleep); STUB_ABORT(strerror_r); From f694bb49ef1e8ffa38bc68d1fe3616e11f0759dd Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 14:01:28 +0100 Subject: [PATCH 27/42] Export stdrup & strcpy Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/string.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nolibc/include/string.h b/nolibc/include/string.h index 9f16cb47..226325e5 100644 --- a/nolibc/include/string.h +++ b/nolibc/include/string.h @@ -16,6 +16,7 @@ char *strerror(int); * needed to build the freestanding version of GMP used by Mirage. */ char *strncpy(char *, const char *, size_t); +char *strcpy(char *, const char *); char *strchr(const char *, int); char *strstr(const char *, const char *); /* @@ -26,5 +27,6 @@ int strncmp(const char*, const char*, size_t); /* TODO(dinosaure): we must track where they are used to know if we need * to implement them or not. */ int strerror_r(int errnum, char *buf, size_t buflen); +char *strdup(const char *); #endif From f1a4264a592457496e8e2e54ad9c52a94c0cbca9 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:57:06 +0100 Subject: [PATCH 28/42] Export qsort and mktemp Note that these functions are not stubbed but they are just exported. They are probably not needed by the OCaml runtime but needed by the way to build OCaml. Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/stdlib.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nolibc/include/stdlib.h b/nolibc/include/stdlib.h index 9f890036..e7949749 100644 --- a/nolibc/include/stdlib.h +++ b/nolibc/include/stdlib.h @@ -31,4 +31,9 @@ int system(const char *); double strtod(const char *, char **); long strtol(const char *, char **, int); +void qsort(void *base, size_t nmemb, size_t size, + int (*compare)(const void *, const void *)); + +char *mktemp(char *); + #endif From 221d3c7ddd2b0e803571bc388872bae088748570 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 14:08:40 +0100 Subject: [PATCH 29/42] Export fstat Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/sys/stat.h | 1 + 1 file changed, 1 insertion(+) diff --git a/nolibc/include/sys/stat.h b/nolibc/include/sys/stat.h index ab9b00b5..cf4d4a59 100644 --- a/nolibc/include/sys/stat.h +++ b/nolibc/include/sys/stat.h @@ -15,5 +15,6 @@ struct stat { #define S_IWUSR 0 int stat(const char *, struct stat *); int mkdir(const char *, mode_t); +int fstat(int, struct stat *); #endif From e43f6e558007a7346a82061de3bd7553bead008d Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:13:35 +0100 Subject: [PATCH 30/42] Export islanum and tolower Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/ctype.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nolibc/include/ctype.h b/nolibc/include/ctype.h index 354a9a70..71aab003 100644 --- a/nolibc/include/ctype.h +++ b/nolibc/include/ctype.h @@ -6,5 +6,7 @@ int isdigit(int); int isprint(int); int isspace(int); int isupper(int); +int isalnum(int); +int tolower(int); #endif From c1cf5d1213fe3256860dcf8aeff51b4a5896f005 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:24:09 +0100 Subject: [PATCH 31/42] Add longjmp & setjmp Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/setjmp.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nolibc/include/setjmp.h b/nolibc/include/setjmp.h index 2e602dad..4d079b5d 100644 --- a/nolibc/include/setjmp.h +++ b/nolibc/include/setjmp.h @@ -1 +1,5 @@ #include + +void longjmp(int, int) __attribute__ ((__noreturn__)); + +#define setjmp(buf) 0 From d4bfcfa43ab8bcc99697e25d1225e0170f1175c1 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Mon, 9 Jan 2023 17:22:40 +0100 Subject: [PATCH 32/42] Add the sched.h interface (and the CPU_ZERO value) Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/sched.h | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 nolibc/include/sched.h diff --git a/nolibc/include/sched.h b/nolibc/include/sched.h new file mode 100644 index 00000000..e5fa9302 --- /dev/null +++ b/nolibc/include/sched.h @@ -0,0 +1,8 @@ +#ifndef _SCHED_H +#define _SCHED_H + +typedef int cpu_set_t; + +#define CPU_ZERO (x) 0 + +#endif From 924cbf54161d867a47cc58e21538d9387bb02339 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 11:41:27 +0100 Subject: [PATCH 33/42] Add the stdatomic.h Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/include/stdatomic.h | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 nolibc/include/stdatomic.h diff --git a/nolibc/include/stdatomic.h b/nolibc/include/stdatomic.h new file mode 100644 index 00000000..af6da749 --- /dev/null +++ b/nolibc/include/stdatomic.h @@ -0,0 +1,43 @@ +#ifndef _STDATOMIC_H +#define _STDATOMIC_H + +#define atomic_load_explicit(x, mode) ( *x ) +#define atomic_load(x) ( *x ) + +extern int memory_order_release; +extern int memory_order_acquire; +extern int memory_order_relaxed; +extern int memory_order_seq_cst; + +#define atomic_fetch_add(X, Y) ({ __auto_type tmp = *X; *X = tmp + Y; tmp; }) +#define atomic_fetch_add_explicit(X, Y, MOD) atomic_fetch_add(X, Y) + +#define atomic_thread_fence(MO) do {} while (0) + +typedef unsigned long long atomic_uint_fast64_t; + +#define atomic_compare_exchange_strong(OBJ, EXPECTED, DESIRED) \ + ({ int ret = 0; \ + if (*OBJ == *EXPECTED) { \ + *OBJ = DESIRED; \ + ret = 1; \ + } \ + ret; \ + }) + +#define atomic_exchange(OBJ, DESIRED) \ + ({ __auto_type tmp = *OBJ; \ + *OBJ = DESIRED; \ + tmp; \ + }) + +#define atomic_store(OBJ, DESIRED) do { *OBJ = DESIRED; } while(0) +#define atomic_store_explicit(OBJ, DESIRED, ORDER) atomic_store(OBJ, DESIRED) + +#define atomic_fetch_or(OBJ, ARG) \ + ({ __auto_type tmp = *OBJ; \ + *OBJ = *OBJ | ARG; \ + tmp; \ + }) + +#endif From 50f066a2a78dc4aa8944909fcaef52722172e5a4 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Fri, 13 Jan 2023 12:48:31 +0100 Subject: [PATCH 34/42] Add sysconf.c (to let OCaml to know the _SC_PAGE{,_}SIZE) Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/Makefile | 3 ++- nolibc/include/unistd.h | 4 ++++ nolibc/sysconf.c | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 nolibc/sysconf.c diff --git a/nolibc/Makefile b/nolibc/Makefile index 571add12..24a6651c 100644 --- a/nolibc/Makefile +++ b/nolibc/Makefile @@ -23,7 +23,8 @@ OBJS=assert.o \ strcmp.o strlen.o strtol.o strchr.o strchrnul.o strncpy.o stpncpy.o \ strstr.o strncmp.o puts.o \ stubs.o \ - vfprintf.o vsnprintf.o snprintf.o fprintf.o printf.o + vfprintf.o vsnprintf.o snprintf.o fprintf.o printf.o \ + sysconf.o dtoa.o: CFLAGS+=-fno-strict-aliasing diff --git a/nolibc/include/unistd.h b/nolibc/include/unistd.h index 60a112fd..cbedb7a3 100644 --- a/nolibc/include/unistd.h +++ b/nolibc/include/unistd.h @@ -17,5 +17,9 @@ int unlink(const char *); int rmdir(const char *); int usleep(useconds_t); int ftruncate(int, off_t); +long sysconf(int); + +#define _SC_PAGESIZE 1 +#define _SC_PAGE_SIZE _SC_PAGESIZE #endif diff --git a/nolibc/sysconf.c b/nolibc/sysconf.c new file mode 100644 index 00000000..5e12bf38 --- /dev/null +++ b/nolibc/sysconf.c @@ -0,0 +1,10 @@ +#include + +long sysconf(int x) { + switch (x) { + case _SC_PAGESIZE: /* _SC_PAGE_SIZE */ + return (1 << 12); /* TODO: How do we do better? */ + default: + return -1; + } +} From f9d621ee90ae7c050f9bfe8a38d5764b4f26295f Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Fri, 13 Jan 2023 12:49:00 +0100 Subject: [PATCH 35/42] Add the mmap() function Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/Makefile | 3 ++- nolibc/include/sys/mman.h | 25 +++++++++++++++++++++++++ nolibc/mmap.c | 35 +++++++++++++++++++++++++++++++++++ nolibc/sysconf.c | 3 ++- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 nolibc/include/sys/mman.h create mode 100644 nolibc/mmap.c diff --git a/nolibc/Makefile b/nolibc/Makefile index 24a6651c..6f8f4c3e 100644 --- a/nolibc/Makefile +++ b/nolibc/Makefile @@ -24,7 +24,8 @@ OBJS=assert.o \ strstr.o strncmp.o puts.o \ stubs.o \ vfprintf.o vsnprintf.o snprintf.o fprintf.o printf.o \ - sysconf.o + sysconf.o \ + mmap.o dtoa.o: CFLAGS+=-fno-strict-aliasing diff --git a/nolibc/include/sys/mman.h b/nolibc/include/sys/mman.h new file mode 100644 index 00000000..59bd8a2e --- /dev/null +++ b/nolibc/include/sys/mman.h @@ -0,0 +1,25 @@ +#ifndef _MMAP_H +#define _MMAP_H + +#include +#include + +void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); + +#define PROT_NONE 0 +#define PROT_READ 1 +#define PROT_WRITE 2 + +#define MAP_SHARED 0x01 +#define MAP_PRIVATE 0x02 +#define MAP_FIXED 0x10 +#define MAP_ANONYMOUS 0x20 +#define MAP_ANON MAP_ANONYMOUS + +#define MAP_FAILED NULL + +#define OCAML_SOLO5_PAGESIZE (1 << 12) + +int munmap(void *addr, size_t len); + +#endif diff --git a/nolibc/mmap.c b/nolibc/mmap.c new file mode 100644 index 00000000..03ca1f96 --- /dev/null +++ b/nolibc/mmap.c @@ -0,0 +1,35 @@ +#include +#include + +#include + +void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) { + + /* man page for mmap says: + * If addr is not NULL, then the kernel takes it as a hint about where to place + * the mapping; [...] If another apping already exists there, the kernel picks + * a new address that may or *may not* depend on the hint. + * + * XXX(dinosaure): for our purpose (Solo5 & OCaml), OCaml does not require a + * specific (aligned) address from [mmap]. We can use [malloc()] instead of. + * The OCaml usage of [mmap()] is only to allocate some spaces, only [fildes + * == -1] is handled so. + */ + (void)addr; + (void)prot; + if (fildes != -1) { + printf("mmap: file descriptor is unsupported.\n"); + abort(); + } + if (!(flags & MAP_ANONYMOUS) || off != 0) { + printf("mmap: only MAP_ANONYMOUS (and offset is 0) is supported.\n"); + abort(); + } + + void *ptr = NULL; + posix_memalign(&ptr, OCAML_SOLO5_PAGESIZE, len); + /* XXX(palainp): Solo5 returns -1 and set errno on error, and it does not + * modify ptr, however both are not standardized. We can return NULL to the + * caller on error and do not check the returned value here. */ + return ptr; +} diff --git a/nolibc/sysconf.c b/nolibc/sysconf.c index 5e12bf38..81297ec9 100644 --- a/nolibc/sysconf.c +++ b/nolibc/sysconf.c @@ -1,9 +1,10 @@ #include +#include long sysconf(int x) { switch (x) { case _SC_PAGESIZE: /* _SC_PAGE_SIZE */ - return (1 << 12); /* TODO: How do we do better? */ + return OCAML_SOLO5_PAGESIZE; default: return -1; } From f3f662e3f1c48e9fd361f8ae97f34293f5ab1727 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 12:12:51 +0100 Subject: [PATCH 36/42] Initialise the Thread Local Store Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- nolibc/sysdeps_solo5.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nolibc/sysdeps_solo5.c b/nolibc/sysdeps_solo5.c index dacd0215..1c308806 100644 --- a/nolibc/sysdeps_solo5.c +++ b/nolibc/sysdeps_solo5.c @@ -76,6 +76,7 @@ static uintptr_t sbrk_start; static uintptr_t sbrk_end; static uintptr_t sbrk_cur; static uintptr_t sbrk_guard_size; +static uint8_t tls[4096]; /* * To be called by Mirage/Solo5 before calling caml_startup(). @@ -96,6 +97,7 @@ void _nolibc_init(uintptr_t heap_start, size_t heap_size) sbrk_start = sbrk_cur = heap_start; sbrk_end = heap_start + heap_size; + solo5_set_tls_base((uintptr_t)tls); } /* From 93f35068c6f377872c4307513662a1452d1d93bf Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 13:46:51 +0100 Subject: [PATCH 37/42] Upgrade ocaml-solo5 with OCaml 5.0 Co-authored-by: Pierre Alain Co-authored-by: Kate Co-authored-by: Christiano Haesbaert --- ocaml-solo5-cross-aarch64.opam | 2 +- ocaml-solo5.opam | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ocaml-solo5-cross-aarch64.opam b/ocaml-solo5-cross-aarch64.opam index f58f85d2..c2b79aca 100644 --- a/ocaml-solo5-cross-aarch64.opam +++ b/ocaml-solo5-cross-aarch64.opam @@ -21,7 +21,7 @@ depends: [ "conf-which" {build} "ocamlfind" {build} # needed by dune context (for tests) "ocaml-src" {build} - "ocaml" {>= "4.12.1" & < "4.15.0"} + "ocaml" {>= "5.0" & < "5.1"} "solo5" {>= "0.7.0"} "solo5-cross-aarch64" {>= "0.7.0" } ] diff --git a/ocaml-solo5.opam b/ocaml-solo5.opam index 3df9e566..c0b3d7ff 100644 --- a/ocaml-solo5.opam +++ b/ocaml-solo5.opam @@ -22,7 +22,7 @@ depends: [ "conf-which" {build} "ocamlfind" {build} # needed by dune context (for tests) "ocaml-src" {build} - "ocaml" {>= "4.12.1" & < "4.15.0"} + "ocaml" {>= "5.0" & < "5.1"} "solo5" {>= "0.7.0"} ] conflicts: [ From 9c45880705cdf9039125c81540632f012915076f Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Wed, 11 Jan 2023 14:22:39 +0100 Subject: [PATCH 38/42] Upgrade GitHub workflow and Cirrus CI with OCaml 5.0 --- .cirrus.yml | 4 +--- .github/workflows/test.yml | 13 +------------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 06d058d3..5cc1d1a6 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -6,9 +6,7 @@ freebsd_task: OPAMYES: 1 env: matrix: - - OCAML_VERSION: 4.12.1 - - OCAML_VERSION: 4.13.0 - - OCAML_VERSION: 4.13.1 + - OCAML_VERSION: 5.0.0 pkg_install_script: pkg install -y ocaml-opam gmp gmake pkgconf bash opam_ocaml_cache: folder: $HOME/.opam diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ba1bf581..d00d5563 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - ocaml-version: [4.13.1] + ocaml-version: [5.0.0] mode: - name: hvt exec: false @@ -17,17 +17,6 @@ jobs: exec: false - name: xen exec: false - include: - - operating-system: ubuntu-latest - ocaml-version: 4.13.0 - mode: - name: spt - exec: true - - operating-system: ubuntu-latest - ocaml-version: 4.12.1 - mode: - name: spt - exec: true runs-on: ${{ matrix.operating-system }} steps: - uses: actions/checkout@v2 From 256805f1f7ccf5f50eeb4005d3450f2b2f4263d0 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Thu, 19 Jan 2023 15:16:48 +0100 Subject: [PATCH 39/42] Fix the example & the test program Co-authored-by: Pierre Alain --- example/startup.c | 1 + test/startup.c | 1 + 2 files changed, 2 insertions(+) diff --git a/example/startup.c b/example/startup.c index cde67ab7..263eddb3 100644 --- a/example/startup.c +++ b/example/startup.c @@ -10,4 +10,5 @@ void _nolibc_init(uintptr_t heap_start, size_t heap_size); // defined in nolibc/ int solo5_app_main(const struct solo5_start_info *si) { _nolibc_init(si->heap_start, si->heap_size); caml_startup(unused_argv); + return 0; } diff --git a/test/startup.c b/test/startup.c index 5544c44d..8d9d5b04 100644 --- a/test/startup.c +++ b/test/startup.c @@ -13,4 +13,5 @@ void _nolibc_init(uintptr_t heap_start, size_t heap_size); // defined in nolibc/ int solo5_app_main(const struct solo5_start_info *si) { _nolibc_init(si->heap_start, si->heap_size); caml_startup(unused_argv); + return 0; } From d5ef317a1a7e4d1ddac2b7799db3cfe4b2c68323 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Thu, 19 Jan 2023 15:24:58 +0100 Subject: [PATCH 40/42] Use __c11 atomic macros when they are available (and fix the LLVM support) Co-authored-by: Pierre Alain --- nolibc/include/stdatomic.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/nolibc/include/stdatomic.h b/nolibc/include/stdatomic.h index af6da749..6ab87ddd 100644 --- a/nolibc/include/stdatomic.h +++ b/nolibc/include/stdatomic.h @@ -1,6 +1,11 @@ #ifndef _STDATOMIC_H #define _STDATOMIC_H +// Compatibility with non-clang compilers +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif + #define atomic_load_explicit(x, mode) ( *x ) #define atomic_load(x) ( *x ) @@ -9,13 +14,23 @@ extern int memory_order_acquire; extern int memory_order_relaxed; extern int memory_order_seq_cst; +#if __has_builtin(__c11_atomic_fetch_add) +#define atomic_fetch_add(X, Y) __c11_atomic_fetch_add(X, Y, __ATOMIC_SEQ_CST) +#else #define atomic_fetch_add(X, Y) ({ __auto_type tmp = *X; *X = tmp + Y; tmp; }) +#endif + #define atomic_fetch_add_explicit(X, Y, MOD) atomic_fetch_add(X, Y) #define atomic_thread_fence(MO) do {} while (0) typedef unsigned long long atomic_uint_fast64_t; +#if __has_builtin(__c11_atomic_compare_exchange_strong) +#define atomic_compare_exchange_strong(OBJ, EXPECTED, DESIRED) \ + __c11_atomic_compare_exchange_strong(OBJ, EXPECTED, DESIRED, \ + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) +#else #define atomic_compare_exchange_strong(OBJ, EXPECTED, DESIRED) \ ({ int ret = 0; \ if (*OBJ == *EXPECTED) { \ @@ -24,20 +39,31 @@ typedef unsigned long long atomic_uint_fast64_t; } \ ret; \ }) +#endif +#if __has_builtin(__c11_atomic_exchange) +#define atomic_exchange(OBJ, DESIRED) \ + __c11_atomic_exchange(OBJ, DESIRED, __ATOMIC_SEQ_CST) +#else #define atomic_exchange(OBJ, DESIRED) \ ({ __auto_type tmp = *OBJ; \ *OBJ = DESIRED; \ tmp; \ }) +#endif #define atomic_store(OBJ, DESIRED) do { *OBJ = DESIRED; } while(0) #define atomic_store_explicit(OBJ, DESIRED, ORDER) atomic_store(OBJ, DESIRED) +#if __has_builtin(__c11_atomic_fetch_or) +#define atomic_fetch_or(OBJ, ARG) \ + __c11_atomic_fetch_or(OBJ, ARG, __ATOMIC_SEQ_CST) +#else #define atomic_fetch_or(OBJ, ARG) \ ({ __auto_type tmp = *OBJ; \ *OBJ = *OBJ | ARG; \ tmp; \ }) +#endif #endif From 88b0c71c3506ed2d304d58bffee9565d3edc9fba Mon Sep 17 00:00:00 2001 From: palainp Date: Tue, 7 Feb 2023 15:21:19 +0100 Subject: [PATCH 41/42] Update to the new Solo5 API. --- nolibc/sysdeps_solo5.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/nolibc/sysdeps_solo5.c b/nolibc/sysdeps_solo5.c index 1c308806..b98c5875 100644 --- a/nolibc/sysdeps_solo5.c +++ b/nolibc/sysdeps_solo5.c @@ -76,7 +76,7 @@ static uintptr_t sbrk_start; static uintptr_t sbrk_end; static uintptr_t sbrk_cur; static uintptr_t sbrk_guard_size; -static uint8_t tls[4096]; +static uintptr_t tls_main; /* * To be called by Mirage/Solo5 before calling caml_startup(). @@ -97,7 +97,20 @@ void _nolibc_init(uintptr_t heap_start, size_t heap_size) sbrk_start = sbrk_cur = heap_start; sbrk_end = heap_start + heap_size; - solo5_set_tls_base((uintptr_t)tls); + + tls_main = (uintptr_t)calloc(solo5_tls_size(), sizeof(uint8_t)); + if (tls_main == (uintptr_t)NULL) { + solo5_console_write("TLS alloc failed\n", 17); + abort(); + } + if (solo5_tls_init(tls_main) != SOLO5_R_OK) { + solo5_console_write("TLS init failed\n", 16); + abort(); + } + if (solo5_set_tls_base(solo5_tls_tp_offset(tls_main)) != SOLO5_R_OK) { + solo5_console_write("TLS set failed\n", 15); + abort(); + } } /* From d7f336b41e8914eb609a36f353b78f98a28b59c7 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Fri, 19 May 2023 11:53:13 +0200 Subject: [PATCH 42/42] minor change to trigger CI --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 04e2536b..ef5ee075 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,7 @@ Run: `solo5-hvt _build/default.solo5/main.exe` ## Supported compiler versions -Tested against OCaml 4.12.1 through 4.13.0. Other versions may require -changing `configure.sh`. +Tested against OCaml 5.0. Other versions may require changing `configure.sh`. ## Porting to a different (uni)kernel base layer