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

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