Skip to content

Commit

Permalink
Build suffixed shared runtimes
Browse files Browse the repository at this point in the history
New names for libcamlrun_shared.so and libasmrun_shared.so without the
_shared suffix and using the target triplet and runtime ID. Both ocamlc
and ocamlopt explicitly recognise `-runtime-variant _shared` and select
the correct name.

Symbolic links for libcamlrun_shared.so and libasmrun_shared.so to allow
any C programs which linked against the the output of `-output-obj` to
continue to work.
  • Loading branch information
dra27 committed Sep 25, 2024
1 parent fc75b38 commit 0893150
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ ___________
(Antonin Décimo, review by Miod Vallat, Gabriel Scherer, and David Allsopp)

- #13???: Introduce a RuntimeID for use in filename mangling to allow different
configurations and different versions of ocamlrun to coexist harmoniously on a
single system.
configurations and different versions of ocamlrun and the shared runtime
libraries to coexist harmoniously on a single system.
(David Allsopp, review by ???)

### Code generation and optimizations:
Expand Down
42 changes: 30 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1321,9 +1321,9 @@ endif
ifeq "$(UNIX_OR_WIN32)" "unix"
ifeq "$(SUPPORTS_SHARED_LIBRARIES)" "true"
runtime_BYTECODE_STATIC_LIBRARIES += runtime/libcamlrun_pic.$(A)
runtime_BYTECODE_SHARED_LIBRARIES += runtime/libcamlrun_shared.$(SO)
runtime_BYTECODE_SHARED_LIBRARIES += camlrun
runtime_NATIVE_STATIC_LIBRARIES += runtime/libasmrun_pic.$(A)
runtime_NATIVE_SHARED_LIBRARIES += runtime/libasmrun_shared.$(SO)
runtime_NATIVE_SHARED_LIBRARIES += asmrun
endif
endif

Expand Down Expand Up @@ -1374,13 +1374,15 @@ ocamlruni_CPPFLAGS = $(runtime_CPPFLAGS) -DCAML_INSTR

.PHONY: runtime-all
runtime-all: \
$(runtime_BYTECODE_STATIC_LIBRARIES) $(runtime_BYTECODE_SHARED_LIBRARIES) \
$(runtime_BYTECODE_STATIC_LIBRARIES) \
$(runtime_BYTECODE_SHARED_LIBRARIES:%=runtime/lib%_shared$(EXT_DLL)) \
$(runtime_PROGRAMS:%=runtime/%$(EXE)) $(SAK)

.PHONY: runtime-allopt
ifeq "$(NATIVE_COMPILER)" "true"
runtime-allopt: \
$(runtime_NATIVE_STATIC_LIBRARIES) $(runtime_NATIVE_SHARED_LIBRARIES)
$(runtime_NATIVE_STATIC_LIBRARIES) \
$(runtime_NATIVE_SHARED_LIBRARIES:%=runtime/lib%_shared$(EXT_DLL))
else
runtime-allopt:
$(error The build has been configured with --disable-native-compiler)
Expand Down Expand Up @@ -2711,17 +2713,31 @@ install::
$(LN) "$(TARGET)-$(1)-$(BYTECODE_RUNTIME_ID)$(EXE)" \
"$(1)-$(BYTECODE_RUNTIME_ID)$(EXE)"
endef
define INSTALL_RUNTIME_LIB
ifeq "$(2)" "BYTECODE"
install::
else
installopt::
endif
$(INSTALL_PROG) \
runtime/lib$(1)_shared$(EXT_DLL) \
"$(INSTALL_LIBDIR)/lib$(1)-$(TARGET)-$($(2)_RUNTIME_ID)$(EXT_DLL)"
cd "$(INSTALL_LIBDIR)" && \
$(LN) "lib$(1)-$(TARGET)-$($(2)_RUNTIME_ID)$(EXT_DLL)" \
"lib$(1)_shared$(EXT_DLL)"
endef

$(foreach runtime, $(runtime_PROGRAMS), \
$(eval $(call INSTALL_RUNTIME,$(runtime))))

