-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Extend ocamlc -output-complete-obj to build .exe #8872
Conversation
3037687
to
3a3ee4d
Compare
This new implementation requires a native toolchain, contrary to the current one. This might exclude some use cases. |
What do you mean by "native"? Isn't a toolchain already needed to build the custom runtime, no matter how you "link" it with the bytecode? |
As far as I can see, both implementations make the same call to the native toolchain using |
One issue is that thanks to putting the bytecode TOC at the end of the bytecode, tools that work with bytecode could work equally well with After this PR, this is no longer the case. For example, |
If we want to keep this feature, one idea would be to put a marker before the bytecode so that tools can extract it. |
Yep, sorry, I was thinking of the mode that allows building a custom runtime, and then concatenating some bytecode program to it (without the need to have a C compiler/linker at that stage). |
I was just reminded this bug. It might be useful to read in the context of this PR. |
Another Debian bug related to the new behaviour of -custom. I remember now why I made the behaviour Debian-specific... |
I went through test failures. Many of them compare the outputs of ocamlc.byte and ocamlc.opt using a custom tool called Another test fails because of a missing C include: glondu@ad34e4c. The last three fail because they try to link in a custom runtime C code that defines a |
I find some of the limitations mentioned on the Debian bugtracker (having |
I consider the ability to run |
Yes, but this anomaly may still be relied upon by an unknown amount of users whose workflow would break with the change -- which does give me cold feet. |
The workaround in this specific case is easy. |
ocamldebug is perfectly able to work with "true" custom bytecode executables, containing a non-standard runtime:
Don't break this just to please Debian's obsession with stripped binaries. |
It works with In that case, whatever we do here is unlikely to break |
ocamldebug needs to 1- start the program instructing the VM to connect to the debugging socket, and 2- read symbol table and debug information from the bytecode executable. Your current proposal does not break 1, but breaks 2 as far as I understand. Please don't. |
I suggest to put a marker at the beginning of the symbol table and debug information. Then |
Apologies if I sound negative, but I think this is a bigger, uglier hack than the one it replaces. |
I agree with @xavierleroy here. I think we can cleanly locate the ELF symbols corresponding to the OCaml [symbol table and debug information] using libbfd or such. Or have the runtime transmit [them] over the debugging socket at startup. |
Both of @glondu ideas seem good to me. The ELF symbol idea seems more generic if we want other tools to be able to easily extract these values. Plus it's the method already used by |
MacOS and Windows don't use ELF. |
I had a feeling that wouldn't be portable... I thought libbfd might but I wasn't sure. That's why I suggested my ugly hack 🙈 Transmitting the info over the debugging socket should be fine, right? |
Another thing that works today is to build a IIUC, the proposed new behavior is very similar to using |
Rather than scanning binaries at all, given that we already have a special way of invoking the runtime to attach to a debugger, can’t we embed the bytecode as here but also have special ways of invoking the custom runtime binary which cause it to emit its bytecode (for |
(A similar mechanism might allow the case when |
@alainfrisch do you expect anyone to rely on this behavior? It's difficult to imagine a use case for constructing both a custom executable and a custom runtime. It seems more natural to choose one or the other. |
One could imagine building a custom bytecode executable, but sometimes execute it with a custom runner built with the debug runtime (or another kind of runtime variant, e.g. with extra hooks). Another use case would be creating programs which could also be executed either in a stand-alone way or through a native host program (that would include the OCaml runtime), without having to create a new process. |
Sorry if the question is obvious, but why not just use |
Why not? Are there any objections? |
At that rate why simply not simply add |
There are three properties for
So far we have two solutions that satisfy two of these properties:
The proposal in this PR is to have a third solution that satisfies 1 and 3, as a way to please our Dune constituency and our Debian constituency. For the record, I still think that dynamic loading of C stub code is the way to go. Static linking is so 20th century... So I don't care about 1 and would gladly kill |
@dbuenzli: yes of course, let me adopt your proposal as if I had made it in the first place. (To my defense, I've essentially never used any of these options before.) |
54a6615
to
6686f50
Compare
OK, I changed the implementation to use the new option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Thanks @nojb for this work and everybody else for their input! |
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
Origin: ocaml/ocaml#8872 Gbp-Pq: Name 0008-Reimplement-custom-without-hacks.patch
This PR extends
ocamlc -output-complete-obj
to build self-contained.exe
's for bytecode programs containing both the runtime and any linked C stubs.The difference with
-custom
is that here we embed the C bytecode directly in the generated C code file so the resulting binary is more robust than the one produced by-custom
(eg it can be stripped).Note that contrary to binaries produced by
-custom
the resulting executable cannot be used with tools that need access to the bytecode/symbol table information (egocamldebug
).The idea is to deprecate
-custom
in a follow-up PR.The code in this PR is based on a patch written by @glondu that modified
-custom
to obtain essentially the same effect, but it was decided to leave-custom
alone because of backwards-compatibility issues (see previous version of this issue description for more information).