|
|
d0ea73 |
From 81a9e4f428e9a2305a2ea8c576dadde60fa5a381 Mon Sep 17 00:00:00 2001
|
|
|
d0ea73 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
d0ea73 |
Date: Thu, 20 Sep 2018 12:42:59 +0100
|
|
|
d0ea73 |
Subject: [PATCH] tools: Link OCaml programs with -runtime-variant _pic if
|
|
|
d0ea73 |
available.
|
|
|
d0ea73 |
MIME-Version: 1.0
|
|
|
d0ea73 |
Content-Type: text/plain; charset=UTF-8
|
|
|
d0ea73 |
Content-Transfer-Encoding: 8bit
|
|
|
d0ea73 |
|
|
|
d0ea73 |
OCaml has a small runtime which is statically linked into the virt
|
|
|
d0ea73 |
tools (providing things like GC and primitives). Since OCaml 4.03 it
|
|
|
d0ea73 |
has been possible to select variants of this runtime, one of which is
|
|
|
d0ea73 |
compiled with -fPIC, using ‘ocamlopt -runtime-variant _pic’.
|
|
|
d0ea73 |
|
|
|
d0ea73 |
This has performance implications on i686, but is relatively free on
|
|
|
d0ea73 |
other architectures. Since it (in theory) adds to the security of the
|
|
|
d0ea73 |
final binary this commit enables it whenever it is available.
|
|
|
d0ea73 |
|
|
|
d0ea73 |
(cherry picked from commit 09abb9c990f6e07b3577088522b8ad9fb439a80e)
|
|
|
d0ea73 |
---
|
|
|
d0ea73 |
.gitignore | 1 +
|
|
|
d0ea73 |
configure.ac | 2 ++
|
|
|
d0ea73 |
m4/guestfs-ocaml.m4 | 18 ++++++++++++++++++
|
|
|
d0ea73 |
ocaml-link.sh => ocaml-link.sh.in | 8 +++++++-
|
|
|
d0ea73 |
4 files changed, 28 insertions(+), 1 deletion(-)
|
|
|
d0ea73 |
rename ocaml-link.sh => ocaml-link.sh.in (88%)
|
|
|
d0ea73 |
|
|
|
d0ea73 |
diff --git a/.gitignore b/.gitignore
|
|
|
d0ea73 |
index af80e36d1..89b8baa17 100644
|
|
|
d0ea73 |
--- a/.gitignore
|
|
|
d0ea73 |
+++ b/.gitignore
|
|
|
d0ea73 |
@@ -410,6 +410,7 @@ Makefile.in
|
|
|
d0ea73 |
/make-fs/virt-make-fs.1
|
|
|
d0ea73 |
/missing
|
|
|
d0ea73 |
/ocaml-dep.sh
|
|
|
d0ea73 |
+/ocaml-link.sh
|
|
|
d0ea73 |
/ocaml/bindtests.bc
|
|
|
d0ea73 |
/ocaml/bindtests.opt
|
|
|
d0ea73 |
/ocaml/bindtests.ml
|
|
|
d0ea73 |
diff --git a/configure.ac b/configure.ac
|
|
|
d0ea73 |
index 4da3bd021..6c38406bb 100644
|
|
|
d0ea73 |
--- a/configure.ac
|
|
|
d0ea73 |
+++ b/configure.ac
|
|
|
d0ea73 |
@@ -198,6 +198,8 @@ AC_CONFIG_FILES([installcheck.sh],
|
|
|
d0ea73 |
[chmod +x,-w installcheck.sh])
|
|
|
d0ea73 |
AC_CONFIG_FILES([ocaml-dep.sh],
|
|
|
d0ea73 |
[chmod +x,-w ocaml-dep.sh])
|
|
|
d0ea73 |
+AC_CONFIG_FILES([ocaml-link.sh],
|
|
|
d0ea73 |
+ [chmod +x,-w ocaml-link.sh])
|
|
|
d0ea73 |
AC_CONFIG_FILES([p2v/virt-p2v-make-disk],
|
|
|
d0ea73 |
[chmod +x,-w p2v/virt-p2v-make-disk])
|
|
|
d0ea73 |
AC_CONFIG_FILES([p2v/virt-p2v-make-kickstart],
|
|
|
d0ea73 |
diff --git a/m4/guestfs-ocaml.m4 b/m4/guestfs-ocaml.m4
|
|
|
d0ea73 |
index e08f40a02..fea11a334 100644
|
|
|
d0ea73 |
--- a/m4/guestfs-ocaml.m4
|
|
|
d0ea73 |
+++ b/m4/guestfs-ocaml.m4
|
|
|
d0ea73 |
@@ -59,6 +59,24 @@ AM_CONDITIONAL([HAVE_OCAMLOPT],
|
|
|
d0ea73 |
AM_CONDITIONAL([HAVE_OCAMLDOC],
|
|
|
d0ea73 |
[test "x$OCAMLDOC" != "xno"])
|
|
|
d0ea73 |
|
|
|
d0ea73 |
+dnl Check if ocamlc/ocamlopt -runtime-variant _pic works. It was
|
|
|
d0ea73 |
+dnl added in OCaml >= 4.03, but in theory might be disabled by
|
|
|
d0ea73 |
+dnl downstream distros.
|
|
|
d0ea73 |
+OCAML_RUNTIME_VARIANT_PIC_OPTION=""
|
|
|
d0ea73 |
+if test "x$OCAMLC" != "xno"; then
|
|
|
d0ea73 |
+ AC_MSG_CHECKING([if OCaml ‘-runtime-variant _pic’ works])
|
|
|
d0ea73 |
+ rm -f conftest.ml contest
|
|
|
d0ea73 |
+ echo 'print_endline "hello world"' > conftest.ml
|
|
|
d0ea73 |
+ if $OCAMLC conftest.ml -runtime-variant _pic -o conftest >&5 2>&5 ; then
|
|
|
d0ea73 |
+ AC_MSG_RESULT([yes])
|
|
|
d0ea73 |
+ OCAML_RUNTIME_VARIANT_PIC_OPTION="-runtime-variant _pic"
|
|
|
d0ea73 |
+ else
|
|
|
d0ea73 |
+ AC_MSG_RESULT([no])
|
|
|
d0ea73 |
+ fi
|
|
|
d0ea73 |
+ rm -f conftest.ml contest
|
|
|
d0ea73 |
+fi
|
|
|
d0ea73 |
+AC_SUBST([OCAML_RUNTIME_VARIANT_PIC_OPTION])
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
dnl Check if ocamldep has options -all and -one-line (not present in RHEL 6).
|
|
|
d0ea73 |
AC_MSG_CHECKING([if ocamldep has the ‘-all’ option])
|
|
|
d0ea73 |
if ocamldep -all >&AS_MESSAGE_LOG_FD 2>&1; then
|
|
|
d0ea73 |
diff --git a/ocaml-link.sh b/ocaml-link.sh.in
|
|
|
d0ea73 |
similarity index 88%
|
|
|
d0ea73 |
rename from ocaml-link.sh
|
|
|
d0ea73 |
rename to ocaml-link.sh.in
|
|
|
d0ea73 |
index 855637534..fbcc07951 100755
|
|
|
d0ea73 |
--- a/ocaml-link.sh
|
|
|
d0ea73 |
+++ b/ocaml-link.sh.in
|
|
|
d0ea73 |
@@ -1,4 +1,6 @@
|
|
|
d0ea73 |
#!/bin/bash -
|
|
|
d0ea73 |
+# Script used to link OCaml programs.
|
|
|
d0ea73 |
+# @configure_input@
|
|
|
d0ea73 |
# (C) Copyright 2015-2018 Red Hat Inc.
|
|
|
d0ea73 |
#
|
|
|
d0ea73 |
# This program is free software; you can redistribute it and/or modify
|
|
|
d0ea73 |
@@ -41,4 +43,8 @@ while true ; do
|
|
|
d0ea73 |
esac
|
|
|
d0ea73 |
done
|
|
|
d0ea73 |
|
|
|
d0ea73 |
-exec "$@" -linkpkg -cclib "${cclib}"
|
|
|
d0ea73 |
+# NB -cclib must come last.
|
|
|
d0ea73 |
+exec "$@" \
|
|
|
d0ea73 |
+ @OCAML_RUNTIME_VARIANT_PIC_OPTION@ \
|
|
|
d0ea73 |
+ -linkpkg \
|
|
|
d0ea73 |
+ -cclib "${cclib}"
|
|
|
d0ea73 |
--
|
|
|
d0ea73 |
2.20.1
|
|
|
d0ea73 |
|