cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.89k stars 983 forks source link

Why is `main.o` installed? #811

Open LiberalArtist opened 4 months ago

LiberalArtist commented 4 months ago

I noticed that main.o is installed, e.g. as /usr/lib/csv9.5.8/ta6le/main.o. I see that this was done intentionally in https://github.com/cisco/ChezScheme/commit/fd7812d05c791e05eb65982c93bd8c36f7a0404f, but it's not clear to me why or what it is useful for. Grepping the repository only turned up the changelog entry and the code in bintar.zuo and install.zuo that installs it.

LdBeth commented 3 months ago

I think the idea is to let user build a scheme executable with extra C functions linked to libkernel.a and main.o, without the need to distribute the user extended C functions as a separate dynamic library file.

LiberalArtist commented 4 weeks ago

I think the idea is to let user build a scheme executable with extra C functions linked to libkernel.a and main.o, without the need to distribute the user extended C functions as a separate dynamic library file.

Interesting! I can see how that would work, though I wouldn't have thought of that approach.

Does anyone know of other software that distributes something similar to this main.o file?

LdBeth commented 3 weeks ago

So (on macOS)

cc libz.a liblz4.a libkernel.a main.o -o foo -liconv -lncurses

would produce an executable works identical to petite or scheme, without need to access the source code. I think this design was settle down long before when Chez was still closed source and the distribution of main.o is only for completeness, and to create binary executable if any of the linked shared libraries, for example ncurses, on the target system changes, without need to request a new binary from software vendor.

Also it is worth mention the version 7 user guide already mentioned the kernel can be a shared library. The program might have been distributed for some now obscure UNIX variants so it is very likely the case why object files are included when sources aren't available since while the object file format can be compatible the system shared libraries might not be the same.

https://www.scheme.com/csug7/use.html#./use:h7

My other conjecture about making additional C code was probably never be applied in reality since it still requires some hack to hook additional code into the main function to register C functions to the runtime to make them available to Scheme.