From patchwork Mon Apr 1 14:44:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1072894 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-498710-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=gdcproject.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="cNpqRIX4"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Xw9F2pK7z9sQt for ; Tue, 2 Apr 2019 01:44:49 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=EiG8aGBz+JDWC3B+ZxJouGT2yTEtqcCHdW/ZZ9uXtJ3EGB QOGH0OVJ9MJ/cZ65wNvzzjvWkDz1lsjp5VHNN4v6E/4NXB18i++50l+PoSfAM++9 7VNCYfM5W2UjL7p45J9BzkH0PAvarB8tHOD9VOIdCDPLTmgOfsPzCmAZ/1EyM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=ka68fptx4r32esoKxuVSjyZ0iCg=; b=cNpqRIX4bk2z3AZijGv0 BBj2gGdY4Wlwl20ERRVOKI+HHJPVxavTMDLGWyu5Ysr039bU/mLOpSdxj7Ua5Nqn vfvBhtuMcE7Q0+nK37vO8sEGog/kK7TtyJLXCKjrpx+nl3Fcd9kIrkT5MMKAbVYu xY2WMxNP2rPpjsfeXL3VTEk= Received: (qmail 23432 invoked by alias); 1 Apr 2019 14:44:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 19256 invoked by uid 89); 1 Apr 2019 14:44:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=nothrow X-HELO: mail-qk1-f174.google.com Received: from mail-qk1-f174.google.com (HELO mail-qk1-f174.google.com) (209.85.222.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 01 Apr 2019 14:44:33 +0000 Received: by mail-qk1-f174.google.com with SMTP id g1so5769209qki.5 for ; Mon, 01 Apr 2019 07:44:33 -0700 (PDT) MIME-Version: 1.0 From: Iain Buclaw Date: Mon, 1 Apr 2019 16:44:20 +0200 Message-ID: Subject: [PATCH PR d/88462] Committed fix for abort in pthread_mutex_init on Solaris To: gcc-patches X-IsSubscribed: yes Hi, This patch merges the libphobos druntime library with druntime upstream d57fa1ff. Fixes alignment of internal core.thread locks that were found to be the cause of abort() being called inside pthread_mutex_init(), fixing the second part of PR d/88462. Bootstrapped and regression tested on x86_64-linux-gnu. Committed to trunk as r270057. diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE index ed756fa6c18..15a55ab612a 100644 --- a/libphobos/libdruntime/MERGE +++ b/libphobos/libdruntime/MERGE @@ -1,4 +1,4 @@ -b9564bef1147c797842e6c1a804f2c3565c64ac1 +d57fa1ffaecc858229ed7a730e8486b59197dee5 The first line of this file holds the git revision number of the last merge done from the dlang/druntime repository. diff --git a/libphobos/libdruntime/core/internal/traits.d b/libphobos/libdruntime/core/internal/traits.d index d5786808054..e56f016c355 100644 --- a/libphobos/libdruntime/core/internal/traits.d +++ b/libphobos/libdruntime/core/internal/traits.d @@ -170,6 +170,29 @@ template anySatisfy(alias F, T...) } } +// simplified from std.traits.maxAlignment +template maxAlignment(U...) +{ + static if (U.length == 0) + static assert(0); + else static if (U.length == 1) + enum maxAlignment = U[0].alignof; + else static if (U.length == 2) + enum maxAlignment = U[0].alignof > U[1].alignof ? U[0].alignof : U[1].alignof; + else + { + enum a = maxAlignment!(U[0 .. ($+1)/2]); + enum b = maxAlignment!(U[($+1)/2 .. $]); + enum maxAlignment = a > b ? a : b; + } +} + +template classInstanceAlignment(T) +if (is(T == class)) +{ + alias classInstanceAlignment = maxAlignment!(void*, typeof(T.tupleof)); +} + // Somehow fails for non-static nested structs without support for aliases template hasElaborateDestructor(T...) { diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d index e502072be7a..1cf26641e05 100644 --- a/libphobos/libdruntime/core/thread.d +++ b/libphobos/libdruntime/core/thread.d @@ -114,6 +114,13 @@ private { import core.atomic, core.memory, core.sync.mutex; + // Handling unaligned mutexes are not supported on all platforms, so we must + // ensure that the address of all shared data are appropriately aligned. + import core.internal.traits : classInstanceAlignment; + + enum mutexAlign = classInstanceAlignment!Mutex; + enum mutexClassInstanceSize = __traits(classInstanceSize, Mutex); + // // exposed by compiler runtime // @@ -1708,29 +1715,30 @@ private: // lock order inversion. @property static Mutex slock() nothrow @nogc { - return cast(Mutex)_locks[0].ptr; + return cast(Mutex)_slock.ptr; } @property static Mutex criticalRegionLock() nothrow @nogc { - return cast(Mutex)_locks[1].ptr; + return cast(Mutex)_criticalRegionLock.ptr; } - __gshared align(Mutex.alignof) void[__traits(classInstanceSize, Mutex)][2] _locks; + __gshared align(mutexAlign) void[mutexClassInstanceSize] _slock; + __gshared align(mutexAlign) void[mutexClassInstanceSize] _criticalRegionLock; static void initLocks() { - foreach (ref lock; _locks) - { - lock[] = typeid(Mutex).initializer[]; - (cast(Mutex)lock.ptr).__ctor(); - } + _slock[] = typeid(Mutex).initializer[]; + (cast(Mutex)_slock.ptr).__ctor(); + + _criticalRegionLock[] = typeid(Mutex).initializer[]; + (cast(Mutex)_criticalRegionLock.ptr).__ctor(); } static void termLocks() { - foreach (ref lock; _locks) - (cast(Mutex)lock.ptr).__dtor(); + (cast(Mutex)_slock.ptr).__dtor(); + (cast(Mutex)_criticalRegionLock.ptr).__dtor(); } __gshared Context* sm_cbeg;