LLVM22 missing bits from upstream

S V <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <CAKDfvLbDA-WvM=D0p6dXVFuBpcTspU_LstSaLCMf2RjMi=iMrg@mail.gmail.com>
Hello, list! Hello, Robert!

Thanks for amazing work on OpenBSD and recent upgrade to LLVM22. I
long awaited it to ease my work on loongarch64 port of OpenBSD.
But I was looking into new src/gnu/llvm and noticed missing bits from
upstream (which is needed to me, that's why I checked it)

base LLVM/clang missing this triples for OpenBSD on loongarch64 arch

https://github.com/llvm/llvm-project/pull/149737

I'll also attach patch that I used to add it to my own src tree

PS BTW, I got cross-tools and many binaries more or less built
already, so if anybody interested in it, feel free to contact me. I'm
prepping first sets of patches now.

-- 
Nerfur Dragon
-==(UDIC)==-
loongarch-clang.patch (application/octet-stream, 10.1 KB)
From 6b9eedcc624316a565cfc4d5eb8c87c67442378f Mon Sep 17 00:00:00 2001
From: "Slava \"nerfur\" Voronzoff" <[email protected]>
Date: Tue, 1 Jul 2025 20:01:34 +0300
Subject: [PATCH 1/9] OpenBSD in Targets.cpp

---
 clang/lib/Basic/Targets.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index af1111a863308..354c72a9eb110 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -752,6 +752,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
     case llvm::Triple::Linux:
       return std::make_unique<LinuxTargetInfo<LoongArch32TargetInfo>>(Triple,
                                                                       Opts);
+    case llvm::Triple::OpenBSD:
+      return std::make_unique<OpenBSDTargetInfo<LoongArch32TargetInfo>>(Triple,
+                                                                        Opts);
     default:
       return std::make_unique<LoongArch32TargetInfo>(Triple, Opts);
     }
@@ -769,6 +772,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
     case llvm::Triple::FreeBSD:
       return std::make_unique<FreeBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
                                                                         Opts);
+    case llvm::Triple::OpenBSD:
+      return std::make_unique<OpenBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
+                                                                        Opts);
     default:
       return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
     }

From f30b4b8d6ff315830de1832bbb103cca3fb19f69 Mon Sep 17 00:00:00 2001
From: "Slava \"nerfur\" Voronzoff" <[email protected]>
Date: Tue, 1 Jul 2025 20:09:57 +0300
Subject: [PATCH 2/9] OpenBSD in OSTargets.h

---
 clang/lib/Basic/Targets/OSTargets.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 5dac699c2bb45..3731937905f0c 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -497,6 +497,7 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
       this->MCountName = "_mcount";
       break;
     case llvm::Triple::riscv64:
+    case llvm::Triple::loongarch64:
       break;
     }
   }

From 60da9e33b4d770eaa2e588643a35d03a2e07c546 Mon Sep 17 00:00:00 2001
From: "Slava \"nerfur\" Voronzoff" <[email protected]>
Date: Tue, 1 Jul 2025 20:12:21 +0300
Subject: [PATCH 3/9] OpenBSD in Targets.cpp

---
 clang/lib/Basic/Targets.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 354c72a9eb110..5d11578893c66 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -752,9 +752,6 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
     case llvm::Triple::Linux:
       return std::make_unique<LinuxTargetInfo<LoongArch32TargetInfo>>(Triple,
                                                                       Opts);
-    case llvm::Triple::OpenBSD:
-      return std::make_unique<OpenBSDTargetInfo<LoongArch32TargetInfo>>(Triple,
-                                                                        Opts);
     default:
       return std::make_unique<LoongArch32TargetInfo>(Triple, Opts);
     }

From 9d5b9c7b8c9081d9dc0542a4b22d2dda1235bb7f Mon Sep 17 00:00:00 2001
From: "Slava \"nerfur\" Voronzoff" <[email protected]>
Date: Tue, 1 Jul 2025 20:19:06 +0300
Subject: [PATCH 4/9] LoongArch on OpenBSD.cpp

---
 clang/lib/Driver/ToolChains/OpenBSD.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 79b1b6960da1f..05d9242a080a9 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -167,6 +167,12 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
       CmdArgs.push_back("--no-relax");
   }
 
+  if (Triple.isLoongArch64()) {
+    CmdArgs.push_back("-X");
+    if (Args.hasArg(options::OPT_mno_relax))
+      CmdArgs.push_back("--no-relax");
+  }
+  
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
     CmdArgs.push_back("-o");

From d1a94a51df2c73458e901d2ca3f124307c8fbdcd Mon Sep 17 00:00:00 2001
From: "Slava \"nerfur\" Voronzoff" <[email protected]>
Date: Tue, 8 Jul 2025 16:18:38 +0300
Subject: [PATCH 5/9] Openbsd loongarch on openbsd.c

---
 clang/test/Driver/openbsd.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 6639e9d2d9d67..0c76249143214 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -29,6 +29,19 @@
 // CHECK-MIPS64-CPU: "-target-cpu" "mips3"
 // CHECK-MIPS64EL-CPU: "-target-cpu" "mips3"
 
