From owner-svn-src-all@freebsd.org Tue Jan 7 20:09:04 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7D4701F1749; Tue, 7 Jan 2020 20:09:04 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47sk3h2pTkz4YVL; Tue, 7 Jan 2020 20:09:04 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5732945DE; Tue, 7 Jan 2020 20:09:04 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 007K94wk003855; Tue, 7 Jan 2020 20:09:04 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 007K93jh003849; Tue, 7 Jan 2020 20:09:03 GMT (envelope-from dim@FreeBSD.org) Message-Id: <202001072009.007K93jh003849@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Tue, 7 Jan 2020 20:09:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r356467 - in stable/12: contrib/llvm-project/clang/lib/AST contrib/llvm-project/clang/lib/Basic/Targets contrib/llvm-project/compiler-rt/lib/builtins contrib/llvm-project/llvm/lib/Targe... X-SVN-Group: stable-12 X-SVN-Commit-Author: dim X-SVN-Commit-Paths: in stable/12: contrib/llvm-project/clang/lib/AST contrib/llvm-project/clang/lib/Basic/Targets contrib/llvm-project/compiler-rt/lib/builtins contrib/llvm-project/llvm/lib/Target/PowerPC lib/libcompiler... X-SVN-Commit-Revision: 356467 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jan 2020 20:09:04 -0000 Author: dim Date: Tue Jan 7 20:09:02 2020 New Revision: 356467 URL: https://svnweb.freebsd.org/changeset/base/356467 Log: MFC r356100: Merge commit d3aeac8e2 from llvm git (by Justin Hibbits) [PowerPC] Only use PLT annotations if using PIC relocation model Summary: The default static (non-PIC, non-PIE) model for 32-bit powerpc does not use @PLT annotations and relocations in GCC. LLVM shouldn't use @PLT annotations either, because it breaks secure-PLT linking with (some versions of?) GNU LD. Update the available-externally.ll test to reflect that default mode should be the same as the static relocation, by using the same check prefix. Reviewed by: sfertile Differential Revision: https://reviews.llvm.org/D70570 Reviewed by: jhibbits Differential Revision: https://reviews.freebsd.org/D22913 MFC r356104 (by jhibbits): [PowerPC] enable atomic.c in compiler_rt and do not check and forces lock/lock_free decisions in compiled time Summary: Enables atomic.c in compiler_rt and forces clang to not emit a call for runtime decision about lock/lock_free. At compiling time, if clang can't decide if atomic operation can be lock free, it emits calls to external functions like `__atomic_is_lock_free`, `__c11_atomic_is_lock_free` and `__atomic_always_lock_free`, postponing decision to a runtime check. According to LLVM code documentation, the mechanism exists due to differences between x86_64 processors that can't be decided at runtime. On PowerPC and PowerPCSPE (32 bits), we already know in advance it can't be lock free, so we force the decision at compile time and avoid having to implement it in an external library. This patch was made after 32 bit users testing the PowePC32 bit ISO reported llvm could not be compiled with in-base llvm due to `__atomic_load8` not implemented. Submitted by: alfredo.junior_eldorado.org.br Reviewed by: jhibbits, dim Differential Revision: https://reviews.freebsd.org/D22549 MFC r356112 (by jhibbits): [PowerPC64] Starting from FreeBSD 13.0, default to ELFv2 ABI This changes the LLVM default powerpc64 ABI to ELFv2, if target OS is FreeBSD >= 13.0 This will also be sent upstream. Submitted by: alfredo.junior_eldorado.org.br Reviewed by: dim, luporl Relnotes: YES Differential Revision: https://reviews.freebsd.org/D20383 Modified: stable/12/contrib/llvm-project/clang/lib/AST/ExprConstant.cpp stable/12/contrib/llvm-project/clang/lib/Basic/Targets/PPC.h stable/12/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp stable/12/lib/libcompiler_rt/Makefile.inc Directory Properties: stable/12/ (props changed) stable/12/contrib/llvm-project/clang/ (props changed) stable/12/contrib/llvm-project/compiler-rt/ (props changed) stable/12/contrib/llvm-project/llvm/ (props changed) Modified: stable/12/contrib/llvm-project/clang/lib/AST/ExprConstant.cpp ============================================================================== --- stable/12/contrib/llvm-project/clang/lib/AST/ExprConstant.cpp Tue Jan 7 20:06:26 2020 (r356466) +++ stable/12/contrib/llvm-project/clang/lib/AST/ExprConstant.cpp Tue Jan 7 20:09:02 2020 (r356467) @@ -9896,6 +9896,13 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const Call } } + // Avoid emiting call for runtime decision on PowerPC 32-bit + // The lock free possibilities on this platform are covered by the lines + // above and we know in advance other cases require lock + if (Info.Ctx.getTargetInfo().getTriple().getArch() == llvm::Triple::ppc) { + return Success(0, E); + } + return BuiltinOp == Builtin::BI__atomic_always_lock_free ? Success(0, E) : Error(E); } Modified: stable/12/contrib/llvm-project/clang/lib/Basic/Targets/PPC.h ============================================================================== --- stable/12/contrib/llvm-project/clang/lib/Basic/Targets/PPC.h Tue Jan 7 20:06:26 2020 (r356466) +++ stable/12/contrib/llvm-project/clang/lib/Basic/Targets/PPC.h Tue Jan 7 20:09:02 2020 (r356467) @@ -375,12 +375,29 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public IntMaxType = SignedLong; Int64Type = SignedLong; + if (Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) { + switch (Triple.getEnvironment()){ + case llvm::Triple::ELFv1: + ABI = "elfv1"; + break; + default: + ABI = "elfv2"; + break; + } + } else { + if ((Triple.getOS() == llvm::Triple::FreeBSD) && + (Triple.getOSMajorVersion() < 13)) { + ABI = "elfv1"; + } else { + ABI = "elfv2"; + } + } + + if ((Triple.getArch() == llvm::Triple::ppc64le)) { resetDataLayout("e-m:e-i64:64-n32:64"); - ABI = "elfv2"; } else { resetDataLayout("E-m:e-i64:64-n32:64"); - ABI = Triple.getEnvironment() == llvm::Triple::ELFv2 ? "elfv2" : "elfv1"; } if (Triple.getOS() == llvm::Triple::AIX) Modified: stable/12/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c ============================================================================== --- stable/12/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c Tue Jan 7 20:06:26 2020 (r356466) +++ stable/12/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c Tue Jan 7 20:09:02 2020 (r356467) @@ -51,8 +51,8 @@ static const long SPINLOCK_MASK = SPINLOCK_COUNT - 1; //////////////////////////////////////////////////////////////////////////////// #ifdef __FreeBSD__ #include -#include #include +#include #include typedef struct _usem Lock; __inline static void unlock(Lock *l) { @@ -117,13 +117,20 @@ static __inline Lock *lock_for_pointer(void *ptr) { return locks + (hash & SPINLOCK_MASK); } -/// Macros for determining whether a size is lock free. Clang can not yet -/// codegen __atomic_is_lock_free(16), so for now we assume 16-byte values are -/// not lock free. +/// Macros for determining whether a size is lock free. #define IS_LOCK_FREE_1 __c11_atomic_is_lock_free(1) #define IS_LOCK_FREE_2 __c11_atomic_is_lock_free(2) #define IS_LOCK_FREE_4 __c11_atomic_is_lock_free(4) + +/// 32 bit PowerPC doesn't support 8-byte lock_free atomics +#if !defined(__powerpc64__) && defined(__powerpc__) +#define IS_LOCK_FREE_8 0 +#else #define IS_LOCK_FREE_8 __c11_atomic_is_lock_free(8) +#endif + +/// Clang can not yet codegen __atomic_is_lock_free(16), so for now we assume +/// 16-byte values are not lock free. #define IS_LOCK_FREE_16 0 /// Macro that calls the compiler-generated lock-free versions of functions Modified: stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp ============================================================================== --- stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp Tue Jan 7 20:06:26 2020 (r356466) +++ stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp Tue Jan 7 20:09:02 2020 (r356467) @@ -4952,7 +4952,12 @@ PrepareCall(SelectionDAG &DAG, SDValue &Callee, SDValu if (auto *G = dyn_cast(Callee)) GV = G->getGlobal(); bool Local = TM.shouldAssumeDSOLocal(*Mod, GV); - bool UsePlt = !Local && Subtarget.isTargetELF() && !isPPC64; + // The PLT is only used in 32-bit ELF PIC mode. Attempting to use the PLT in + // a static relocation model causes some versions of GNU LD (2.17.50, at + // least) to force BSS-PLT, instead of secure-PLT, even if all objects are + // built with secure-PLT. + bool UsePlt = !Local && Subtarget.isTargetELF() && !isPPC64 && + Subtarget.getTargetMachine().getRelocationModel() == Reloc::PIC_; // If the callee is a GlobalAddress/ExternalSymbol node (quite common, // every direct call is) turn it into a TargetGlobalAddress / Modified: stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp ============================================================================== --- stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp Tue Jan 7 20:06:26 2020 (r356466) +++ stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp Tue Jan 7 20:09:02 2020 (r356467) @@ -209,6 +209,20 @@ static PPCTargetMachine::PPCABI computeTargetABI(const if (TT.isMacOSX()) return PPCTargetMachine::PPC_ABI_UNKNOWN; + if (TT.isOSFreeBSD()) { + switch (TT.getArch()) { + case Triple::ppc64le: + case Triple::ppc64: + if (TT.getOSMajorVersion() >= 13) + return PPCTargetMachine::PPC_ABI_ELFv2; + else + return PPCTargetMachine::PPC_ABI_ELFv1; + case Triple::ppc: + default: + return PPCTargetMachine::PPC_ABI_UNKNOWN; + } + } + switch (TT.getArch()) { case Triple::ppc64le: return PPCTargetMachine::PPC_ABI_ELFv2; Modified: stable/12/lib/libcompiler_rt/Makefile.inc ============================================================================== --- stable/12/lib/libcompiler_rt/Makefile.inc Tue Jan 7 20:06:26 2020 (r356466) +++ stable/12/lib/libcompiler_rt/Makefile.inc Tue Jan 7 20:09:02 2020 (r356467) @@ -205,6 +205,14 @@ CFLAGS+= -DEMIT_SYNC_ATOMICS SRCF+= stdatomic .endif + +.if "${COMPILER_TYPE}" == "clang" && \ + (${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpcspe") +SRCS+= atomic.c +CFLAGS.atomic.c+= -Wno-atomic-alignment +.endif + + .for file in ${SRCF} .if ${MACHINE_ARCH:Marmv[67]*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "") \ && exists(${CRTSRC}/${CRTARCH}/${file}vfp.S)