Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for running MIR binaries, useful for binfmt_misc #389

Merged
merged 5 commits into from
Feb 1, 2024

Conversation

Wiguwbe
Copy link

@Wiguwbe Wiguwbe commented Jan 10, 2024

(Tries to solve #378 )

In order to be able to execute .bmir files directly from the command line, a "soft link interface" was added (similar to busybox), where the links c2m-ei, c2m-eg and c2m-el are created, pointing to c2m.

These links, to correspond with the binfmt nomenclature, are referred as interpreters

The c2mir driver source was adapted to check if the argv[0] is any of those links.

Invoking c2m through those links is similar to invoking using

$ c2m /path/to/binary {-ei | -eg | -el} <args>...

To use with binfmt_misc, the driver expects the P flag on the binfmt format, that is, the first argument should be the full path to the executable binary.

./a.bmir <args>...
c2m-ei /path/to/a.mir ./a.mir <args...>

or if the binary is in PATH

a.bmir
c2m-ei /usr/local/bin/a.mir a.mir

The binfmt line is (echo it to /proc/sys/fs/binfmt_misc/register as root, or add it to /etc/binfmt.d/)

:mir:M::MIR:/usr/local/bin/c2m-el:P

Do adapt the path where the c2m-* are and possibly change -el to your favorite interface (interpeted, generated or lazy)

In order to be able to execute `.bmir` files directly from the command line,
a "soft link interface" was added (similar to busybox),
where the links `c2m-ei`, `c2m-eg` and `c2m-el` are created, pointing to `c2m`.

These links, to correspond with the binfmt nomenclature, are referred as `interpreters`

The c2mir driver source was adapted to check if the argv[0] is any of those links.

Invoking `c2m` through those links is similar to invoking using
```
$ c2m /path/to/binary {-ei | -eg | -el} <args>...
```

To use with `binfmt_misc`, the driver expects the `P` flag on the binfmt format,
that is, the first argument should be the full path to the executable binary.

```
./a.bmir <args>...
c2m-ei /path/to/a.mir ./a.mir <args...>
```

or if the binary is in PATH

```
a.bmir
c2m-ei /usr/local/bin/a.mir a.mir
```

The binfmt line is
```
:mir:M::MIR:/usr/local/bin/c2m-el:P
```

Do adapt the path where the `c2m-*` are and possibly change `-el` to your favorite interface
(interpeted, generated or lazy)
As a follow up on `binfmt_misc`, a new `mir-run` tool is created to handle
the running of bmir binaries.

The MIR execution type is defined by the `MIR_TYPE` environment variable, defaulting
to `interp` (other options are `jit` for generation and `lazy` for lazy code generation).

This tool also accepts extra libraries to be loaded using the `MIR_LIBS` environment variable
and extra library paths to search through environment variables `LD_LIBRARY_PATH` and
`MIR_LIB_DIRS` (besides the default ones).
@Wiguwbe Wiguwbe changed the title Add support for "soft link interface", useful for binfmt_misc Add support for running MIR binaries, useful for binfmt_misc Jan 15, 2024
@Wiguwbe
Copy link
Author

Wiguwbe commented Jan 15, 2024

A new "interface" was added, mir-run on latest commit:

As a follow up on binfmt_misc, a new mir-run tool is created to handle
the running of bmir binaries.

The MIR execution type is defined by the MIR_TYPE environment variable, defaulting
to interp (other options are jit for generation and lazy for lazy code generation).

This tool also accepts extra libraries to be loaded using the MIR_LIBS environment variable
and extra library paths to search through environment variables LD_LIBRARY_PATH and
MIR_LIB_DIRS (besides the default ones).

@Wiguwbe
Copy link
Author

Wiguwbe commented Jan 15, 2024

Note: library loading is still a work in progress...

Initialize temp_string array and use malloc instead of alloca
@Wiguwbe
Copy link
Author

Wiguwbe commented Jan 15, 2024

Just a minor fix needed after all

@vnmakarov
Copy link
Owner

Thank you for the pull request implementing an interesting feature. I'll review it on this week. If it is ok for me, I'll merge it.

I'll probably do some additional changes in doc (and may be in makefile) after that as this feature is not portable. Still it is pretty interesting. Thank you for the PR again.

@vnmakarov vnmakarov merged commit 12a5d15 into vnmakarov:master Feb 1, 2024
@vnmakarov
Copy link
Owner

Sorry for the delay. I was and still am very busy.

Thank you for the PR. I've merged it.

@edubart
Copy link
Contributor

edubart commented Feb 4, 2024

Would be nice to also have this available in bbv branch.

vnmakarov added a commit that referenced this pull request Feb 5, 2024
Add support for running MIR binaries, useful for binfmt_misc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants