1From fe21cede3939a435d62efbd5799547fab6af1b0a Mon Sep 17 00:00:00 2001 2From: Romain Naour <romain.naour@smile.fr> 3Date: Mon, 5 Aug 2019 16:06:48 +0200 4Subject: [PATCH] lib/Driver/ToolChains/Gnu: Use GCC_INSTALL_PREFIX in the set 5 of prefixes for searching the gcc toolchain 6 7By default, the Gnu Toolchains driver is looking at the parent 8directory while looking for the gcc toolchain when clang is installed 9at "D.InstalledDir" 10 11But this doesn't work with Buildroot since the external 12toolchain is installed in host/opt/ext-toolchain and the sysroot is 13moved to host/<arch>-buildroot-linux-gnu/sysroot/ directory. 14 15We tried by setting GCC_INSTALL_PREFIX in clang.mk for host-clang 16but it doesn't work since we already provide a sysroot [1]. 17 18Help the Gnu Toolchains driver by using GCC_INSTALL_PREFIX path. 19 20Since we want to be able to relocate the clang toolchain, 21allow to use a relative path with GCC_INSTALL_PREFIX. 22 23Buildroot will provide such relative path by using: 24HOST_CLANG_CONF_OPTS += -DGCC_INSTALL_PREFIX:PATH=`realpath --relative-to=$(HOST_DIR)/bin/ $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)` 25 26Doing so allow to use clang without providing additional search 27paths with -B option on the clang's command line. 28 29[1] https://reviews.llvm.org/D49244 30[2] http://lists.busybox.net/pipermail/buildroot/2019-August/256204.html 31 32Signed-off-by: Romain Naour <romain.naour@smile.fr> 33Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com> 34--- 35Pending, access to llvm mailing lists to submit it is pending. They 36seem to be having issues with their listserv. 37--- 38 lib/Driver/ToolChains/Gnu.cpp | 17 +++++++++++++++++ 39 1 file changed, 17 insertions(+) 40 41diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp 42index 2ad45097dc..90d6b5b748 100644 43--- a/lib/Driver/ToolChains/Gnu.cpp 44+++ b/lib/Driver/ToolChains/Gnu.cpp 45@@ -1725,6 +1725,8 @@ void Generic_GCC::GCCInstallationDetector::init( 46 47 Prefixes.push_back(GCCToolchainDir); 48 } else { 49+ StringRef GccIinstallPrefix = GCC_INSTALL_PREFIX; 50+ 51 // If we have a SysRoot, try that first. 52 if (!D.SysRoot.empty()) { 53 Prefixes.push_back(D.SysRoot); 54@@ -1734,6 +1736,21 @@ void Generic_GCC::GCCInstallationDetector::init( 55 // Then look for gcc installed alongside clang. 56 Prefixes.push_back(D.InstalledDir + "/.."); 57 58+ // Use GCC_INSTALL_PREFIX if provided by the buildsystem. 59+ if (!GccIinstallPrefix.empty()) 60+ { 61+ if (llvm::sys::path::is_relative(GccIinstallPrefix)) 62+ { 63+ // Use a relative path to gcc from clang install path. 64+ Prefixes.push_back(D.InstalledDir + "/" + GccIinstallPrefix.str()); 65+ } 66+ else 67+ { 68+ // Hardcode the absolute path provided by GCC_INSTALL_PREFIX. 69+ Prefixes.push_back(GCC_INSTALL_PREFIX); 70+ } 71+ } 72+ 73 // Next, look for prefix(es) that correspond to distribution-supplied gcc 74 // installations. 75 if (D.SysRoot.empty()) { 76-- 772.20.1 78 79