Make the SDK relocatable
v8 cover Make the SDK relocatable
Hello,
this is v8 of my patch series to make the buildroot SDK (HOST_DIR) relocatable. It sanitizes the RPATH of all ELF files in the "target", "staging" and "host" tree using "patchelf --make-rpath-relative". We now use patchelf v0.9 to still support old Debian and RHEL systems.
v5 did RPATH sanitization per package after package installation into the host, staging or target tree using GLOBAL_INSTRUMENTATION_HOOKS. This approach got more and more complex and inefficient. Therefore it was abandoned in favor of global sanititation at the end of the host, staging and target build (see changes since v5).
Furthermore this patch creates the script "relocate-sdk.sh" in the top directory of the "host" tree allowing to relocate the SDK after it has been moved to a new location. It replaces the old path with the new one in all text files identified by "file --mime-type". The location is stored in "share/buildroot/sdk-location". This patch is already upstream.
Unfortunately, "qmake" uses hard-coded pathes compiled into the QT5 libraries. To overcome this problem, "qt5pase" now creates "qt.conf".
v8 now creates a relocatable SDK with "make sdk". The normal "make" only sanitizes the RPATH in the target tree.
Hope I have not too much pending issues.
Wolfgang.
Changes since v7:
- patchelf patches are now created with git (base on v0.9)
- the target tree is now sanitized before the overlay files are copied
- "make sdk" sanitizes the staging and host tree and adds relocate.sh
- relocate.sh does not use basism an longer
- fix-rpath now uses absolute path without rootdir for staging and target dir
- various other minor fixes (doc, indention, etc.)
Changes since v6:
- patchelf patches: update patch header with upstream commit, etc.
- ${HOST_DIR}/usr is gone which required various fixes
- Proper qt.conf.in added
Changes since v5:
- switch back to v4
- patchelf patches are now based on v0.9
- patchelf now calculates minimal relative path to the ELF file (and not to the rootdir as before).
- patchelf: neededLibFound is now passed to libFoundInRPath
- Makefile: the "host-finalize" target has been added for SDK relocation
- fix-rpath now uses variables to define the list of dirs to be pruned
- fix-rpath: the staging tree is sanitized like the target tree
- various minor fixes (typos)
Changes since v4:
- RPATH sanitation is now done per package and installation step in "pkg-generic.mk".
- After the installation step, the list of the installed files is stored in "<package-build-dir>/.br_[host|staging|target]_filelist".
- The GLOBAL_INSTRUMENTATION_HOOKS "step_sanitize_rpath" then calls "fix-rpath" to do the sanitation.
- DEPENDENCIES_HOST_PREREQ += host-patchelf is set early in the Makefile as we need it for RPATH sanitation. As soon it's available sanitation can start (currently missing some packages).
- The patchelf "file busy" issue is now worked-around differently.
Changes since v3:
- The patchelf patch implementing " --make-rpath-relative" now supports the option "--relative-to-file" instructing to use "$ORIGIN" in RPATHs. Otherwise an absolute path relative to the root directory will be used.
- The staging tree is now sanitized as well using the options "--relative-to-file" and "--no-standard-libs".
- For the "target" tree, relative RPATHs do not use "$ORIGIN" any longer. An absolute path relative to the root directory is used instead.
Changes since v2:
- provide "qt.conf" to make "qmake" relocatable
- sed now uses the separator "\" to substitute the directory path. It's one of the few characters not allowed in file names. To avoid interpreting it as escape character, the "read -r" is used.
- The paranoia substituion check is done before doing the real substituion.
Changes since v1:
- The name SDK has been chosen for the relocatabed "HOST_DIR" (instead of toolchanin).
- The patchelf version bump and patching are now done by 2 patches
- No more helper functions are used in the Makefile to call "fix-rpath" but added directly.
- The staging tree is not touched any more... until we have a good reason to do so.
- The sanitation is now performed by an optimized "fix-rpath" script.
- The relocate-sdk script is now copied for support/misc to the top directory of the host tree.
Samuel Martin (1):
support/scripts: add fix-rpath script to sanitize the rpath
Wolfgang Grandegger (9):
support/scripts: relocate-sdk.sh now uses a normal pipe to find
strings
package/patchelf: add patch for rpath sanitization under a root
directory
patchelf: always build this package required for RPATH sanitization
core: sanitize RPATH in target tree before copying the overlay
core: introduce "sdk" target to make a relocatable SDK
core: sanitize RPATH in staging tree to make a relocatable SDK
external-toolchain: check if a buildroot SDK has already been
relocated
core: install relocation script and location to make a relocatable SDK package/qt5base: provide "qt.conf" to make "qmake" relocatable
Makefile | 13 + ...move-apparently-incorrect-usage-of-static.patch | 56 ++++ ...unction-for-splitting-a-colon-separated-s.patch | 63 ++++ ...to-make-the-rpath-relative-under-a-specif.patch | 332 +++++++++++++++++++++ package/patchelf/Config.in.host | 3 +- package/qt5/qt5base/qt.conf.in | 19 ++ package/qt5/qt5base/qt5base.mk | 8 + support/misc/relocate-sdk.sh | 4 +- support/scripts/fix-rpath | 133 +++++++++ toolchain/helpers.mk | 16 + .../toolchain-external/pkg-toolchain-external.mk | 1 + 11 files changed, 645 insertions(+), 3 deletions(-) create mode 100644 package/patchelf/0001-Remove-apparently-incorrect-usage-of-static.patch create mode 100644 package/patchelf/0002-Extract-a-function-for-splitting-a-colon-separated-s.patch create mode 100644 package/patchelf/0003-Add-option-to-make-the-rpath-relative-under-a-specif.patch create mode 100644 package/qt5/qt5base/qt.conf.in create mode 100755 support/scripts/fix-rpath
Signature · 1 line
2.7.4
PATCH v8 1/10 support/scripts: relocate-sdk.sh now uses a normal pipe to find strings
The normal shell does not support the bashism "< <(...)". Therefore we use a normal pipe to find files containing a specific string.
--- support/misc/relocate-sdk.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
support/misc/relocate-sdk.sh +2 -2
@@ -35,12 +35,12 @@ echo "Relocating the buildroot SDK from ${OLDPATH} to ${NEWPATH} ..." # Make sure file uses the right language export LC_ALL=C # Replace the old path with the new one in all text files -while read -r FILE ; do +grep -lr "${OLDPATH}" . | while read -r FILE ; do if file -b --mime-type "${FILE}" | grep -q '^text/' && [ "${FILE}" != "${LOCFILE}" ] then sed -i "s|${OLDPATH}|${NEWPATH}|g" "${FILE}" fi -done < <(grep -lr "${OLDPATH}" .) +done # At the very end, we update the location file to not break the # SDK if this script gets interruted.
Signature · 1 line
2.7.4
Thomas Petazzoni
AppliedPATCH v8 1/10 support/scripts: relocate-sdk.sh now uses a normal pipe to find strings
Hello,
Quoted 7 lines · Wolfgang Grandegger
The normal shell does not support the bashism "< <(...)". Therefore we use a normal pipe to find files containing a specific string.
Signed-off-by Wolfgang Grandegger <[email protected]>--- support/misc/relocate-sdk.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH v8 2/10 package/patchelf: add patch for rpath sanitization under a root directory
In reply to Wolfgang GrandeggerThe patch allows to use patchelf to sanitize the rpath of the buildroot libraries and binaries using the option "--make-rpath-relative <rootdir>". Recent versions of patchelf will not built on old Debian and RHEL systems due to C++11 constructs. Therefore we stick with v0.9 for the time being.
--- ...move-apparently-incorrect-usage-of-static.patch | 56 ++++ ...unction-for-splitting-a-colon-separated-s.patch | 63 ++++ ...to-make-the-rpath-relative-under-a-specif.patch | 332 +++++++++++++++++++++ 3 files changed, 451 insertions(+) create mode 100644 package/patchelf/0001-Remove-apparently-incorrect-usage-of-static.patch create mode 100644 package/patchelf/0002-Extract-a-function-for-splitting-a-colon-separated-s.patch create mode 100644 package/patchelf/0003-Add-option-to-make-the-rpath-relative-under-a-specif.patch
package/patchelf/0001-Remove-apparently-incorrect-usage-of-static.patch new file +56 -0
@@ -0,0 +1,56 @@ +From 2480efa8411523cf046094492192a5ee451aae5d Mon Sep 17 00:00:00 2001 +From: Eelco Dolstra <[email protected]> +Date: Mon, 19 Sep 2016 17:31:37 +0200 +Subject: [PATCH] Remove apparently incorrect usage of "static" + +[Upstream-commit: https://github.com/NixOS/patchelf/commit/a365bcb7d7025da51b33165ef7ebc7180199a05e +This patch also removes the DT_INIT symbols from needed_libs (DT_INIT +points to library initialisation function, not to needed libraries...)] +Signed-off-by: Wolfgang Grandegger <[email protected]> +--- + src/patchelf.cc | 8 +++----- + 1 file changed, 3 insertions(+), 5 deletions(-) + +diff --git a/src/patchelf.cc b/src/patchelf.cc +index 136098f..c870638 100644 +--- a/src/patchelf.cc ++++ b/src/patchelf.cc +@@ -941,7 +941,6 @@ void ElfFile<ElfFileParamNames>::modifySoname(sonameMode op, const string & newS + assert(strTabAddr == rdi(shdrDynStr.sh_addr)); + + /* Walk through the dynamic section, look for the DT_SONAME entry. */ +- static vector<string> neededLibs; + dyn = (Elf_Dyn *) (contents + rdi(shdrDynamic.sh_offset)); + Elf_Dyn * dynSoname = 0; + char * soname = 0; +@@ -949,8 +948,7 @@ void ElfFile<ElfFileParamNames>::modifySoname(sonameMode op, const string & newS + if (rdi(dyn->d_tag) == DT_SONAME) { + dynSoname = dyn; + soname = strTab + rdi(dyn->d_un.d_val); +- } else if (rdi(dyn->d_tag) == DT_INIT) +- neededLibs.push_back(string(strTab + rdi(dyn->d_un.d_val))); ++ } + } + + if (op == printSoname) { +@@ -1058,7 +1056,7 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op, string newRPath) + unless you use its `--enable-new-dtag' option, in which case it + generates a DT_RPATH and DT_RUNPATH pointing at the same + string. */ +- static vector<string> neededLibs; ++ vector<string> neededLibs; + dyn = (Elf_Dyn *) (contents + rdi(shdrDynamic.sh_offset)); + Elf_Dyn * dynRPath = 0, * dynRunPath = 0; + char * rpath = 0; +@@ -1091,7 +1089,7 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op, string newRPath) + /* For each directory in the RPATH, check if it contains any + needed library. */ + if (op == rpShrink) { +- static vector<bool> neededLibFound(neededLibs.size(), false); ++ vector<bool> neededLibFound(neededLibs.size(), false); + + newRPath = ""; + +-- +1.9.1 +
package/patchelf/0002-Extract-a-function-for-splitting-a-colon-separated-s.patch new file +63 -0
63 lines not on this page · raw message
package/patchelf/0003-Add-option-to-make-the-rpath-relative-under-a-specif.patch new file +332 -0
332 lines not on this page · raw message
Signature · 1 line
2.7.4
Thomas Petazzoni
AppliedPATCH v8 2/10 package/patchelf: add patch for rpath sanitization under a root directory
Hello,
Quoted 7 lines · Wolfgang Grandegger
The patch allows to use patchelf to sanitize the rpath of the buildroot libraries and binaries using the option "--make-rpath-relative <rootdir>". Recent versions of patchelf will not built on old Debian and RHEL systems due to C++11 constructs. Therefore we stick with v0.9 for the time being.
Quoted 8 lines
--- ...move-apparently-incorrect-usage-of-static.patch | 56 ++++ ...unction-for-splitting-a-colon-separated-s.patch | 63 ++++ ...to-make-the-rpath-relative-under-a-specif.patch | 332 +++++++++++++++++++++ 3 files changed, 451 insertions(+) create mode 100644 package/patchelf/0001-Remove-apparently-incorrect-usage-of-static.patch create mode 100644 package/patchelf/0002-Extract-a-function-for-splitting-a-colon-separated-s.patch create mode 100644 package/patchelf/0003-Add-option-to-make-the-rpath-relative-under-a-specif.patch
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH v8 3/10 support/scripts: add fix-rpath script to sanitize the rpath
In reply to Wolfgang GrandeggerFrom: Samuel Martin <[email protected]>
This commit introduces the script "fix-rpath" able to scan a tree, detect ELF files, check their RPATH and fix it in a proper way. The RPATH fixup is done by the patchelf utility using the option "--make-rpath-relative <root-directory>".
--- support/scripts/fix-rpath | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 support/scripts/fix-rpath
support/scripts/fix-rpath new file +133 -0
@@ -0,0 +1,133 @@ +#!/usr/bin/env bash + +# Copyright (C) 2016 Samuel Martin <[email protected]> +# Copyright (C) 2017 Wolfgang Grandegger <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +usage() { + cat <<EOF >&2 +Usage: ${0} TREE_KIND + +Description: + + This script scans a tree and sanitize ELF files' RPATH found in there. + + Sanitization behaves the same whatever the kind of the processed tree, + but the resulting RPATH differs. The rpath sanitization is done using + "patchelf --make-rpath-relazive". + +Arguments: + + TREE_KIND Kind of tree to be processed. + Allowed values: host, target, staging + +Environment: + + PATCHELF patchelf program to use + (default: HOST_DIR/bin/patchelf) + + HOST_DIR host directory + STAGING_DIR staging directory + TARGET_DIR target directory + + TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR + (default HOST_DIR/opt/ext-toolchain) +EOF +} + +: ${PATCHELF:=${HOST_DIR}/bin/patchelf} + +# ELF files should not be in these sub-directories +HOST_EXCLUDEPATHS="/share/terminfo" +STAGING_EXCLUDEPATHS="/usr/include /usr/share/terminfo" + +main() { + local rootdir + local tree="${1}" + local find_args=( ) + local sanitize_extra_args=( ) + + case "${tree}" in + host) + rootdir="${HOST_DIR}" + + # do not process the sysroot (only contains target binaries) + find_args+=( "-path" "${STAGING_DIR}" "-prune" "-o" ) + + # do not process the external toolchain installation directory to + # avoid breaking it. + test "${TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR}" != "" && \ + find_args+=( "-path" "${TOOLCHAIN_EXTERNAL_DOWNLOAD_INSTALL_DIR}" "-prune" "-o" ) + + for excludepath in ${HOST_EXCLUDEPATHS}; do + find_args+=( "-path" "${HOST_DIR}""${excludepath}" "-prune" "-o" ); + done + + # do not process the patchelf binary but a copy to work-around "file in use" + find_args+=( "-path" "${PATCHELF}" "-prune" "-o" ) + cp "${PATCHELF}" "${PATCHELF}.__to_be_patched" + + # we always want $ORIGIN-based rpaths to make it relocatable. + sanitize_extra_args+=( "--relative-to-file" ) + ;; + + staging) + rootdir="${STAGING_DIR}" + + # ELF files should not be in these sub-directories + for excludepath in ${STAGING_EXCLUDEPATHS}; do + find_args+=( "-path" "${STAGING_DIR}""${excludepath}" "-prune" "-o" ) + done + + # should be like for the target tree below + sanitize_extra_args+=( "--no-standard-lib-dirs" ) + ;; + + target) + rootdir="${TARGET_DIR}" + # we don't want $ORIGIN-based rpaths but absolute paths without rootdir. + # we also want to remove rpaths pointing to /lib or /usr/lib. + sanitize_extra_args+=( "--no-standard-lib-dirs" ) + ;; + + *) + usage + exit 1 + ;; + esac + + find_args+=( "-type" "f" "-print" ) + + while read file ; do + # check if it's an ELF file + if ${PATCHELF} --print-rpath "${file}" > /dev/null 2>&1; then + # make files writable if necessary + changed=$(chmod -c u+w "${file}") + # call patchelf to sanitize the rpath + ${PATCHELF} --make-rpath-relative "${rootdir}" ${sanitize_extra_args[@]} "${file}" + # restore the original permission + test "${changed}" != "" && chmod u-w "${file}" + fi + done < <(find "${rootdir}" ${find_args[@]}) + + # Restore patched patchelf utility + test "${tree}" = "host" && mv "${PATCHELF}.__to_be_patched" "${PATCHELF}" + + # ignore errors + return 0 +} + +main ${@}
Signature · 1 line
2.7.4
PATCH v8 3/10 support/scripts: add fix-rpath script to sanitize the rpath
Hello,
Quoted 7 lines · Wolfgang Grandegger
From: Samuel Martin <[email protected]>
This commit introduces the script "fix-rpath" able to scan a tree, detect ELF files, check their RPATH and fix it in a proper way. The RPATH fixup is done by the patchelf utility using the option "--make-rpath-relative <root-directory>".
Quoted 7 lines
Signed-off-by Samuel Martin <[email protected]>Signed-off-by Wolfgang Grandegger <[email protected]>--- support/scripts/fix-rpath | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 support/scripts/fix-rpath
I've applied to master, after removing trailing slashes.
However, I noticed that when patchelf is not available in HOST_DIR, this script does nothing, but doesn't show any error:
thomas at windsurf:~/projets/buildroot (master)$ rm output/host/usr/bin/patchelf thomas at windsurf:~/projets/buildroot (master)$ make
[...]
Quoted 1 line
Quoted 1 line
Quoted 1 line
Sanitizing RPATH in target tree
/home/thomas/projets/buildroot/support/scripts/fix-rpath target thomas at windsurf:~/projets/buildroot (master)$
This is a little bit disturbing, so I believe it should be fixed in a follow-up patch.
Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH v8 3/10 support/scripts: add fix-rpath script to sanitize the rpath
Quoted 18 lines · Thomas Petazzoni
Hello,
Quoted 7 lines · Wolfgang Grandegger
From: Samuel Martin <[email protected]>
This commit introduces the script "fix-rpath" able to scan a tree, detect ELF files, check their RPATH and fix it in a proper way. The RPATH fixup is done by the patchelf utility using the option "--make-rpath-relative <root-directory>".
Quoted 7 lines
Signed-off-by Samuel Martin <[email protected]>Signed-off-by Wolfgang Grandegger <[email protected]>--- support/scripts/fix-rpath | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 support/scripts/fix-rpath
Quoted 1 line
I've applied to master, after removing trailing slashes.
Which trailing slashes?
Quoted 6 lines
However, I noticed that when patchelf is not available in
HOST_DIR, this script does nothing, but doesn't show any error:thomas at windsurf:~/projets/buildroot (master)$ rm output/host/usr/bin/patchelf thomas at windsurf:~/projets/buildroot (master)$ make
[...]
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Sanitizing RPATH in target tree
/home/thomas/projets/buildroot/support/scripts/fix-rpathtarget thomas at windsurf:~/projets/buildroot (master)$This is a little bit disturbing, so I believe it should be fixed in a follow-up patch.
Right! That's because the "if ${PATCHELF} ..." just fails and the error is
redirected to /dev/null.
Better check if ${PATCHELF} is executable somewhere in the beginning.
However, there is never a guarantee. If e.g. it would be missing a shared
library, it would still fail in the same way. To be really sure, you'd have do e.g. call patchelf on itself to verify it is actually working.
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
PATCH v8 3/10 support/scripts: add fix-rpath script to sanitize the rpath
Hello,
Quoted 7 lines · Arnout Vandecappelle
Quoted 5 lines
Quoted 3 lines
support/scripts/fix-rpath | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 support/scripts/fix-rpathI've applied to master, after removing trailing slashes.
Which trailing slashes?
Gaah, I wanted to say "trailing spaces".
Quoted 11 lines
Quoted 2 lines
This is a little bit disturbing, so I believe it should be fixed in a follow-up patch.
Right! That's because the "if ${PATCHELF} ..." just fails and the error is
redirected to/dev/null.Better check if ${PATCHELF} is executable somewhere in the beginning.
However, there is never a guarantee. If e.g. it would be missing a shared
library, it would still fail in the same way. To be really sure, you'd have do e.g. call patchelf on itself to verify it is actually working.
Perhaps patchelf --help is sufficient?
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 3/10 support/scripts: add fix-rpath script to sanitize the rpath
In reply to Arnout VandecappelleAm 20.07.2017 um 23:05 schrieb Arnout Vandecappelle:
Quoted 39 lines · Thomas Petazzoni
Quoted 18 lines
Hello,
Quoted 7 lines · Wolfgang Grandegger
From: Samuel Martin <[email protected]>
This commit introduces the script "fix-rpath" able to scan a tree, detect ELF files, check their RPATH and fix it in a proper way. The RPATH fixup is done by the patchelf utility using the option "--make-rpath-relative <root-directory>".
Quoted 7 lines
Signed-off-by Samuel Martin <[email protected]>Signed-off-by Wolfgang Grandegger <[email protected]>--- support/scripts/fix-rpath | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+)create mode 100755 support/scripts/fix-rpath
Quoted 1 line
I've applied to master, after removing trailing slashes.
Which trailing slashes?
Quoted 6 lines
However, I noticed that when patchelf is not available in
HOST_DIR, this script does nothing, but doesn't show any error:thomas at windsurf:~/projets/buildroot (master)$ rm output/host/usr/bin/patchelf thomas at windsurf:~/projets/buildroot (master)$ make
[...]Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Sanitizing RPATH in target tree
/home/thomas/projets/buildroot/support/scripts/fix-rpathtarget thomas at windsurf:~/projets/buildroot (master)$This is a little bit disturbing, so I believe it should be fixed in a follow-up patch.
Quoted 8 lines
Right! That's because the "if ${PATCHELF} ..." just fails and the error is
redirected to/dev/null.Better check if ${PATCHELF} is executable somewhere in the beginning.However, there is never a guarantee. If e.g. it would be missing a shared
library, it would still fail in the same way. To be really sure, you'd have do e.g. call patchelf on itself to verify it is actually working.
Or you can set "PATCHELF_DEBUG=1" to check what patchelf is doing.
Wolfgang.
PATCH v8 3/10 support/scripts: add fix-rpath script to sanitize the rpath
Hello,
Quoted 10 lines · Wolfgang Grandegger
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Sanitizing RPATH in target tree
/home/thomas/projets/buildroot/support/scripts/fix-rpathtarget thomas at windsurf:~/projets/buildroot (master)$This is a little bit disturbing, so I believe it should be fixed in a follow-up patch.
Right! That's because the "if ${PATCHELF} ..." just fails and the error is
redirected to/dev/null.
Quoted 7 lines
Quoted 5 lines
Better check if ${PATCHELF} is executable somewhere in the beginning.However, there is never a guarantee. If e.g. it would be missing a shared
library, it would still fail in the same way. To be really sure, you'd have do e.g. call patchelf on itself to verify it is actually working.Or you can set "PATCHELF_DEBUG=1" to check what patchelf is doing.
We're not interested in knowing what patchelf is doing. My initial report is that if the patchelf binary doesn't exist, the script runs without reporting any error:
- Nothing on stdout/stderr
- The script has an exit code of 0
This is not good: the script should at the very least return a non-zero error code if patchelf isn't available, and should probably display an error as well.
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 3/10 support/scripts: add fix-rpath script to sanitize the rpath
Am 21.07.2017 um 09:40 schrieb Thomas Petazzoni:
Quoted 26 lines
Hello,
Quoted 10 lines · Wolfgang Grandegger
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Sanitizing RPATH in target tree
/home/thomas/projets/buildroot/support/scripts/fix-rpathtarget thomas at windsurf:~/projets/buildroot (master)$This is a little bit disturbing, so I believe it should be fixed in a follow-up patch.
Right! That's because the "if ${PATCHELF} ..." just fails and the error is
redirected to/dev/null.Quoted 7 lines
Quoted 5 lines
Better check if ${PATCHELF} is executable somewhere in the beginning.However, there is never a guarantee. If e.g. it would be missing a shared
library, it would still fail in the same way. To be really sure, you'd have do e.g. call patchelf on itself to verify it is actually working.Or you can set "PATCHELF_DEBUG=1" to check what patchelf is doing.
We're not interested in knowing what patchelf is doing. My initial report is that if the patchelf binary doesn't exist, the script runs without reporting any error:
Quoted 6 lines
- Nothing on stdout/stderr
- The script has an exit code of 0This is not good: the script should at the very least return a non-zero error code if patchelf isn't available, and should probably display an error as well.
Yes, I already got that point.
Wolfgang.
PATCH v8 3/10 support/scripts: add fix-rpath script to sanitize the rpath
In reply to Wolfgang GrandeggerOn 20-07-17 16:35, Wolfgang Grandegger wrote:
[snip]
You forgot:
Quoted 1 line
+ This script scans a tree and sanitize ELF files' RPATH found in there.
^s
support/scripts/fix-rpath line 30
Quoted 4 lines
support/scripts/fix-rpath new file +4
-0+ + Sanitization behaves the same whatever the kind of the processed tree, + but the resulting RPATH differs. The rpath sanitization is done using + "patchelf --make-rpath-relazive".
^t
[snip]
support/scripts/fix-rpath line 76
Quoted 2 lines
support/scripts/fix-rpath new file +2
-0+ for excludepath in ${HOST_EXCLUDEPATHS}; do + find_args+=( "-path" "${HOST_DIR}""${excludepath}" "-prune" "-o" );
Unneeded ;
Regards,
Arnout
[snip]
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
Thomas Petazzoni
AppliedPATCH v8 3/10 support/scripts: add fix-rpath script to sanitize the rpath
Hello,
Quoted 10 lines · Arnout Vandecappelle
On 20-07-17 16:35, Wolfgang Grandegger wrote:
[snip]You forgot:
Quoted 1 line
+ This script scans a tree and sanitize ELF files' RPATH found in there.
^ssupport/scripts/fix-rpath line 30
Quoted 4 lines
support/scripts/fix-rpath new file +4
-0+ + Sanitization behaves the same whatever the kind of the processed tree, + but the resulting RPATH differs. The rpath sanitization is done using + "patchelf --make-rpath-relazive".
Quoted 7 lines
^t[snip]
support/scripts/fix-rpath line 76
Quoted 2 lines
support/scripts/fix-rpath new file +2
-0+ for excludepath in ${HOST_EXCLUDEPATHS}; do + find_args+=( "-path" "${HOST_DIR}""${excludepath}" "-prune" "-o" );Unneeded ;
Please send follow-up patches. Thanks!
I've applied 1 to 5 and 10 tonight. I won't apply 6 to 9 today, so there's more time to review/adjust them if needed.
Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 4/10 patchelf: always build this package required for RPATH sanitization
In reply to Wolfgang Grandegger--- package/patchelf/Config.in.host | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
package/patchelf/Config.in.host +2 -1
@@ -1,5 +1,6 @@ config BR2_PACKAGE_HOST_PATCHELF - bool "host patchelf" + bool + default "y" help PatchELF is a small utility to modify the dynamic linker and RPATH of ELF executables.
Signature · 1 line
2.7.4
PATCH v8 4/10 patchelf: always build this package required for RPATH sanitization
Hello,
Quoted 10 lines · Wolfgang Grandegger
Signed-off-by Wolfgang Grandegger <[email protected]>--- package/patchelf/Config.in.host | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)package/patchelf/Config.in.host +0
-0
package/patchelf/Config.in.host line 3
Quoted 4 lines
package/patchelf/Config.in.host +2
-1@@ -1,5 +1,6 @@ config BR2_PACKAGE_HOST_PATCHELF - bool "host patchelf" + bool + default "y"
Double quotes are not needed, so I dropped them and applied.
Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 5/10 core: sanitize RPATH in target tree before copying the overlay
In reply to Wolfgang GrandeggerWe sanitize the RPATH of ELF files in the target tree to deal with stupid packages that don't correctly use --prefix/DESTDIR and that end up putting the full absolute build-time directory in the RPATH.
We do it before copying the overlay and calling the post-build script. The user is completely responsible for what happens in the last two steps, and it should never be touched by us.
--- Makefile | 3 +++ 1 file changed, 3 insertions(+)
Makefile +3 -0
@@ -709,6 +709,9 @@ endif echo "PRETTY_NAME=\"Buildroot $(BR2_VERSION)\"" \ ) > $(TARGET_DIR)/etc/os-release + @$(call MESSAGE,"Sanitizing RPATH in target tree") + $(TOPDIR)/support/scripts/fix-rpath target + @$(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \ $(call MESSAGE,"Copying overlay $(d)"); \ rsync -a --ignore-times --keep-dirlinks $(RSYNC_VCS_EXCLUSIONS) \
Signature · 1 line
2.7.4
Thomas Petazzoni
AppliedPATCH v8 5/10 core: sanitize RPATH in target tree before copying the overlay
Hello,
Quoted 5 lines · Wolfgang Grandegger
We sanitize the RPATH of ELF files in the target tree to deal with stupid packages that don't correctly use --prefix/DESTDIR and that end up putting the full absolute build-time directory in the RPATH.
Quoted 8 lines
We do it before copying the overlay and calling the post-build script. The user is completely responsible for what happens in the last two steps, and it should never be touched by us.
Signed-off-by Wolfgang Grandegger <[email protected]>--- Makefile | 3 +++ 1 file changed, 3 insertions(+)
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH v8 6/10 core: introduce "sdk" target to make a relocatable SDK
In reply to Wolfgang GrandeggerWe use a separate make target to build a relocatable SDK. We first sanitize the RPATH in host tree depending on the toolchain.
--- Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
Makefile +6 -0
@@ -552,6 +552,11 @@ prepare: $(BUILD_DIR)/buildroot-config/auto.conf .PHONY: world world: target-post-image +.PHONY: sdk +sdk: toolchain + @$(call MESSAGE,"Rendering the SDK relocatable") + $(TOPDIR)/support/scripts/fix-rpath host + # Compatibility symlink in case a post-build script still uses $(HOST_DIR)/usr $(HOST_DIR)/usr: $(HOST_DIR) @ln -snf . $@
@@ -1001,6 +1006,7 @@ help: @echo 'Build:' @echo ' all - make world' @echo ' toolchain - build toolchain' + @echo ' sdk - build relocatable SDK' @echo @echo 'Configuration:' @echo ' menuconfig - interactive curses-based configurator'
Signature · 1 line
2.7.4
PATCH v8 6/10 core: introduce "sdk" target to make a relocatable SDK
Quoted 14 lines · Wolfgang Grandegger
We use a separate make target to build a relocatable SDK. We first sanitize the RPATH in host tree depending on the toolchain.
Signed-off-by Wolfgang Grandegger <[email protected]>--- Makefile | 6 ++++++ 1 file changed, 6 insertions(+)Makefile +0
-0
Makefile prepare: $(BUILD_DIR)/buildroot-config/auto.conf · line 556
Quoted 5 lines
Makefile +2
-0@@ -552,6 +552,11 @@ prepare: $(BUILD_DIR)/buildroot-config/auto.conf .PHONY: world world: target-post-image +.PHONY: sdk +sdk: toolchain
As mentioned by Thomas, this should depend on "world", not just toolchain.
Indeed, plenty of host packages are built *after* the toolchain. You could add ${PACKAGES} as a dependency, but that still misses the dependencies of the rootfs targets that don't have a Kconfig option. So depending on "world" is the easiest.
With that (and updating the commit message accordingly):
Regards,
Arnout
Quoted 15 lines
Makefile +4
-0+ @$(call MESSAGE,"Rendering the SDK relocatable") + $(TOPDIR)/support/scripts/fix-rpath host + # Compatibility symlink in case a post-build script still uses $(HOST_DIR)/usr $(HOST_DIR)/usr: $(HOST_DIR) @ln -snf . $@@@ -1001,6 +1006,7 @@ help: @echo 'Build:' @echo ' all - make world' @echo ' toolchain - build toolchain' + @echo ' sdk - build relocatable SDK' @echo @echo 'Configuration:' @echo ' menuconfig - interactive curses-based configurator'
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
PATCH v8 6/10 core: introduce "sdk" target to make a relocatable SDK
Hello,
Quoted 8 lines · Arnout Vandecappelle
As mentioned by Thomas, this should depend on "world", not just toolchain.
Indeed, plenty of host packages are built *after* the toolchain. You could add ${PACKAGES} as a dependency, but that still misses the dependencies of the rootfs targets that don't have aKconfigoption. So depending on "world" is the easiest.With that (and updating the commit message accordingly):
Wolfgang added the dependency on $(PACKAGES) in PATCH 07/10. But actually, I think PATCH 06/10 and 07/10 should probably be squashed together, and indeed have sdk depend on world.
In fact even PATCH 09/10 should be squashed with 06/10 and 07/10. Just one patch adding the "sdk" target is enough, it's just a few lines overall.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 7/10 core: sanitize RPATH in staging tree to make a relocatable SDK
In reply to Wolfgang GrandeggerWhen calling "make sdk" we also sanitize the staging tree. Therefore "sdk" must depend on all packages.
Sanitizing staging is not really needed, in the sense that any rpath in there is simply not going to be used. We want to sanitize staging for the following reasons:
- To avoid leaking references to the original output directory. This way, we can validate that the SDK is relocatable by running a simple "grep -r ${BASE_DIR} ${HOST_DIR}". Obviously RPATH sanitization is not sufficient (e.g. also the references to source files have to be stripped), but it's a step in the right direction. This reason is obviously only relevant for the SDK.
- To make sure that when an executable is copied to target that it actually executes correctly. Since within Buildroot we never copy stuff from staging to target, this is clearly only relevant for the SDK.
--- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Makefile +3 -1
@@ -553,9 +553,11 @@ prepare: $(BUILD_DIR)/buildroot-config/auto.conf world: target-post-image .PHONY: sdk -sdk: toolchain +sdk: toolchain $(PACKAGES) @$(call MESSAGE,"Rendering the SDK relocatable") $(TOPDIR)/support/scripts/fix-rpath host + @$(call MESSAGE,"Sanitizing RPATH in staging tree") + $(TOPDIR)/support/scripts/fix-rpath staging # Compatibility symlink in case a post-build script still uses $(HOST_DIR)/usr $(HOST_DIR)/usr: $(HOST_DIR)
Signature · 1 line
2.7.4
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
In reply to Wolfgang GrandeggerThe location of the buildroot SDK is stored in the file "sdk-location" in "share/buildroot". If it's content does not match the current SDK location, ask the user to run the script "relocate-sdk.sh" in the top directory once. The external toolchain may be a pre-installed one in a directory that is not writeable by us. Therefore, we can't run the script directly.
--- toolchain/helpers.mk | 16 ++++++++++++++++ toolchain/toolchain-external/pkg-toolchain-external.mk | 1 + 2 files changed, 17 insertions(+)
toolchain/helpers.mk +16 -0
@@ -484,3 +484,19 @@ define simplify_symlink ln -sf "$${DOTS}$${REL_DEST}" "$${FULL_SRC}" ; \ ) endef + +# +# Check if it's a buildroot toolchain and if it's already relocatable by +# reading and testing the toolchain location file +# +# $1: toolchain installation directory +# +define check_buildroot_sdk_relocated + if [ -r $(1)/share/buildroot/sdk-location ]; then \ + sdkroot="$(1)"; \ + if [ "`cat $(1)/share/buildroot/sdk-location`" != "$${sdkroot}" ]; then \ + echo "Please relocate the buildroot SDK by executing \"$${sdkroot}/relocate-sdk.sh\" once!" ; \ + exit 1 ; \ + fi \ + fi +endef
toolchain/toolchain-external/pkg-toolchain-external.mk +1 -0
@@ -529,6 +529,7 @@ endif # matches the configuration provided in Buildroot: ABI, C++ support, # kernel headers version, type of C library and all C library features. define $(2)_CONFIGURE_CMDS + $$(Q)$$(call check_buildroot_sdk_relocated,$$(TOOLCHAIN_EXTERNAL_INSTALL_DIR)) $$(Q)$$(call check_cross_compiler_exists,$$(TOOLCHAIN_EXTERNAL_CC)) $$(Q)$$(call check_unusable_toolchain,$$(TOOLCHAIN_EXTERNAL_CC)) $$(Q)SYSROOT_DIR="$$(call toolchain_find_sysroot,$$(TOOLCHAIN_EXTERNAL_CC))" ; \
Signature · 1 line
2.7.4
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
Hello,
Quoted 7 lines · Wolfgang Grandegger
The location of the buildroot SDK is stored in the file "sdk-location" in "share/buildroot". If it's content does not match the current SDK location, ask the user to run the script "
relocate-sdk.sh" in the top directory once. The external toolchain may be a pre-installed one in a directory that is not writeable by us. Therefore, we can't run the script directly.
Quoted 5 lines
Signed-off-by Wolfgang Grandegger <[email protected]>--- toolchain/helpers.mk | 16 ++++++++++++++++ toolchain/toolchain-external/pkg-toolchain-external.mk | 1 + 2 files changed, 17 insertions(+)
Now that I think of it, this is going to be a bit annoying. This means that whenever you want to use a Buildroot-generated toolchain as an external toolchain in another Buildroot configuration, you have to run this relocate script.
This will break a lot of things, like the autobuilders, the runtime test infrastructure, etc. that all rely on pre-built Buildroot toolchains, but don't run the relocate-sdk script. In addition, we simply can't do it, because it's directly Buildroot itself that downloads the toolchain tarball and extracts it, so we don't even get the opportunity to run the relocate-sdk script.
Therefore, I cannot apply this as-is, a better solution needs to be found.
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
Quoted 21 lines · Thomas Petazzoni
Hello,
Quoted 7 lines · Wolfgang Grandegger
The location of the buildroot SDK is stored in the file "sdk-location" in "share/buildroot". If it's content does not match the current SDK location, ask the user to run the script "
relocate-sdk.sh" in the top directory once. The external toolchain may be a pre-installed one in a directory that is not writeable by us. Therefore, we can't run the script directly.Quoted 5 lines
Signed-off-by Wolfgang Grandegger <[email protected]>--- toolchain/helpers.mk | 16 ++++++++++++++++ toolchain/toolchain-external/pkg-toolchain-external.mk | 1 + 2 files changed, 17 insertions(+)Now that I think of it, this is going to be a bit annoying. This means that whenever you want to use a Buildroot-generated toolchain as an external toolchain in another Buildroot configuration, you have to run this relocate script.
Quoted 6 lines
This will break a lot of things, like the autobuilders, the runtime test infrastructure, etc. that all rely on pre-built Buildroot toolchains, but don't run the relocate-sdk script. In addition, we simply can't do it, because it's directly Buildroot itself that downloads the toolchain tarball and extracts it, so we don't even get the opportunity to run the relocate-sdk script.
Well, we could run the script directly for downloaded toolchains, and do the
check for pre-installed toolchains. Does that sound acceptable?
I'm probably forgetting something though :-)
Regards,
Arnout
Quoted 8 lines
Therefore, I cannot apply this as-is, a better solution needs to be found.
Best regards,
Thomas
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
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
Hello,
Quoted 12 lines · Arnout Vandecappelle
Quoted 11 lines
Now that I think of it, this is going to be a bit annoying. This means that whenever you want to use a Buildroot-generated toolchain as an external toolchain in another Buildroot configuration, you have to run this relocate script.
This will break a lot of things, like the autobuilders, the runtime test infrastructure, etc. that all rely on pre-built Buildroot toolchains, but don't run the relocate-sdk script. In addition, we simply can't do it, because it's directly Buildroot itself that downloads the toolchain tarball and extracts it, so we don't even get the opportunity to run the relocate-sdk script.
Quoted 4 lines
Well, we could run the script directly for downloaded toolchains, and do the
check for pre-installed toolchains. Does that sound acceptable?I'm probably forgetting something though :-)
In fact, I wonder why this check is necessary at all, for the use case of an external toolchain. Indeed, an external toolchain is really a very minimal SDK, with just gcc/binutils/gdb/libc. And there is nothing that relocate-sdk will relocate in such a simple SDK: SDKs that are just toolchains are relocatable by design, with no fixup needed.
The relocate-sdk is useful when you start having more stuff in the SDK, with libtool files and other weird things that hardcore paths. But that's not the case for the SDK-is-just-a-toolchain case.
Therefore, I would suggest to simply drop this check.
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
Am 21.07.2017 um 08:36 schrieb Thomas Petazzoni:
Quoted 27 lines
Hello,
Quoted 12 lines · Arnout Vandecappelle
Quoted 11 lines
Now that I think of it, this is going to be a bit annoying. This means that whenever you want to use a Buildroot-generated toolchain as an external toolchain in another Buildroot configuration, you have to run this relocate script.
This will break a lot of things, like the autobuilders, the runtime test infrastructure, etc. that all rely on pre-built Buildroot toolchains, but don't run the relocate-sdk script. In addition, we simply can't do it, because it's directly Buildroot itself that downloads the toolchain tarball and extracts it, so we don't even get the opportunity to run the relocate-sdk script.
Quoted 4 lines
Well, we could run the script directly for downloaded toolchains, and do the
check for pre-installed toolchains. Does that sound acceptable?I'm probably forgetting something though :-)
In fact, I wonder why this check is necessary at all, for the use case of an external toolchain. Indeed, an external toolchain is really a very minimal SDK, with just gcc/binutils/gdb/libc. And there is nothing that relocate-sdk will relocate in such a simple SDK: SDKs that are just toolchains are relocatable by design, with no fixup needed.
Quoted 3 lines
The relocate-sdk is useful when you start having more stuff in the SDK, with libtool files and other weird things that hardcore paths. But that's not the case for the SDK-is-just-a-toolchain case.
Yes.
Quoted 1 line
Therefore, I would suggest to simply drop this check.
If you make a toolchain with "make toolchain" the check will not harm. If it's created with "make sdk" it will do the check because "share/buildroot/sdk-location" does exist. "make sdk" will never create just the toolchain.
Wolfgang.
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
Hello,
Quoted 6 lines · Wolfgang Grandegger
Quoted 1 line
Therefore, I would suggest to simply drop this check.
If you make a toolchain with "make toolchain" the check will not harm. If it's created with "make sdk" it will do the check because "share/buildroot/sdk-location" does exist. "make sdk" will never create just the toolchain.
"make sdk" will definitely create just the toolchain if what you have in your configuration is... just the toolchain, which is exactly how I build Buildroot toolchains, such as the ones used by the autobuilders or on toolchains.free-electrons.com.
Doing "make toolchain" doesn't work for this use case, because you definitely want the RPATH sanitization of host binaries done in "make sdk".
Again, I think this additional check in the external toolchain code is useless. For a SDK to be usable as an external toolchain, it has to be a SDK that contains *just* a toolchain and *nothing* else. If its sysroot is polluted with additional libraries than the C library, it cannot be used as an external toolchain. And therefore, the relocate-sdk procedure is useless, because there's nothing to relocate in an SDK that is just a toolchain.
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
Am 21.07.2017 um 09:24 schrieb Thomas Petazzoni:
Quoted 20 lines
Hello,
Quoted 6 lines · Wolfgang Grandegger
Quoted 1 line
Therefore, I would suggest to simply drop this check.
If you make a toolchain with "make toolchain" the check will not harm. If it's created with "make sdk" it will do the check because "share/buildroot/sdk-location" does exist. "make sdk" will never create just the toolchain.
"make sdk" will definitely create just the toolchain if what you have in your configuration is... just the toolchain, which is exactly how I build Buildroot toolchains, such as the ones used by the autobuilders or on toolchains.free-electrons.com.
Doing "make toolchain" doesn't work for this use case, because you definitely want the RPATH sanitization of host binaries done in "make sdk".
Quoted 7 lines
Again, I think this additional check in the external toolchain code is useless. For a SDK to be usable as an external toolchain, it has to be a SDK that contains *just* a toolchain and *nothing* else. If its sysroot is polluted with additional libraries than the C library, it cannot be used as an external toolchain. And therefore, the relocate-sdk procedure is useless, because there's nothing to relocate in an SDK that is just a toolchain.
OK. I see. Then I will drop this patch.
Wolfgang.
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
Hello,
Quoted 17 lines · Wolfgang Grandegger
Quoted 9 lines
"make sdk" will definitely create just the toolchain if what you have in your configuration is... just the toolchain, which is exactly how I build Buildroot toolchains, such as the ones used by the autobuilders or on toolchains.free-electrons.com.
Doing "make toolchain" doesn't work for this use case, because you definitely want the RPATH sanitization of host binaries done in "make sdk".
Quoted 7 lines
Again, I think this additional check in the external toolchain code is useless. For a SDK to be usable as an external toolchain, it has to be a SDK that contains *just* a toolchain and *nothing* else. If its sysroot is polluted with additional libraries than the C library, it cannot be used as an external toolchain. And therefore, the relocate-sdk procedure is useless, because there's nothing to relocate in an SDK that is just a toolchain.
Quoted 1 line
OK. I see. Then I will drop this patch.
Let's see if Arnout agrees with my reasoning. Quite often he points me at details I have missed :-)
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
On 21-07-17 10:05, Thomas Petazzoni wrote:
[snip]
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
For a SDK to be usable as an external toolchain, it has to be a SDK that contains *just* a toolchain and *nothing* else. If its sysroot is polluted with additional libraries than the C library, it cannot be used as an external toolchain.
This is not true. I already regularly use a Buildroot SDK in projects by
setting BR2_HOST_DIR=/opt/... and packaging that. This SDK is then used to create a rootfs+kernel with Buildroot, and separately to build applications. Since the applications need some additional libraries, these libraries are included in the SDK. They are not used by Buildroot, so it's double work (they are included in the SDK, and built again for the target rootfs).
Admittedly it's not perfect, but it works. At least, as long as you don't go
and update Buildroot (thus putting new versions of the libraries on the target) without updating the SDK as well.
However...
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
And therefore, the
relocate-sdk procedure is useless, because there's nothing to relocate in an SDK that is just a toolchain.OK. I see. Then I will drop this patch.
Let's see if Arnout agrees with my reasoning. Quite often he points me at details I have missed :-)
relocate-sdk is still useless when using it as an external toolchain. You could
say it makes sense for a pre-installed toolchain, but then only if you're using that SDK outside of Buildroot. Buildroot is not going to use any of the additional stuff.
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
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
Hello,
Quoted 6 lines · Arnout Vandecappelle
This is not true. I already regularly use a Buildroot SDK in projects by
setting BR2_HOST_DIR=/opt/... and packaging that. This SDK is then used to create a rootfs+kernel with Buildroot, and separately to build applications. Since the applications need some additional libraries, these libraries are included in the SDK. They are not used by Buildroot, so it's double work (they are included in the SDK, and built again for the target rootfs).
This is really horrible, because it means that some libraries that Buildroot doesn't know about may be present in the toolchain sysroot, be detected by packages, etc.
Quoted 12 lines
Admittedly it's not perfect, but it works. At least, as long as you don't go
and update Buildroot (thus putting new versions of the libraries on the target) without updating the SDK as well.However...
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
And therefore, the
relocate-sdk procedure is useless, because there's nothing to relocate in an SDK that is just a toolchain.OK. I see. Then I will drop this patch.
Quoted 7 lines
Quoted 2 lines
Let's see if Arnout agrees with my reasoning. Quite often he points me at details I have missed :-)
relocate-sdk is still useless when using it as an external toolchain. You could
say it makes sense for a pre-installed toolchain, but then only if you're using that SDK outside of Buildroot. Buildroot is not going to use any of the additional stuff.
Sorry, but I did not understand this paragraph :/
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v8 8/10 external-toolchain: check if a buildroot SDK has already been relocated
Quoted 11 lines · Thomas Petazzoni
Hello,
Quoted 6 lines · Arnout Vandecappelle
This is not true. I already regularly use a Buildroot SDK in projects by
setting BR2_HOST_DIR=/opt/... and packaging that. This SDK is then used to create a rootfs+kernel with Buildroot, and separately to build applications. Since the applications need some additional libraries, these libraries are included in the SDK. They are not used by Buildroot, so it's double work (they are included in the SDK, and built again for the target rootfs).
Quoted 3 lines
This is really horrible, because it means that some libraries that Buildroot doesn't know about may be present in the toolchain sysroot, be detected by packages, etc.
No it doesn't. Buildroot doesn't use the external toolchain as-is; the relevant
files are copied to STAGING_DIR. Only the gcc related includes are still used from HOST_DIR/opt/ext-toolchain. Just do a gcc -v link and you'll see.
[snip]
Quoted 6 lines
Quoted 4 lines
relocate-sdk is still useless when using it as an external toolchain. You could
say it makes sense for a pre-installed toolchain, but then only if you're using that SDK outside of Buildroot. Buildroot is not going to use any of the additional stuff.Sorry, but I did not understand this paragraph :/
Since Buildroot doesn't use anything from HOSTDIR/opt/ext-toolchain,
"relocating" it isn't relevant.
Bottom line: indeed this patch should be dropped.
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
PATCH v8 9/10 core: install relocation script and location to make a relocatable SDK
In reply to Wolfgang GrandeggerThe script "relocate-sdk.sh" is installed into the top directory of the SDK (HOST_DIR) and the SDK location path is stored in the file "HOST_DIR/share/buildroot/sdk-location"-
--- Makefile | 2 ++ 1 file changed, 2 insertions(+)
Makefile +2 -0
@@ -558,6 +558,8 @@ sdk: toolchain $(PACKAGES) $(TOPDIR)/support/scripts/fix-rpath host @$(call MESSAGE,"Sanitizing RPATH in staging tree") $(TOPDIR)/support/scripts/fix-rpath staging + install $(TOPDIR)/support/misc/relocate-sdk.sh $(HOST_DIR) + echo $(HOST_DIR) > $(HOST_DIR)/share/buildroot/sdk-location # Compatibility symlink in case a post-build script still uses $(HOST_DIR)/usr $(HOST_DIR)/usr: $(HOST_DIR)
Signature · 1 line
2.7.4
PATCH v8 10/10 package/qt5base: provide "qt.conf" to make "qmake" relocatable
In reply to Wolfgang GrandeggerThe file "qt.conf" can be used to override the hard-coded paths that are compiled into the Qt library. This is required to make "qmake" relocatable. Actually, we need to specify all variables to overwrite the compiled in values.
--- package/qt5/qt5base/qt.conf.in | 19 +++++++++++++++++++ package/qt5/qt5base/qt5base.mk | 8 ++++++++ 2 files changed, 27 insertions(+) create mode 100644 package/qt5/qt5base/qt.conf.in
package/qt5/qt5base/qt.conf.in new file +19 -0
@@ -0,0 +1,19 @@ +[Paths] +Prefix=@@HOST_DIR@@ +Sysroot=@@STAGING_DIR@@ +Headers=/usr/include/qt5 +Libraries=/usr/lib +LibraryExecutables=/usr/libexec +Binaries=/usr/bin +Plugins=/usr/lib/qt/plugins +Examples=/usr/lib/qt/examples +Qml2Imports=/usr/qml +Imports=/usr/imports +Translations=/usr/translations +Examples=/usr/lib/qt/examples +Demos=/usr/lib/qt/examples +Tests=/usr/tests +Settings=/usr +Documentation=/usr/doc +ArchData=/usr +Data=/usr
package/qt5/qt5base/qt5base.mk +8 -0
@@ -264,9 +264,17 @@ define QT5BASE_BUILD_CMDS $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) endef +# The file "qt.conf" can be used to override the hard-coded paths that are +# compiled into the Qt library. We need it to make "qmake" relocatable. +define QT5BASE_INSTALL_QT_CONF + sed -e "s|@@HOST_DIR@@|$(HOST_DIR)|" -e "s|@@STAGING_DIR@@|$(STAGING_DIR)|" \ + $(QT5BASE_PKGDIR)/qt.conf.in > $(HOST_DIR)/bin/qt.conf +endef + define QT5BASE_INSTALL_STAGING_CMDS $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) install $(QT5_LA_PRL_FILES_FIXUP) + $(QT5BASE_INSTALL_QT_CONF) endef define QT5BASE_INSTALL_TARGET_LIBS
Signature · 1 line
2.7.4
Thomas Petazzoni
AppliedPATCH v8 10/10 package/qt5base: provide "qt.conf" to make "qmake" relocatable
Hello,
Quoted 5 lines · Wolfgang Grandegger
The file "qt.conf" can be used to override the hard-coded paths that are compiled into the Qt library. This is required to make "qmake" relocatable. Actually, we need to specify all variables to overwrite the compiled in values.
Quoted 8 lines
CC Julien Corjon <[email protected]>CC Peter Seiderer <[email protected]>Signed-off-by Wolfgang Grandegger <[email protected]>--- package/qt5/qt5base/qt.conf.in | 19 +++++++++++++++++++ package/qt5/qt5base/qt5base.mk | 8 ++++++++ 2 files changed, 27 insertions(+) create mode 100644 package/qt5/qt5base/qt.conf.in
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com