From patchwork Mon Feb 19 09:45:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Senkevich X-Patchwork-Id: 25961 Received: (qmail 3579 invoked by alias); 19 Feb 2018 09:46:41 -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 3435 invoked by uid 89); 19 Feb 2018 09:46:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 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.2 spammy=Hx-languages-length:3217 X-HELO: mail-lf0-f68.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=e7UXltHt7ApO6ElWBCaPanb537e2caTIdsy9YN8K+XA=; b=aXyUbpoMXiAAe5Ib5XJS/7RAhqSPlxdfBalKflD3PvBbqG58J0GI2Io2tpE+VWuXVF wBG35F2hHGrAwjJeYdJXaK+K1KmAL0lKIlWQo9BIi8jniOXmXQC9DbUwFOV9SFYHzu64 O4tVUt05jG1XoiK3Tqtx46JwRqUiRt2uzVHyjqm1RV11Jd9vDl2QQ4GeOIlLz0qwScNR 70XiknKJ0+sUCVG30S35YVGK8aRGOEGlpId7sM9DVDhuo/FUlEcP4yvpf3sIkguPE+Ow wfDXcSVhJk7KtikQPYsQinrzbQbyoP5398OsakknPaNwClIDBfv6gaBEOuhpUEYkD1wK N/zw== X-Gm-Message-State: APf1xPC36wNJ2fAvhD7XaHA5mLz3asYmq2lTAzPGK4QrE6Khh4YVNjsk sulm6LPqdJmtY1mSBbi62AQVFEYJkFNY7s7AjJNHKeM4 X-Google-Smtp-Source: AH8x2253t1FKwYH+W41n15cch6IQNUQ7sLjJWZ0GfkLTZ1EhHR2Sfjk+VoQwdQPewFHNMxrLyXYLdJqHuwCOb+szuqQ= X-Received: by 10.46.109.18 with SMTP id i18mr8988744ljc.19.1519033586871; Mon, 19 Feb 2018 01:46:26 -0800 (PST) MIME-Version: 1.0 From: Andrew Senkevich Date: Mon, 19 Feb 2018 10:45:56 +0100 Message-ID: Subject: [PATCH] Fix i386 memmove issue [BZ #22644] To: libc-alpha Cc: max@quendi.de Hi, in BZ #22644 was localized bug in i386 memmove-sse2-unaligned. This patch adds fix and testcase. Any comments? * sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S: Fixed branch conditions. * string/test-memmove.c (do_test2): New testcase. int test_main (void) { @@ -284,6 +327,11 @@ test_main (void) } do_random_tests (); + +#if __SIZEOF_POINTER__ == 4 + do_test2 (); +#endif + return ret; } --- WBR, Andrew diff --git a/sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S b/sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S index 9c3bbe7..9aa17de 100644 --- a/sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S +++ b/sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S @@ -72,7 +72,7 @@ ENTRY (MEMCPY) cmp %edx, %eax # ifdef USE_AS_MEMMOVE - jg L(check_forward) + ja L(check_forward) L(mm_len_0_or_more_backward): /* Now do checks for lengths. We do [0..16], [16..32], [32..64], [64..128] @@ -81,7 +81,7 @@ L(mm_len_0_or_more_backward): jbe L(mm_len_0_16_bytes_backward) cmpl $32, %ecx - jg L(mm_len_32_or_more_backward) + ja L(mm_len_32_or_more_backward) /* Copy [0..32] and return. */ movdqu (%eax), %xmm0 @@ -92,7 +92,7 @@ L(mm_len_0_or_more_backward): L(mm_len_32_or_more_backward): cmpl $64, %ecx - jg L(mm_len_64_or_more_backward) + ja L(mm_len_64_or_more_backward) /* Copy [0..64] and return. */ movdqu (%eax), %xmm0 @@ -107,7 +107,7 @@ L(mm_len_32_or_more_backward): L(mm_len_64_or_more_backward): cmpl $128, %ecx - jg L(mm_len_128_or_more_backward) + ja L(mm_len_128_or_more_backward) /* Copy [0..128] and return. */ movdqu (%eax), %xmm0 @@ -132,7 +132,7 @@ L(mm_len_128_or_more_backward): add %ecx, %eax cmp %edx, %eax movl SRC(%esp), %eax - jle L(forward) + jbe L(forward) PUSH (%esi) PUSH (%edi) PUSH (%ebx) @@ -269,7 +269,7 @@ L(check_forward): add %edx, %ecx cmp %eax, %ecx movl LEN(%esp), %ecx - jle L(forward) + jbe L(forward) /* Now do checks for lengths. We do [0..16], [0..32], [0..64], [0..128] separately. */ diff --git a/string/test-memmove.c b/string/test-memmove.c index edc7a4c..8dc152b --- a/string/test-memmove.c +++ b/string/test-memmove.c @@ -245,6 +245,49 @@ do_random_tests (void) } } +#if __SIZEOF_POINTER__ == 4 +static void +do_test2 (void) +{ + uint32_t i; + uint32_t num = 0x20000000; + uint32_t * large_buf = mmap (0, sizeof(uint32_t) * num, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (large_buf == MAP_FAILED) + error (EXIT_FAILURE, errno, "large mmap failed"); + + if (!((uint32_t)(large_buf) < (0x80000000 - 128) && (0x80000000 + 128) < (uint32_t)(&large_buf[num]))) + { + error (0, 0,"allocated large memory doesn't cross 0x80000000 boundary"); + ret = 1; + return; + } + + int bytes_move = 0x80000000 - (uint32_t)large_buf; + int arr_size = bytes_move / sizeof(uint32_t); + + FOR_EACH_IMPL (impl, 0) + { + for (i = 0; i < arr_size; i++) + large_buf[i] = i; + + uint32_t * dst = &large_buf[33]; + + CALL (impl, (char *)dst, (char *)large_buf, bytes_move); + + for (i = 0; i < arr_size; i++) + { + if (dst[i] != i) + { + error (0, 0, "Wrong result in function %s dst \"%p\" src \"%p\" offset \"%d\"", + impl->name, dst, large_buf, i); + ret = 1; + return; + } + } +} +#endif +