From patchwork Wed Apr 30 02:40:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Miller X-Patchwork-Id: 750 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx20.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 75303360078 for ; Tue, 29 Apr 2014 19:40:56 -0700 (PDT) Received: by homiemail-mx20.g.dreamhost.com (Postfix, from userid 14307373) id 196E1412DEC63; Tue, 29 Apr 2014 19:40:56 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx20.g.dreamhost.com 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 homiemail-mx20.g.dreamhost.com (Postfix) with ESMTPS id E8E29412CFE22 for ; Tue, 29 Apr 2014 19:40:55 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:message-id:to:cc:subject:from:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=VrpFphEGe/cgbMAVSex7fkWApH+UL6lVdwxmm9VM4JG 2hlZim07BXChxBgHQvOhJiKrdADKAMxWXENH42DYAHn4aLZYQ5p2XDI48IeOnpxb fBgOdz2B7HqptXEauiJJ36cujSXf0UZkNVM1AO5n9zsDnHos28vxClY6Hd4JNX6o = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:message-id:to:cc:subject:from:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=ivzHX6mkXZmZbnEE9QpYhTY3JmI=; b=xe+0hHV89hRfSpLb0 7zq+j7igSpVoWB3A70Oi0G2SydEhG01GAJoJ/lmoTwBo8s9tGowiJUBZOlseEZ+B jpNVl50yHULrb+4WvqeRFVPG5Abn8ZM8uJcCUfJf8+pg8NrO9mNZKrAh62MZOFS7 kJ8tXS3ud8IHf+1/0ffwAy6QqA= Received: (qmail 11345 invoked by alias); 30 Apr 2014 02:40:52 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 11330 invoked by uid 89); 30 Apr 2014 02:40:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: shards.monkeyblade.net Date: Tue, 29 Apr 2014 22:40:46 -0400 (EDT) Message-Id: <20140429.224046.1363822337091646659.davem@davemloft.net> To: aurelien@aurel32.net Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] Rewritten v9/64-bit sparc strcmp. From: David Miller In-Reply-To: <20140429095339.GA31556@hall.aurel32.net> References: <20110824.013854.674433294054458127.davem@davemloft.net> <20140429095339.GA31556@hall.aurel32.net> Mime-Version: 1.0 X-DH-Original-To: glibc@patchwork.siddhesh.in From: Aurelien Jarno Date: Tue, 29 Apr 2014 11:53:39 +0200 > This method doesn't work when comparing a 0x00 char in string 1 and 0x01 > char in string 2. In that case the mask for this byte is 0x01 and the > corresponding xor is also 0x01. The result of the comparison therefore > depends on the garbage after the end of the string. > > On Debian [1] this causes for example debian-installer to fail to build > [2], and it might be the source of the random segfaults which we are > trying to debug for a few years. > > [1] http://bugs.debian.org/746310 > [2] http://bugs.debian.org/731806 Right you are, if there are any zeros after the first zero we will potentially miscompare. The only solution I can see at the moment is to clear all except the topmost bit in the mask. Can you please test this patch? Meanwhile I'll try to adjust string/test-strcmp.c so that it explicitly tests this situation. Thanks! diff --git a/sysdeps/sparc/sparc64/strcmp.S b/sysdeps/sparc/sparc64/strcmp.S index 8925396..312924a 100644 --- a/sysdeps/sparc/sparc64/strcmp.S +++ b/sysdeps/sparc/sparc64/strcmp.S @@ -121,6 +121,37 @@ ENTRY(strcmp) movleu %xcc, -1, %o0 srlx rTMP1, 7, rTMP1 + /* In order not to be influenced by bytes after the zero byte, we + * have to retain only the highest bit in the mask for the comparison + * with rSTRXOR to work properly. + */ + mov 0, rTMP2 + andcc rTMP1, 0x0100, %g0 + + movne %xcc, 8, rTMP2 + sllx rTMP1, 63 - 16, %o1 + + movrlz %o1, 16, rTMP2 + sllx rTMP1, 63 - 24, %o1 + + movrlz %o1, 24, rTMP2 + sllx rTMP1, 63 - 32, %o1 + + movrlz %o1, 32, rTMP2 + sllx rTMP1, 63 - 40, %o1 + + movrlz %o1, 40, rTMP2 + sllx rTMP1, 63 - 48, %o1 + + movrlz %o1, 48, rTMP2 + sllx rTMP1, 63 - 56, %o1 + + movrlz %o1, 56, rTMP2 + + srlx rTMP1, rTMP2, rTMP1 + + sllx rTMP1, rTMP2, rTMP1 + cmp rTMP1, rSTRXOR retl movgu %xcc, 0, %o0