[Libguestfs] [PATCH v2] daemon: Use a configure-time test to find the best OCaml runtime.

Richard W.M. Jones rjones at redhat.com
Tue Nov 14 18:02:51 UTC 2017


In OCaml 4.06 we need to link to daemon to libasmrun_pic.a (the OCaml
runtime linked with -fPIC).  Otherwise you will see many errors like
this:

    /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(startup_aux.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(startup.o): relocation R_X86_64_32S against symbol `caml_data_segments' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(fail.o): relocation R_X86_64_32 against symbol `caml_exn_Failure' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(roots.o): relocation R_X86_64_32 against symbol `caml_frametable' can not be used when making a shared object; recompile with -fPIC

This commit use a configure-time test to find the best OCaml runtime.
---
 daemon/Makefile.am  |  2 --
 m4/guestfs-ocaml.m4 | 26 ++++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index af3184d3e..27630d2bc 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -328,10 +328,8 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR)
 
 if !HAVE_OCAMLOPT
 OBJECTS = $(BOBJECTS)
-CAMLRUN = camlrun
 else
 OBJECTS = $(XOBJECTS)
-CAMLRUN = asmrun
 endif
 OCAML_LIBS = \
 	-lmlpcre \
diff --git a/m4/guestfs-ocaml.m4 b/m4/guestfs-ocaml.m4
index 54ad355cd..3f78d1fb3 100644
--- a/m4/guestfs-ocaml.m4
+++ b/m4/guestfs-ocaml.m4
@@ -85,6 +85,32 @@ if test "x$enable_daemon" = "xyes"; then
     if test "x$OCAML_PKG_hivex" = "xno"; then
         AC_MSG_ERROR([the OCaml module 'hivex' is required])
     fi
+
+    dnl Check which OCaml runtime to link the daemon again.
+    dnl We can't use AC_CHECK_LIB here unfortunately because
+    dnl the other symbols are resolved by OCaml itself.
+    AC_MSG_CHECKING([which OCaml runtime we should link the daemon with])
+    if test "x$OCAMLOPT" != "xno"; then
+        for f in asmrun_pic asmrun; do
+            if test -f "$OCAMLLIB/lib$f.a"; then
+                CAMLRUN=$f
+                break
+            fi
+        done
+    else
+        for f in camlrun; do
+            if test -f "$OCAMLLIB/lib$f.a"; then
+                CAMLRUN=$f
+                break
+            fi
+        done
+    fi
+    if test "x$CAMLRUN" != "x"; then
+        AC_MSG_RESULT([$CAMLRUN])
+    else
+        AC_MSG_ERROR([could not find or link to libasmrun or libcamlrun])
+    fi
+    AC_SUBST([CAMLRUN])
 fi
 
 OCAML_PKG_gettext=no
-- 
2.13.2




More information about the Libguestfs mailing list