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

Include prims.o in libcamlrun_shared.so #13132

Closed
wants to merge 1 commit into from

Conversation

yallop
Copy link
Member

@yallop yallop commented Apr 27, 2024

I'd like to use libcamlrun_shared.so from other languages, but it has an undefined symbol caml_names_of_builtin_cprim:

$ python3 -c "import ctypes; ctypes.CDLL('runtime/libcamlrun_shared.so')"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.11/ctypes/__init__.py", line 376, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: runtime/libcamlrun_shared.so: undefined symbol: caml_names_of_builtin_cprim

This PR includes prims.o in the shared object so that the symbol is no longer undefined:

$ python3 -c "import ctypes; ctypes.CDLL('runtime/libcamlrun_shared.so')"
$

@yallop
Copy link
Member Author

yallop commented Jun 3, 2024

Is someone (perhaps @dra27 or @shindere) able to take a quick look at this? It shouldn't take long: it's just a one-line change to a Makefile, with a one-line test case in the description that shows how it fixes a bug.

@shindere
Copy link
Contributor

shindere commented Jun 3, 2024 via email

@shindere
Copy link
Contributor

shindere commented Jun 3, 2024

@yallop I am wondering why you have chosen to add runtime/prims.$(O) as
an explicit prerequisite of runtime/libcamlrun_shared.$(SO), rather
than adding the file to the (beginning of the) definition of
libcamlrunpic_OBJECTS variable?

To rephrase, are you sure this file needs to be added only to this target
and not to all the other targets built from libcamlrunpic_OBJECTS?

@dra27
Copy link
Member

dra27 commented Jun 3, 2024

Sorry for the slowness here, but I think this may need an additional .so - the purpose of that library is as alternative to -lcamlrun where those symbols are defined elsewhere (e.g. by -output-obj and friends - cf. the way ocamlrun.exe itself is assembled) ... the _shared is a trick which allows it to be used with -runtime-variant (IIRC - I haven't dug into the various notes I have about this part)

I wonder if the better fix is to introduce libcamlrun.so with prims.o included and leave libcamlrun_shared.so as-is?

@shindere
Copy link
Contributor

shindere commented Jun 3, 2024 via email

@yallop
Copy link
Member Author

yallop commented Jun 8, 2024

Thank you for the analysis, @shindere and @dra27!

While it would be useful to me to have a shared library that I could use directly, it's not clear that the effort of building a new libcamlrun.so is worth it (since it's easy enough to relink prims.o together with libcamlrun_shared.so for my purposes).

@yallop yallop closed this Jun 8, 2024
@yallop yallop deleted the link-prims-shared branch June 8, 2024 15:51
@dra27
Copy link
Member

dra27 commented Jun 10, 2024

Are additional libraries (e.g. Unix) also dynamically loaded? The linking "model" (it's a slightly grand word for it!) with those .a and .so basically ignores dynamic loading of C, so if what you're doing would otherwise never involve having to relink .so files, I can certainly see a gap in the distribution for providing an actual "here is the basic OCaml runtime as a self-contained DLL"

@yallop
Copy link
Member Author

yallop commented Jun 10, 2024

Are additional libraries (e.g. Unix) also dynamically loaded?

I don't have a need for that at the moment; I only need to load the compiler code itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants