[llvm] [ELF] Correctly set the `nvptx` triple from `makeTriple()` (PR #76970)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 4 08:20:08 PST 2024


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/76970

Summary:
The ELFObject file should be able to handle `nvptx` objects be we
currently list them as unknown. This patch should now make it return
`nvptx64--` correctly.


>From 3b234ba37833e6ba82ce7841d2e42ae1a6a52fa9 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Thu, 4 Jan 2024 10:18:34 -0600
Subject: [PATCH] [ELF] Correctly set the `nvptx` triple from `makeTriple()`

Summary:
The ELFObject file should be able to handle `nvptx` objects be we
currently list them as unknown. This patch should now make it return
`nvptx64--` correctly.
---
 llvm/include/llvm/Object/ELFObjectFile.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 99477644de4de7..da78e11b678d99 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -1349,6 +1349,13 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
     return Triple::UnknownArch;
   }
 
+  case ELF::EM_CUDA: {
+    if (EF.getHeader().e_ident[ELF::EI_CLASS] == ELF::ELFCLASS32)
+      return Triple::nvptx;
+    else
+      return Triple::nvptx64;
+  }
+
   case ELF::EM_BPF:
     return IsLittleEndian ? Triple::bpfel : Triple::bpfeb;
 



More information about the llvm-commits mailing list