Blame SOURCES/0001-ocaml-Link-the-C-bindings-with-LDFLAGS-RHBZ-1548536.patch

ba2470
From be51757920b56a77e2e63247f9a8409ce994d33c Mon Sep 17 00:00:00 2001
ba2470
From: "Richard W.M. Jones" <rjones@redhat.com>
ba2470
Date: Mon, 26 Feb 2018 12:38:12 +0000
ba2470
Subject: [PATCH] ocaml: Link the C bindings with LDFLAGS (RHBZ#1548536).
ba2470
ba2470
Use the ocamlmklib -ldopt flag to pass the general $(LDFLAGS) when
ba2470
calling gcc to link dllmlhivex.so.  We were already passing $(CFLAGS)
ba2470
when building the object file.
ba2470
ba2470
When building using Fedora's standard hardening flags this gives:
ba2470
ba2470
ocamlmklib -o mlhivex hivex_c.o hivex.cmo \
ba2470
    -verbose -ldopt '-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld' \
ba2470
    -L../lib/.libs -lhivex
ba2470
+ gcc -shared  -o ./dllmlhivex.so hivex_c.o  -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -L../lib/.libs -lhivex
ba2470
+ ar rc ./libmlhivex.a  hivex_c.o; ranlib ./libmlhivex.a
ba2470
+ /usr/bin/ocamlc -a    -o mlhivex.cma  hivex.cmo -dllib -lmlhivex -cclib -lmlhivex   -cclib -L../lib/.libs -cclib -lhivex
ba2470
ba2470
This also works if $(LDFLAGS) is empty, because ocamlmklib ignores
ba2470
-ldopt ''.
ba2470
---
ba2470
 ocaml/Makefile.am | 8 ++++++--
ba2470
 1 file changed, 6 insertions(+), 2 deletions(-)
ba2470
ba2470
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
ba2470
index 61db095..85655b6 100644
ba2470
--- a/ocaml/Makefile.am
ba2470
+++ b/ocaml/Makefile.am
ba2470
@@ -41,10 +41,14 @@ OBJS = hivex_c.o hivex.cmo
ba2470
 XOBJS = $(OBJS:.cmo=.cmx)
ba2470
 
ba2470
 mlhivex.cma: $(OBJS)
ba2470
-	$(OCAMLMKLIB) -o mlhivex $^ -L$(top_builddir)/lib/.libs -lhivex
ba2470
+	$(OCAMLMKLIB) -o mlhivex $^ \
ba2470
+	    -ldopt '$(LDFLAGS)' \
ba2470
+	    -L$(top_builddir)/lib/.libs -lhivex
ba2470
 
ba2470
 mlhivex.cmxa: $(XOBJS)
ba2470
-	$(OCAMLMKLIB) -o mlhivex $^ -L$(top_builddir)/lib/.libs -lhivex
ba2470
+	$(OCAMLMKLIB) -o mlhivex $^ \
ba2470
+	    -ldopt '$(LDFLAGS)' \
ba2470
+	    -L$(top_builddir)/lib/.libs -lhivex
ba2470
 
ba2470
 hivex_c.o: hivex_c.c
ba2470
 	$(CC) $(AM_CPPFLAGS) $(CFLAGS) -fPIC -Wall -c $<
ba2470
-- 
ba2470
2.13.2
ba2470