diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp --- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp @@ -119,8 +119,7 @@ const ArgList &Args) { if (Args.getLastArg(options::OPT_msecure_plt)) return ppc::ReadGOTPtrMode::SecurePlt; - if ((Triple.isOSFreeBSD() && Triple.getOSMajorVersion() >= 13) || - Triple.isOSNetBSD() || Triple.isOSOpenBSD() || Triple.isMusl()) + if (Triple.isPPC32SecurePlt()) return ppc::ReadGOTPtrMode::SecurePlt; else return ppc::ReadGOTPtrMode::Bss; diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -890,6 +890,15 @@ getOS() == Triple::OpenBSD || isMusl())); } + /// Tests whether the target 32-bit PowerPC uses Secure PLT. + bool isPPC32SecurePlt() const { + return ((getArch() == Triple::ppc || getArch() == Triple::ppcle) && + ((getOS() == Triple::FreeBSD && + (getOSMajorVersion() >= 13 || getOSVersion().empty())) || + getOS() == Triple::NetBSD || getOS() == Triple::OpenBSD || + isMusl())); + } + /// Tests whether the target is 32-bit RISC-V. bool isRISCV32() const { return getArch() == Triple::riscv32; } diff --git a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp --- a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp +++ b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp @@ -106,9 +106,7 @@ if (IsPPC64 && has64BitSupport()) Use64BitRegs = true; - if ((TargetTriple.isOSFreeBSD() && TargetTriple.getOSMajorVersion() >= 13) || - TargetTriple.isOSNetBSD() || TargetTriple.isOSOpenBSD() || - TargetTriple.isMusl()) + if (TargetTriple.isPPC32SecurePlt()) IsSecurePlt = true; if (HasSPE && IsPPC64)