Skip to contentSkip to conversation

Symlinks in compilation path confuse check-host-rpath

PATCH New Jérôme Pouiller 4 participants 8 messages Sep 30, 2016 – Oct 16, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Symlinks in compilation path confuse check-host-rpath

If user do:

      $ ln -s /opt/buildroot /opt/buildroot-symblink
      $ cd /opt/buildroot-symlink
      $ make O=out
      $ make -C out package-rebuild

the last command produce an error since already installed host binaries contains /opt/buildroot/out/host/usr/lib as rpath while check-host-rpath expect /opt/buildroot-symlink/out/host/usr/lib

These two patch solve this issue. First patch only fix check-host-rpath. However, other tools may be impacted by this issue, so I wrote a second patch to use canonicalized path everywhere.

J?r?me Pouiller (2):
check-host-rpath: support symlinks in rpath
Canonicalize $(BASE_DIR)

 Makefile                         | 2 +-
 support/scripts/check-host-rpath | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 check-host-rpath: support symlinks in rpath

If compilation path contains symlinks, rpath may sometime contains symlinks and sometime canonicalized path.

A pratical example:

  $ ln -s /opt/buildroot /opt/buildroot-symblink
  $ cd /opt/buildroot-symlink
  $ make O=out
  $ make -C out package-rebuild

This last command produce an error since already installed host binaries contains /opt/buildroot/out/host/usr/lib as rpath while check-host-rpath expect /opt/buildroot-symlink/out/host/usr/lib

This patch canonicalize all paths used in check-host-rpath in order to avoid problem

---
 support/scripts/check-host-rpath | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
support/scripts/check-host-rpath +4 -4
index 6ce547c..2541e53 100755
@@ -13,8 +13,8 @@ main() {
     local hostdir="${2}"
     local file ret
 
-    # Remove duplicate and trailing '/' for proper match
-    hostdir="$( sed -r -e 's:/+:/:g; s:/$::;' <<<"${hostdir}" )"
+    # Canonicalize path: follow symlinks, remove duplicate and trailing '/'
+    hostdir="$( readlink -m "${hostdir}" )"
 
     ret=0
     while read file; do
@@ -56,8 +56,8 @@ check_elf_has_rpath() {
 
     while read rpath; do
         for dir in ${rpath//:/ }; do
-            # Remove duplicate and trailing '/' for proper match
-            dir="$( sed -r -e 's:/+:/:g; s:/$::;' <<<"${dir}" )"
+            # Canonicalize path: follow symlinks, remove duplicate and trailing '/'
+            dir="$( readlink -m "${dir}" )"
             [ "${dir}" = "${hostdir}/usr/lib" ] && return 0
         done
     done < <( readelf -d "${file}"                                              \
Signature · 1 line
1.9.1
#2 lore raw

PATCH 1/2 check-host-rpath: support symlinks in rpath

Quoted 10 lines · J?r?me Pouiller

If compilation path contains symlinks, rpath may sometime contains symlinks and sometime canonicalized path.

A pratical example:

  $ ln -s /opt/buildroot /opt/buildroot-symblink
  $ cd /opt/buildroot-symlink
  $ make O=out
  $ make -C out package-rebuild
Quoted 6 lines

This last command produce an error since already installed host binaries contains /opt/buildroot/out/host/usr/lib as rpath while check-host-rpath expect /opt/buildroot-symlink/out/host/usr/lib

This patch canonicalize all paths used in check-host-rpath in order to avoid problem

Wouldn't this also be fixed by http://patchwork.ozlabs.org/patch/613854/ ? With
that patch (series) applied, there shouldn't be any symlinks anymore once the real make starts.

Note that I still had remarks on that specific patch and Samuel hasn't respun.
Maybe something for in Berlin.

Regards,
Arnout

Quoted 33 lines
---
 support/scripts/check-host-rpath | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
support/scripts/check-host-rpath +4 -4
index 6ce547c..2541e53 100755
@@ -13,8 +13,8 @@ main() {
     local hostdir="${2}"
     local file ret
 
-    # Remove duplicate and trailing '/' for proper match
-    hostdir="$( sed -r -e 's:/+:/:g; s:/$::;' <<<"${hostdir}" )"
+    # Canonicalize path: follow symlinks, remove duplicate and trailing '/'
+    hostdir="$( readlink -m "${hostdir}" )"
 
     ret=0
     while read file; do
@@ -56,8 +56,8 @@ check_elf_has_rpath() {
 
     while read rpath; do
         for dir in ${rpath//:/ }; do
-            # Remove duplicate and trailing '/' for proper match
-            dir="$( sed -r -e 's:/+:/:g; s:/$::;' <<<"${dir}" )"
+            # Canonicalize path: follow symlinks, remove duplicate and trailing '/'
+            dir="$( readlink -m "${dir}" )"
             [ "${dir}" = "${hostdir}/usr/lib" ] && return 0
         done
     done < <( readelf -d "${file}"                                              \
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#3 lore raw

PATCH 1/2 check-host-rpath: support symlinks in rpath

Hi Arnout,

Quoted 14 lines · On Tuesday 04 October 2016 23:33:34 Arnout Vandecappelle wrote:
Quoted 13 lines · J?r?me Pouiller

If compilation path contains symlinks, rpath may sometime contains symlinks and sometime canonicalized path.

A pratical example:

  $ ln -s /opt/buildroot /opt/buildroot-symblink
  $ cd /opt/buildroot-symlink
  $ make O=out
  $ make -C out package-rebuild

This last command produce an error since already installed host binaries contains /opt/buildroot/out/host/usr/lib as rpath while check-host-rpath expect /opt/buildroot-symlink/out/host/usr/lib

Quoted 7 lines
Quoted 2 lines

This patch canonicalize all paths used in check-host-rpath in order to avoid problem

Wouldn't this also be fixed by
http://patchwork.ozlabs.org/patch/613854/ ? With that patch (series) applied, there shouldn't be any symlinks anymore once the real make starts.

I didn't saw Samuel's patch. I will test it soon. I think it supersede mine.

BR,

Signature · 3 lines
J?r?me Pouiller, Sysmic
Embedded Linux specialist
http://www.sysmic.fr
#4 lore raw

PATCH 1/2 check-host-rpath: support symlinks in rpath

Hi Jerome,

Quoted 20 lines · J?r?me Pouiller

Hi Arnout,

Quoted 17 lines · On Tuesday 04 October 2016 23:33:34 Arnout Vandecappelle wrote:
Quoted 15 lines · J?r?me Pouiller

If compilation path contains symlinks, rpath may sometime contains symlinks and sometime canonicalized path.

A pratical example:

  $ ln -s /opt/buildroot /opt/buildroot-symblink
  $ cd /opt/buildroot-symlink
  $ make O=out
  $ make -C out package-rebuild

This last command produce an error since already installed host binaries contains /opt/buildroot/out/host/usr/lib as rpath while check-host-rpath expect /opt/buildroot-symlink/out/host/usr/lib

This patch canonicalize all paths used in check-host-rpath in order to avoid problem

Quoted 7 lines
Quoted 4 lines

Wouldn't this also be fixed by
http://patchwork.ozlabs.org/patch/613854/ ? With that patch (series) applied, there shouldn't be any symlinks anymore once the real make starts.

I didn't saw Samuel's patch. I will test it soon. I think it supersede mine.

You never came back to this. We will apply Samuel's patches soon. Can you
re-test after that and resubmit your patches if still needed?

I've marked you patches as Rejected for now.

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#5 lore raw

PATCH 1/2 check-host-rpath: support symlinks in rpath

Hi Jerome,

Quoted 28 lines · Arnout Vandecappelle

Hi Jerome,

Quoted 25 lines · J?r?me Pouiller

Hi Arnout,

Quoted 21 lines · On Tuesday 04 October 2016 23:33:34 Arnout Vandecappelle wrote:
Quoted 9 lines · J?r?me Pouiller

If compilation path contains symlinks, rpath may sometime contains symlinks and sometime canonicalized path.

A pratical example:

  $ ln -s /opt/buildroot /opt/buildroot-symblink
  $ cd /opt/buildroot-symlink
  $ make O=out
  $ make -C out package-rebuild
Quoted 6 lines

This last command produce an error since already installed host binaries contains /opt/buildroot/out/host/usr/lib as rpath while check-host-rpath expect /opt/buildroot-symlink/out/host/usr/lib

This patch canonicalize all paths used in check-host-rpath in order to avoid problem

Wouldn't this also be fixed by
http://patchwork.ozlabs.org/patch/613854/ ? With that patch (series) applied, there shouldn't be any symlinks anymore once the real make starts.

Quoted 5 lines
Quoted 2 lines

I didn't saw Samuel's patch. I will test it soon. I think it supersede mine.

You never came back to this. We will apply Samuel's patches soon. Can you
re-test after that and resubmit your patches if still needed?

I've just reposted a new iteration of this change:
http://lists.busybox.net/pipermail/buildroot/2016-October/174677.html

Regards,

Signature · 1 line
Samuel
#6 lore raw

PATCH 2/2 Canonicalize $(BASE_DIR)

In reply to Jérôme Pouiller

If compilation path contains symlinks, $(*_DIR) variables does not contains same values depending if user run 'make O=out' or 'make -C out'.

This patch always canonicalize $(BASE_DIR) to avoid this problem.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 5e4daef..5c907e5 100644
@@ -136,7 +136,7 @@ endif
 # line doesn't affect the environment of $(shell ..) calls, so
 # explictly throw away any output from 'cd' here.
 export CDPATH :=
-BASE_DIR := $(shell mkdir -p $(O) && cd $(O) >/dev/null && pwd)
+BASE_DIR := $(shell mkdir -p $(O) && cd $(O) >/dev/null && readlink -m .)
 $(if $(BASE_DIR),, $(error output directory "$(O)" does not exist))
 
 
Signature · 1 line
1.9.1
#7 lore raw

cover Symlinks in compilation path confuse check-host-rpath

In reply to Jérôme Pouiller

Hello,

Quoted 3 lines · J?r?me Pouiller

J?r?me Pouiller (2):
check-host-rpath: support symlinks in rpath
Canonicalize $(BASE_DIR)

Samuel, Yann, Arnout, could you help reviewing this patch series?

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com