Skip to content

Commit

Permalink
Mangle the bytecode runtime names
Browse files Browse the repository at this point in the history
  • Loading branch information
dra27 committed Oct 22, 2024
1 parent ca68897 commit 9841637
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,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 the runtime system to coexist
harmoniously on a single system.
configurations and different versions of ocamlrun to coexist harmoniously on a
single system.
(David Allsopp, review by ???)

### Code generation and optimizations:
Expand Down
42 changes: 33 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ defaultentry: $(DEFAULT_BUILD_TARGET)

include stdlib/StdlibModules

CAMLC = $(BOOT_OCAMLC) $(BOOT_STDLIBFLAGS) -use-prims runtime/primitives
RUNTIME_NAME = $(BINDIR)/ocamlrun-$(BYTECODE_RUNTIME_ID)$(EXE)
CAMLC = $(BOOT_OCAMLC) $(BOOT_STDLIBFLAGS) \
-use-prims runtime/primitives \
-use-runtime '$(subst ','\'',$(RUNTIME_NAME))'
CAMLOPT=$(OCAMLRUN) ./ocamlopt$(EXE) $(STDLIBFLAGS) -I otherlibs/dynlink
ARCHES=amd64 arm64 power s390x riscv
VPATH = utils parsing typing bytecomp file_formats lambda middle_end \
Expand Down Expand Up @@ -622,8 +625,12 @@ OCAML_NATIVE_LIBRARIES =
$(foreach LIBRARY, $(OCAML_NATIVE_LIBRARIES),\
$(eval $(call OCAML_NATIVE_LIBRARY,$(LIBRARY))))

