From patchwork Tue Mar 21 09:39:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 19680 Received: (qmail 541 invoked by alias); 21 Mar 2017 09:39:31 -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 437 invoked by uid 89); 21 Mar 2017 09:39:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com To: libc-alpha@sourceware.org From: Stefan Liebler Subject: [PATCH]: Fix failing test malloc/tst-interpose-nothread with GCC 7. Date: Tue, 21 Mar 2017 10:39:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17032109-0040-0000-0000-00000369BBBA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17032109-0041-0000-0000-00001F5A574E Message-Id: <639e8844-ca14-1873-2407-484f286974b1@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-21_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703210087 Hi, The test malloc/tst-interpose-nothread fails on s390x if built with GCC 7 and recent glibc commit "Remove the str(n)dup inlines from string/bits/string2.h. Although inlining" (ae65d4f3c3995279ca458c460ebf8bab1885fa03) with output: error: free: 0x3fffdffa010: invalid allocation index: 0 (not less than 0) The destructor check_for_allocations in malloc/tst-interpose-aux.c is called twice. One time after the test-child-process has finished successfully and once after the test-parent-process finishes. During the latter invocation, allocation_index == 0. GCC 7 is now inlining the free function and calls unconditionally fail in get_header as header->allocation_index (type == size_t) is always >= allocation_index (== 0). Before the mentioned commit above, strdup was replaced by strlen, malloc and memcpy. The malloc call was also inlined and allocation_index was set to one. This patch moves the already existing compiler barrier before the invocation of free. Okay to commit? ChangeLog: * malloc/tst-interpose-aux.c (check_for_allocations): Move compiler barrier before free. commit 0d796fb327dc6e14e7888eb4a0531fdde4ce93b2 Author: Stefan Liebler Date: Tue Mar 21 09:29:09 2017 +0100 Fix failing test malloc/tst-interpose-nothread with GCC 7. The test malloc/tst-interpose-nothread fails on s390x if built with GCC 7 and glibc commit "Remove the str(n)dup inlines from string/bits/string2.h. Although inlining" (ae65d4f3c3995279ca458c460ebf8bab1885fa03) with output: error: free: 0x3fffdffa010: invalid allocation index: 0 (not less than 0) The destructor check_for_allocations in malloc/tst-interpose-aux.c is called twice. One time after the test-child-process has finished successfully and once after the test-parent-process finishes. During the latter invocation, allocation_index = 0. GCC 7 is now inlining the free function and calls unconditionally fail in get_header as header->allocation_index (type == size_t) is always >= allocation_index (= 0). Before the mentioned commit above, strdup was replaced by strlen, malloc and memcpy. The malloc call was also inlined and allocation_index was set to one. This patch moves the already existing compiler barrier before the invocation of free. ChangeLog: * malloc/tst-interpose-aux.c (check_for_allocations): Move compiler barrier before free. diff --git a/malloc/tst-interpose-aux.c b/malloc/tst-interpose-aux.c index e80e979..68282b4 100644 --- a/malloc/tst-interpose-aux.c +++ b/malloc/tst-interpose-aux.c @@ -113,11 +113,11 @@ check_for_allocations (void) { /* Make sure that malloc is called at least once from libc. */ void *volatile ptr = strdup ("ptr"); - free (ptr); /* Compiler barrier. The strdup function calls malloc, which updates allocation_index, but strdup is marked __THROW, so the compiler could optimize away the reload. */ __asm__ volatile ("" ::: "memory"); + free (ptr); /* If the allocation count is still zero, it means we did not interpose malloc successfully. */ if (allocation_index == 0)