[llvm] [MC][ARM] Set default Tag_ABI_VFP_args EABI attr (PR #205883)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 25 11:45:55 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-arm
Author: Prabhu Rajasekaran (Prabhuk)
<details>
<summary>Changes</summary>
When compiling assembly (.S) files for ARM, Clang's integrated
assembler was not emitting any default Tag_ABI_VFP_args (float ABI)
attribute. This made it look like the files were
calling-convention-neutral, which can lead to silent float ABI
mismatches during linking. This patch fixes that by automatically
setting the float ABI attribute in the ELF streamer which can be
used by the linker.
---
Full diff: https://github.com/llvm/llvm-project/pull/205883.diff
3 Files Affected:
- (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp (+16)
- (added) llvm/test/MC/ARM/elf-float-abi-explicit.s (+14)
- (added) llvm/test/MC/ARM/elf-float-abi.s (+21)
``````````diff
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
index a9072e38f1181..921fbe71a1119 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
@@ -50,6 +50,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/TargetParser/Triple.h"
#include <cassert>
#include <climits>
#include <cstdint>
@@ -1068,6 +1069,21 @@ void ARMTargetELFStreamer::finishAttributeSection() {
if (Arch != ARM::ArchKind::INVALID)
emitArchDefaultAttributes();
+ // Set Tag_ABI_VFP_args based on the target triple environment.
+ // For hard-float environments (ending in 'hf') and Windows on ARM (which
+ // strictly mandates the AAPCS-VFP hard-float calling convention), we default
+ // Tag_ABI_VFP_args to HardFPAAPCS. We set OverwriteExisting to false to
+ // ensure that any explicit .eabi_attribute directives in the assembly source
+ // are respected and not overwritten.
+ const Triple &TT = S.getContext().getTargetTriple();
+ if (TT.getEnvironment() == Triple::GNUEABIHF ||
+ TT.getEnvironment() == Triple::GNUEABIHFT64 ||
+ TT.getEnvironment() == Triple::MuslEABIHF ||
+ TT.getEnvironment() == Triple::EABIHF || TT.isOSWindows()) {
+ S.setAttributeItem(ARMBuildAttrs::ABI_VFP_args, ARMBuildAttrs::HardFPAAPCS,
+ /* OverwriteExisting= */ false);
+ }
+
if (S.Contents.empty())
return;
diff --git a/llvm/test/MC/ARM/elf-float-abi-explicit.s b/llvm/test/MC/ARM/elf-float-abi-explicit.s
new file mode 100644
index 0000000000000..3727cf0f23282
--- /dev/null
+++ b/llvm/test/MC/ARM/elf-float-abi-explicit.s
@@ -0,0 +1,14 @@
+@ RUN: llvm-mc -triple armv7a-unknown-linux-gnueabihf -filetype=obj -o - %s \
+@ RUN: | llvm-readobj --arch-specific - | FileCheck %s --check-prefix=EXPLICIT-SOFT
+
+@ EXPLICIT-SOFT: Tag: 28
+@ EXPLICIT-SOFT-NEXT: Value: 0
+@ EXPLICIT-SOFT-NEXT: TagName: ABI_VFP_args
+@ EXPLICIT-SOFT-NEXT: Description: AAPCS
+
+.syntax unified
+.eabi_attribute 28, 0 @ Explicitly declare Base AAPCS (soft-float/softfp)
+.text
+.global _start
+_start:
+ bx lr
diff --git a/llvm/test/MC/ARM/elf-float-abi.s b/llvm/test/MC/ARM/elf-float-abi.s
new file mode 100644
index 0000000000000..df01965e40e0d
--- /dev/null
+++ b/llvm/test/MC/ARM/elf-float-abi.s
@@ -0,0 +1,21 @@
+@ RUN: llvm-mc -triple armv7a-unknown-linux-gnueabihf -filetype=obj -o - %s \
+@ RUN: | llvm-readobj --arch-specific - | FileCheck %s --check-prefix=HARD
+
+@ RUN: llvm-mc -triple armv7a-unknown-linux-gnueabi -filetype=obj -o - %s \
+@ RUN: | llvm-readobj --arch-specific - | FileCheck %s --check-prefix=SOFT
+
+@ RUN: llvm-mc -triple thumbv7-pc-windows-elf -filetype=obj -o - %s \
+@ RUN: | llvm-readobj --arch-specific - | FileCheck %s --check-prefix=HARD
+
+@ HARD: Tag: 28
+@ HARD-NEXT: Value: 1
+@ HARD-NEXT: TagName: ABI_VFP_args
+@ HARD-NEXT: Description: AAPCS VFP
+
+@ SOFT-NOT: TagName: ABI_VFP_args
+
+.syntax unified
+.text
+.global _start
+_start:
+ bx lr
``````````
</details>
https://github.com/llvm/llvm-project/pull/205883
More information about the llvm-commits
mailing list