Skip to content

Commit b73e1b3

Browse files
committed
[ARM] Emit an error when the hard-float ABI is enabled but can't be used.
Currently, compiling for eabihf with a CPU lacking floating-point registers will silently use the soft-float ABI instead, even though the Arm attributes section still has Tag_ABI_VFP_args: VFP registers, which leads to silent ABI mismatches at link time. Fixes #110383.
1 parent acf92a4 commit b73e1b3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

clang/test/Driver/arm-float-abi-lto.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s -flto=full -c -o %t.call_full.bc -DCALL_LIB
66
// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s -flto=full -c -o %t.define_full.bc -DDEFINE_LIB
7-
// RUN: llvm-lto2 run -o %t.lto_full -save-temps %t.call_full.bc %t.define_full.bc \
7+
// RUN: llvm-lto2 run --mcpu=cortex-m33 --float-abi=hard -o %t.lto_full -save-temps %t.call_full.bc %t.define_full.bc \
88
// RUN: -r %t.call_full.bc,fn,px \
99
// RUN: -r %t.call_full.bc,fwrite,l \
1010
// RUN: -r %t.call_full.bc,putchar,l \
@@ -16,7 +16,7 @@
1616

1717
// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s -flto=thin -c -o %t.call_thin.bc -DCALL_LIB
1818
// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s -flto=thin -c -o %t.define_thin.bc -DDEFINE_LIB
19-
// RUN: llvm-lto2 run -o %t.lto_thin -save-temps %t.call_thin.bc %t.define_thin.bc \
19+
// RUN: llvm-lto2 run --mcpu=cortex-m33 --float-abi=hard -o %t.lto_thin -save-temps %t.call_thin.bc %t.define_thin.bc \
2020
// RUN: -r %t.call_thin.bc,fn,px \
2121
// RUN: -r %t.call_thin.bc,fwrite,l \
2222
// RUN: -r %t.call_thin.bc,putchar,l \

llvm/lib/Target/ARM/ARMTargetMachine.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,15 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
309309
// function that reside in TargetOptions.
310310
resetTargetOptions(F);
311311
I = std::make_unique<ARMSubtarget>(TargetTriple, CPU, FS, *this, isLittle,
312-
F.hasMinSize());
312+
F.hasMinSize());
313313

314314
if (!I->isThumb() && !I->hasARMOps())
315315
F.getContext().emitError("Function '" + F.getName() + "' uses ARM "
316316
"instructions, but the target does not support ARM mode execution.");
317+
318+
if (I->isTargetHardFloat() && !I->hasFPRegs())
319+
F.getContext().emitError("The hard-float ABI is enabled, but the target "
320+
"lacks floating-point registers.");
317321
}
318322

319323
return I.get();

0 commit comments

Comments
 (0)