USE_RUNTIME_PRIMS = -use-prims ../runtime/primitives
USE_RUNTIME_PRIMS = \
-use-prims ../runtime/primitives
USE_RUNTIME = \
-use-runtime '\''$(subst ','\\\'\\\',$(RUNTIME_NAME))'\''
USE_STDLIB = -nostdlib -I ../stdlib
FLEXLINK_BOOT_OCAMLC_FLAGS = $(USE_RUNTIME_PRIMS) $(USE_RUNTIME) $(USE_STDLIB)

FLEXDLL_OBJECTS = \
flexdll_$(FLEXDLL_CHAIN).$(O) flexdll_initer_$(FLEXDLL_CHAIN).$(O)
Expand All @@ -642,7 +649,7 @@ flexlink.byte$(EXE): $(FLEXDLL_SOURCES)
rm -f $(FLEXDLL_SOURCE_DIR)/flexlink.exe
$(MAKE) -C $(FLEXDLL_SOURCE_DIR) $(FLEXLINK_BUILD_ENV) \
OCAMLRUN='$$(ROOTDIR)/boot/ocamlrun$(EXE)' NATDYNLINK=false \
OCAMLOPT='$(value BOOT_OCAMLC) $(USE_RUNTIME_PRIMS) $(USE_STDLIB)' \
OCAMLOPT='$(value BOOT_OCAMLC) $(FLEXLINK_BOOT_OCAMLC_FLAGS)' \
flexlink.exe support
cp $(FLEXDLL_SOURCE_DIR)/flexlink.exe $@

Expand Down Expand Up @@ -1267,7 +1274,7 @@ runtime_BUILT_HEADERS = $(addprefix runtime/, \

## Targets to build and install

runtime_PROGRAMS = runtime/ocamlrun$(EXE)
runtime_PROGRAMS = ocamlrun
runtime_BYTECODE_STATIC_LIBRARIES = $(addprefix runtime/, \
ld.conf libcamlrun.$(A))
runtime_BYTECODE_SHARED_LIBRARIES =
Expand All @@ -1276,13 +1283,13 @@ runtime_NATIVE_STATIC_LIBRARIES = \
runtime_NATIVE_SHARED_LIBRARIES =

ifeq "$(RUNTIMED)" "true"
runtime_PROGRAMS += runtime/ocamlrund$(EXE)
runtime_PROGRAMS += ocamlrund
runtime_BYTECODE_STATIC_LIBRARIES += runtime/libcamlrund.$(A)
runtime_NATIVE_STATIC_LIBRARIES += runtime/libasmrund.$(A)
endif

ifeq "$(INSTRUMENTED_RUNTIME)" "true"
runtime_PROGRAMS += runtime/ocamlruni$(EXE)
runtime_PROGRAMS += ocamlruni
runtime_BYTECODE_STATIC_LIBRARIES += runtime/libcamlruni.$(A)
runtime_NATIVE_STATIC_LIBRARIES += runtime/libasmruni.$(A)
endif
Expand Down Expand Up @@ -1344,7 +1351,7 @@ ocamlruni_CPPFLAGS = $(runtime_CPPFLAGS) -DCAML_INSTR
.PHONY: runtime-all
runtime-all: \
$(runtime_BYTECODE_STATIC_LIBRARIES) $(runtime_BYTECODE_SHARED_LIBRARIES) \
$(runtime_PROGRAMS) $(SAK)
$(runtime_PROGRAMS:%=runtime/%$(EXE)) $(SAK)

.PHONY: runtime-allopt
ifeq "$(NATIVE_COMPILER)" "true"
Expand Down Expand Up @@ -2674,16 +2681,33 @@ endif
INSTALL_LIBDIR_DYNLINK = $(INSTALL_LIBDIR)/dynlink

# Installation

.PHONY: install
install:
install::
$(MKDIR) "$(INSTALL_BINDIR)"
$(MKDIR) "$(INSTALL_LIBDIR)"
$(MKDIR) "$(INSTALL_STUBLIBDIR)"
$(MKDIR) "$(INSTALL_COMPLIBDIR)"
$(MKDIR) "$(INSTALL_DOCDIR)"
$(MKDIR) "$(INSTALL_INCDIR)"
$(MKDIR) "$(INSTALL_LIBDIR_PROFILING)"
$(INSTALL_PROG) $(runtime_PROGRAMS) "$(INSTALL_BINDIR)"

define INSTALL_RUNTIME
install::
$(INSTALL_PROG) \
runtime/$(1)$(EXE) \
"$(INSTALL_BINDIR)/$(TARGET)-$(1)-$(BYTECODE_RUNTIME_ID)$(EXE)"
cd "$(INSTALL_BINDIR)" && \
$(LN) "$(TARGET)-$(1)-$(BYTECODE_RUNTIME_ID)$(EXE)" "$(1)$(EXE)"
cd "$(INSTALL_BINDIR)" && \
$(LN) "$(TARGET)-$(1)-$(BYTECODE_RUNTIME_ID)$(EXE)" \
"$(1)-$(BYTECODE_RUNTIME_ID)$(EXE)"
endef

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

install::
$(INSTALL_DATA) $(runtime_BYTECODE_STATIC_LIBRARIES) \
"$(INSTALL_LIBDIR)"
ifneq "$(runtime_BYTECODE_SHARED_LIBRARIES)" ""
Expand Down
3 changes: 2 additions & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ MKDIR=mkdir -p
EMPTY :=
# $(SPACE) contains a single space
SPACE := $(EMPTY) $(EMPTY)
# $( ) suppresses warning from the alignments in the V_ macros below
# $( ) suppresses warning from the alignments in the V_ macros below and also
# allows $\ at the end a line
$(SPACE) :=

ifeq "$(UNIX_OR_WIN32)" "win32"
Expand Down
5 changes: 4 additions & 1 deletion bytecomp/bytelink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,10 @@ let write_header outchan =
if String.length !Clflags.use_runtime > 0 then
make_absolute !Clflags.use_runtime
else
let runtime = "ocamlrun" ^ !Clflags.runtime_variant in
let runtime =
Printf.sprintf "ocamlrun%s-%s"
!Clflags.runtime_variant Config.bytecode_runtime_id
in
Filename.concat runtime_info.bindir runtime
in
(* Determine which method will be used for launching the executable:
Expand Down
1 change: 1 addition & 0 deletions runtime/startup_byt.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ static void do_print_config(void)
printf("word_size: %d\n", 8 * (int)sizeof(value) - 1);
printf("os_type: %s\n", OCAML_OS_TYPE);
printf("host: %s\n", HOST);
printf("bytecode_runtime_id: %s\n", BYTECODE_RUNTIME_ID);
printf("flat_float_array: %s\n",
#ifdef FLAT_FLOAT_ARRAY
"true");
Expand Down

0 comments on commit 9841637

Please sign in to comment.