From patchwork Thu Nov 18 08:20:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 47873 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 85FAF3858420 for ; Thu, 18 Nov 2021 08:21:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85FAF3858420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637223694; bh=K4wkxXVNVbRxVN23fJnZrXRM/y397tq86rJw/aajzVA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xjvRCkwt1pHLVD9EH18smm8cT5U4Bbm8ZfnsOAVfXVtpnxIqlCmI14M4bRpvfhiC3 YOYhjMD89oQzN4SO9vWXfIi7aUwJl81BHmhbh0iicIezKquaHZSBe8sDzzoddnaM5m cEvJ+ZAa6g8+R0kzCAhoPBtgCwawMOnzw4z0RiGE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D79C93858433 for ; Thu, 18 Nov 2021 08:20:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D79C93858433 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-205-qITDu37-OMqAbMe-fBh-yQ-1; Thu, 18 Nov 2021 03:20:38 -0500 X-MC-Unique: qITDu37-OMqAbMe-fBh-yQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 072729F92B for ; Thu, 18 Nov 2021 08:20:37 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A58C35C1D5 for ; Thu, 18 Nov 2021 08:20:36 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1AI8KXi22640270 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Thu, 18 Nov 2021 09:20:34 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1AI8KXTc2640269 for gcc-patches@gcc.gnu.org; Thu, 18 Nov 2021 09:20:33 +0100 Date: Thu, 18 Nov 2021 09:20:33 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] libgomp: Fix up aligned_alloc arguments [PR102838] Message-ID: <20211118082033.GP2710@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! C says that aligned_alloc size must be an integral multiple of alignment. While glibc doesn't care about it, apparently Solaris does. So, this patch decreases the priority of aligned_alloc among the other variants because it needs more work and can waste more memory and rounds up the size to multiple of alignment. Bootstrapped/regtested on x86_64-linux and i686-linux and in the PR Rainer mentioned testing on Solaris, committed to trunk. 2021-11-18 Jakub Jelinek PR libgomp/102838 * alloc.c (gomp_aligned_alloc): Prefer _aligned_alloc over memalign over posix_memalign over aligned_alloc over fallback with malloc instead of aligned_alloc over _aligned_alloc over posix_memalign over memalign over fallback with malloc. For aligned_alloc, round up size up to multiple of al. Jakub --- libgomp/alloc.c.jj 2021-01-04 10:25:56.157037659 +0100 +++ libgomp/alloc.c 2021-11-17 13:32:25.246271672 +0100 @@ -65,18 +65,24 @@ gomp_aligned_alloc (size_t al, size_t si void *ret; if (al < sizeof (void *)) al = sizeof (void *); -#ifdef HAVE_ALIGNED_ALLOC - ret = aligned_alloc (al, size); -#elif defined(HAVE__ALIGNED_MALLOC) +#ifdef HAVE__ALIGNED_MALLOC ret = _aligned_malloc (size, al); -#elif defined(HAVE_POSIX_MEMALIGN) - if (posix_memalign (&ret, al, size) != 0) - ret = NULL; #elif defined(HAVE_MEMALIGN) { extern void *memalign (size_t, size_t); ret = memalign (al, size); } +#elif defined(HAVE_POSIX_MEMALIGN) + if (posix_memalign (&ret, al, size) != 0) + ret = NULL; +#lif defined(HAVE_ALIGNED_ALLOC) + { + size_t sz = (size + al - 1) & ~(al - 1); + if (__builtin_expect (sz >= size, 1)) + ret = aligned_alloc (al, sz); + else + ret = NULL; + } #else ret = NULL; if ((al & (al - 1)) == 0 && size)