+// Check that LoongArch passes the correct linker emulation.
+//
+// RUN: %clang --target=loongarch64-unknown-openbsd -### %s %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LA64-LD %s
+// CHECK-LA64-LD: ld{{.*}}" {{.*}} "-m" "elf64loongarch"
+//
+// Check options passed to the linker on LoongArch
+//
+// RUN: %clang --target=loongarch64-unknown-openbsd -mno-relax -### %s %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LA64-LD-OPTS %s
+// CHECK-LA64-LD-OPTS: ld{{.*}}" {{.*}} "-X" "--no-relax"
+//
+
 // Check that the new linker flags are passed to OpenBSD
 // RUN: %clang --target=i686-pc-openbsd -r -### %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-R %s

From 804f99296657ca2d071c3428ca74475ded1b6e39 Mon Sep 17 00:00:00 2001
From: "Slava \"nerfur\" Voronzoff" <[email protected]>
Date: Tue, 22 Jul 2025 06:24:45 +0300
Subject: [PATCH 6/9] sorting targets

---
 clang/lib/Basic/Targets/OSTargets.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 7f55b1dcd42f4..94b018a0751d1 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -496,8 +496,8 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
     case llvm::Triple::sparcv9:
       this->MCountName = "_mcount";
       break;
-    case llvm::Triple::riscv64:
     case llvm::Triple::loongarch64:
+    case llvm::Triple::riscv64:
       break;
     }
   }

From e37644202e3b4b3f21c6dad023abed53a486be76 Mon Sep 17 00:00:00 2001
From: "Slava \"nerfur\" Voronzoff" <[email protected]>
Date: Tue, 22 Jul 2025 06:29:35 +0300
Subject: [PATCH 7/9] join loongarch64 and riscv64 no-relax

---
 clang/lib/Driver/ToolChains/OpenBSD.cpp | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 05d9242a080a9..b66fa223c3683 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -161,13 +161,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   if (Nopie || Profiling)
     CmdArgs.push_back("-nopie");
 
-  if (Triple.isRISCV64()) {
-    CmdArgs.push_back("-X");
-    if (Args.hasArg(options::OPT_mno_relax))
-      CmdArgs.push_back("--no-relax");
-  }
-
-  if (Triple.isLoongArch64()) {
+  if (Triple.isLoongArch64() || Triple.isRISCV64()) {
     CmdArgs.push_back("-X");
     if (Args.hasArg(options::OPT_mno_relax))
       CmdArgs.push_back("--no-relax");

From f4272666dd2a0d131183bcb4687041c3e9440ff3 Mon Sep 17 00:00:00 2001
From: "Slava \"nerfur\" Voronzoff" <[email protected]>
Date: Tue, 22 Jul 2025 06:49:11 +0300
Subject: [PATCH 8/9] joining --no-relax test with riscv64

---
 clang/test/Driver/openbsd.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 0c76249143214..1f12cfca9488b 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -29,19 +29,6 @@
 // CHECK-MIPS64-CPU: "-target-cpu" "mips3"
 // CHECK-MIPS64EL-CPU: "-target-cpu" "mips3"
 
-// Check that LoongArch passes the correct linker emulation.
-//
-// RUN: %clang --target=loongarch64-unknown-openbsd -### %s %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-LA64-LD %s
-// CHECK-LA64-LD: ld{{.*}}" {{.*}} "-m" "elf64loongarch"
-//
-// Check options passed to the linker on LoongArch
-//
-// RUN: %clang --target=loongarch64-unknown-openbsd -mno-relax -### %s %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-LA64-LD-OPTS %s
-// CHECK-LA64-LD-OPTS: ld{{.*}}" {{.*}} "-X" "--no-relax"
-//
-
 // Check that the new linker flags are passed to OpenBSD
 // RUN: %clang --target=i686-pc-openbsd -r -### %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-R %s
@@ -140,9 +127,12 @@
 // UNWIND-TABLES: "-funwind-tables=2"
 // NO-UNWIND-TABLES-NOT: "-funwind-tables=2"
 
-// Check that the -X and --no-relax flags are passed to the linker on riscv64
+// Check that the -X and --no-relax flags are passed to the linker
+// RUN: %clang --target=loongarch64-unknown-openbsd -mno-relax -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=LA64-FLAGS %s
 // RUN: %clang --target=riscv64-unknown-openbsd -mno-relax -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=RISCV64-FLAGS %s
+// LA64-FLAGS: "-X" "--no-relax"
 // RISCV64-FLAGS: "-X" "--no-relax"
 
 // Check passing LTO flags to the linker

From 465109d06729b7f38c3df6f4f76794b38c3d09d8 Mon Sep 17 00:00:00 2001
From: "Slava \"nerfur\" Voronzoff" <[email protected]>
Date: Tue, 22 Jul 2025 07:09:02 +0300
Subject: [PATCH 9/9] killed slipped "space button"

---
 clang/lib/Driver/ToolChains/OpenBSD.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index b66fa223c3683..8f589186af343 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -166,7 +166,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     if (Args.hasArg(options::OPT_mno_relax))
       CmdArgs.push_back("--no-relax");
   }
-  
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
     CmdArgs.push_back("-o");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.