Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Jan 4, 2024

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

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.
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 4, 2024

@llvm/pr-subscribers-llvm-binary-utilities

Author: Joseph Huber (jhuber6)

Changes

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.


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

1 Files Affected:

  • (modified) llvm/include/llvm/Object/ELFObjectFile.h (+7)
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;
 

@jlebar
Copy link
Member

jlebar commented Jan 4, 2024

objects be we currently list them as unknown

Typo?

@jhuber6 jhuber6 merged commit c12a9fc into llvm:main Jan 4, 2024
4 of 5 checks passed
Comment on lines +1353 to +1356
if (EF.getHeader().e_ident[ELF::EI_CLASS] == ELF::ELFCLASS32)
return Triple::nvptx;
else
return Triple::nvptx64;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid else-after-return, per the LLVM style guide.
Instead use:

if (...)
  return ...;
return ...;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a test for this now in #76992. I can do the style NFC if needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally the test should go with the patch that introduces the change in behavior. If the change in behavior is unreachable/untestable without some other changes, then they should go together so test coverage is clear (otherwise it's hard to track that the patch did eventually get tested).

Sure - an NFC change would be good - no need to send it for review, you can commit that directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There weren't any existing tests for any of this code, so I just punted it until the second patch. Thanks, I'll do the NFC.

@dwblaikie
Copy link
Collaborator

Test coverage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants