Skip to content

Use as as Dynlink-like extension mechanism #2

@copy

Description

@copy

I'm working on an OCaml program that can be extended with scripts written in OCaml, however the existing Dynlink mechanism (and higher-level approaches like ocaml_plugin) is too heavyweight and doesn't work in statically compiled programs. I've had a similar implementation in mind (link with the OCaml compiler, generate assembly, assemble it using a custom x86 assembler in memory and make it executable in the running process using mmap/mprotect). I'm curious if this project could be extended to handle this, in particular:

  • Accept complete ml files as input, rather than toplevel phrases
  • Link against the cmi of the main program, so that we can provide a mechanism to register the plugin. This may also be useful for custom toplevels, and I believe the existing code to look up symbols is already able to locale the symbols.
  • In the long run, allow unloading modules

From what I can tell this is technically possible (the old native toplevel already uses Dynlink, and jit_run in this repository is similar to the native dynlink code in OCaml), although I might be missing some difficulties, especially around changes to the OCaml compiler. If there's anything you need, I'd gladly contribute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions