Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp =================================================================== --- clang/lib/Driver/ToolChains/RISCVToolchain.cpp +++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp @@ -33,6 +33,8 @@ getFilePaths().push_back(GCCInstallation.getInstallPath().str()); getProgramPaths().push_back( (GCCInstallation.getParentLibPath() + "/../bin").str()); + } else { + getProgramPaths().push_back(D.Dir); } } @@ -74,17 +76,22 @@ if (!getDriver().SysRoot.empty()) return getDriver().SysRoot; - if (!GCCInstallation.isValid()) - return std::string(); - - StringRef LibDir = GCCInstallation.getParentLibPath(); - StringRef TripleStr = GCCInstallation.getTriple().str(); - std::string SysRootDir = LibDir.str() + "/../" + TripleStr.str(); + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { + StringRef LibDir = GCCInstallation.getParentLibPath(); + StringRef TripleStr = GCCInstallation.getTriple().str(); + llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr); + } else { + // Use the triple as provided to the driver. Unlike the parsed triple + // this has not been normalized to always contain every field. + llvm::sys::path::append(SysRootDir, getDriver().Dir, "..", + getDriver().getTargetTriple()); + } if (!llvm::sys::fs::exists(SysRootDir)) return std::string(); - return SysRootDir; + return SysRootDir.str(); } void RISCV::Linker::ConstructJob(Compilation &C, const JobAction &JA, Index: clang/test/Driver/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld =================================================================== --- /dev/null +++ clang/test/Driver/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld @@ -0,0 +1 @@ +#!/bin/true Index: clang/test/Driver/Inputs/basic_riscv64_nogcc_tree/bin/riscv64-unknown-elf-ld =================================================================== --- /dev/null +++ clang/test/Driver/Inputs/basic_riscv64_nogcc_tree/bin/riscv64-unknown-elf-ld @@ -0,0 +1 @@ +#!/bin/true Index: clang/test/Driver/riscv32-toolchain-extra.c =================================================================== --- /dev/null +++ clang/test/Driver/riscv32-toolchain-extra.c @@ -0,0 +1,33 @@ +// A basic clang -cc1 command-line, and simple environment check. + +// The tests here are similar to those in riscv32-toolchain.c, however +// these tests need to create symlinks to test directory trees in order to +// set up the environment and therefore shell support is required. +// REQUIRES: shell +// UNSUPPORTED: system-windows + +// If there is no GCC install detected then the driver searches for executables +// and runtime starting from the directory tree above the driver itself. +// The test below checks that the driver correctly finds the linker and +// runtime if and only if they exist. +// +// RUN: mkdir -p %T/testroot-riscv32-baremetal-nogcc/bin +// RUN: [ ! -s %T/testroot-riscv32-baremetal-nogcc/bin/clang ] || rm %T/testroot-riscv32-baremetal-nogcc/bin/clang +// RUN: [ ! -s %T/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld ] || rm %T/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld +// RUN: [ ! -s %T/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf ] || rm %T/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf +// RUN: ln -s %clang %T/testroot-riscv32-baremetal-nogcc/bin/clang +// RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld %T/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld +// RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/riscv32-unknown-elf %T/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf +// RUN: %T/testroot-riscv32-baremetal-nogcc/bin/clang %s -### -no-canonical-prefixes \ +// RUN: -target riscv32-unknown-elf 2>&1 \ +// RUN: | FileCheck -check-prefix=C-RV32-BAREMETAL-ILP32-NOGCC %s + +// C-RV32-BAREMETAL-ILP32-NOGCC: InstalledDir: [[DRIVERDIR:.*]] +// C-RV32-BAREMETAL-ILP32-NOGCC: "-fuse-init-array" +// C-RV32-BAREMETAL-ILP32-NOGCC: "-internal-isystem" "[[DRIVERDIR]]/../riscv32-unknown-elf/include" +// C-RV32-BAREMETAL-ILP32-NOGCC: "[[DRIVERDIR]]/riscv32-unknown-elf-ld" +// C-RV32-BAREMETAL-ILP32-NOGCC: "[[DRIVERDIR]]/../riscv32-unknown-elf/lib/crt0.o" +// C-RV32-BAREMETAL-ILP32-NOGCC: "[[DRIVERDIR]]/../riscv32-unknown-elf/lib/crtbegin.o" +// C-RV32-BAREMETAL-ILP32-NOGCC: "-L[[DRIVERDIR]]/../riscv32-unknown-elf/lib" +// C-RV32-BAREMETAL-ILP32-NOGCC: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc" +// C-RV32-BAREMETAL-ILP32-NOGCC: "[[DRIVERDIR]]/../riscv32-unknown-elf/lib/crtend.o" Index: clang/test/Driver/riscv64-toolchain-extra.c =================================================================== --- /dev/null +++ clang/test/Driver/riscv64-toolchain-extra.c @@ -0,0 +1,33 @@ +// A basic clang -cc1 command-line, and simple environment check. + +// The tests here are similar to those in riscv64-toolchain.c, however +// these tests need to create symlinks to test directory trees in order to +// set up the environment and therefore shell support is required. +// REQUIRES: shell +// UNSUPPORTED: system-windows + +// If there is no GCC install detected then the driver searches for executables +// and runtime starting from the directory tree above the driver itself. +// The test below checks that the driver correctly finds the linker and +// runtime if and only if they exist. +// +// RUN: mkdir -p %T/testroot-riscv64-baremetal-nogcc/bin +// RUN: [ ! -s %T/testroot-riscv64-baremetal-nogcc/bin/clang ] || rm %T/testroot-riscv64-baremetal-nogcc/bin/clang +// RUN: [ ! -s %T/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld ] || rm %T/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld +// RUN: [ ! -s %T/testroot-riscv64-baremetal-nogcc/riscv64-unknown-elf ] || rm %T/testroot-riscv64-baremetal-nogcc/riscv64-unknown-elf +// RUN: ln -s %clang %T/testroot-riscv64-baremetal-nogcc/bin/clang +// RUN: ln -s %S/Inputs/basic_riscv64_nogcc_tree/bin/riscv64-unknown-elf-ld %T/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld +// RUN: ln -s %S/Inputs/basic_riscv64_nogcc_tree/riscv64-unknown-elf %T/testroot-riscv64-baremetal-nogcc/riscv64-unknown-elf +// RUN: %T/testroot-riscv64-baremetal-nogcc/bin/clang %s -### -no-canonical-prefixes \ +// RUN: -target riscv64-unknown-elf 2>&1 \ +// RUN: | FileCheck -check-prefix=C-RV64-BAREMETAL-LP64-NOGCC %s + +// C-RV64-BAREMETAL-LP64-NOGCC: InstalledDir: [[DRIVERDIR:.*]] +// C-RV64-BAREMETAL-LP64-NOGCC: "-fuse-init-array" +// C-RV64-BAREMETAL-LP64-NOGCC: "-internal-isystem" "[[DRIVERDIR]]/../riscv64-unknown-elf/include" +// C-RV64-BAREMETAL-LP64-NOGCC: "[[DRIVERDIR]]/riscv64-unknown-elf-ld" +// C-RV64-BAREMETAL-LP64-NOGCC: "[[DRIVERDIR]]/../riscv64-unknown-elf/lib/crt0.o" +// C-RV64-BAREMETAL-LP64-NOGCC: "[[DRIVERDIR]]/../riscv64-unknown-elf/lib/crtbegin.o" +// C-RV64-BAREMETAL-LP64-NOGCC: "-L[[DRIVERDIR]]/../riscv64-unknown-elf/lib" +// C-RV64-BAREMETAL-LP64-NOGCC: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc" +// C-RV64-BAREMETAL-LP64-NOGCC: "[[DRIVERDIR]]/../riscv64-unknown-elf/lib/crtend.o"