Skip to content

[GOB] Relocatable OCaml 5.3 - #305

Open
dra27 wants to merge 25 commits into
test-in-prefix-5.3from
relocatable-ocaml-5.3
Open

dra27 wants to merge 25 commits into
test-in-prefix-5.3from
relocatable-ocaml-5.3

Conversation

@dra27

@dra27 dra27 commented Sep 2, 2026

Copy link
Copy Markdown
Owner

No description provided.

dra27 and others added 25 commits March 31, 2026 21:23
Previously Windows unconditionally uses `cp`, doubling the size required
for the OCaml binaries. `configure` now determines if `ln` creates
native symlinks and only uses `cp` if that fails. Users of the compiler
are simply required to enable Developer Mode (or build OCaml using an
elevated shell).

(cherry picked from commit b082fd1)
Slightly easier detection, and a somewhat hardened implementation.

(cherry picked from commit e0467cc)
Co-authored-by: David Allsopp <david.allsopp@metastack.com>
(cherry picked from commit 49755db)
echo cannot portably be used to display strings containing backslashes
and the echo builtin in dash in particular always transforms \\ to \
which breaks the transformation in sak.

Use printf instead.

Co-authored-by: Samuel Hym <samuel@tarides.com>
(cherry picked from commit 9d31646)
Previously, the flexdll support objects were placed in both byte/bin and
opt/bin with the copy of flexlink.exe when flexlink was being
bootstrapped with OCaml. The objects are small, so the copying was not
particulary onerous.

However, if opt/bin/flexlink.exe is a native Windows symlink (pointing
to ../../flexlink.opt.exe) then Sys.executable_name when flexlink runs
will point to the wrong place. While flexlink ought to be checking
Sys.argv.(0) rather than Sys.executable_name, a better hardening is to
be explicit and set the FLEXDIR environment variable to point to the
directory containing the support objects. This also allows
byte/bin/flexlink.exe and opt/bin/flexlink.exe to share the same copy of
the objects.

(cherry picked from commit 8447496)
Unify the two executable header implementations

(cherry picked from commit 076b435)
Relocatable OCaml - explicit-relative paths in `ld.conf`

(cherry picked from commit 1e05f34)
Relocatable OCaml - `--with-relative-libdir`

(cherry picked from commit cfbf210)
(cherry picked from commit d315509)
(cherry picked from commit 1ecddf1)
boot/ocamlc doesn't yet support -set-runtime-default and
%standard_library_default.
Misc.String.to_utf_8_seq was added in PR#14014 for the testsuite, but
isn't part of the backport. It's only needed in Bytelink, so share it
from there instead.
Relocatable OCaml - Searching and Suffixing

(cherry picked from commit da60a2e)
(cherry picked from commit c40b687)
boot/ocamlc still uses the old runtime-launch-info format and doesn't
yet support -launch-method or -runtime-search.
Config.shebangscripts was added in PR#14014 for the testuiste, but isn't
part of the backport. Similarly, Bytelink.read_runtime_launch_info was
exposed, only to be deleted as part of PR#14245, so the backport cuts
out this intermediate step by temporarily copying
Bytelink.read_rutime_launch_info, which therefore needs deleting here.
- Byterntm removed from ocamlbytecomp and linked directly in
  ocamlobjinfo (the test-in-prefix driver likewise links it directly)
- Cmm_helpers.emit_global_string_constant inlined into its single use in
  Asmlink.make_startup_file
- Compenv.parse_runtime_parameter inlined into its single use in
  Main_args and Compenv.fatalf consequently removed
- Config.as_is_cc moved to Toolchain.as_is_cc
- Config.target_{unix,win32,cygwin} removed and uses of
  Config.target_win32 inlined
Virtually elimates changes to the runtime headers:
- caml_parse_ld_conf (protected by CAML_INTERNALS) changes arguments,
  but this function was already checked for not being used outside the
  runtime as part of OCaml 5.5
- exec.h now includes <stdint.h> (protected by CAML_INTERNALS)
- version.h now defines OCAML_RELEASE_NUMBER
In OCaml 5.5, the suffixing mode is enabled by default. For
compatibility, the backports only enable this mode by default if
--enable-runtime-search and/or --enable-runtime-search-target is
specified (the usual validation rules for these flags still applies -
i.e. --disable-suffixing is still prohibited if either
--enable-runtime-search or --enable-runtime-search-target is specified)
Cmo_format.library.lib_dllibs is able to change type without a bootstrap
because the bootstrap cycle never reads a .cma which has any entries for
dllibs (it fundamentally can't, because that would imply a dependency on
dynamic loading, which isn't permitted in ultra-portable bootstrap)

However, the format absolutely cannot change without ultimately changing
the cma magic number, which is non-trivial, because we don't normally
change the magic numbers in maintenance releases, and the numbering
scheme consequently doesn't reserve space for them.

This is worked around instead by leaving Cmo_format.library unaltered
and instead writing a _second_ list after the Cmo_format.library in the
cma format. This list is guarded with the cma magic number, but written
in reverse. If this magic number is present, then the list must follow
and must be the same length as lib_dllibs. If the magic number is not
present, then the suffixed member of each lib_dllibs is assumed to be
false, which is used also used as an "optimisation" to avoid writing the
extra list at all when none of entries have suffixed:true.
As with Cmo_format.library, the type of Cmx_format.unit_infos cannot
change without changing the cmx and cmxa magic numbers, which is
similarly awkward.

The workaround here is slightly simpler, if also somewhat more devious.
Cmx_format.unit_infos is handily a fully mutable record, meaning that
there are few if any optimisation assumptions which will ever be made
around it.

For the compiler, the interface is altered to add
Compilenv.needs_stdlib_location which takes a Cmx_format.unit_infos and
"accesses" its ui_need_stdlib field. In parallel,
Compilenv.write_unit_info gains an optional ui_need_stdlib argument
which allows the field to be specified when a Cmx_format.unit_infos is
written to a file.

The devious part is that instead of writing a Cmx_format.unit_infos
value, Compilenv.write_unit_info writes a tuple with one extra element
for the ui_need_stdlib field to be added in.
Compilenv.needs_stdlib_location looks to see if the
Cmx_format.unit_infos it has been passed in fact contains an extra field
in the block and, if it does, reads it.
Relocatable OCaml - to opam and beyond. Includes subsequent fixes from
PR#14914 and PR#14923.

(cherry picked from commit f6c8af4)
(cherry picked from commit 63b0c81)
(cherry picked from commit 31d08a3)
Improve installation time in opam by shrinking the Git-generated source archives

(cherry picked from commit 172b5c5)
@dra27 dra27 added CI: Skip testsuite Skip the testsuite runs on a PR CI: Full matrix Full CI test matrix labels Sep 2, 2026
@dra27
dra27 force-pushed the relocatable-ocaml-5.3 branch from 6b1c5cf to e22c7e5 Compare September 3, 2026 10:59
@dra27
dra27 force-pushed the relocatable-ocaml-5.3 branch from d3e8ec4 to e22c7e5 Compare September 3, 2026 11:01
@dra27
dra27 force-pushed the relocatable-ocaml-5.3 branch from e22c7e5 to cbe13b4 Compare September 3, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: Full matrix Full CI test matrix CI: Skip testsuite Skip the testsuite runs on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants