From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 76569 invoked by alias); 19 Nov 2015 12:31:19 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 76546 invoked by uid 89); 19 Nov 2015 12:31:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 19 Nov 2015 12:31:17 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 370326564C; Thu, 19 Nov 2015 12:31:16 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAJCVEGP016571 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Nov 2015 07:31:15 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id tAJCVCLT006587; Thu, 19 Nov 2015 13:31:12 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id tAJCV830006586; Thu, 19 Nov 2015 13:31:08 +0100 Date: Thu, 19 Nov 2015 12:31:00 -0000 From: Jakub Jelinek To: Ilya Verbin Cc: Thomas Schwinge , Julian Brown , gcc-patches@gcc.gnu.org, Kirill Yukhin Subject: Re: libgomp: Compile-time error for non-portable gomp_mutex_t initialization Message-ID: <20151119123108.GU5675@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <87a902ib93.fsf@schwinge.name> <20150226172511.GA49293@msticlxl57.ims.intel.com> <20150306140113.GB26588@msticlxl57.ims.intel.com> <20150309144555.3a078f48@octopus> <20150323194439.GA12972@msticlxl57.ims.intel.com> <20150326120919.GZ1746@tucnak.redhat.com> <20150326204130.GA65474@msticlxl57.ims.intel.com> <87io6ywne8.fsf@kepler.schwinge.homeip.net> <20150925152825.GQ1847@tucnak.redhat.com> <20151118151929.GA4267@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151118151929.GA4267@msticlxl57.ims.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg02327.txt.bz2 On Wed, Nov 18, 2015 at 06:19:29PM +0300, Ilya Verbin wrote: > On Fri, Sep 25, 2015 at 17:28:25 +0200, Jakub Jelinek wrote: > > On Fri, Sep 25, 2015 at 05:04:47PM +0200, Thomas Schwinge wrote: > > > On Thu, 26 Mar 2015 23:41:30 +0300, Ilya Verbin wrote: > > > > On Thu, Mar 26, 2015 at 13:09:19 +0100, Jakub Jelinek wrote: > > > > > the current code is majorly broken. As I've said earlier, e.g. the lack > > > > > of mutex guarding gomp_target_init (which is using pthread_once guaranteed > > > > > to be run just once) vs. concurrent GOMP_offload_register calls > > > > > (if those are run from ctors, then I guess something like dl_load_lock > > > > > ensures at least on glibc that multiple GOMP_offload_register calls aren't > > > > > performed at the same time) in accessing/reallocating offload_images > > > > > and num_offload_images and the lack of support to register further > > > > > images after the gomp_target_init call (if you dlopen further shared > > > > > libraries) is really bad. And it would be really nice to support the > > > > > unloading. > > > > > > > Here is the latest patch for libgomp and mic plugin. > > > > > > > libgomp/ > > > > > > > * target.c (register_lock): New mutex for offload image registration. > > > > > > > (GOMP_offload_register): Add mutex lock. > > > > That is definitely wrong. You'd totally break --disable-linux-futex support > > on linux and bootstrap on e.g. Solaris and various other pthread targets. > > I don't quite understand, do you mean that gcc 5 and trunk are broken, because > register_lock doesn't have initialization? But it seems that bootstrap on > Solaris and other targets works fine... Thomas has been proposing to add an #error when !GOMP_MUTEX_INIT_0 into target.c, so that means break build of libgomp on all targets where config/posix/mutex.h is used. That includes --disable-linux-futex on Linux, and various other targets. > > At least for ELF and dynamic linking, shared libraries that contain > > constructors that call GOMP_offload_register* should have DT_NEEDED libgomp > > and thus libgomp's constructors should be run before the constructors of > > the libraries that call GOMP_offload_register*. > > So, libgomp should contain a constructor, which will call gomp_mutex_init > (®ister_lock) before any call to GOMP_offload_register*, right? No, I think the GOMP_MUTEX_INITIALIZER case is better. All pthread targets need to support PTHREAD_MUTEX_INITIALIZER, and the other config/*/bar.h implementations are GOMP_MUTEX_INIT_0 1. So, config/posix/bar.h would #define GOMP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER config/linux/bar.h would #define GOMP_MUTEX_INITIALIZER { 0 } and config/rtems/bar.h would #define GOMP_MUTEX_INITIALIZER {} // or something similar. and then just initialize the file scope locks with that static initializer. Jakub