From: Edwin Török <edwin.to...@cloud.com>

The code currently uses GCC to compile OCaml C stubs directly,
and although in most cases this works, it is not entirely correct.

This will fail if the OCaml runtime has been recompiled to use and link with 
ASAN for example
(or other situations where a flag needs to be used consistently in everything 
that is linked into the same binary).

Use the OCaml compiler instead, which knows how to invoke the correct C 
compiler with the correct flags,
and append the Xen specific CFLAGS to that instead.

Drop the explicit -fPIC and -I$(ocamlc -where): these will now be provided by 
the compiler as needed.

Use -verbose so we see the actuall full C compiler command line invocation done 
by the OCaml compiler.

Signed-off-by: Edwin Török <edwin.to...@cloud.com>
---
 tools/ocaml/Makefile.rules | 2 +-
 tools/ocaml/common.make    | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/tools/ocaml/Makefile.rules b/tools/ocaml/Makefile.rules
index 0d3c6ac839..74856e2282 100644
--- a/tools/ocaml/Makefile.rules
+++ b/tools/ocaml/Makefile.rules
@@ -37,7 +37,7 @@ ALL_OCAML_OBJS ?= $(OBJS)
        $(call quiet-command, $(OCAMLYACC) -q $<,MLYACC,$@)
 
 %.o: %.c
-       $(call quiet-command, $(CC) $(CFLAGS) -c -o $@ $<,CC,$@)
+       $(call quiet-command, $(OCAMLOPT) -verbose $(addprefix -ccopt 
,$(CFLAGS)) -c -o $@ $<,CC,$@)
 
 META: META.in
        sed 's/@VERSION@/$(VERSION)/g' < $< $o
diff --git a/tools/ocaml/common.make b/tools/ocaml/common.make
index 0c8a597d5b..629e4b3e66 100644
--- a/tools/ocaml/common.make
+++ b/tools/ocaml/common.make
@@ -9,8 +9,6 @@ OCAMLLEX ?= ocamllex
 OCAMLYACC ?= ocamlyacc
 OCAMLFIND ?= ocamlfind
 
-CFLAGS += -fPIC -I$(shell ocamlc -where)
-
 OCAMLOPTFLAG_G := $(shell $(OCAMLOPT) -h 2>&1 | sed -n 's/^  *\(-g\) .*/\1/p')
 OCAMLOPTFLAGS = $(OCAMLOPTFLAG_G) -ccopt "$(LDFLAGS)" -dtypes $(OCAMLINCLUDE) 
-cc $(CC) -w F -warn-error F
 OCAMLCFLAGS += -g $(OCAMLINCLUDE) -w F -warn-error F
-- 
2.41.0


Reply via email to