install::
$(INSTALL_DATA) $(runtime_BYTECODE_STATIC_LIBRARIES) \
"$(INSTALL_LIBDIR)"
ifneq "$(runtime_BYTECODE_SHARED_LIBRARIES)" ""
$(INSTALL_PROG) $(runtime_BYTECODE_SHARED_LIBRARIES) \
"$(INSTALL_LIBDIR)"
endif

$(foreach shared_runtime, $(runtime_BYTECODE_SHARED_LIBRARIES), \
$(eval $(call INSTALL_RUNTIME_LIB,$(shared_runtime),BYTECODE)))

install::
$(INSTALL_DATA) runtime/caml/domain_state.tbl runtime/caml/*.h \
"$(INSTALL_INCDIR)"
$(INSTALL_PROG) ocaml$(EXE) "$(INSTALL_BINDIR)"
Expand Down Expand Up @@ -2874,11 +2890,13 @@ endif

# Installation of the native-code compiler
.PHONY: installopt
installopt:
installopt::
$(INSTALL_DATA) $(runtime_NATIVE_STATIC_LIBRARIES) "$(INSTALL_LIBDIR)"
ifneq "$(runtime_NATIVE_SHARED_LIBRARIES)" ""
$(INSTALL_PROG) $(runtime_NATIVE_SHARED_LIBRARIES) "$(INSTALL_LIBDIR)"
endif

$(foreach shared_runtime, $(runtime_NATIVE_SHARED_LIBRARIES), \
$(eval $(call INSTALL_RUNTIME_LIB,$(shared_runtime),NATIVE)))

installopt::
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
$(call INSTALL_STRIPPED_BYTE_PROG,\
ocamlopt$(EXE),"$(INSTALL_BINDIR)/ocamlopt.byte$(EXE)")
Expand Down
17 changes: 11 additions & 6 deletions asmcomp/asmlink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ let add_ccobjs origin l =
end

let runtime_lib () =
let libname = "libasmrun" ^ !Clflags.runtime_variant ^ ext_lib in
try
if !Clflags.nopervasives || not !Clflags.with_runtime then []
else [ Load_path.find libname ]
with Not_found ->
raise(Error(File_not_found libname))
if !Clflags.runtime_variant = "_shared" then
[Printf.sprintf "-lasmrun-%s-%s"
Config.target
Config.native_runtime_id]
else
let libname = "libasmrun" ^ !Clflags.runtime_variant ^ ext_lib in
try
if !Clflags.nopervasives || not !Clflags.with_runtime then []
else [ Load_path.find libname ]
with Not_found ->
raise(Error(File_not_found libname))

(* First pass: determine which units are needed *)

Expand Down
14 changes: 12 additions & 2 deletions bytecomp/bytelink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -718,13 +718,22 @@ value caml_startup_pooled_exn(char_os ** argv)
if not with_main && !Clflags.debug then
output_cds_file ((Filename.chop_extension outfile) ^ ".cds")

let runtime_library_name runtime_variant =
if runtime_variant = "_shared" then
Printf.sprintf "-lcamlrun-%s-%s"
Config.target
Config.bytecode_runtime_id
else
"-lcamlrun" ^ runtime_variant

(* Build a custom runtime *)

let build_custom_runtime prim_name exec_name =
let runtime_lib =
if not !Clflags.with_runtime
then ""
else "-lcamlrun" ^ !Clflags.runtime_variant in
else runtime_library_name !Clflags.runtime_variant
in
let stable_name =
if not !Clflags.keep_camlprimc_file then
Some "camlprim.c"
Expand Down Expand Up @@ -861,7 +870,8 @@ extern "C" {
let runtime_lib =
if not !Clflags.with_runtime
then ""
else "-lcamlrun" ^ !Clflags.runtime_variant in
else runtime_library_name !Clflags.runtime_variant
in
Ccomp.call_linker mode output_name
([obj_file] @ List.rev !Clflags.ccobjs @ [runtime_lib])
c_libs = 0
Expand Down

0 comments on commit 0893150

Please sign in to comment.