https://github.com/pawosm-arm updated https://github.com/llvm/llvm-project/pull/116432
>From 5614595f48dc2a6b4087c992c108874ca6c787ee Mon Sep 17 00:00:00 2001 From: Pawel Osmialowski <pawel.osmialow...@arm.com> Date: Fri, 15 Nov 2024 15:22:21 +0000 Subject: [PATCH] [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. --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 11 +++++++++++ clang/lib/Driver/ToolChains/MSVC.cpp | 8 ++++++++ clang/test/Driver/fveclib.c | 14 ++++++++++++++ flang/test/Driver/fveclib.f90 | 14 ++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index cbba4289eb9450..94143d68d39649 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -490,6 +490,17 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, else A.renderAsInput(Args, CmdArgs); } + if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) { + if (A->getNumValues() == 1) { + const llvm::Triple &Triple = TC.getTriple(); + StringRef V = A->getValue(); + if ((V == "ArmPL") && (Triple.isOSLinux() || Triple.isOSDarwin())) { + CmdArgs.push_back(Args.MakeArgString("-lamath")); + CmdArgs.push_back(Args.MakeArgString("-lm")); + addArchSpecificRPath(TC, Args, CmdArgs); + } + } + } } void tools::addLinkerCompressDebugSectionsOption( diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp index 80799d1e715f07..dc5d8d46585ef3 100644 --- a/clang/lib/Driver/ToolChains/MSVC.cpp +++ b/clang/lib/Driver/ToolChains/MSVC.cpp @@ -84,6 +84,14 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, else if (TC.getTriple().isWindowsArm64EC()) CmdArgs.push_back("-machine:arm64ec"); + if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) { + if (A->getNumValues() == 1) { + StringRef V = A->getValue(); + if (V == "ArmPL") + CmdArgs.push_back(Args.MakeArgString("--dependent-lib=amath")); + } + } + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) && !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) { CmdArgs.push_back("-defaultlib:libcmt"); diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c index 8b233b0023398f..31d44ee06e1594 100644 --- a/clang/test/Driver/fveclib.c +++ b/clang/test/Driver/fveclib.c @@ -102,3 +102,17 @@ /* Verify no warning when math-errno is re-enabled for a different veclib (that does not imply -fno-math-errno). */ // RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -fmath-errno -fveclib=LIBMVEC %s 2>&1 | FileCheck --check-prefix=CHECK-REPEAT-VECLIB %s // CHECK-REPEAT-VECLIB-NOT: math errno enabled + +/* Verify that vectorized routines library is being linked in. */ +// RUN: %clang -### --target=aarch64-pc-windows-msvc -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL-MSVC %s +// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL %s +// RUN: %clang -### --target=arm64-apple-darwin -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL %s +// CHECK-LINKING-ARMPL: "-lamath" +// CHECK-LINKING-ARMPL-SAME: "-lm" +// CHECK-LINKING-ARMPL-MSVC: "--dependent-lib=amath" + +/* Verify that the RPATH is being set when needed. */ +// 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 +// CHECK-RPATH-ARMPL: "-lamath" +// CHECK-RPATH-ARMPL-SAME: "-lm" +// CHECK-RPATH-ARMPL-SAME: "-rpath" diff --git a/flang/test/Driver/fveclib.f90 b/flang/test/Driver/fveclib.f90 index 14c59b0616f828..68fff31332ff8a 100644 --- a/flang/test/Driver/fveclib.f90 +++ b/flang/test/Driver/fveclib.f90 @@ -30,3 +30,17 @@ ! TODO: if we add support for -nostdlib or -nodefaultlibs we need to test that ! these prevent "-framework Accelerate" being added on Darwin + +! RUN: %flang -### --target=aarch64-pc-windows-msvc -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL-MSVC %s +! RUN: %flang -### --target=aarch64-linux-gnu -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL %s +! RUN: %flang -### --target=arm64-apple-darwin -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-LINKING-ARMPL %s +! CHECK-LINKING-ARMPL: "-lamath" +! CHECK-LINKING-ARMPL-SAME: "-lm" +! CHECK-LINKING-ARMPL-MSVC: "--dependent-lib=amath" + +! 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 +! CHECK-RPATH-ARMPL: "-lamath" +! CHECK-RPATH-ARMPL-SAME: "-lm" +! We need to see "-rpath" at least twice, one for veclib, one for the Fortran runtime +! CHECK-RPATH-ARMPL-SAME: "-rpath" +! CHECK-RPATH-ARMPL-SAME: "-rpath" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits