Skip to content

[AArch64] Restrict .variant_pcs directive to ELF targets #140022

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

Conversation

c-rhodes
Copy link
Collaborator

@c-rhodes c-rhodes commented May 15, 2025

Directive was implemented in c87bd2d to support lazy binding and is emitted for vector PCS functions. It's specific to ELF but is currently emitted for all binary formats and crashing on non-ELF targets.

Fixes #138260

Directive was implemented in c87bd2d to support lazy binding and is
emitted for vector PCS functions. It's specific to ELF but is currently
emitted for all binary formats and crashing on non-ELF targets.

Fixes llvm#138260

[1]
https://github.com/ARM-software/abi-aa/blob/master/aaelf64/aaelf64.rst#st-other-values
@llvmbot
Copy link
Member

llvmbot commented May 15, 2025

@llvm/pr-subscribers-backend-aarch64

Author: Cullen Rhodes (c-rhodes)

Changes

Directive was implemented in c87bd2d to support lazy binding and is emitted for vector PCS functions. It's specific to ELF but is currently emitted for all binary formats and crashing on non-ELF targets.

Fixes #138260

[1] https://github.com/ARM-software/abi-aa/blob/master/aaelf64/aaelf64.rst#st-other-values


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

2 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp (+7-6)
  • (modified) llvm/test/CodeGen/AArch64/variant-pcs.ll (+7)
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index a53606851d0a2..f55b7ef7c20bb 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -1344,10 +1344,12 @@ AArch64AsmPrinter::getCodeViewJumpTableInfo(int JTI,
 }
 
 void AArch64AsmPrinter::emitFunctionEntryLabel() {
-  if (MF->getFunction().getCallingConv() == CallingConv::AArch64_VectorCall ||
-      MF->getFunction().getCallingConv() ==
-          CallingConv::AArch64_SVE_VectorCall ||
-      MF->getInfo<AArch64FunctionInfo>()->isSVECC()) {
+  const Triple &TT = TM.getTargetTriple();
+  if (TT.isOSBinFormatELF() &&
+      (MF->getFunction().getCallingConv() == CallingConv::AArch64_VectorCall ||
+       MF->getFunction().getCallingConv() ==
+           CallingConv::AArch64_SVE_VectorCall ||
+       MF->getInfo<AArch64FunctionInfo>()->isSVECC())) {
     auto *TS =
         static_cast<AArch64TargetStreamer *>(OutStreamer->getTargetStreamer());
     TS->emitDirectiveVariantPCS(CurrentFnSym);
@@ -1355,8 +1357,7 @@ void AArch64AsmPrinter::emitFunctionEntryLabel() {
 
   AsmPrinter::emitFunctionEntryLabel();
 
-  if (TM.getTargetTriple().isWindowsArm64EC() &&
-      !MF->getFunction().hasLocalLinkage()) {
+  if (TT.isWindowsArm64EC() && !MF->getFunction().hasLocalLinkage()) {
     // For ARM64EC targets, a function definition's name is mangled differently
     // from the normal symbol, emit required aliases here.
     auto emitFunctionAlias = [&](MCSymbol *Src, MCSymbol *Dst) {
diff --git a/llvm/test/CodeGen/AArch64/variant-pcs.ll b/llvm/test/CodeGen/AArch64/variant-pcs.ll
index 49c504177358e..38510751fdd43 100644
--- a/llvm/test/CodeGen/AArch64/variant-pcs.ll
+++ b/llvm/test/CodeGen/AArch64/variant-pcs.ll
@@ -1,6 +1,13 @@
 ; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve -o - %s | FileCheck %s --check-prefix=CHECK-ASM --strict-whitespace
+; RUN: llc -mtriple=arm64-apple-macosx -mattr=+sve -o - %s | FileCheck %s --check-prefix=CHECK-ASM-NON-ELF-TARGET
 ; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve -filetype=obj -o - %s \
 ; RUN:   | llvm-readobj --symbols - | FileCheck %s --check-prefix=CHECK-OBJ
+; RUN: llc -mtriple=arm64-apple-macosx -mattr=+sve -filetype=obj -o - %s \
+; RUN:   | llvm-readobj --symbols - | FileCheck %s --check-prefix=CHECK-OBJ-NON-ELF-TARGET
+
+; .variant_pcs directive should only be emitted for ELF targets.
+; CHECK-ASM-NON-ELF-TARGET-NOT: .variant_pcs
+; CHECK-OBJ-NON-ELF-TARGET-NOT: Other [ (0x80)
 
 define i32 @base_pcs() {
 ; CHECK-ASM-LABEL: base_pcs:

Copy link
Collaborator

@davemgreen davemgreen left a comment

Choose a reason for hiding this comment

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

Is this similar to #138924? @MacDue

@c-rhodes
Copy link
Collaborator Author

Is this similar to #138924? @MacDue

seems so! Apologies I wasn't aware there was a fix in progress already.. I came across this via #138260 the other day and there's no link to the existing PR, perhaps @MacDue wasn't aware there's an existing issue.

Copy link
Collaborator

@sdesmalen-arm sdesmalen-arm left a comment

Choose a reason for hiding this comment

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

This indeed seems a duplicate of #138924. Since this version addresses already the comment I left on the other PR, I'm happy to accept it if you address my nit on the test. Thanks!


; .variant_pcs directive should only be emitted for ELF targets.
; CHECK-ASM-NON-ELF-TARGET-NOT: .variant_pcs
; CHECK-OBJ-NON-ELF-TARGET-NOT: Other [ (0x80)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this check makes sense, because this seems ELF specific. You can just remove the | FileCheck %s --check-prefix=CHECK-OBJ-NON-ELF-TARGET part of the RUN line, we just need to make sure it doesn't fail to compile.

@c-rhodes
Copy link
Collaborator Author

This indeed seems a duplicate of #138924. Since this version addresses already the comment I left on the other PR, I'm happy to accept it if you address my nit on the test. Thanks!

Appreciate it, but Ben got there first so he can have this one.

@c-rhodes c-rhodes closed this May 15, 2025
@MacDue
Copy link
Member

MacDue commented May 15, 2025

This indeed seems a duplicate of #138924. Since this version addresses already the comment I left on the other PR, I'm happy to accept it if you address my nit on the test. Thanks!

Appreciate it, but Ben got there first so he can have this one.

I think this version of the fix is more correct than mine, so I'll take version this and add you as a co-author on my PR 👍

@MacDue
Copy link
Member

MacDue commented May 15, 2025

I've pushed your patch to #138924 (and addressed @sdesmalen-arm's nit).

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.

Compiler Crash with ACLE - Aarch64 Apple Darwin targets
5 participants