[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)
quic-garvgupt wrote: Hi @topperc, can you add instruction alias for cflush and cdiscard instructions when the rs1 is X0 to `sf.cflush.d.l1` and `sf.cflush.d.l1` respectively, as this register is optional according to spec? https://github.com/llvm/llvm-project/pull/83896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)
quic-garvgupt wrote: Also, I think we might need to update the extensions in the `RISCVProcessors.td` file under SIFIVE_S76 microcontroller? https://github.com/llvm/llvm-project/pull/83896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)
quic-garvgupt wrote: > > Hi @topperc, can you add instruction alias for cflush and cdiscard > > instructions when the rs1 is X0 to `sf.cflush.d.l1` and `sf.cflush.d.l1` > > respectively, as this register is optional according to spec? > > x0 has special meaning, but the spec never says it is "optional". Possibly I am mistaken here but this is what I inferred from the below text in the mannual - rs1 is optional, so if a user does not specify it then by default it will be X0. Apologies if I am missing something here but just wanted to be clear. >From the mannual - `Opcode 0xFC73, with **optional** rs1 field in bits [19:15]` https://github.com/llvm/llvm-project/pull/83896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)
quic-garvgupt wrote: > > Also, I think we might need to update the extensions in the > > `RISCVProcessors.td` file under SIFIVE_S76 microcontroller? > > This is a M-mode only extension, and we haven't historically been adding M or > S mode extensions to the -mcpu lists. Except for `xiangshan-nanhu` having > `Svinval`. But maybe there's a microcontroller vs application core > distinction we should be making? I see, I was not aware of this. Thanks for your reply https://github.com/llvm/llvm-project/pull/83896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)
quic-garvgupt wrote: Thanks for clearing the confusion around whether rs1 would be optional or not. Can we also add lit tests for the aliases? https://github.com/llvm/llvm-project/pull/83896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1 and cflush.d.l1 instructions. (PR #83896)
quic-garvgupt wrote: Thanks for the prompt reply and latest patchset. 1. Do we need to add documentation in RISCVUsage.rst file for xsfcease? 2. Also, as we are adding cease instruction in this PR, can we rename the PR to include the cease instruction as well? https://github.com/llvm/llvm-project/pull/83896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add back SiFive's cdiscard.d.l1, cflush.d.l1, and cease instructions. (PR #83896)
quic-garvgupt wrote: I believe the patch is ready to be merged now, but since I am not the reviewer here, someone else must approve it as well. Thanks again for the patch! https://github.com/llvm/llvm-project/pull/83896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)
quic-garvgupt wrote: ping! for merging this PR https://github.com/llvm/llvm-project/pull/81727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV ba… (PR #81727)
https://github.com/quic-garvgupt created https://github.com/llvm/llvm-project/pull/81727 The below culprit patch enabled the generation of asynchronous unwind tables (-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain baremetal object. However, since there are 2 baremetal toolchain objects for RISCV, this created a discrepancy between their behavior. Moreover, enabling the generation of asynchronous unwind tables based on whether `-gcc-toolchain` option is present or not doesn't seem to be the best criteria to decide on the same. This patch make the behavior consistent by disabling the unwind tables in RISCVToolChain Baremetal object. Culprit Patch - https://reviews.llvm.org/D145164 >From 42211bccd8ffc60751234ab5695be135ea8b6373 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 14 Feb 2024 03:00:20 -0800 Subject: [PATCH] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal The below culprit patch enabled the generation of asynchronous unwind tables (-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain baremetal object. However, since there are 2 baremetal toolchain objects for RISCV, this created a discrepancy between their behavior. Moreover, enabling the generation of asynchronous unwind tables based on whether `-gcc-toolchain` option is present or not doesn't seem to be the best criteria to decide on the same. Culprit Patch - https://reviews.llvm.org/D145164 --- clang/lib/Driver/ToolChains/RISCVToolchain.cpp | 5 + clang/lib/Driver/ToolChains/RISCVToolchain.h | 2 ++ clang/test/Driver/clang-translation.c | 8 3 files changed, 15 insertions(+) diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp index 85beb945cbf6fc..624099d21ae124 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp @@ -86,6 +86,11 @@ RISCVToolChain::GetUnwindLibType(const llvm::opt::ArgList &Args) const { return ToolChain::UNW_None; } +ToolChain::UnwindTableLevel RISCVToolChain::getDefaultUnwindTableLevel( +const llvm::opt::ArgList &Args) const { + return UnwindTableLevel::None; +} + void RISCVToolChain::addClangTargetOptions( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h b/clang/lib/Driver/ToolChains/RISCVToolchain.h index cec817ef7190be..fa0aa265d842bb 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.h +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h @@ -28,6 +28,8 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public Generic_ELF { RuntimeLibType GetDefaultRuntimeLibType() const override; UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const override; + UnwindTableLevel + getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; diff --git a/clang/test/Driver/clang-translation.c b/clang/test/Driver/clang-translation.c index a7343ea18b2135..64d55f1b88ea6d 100644 --- a/clang/test/Driver/clang-translation.c +++ b/clang/test/Driver/clang-translation.c @@ -421,3 +421,11 @@ // MIPSN32R6EL: "-target-cpu" "mips64r6" // MIPSN32R6EL: "-target-abi" "n32" // MIPSN32R6EL: "-mfloat-abi" "hard" + +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// +// UWTABLE: "-funwind-tables=2" +// NOUWTABLE-NOT: "-funwind-tables=2" \ No newline at end of file ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV ba… (PR #81727)
quic-garvgupt wrote: Hi @jonathonpenix @apazos @kito-cheng @asb @MaskRay - Requesting for adding as reviewers to review the PR. Thanks in advance! https://github.com/llvm/llvm-project/pull/81727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)
quic-garvgupt wrote: Hi @asb, since Petr already gave a good-ahead to this patch in the meeting, let me know if we can merge this PR if there are no new changes need to be made https://github.com/llvm/llvm-project/pull/81727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/81727 >From 42211bccd8ffc60751234ab5695be135ea8b6373 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 14 Feb 2024 03:00:20 -0800 Subject: [PATCH 1/2] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal The below culprit patch enabled the generation of asynchronous unwind tables (-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain baremetal object. However, since there are 2 baremetal toolchain objects for RISCV, this created a discrepancy between their behavior. Moreover, enabling the generation of asynchronous unwind tables based on whether `-gcc-toolchain` option is present or not doesn't seem to be the best criteria to decide on the same. Culprit Patch - https://reviews.llvm.org/D145164 --- clang/lib/Driver/ToolChains/RISCVToolchain.cpp | 5 + clang/lib/Driver/ToolChains/RISCVToolchain.h | 2 ++ clang/test/Driver/clang-translation.c | 8 3 files changed, 15 insertions(+) diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp index 85beb945cbf6fc..624099d21ae124 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp @@ -86,6 +86,11 @@ RISCVToolChain::GetUnwindLibType(const llvm::opt::ArgList &Args) const { return ToolChain::UNW_None; } +ToolChain::UnwindTableLevel RISCVToolChain::getDefaultUnwindTableLevel( +const llvm::opt::ArgList &Args) const { + return UnwindTableLevel::None; +} + void RISCVToolChain::addClangTargetOptions( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h b/clang/lib/Driver/ToolChains/RISCVToolchain.h index cec817ef7190be..fa0aa265d842bb 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.h +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h @@ -28,6 +28,8 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public Generic_ELF { RuntimeLibType GetDefaultRuntimeLibType() const override; UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const override; + UnwindTableLevel + getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; diff --git a/clang/test/Driver/clang-translation.c b/clang/test/Driver/clang-translation.c index a7343ea18b2135..64d55f1b88ea6d 100644 --- a/clang/test/Driver/clang-translation.c +++ b/clang/test/Driver/clang-translation.c @@ -421,3 +421,11 @@ // MIPSN32R6EL: "-target-cpu" "mips64r6" // MIPSN32R6EL: "-target-abi" "n32" // MIPSN32R6EL: "-mfloat-abi" "hard" + +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// +// UWTABLE: "-funwind-tables=2" +// NOUWTABLE-NOT: "-funwind-tables=2" \ No newline at end of file >From 559f1d6e4221dc94cd035c0f568dea630dcb6f37 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 14 Feb 2024 03:00:20 -0800 Subject: [PATCH 2/2] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal The below culprit patch enabled the generation of asynchronous unwind tables (-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain baremetal object. However, since there are 2 baremetal toolchain objects for RISCV, this created a discrepancy between their behavior. Moreover, enabling the generation of asynchronous unwind tables based on whether `-gcc-toolchain` option is present or not doesn't seem to be the best criteria to decide on the same. Culprit Patch - https://reviews.llvm.org/D145164 --- clang/test/Driver/riscv-features.c | 8 1 file changed, 8 insertions(+) diff --git a/clang/test/Driver/riscv-features.c b/clang/test/Driver/riscv-features.c index d3700f71aa7e1d..15832e79d2a491 100644 --- a/clang/test/Driver/riscv-features.c +++ b/clang/test/Driver/riscv-features.c @@ -35,6 +35,14 @@ // FAST-UNALIGNED-ACCESS: "-target-feature" "+fast-unaligned-access" // NO-FAST-UNALIGNED-ACCESS: "-target-feature" "-fast-unaligned-access" +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -#
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/81727 >From 42211bccd8ffc60751234ab5695be135ea8b6373 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 14 Feb 2024 03:00:20 -0800 Subject: [PATCH] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal The below culprit patch enabled the generation of asynchronous unwind tables (-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain baremetal object. However, since there are 2 baremetal toolchain objects for RISCV, this created a discrepancy between their behavior. Moreover, enabling the generation of asynchronous unwind tables based on whether `-gcc-toolchain` option is present or not doesn't seem to be the best criteria to decide on the same. Culprit Patch - https://reviews.llvm.org/D145164 --- clang/lib/Driver/ToolChains/RISCVToolchain.cpp | 5 + clang/lib/Driver/ToolChains/RISCVToolchain.h | 2 ++ clang/test/Driver/clang-translation.c | 8 3 files changed, 15 insertions(+) diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp index 85beb945cbf6fc..624099d21ae124 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp @@ -86,6 +86,11 @@ RISCVToolChain::GetUnwindLibType(const llvm::opt::ArgList &Args) const { return ToolChain::UNW_None; } +ToolChain::UnwindTableLevel RISCVToolChain::getDefaultUnwindTableLevel( +const llvm::opt::ArgList &Args) const { + return UnwindTableLevel::None; +} + void RISCVToolChain::addClangTargetOptions( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h b/clang/lib/Driver/ToolChains/RISCVToolchain.h index cec817ef7190be..fa0aa265d842bb 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.h +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h @@ -28,6 +28,8 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public Generic_ELF { RuntimeLibType GetDefaultRuntimeLibType() const override; UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const override; + UnwindTableLevel + getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; diff --git a/clang/test/Driver/clang-translation.c b/clang/test/Driver/clang-translation.c index a7343ea18b2135..64d55f1b88ea6d 100644 --- a/clang/test/Driver/clang-translation.c +++ b/clang/test/Driver/clang-translation.c @@ -421,3 +421,11 @@ // MIPSN32R6EL: "-target-cpu" "mips64r6" // MIPSN32R6EL: "-target-abi" "n32" // MIPSN32R6EL: "-mfloat-abi" "hard" + +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// +// UWTABLE: "-funwind-tables=2" +// NOUWTABLE-NOT: "-funwind-tables=2" \ No newline at end of file ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/81727 >From 8cc7535ed4c05d4cf14cdedc26077eccf06c8d53 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 14 Feb 2024 03:00:20 -0800 Subject: [PATCH] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal The below culprit patch enabled the generation of asynchronous unwind tables (-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain baremetal object. However, since there are 2 baremetal toolchain objects for RISCV, this created a discrepancy between their behavior. Moreover, enabling the generation of asynchronous unwind tables based on whether `-gcc-toolchain` option is present or not doesn't seem to be the best criteria to decide on the same. Culprit Patch - https://reviews.llvm.org/D145164 --- clang/lib/Driver/ToolChains/RISCVToolchain.cpp | 5 + clang/lib/Driver/ToolChains/RISCVToolchain.h | 2 ++ clang/test/Driver/riscv-features.c | 8 3 files changed, 15 insertions(+) diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp index 85beb945cbf6fc..624099d21ae124 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp @@ -86,6 +86,11 @@ RISCVToolChain::GetUnwindLibType(const llvm::opt::ArgList &Args) const { return ToolChain::UNW_None; } +ToolChain::UnwindTableLevel RISCVToolChain::getDefaultUnwindTableLevel( +const llvm::opt::ArgList &Args) const { + return UnwindTableLevel::None; +} + void RISCVToolChain::addClangTargetOptions( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h b/clang/lib/Driver/ToolChains/RISCVToolchain.h index cec817ef7190be..fa0aa265d842bb 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.h +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h @@ -28,6 +28,8 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public Generic_ELF { RuntimeLibType GetDefaultRuntimeLibType() const override; UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const override; + UnwindTableLevel + getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; diff --git a/clang/test/Driver/riscv-features.c b/clang/test/Driver/riscv-features.c index d3700f71aa7e1d..15832e79d2a491 100644 --- a/clang/test/Driver/riscv-features.c +++ b/clang/test/Driver/riscv-features.c @@ -35,6 +35,14 @@ // FAST-UNALIGNED-ACCESS: "-target-feature" "+fast-unaligned-access" // NO-FAST-UNALIGNED-ACCESS: "-target-feature" "-fast-unaligned-access" +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// +// UWTABLE: "-funwind-tables=2" +// NOUWTABLE-NOT: "-funwind-tables=2" + // RUN: %clang --target=riscv32-linux -### %s -fsyntax-only 2>&1 \ // RUN: | FileCheck %s -check-prefix=DEFAULT-LINUX // RUN: %clang --target=riscv64-linux -### %s -fsyntax-only 2>&1 \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)
@@ -421,3 +421,11 @@ // MIPSN32R6EL: "-target-cpu" "mips64r6" // MIPSN32R6EL: "-target-abi" "n32" // MIPSN32R6EL: "-mfloat-abi" "hard" + +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE quic-garvgupt wrote: Done https://github.com/llvm/llvm-project/pull/81727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)
quic-garvgupt wrote: Hi @asb, I do not have write access, requesting to merge this PR on my behalf. Also, requesting to backport this PR onto the release branch. Thanks in advance! https://github.com/llvm/llvm-project/pull/81727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/81727 >From 0d1f9be389a41ba2f1531bf13e8d1f14aadf9eeb Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 14 Feb 2024 03:00:20 -0800 Subject: [PATCH] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal The below culprit patch enabled the generation of asynchronous unwind tables (-funwind-tables=2) by default for RISCV for both linux and RISCVToolChain baremetal object. However, since there are 2 baremetal toolchain objects for RISCV, this created a discrepancy between their behavior. Moreover, enabling the generation of asynchronous unwind tables based on whether `-gcc-toolchain` option is present or not doesn't seem to be the best criteria to decide on the same. Culprit Patch - https://reviews.llvm.org/D145164 --- clang/lib/Driver/ToolChains/RISCVToolchain.cpp | 5 + clang/lib/Driver/ToolChains/RISCVToolchain.h | 2 ++ clang/test/Driver/riscv-features.c | 8 3 files changed, 15 insertions(+) diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp index 85beb945cbf6fc..624099d21ae124 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp @@ -86,6 +86,11 @@ RISCVToolChain::GetUnwindLibType(const llvm::opt::ArgList &Args) const { return ToolChain::UNW_None; } +ToolChain::UnwindTableLevel RISCVToolChain::getDefaultUnwindTableLevel( +const llvm::opt::ArgList &Args) const { + return UnwindTableLevel::None; +} + void RISCVToolChain::addClangTargetOptions( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h b/clang/lib/Driver/ToolChains/RISCVToolchain.h index cec817ef7190be..fa0aa265d842bb 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.h +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h @@ -28,6 +28,8 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public Generic_ELF { RuntimeLibType GetDefaultRuntimeLibType() const override; UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const override; + UnwindTableLevel + getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override; void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; diff --git a/clang/test/Driver/riscv-features.c b/clang/test/Driver/riscv-features.c index a108383e29fb6b..fc5fb0f27e3af4 100644 --- a/clang/test/Driver/riscv-features.c +++ b/clang/test/Driver/riscv-features.c @@ -41,6 +41,14 @@ // FAST-UNALIGNED-ACCESS: "-target-feature" "+fast-unaligned-access" // NO-FAST-UNALIGNED-ACCESS: "-target-feature" "-fast-unaligned-access" +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -### %s 2>&1 | FileCheck %s -check-prefix=NOUWTABLE +// RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain="" -fasynchronous-unwind-tables -### %s 2>&1 | FileCheck %s -check-prefix=UWTABLE +// +// UWTABLE: "-funwind-tables=2" +// NOUWTABLE-NOT: "-funwind-tables=2" + // RUN: %clang --target=riscv32-linux -### %s -fsyntax-only 2>&1 \ // RUN: | FileCheck %s -check-prefix=DEFAULT-LINUX // RUN: %clang --target=riscv64-linux -### %s -fsyntax-only 2>&1 \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Disable generation of asynchronous unwind tables for RISCV baremetal (PR #81727)
quic-garvgupt wrote: Hi @MaskRay, please review the updated changes and if they are fine, please merge this PR on my behalf. Thanks! https://github.com/llvm/llvm-project/pull/81727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)
https://github.com/quic-garvgupt created https://github.com/llvm/llvm-project/pull/118809 Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal development, creating unnecessary maintenance overhead. This patch extends the BareMetal toolchain to support an existing GCC installation, resolving this issue. The latest patchset preserves the behavior of both toolchain objects with minor differences. If no --sysroot option is passed on the command line or if the GCC installation is invalid, the sysroot will first be formed as per the RISCVToolChain baremetal object. If this path does not exist, the sysroot will be formed as per the BareMetal toolchain object. Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply that GNU linker is the default linker unless otherwise a differnt linker is passed through `-fuse-ld` flag. RFC - https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 >From b1bd1ee4f3a4966b50e0b35fd349091660e84576 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 13 Nov 2024 02:45:51 -0800 Subject: [PATCH] [RISCV] Merging RISCVToolChain and BareMetal toolchains Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal development, creating unnecessary maintenance overhead. This patch extends the BareMetal toolchain to support an existing GCC installation, resolving this issue. The latest patchset preserves the behavior of both toolchain objects with minor differences. If no --sysroot option is passed on the command line or if the GCC installation is invalid, the sysroot will first be formed as per the RISCVToolChain baremetal object. If this path does not exist, the sysroot will be formed as per the BareMetal toolchain object. Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply that GNU linker is the default linker unless otherwise a differnt linker is passed through `-fuse-ld` flag. RFC - https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 --- clang/lib/Driver/Driver.cpp | 4 - clang/lib/Driver/ToolChains/BareMetal.cpp | 225 clang/lib/Driver/ToolChains/BareMetal.h | 34 ++- clang/test/Driver/arm-gnutools.c| 12 ++ clang/test/Driver/baremetal-multilib.yaml | 4 +- clang/test/Driver/baremetal-sysroot.cpp | 4 +- clang/test/Driver/baremetal.cpp | 123 ++- clang/test/Driver/riscv-args.c | 2 +- clang/test/Driver/riscv32-toolchain-extra.c | 4 +- clang/test/Driver/riscv32-toolchain.c | 6 +- clang/test/Driver/riscv64-toolchain-extra.c | 4 +- clang/test/Driver/riscv64-toolchain.c | 4 +- 12 files changed, 314 insertions(+), 112 deletions(-) create mode 100644 clang/test/Driver/arm-gnutools.c diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7de8341b8d2d61..c5185ccedd6201 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -6521,10 +6521,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, break; case llvm::Triple::riscv32: case llvm::Triple::riscv64: -if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args)) - TC = - std::make_unique(*this, Target, Args); -else TC = std::make_unique(*this, Target, Args); break; case llvm::Triple::ve: diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index f9a73f60973e4c..1d065562e9a6ef 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -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, +bool IncludeTriple) { if (!D.SysRoot.empty()) return D.SysRoot; @@ -110,20 +111,94 @@ 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 e
[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/118809 >From b74795d44846b79252bd3fb1f1e8179311725c74 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 13 Nov 2024 02:45:51 -0800 Subject: [PATCH] [RISCV] Merging RISCVToolChain and BareMetal toolchains Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal development, creating unnecessary maintenance overhead. This patch extends the BareMetal toolchain to support an existing GCC installation, resolving this issue. The latest patchset preserves the behavior of both toolchain objects with minor differences. If no --sysroot option is passed on the command line or if the GCC installation is invalid, the sysroot will first be formed as per the RISCVToolChain baremetal object. If this path does not exist, the sysroot will be formed as per the BareMetal toolchain object. Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply that GNU linker is the default linker unless otherwise a differnt linker is passed through `-fuse-ld` flag. RFC - https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 --- clang/lib/Driver/Driver.cpp | 6 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 226 clang/lib/Driver/ToolChains/BareMetal.h | 34 ++- clang/test/Driver/arm-gnutools.c| 12 ++ clang/test/Driver/baremetal-multilib.yaml | 4 +- clang/test/Driver/baremetal-sysroot.cpp | 4 +- clang/test/Driver/baremetal.cpp | 123 ++- clang/test/Driver/riscv-args.c | 2 +- clang/test/Driver/riscv32-toolchain-extra.c | 4 +- clang/test/Driver/riscv32-toolchain.c | 6 +- clang/test/Driver/riscv64-toolchain-extra.c | 4 +- clang/test/Driver/riscv64-toolchain.c | 4 +- 12 files changed, 316 insertions(+), 113 deletions(-) create mode 100644 clang/test/Driver/arm-gnutools.c diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7de8341b8d2d61..543ed9e301ef84 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -6521,11 +6521,7 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, break; case llvm::Triple::riscv32: case llvm::Triple::riscv64: -if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args)) - TC = - std::make_unique(*this, Target, Args); -else - TC = std::make_unique(*this, Target, Args); +TC = std::make_unique(*this, Target, Args); break; case llvm::Triple::ve: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index f9a73f60973e4c..66a76d56ad8c48 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -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, +bool IncludeTriple) { if (!D.SysRoot.empty()) return D.SysRoot; @@ -110,20 +111,95 @@ 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)) +return std::string(); + + return std::string(SysRootDir); +} + +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; + + std::string SysRoot = getDriver().SysRoot; + if (!SysRoot.empty() && llvm::sys::fs::exists(SysRoot)) +return SysRoot; + + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SysRoot = computeGCCSysRoot(); + if (!SysRoot.empty()) +return SysRoot; + + SysRoot = + comp
[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)
@@ -503,12 +624,22 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, const llvm::Triple::ArchType Arch = TC.getArch(); const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); - AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA); + if (!D.SysRoot.empty()) +CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); + Args.addAllArgs(CmdArgs, {options::OPT_u}); quic-garvgupt wrote: Sure, I will be making these changes in the next patchset. However, I wanted to clarify if there is any specific reason why, in the RISCVToolchain baremetal object, OPT_L and OPT_u are added separately before FilePathLibArgs, and then subsequently the rest of the OPT_* options are added. https://github.com/llvm/llvm-project/blob/89e919fb0df391da42dbfd48cd8de268335fe672/clang/lib/Driver/ToolChains/RISCVToolchain.cpp#L201 I understand that for gnuld, the order in which flags and object files appear on the command line is relevant, unlike for lld. Was this intentional? If so, I will maintain that behavior; otherwise, I will add them in a single `addAllArgs(...)` function. https://github.com/llvm/llvm-project/pull/118809 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
https://github.com/quic-garvgupt created https://github.com/llvm/llvm-project/pull/121829 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 >From 908c2dfa26c5fa7dea14945e4eba411ebe5b3e82 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 | 121 +++--- clang/lib/Driver/ToolChains/BareMetal.h | 8 +- .../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 .../armv6m-none-eabi/lib/libstdc++.a | 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 | 28 clang/test/Driver/arm-toolchain.c | 62 + clang/test/Driver/baremetal.cpp | 16 +++ 31 files changed, 320 insertions(+), 20 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 m
[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
quic-garvgupt wrote: * **#121829** https://app.graphite.dev/github/pr/llvm/llvm-project/121829?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/121829?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121821)
https://github.com/quic-garvgupt created https://github.com/llvm/llvm-project/pull/121821 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 >From f11eb9f6f7c7407f30593360b788bfd970298146 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 | 121 +++--- clang/lib/Driver/ToolChains/BareMetal.h | 8 +- .../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 .../armv6m-none-eabi/lib/libstdc++.a | 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 | 28 clang/test/Driver/arm-toolchain.c | 62 + clang/test/Driver/baremetal.cpp | 16 +++ 31 files changed, 320 insertions(+), 20 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_aar
[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121821)
https://github.com/quic-garvgupt closed https://github.com/llvm/llvm-project/pull/121821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
https://github.com/quic-garvgupt ready_for_review https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/121829 >From 02d70a2c1fa746eafa87308f0c8109bb2c91164f 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 | 121 +++--- clang/lib/Driver/ToolChains/BareMetal.h | 8 +- .../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, 321 insertions(+), 20 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 cla
[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
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 cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/118809 >From 569feb86c654be044781aa5968907a72ea882e88 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 13 Nov 2024 02:45:51 -0800 Subject: [PATCH] [WIP] Merging RISCVToolChain and BareMetal toolchains Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal development, creating unnecessary maintenance overhead. This patch extends the BareMetal toolchain to support an existing GCC installation, resolving this issue. The latest patchset preserves the behavior of both toolchain objects with minor differences. If no --sysroot option is passed on the command line or if the GCC installation is invalid, the sysroot will first be formed as per the RISCVToolChain baremetal object. If this path does not exist, the sysroot will be formed as per the BareMetal toolchain object. Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply that GNU linker is the default linker unless otherwise a differnt linker is passed through `-fuse-ld` flag. RFC - https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 change-Id: Ie2cdefd3c95b25770a33319ce2e711c9300efc2e --- clang/lib/Driver/Driver.cpp | 4 - clang/lib/Driver/ToolChains/BareMetal.cpp | 247 ++ clang/lib/Driver/ToolChains/BareMetal.h | 29 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 232 clang/lib/Driver/ToolChains/RISCVToolchain.h | 67 - clang/test/Driver/arm-gnutools.c | 12 + clang/test/Driver/baremetal-multilib.yaml | 2 +- clang/test/Driver/baremetal-sysroot.cpp | 2 +- clang/test/Driver/baremetal.cpp | 77 +++--- clang/test/Driver/riscv-args.c| 2 +- clang/test/Driver/riscv32-toolchain-extra.c | 7 +- clang/test/Driver/riscv32-toolchain.c | 22 +- clang/test/Driver/riscv64-toolchain-extra.c | 7 +- clang/test/Driver/riscv64-toolchain.c | 16 +- 14 files changed, 295 insertions(+), 431 deletions(-) delete mode 100644 clang/lib/Driver/ToolChains/RISCVToolchain.cpp delete mode 100644 clang/lib/Driver/ToolChains/RISCVToolchain.h create mode 100644 clang/test/Driver/arm-gnutools.c diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index fb73b62cf2daed..48b6361f588843 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -6557,10 +6557,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, break; case llvm::Triple::riscv32: case llvm::Triple::riscv64: -if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args)) - TC = - std::make_unique(*this, Target, Args); -else TC = std::make_unique(*this, Target, Args); break; case llvm::Triple::ve: diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index eecaaa9a42930d..a2fecb297cd05a 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -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, +bool IncludeTriple) { if (!D.SysRoot.empty()) return D.SysRoot; @@ -110,20 +111,95 @@ 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)) +return std::string(); + + return std::string(SysRootDir); +} + +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; + + std::string SysRoot = getDriver().SysRoot; + if (!SysRoot.empty() && llvm::sys::fs::exists(SysRoot)) +return SysRoot; + + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain,
[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/118809 >From b58f9dd197c78b1e39676022a421ca0e6d5552a5 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 13 Nov 2024 02:45:51 -0800 Subject: [PATCH] [WIP] Merging RISCVToolChain and BareMetal toolchains Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal development, creating unnecessary maintenance overhead. This patch extends the BareMetal toolchain to support an existing GCC installation, resolving this issue. The latest patchset preserves the behavior of both toolchain objects with minor differences. If no --sysroot option is passed on the command line or if the GCC installation is invalid, the sysroot will first be formed as per the RISCVToolChain baremetal object. If this path does not exist, the sysroot will be formed as per the BareMetal toolchain object. Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply that GNU linker is the default linker unless otherwise a differnt linker is passed through `-fuse-ld` flag. RFC - https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 change-Id: Ie2cdefd3c95b25770a33319ce2e711c9300efc2e --- clang/lib/Driver/CMakeLists.txt | 1 - clang/lib/Driver/Driver.cpp | 7 +- clang/lib/Driver/ToolChains/BareMetal.cpp | 247 ++ clang/lib/Driver/ToolChains/BareMetal.h | 29 +- .../lib/Driver/ToolChains/RISCVToolchain.cpp | 232 clang/lib/Driver/ToolChains/RISCVToolchain.h | 67 - clang/test/Driver/arm-gnutools.c | 12 + clang/test/Driver/baremetal-multilib.yaml | 2 +- clang/test/Driver/baremetal-sysroot.cpp | 2 +- clang/test/Driver/baremetal.cpp | 77 +++--- clang/test/Driver/riscv-args.c| 2 +- clang/test/Driver/riscv32-toolchain-extra.c | 7 +- clang/test/Driver/riscv32-toolchain.c | 22 +- clang/test/Driver/riscv64-toolchain-extra.c | 7 +- clang/test/Driver/riscv64-toolchain.c | 20 +- 15 files changed, 298 insertions(+), 436 deletions(-) delete mode 100644 clang/lib/Driver/ToolChains/RISCVToolchain.cpp delete mode 100644 clang/lib/Driver/ToolChains/RISCVToolchain.h create mode 100644 clang/test/Driver/arm-gnutools.c diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 4fd10bf671512f..59c219e1f709b4 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -74,7 +74,6 @@ add_clang_library(clangDriver ToolChains/OHOS.cpp ToolChains/OpenBSD.cpp ToolChains/PS4CPU.cpp - ToolChains/RISCVToolchain.cpp ToolChains/Solaris.cpp ToolChains/SPIRV.cpp ToolChains/TCE.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index fb73b62cf2daed..e16b0af1790cc9 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -41,7 +41,6 @@ #include "ToolChains/PPCFreeBSD.h" #include "ToolChains/PPCLinux.h" #include "ToolChains/PS4CPU.h" -#include "ToolChains/RISCVToolchain.h" #include "ToolChains/SPIRV.h" #include "ToolChains/Solaris.h" #include "ToolChains/TCE.h" @@ -6557,11 +6556,7 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, break; case llvm::Triple::riscv32: case llvm::Triple::riscv64: -if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args)) - TC = - std::make_unique(*this, Target, Args); -else - TC = std::make_unique(*this, Target, Args); +TC = std::make_unique(*this, Target, Args); break; case llvm::Triple::ve: TC = std::make_unique(*this, Target, Args); diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index eecaaa9a42930d..a2fecb297cd05a 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -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, +bool IncludeTriple) { if (!D.SysRoot.empty()) return D.SysRoot; @@ -110,20 +111,95 @@ 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.getPa
[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)
@@ -6521,11 +6521,7 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, break; case llvm::Triple::riscv32: case llvm::Triple::riscv64: -if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args)) - TC = - std::make_unique(*this, Target, Args); -else - TC = std::make_unique(*this, Target, Args); quic-garvgupt wrote: yes, I have deleted those files as a part of my current patchset https://github.com/llvm/llvm-project/pull/118809 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)
@@ -110,20 +111,95 @@ 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)) +return std::string(); + + return std::string(SysRootDir); +} + +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; + + std::string SysRoot = getDriver().SysRoot; + if (!SysRoot.empty() && llvm::sys::fs::exists(SysRoot)) +return SysRoot; + + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SysRoot = computeGCCSysRoot(); + if (!SysRoot.empty()) +return SysRoot; + + SysRoot = + computeInstalledToolchainSysRoot(getDriver(), /*IncludeTriple*/ true); + + return SysRoot; +} + +static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, + const Multilib &Multilib, + StringRef InstallPath, + ToolChain::path_list &Paths) { + if (const auto &PathsCallback = Multilibs.filePathsCallback()) +for (const auto &Path : PathsCallback(Multilib)) + addPathIfExists(D, InstallPath + Path, Paths); +} + BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); +: Generic_ELF(D, Triple, Args) { + GCCInstallation.init(Triple, Args); + SysRoot = computeSysRoot(); + UseLD = + Args.getLastArgValue(options::OPT_fuse_ld_EQ).equals_insensitive("ld"); quic-garvgupt wrote: value will be "0". The function to decide the default linker is "getDefaultLinker" which calls "isUsingLd". I have made this function virtual which can be overridden in derived classes and can return false for all cases. https://github.com/llvm/llvm-project/pull/118809 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)
@@ -78,8 +86,9 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain { using OrderedMultilibs = llvm::iterator_range::const_reverse_iterator>; OrderedMultilibs getOrderedMultilibs() const; - + bool UseLD; quic-garvgupt wrote: please see my comment below https://github.com/llvm/llvm-project/pull/118809 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
@@ -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 cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
quic-garvgupt wrote: Gentle Ping again! https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
quic-garvgupt wrote: Gentle Ping! https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)
quic-garvgupt wrote: I have divided this PR into three separate PRs to streamline the review process and ensured that ARM and RISCV tests are not modified in the same PR. Please review them and provide any feedback or comments. Thanks! [RISCV] Teach Barmetal toolchain about GCC installation(1/3) - https://github.com/llvm/llvm-project/pull/121831 [RISCV] Change linker job in Baremetal toolchain object accomodate GCCInstallation.(2/3) - https://github.com/llvm/llvm-project/pull/121830 [RISCV] Integrate RISCV target in baremetal toolchain object and deprecate RISCVToolchain object.(3/3) - https://github.com/llvm/llvm-project/pull/121829 https://github.com/llvm/llvm-project/pull/118809 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/121829 >From 03b91a8d408bacec17391b995611dbbb0ea62edd 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 | 121 +++--- 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, 326 insertions(+), 20 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 cla
[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
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 (PR #121829)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,20 +110,76 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; + + std::string SysRoot = getDriver().SysRoot; + if (!SysRoot.empty()) +return SysRoot; + + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + 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(SysRootDir); + SysRoot = computeBaseSysRoot(getDriver(), /*IncludeTriple*/ true); + + return SysRoot; quic-garvgupt wrote: Thanks for pointing this out!. I have fixed it in the next patchset https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -79,7 +87,6 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain { OrderedMultilibs getOrderedMultilibs() const; std::string SysRoot; quic-garvgupt wrote: Removing this private variable was making the code messy because there have been updates to this variable in some member functions and the updated value is then further used in other functions. Removing this variable would need to pass this as an argument to all those functions which would make the code less readable. To avoid the confusion, all local variables for sysroot are named as `SysRootDir` and any references to this variable as `SysRoot` only https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
quic-garvgupt wrote: > I'm looking at this patch in isolation, so its possible that the comments > here are addressed elasewhere. > > It looks like useful functionality to add to the bare metal driver. > > It also looks like there is some scope for some documentation, for users and > for toolchain developers. Users will need to know about what options to set > to point at their GCC installation (or place adjacent). Non-GNU toolchain > developers will need to avoid `/lib/crt0.o`. If multilibs doesn't > work for all toolchains yet, would be good to add that as a limitation. > > That could be done with a follow up patch though. Thanks for providing feedback @smithp35. I can add documentation related to the points you mentioned. Pls let me know if adding them in the BareMetal.cpp file would be ok or should I consider adding it in some other file. https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,20 +110,81 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); +} + +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; + + const Driver &D = getDriver(); + if (!D.SysRoot.empty()) +return D.SysRoot; + + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { +StringRef LibDir = GCCInstallation.getParentLibPath(); +StringRef TripleStr = GCCInstallation.getTriple().str(); +llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr); + } else if (hasGCCToolChainAlongSideClang(D)) { +// 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, D.Dir, "..", D.getTargetTriple()); + } + + if (llvm::sys::fs::exists(SysRootDir)) +return std::string(SysRootDir); + return computeBaseSysRoot(D, /*IncludeTriple*/ true); +} + +static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, + const Multilib &Multilib, + StringRef InstallPath, + ToolChain::path_list &Paths) { + if (const auto &PathsCallback = Multilibs.filePathsCallback()) +for (const auto &Path : PathsCallback(Multilib)) + addPathIfExists(D, InstallPath + Path, Paths); +} + BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); +: Generic_ELF(D, Triple, Args) { + GCCInstallation.init(Triple, Args); + SysRoot = computeSysRoot(); + if (GCCInstallation.isValid()) { +Multilibs = GCCInstallation.getMultilibs(); +SelectedMultilibs.assign({GCCInstallation.getMultilib()}); quic-garvgupt wrote: Yes, GNU arm-none-eabi toolchains won't work since mutlilibs for this target is not added. Currently, only form some targets hard-coded multilibs are added including RISCV. One can look at `ScanGCCForMultilibs` function in `Gnu.cpp` to see for what all architectures GCC multilibs are supported IINW. https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
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 cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
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)
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 cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)
@@ -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 cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
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 cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/121829 >From 1d0db96afab52903a267d600cab02c24900101af 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 (PR #121829)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/121829 >From 8d6d2e0f1eaa0b81613a786dbe003ddf7d0a2983 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/docs/Toolchain.rst | 5 + .../clang/Basic/DiagnosticDriverKinds.td | 2 + clang/lib/Driver/ToolChains/BareMetal.cpp | 207 +- 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-gnutools.c | 4 + clang/test/Driver/aarch64-toolchain-extra.c | 28 +++ clang/test/Driver/aarch64-toolchain.c | 61 ++ clang/test/Driver/arm-gnutools.c | 6 + clang/test/Driver/arm-toolchain-extra.c | 29 +++ clang/test/Driver/arm-toolchain.c | 62 ++ clang/test/Driver/baremetal.cpp | 16 ++ clang/test/Driver/check-no-multlib-warning.c | 10 + 32 files changed, 386 insertions(+), 62 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
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,20 +110,81 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); +} + +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; + + const Driver &D = getDriver(); + if (!D.SysRoot.empty()) +return D.SysRoot; + + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { +StringRef LibDir = GCCInstallation.getParentLibPath(); +StringRef TripleStr = GCCInstallation.getTriple().str(); +llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr); + } else if (hasGCCToolChainAlongSideClang(D)) { +// 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, D.Dir, "..", D.getTargetTriple()); + } + + if (llvm::sys::fs::exists(SysRootDir)) +return std::string(SysRootDir); + return computeBaseSysRoot(D, /*IncludeTriple*/ true); +} + +static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, + const Multilib &Multilib, + StringRef InstallPath, + ToolChain::path_list &Paths) { + if (const auto &PathsCallback = Multilibs.filePathsCallback()) +for (const auto &Path : PathsCallback(Multilib)) + addPathIfExists(D, InstallPath + Path, Paths); +} + BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); +: Generic_ELF(D, Triple, Args) { + GCCInstallation.init(Triple, Args); + SysRoot = computeSysRoot(); + if (GCCInstallation.isValid()) { +Multilibs = GCCInstallation.getMultilibs(); +SelectedMultilibs.assign({GCCInstallation.getMultilib()}); +path_list &Paths = getFilePaths(); +// Add toolchain/multilib specific file paths. +addMultilibsFilePaths(D, Multilibs, SelectedMultilibs.back(), + GCCInstallation.getInstallPath(), Paths); +getFilePaths().push_back(GCCInstallation.getInstallPath().str()); +ToolChain::path_list &PPaths = getProgramPaths(); +// Multilib cross-compiler GCC installations put ld in a triple-prefixed +// directory off of the parent of the GCC installation. +PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + + GCCInstallation.getTriple().str() + "/bin") + .str()); +PPaths.push_back((GCCInstallation.getParentLibPath() + "/../bin").str()); +getFilePaths().push_back(SysRoot + "/lib"); + } else { quic-garvgupt wrote: > Stepping back a bit, there's a bit of the logic/use-case in computeSysRoot > that I don't understand. When we find a GCC ToolChain alongside clang, I > don't see any logic to validate it. There is no code to validate it in the constructor. However, it's use was needed in the linker job (see `Linker::ConstructJob`). This was done to preserve the behavior of RISCVToolChain Object. I am not sure why it was decided there that the mere presence of `lib/crt0.o` file alongside clang in target triple prefixed directory will indicate a GCC toolchain, however in RISCVToolchain object, toolchain found along clang isn't considered a valid GCCInstallation and the same has been implemented here to preserve that behavior. One needs to look at `hasGCCToolchain`, `computeSysRoot` and constructor in RISCVToolChain.cpp for the same >Is the intention here to find a valid GCC installation equivalent to the >-gcc-install-dir or --gcc-toolchain, or something else? Yes it is trying to find a toolchain that is equivalent to `--gcc-toolchain`. The same is also mentioned in the comments for the function `hasGCCToolChain` in RISCVToolChain.cpp. You can also look at tests "clang/test/Driver/riscv64-toolchain-extra.c` and "clang/test/Driver/riscv32-toolchain-extra.c" to see how it works. > The logic in this block is the same as if clang-runtimes w
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/121829 >From 63eaf99ffe04d8c66bf11ec3bad6b04b83de3c96 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/docs/Toolchain.rst | 5 + .../clang/Basic/DiagnosticDriverKinds.td | 3 + clang/lib/Driver/ToolChains/BareMetal.cpp | 206 +- 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-gnutools.c | 4 + clang/test/Driver/aarch64-toolchain-extra.c | 28 +++ clang/test/Driver/aarch64-toolchain.c | 61 ++ clang/test/Driver/arm-gnutools.c | 6 + clang/test/Driver/arm-toolchain-extra.c | 29 +++ clang/test/Driver/arm-toolchain.c | 62 ++ clang/test/Driver/baremetal.cpp | 16 ++ clang/test/Driver/check-no-multlib-warning.c | 10 + 32 files changed, 386 insertions(+), 62 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
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,20 +110,81 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); +} + +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; + + const Driver &D = getDriver(); + if (!D.SysRoot.empty()) +return D.SysRoot; + + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { +StringRef LibDir = GCCInstallation.getParentLibPath(); +StringRef TripleStr = GCCInstallation.getTriple().str(); +llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr); + } else if (hasGCCToolChainAlongSideClang(D)) { +// 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, D.Dir, "..", D.getTargetTriple()); + } + + if (llvm::sys::fs::exists(SysRootDir)) +return std::string(SysRootDir); + return computeBaseSysRoot(D, /*IncludeTriple*/ true); +} + +static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, + const Multilib &Multilib, + StringRef InstallPath, + ToolChain::path_list &Paths) { + if (const auto &PathsCallback = Multilibs.filePathsCallback()) +for (const auto &Path : PathsCallback(Multilib)) + addPathIfExists(D, InstallPath + Path, Paths); +} + BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); +: Generic_ELF(D, Triple, Args) { + GCCInstallation.init(Triple, Args); + SysRoot = computeSysRoot(); + if (GCCInstallation.isValid()) { +Multilibs = GCCInstallation.getMultilibs(); +SelectedMultilibs.assign({GCCInstallation.getMultilib()}); quic-garvgupt wrote: Yes, I have added a warning in the latest patchset. https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
quic-garvgupt wrote: Hi @smithp35, can you pls review the latest changes and approve this PR if everything looks fine? https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #144640)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/144640 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #121829)
quic-garvgupt wrote: > > Do the fuchsia builders actually produce output on a failure? We seem to > > just get exit code 1, but no indication of what filecheck had problems with. > > They do; here's a link! Let me know if you have an problems with the Web UI; > I can paste things here if so. > https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8711783358287375697/overview The check lines that are not found in the tests were added as part of different commit ec230aa and not this one. I will be relanding this commit as is here https://github.com/llvm/llvm-project/pull/144640 https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #144640)
https://github.com/quic-garvgupt created https://github.com/llvm/llvm-project/pull/144640 This patch introduces enhancements to the Baremetal toolchain to support GCC toolchain detection. - If the --gcc-install-dir or --gcc-toolchain options are provided and point to valid paths, the sysroot is derived from those locations. - If not, the logic falls back to the existing sysroot inference mechanism already present in the Baremetal toolchain. - Support for adding include paths for the libstdc++ library has also been added. Additionally, the restriction to always use the integrated assembler has been removed. With a valid GCC installation, the GNU assembler can now be used as well. This patch currently updates and adds tests for the ARM target only. RISC-V-specific tests will be introduced in a later patch, once the RISCVToolChain is fully merged into the Baremetal toolchain. At this stage, there is no way to test the RISC-V target within this PR. RFC: https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 >From b5bf681e5d503569253eabc9c987e7d9797e53c8 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Tue, 17 Jun 2025 21:43:17 +0530 Subject: [PATCH] [Driver] Add support for GCC installation detection in Baremetal toolchain (#121829) This patch introduces enhancements to the Baremetal toolchain to support GCC toolchain detection. - If the --gcc-install-dir or --gcc-toolchain options are provided and point to valid paths, the sysroot is derived from those locations. - If not, the logic falls back to the existing sysroot inference mechanism already present in the Baremetal toolchain. - Support for adding include paths for the libstdc++ library has also been added. Additionally, the restriction to always use the integrated assembler has been removed. With a valid GCC installation, the GNU assembler can now be used as well. This patch currently updates and adds tests for the ARM target only. RISC-V-specific tests will be introduced in a later patch, once the RISCVToolChain is fully merged into the Baremetal toolchain. At this stage, there is no way to test the RISC-V target within this PR. RFC: https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 --- clang/docs/Toolchain.rst | 5 + .../clang/Basic/DiagnosticDriverKinds.td | 3 + clang/lib/Driver/ToolChains/BareMetal.cpp | 235 +- clang/lib/Driver/ToolChains/BareMetal.h | 19 +- .../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-gnutools.c | 4 + clang/test/Driver/aarch64-toolchain-extra.c | 28 +++ clang/test/Driver/aarch64-toolchain.c | 61 + clang/test/Driver/arm-gnutools.c | 6 + clang/test/Driver/arm-toolchain-extra.c | 29 +++ clang/test/Driver/arm-toolchain.c | 62 + clang/test/Driver/baremetal.cpp | 16 ++ clang/test/Driver/check-no-multlib-warning.c | 10 + 32 files changed, 418 insertions(+), 64 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 10
[clang] Fix tests failing on fuchsia clang x86_64 builders (PR #144655)
https://github.com/quic-garvgupt created https://github.com/llvm/llvm-project/pull/144655 Fuchsia sets CLANG_DEFAULT_UNWINDLIB to libunwind. As a result, when rtlib is set to libgcc and unwindlib is not explicitly specified, tests using Fuchsia as the default platform will fail. To address this, the affected tests are now marked as unsupported on the Fuchsia platform. This change fixes the following tests introduced in https://github.com/llvm/llvm-project/commit/45ea46c44636094e9fcdbbeabfd11f9d0fad5e38: clang/test/Driver/aarch64-toolchain-extra.c clang/test/Driver/arm-toolchain-extra.c clang/test/Driver/aarch64-toolchain.c clang/test/Driver/arm-toolchain.c >From 5041a43ba895f1dc49e02b894a535976671124fe Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Wed, 18 Jun 2025 01:57:27 -0700 Subject: [PATCH] Fix tests failing on fuchsia clang x86_64 builders Change-Id: I18c76810d7a58770ab4883d29c2da544730ade62 --- clang/test/Driver/aarch64-toolchain-extra.c | 2 +- clang/test/Driver/aarch64-toolchain.c | 2 +- clang/test/Driver/arm-toolchain-extra.c | 2 +- clang/test/Driver/arm-toolchain.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/test/Driver/aarch64-toolchain-extra.c b/clang/test/Driver/aarch64-toolchain-extra.c index 2610e962bd690..d8ba0556167ab 100644 --- a/clang/test/Driver/aarch64-toolchain-extra.c +++ b/clang/test/Driver/aarch64-toolchain-extra.c @@ -4,7 +4,7 @@ // 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 +// UNSUPPORTED: system-windows, target={{.*}}-fuchsia{{.*}} // If there is no GCC install detected then the driver searches for executables // and runtime starting from the directory tree above the driver itself. diff --git a/clang/test/Driver/aarch64-toolchain.c b/clang/test/Driver/aarch64-toolchain.c index 7f2c01d928e43..dfa63bfff4d1c 100644 --- a/clang/test/Driver/aarch64-toolchain.c +++ b/clang/test/Driver/aarch64-toolchain.c @@ -1,4 +1,4 @@ -// UNSUPPORTED: system-windows +// UNSUPPORTED: system-windows, target={{.*}}-fuchsia{{.*}} // RUN: %clang -### %s -fuse-ld= \ // RUN: --target=aarch64-none-elf --rtlib=libgcc \ diff --git a/clang/test/Driver/arm-toolchain-extra.c b/clang/test/Driver/arm-toolchain-extra.c index 114de0a8154ab..f3e4f5f368d38 100644 --- a/clang/test/Driver/arm-toolchain-extra.c +++ b/clang/test/Driver/arm-toolchain-extra.c @@ -4,7 +4,7 @@ // 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 +// UNSUPPORTED: system-windows, target={{.*}}-fuchsia{{.*}} // If there is no GCC install detected then the driver searches for executables // and runtime starting from the directory tree above the driver itself. diff --git a/clang/test/Driver/arm-toolchain.c b/clang/test/Driver/arm-toolchain.c index 2e38461fb7a3e..8cd6c5e96b7a0 100644 --- a/clang/test/Driver/arm-toolchain.c +++ b/clang/test/Driver/arm-toolchain.c @@ -1,4 +1,4 @@ -// UNSUPPORTED: system-windows +// UNSUPPORTED: system-windows, target={{.*}}-fuchsia{{.*}} // RUN: %clang -### %s -fuse-ld= \ // RUN: --target=armv6m-none-eabi --rtlib=libgcc \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (PR #144649)
https://github.com/quic-garvgupt created https://github.com/llvm/llvm-project/pull/144649 This patch conditionalise the addition of crt{begin,end}.o object files along with addition of -lgloss lib based on whether libc selected is newlib or llvm libc. Since there is no way a user can specify which libc it wants to link against, currently passing valid GCCInstallation to driver will select newlib otherwise it will default to llvm libc. Moreover, this patch makes gnuld the default linker for baremetal toolchain object. User need to pass `-fuse-ld=lld` explicitly to driver to select lld This is the 2nd patch in the series of patches of merging RISCVToolchain into BareMetal toolchain object. RFC: https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 >From 43ea078f3a000f4d13c76115284219937c8f1ef7 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Tue, 17 Jun 2025 22:49:55 +0530 Subject: [PATCH] [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (#121830) This patch conditionalise the addition of crt{begin,end}.o object files along with addition of -lgloss lib based on whether libc selected is newlib or llvm libc. Since there is no way a user can specify which libc it wants to link against, currently passing valid GCCInstallation to driver will select newlib otherwise it will default to llvm libc. Moreover, this patch makes gnuld the default linker for baremetal toolchain object. User need to pass `-fuse-ld=lld` explicitly to driver to select lld This is the 2nd patch in the series of patches of merging RISCVToolchain into BareMetal toolchain object. RFC: https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 --- clang/lib/Driver/ToolChains/BareMetal.cpp | 37 +++- clang/lib/Driver/ToolChains/BareMetal.h | 3 +- clang/test/Driver/aarch64-toolchain-extra.c | 13 ++- clang/test/Driver/aarch64-toolchain.c | 95 clang/test/Driver/arm-toolchain-extra.c | 7 ++ clang/test/Driver/arm-toolchain.c | 99 - clang/test/Driver/baremetal.cpp | 3 +- clang/test/Driver/sanitizer-ld.c| 2 +- 8 files changed, 246 insertions(+), 13 deletions(-) diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index 0fbfe6c77f342..a08bb588dd764 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -584,9 +584,31 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL"); } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, - options::OPT_r)) { -CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o"))); + bool NeedCRTs = + !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles); + + const char *CRTBegin, *CRTEnd; + if (NeedCRTs) { +if (!Args.hasArg(options::OPT_r)) + CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o"))); +if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) { + auto RuntimeLib = TC.GetRuntimeLibType(Args); + switch (RuntimeLib) { + case (ToolChain::RLT_Libgcc): { +CRTBegin = "crtbegin.o"; +CRTEnd = "crtend.o"; +break; + } + case (ToolChain::RLT_CompilerRT): { +CRTBegin = +TC.getCompilerRTArgString(Args, "crtbegin", ToolChain::FT_Object); +CRTEnd = +TC.getCompilerRTArgString(Args, "crtend", ToolChain::FT_Object); +break; + } + } + CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTBegin))); +} } Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, @@ -609,15 +631,22 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, } if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { +CmdArgs.push_back("--start-group"); AddRunTimeLibs(TC, D, CmdArgs, Args); - CmdArgs.push_back("-lc"); +if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) + CmdArgs.push_back("-lgloss"); +CmdArgs.push_back("--end-group"); } if (D.isUsingLTO()) addLTOOptions(TC, Args, CmdArgs, Output, Inputs, D.getLTOMode() == LTOK_Thin); + if ((TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) && + NeedCRTs) +CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTEnd))); + if (TC.getTriple().isRISCV()) CmdArgs.push_back("-X"); diff --git a/clang/lib/Driver/ToolChains/BareMetal.h b/clang/lib/Driver/ToolChains/BareMetal.h index 930f8584e6435..54805530bae82 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.h +++ b/clang/lib/Driver/ToolChains/BareMetal.h @@ -38,6 +38,7 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF { public: bool initGCCInstallation(const llvm::Tripl
[clang] Reland [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #144640)
https://github.com/quic-garvgupt closed https://github.com/llvm/llvm-project/pull/144640 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #144640)
quic-garvgupt wrote: Fix for tests failing on https://lab.llvm.org/buildbot/#/builders/11 - https://github.com/llvm/llvm-project/pull/144655 https://github.com/llvm/llvm-project/pull/144640 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Pass TargetMachine from from Clang to `BitcodeWriter`and `ThinLTOBitcodeWriter` pass for thin and fat LTO respectively. (PR #143692)
quic-garvgupt wrote: Gentle Ping! https://github.com/llvm/llvm-project/pull/143692 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #145390)
quic-garvgupt wrote: Hi @mysterymath, could you please initiate a build for this PR (#145390) along with PR #144649 on the Fuchsia buildbot? These two PRs contain the necessary fixes to resolve the failure previously encountered on the [fuchsia buildbots](https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8711783358287375697/overview) , which led to their reversion in PR #144603. Triggering a force build will help verify that the fix is effective and does not cause any further buildbot failures. Please ensure that PR #145390 and PR #144649 are applied in sequence to avoid any merge conflicts https://github.com/llvm/llvm-project/pull/145390 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #121829)
https://github.com/quic-garvgupt closed https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (PR #121830)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/121830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (PR #121830)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/121830 >From c490d1f4f1d1c3a65ad722d46b87fe49ade11c21 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Mon, 24 Mar 2025 04:58:57 -0700 Subject: [PATCH] [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object This patch conditionalise the addition of crt{begin,end}.o object files along with addition of -lgloss lib based on whether libc selected is newlib or llvm libc. Since there is no way a user can specify which libc it wants to link against, currently passing valid GCCInstallation to driver will select newlib otherwise it will default to llvm libc. Moreover, this patch makes gnuld the default linker for baremetal toolchain object. User need to pass `-fuse-ld=lld` explicitly to driver to select lld This is the 2nd patch in the series of patches of merging RISCVToolchain into BareMetal toolchain object. RFC: https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 Change-Id: Ie06dc976c306cf04ec2733bbb2d271c57d201f86 --- clang/lib/Driver/ToolChains/BareMetal.cpp | 37 +++- clang/lib/Driver/ToolChains/BareMetal.h | 3 +- clang/test/Driver/aarch64-toolchain-extra.c | 13 ++- clang/test/Driver/aarch64-toolchain.c | 95 clang/test/Driver/arm-toolchain-extra.c | 7 ++ clang/test/Driver/arm-toolchain.c | 99 - clang/test/Driver/baremetal.cpp | 3 +- clang/test/Driver/sanitizer-ld.c| 2 +- 8 files changed, 246 insertions(+), 13 deletions(-) diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index 0fbfe6c77f342..a08bb588dd764 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -584,9 +584,31 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL"); } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, - options::OPT_r)) { -CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o"))); + bool NeedCRTs = + !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles); + + const char *CRTBegin, *CRTEnd; + if (NeedCRTs) { +if (!Args.hasArg(options::OPT_r)) + CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o"))); +if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) { + auto RuntimeLib = TC.GetRuntimeLibType(Args); + switch (RuntimeLib) { + case (ToolChain::RLT_Libgcc): { +CRTBegin = "crtbegin.o"; +CRTEnd = "crtend.o"; +break; + } + case (ToolChain::RLT_CompilerRT): { +CRTBegin = +TC.getCompilerRTArgString(Args, "crtbegin", ToolChain::FT_Object); +CRTEnd = +TC.getCompilerRTArgString(Args, "crtend", ToolChain::FT_Object); +break; + } + } + CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTBegin))); +} } Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, @@ -609,15 +631,22 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, } if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { +CmdArgs.push_back("--start-group"); AddRunTimeLibs(TC, D, CmdArgs, Args); - CmdArgs.push_back("-lc"); +if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) + CmdArgs.push_back("-lgloss"); +CmdArgs.push_back("--end-group"); } if (D.isUsingLTO()) addLTOOptions(TC, Args, CmdArgs, Output, Inputs, D.getLTOMode() == LTOK_Thin); + if ((TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) && + NeedCRTs) +CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTEnd))); + if (TC.getTriple().isRISCV()) CmdArgs.push_back("-X"); diff --git a/clang/lib/Driver/ToolChains/BareMetal.h b/clang/lib/Driver/ToolChains/BareMetal.h index 930f8584e6435..54805530bae82 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.h +++ b/clang/lib/Driver/ToolChains/BareMetal.h @@ -38,6 +38,7 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF { public: bool initGCCInstallation(const llvm::Triple &Triple, const llvm::opt::ArgList &Args); + bool hasValidGCCInstallation() const { return IsGCCInstallationValid; } bool isBareMetal() const override { return true; } bool isCrossCompiling() const override { return true; } bool HasNativeLLVMSupport() const override { return true; } @@ -63,8 +64,6 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF { return ToolChain::CST_Libcxx; } - const char *getDefaultLinker() const override { return "ld.lld"; } - void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args)
[clang] [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (PR #121830)
https://github.com/quic-garvgupt closed https://github.com/llvm/llvm-project/pull/121830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix link order of BareMetal toolchain object (PR #132806)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/132806 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add option to force undefined symbols during linking in BareMetal toolchain object. (PR #132807)
https://github.com/quic-garvgupt closed https://github.com/llvm/llvm-project/pull/132807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Forward sysroot from Driver to linker in BareMetal ToolChain Object (PR #132808)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/132808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Forward sysroot from Driver to linker in BareMetal ToolChain Object (PR #132808)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/132808 >From f4a5757a8abf6ff7ba3e064533f3993a0ed0198e Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Mon, 24 Mar 2025 07:04:59 -0700 Subject: [PATCH] [Driver] Forward sysroot from Driver to linker in BareMetal ToolChain Object RISCVToolChain object passes `--sysroot` option from clang to gnuld. Adding the supprt for the same in BareMetal toolchain object. This is done as a part of the effort to merge RISCVToolchain object into BareMetal toolchain object. This is the 5th patch in the series of patches for merging RISCVToolchain object into BareMetal toolchain object. RFC: https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 Change-Id: Ie830bf6d126fea46dc225e5ef97e14349765ba07 --- clang/lib/Driver/ToolChains/BareMetal.cpp | 3 + clang/test/Driver/aarch64-toolchain.c | 5 +- clang/test/Driver/arm-toolchain.c | 3 + clang/test/Driver/baremetal.cpp | 96 +-- 4 files changed, 82 insertions(+), 25 deletions(-) diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index d4e4e6d04b417..84d9747488060 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -568,6 +568,9 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, const llvm::Triple::ArchType Arch = TC.getArch(); const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); + if (!D.SysRoot.empty()) +CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); + CmdArgs.push_back("-Bstatic"); if (TC.getTriple().isRISCV() && Args.hasArg(options::OPT_mno_relax)) diff --git a/clang/test/Driver/aarch64-toolchain.c b/clang/test/Driver/aarch64-toolchain.c index e12107fa2c506..d6628aa3e2e36 100644 --- a/clang/test/Driver/aarch64-toolchain.c +++ b/clang/test/Driver/aarch64-toolchain.c @@ -29,6 +29,7 @@ // C-AARCH64-BAREMETAL: "-isysroot" "{{.*}}Inputs/basic_aarch64_gcc_tree/aarch64-none-elf" // C-AARCH64-BAREMETAL: "-internal-isystem" "{{.*}}Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include" // C-AARCH64-BAREMETAL: "{{.*}}/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/../../../../bin/aarch64-none-elf-ld" +// C-AARCH64-BAREMETAL: "--sysroot={{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf" // C-AARCH64-BAREMETAL: "-Bstatic" "-EL" // C-AARCH64-BAREMETAL: "{{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/crt0.o" // C-AARCH64-BAREMETAL: "{{.*}}/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o" @@ -65,6 +66,7 @@ // CXX-AARCH64-BAREMETAL: "-internal-isystem" "{{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include/c++/8.2.1" // CXX-AARCH64-BAREMETAL: "-internal-isystem" "{{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include" // CXX-AARCH64-BAREMETAL: "{{.*}}/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/../../../../bin/aarch64-none-elf-ld" +// CXX-AARCH64-BAREMETAL: "--sysroot={{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf" // CXX-AARCH64-BAREMETAL: "-Bstatic" "-EL" // CXX-AARCH64-BAREMETAL: "{{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/crt0.o" // CXX-AARCH64-BAREMETAL: "{{.*}}/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o" @@ -101,7 +103,8 @@ // CXX-AARCH64-BAREMETAL-LIBCXX: "-isysroot" "{{.*}}Inputs/basic_aarch64_gcc_tree/aarch64-none-elf" // CXX-AARCH64-BAREMETAL-LIBCXX: "-internal-isystem" "{{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include/c++/v1" // CXX-AARCH64-BAREMETAL-LIBCXX: "-internal-isystem" "{{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include" -// CXX-AARCH64-BAREMETAL-LIBCXX: "{{.*}}/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/../../../../bin/aarch64-none-elf-ld +// CXX-AARCH64-BAREMETAL-LIBCXX: "{{.*}}/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/../../../../bin/aarch64-none-elf-ld" +// CXX-AARCH64-BAREMETAL-LIBCXX: "--sysroot={{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf" // CXX-AARCH64-BAREMETAL-LIBCXX: "-Bstatic" "-EL" // CXX-AARCH64-BAREMETAL-LIBCXX: "{{.*}}/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/crt0.o" // CXX-AARCH64-BAREMETAL-LIBCXX: "{{.*}}/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o" diff --git a/clang/test/Driver/arm-toolchain.c b/clang/test/Driver/arm-toolchain.c index d4f9bf2aaf3d5..3e507be44a8dd 100644 --- a/clang/test/Driver/arm-toolchain.c +++ b/clang/test/Driver/arm-toolchain.c @@ -28,6 +28,7 @@ // C-ARM-BAREMETAL: "-isysroot" "{{.*}}Inputs/basic_arm_gcc_tree/armv6m-none-eabi" // C-ARM-BAREMETAL: "-internal-isystem" "{{.*}}Inputs/basic_arm_gcc_tree/armv6m-none-eabi/include" // C-ARM-BAREMETAL: "{{.*}}/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/../../../../bin/armv6m-none-eabi-ld" +// C-ARM-BAREMETAL: "--sysroot={{.*}}/Inputs/basic_arm_
[clang] [Driver] Add option to force undefined symbols during linking in BareMetal toolchain object. (PR #132807)
quic-garvgupt wrote: `ToolChain::UnwindLibType ToolChain::GetUnwindLibType( const ArgList &Args) const { if (unwindLibType) return *unwindLibType; const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ); StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;` If the --unwindlib flag is not set to empty explicitly, then it takes whatever it set by `CLANG_DEFAULT_UNWINDLIB`. I think, by adding `--unwindlib= ` to the instance which is failing should fix the issue https://github.com/llvm/llvm-project/pull/132807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix Arm/AArch64 Link Argument tests (PR #144582)
quic-garvgupt wrote: `ToolChain::UnwindLibType ToolChain::GetUnwindLibType( const ArgList &Args) const { if (unwindLibType) return *unwindLibType; const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ); StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;` If --unwindlib= is not set to empty explicitly, then `CLANG_DEFAULT_UNWINDLIB` overrides. I think, adding `--unwindlib=`, might fix the tests. https://github.com/llvm/llvm-project/pull/144582 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add option to force undefined symbols during linking in BareMetal toolchain object. (PR #132807)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/132807 >From 7f26ac995e18f71ec8bccdb5b39be95bf629da19 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Mon, 24 Mar 2025 06:49:09 -0700 Subject: [PATCH] [Driver] Add option to force udnefined symbols during linking in BareMetal toolchain object. Add support for `-u` option to force defined symbols. This option is supported by both lld and gnuld. This is done as a part of the effort to merge RISCVToolchain object into BareMetal toolchain object. This is the 4th patch in the series of patches for merging RISCVToolchain object into BareMetal toolchain object. RFC: https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 Change-Id: Ia6597c756923a77fd9c7cb9a6ae8e52a56f5457d --- clang/lib/Driver/ToolChains/BareMetal.cpp | 5 +++-- clang/test/Driver/baremetal-undefined-symbols.c | 14 ++ clang/test/Driver/riscv-args.c | 6 -- 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 clang/test/Driver/baremetal-undefined-symbols.c delete mode 100644 clang/test/Driver/riscv-args.c diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index a665040662a3f..d4e4e6d04b417 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -609,8 +609,9 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, } } - Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, -options::OPT_s, options::OPT_t, options::OPT_r}); + Args.addAllArgs(CmdArgs, + {options::OPT_L, options::OPT_u, options::OPT_T_Group, + options::OPT_s, options::OPT_t, options::OPT_r}); TC.AddFilePathLibArgs(Args, CmdArgs); diff --git a/clang/test/Driver/baremetal-undefined-symbols.c b/clang/test/Driver/baremetal-undefined-symbols.c new file mode 100644 index 0..bff58c7c54c33 --- /dev/null +++ b/clang/test/Driver/baremetal-undefined-symbols.c @@ -0,0 +1,14 @@ +// Check the arguments are correctly passed + +// Make sure -T is the last with gcc-toolchain option +// RUN: %clang -### --target=riscv32 --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds -u foo %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-LD %s +// CHECK-LD: {{.*}} "--defsym=FOO=10" {{.*}} "-u" "foo" {{.*}} "-T" "a.lds" + +// TODO: Merge this test with the above in the last patch when finally integrating riscv +// Make sure -T is the last with gcc-toolchain option +// RUN: %clang -### --target=aarch64-none-elf --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds -u foo %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ARM-LD %s +// RUN: %clang -### --target=armv6m-none-eabi --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds -u foo %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ARM-LD %s +// CHECK-ARM-LD: {{.*}} "-T" "a.lds" "-u" "foo" {{.*}} "--defsym=FOO=10" diff --git a/clang/test/Driver/riscv-args.c b/clang/test/Driver/riscv-args.c deleted file mode 100644 index cab08e5b0f811..0 --- a/clang/test/Driver/riscv-args.c +++ /dev/null @@ -1,6 +0,0 @@ -// Check the arguments are correctly passed - -// Make sure -T is the last with gcc-toolchain option -// RUN: %clang -### --target=riscv32 --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds -u foo %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-LD %s -// CHECK-LD: {{.*}} "--defsym=FOO=10" {{.*}} "-u" "foo" {{.*}} "-T" "a.lds" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix link order of BareMetal toolchain object (PR #132806)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/132806 >From fa8aad1e9df9b21696fea33de4678a809a13367c Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Mon, 24 Mar 2025 06:17:42 -0700 Subject: [PATCH] [Driver] Fix link order of BareMetal toolchain object The linker job in BareMetal toolchain object will be used by gnuld and lld both. However, gnuld process the arguments in the order in which they appear on command line, whereas there is no such restriction with lld. The previous order was: LibraryPaths -> Libraries -> LTOOptions -> LinkerInputs The new iorder is: LibraryPaths -> LTOOptions -> LinkerInputs -> Libraries LTO options need to be added before adding any linker inputs because file format after compile stage during LTO is bitcode which gnuld natively cannot process. Hence iwill need to pass appropriate plugins before adding any bitcode file on the command line. Object files that are getting linked need to be passed before processing any libraries so that gnuld can appropriately do symbol resolution for the symbols for which no definition is provided through user code. Similar link order is also followed by other linker jobs for gnuld such as in gnutools::Linker in Gnu.cpp This is the 3rd patch in the series of patches of merging RISCVToolchain into BareMetal toolchain object. RFC: https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 Change-Id: I0e68e403c08b5687cc3346e833981f7b9f3819c4 --- clang/lib/Driver/ToolChains/BareMetal.cpp | 12 ++-- clang/test/Driver/aarch64-toolchain-extra.c | 2 +- clang/test/Driver/aarch64-toolchain.c | 28 clang/test/Driver/arm-toolchain-extra.c | 2 +- clang/test/Driver/arm-toolchain.c | 28 clang/test/Driver/baremetal-multilib.yaml | 3 +- clang/test/Driver/baremetal-sysroot.cpp | 8 ++- clang/test/Driver/baremetal.cpp | 79 + 8 files changed, 92 insertions(+), 70 deletions(-) diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index a08bb588dd764..a665040662a3f 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -568,8 +568,6 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, const llvm::Triple::ArchType Arch = TC.getArch(); const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); - AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA); - CmdArgs.push_back("-Bstatic"); if (TC.getTriple().isRISCV() && Args.hasArg(options::OPT_mno_relax)) @@ -619,6 +617,12 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, for (const auto &LibPath : TC.getLibraryPaths()) CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-L", LibPath))); + if (D.isUsingLTO()) +addLTOOptions(TC, Args, CmdArgs, Output, Inputs, + D.getLTOMode() == LTOK_Thin); + + AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA); + if (TC.ShouldLinkCXXStdlib(Args)) { bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && !Args.hasArg(options::OPT_static); @@ -639,10 +643,6 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("--end-group"); } - if (D.isUsingLTO()) -addLTOOptions(TC, Args, CmdArgs, Output, Inputs, - D.getLTOMode() == LTOK_Thin); - if ((TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) && NeedCRTs) CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTEnd))); diff --git a/clang/test/Driver/aarch64-toolchain-extra.c b/clang/test/Driver/aarch64-toolchain-extra.c index 2a930e35acd45..a0b5f2902962f 100644 --- a/clang/test/Driver/aarch64-toolchain-extra.c +++ b/clang/test/Driver/aarch64-toolchain-extra.c @@ -31,5 +31,5 @@ // C-AARCH64-BAREMETAL-NOGCC: "{{.*}}/aarch64-nogcc/bin/../aarch64-none-elf/lib/crt0.o" // C-AARCH64-BAREMETAL-NOGCC: "{{.*}}/aarch64-nogcc/{{.*}}/aarch64-none-elf/lib/crtbegin.o" // C-AARCH64-BAREMETAL-NOGCC: "{{.*}}/aarch64-nogcc/bin/../aarch64-none-elf/lib" -// C-AARCH64-BAREMETAL-NOGCC: "--start-group" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgloss" "--end-group" +// C-AARCH64-BAREMETAL-NOGCC: "{{.*}}.o" "--start-group" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgloss" "--end-group" // C-AARCH64-BAREMETAL-NOGCC: "{{.*}}/aarch64-nogcc/{{.*}}/aarch64-none-elf/lib/crtend.o" diff --git a/clang/test/Driver/aarch64-toolchain.c b/clang/test/Driver/aarch64-toolchain.c index 83cd95136b158..e12107fa2c506 100644 --- a/clang/test/Driver/aarch64-toolchain.c +++ b/clang/test/Driver/aarch64-toolchain.c @@ -11,12 +11,12 @@ // LLD-AARCH64-BAREMETAL: "-isysroot" "{{.*}}Inputs/basic_aarch64_gcc_tree/aarch64-none-elf" // LLD-AARCH64-BAREMETAL: "-internal-isystem" "{{.*}}Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include" // LLD-AARCH64-BA
[clang] [Driver] Fix link order of BareMetal toolchain object (PR #132806)
https://github.com/quic-garvgupt closed https://github.com/llvm/llvm-project/pull/132806 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add option to force undefined symbols during linking in BareMetal toolchain object. (PR #132807)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/132807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix Arm/AArch64 Link Argument tests (PR #144582)
quic-garvgupt wrote: > `ToolChain::UnwindLibType ToolChain::GetUnwindLibType( const ArgList &Args) > const { if (unwindLibType) return *unwindLibType; > > const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ); StringRef LibName > = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;` > > If --unwindlib= is not set to empty explicitly, then > `CLANG_DEFAULT_UNWINDLIB` overrides. I think, adding `--unwindlib=`, might > fix the tests. > `ToolChain::UnwindLibType ToolChain::GetUnwindLibType( const ArgList &Args) > const { if (unwindLibType) return *unwindLibType; > > const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ); StringRef LibName > = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;` > > If --unwindlib= is not set to empty explicitly, then > `CLANG_DEFAULT_UNWINDLIB` overrides. I think, adding `--unwindlib=`, might > fix the tests. I revisited the tests and realized that for the ARM and RISC-V targets, the flow goes through `GetDefaultUnwindLibType`, which defaults to `UNW_None`. Explicitly adding `--unwindlib= ` to the failing instance would make the test redundant, as it would no longer validate the intended behavior. Please disregard my earlier comment—I'm aligned with this fix. Thanks for pushing the change! https://github.com/llvm/llvm-project/pull/144582 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #121829)
https://github.com/quic-garvgupt edited https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #121829)
quic-garvgupt wrote: @smithp35 , could you pls parallely also review PR - https://github.com/llvm/llvm-project/pull/121831? I added you as reviewer there as well in the beginning and will appreciate your comments/feedback. Thanks! https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,56 +144,99 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } -BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, - const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); -} - } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); } -/// Is the triple {aarch64.aarch64_be}-none-elf? -static bool isAArch64BareMetal(const llvm::Triple &Triple) { - if (Triple.getArch() != llvm::Triple::aarch64 && - Triple.getArch() != llvm::Triple::aarch64_be) -return false; +// Users can specify their GCC toolchain using `-gcc-install-dir` or +// `--gcc-toolchain`. If no sysroot is explicitly provided, the driver will +// attempt to infer it from the values of the above flags. +// +// If neither flag is used, the sysroot defaults to either: +// - `bin/../` +// - `bin/../lib/clang-runtimes/` +// +// To use the `clang-runtimes` path, ensure that `..//lib/crt0.o` +// does not exist relative to the driver. +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; - if (Triple.getVendor() != llvm::Triple::UnknownVendor) -return false; + const Driver &D = getDriver(); + if (!D.SysRoot.empty()) +return D.SysRoot; - if (Triple.getOS() != llvm::Triple::UnknownOS) -return false; + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { +StringRef LibDir = GCCInstallation.getParentLibPath(); +StringRef TripleStr = GCCInstallation.getTriple().str(); +llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr); + } else if (hasGCCToolChainAlongSideClang(D)) { +// 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, D.Dir, "..", D.getTargetTriple()); + } - return Triple.getEnvironmentName() == "elf"; + if (llvm::sys::fs::exists(SysRootDir)) quic-garvgupt wrote: Done https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,56 +144,99 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } -BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, - const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); -} - } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); } -/// Is the triple {aarch64.aarch64_be}-none-elf? -static bool isAArch64BareMetal(const llvm::Triple &Triple) { - if (Triple.getArch() != llvm::Triple::aarch64 && - Triple.getArch() != llvm::Triple::aarch64_be) -return false; +// Users can specify their GCC toolchain using `-gcc-install-dir` or +// `--gcc-toolchain`. If no sysroot is explicitly provided, the driver will +// attempt to infer it from the values of the above flags. +// +// If neither flag is used, the sysroot defaults to either: +// - `bin/../` +// - `bin/../lib/clang-runtimes/` +// +// To use the `clang-runtimes` path, ensure that `..//lib/crt0.o` +// does not exist relative to the driver. +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; - if (Triple.getVendor() != llvm::Triple::UnknownVendor) -return false; + const Driver &D = getDriver(); + if (!D.SysRoot.empty()) +return D.SysRoot; - if (Triple.getOS() != llvm::Triple::UnknownOS) -return false; + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { +StringRef LibDir = GCCInstallation.getParentLibPath(); +StringRef TripleStr = GCCInstallation.getTriple().str(); +llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr); + } else if (hasGCCToolChainAlongSideClang(D)) { +// 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, D.Dir, "..", D.getTargetTriple()); + } - return Triple.getEnvironmentName() == "elf"; + if (llvm::sys::fs::exists(SysRootDir)) +return std::string(SysRootDir); + return computeBaseSysRoot(D, /*IncludeTriple*/ true); } -static bool isRISCVBareMetal(const llvm::Triple &Triple) { - if (!Triple.isRISCV()) -return false; - - if (Triple.getVendor() != llvm::Triple::UnknownVendor) -return false; - - if (Triple.getOS() != llvm::Triple::UnknownOS) -return false; - - return Triple.getEnvironmentName() == "elf"; +static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, + const Multilib &Multilib, + StringRef InstallPath, + ToolChain::path_list &Paths) { + if (const auto &PathsCallback = Multilibs.filePathsCallback()) +for (const auto &Path : PathsCallback(Multilib)) + addPathIfExists(D, InstallPath + Path, Paths); } -/// Is the triple powerpc[64][le]-*-none-eabi? -static bool isPPCBareMetal(const llvm::Triple &Triple) { - return Triple.isPPC() && Triple.getOS() == llvm::Triple::UnknownOS && - Triple.getEnvironment() == llvm::Triple::EABI; +// GCC mutltilibs will only work for those targets that have their multlib +// structure encoded into GCCInstallation. Baremetal toolchain support ARM, quic-garvgupt wrote: Done https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,56 +144,99 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } -BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, - const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); -} - } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); } -/// Is the triple {aarch64.aarch64_be}-none-elf? -static bool isAArch64BareMetal(const llvm::Triple &Triple) { - if (Triple.getArch() != llvm::Triple::aarch64 && - Triple.getArch() != llvm::Triple::aarch64_be) -return false; +// Users can specify their GCC toolchain using `-gcc-install-dir` or +// `--gcc-toolchain`. If no sysroot is explicitly provided, the driver will quic-garvgupt wrote: Done https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,56 +144,99 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } -BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, - const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); -} - } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); } -/// Is the triple {aarch64.aarch64_be}-none-elf? -static bool isAArch64BareMetal(const llvm::Triple &Triple) { - if (Triple.getArch() != llvm::Triple::aarch64 && - Triple.getArch() != llvm::Triple::aarch64_be) -return false; +// Users can specify their GCC toolchain using `-gcc-install-dir` or +// `--gcc-toolchain`. If no sysroot is explicitly provided, the driver will +// attempt to infer it from the values of the above flags. +// +// If neither flag is used, the sysroot defaults to either: +// - `bin/../` +// - `bin/../lib/clang-runtimes/` +// +// To use the `clang-runtimes` path, ensure that `..//lib/crt0.o` +// does not exist relative to the driver. +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; - if (Triple.getVendor() != llvm::Triple::UnknownVendor) -return false; + const Driver &D = getDriver(); + if (!D.SysRoot.empty()) +return D.SysRoot; - if (Triple.getOS() != llvm::Triple::UnknownOS) -return false; + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { +StringRef LibDir = GCCInstallation.getParentLibPath(); +StringRef TripleStr = GCCInstallation.getTriple().str(); +llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr); + } else if (hasGCCToolChainAlongSideClang(D)) { +// 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, D.Dir, "..", D.getTargetTriple()); + } - return Triple.getEnvironmentName() == "elf"; + if (llvm::sys::fs::exists(SysRootDir)) +return std::string(SysRootDir); + return computeBaseSysRoot(D, /*IncludeTriple*/ true); } -static bool isRISCVBareMetal(const llvm::Triple &Triple) { - if (!Triple.isRISCV()) -return false; - - if (Triple.getVendor() != llvm::Triple::UnknownVendor) -return false; - - if (Triple.getOS() != llvm::Triple::UnknownOS) -return false; - - return Triple.getEnvironmentName() == "elf"; +static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, + const Multilib &Multilib, + StringRef InstallPath, + ToolChain::path_list &Paths) { + if (const auto &PathsCallback = Multilibs.filePathsCallback()) +for (const auto &Path : PathsCallback(Multilib)) + addPathIfExists(D, InstallPath + Path, Paths); } -/// Is the triple powerpc[64][le]-*-none-eabi? -static bool isPPCBareMetal(const llvm::Triple &Triple) { - return Triple.isPPC() && Triple.getOS() == llvm::Triple::UnknownOS && - Triple.getEnvironment() == llvm::Triple::EABI; +// GCC mutltilibs will only work for those targets that have their multlib +// structure encoded into GCCInstallation. Baremetal toolchain support ARM, +// AArch64, RISCV and PPC and of them only RISCV have GCC multilibs hardcoded +// in GCCInstallation. +BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, + const ArgList &Args) +: Generic_ELF(D, Triple, Args) { + GCCInstallation.init(Triple, Args); + SysRoot = computeSysRoot(); + if (GCCInstallation.isValid()) { +if (!isRISCVBareMetal(Triple)) + D.Diag(clang::diag::warn_drv_multilib_not_available_for_target); +Multilibs = GCCInstallation.getMultilibs(); +SelectedMultilibs.assign({GCCInstallation.getMultilib()}); +path_list &Paths = getFilePaths(); +// Add toolchain/multilib specific file paths. +addMultilibsFilePaths(D, Multilibs, SelectedMultilibs.back(), + GCCInstallation.getInstallPath(), Paths); +getFilePaths().push_back(GCCInstallation.getInstallPath().str()); +ToolChain::path
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,20 +110,81 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); +} + +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; + + const Driver &D = getDriver(); + if (!D.SysRoot.empty()) +return D.SysRoot; + + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { +StringRef LibDir = GCCInstallation.getParentLibPath(); +StringRef TripleStr = GCCInstallation.getTriple().str(); +llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr); + } else if (hasGCCToolChainAlongSideClang(D)) { +// 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, D.Dir, "..", D.getTargetTriple()); + } + + if (llvm::sys::fs::exists(SysRootDir)) +return std::string(SysRootDir); + return computeBaseSysRoot(D, /*IncludeTriple*/ true); +} + +static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, + const Multilib &Multilib, + StringRef InstallPath, + ToolChain::path_list &Paths) { + if (const auto &PathsCallback = Multilibs.filePathsCallback()) +for (const auto &Path : PathsCallback(Multilib)) + addPathIfExists(D, InstallPath + Path, Paths); +} + BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); +: Generic_ELF(D, Triple, Args) { + GCCInstallation.init(Triple, Args); + SysRoot = computeSysRoot(); + if (GCCInstallation.isValid()) { +Multilibs = GCCInstallation.getMultilibs(); +SelectedMultilibs.assign({GCCInstallation.getMultilib()}); +path_list &Paths = getFilePaths(); +// Add toolchain/multilib specific file paths. +addMultilibsFilePaths(D, Multilibs, SelectedMultilibs.back(), + GCCInstallation.getInstallPath(), Paths); +getFilePaths().push_back(GCCInstallation.getInstallPath().str()); +ToolChain::path_list &PPaths = getProgramPaths(); +// Multilib cross-compiler GCC installations put ld in a triple-prefixed +// directory off of the parent of the GCC installation. +PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + + GCCInstallation.getTriple().str() + "/bin") + .str()); +PPaths.push_back((GCCInstallation.getParentLibPath() + "/../bin").str()); +getFilePaths().push_back(SysRoot + "/lib"); + } else { quic-garvgupt wrote: The crt0.o files are located in the `bin/..//lib/crt0.o` directory, so this path is explicitly added. I've refactored the code to group all file path additions together, followed by program path additions, to make the logic easier to review. Each section is now clearly commented to explain the purpose of the paths https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
quic-garvgupt wrote: > I've done another review pass. Mostly some small stylistic comments. > > I'm finding it difficult to follow the code with the various different > code-paths with similar names. I've made some suggestions on renaming. We may > also be able to add some more comments to make it clearer. I've made few more refactoring changes in addition to suggestion to improve code readability and facilitate the review process: - Renamed the function from `hasGCCToolchainAlongSideClang` to `detectGCCToolchainAdjacent`, and added a comment explaining its purpose. (Pls let me know if there is need for a `fixme` or `todo` here to remove/fix this logic in future.) - In the `computeSysRoot` function, renamed the local variable `SysRootDir` to `inferredSysRoot` for better clarity, and added additional comments to explain the logic. - In the constructor, grouped all file path additions together and all program path additions together, with comments explaining the rationale behind each block. https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/121829 >From 0ffc48d7367a37a9a02333456a9dbfc20ab9e71f 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/docs/Toolchain.rst | 5 + .../clang/Basic/DiagnosticDriverKinds.td | 3 + clang/lib/Driver/ToolChains/BareMetal.cpp | 226 +- clang/lib/Driver/ToolChains/BareMetal.h | 15 +- .../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-gnutools.c | 4 + clang/test/Driver/aarch64-toolchain-extra.c | 28 +++ clang/test/Driver/aarch64-toolchain.c | 61 + clang/test/Driver/arm-gnutools.c | 6 + clang/test/Driver/arm-toolchain-extra.c | 29 +++ clang/test/Driver/arm-toolchain.c | 62 + clang/test/Driver/baremetal.cpp | 16 ++ clang/test/Driver/check-no-multlib-warning.c | 10 + 32 files changed, 405 insertions(+), 64 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/t
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,56 +144,99 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } -BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, - const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); -} - } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); } -/// Is the triple {aarch64.aarch64_be}-none-elf? -static bool isAArch64BareMetal(const llvm::Triple &Triple) { - if (Triple.getArch() != llvm::Triple::aarch64 && - Triple.getArch() != llvm::Triple::aarch64_be) -return false; +// Users can specify their GCC toolchain using `-gcc-install-dir` or +// `--gcc-toolchain`. If no sysroot is explicitly provided, the driver will +// attempt to infer it from the values of the above flags. +// +// If neither flag is used, the sysroot defaults to either: +// - `bin/../` +// - `bin/../lib/clang-runtimes/` +// +// To use the `clang-runtimes` path, ensure that `..//lib/crt0.o` +// does not exist relative to the driver. +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; - if (Triple.getVendor() != llvm::Triple::UnknownVendor) -return false; + const Driver &D = getDriver(); + if (!D.SysRoot.empty()) +return D.SysRoot; - if (Triple.getOS() != llvm::Triple::UnknownOS) -return false; + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { +StringRef LibDir = GCCInstallation.getParentLibPath(); +StringRef TripleStr = GCCInstallation.getTriple().str(); +llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr); + } else if (hasGCCToolChainAlongSideClang(D)) { +// 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, D.Dir, "..", D.getTargetTriple()); + } - return Triple.getEnvironmentName() == "elf"; + if (llvm::sys::fs::exists(SysRootDir)) +return std::string(SysRootDir); + return computeBaseSysRoot(D, /*IncludeTriple*/ true); } -static bool isRISCVBareMetal(const llvm::Triple &Triple) { - if (!Triple.isRISCV()) -return false; - - if (Triple.getVendor() != llvm::Triple::UnknownVendor) -return false; - - if (Triple.getOS() != llvm::Triple::UnknownOS) -return false; - - return Triple.getEnvironmentName() == "elf"; +static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, + const Multilib &Multilib, + StringRef InstallPath, + ToolChain::path_list &Paths) { + if (const auto &PathsCallback = Multilibs.filePathsCallback()) +for (const auto &Path : PathsCallback(Multilib)) + addPathIfExists(D, InstallPath + Path, Paths); } -/// Is the triple powerpc[64][le]-*-none-eabi? -static bool isPPCBareMetal(const llvm::Triple &Triple) { - return Triple.isPPC() && Triple.getOS() == llvm::Triple::UnknownOS && - Triple.getEnvironment() == llvm::Triple::EABI; +// GCC mutltilibs will only work for those targets that have their multlib +// structure encoded into GCCInstallation. Baremetal toolchain support ARM, +// AArch64, RISCV and PPC and of them only RISCV have GCC multilibs hardcoded +// in GCCInstallation. +BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, + const ArgList &Args) +: Generic_ELF(D, Triple, Args) { + GCCInstallation.init(Triple, Args); + SysRoot = computeSysRoot(); quic-garvgupt wrote: > It is possible we may need to cache the SysRoot here. Assuming computeSysRoot > is idempotent it can be done later. Can you expand a bit on where do we need to cache the sysroot. I couldn't understood this comment clearly. https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
@@ -110,56 +144,99 @@ static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) { return std::string(SysRootDir); } -BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple, - const ArgList &Args) -: ToolChain(D, Triple, Args), - SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) { - getProgramPaths().push_back(getDriver().Dir); - - findMultilibs(D, Triple, Args); - SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { -for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.osSuffix(), "lib"); - getFilePaths().push_back(std::string(Dir)); - getLibraryPaths().push_back(std::string(Dir)); -} - } +static bool hasGCCToolChainAlongSideClang(const Driver &D) { + SmallString<128> GCCDir; + llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(), + "lib/crt0.o"); + return llvm::sys::fs::exists(GCCDir); } -/// Is the triple {aarch64.aarch64_be}-none-elf? -static bool isAArch64BareMetal(const llvm::Triple &Triple) { - if (Triple.getArch() != llvm::Triple::aarch64 && - Triple.getArch() != llvm::Triple::aarch64_be) -return false; +// Users can specify their GCC toolchain using `-gcc-install-dir` or +// `--gcc-toolchain`. If no sysroot is explicitly provided, the driver will +// attempt to infer it from the values of the above flags. +// +// If neither flag is used, the sysroot defaults to either: +// - `bin/../` +// - `bin/../lib/clang-runtimes/` +// +// To use the `clang-runtimes` path, ensure that `..//lib/crt0.o` +// does not exist relative to the driver. +std::string BareMetal::computeSysRoot() const { + if (!SysRoot.empty()) +return SysRoot; - if (Triple.getVendor() != llvm::Triple::UnknownVendor) -return false; + const Driver &D = getDriver(); + if (!D.SysRoot.empty()) +return D.SysRoot; - if (Triple.getOS() != llvm::Triple::UnknownOS) -return false; + // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or + // alongside clang. If valid, form the sysroot. Otherwise, check + // lib/clang-runtimes above the driver. + SmallString<128> SysRootDir; + if (GCCInstallation.isValid()) { +StringRef LibDir = GCCInstallation.getParentLibPath(); quic-garvgupt wrote: Done https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/121829 >From c4d61f3eafe108d705a67a9b8b7ca640119afe78 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/docs/Toolchain.rst | 5 + .../clang/Basic/DiagnosticDriverKinds.td | 3 + clang/lib/Driver/ToolChains/BareMetal.cpp | 227 +- clang/lib/Driver/ToolChains/BareMetal.h | 15 +- .../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-gnutools.c | 4 + clang/test/Driver/aarch64-toolchain-extra.c | 28 +++ clang/test/Driver/aarch64-toolchain.c | 61 + clang/test/Driver/arm-gnutools.c | 6 + clang/test/Driver/arm-toolchain-extra.c | 29 +++ clang/test/Driver/arm-toolchain.c | 62 + clang/test/Driver/baremetal.cpp | 16 ++ clang/test/Driver/check-no-multlib-warning.c | 10 + 32 files changed, 405 insertions(+), 65 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/t
[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)
quic-garvgupt wrote: Hi @petrhosek, while petrsmith is reviewing this PR, if you don’t have any further suggestions, comments, or feedback, could you please provide an LGTM? That would help us proceed with merging the PR promptly once petr approves it. Thanks so much! https://github.com/llvm/llvm-project/pull/121829 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #145390)
https://github.com/quic-garvgupt created https://github.com/llvm/llvm-project/pull/145390 This patch introduces enhancements to the Baremetal toolchain to support GCC toolchain detection. - If the --gcc-install-dir or --gcc-toolchain options are provided and point to valid paths, the sysroot is derived from those locations. - If not, the logic falls back to the existing sysroot inference mechanism already present in the Baremetal toolchain. - Support for adding include paths for the libstdc++ library has also been added. Additionally, the restriction to always use the integrated assembler has been removed. With a valid GCC installation, the GNU assembler can now be used as well. This patch currently updates and adds tests for the ARM target only. RISC-V-specific tests will be introduced in a later patch, once the RISCVToolChain is fully merged into the Baremetal toolchain. At this stage, there is no way to test the RISC-V target within this PR. RFC: https: //discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 >From a9ad8f0f10fa7e62116598c1d6a867480e187fab Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Tue, 17 Jun 2025 21:43:17 +0530 Subject: [PATCH] [Driver] Add support for GCC installation detection in Baremetal toolchain (#121829) This patch introduces enhancements to the Baremetal toolchain to support GCC toolchain detection. - If the --gcc-install-dir or --gcc-toolchain options are provided and point to valid paths, the sysroot is derived from those locations. - If not, the logic falls back to the existing sysroot inference mechanism already present in the Baremetal toolchain. - Support for adding include paths for the libstdc++ library has also been added. Additionally, the restriction to always use the integrated assembler has been removed. With a valid GCC installation, the GNU assembler can now be used as well. This patch currently updates and adds tests for the ARM target only. RISC-V-specific tests will be introduced in a later patch, once the RISCVToolChain is fully merged into the Baremetal toolchain. At this stage, there is no way to test the RISC-V target within this PR. RFC: https: //discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 Change-Id: I70021d8d1972a6c4940f04a2eb8b5ffdbfbfc49b --- clang/docs/Toolchain.rst | 5 + .../clang/Basic/DiagnosticDriverKinds.td | 3 + clang/lib/Driver/ToolChains/BareMetal.cpp | 235 +- clang/lib/Driver/ToolChains/BareMetal.h | 19 +- .../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-gnutools.c | 4 + clang/test/Driver/aarch64-toolchain-extra.c | 28 +++ clang/test/Driver/aarch64-toolchain.c | 61 + clang/test/Driver/arm-gnutools.c | 6 + clang/test/Driver/arm-toolchain-extra.c | 29 +++ clang/test/Driver/arm-toolchain.c | 62 + clang/test/Driver/baremetal.cpp | 16 ++ clang/test/Driver/check-no-multlib-warning.c | 10 + 32 files changed, 418 insertions(+), 64 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/basi
[clang] Reland [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (PR #144649)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/144649 >From 296df79cb9e9696daa926267c8a9a853930fdc46 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Tue, 17 Jun 2025 21:43:17 +0530 Subject: [PATCH 1/2] Reland [Driver] Add support for GCC installation detection in Baremetal toolchain This patch introduces enhancements to the Baremetal toolchain to support GCC toolchain detection. - If the --gcc-install-dir or --gcc-toolchain options are provided and point to valid paths, the sysroot is derived from those locations. - If not, the logic falls back to the existing sysroot inference mechanism already present in the Baremetal toolchain. - Support for adding include paths for the libstdc++ library has also been added. Additionally, the restriction to always use the integrated assembler has been removed. With a valid GCC installation, the GNU assembler can now be used as well. This patch currently updates and adds tests for the ARM target only. RISC-V-specific tests will be introduced in a later patch, once the RISCVToolChain is fully merged into the Baremetal toolchain. At this stage, there is no way to test the RISC-V target within this PR. RFC: https: //discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 This PR include fixes to tests which were failing on fuchsia builders Change-Id: I5cd1d949297fee025b62ea6037c554bd4a0eeda1 --- clang/docs/Toolchain.rst | 5 + .../clang/Basic/DiagnosticDriverKinds.td | 3 + clang/lib/Driver/ToolChains/BareMetal.cpp | 235 +- clang/lib/Driver/ToolChains/BareMetal.h | 19 +- .../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-gnutools.c | 4 + clang/test/Driver/aarch64-toolchain-extra.c | 28 +++ clang/test/Driver/aarch64-toolchain.c | 61 + clang/test/Driver/arm-gnutools.c | 6 + clang/test/Driver/arm-toolchain-extra.c | 29 +++ clang/test/Driver/arm-toolchain.c | 62 + clang/test/Driver/baremetal.cpp | 16 ++ clang/test/Driver/check-no-multlib-warning.c | 10 + 32 files changed, 418 insertions(+), 64 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
[clang] Reland [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (PR #144649)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/144649 >From 296df79cb9e9696daa926267c8a9a853930fdc46 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Tue, 17 Jun 2025 21:43:17 +0530 Subject: [PATCH 1/2] Reland [Driver] Add support for GCC installation detection in Baremetal toolchain This patch introduces enhancements to the Baremetal toolchain to support GCC toolchain detection. - If the --gcc-install-dir or --gcc-toolchain options are provided and point to valid paths, the sysroot is derived from those locations. - If not, the logic falls back to the existing sysroot inference mechanism already present in the Baremetal toolchain. - Support for adding include paths for the libstdc++ library has also been added. Additionally, the restriction to always use the integrated assembler has been removed. With a valid GCC installation, the GNU assembler can now be used as well. This patch currently updates and adds tests for the ARM target only. RISC-V-specific tests will be introduced in a later patch, once the RISCVToolChain is fully merged into the Baremetal toolchain. At this stage, there is no way to test the RISC-V target within this PR. RFC: https: //discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 This PR include fixes to tests which were failing on fuchsia builders Change-Id: I5cd1d949297fee025b62ea6037c554bd4a0eeda1 --- clang/docs/Toolchain.rst | 5 + .../clang/Basic/DiagnosticDriverKinds.td | 3 + clang/lib/Driver/ToolChains/BareMetal.cpp | 235 +- clang/lib/Driver/ToolChains/BareMetal.h | 19 +- .../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-gnutools.c | 4 + clang/test/Driver/aarch64-toolchain-extra.c | 28 +++ clang/test/Driver/aarch64-toolchain.c | 61 + clang/test/Driver/arm-gnutools.c | 6 + clang/test/Driver/arm-toolchain-extra.c | 29 +++ clang/test/Driver/arm-toolchain.c | 62 + clang/test/Driver/baremetal.cpp | 16 ++ clang/test/Driver/check-no-multlib-warning.c | 10 + 32 files changed, 418 insertions(+), 64 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
[clang] Reland [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (PR #144649)
https://github.com/quic-garvgupt updated https://github.com/llvm/llvm-project/pull/144649 >From 22fca1c6a0a9fd26509720800a0244e824effc41 Mon Sep 17 00:00:00 2001 From: Garvit Gupta Date: Tue, 17 Jun 2025 22:49:55 +0530 Subject: [PATCH] [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (#121830) This patch conditionalise the addition of crt{begin,end}.o object files along with addition of -lgloss lib based on whether libc selected is newlib or llvm libc. Since there is no way a user can specify which libc it wants to link against, currently passing valid GCCInstallation to driver will select newlib otherwise it will default to llvm libc. Moreover, this patch makes gnuld the default linker for baremetal toolchain object. User need to pass `-fuse-ld=lld` explicitly to driver to select lld This is the 2nd patch in the series of patches of merging RISCVToolchain into BareMetal toolchain object. RFC: https: //discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524 Change-Id: If4445eb8074473238191d9c837f67dd8cc0f9dc4 --- clang/lib/Driver/ToolChains/BareMetal.cpp | 37 - clang/lib/Driver/ToolChains/BareMetal.h | 6 +- clang/test/Driver/aarch64-toolchain-extra.c | 35 + clang/test/Driver/aarch64-toolchain.c | 156 +++ clang/test/Driver/arm-toolchain-extra.c | 36 + clang/test/Driver/arm-toolchain.c | 157 clang/test/Driver/baremetal.cpp | 3 +- clang/test/Driver/sanitizer-ld.c| 2 +- 8 files changed, 423 insertions(+), 9 deletions(-) create mode 100644 clang/test/Driver/aarch64-toolchain-extra.c create mode 100644 clang/test/Driver/aarch64-toolchain.c create mode 100644 clang/test/Driver/arm-toolchain-extra.c create mode 100644 clang/test/Driver/arm-toolchain.c diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index d8168ed15febd..6abe537d92d12 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -471,9 +471,31 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL"); } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, - options::OPT_r)) { -CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o"))); + bool NeedCRTs = + !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles); + + const char *CRTBegin, *CRTEnd; + if (NeedCRTs) { +if (!Args.hasArg(options::OPT_r)) + CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o"))); +if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) { + auto RuntimeLib = TC.GetRuntimeLibType(Args); + switch (RuntimeLib) { + case (ToolChain::RLT_Libgcc): { +CRTBegin = "crtbegin.o"; +CRTEnd = "crtend.o"; +break; + } + case (ToolChain::RLT_CompilerRT): { +CRTBegin = +TC.getCompilerRTArgString(Args, "crtbegin", ToolChain::FT_Object); +CRTEnd = +TC.getCompilerRTArgString(Args, "crtend", ToolChain::FT_Object); +break; + } + } + CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTBegin))); +} } Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, @@ -496,15 +518,22 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, } if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { +CmdArgs.push_back("--start-group"); AddRunTimeLibs(TC, D, CmdArgs, Args); - CmdArgs.push_back("-lc"); +if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) + CmdArgs.push_back("-lgloss"); +CmdArgs.push_back("--end-group"); } if (D.isUsingLTO()) addLTOOptions(TC, Args, CmdArgs, Output, Inputs, D.getLTOMode() == LTOK_Thin); + if ((TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) && + NeedCRTs) +CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTEnd))); + if (TC.getTriple().isRISCV()) CmdArgs.push_back("-X"); diff --git a/clang/lib/Driver/ToolChains/BareMetal.h b/clang/lib/Driver/ToolChains/BareMetal.h index f6295bda0a6a2..8e3799aff8e02 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.h +++ b/clang/lib/Driver/ToolChains/BareMetal.h @@ -35,7 +35,9 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain { Tool *buildStaticLibTool() const override; public: - bool useIntegratedAs() const override { return true; } + bool initGCCInstallation(const llvm::Triple &Triple, + const llvm::opt::ArgList &Args); + bool hasValidGCCInstallation() const { return IsGCCInstallationValid; } bool isBareMetal() const override { return true; } bool isCrossCompiling() const override { return true; } bool HasNativeLLVMSupport() const o