Skip to content

Commit 81fa4f4

Browse files
committed
clang: Define / releative gcc installation dir
This is required for OE gcc installation to work. Without this its not able to find the paths for libgcc and other standard headers and libraries from gcc installation in OE * Do not use install relative libc++ headers In OE we use same clang for native and cross builds, therefore we need to ensure that native sysroot install of libc++ is not searched for headers when doing cross compile instead it searches the target sysroot this is especially troublesome when libcxx-native is staged along with libcxx e.g. chromium * Fix lib paths for OpenEmbedded Host Under OpenEmbedded Host, while building with clang-native, it cannot find the GCCInstallPath, which causing following error: [snip] compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin/clang -target x86_64-linux -isystem/path/to/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/include -O2 -pipe /path/to/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/share/cmake-3.21/Modules/CMakeCCompilerABI.c` hosttools/ld: cannot find crtbeginS.o: No such file or directory [snip] Before this patch: compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin/clang clang version 13.0.1 (https://github.com/llvm/llvm-project 08e3a5c) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /build/tmp-glibc/work/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-wrs-linux/10.2.0 After this patch: compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin/clang clang version 13.0.1 (https://github.com/llvm/llvm-project 08e3a5c) Thread model: posix InstalledDir: /build/tmp-glibc/work/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-wrs-linux/10.2.0 Found candidate GCC installation: /usr/lib/x86_64-wrs-linux/10.2.0 Selected GCC installation: /usr/lib/x86_64-wrs-linux/10.2.0 Candidate multilib: .;@m64 Selected multilib: .;@m64 For OpenEmbedded Host, sysroots are of the form<sysroot>/usr/lib/<triple>/x.y.z. Take x86-64 as example, the default triple is x86_64-unknown-linux-gnu. For clang-native, the target vendor is '-unknown', need to test current distro to follow above form. Upstream-Status: Inappropriate [oe specific] Signed-off-by: Changqing Li <[email protected]> Signed-off-by: Khem Raj <[email protected]>
1 parent 16fc449 commit 81fa4f4

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Config/config.h" // for GCC_INSTALL_PREFIX
1919
#include "clang/Driver/CommonArgs.h"
2020
#include "clang/Driver/Compilation.h"
21+
#include "clang/Driver/Distro.h"
2122
#include "clang/Driver/Driver.h"
2223
#include "clang/Driver/MultilibBuilder.h"
2324
#include "clang/Driver/Tool.h"
@@ -2832,6 +2833,7 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
28322833
const llvm::Triple &TargetTriple, const ArgList &Args,
28332834
const std::string &LibDir, StringRef CandidateTriple,
28342835
bool NeedsBiarchSuffix, bool GCCDirExists, bool GCCCrossDirExists) {
2836+
Distro Distro(D.getVFS(), TargetTriple);
28352837
// Locations relative to the system lib directory where GCC's triple-specific
28362838
// directories might reside.
28372839
struct GCCLibSuffix {
@@ -2843,19 +2845,20 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
28432845
// Whether this library suffix is relevant for the triple.
28442846
bool Active;
28452847
} Suffixes[] = {
2846-
// This is the normal place.
2847-
{"gcc/" + CandidateTriple.str(), "../..", GCCDirExists},
2848-
2849-
// Debian puts cross-compilers in gcc-cross.
2850-
{"gcc-cross/" + CandidateTriple.str(), "../..", GCCCrossDirExists},
2851-
28522848
// The Freescale PPC SDK has the gcc libraries in
28532849
// <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. Only do
28542850
// this on Freescale triples, though, since some systems put a *lot* of
28552851
// files in that location, not just GCC installation data.
28562852
{CandidateTriple.str(), "..",
28572853
TargetTriple.getVendor() == llvm::Triple::Freescale ||
2858-
TargetTriple.getVendor() == llvm::Triple::OpenEmbedded}};
2854+
TargetTriple.getVendor() == llvm::Triple::OpenEmbedded ||
2855+
Distro.IsOpenEmbedded()},
2856+
2857+
// This is the normal place.
2858+
{"gcc/" + CandidateTriple.str(), "../..", GCCDirExists},
2859+
2860+
// Debian puts cross-compilers in gcc-cross.
2861+
{"gcc-cross/" + CandidateTriple.str(), "../..", GCCCrossDirExists}};
28592862

28602863
SmallVector<GCCInstallCandidate, 3> Installations;
28612864
for (auto &Suffix : Suffixes) {
@@ -3258,8 +3261,11 @@ Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
32583261
// incompatible with the NDK libraries.
32593262
SmallString<128> DriverIncludeDir(getDriver().Dir);
32603263
llvm::sys::path::append(DriverIncludeDir, "..", "include");
3264+
3265+
// do not add it when --sysroot is specified, since it would expect
3266+
// libc++ headers from sysroot and not relative to compiler install location
32613267
if (AddIncludePath(DriverIncludeDir,
3262-
/*TargetDirRequired=*/getTriple().isAndroid()))
3268+
/*TargetDirRequired=*/getTriple().isAndroid() | !computeSysRoot().empty()))
32633269
return;
32643270
// If this is a development, non-installed, clang, libcxx will
32653271
// not be found at ../include/c++ but it likely to be found at

0 commit comments

Comments
 (0)