From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18693 invoked by alias); 27 Oct 2006 08:32:21 -0000 Received: (qmail 18675 invoked by uid 22791); 27 Oct 2006 08:32:19 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 27 Oct 2006 08:32:16 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id k9R8WCYN015499; Fri, 27 Oct 2006 10:32:12 +0200 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id k9R8WBqM015498; Fri, 27 Oct 2006 10:32:11 +0200 Date: Fri, 27 Oct 2006 08:32:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix __rtld_mrlock_{lock,change} Message-ID: <20061027083211.GP5868@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2006-10/txt/msg00018.txt.bz2 Hi! __rtld_mrlock_{lock,change} can get into an endless loop. If lock is changed between oldval = lock and the atomic compare and swap, the loop will cycle until something changes lock back to the oldvalue (which doesn't have to happen ever). When CAS is unsuccessful, we need to reread oldval, either from lock directly or better yet from what CAS returned. 2006-10-27 Jakub Jelinek * sysdeps/unix/sysv/linux/rtld-lowlevel.h (__rtld_mrlock_lock, __rtld_mrlock_change): Update oldval if atomic compare and exchange failed. --- libc/nptl/sysdeps/unix/sysv/linux/rtld-lowlevel.h.jj 2006-10-19 17:26:40.000000000 +0200 +++ libc/nptl/sysdeps/unix/sysv/linux/rtld-lowlevel.h 2006-10-25 21:36:37.000000000 +0200 @@ -67,6 +67,7 @@ typedef int __rtld_mrlock_t; oldval); \ if (__builtin_expect (ret == oldval, 1)) \ goto out; \ + oldval = ret; \ } \ atomic_delay (); \ } \ @@ -112,6 +113,7 @@ typedef int __rtld_mrlock_t; oldval); \ if (__builtin_expect (ret == oldval, 1)) \ goto out; \ + oldval = ret; \ } \ atomic_delay (); \ } \ Jakub