Skip to contentSkip to conversation

Fix rpath handling in OCaml's Makefile.rules

PATCH Superseded Andrii Sultanov 2 participants 4 messages Dec 9, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix rpath handling in OCaml's Makefile.rules

As reported by Nix's Xen team, OCaml stub libs would embed an absolute rpath in the binaries, which was picked up on by patchelf. This is a symptom of improper handling of -rpath-link in the first place, so correct that and get rid of the issue.

Andrii Sultanov (1):
tools/ocaml: Specify rpath correctly for ocamlmklib

 tools/ocaml/Makefile.rules | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.39.5
#1 lore raw

PATCH 1/1 tools/ocaml: Specify rpath correctly for ocamlmklib

ocamlmklib has special handling for C-like '-Wl,-rpath' option, but does not know how to handle '-Wl,-rpath-link', as evidenced by warnings like:
"Unknown option -Wl,-rpath-link=$HOME/xen/tools/ocaml/libs/eventchn/../../../../tools/libs/toollog" Pass this option directly to the compiler with -ccopt instead.

This prevents embedding absolute paths from buildtime into binary's RPATH.

Fixes f7b4e4558b42 ("tools/ocaml: Fix OCaml libs rules")
---
 tools/ocaml/Makefile.rules | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/ocaml/Makefile.rules +2 -2
index b9d4b51f0a..055725d910 100644
@@ -63,7 +63,7 @@ mk-caml-lib-bytecode = $(call quiet-command, $(OCAMLC) $(OCAMLCFLAGS) -a -o $1 $
 
 mk-caml-stubs = $(call quiet-command, $(OCAMLMKLIB) -o `basename $1 .a` $2,MKLIB,$1)
 mk-caml-lib-stubs = \
-	$(call quiet-command, $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $2 $3,MKLIB,$1)
+	$(call quiet-command, $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $2 `echo $3 | sed -e 's/-ccopt \(-l\|-L\)/\1/g'`,MKLIB,$1)
 
 # define a library target <name>.cmxa and <name>.cma
 define OCAML_LIBRARY_template
@@ -74,7 +74,7 @@ define OCAML_LIBRARY_template
  $(1)_stubs.a: $(foreach obj,$$($(1)_C_OBJS),$(obj).o)
 	$(call mk-caml-stubs,$$@, $$+)
  lib$(1)_stubs.a: $(foreach obj,$($(1)_C_OBJS),$(obj).o)
-	$(call mk-caml-lib-stubs,$$@, $$+, $(foreach lib,$(LIBS_$(1)),$(lib)))
+	$(call mk-caml-lib-stubs,$$@, $$+, $(foreach lib,$(LIBS_$(1)),-ccopt $(lib)))
 endef
 
 # Dynamically linked OCaml libraries ("plugins" in Dynlink parlance)
Signature · 1 line
2.39.5
Acked-by on the v1 series
#2 lore raw
In reply to Andrii Sultanov
Quoted 9 lines · Andrii Sultanov

As reported by Nix's Xen team, OCaml stub libs would embed an absolute rpath in the binaries, which was picked up on by patchelf. This is a symptom of improper handling of -rpath-link in the first place, so correct that and get rid of the issue.

Quoted 9 lines

Andrii Sultanov (1):
tools/ocaml: Specify rpath correctly for ocamlmklib

tools/ocaml/Makefile.rules | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.39.5
#3 lore raw
In reply to Andrii Sultanov

DO NOT COMMIT - this patch is not correct, and I will send an updated version later.

Quoted 15 lines · Andrii Sultanov

As reported by Nix's Xen team, OCaml stub libs would embed an absolute rpath in the binaries, which was picked up on by patchelf. This is a symptom of improper handling of -rpath-link in the first place, so correct that and get rid of the issue.

Andrii Sultanov (1):
tools/ocaml: Specify rpath correctly for ocamlmklib

 tools/ocaml/Makefile.rules | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.39.5