-
Notifications
You must be signed in to change notification settings - Fork 154
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
Shebang support for Mir files? #378
Comments
Sorry for delay with the answer. Usually I am very busy at the end of year. I never thought about this. I guess it is not hard to implement. So I am not against this. I has to much work on my plate to implement it myself. But I am ready to consider the corresponding PR. Imho shebangs is more oriented to textual files. As MIR-textual file has # as a comment start, shebangs should already work for MIR-textual files. But binary files are much smaller. |
Hello! Glad you are doing fine my friend, I haven't seen you in a while! Well, shebangs can be used with Mir so we can directly execute them through shell or through the "execve" system call. It will make Mir files feel more "native" in my opinion, and it will make it seem more professional overall. I suppose it would be easy to implement. Unless I see something, there should be 2 steps.
I would be glad to help if you would tell me which places I should look at and change, as I never looked into Mir's code before, and I'm not exactly the best at looking at source code of other people. And with that I mean that I suck hard and never done it before. So in the positive side, it would be a nice first experience! ;) I should also mention that I want to use Mir alongside LLVM for Nemesis, so the time has come where I don't tell you how I plan to use Mir, but I actually go and use it! I will start building the frontend soon so we're going to see some real world usage! |
Hello there, I think another option could be the |
Hello and happy new year!!! This looks very interesting! I have seen a video about RISC-V assembly on Linux and at some point, he is able to run the problem without invoking "qemu-riscv64" before the name of the program. I suppose, this is what it's used there! Compared to shebangs, this has the advantage of been more clean and not requiring extra work to happen. The disadvantage however is that it's not portable and every system will have to add it. It is a small disadvantage however if the loader is packed for the package managers and automatically add it every time it is installed (same way that happens on Arch with the "qemu-user-binfmt" package for QEMU)! As for the loader, |
I added some modifications to the c2mir driver, with binfmt_misc line
|
Damn, you guys make me feel jealous! I'm too lazy to do anything other than watching YouTube the last 1 month! 😭 This is basically the idea! Now, all that remains is for Vladimir to "separate" the loader and make it its own executable. This would also allow "c2m" to be compiled with One thing to think about that now is the fact that the "binfmt_misc" file will hardcode the opinion passed to the loader. Now, we can say that in a real scenario (release binary), we can forget the interpretation mode. However, there are still two JIT modes one been lazy compilation ( |
Don't feel bad xD we all go through "phases" of some sort, Anyway, this was mostly a PoC, I used the c2mir sub project because it already had the symbol resolver and the functions to make it compile (top API doesn't seem to have that?) Regarding the hardcoded option, from the expected command line usage ( Although I'd suggest a environment variable to configure which execution to run (interp/JIT/lazy), that the MIR loader would see: MIR_EXE_WAY=interp some-command arg1 ...
# or
export MIR_EXE_WAY=lazy
# ... Later on ...
some-command arg1... (Here In general you'd have to modify the binary, even with shebang, to specify the execution "way" to go for (I believe). A new loader would be advantageous here indeed, it would also remove the need for the I may be able to look into it next week |
Thank you! I'm slowly getting over it ;)
That's a great idea! We could have a default mode (I suggest "lazy") when the environment variable is not set, and then have the environment variable be set or modified (if already set) when you want to use a different mode. The only thing I would change for that is the "JIT" mode to be used with lowercase letter ("jit"). "interp" could also be changed to the shorter "exec" which also makes sense as this is practically what the interpreter does.
Another name I thought about is:
And for that reason,
Yeah, removing the extension would also make it feel better and more like a "system" file!
Sounds awesome! Glad you are having fun with the project! :) |
Hello, I created the Here is an example of running it:
|
Here is an example with shared libraries:
|
That's so awesome!!!! Your work is amazing! I'll leave this issue open until Vladimir merges your pull request! Now, we need system call support and been able to create libraries and MIR is set for a general purpose backend!!! You guys are awesome!!! You give my motivation to work on Nemesis and hopefully have it ready at some point! |
Regarding libraries, or modules (which could probably be another issue), and here I'm assuming these libraries will also be output in MIR, There are a couple of ways that could be implemented (from the top of my head), depending as well on how you decide to implement them in Nemesis: One way would be to have a custom C function that takes the name of the library ( I guess this could be the easier option as you can create a wrapper script for binfmt_misc that sets the environment variables and then calls Then you have other options such as:
I hope that's useful, best of luck |
Thank you so much for the information. However, if I am to use libraries, I'll wait until and if Mir gives native support for them (think how ELF has one). Until then, I'll keep working in the frontend and wait! |
Would you consider to support shebangs? I think that this will make Mir files feel much more "native" and easier to use.
From what I understand, there should be support to both add a shebang when you generate the final "bmir" file and then, there should be support to "skip" the shebang in the beginning of the file when it is given for interpretation (jit or not).
Let me know what you think!
The text was updated successfully, but these errors were encountered: