[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-11 Thread YunQiang Su via cfe-commits

wzssyqa wrote:


> It's better to do some normalization in CMake.

I will try to work in CMake, then.

https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-11 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay closed 
https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-11 Thread Fangrui Song via cfe-commits

MaskRay wrote:

```
cmake -Sllvm -B/tmp/out/d-a64 -G Ninja 
-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu -DLLVM_USE_LINKER=lld 
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libunwind" 
-DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_C_COMPILER=~/Stable/bin/clang 
-DCMAKE_CXX_COMPILER=~/Stable/bin/clang++ -DCMAKE_BUILD_TYPE=Debug
ninja -C /tmp/out/d-a64 builtins
```
gives me `/tmp/out/d-a64/lib/clang/19/lib/aarch64-linux-gnu/clang_rt.*`. 
Sanitizer targets are not available. I haven't investigated why.

Anyhow, I posted a similar but probably more complete clang driver patch: 
https://reviews.llvm.org/D110663 , but I concluded that detecting Debian-style 
`x86_64-linux-gnu` is not a good idea. 

It's better to do some normalization in CMake.



https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-11 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

Configure cmd
```
cmake ../llvm -G Ninja -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu 
-DLLVM_USE_LINKER=lld -DLLVM_ENABLE_RUNTIMES="compiler-rt;libunwind" 
-DLLVM_ENABLE_PROJECTS="mlir;clang;clang-tools-extra;lld" 
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ 
-DCMAKE_BUILD_TYPE=RelWithDebInfo
```

Note, in `-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu`,  there is no 
`unknown` aka vendor section.


With this configure, `libclang_rt.builtin.a` is present in 
```
./lib/clang/19/lib/aarch64-linux-gnu/
```

While clang expects it in
   ```
./lib/clang/19/lib/aarch64-unknown-linux-gnu/    Note "unknown"
```

The reason is that in `computeTargetTriple`, the line
```
llvm::Triple Target(llvm::Triple::normalize(TargetTriple));
```
convert the triple to normalize.

https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-10 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Can you provide CMake configure command and the compiler-rt file paths? I am 
not sure we need more changes to clangDriver.

https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-10 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa converted_to_draft 
https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: YunQiang Su (wzssyqa)


Changes

Currently, clang looks for compiler-rt only from the normalized triple subdir. 
While if we are configured with a non-normalized triple with 
-DLLVM_DEFAULT_TARGET_TRIPLE, such as triples without vendor section, clang 
will fail to find compiler_rt.

Let's look for compiler_rt from the subdir with name from --target option, too.

To archive this, we add a new member called Origin to class Triple.

Fixes: #87150.

---
Full diff: https://github.com/llvm/llvm-project/pull/88334.diff


4 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+1) 
- (modified) clang/lib/Driver/ToolChain.cpp (+6) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+6) 
- (modified) llvm/lib/TargetParser/Triple.cpp (+3-3) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e7335a61b10c53..4a0c939039eb31 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -516,6 +516,7 @@ static llvm::Triple computeTargetTriple(const Driver ,
 TargetTriple = A->getValue();
 
   llvm::Triple Target(llvm::Triple::normalize(TargetTriple));
+  Target.setOrigin(TargetTriple);
 
   // GNU/Hurd's triples should have been -hurd-gnu*, but were historically made
   // -gnu* only, and we can not change this, so we have to detect that case as
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 237092ed07e5dc..57f27a61c4060b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -755,6 +755,12 @@ std::optional
 ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   auto getPathForTriple =
   [&](const llvm::Triple ) -> std::optional {
+if (!Triple.getOrigin().empty()) {
+  SmallString<128> Po(BaseDir);
+  llvm::sys::path::append(Po, Triple.getOrigin());
+  if (getVFS().exists(Po))
+return std::string(Po);
+}
 SmallString<128> P(BaseDir);
 llvm::sys::path::append(P, Triple.str());
 if (getVFS().exists(P))
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index f256e2b205a889..a2fc28ada0ca31 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -298,6 +298,8 @@ class Triple {
 private:
   std::string Data;
 
+  StringRef Origin = StringRef();
+
   /// The parsed arch type.
   ArchType Arch{};
 
@@ -425,6 +427,8 @@ class Triple {
 
   const std::string () const { return Data; }
 
+  const StringRef getOrigin() const { return Origin; }
+
   /// Get the architecture (first) component of the triple.
   StringRef getArchName() const;
 
@@ -1058,6 +1062,8 @@ class Triple {
   /// @name Mutators
   /// @{
 
+  void setOrigin(StringRef Orig) { Origin = Orig; };
+
   /// Set the architecture (first) component of the triple to a known type.
   void setArch(ArchType Kind, SubArchType SubArch = NoSubArch);
 
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 624679ff507a7f..ce44903d0f7d70 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -928,9 +928,9 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple ) {
 /// This stores the string representation and parses the various pieces into
 /// enum members.
 Triple::Triple(const Twine )
-: Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
-  Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
-  ObjectFormat(UnknownObjectFormat) {
+: Data(Str.str()), Origin(Str.getSingleStringRef()), Arch(UnknownArch),
+  SubArch(NoSubArch), Vendor(UnknownVendor), OS(UnknownOS),
+  Environment(UnknownEnvironment), ObjectFormat(UnknownObjectFormat) {
   // Do minimal parsing by hand here.
   SmallVector Components;
   StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);

``




https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-10 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/88334

Currently, clang looks for compiler-rt only from the normalized triple subdir. 
While if we are configured with a non-normalized triple with 
-DLLVM_DEFAULT_TARGET_TRIPLE, such as triples without vendor section, clang 
will fail to find compiler_rt.

Let's look for compiler_rt from the subdir with name from --target option, too.

To archive this, we add a new member called Origin to class Triple.

Fixes: #87150.

>From a4d6590cf3cecf90b3914933313749e8aad03210 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Mon, 1 Apr 2024 17:17:08 +0800
Subject: [PATCH] Look for compiler-rt from subdir given by --target

Currently, clang looks for compiler-rt only from the normalized
triple subdir. While if we are configured with a non-normalized
triple with -DLLVM_DEFAULT_TARGET_TRIPLE, such as triples without
vendor section, clang will fail to find compiler_rt.

Let's look for compiler_rt from the subdir with name from --target
option.

To archive this, we add a new member called Origin to class Triple.

Fixes: #87150.
---
 clang/lib/Driver/Driver.cpp | 1 +
 clang/lib/Driver/ToolChain.cpp  | 6 ++
 llvm/include/llvm/TargetParser/Triple.h | 6 ++
 llvm/lib/TargetParser/Triple.cpp| 6 +++---
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e7335a61b10c53..4a0c939039eb31 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -516,6 +516,7 @@ static llvm::Triple computeTargetTriple(const Driver ,
 TargetTriple = A->getValue();
 
   llvm::Triple Target(llvm::Triple::normalize(TargetTriple));
+  Target.setOrigin(TargetTriple);
 
   // GNU/Hurd's triples should have been -hurd-gnu*, but were historically made
   // -gnu* only, and we can not change this, so we have to detect that case as
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 237092ed07e5dc..57f27a61c4060b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -755,6 +755,12 @@ std::optional
 ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   auto getPathForTriple =
   [&](const llvm::Triple ) -> std::optional {
+if (!Triple.getOrigin().empty()) {
+  SmallString<128> Po(BaseDir);
+  llvm::sys::path::append(Po, Triple.getOrigin());
+  if (getVFS().exists(Po))
+return std::string(Po);
+}
 SmallString<128> P(BaseDir);
 llvm::sys::path::append(P, Triple.str());
 if (getVFS().exists(P))
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index f256e2b205a889..a2fc28ada0ca31 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -298,6 +298,8 @@ class Triple {
 private:
   std::string Data;
 
+  StringRef Origin = StringRef();
+
   /// The parsed arch type.
   ArchType Arch{};
 
@@ -425,6 +427,8 @@ class Triple {
 
   const std::string () const { return Data; }
 
+  const StringRef getOrigin() const { return Origin; }
+
   /// Get the architecture (first) component of the triple.
   StringRef getArchName() const;
 
@@ -1058,6 +1062,8 @@ class Triple {
   /// @name Mutators
   /// @{
 
+  void setOrigin(StringRef Orig) { Origin = Orig; };
+
   /// Set the architecture (first) component of the triple to a known type.
   void setArch(ArchType Kind, SubArchType SubArch = NoSubArch);
 
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 624679ff507a7f..ce44903d0f7d70 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -928,9 +928,9 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple ) {
 /// This stores the string representation and parses the various pieces into
 /// enum members.
 Triple::Triple(const Twine )
-: Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
-  Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
-  ObjectFormat(UnknownObjectFormat) {
+: Data(Str.str()), Origin(Str.getSingleStringRef()), Arch(UnknownArch),
+  SubArch(NoSubArch), Vendor(UnknownVendor), OS(UnknownOS),
+  Environment(UnknownEnvironment), ObjectFormat(UnknownObjectFormat) {
   // Do minimal parsing by hand here.
   SmallVector Components;
   StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits