From patchwork Tue Jul 27 18:16:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1510612 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GZ4l03y06z9sXG for ; Wed, 28 Jul 2021 04:17:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 23EE9389850F for ; Tue, 27 Jul 2021 18:17:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.tachyum.com (mx2.tachyum.com [50.229.46.110]) by sourceware.org (Postfix) with ESMTPS id 04AF13857C7E for ; Tue, 27 Jul 2021 18:16:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 04AF13857C7E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tachyum.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tachyum.com Received: by mx2.tachyum.com (Postfix, from userid 1000) id 08E151076C73; Tue, 27 Jul 2021 11:16:48 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-Spam-Level: X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 Received: from THQ-EX1.tachyum.com (thq-ex1.tachyum.com [10.7.1.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx2.tachyum.com (Postfix) with ESMTPS id 8790F1076C71 for ; Tue, 27 Jul 2021 11:16:47 -0700 (PDT) Received: from [10.0.96.2] (10.0.96.2) by THQ-EX1.tachyum.com (10.7.1.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 27 Jul 2021 11:16:46 -0700 To: GCC Patches From: Jeff Law Subject: [committed] Fix argument to pthread_join Message-ID: <3ce0ef8c-3a2d-65c8-081b-48a4150ffb06@tachyum.com> Date: Tue, 27 Jul 2021 12:16:46 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [10.0.96.2] X-ClientProxiedBy: THQ-EX3.tachyum.com (10.7.1.26) To THQ-EX1.tachyum.com (10.7.1.6) X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This showed up as a segfault running the gcov-threads-1.C test in qemu system mode on our internal port. We're passing the address of an int to pthread_join.  That int object is only guaranteed 4 byte alignment.  Later when pthread_join wants to store a pointer into that location, we naturally fault due to misalignment.  This is also a stack overrun since the pointer is 64 bits, but we've only got 32 bits of stack space allocated. pthread_join really wants a pointer to a pointer.   So instead of passing &int_var, we can just pass &pointer_var.  That also avoids the silly cast.  We never use the value anyway, so we could just as easily pass NULL. This may also be the root cause of the riscv64 gcov-threads-1 failure that you can find in the gcc-testresults archives. Bootstrapped and tested on x86, also verified that gcov-threads-1.C now works with our internal port. Committed to the trunk. Jeff commit 0853f392a213ef2cecc71ef5349aab079e30f5a0 Author: Jeff Law Date: Tue Jul 27 14:14:05 2021 -0400 Fix argument to pthread_join gcc/testsuite * g++.dg/gcov/gcov-threads-1.C: Fix argument to pthread_join. diff --git a/gcc/testsuite/g++.dg/gcov/gcov-threads-1.C b/gcc/testsuite/g++.dg/gcov/gcov-threads-1.C index b020dd87d4c..3ae00789439 100644 --- a/gcc/testsuite/g++.dg/gcov/gcov-threads-1.C +++ b/gcc/testsuite/g++.dg/gcov/gcov-threads-1.C @@ -36,7 +36,7 @@ int main(int argc, char **argv) { assert (r == 0); /* count(5*) */ } - int ret; + void *ret; for (int i = 0; i < NR; i++) { int r = pthread_join (t[i], (void**)&ret);