[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-03-24 Thread Garvit Gupta via cfe-commits

https://github.com/quic-garvgupt updated 
https://github.com/llvm/llvm-project/pull/121829

>From e07a4cd4e0ff77f74b66695923bc998904c14746 Mon Sep 17 00:00:00 2001
From: Garvit Gupta 
Date: Fri, 13 Dec 2024 05:31:56 -0800
Subject: [PATCH] [Driver] Teach Barmetal toolchain about GCC installation

This patch introduces the baretmetal toolchain object about GCC Installation.
Currently, if `--gcc-installation` ot `--gcc-install-dir` options are passed on
commandline, then sysroot will be formed from there if paths will be valid.
Otherwise, it will be fallback to as it already existed in the Baremetal
toolchaibn object. Moreover, support for adding include paths for libstd
C++ library is added as well.

Additionally, the restriction to always use integrated assembler is removed
because with valid gcc installation, gnu assembler can be invoked as well.

This patch currently adds and modifies arm related test only. The riscv specific
test will be added in the last PR when driver code related to calling of
RISCVToolchain object will be removed. Currently in this PR, there is no way to
test riscv target.

RFC:
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

Change-Id: Ibaeb569cf7e2cee03c022aa9ecd1abe29d5c30d4
---
 clang/lib/Driver/ToolChains/BareMetal.cpp | 130 ++
 clang/lib/Driver/ToolChains/BareMetal.h   |  14 +-
 .../aarch64-none-elf/include/c++/8.2.1/.keep  |   0
 .../aarch64-none-elf/lib/.keep|   0
 .../aarch64-none-elf/lib/crt0.o   |   0
 .../bin/aarch64-none-elf-ld   |   1 +
 .../lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o |   0
 .../lib/gcc/aarch64-none-elf/8.2.1/crtend.o   |   0
 .../aarch64-none-elf/lib/crt0.o   |   0
 .../aarch64-none-elf/lib/crtbegin.o   |   0
 .../aarch64-none-elf/lib/crtend.o |   0
 .../bin/aarch64-none-elf-ld   |   1 +
 .../armv6m-none-eabi/include/c++/8.2.1/.keep  |   0
 .../armv6m-none-eabi/lib/.keep|   0
 .../armv6m-none-eabi/lib/crt0.o   |   0
 .../bin/armv6m-none-eabi-ld   |   1 +
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o |   0
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtend.o   |   0
 .../armv6m-none-eabi/lib/crt0.o   |   0
 .../armv6m-none-eabi/lib/crtbegin.o   |   0
 .../armv6m-none-eabi/lib/crtend.o |   0
 .../bin/armv6m-none-eabi-ld   |   1 +
 clang/test/Driver/aarch64-toolchain-extra.c   |  28 
 clang/test/Driver/aarch64-toolchain.c |  61 
 clang/test/Driver/arm-gnutools.c  |  12 ++
 clang/test/Driver/arm-toolchain-extra.c   |  29 
 clang/test/Driver/arm-toolchain.c |  62 +
 clang/test/Driver/baremetal.cpp   |  16 +++
 28 files changed, 324 insertions(+), 32 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include/c++/8.2.1/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/crt0.o
 create mode 100755 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/bin/aarch64-none-elf-ld
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crt0.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtend.o
 create mode 100755 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/bin/aarch64-none-elf-ld
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/include/c++/8.2.1/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/crt0.o
 create mode 100755 
clang/test/Driver/Inputs/basic_arm_gcc_tree/bin/armv6m-none-eabi-ld
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crt0.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtend.o
 create mode 100755 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/bin/armv6m-none-eabi-ld
 create mode 100644 clang/test/Driver/aarch64-toolchain-extra.c
 create mode 100644 clang/test/Driver/aarch64-toolchain.c
 create mode 100644 clan

[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-03-11 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

Hi @petrhosek, I've addressed all your comments. Please review the changes and 
approve the PR if everything looks good.

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-03-11 Thread Garvit Gupta via cfe-commits

https://github.com/quic-garvgupt updated 
https://github.com/llvm/llvm-project/pull/121829

>From 9bb78235d2ba008dc49dc4746edbd9978a92396b Mon Sep 17 00:00:00 2001
From: Garvit Gupta 
Date: Fri, 13 Dec 2024 05:31:56 -0800
Subject: [PATCH] [RISCV] Teach Barmetal toolchain about GCC installation(1/3)

This patch introduces the baretmetal toolchain object about GCC Installation.
Currently, if `--gcc-installation` ot `--gcc-install-dir` options are passed on
commandline, then sysroot will be formed from there if paths will be valid.
Otherwise, it will be fallback to as it already existed in the Baremetal
toolchaibn object.

Additionally, the restriction to always use integrated assembler is removed
because with valid gcc installation, gnu assembler can be invoked as well.

This patch currently adds and modifies arm related test only. The riscv specific
test will be added in the last PR when driver code related to calling of
RISCVToolchain object will be removed. Currently in this PR, there is no way to
test riscv target.

This is the first PR in the series of 3 PRs for merging and extending Baremetal
toolchain object. The division of the PRs is as follows:
- Teach Baremetal toolchain about GCC installation and make sysroot and 
assembler
  related changes.
- Changes related to linker job and defaults for CXXStdlib and other runtime 
libs.
- Finally removing the call to RISCVToolchain object.

The above division will also ensure that riscv and arm specific tests are not
modified in the same PR.

RFC: 
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

Change-Id: Ibaeb569cf7e2cee03c022aa9ecd1abe29d5c30d4
---
 clang/lib/Driver/ToolChains/BareMetal.cpp | 97 ---
 clang/lib/Driver/ToolChains/BareMetal.h   | 13 ++-
 .../aarch64-none-elf/bin/ld   |  1 +
 .../aarch64-none-elf/include/c++/8.2.1/.keep  |  0
 .../aarch64-none-elf/lib/.keep|  0
 .../aarch64-none-elf/lib/crt0.o   |  0
 .../lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o |  0
 .../lib/gcc/aarch64-none-elf/8.2.1/crtend.o   |  0
 .../aarch64-none-elf/bin/ld   |  1 +
 .../aarch64-none-elf/lib/.keep|  0
 .../aarch64-none-elf/lib/crt0.o   |  0
 .../aarch64-none-elf/lib/crtbegin.o   |  0
 .../aarch64-none-elf/lib/crtend.o |  0
 .../armv6m-none-eabi/bin/ld   |  1 +
 .../armv6m-none-eabi/include/c++/8.2.1/.keep  |  0
 .../armv6m-none-eabi/lib/.keep|  0
 .../armv6m-none-eabi/lib/crt0.o   |  0
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o |  0
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtend.o   |  0
 .../armv6m-none-eabi/bin/ld   |  1 +
 .../armv6m-none-eabi/lib/.keep|  0
 .../armv6m-none-eabi/lib/crt0.o   |  0
 .../armv6m-none-eabi/lib/crtbegin.o   |  0
 .../armv6m-none-eabi/lib/crtend.o |  0
 clang/test/Driver/aarch64-toolchain-extra.c   | 28 ++
 clang/test/Driver/aarch64-toolchain.c | 61 
 clang/test/Driver/arm-gnutools.c  | 12 +++
 clang/test/Driver/arm-toolchain-extra.c   | 29 ++
 clang/test/Driver/arm-toolchain.c | 62 
 clang/test/Driver/baremetal.cpp   | 16 +++
 30 files changed, 304 insertions(+), 18 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/bin/ld
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include/c++/8.2.1/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/crt0.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/bin/ld
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crt0.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/bin/ld
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/include/c++/8.2.1/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/crt0.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o
 create mode 100644 
clang/test/Driver/Inp

[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-27 Thread Petr Hosek via cfe-commits


@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  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))

petrhosek wrote:

I believe the underlying issue is that BareMetal and RISCVToolchain original 
authors made different choices when it comes to the default sysroot location:

* BareMetal uses the `bin/../lib/clang-runtimes/` directory.
* RISCVToolchain uses the `bin/../` directory.

Unless we deprecate one (or both) of these and force everyone to switch to a 
common one, I don't think we can avoid the directory check.

I'd be in favor of unifying on a single location sooner rather than later even 
if it's going to require a migration for some users. This would be probably 
best discussed in an RFC though.

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-27 Thread Petr Hosek via cfe-commits


@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {

petrhosek wrote:

I'd consider inlining this method into `computeSysRoot`, I think that would 
actually help with readability.

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-27 Thread Petr Hosek via cfe-commits


@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;

petrhosek wrote:

This check shouldn't be necessary.

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-27 Thread Petr Hosek via cfe-commits


@@ -97,7 +97,8 @@ static bool findRISCVMultilibs(const Driver &D,
   return false;
 }
 
-static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
+static std::string computeInstalledToolchainSysRoot(const Driver &D,

petrhosek wrote:

Can we avoid renaming this method? That doesn't seem to be necessary and it 
only creates unnecessary churn.

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-27 Thread Petr Hosek via cfe-commits


@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  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());

petrhosek wrote:

I understand that this is copied as-is from `RISCVToolchain`, but it's quite 
confusing for this to be inside the method called `computeGCCSysroot` when it 
is not in fact a GCC sysroot, it's the sysroot installed alongside Clang.

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-23 Thread Fangrui Song via cfe-commits


@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  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))

MaskRay wrote:

Thanks. If there is commitment to remove the quirks, this looks good to me!

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-23 Thread Garvit Gupta via cfe-commits


@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  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))

quic-garvgupt wrote:

I agree that the condition can be removed if it is actually not needed. Though 
that has to be done as a part of new patch because for now, this patch aims to 
preserve the behavior as it was before. 

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-23 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

It's been a few weeks since this patch was last reviewed. If everything looks 
good, could someone please provide an LGTM? I'd like to merge this patch soon.



https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-04 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-04 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-04 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-04 Thread Fangrui Song via cfe-commits


@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  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))

MaskRay wrote:

This divergence is ok if eventually the condition will be removed. We do want 
to drop this difference in the future...

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-02-04 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

Hi @petrhosek, following up on our last RISC-V embedded sync-up, can you please 
review this patch? Thanks

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-01-29 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

Gentle Ping again!

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-01-20 Thread Garvit Gupta via cfe-commits


@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  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))

quic-garvgupt wrote:

 I understand that. However, to preserve the behavior of both the BareMetal and 
RISCVToolchain objects, I need to maintain this condition. If this returns 
empty, only then does the control transfer to compute the sysroot, as it was 
done previously in the BareMetal toolchain. (See line 152 under 
`BareMetal::computeSysRoot()` function)

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-01-13 Thread Fangrui Song via cfe-commits


@@ -110,20 +111,93 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the
+// command line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  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))

MaskRay wrote:

The `exists` test from RISCVToolChain is not a good idea. The sysroot should 
not be affected whether it is existent or not.

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-01-13 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

Gentle Ping!

https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-01-10 Thread Garvit Gupta via cfe-commits

https://github.com/quic-garvgupt edited 
https://github.com/llvm/llvm-project/pull/121829
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits