Skip to content

Commit 5614595

Browse files
committed
[clang][driver] When -fveclib=ArmPL flag is in use, always link against libamath
Using `-fveclib=ArmPL` without libamath likely effects in the link-time errors.
1 parent 9a5e5e2 commit 5614595

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,17 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
490490
else
491491
A.renderAsInput(Args, CmdArgs);
492492
}
493+
if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
494+
if (A->getNumValues() == 1) {
495+
const llvm::Triple &Triple = TC.getTriple();
496+
StringRef V = A->getValue();
497+
if ((V == "ArmPL") && (Triple.isOSLinux() || Triple.isOSDarwin())) {
498+
CmdArgs.push_back(Args.MakeArgString("-lamath"));
499+
CmdArgs.push_back(Args.MakeArgString("-lm"));
500+
addArchSpecificRPath(TC, Args, CmdArgs);
501+
}
502+
}
503+
}
493504
}
494505

495506
void tools::addLinkerCompressDebugSectionsOption(

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
8484
else if (TC.getTriple().isWindowsArm64EC())
8585
CmdArgs.push_back("-machine:arm64ec");
8686

87+
if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
88+
if (A->getNumValues() == 1) {
89+
StringRef V = A->getValue();
90+
if (V == "ArmPL")
91+
CmdArgs.push_back(Args.MakeArgString("--dependent-lib=amath"));
92+
}
93+
}
94+
8795
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
8896
!C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
8997
CmdArgs.push_back("-defaultlib:libcmt");

clang/test/Driver/fveclib.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,17 @@
102102
/* Verify no warning when math-errno is re-enabled for a different veclib (that does not imply -fno-math-errno). */
103103
// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -fmath-errno -fveclib=LIBMVEC %s 2>&1 | FileCheck --check-prefix=CHECK-REPEAT-VECLIB %s
104104
// CHECK-REPEAT-VECLIB-NOT: math errno enabled
105+
106+
/* Verify that vectorized routines library is being linked in. */
107+
// RUN: %clang -### --target=aarch64-pc-windows-msvc -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL-MSVC %s
108+
// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL %s
109+
// RUN: %clang -### --target=arm64-apple-darwin -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL %s
110+
// CHECK-LINKING-ARMPL: "-lamath"
111+
// CHECK-LINKING-ARMPL-SAME: "-lm"
112+
// CHECK-LINKING-ARMPL-MSVC: "--dependent-lib=amath"
113+
114+
/* Verify that the RPATH is being set when needed. */
115+
// RUN: %clang -### --target=aarch64-linux-gnu -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_arch_subdir -frtlib-add-rpath -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-RPATH-ARMPL %s
116+
// CHECK-RPATH-ARMPL: "-lamath"
117+
// CHECK-RPATH-ARMPL-SAME: "-lm"
118+
// CHECK-RPATH-ARMPL-SAME: "-rpath"

flang/test/Driver/fveclib.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@
3030

3131
! TODO: if we add support for -nostdlib or -nodefaultlibs we need to test that
3232
! these prevent "-framework Accelerate" being added on Darwin
33+
34+
! RUN: %flang -### --target=aarch64-pc-windows-msvc -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL-MSVC %s
35+
! RUN: %flang -### --target=aarch64-linux-gnu -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL %s
36+
! RUN: %flang -### --target=arm64-apple-darwin -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL %s
37+
! CHECK-LINKING-ARMPL: "-lamath"
38+
! CHECK-LINKING-ARMPL-SAME: "-lm"
39+
! CHECK-LINKING-ARMPL-MSVC: "--dependent-lib=amath"
40+
41+
! RUN: %flang -### --target=aarch64-linux-gnu -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_arch_subdir -frtlib-add-rpath -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-RPATH-ARMPL %s
42+
! CHECK-RPATH-ARMPL: "-lamath"
43+
! CHECK-RPATH-ARMPL-SAME: "-lm"
44+
! We need to see "-rpath" at least twice, one for veclib, one for the Fortran runtime
45+
! CHECK-RPATH-ARMPL-SAME: "-rpath"
46+
! CHECK-RPATH-ARMPL-SAME: "-rpath"

0 commit comments

Comments
 (0)