From patchwork Fri Nov 13 17:11:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 544393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 69671141420 for ; Sat, 14 Nov 2015 04:11:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=IQ7wce71; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=B5v1mL8P05PHZIivV2StPRDThxNpiLMCZpXngrEEfzz eQCxwOORKcKCAeLvz9nmwuX1eNBhlO+1L3Frw7Y5o4bqHaoBZl4PJCecx8PJxZhV HCE7+q6tn/PGTiQECYaUK/Egbr/QXIdUmqFeVhQfBB8E+G7vpu8mnW44YIMw2+54 = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=OfP8wv+ZVo/zyDF2aNU8ZFlfOvQ=; b=IQ7wce71UTPNGRmpV TKshh57XbZh2smbyQWiHj8XnR8YWDMx8sY+gbJReSOuucSEc9xdD7RnbHu8geOG/ SUdJ2JCrvnujpMSAptEZD2AsfxH3KN/8cSnB+SVUL15n8XaJ/qcKH6WmWRWA+QGv GqN/INplpKeGomkkq8mARXO0Uk= Received: (qmail 95219 invoked by alias); 13 Nov 2015 17:11:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 95204 invoked by uid 89); 13 Nov 2015 17:11:27 -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, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Nov 2015 17:11:26 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-25-u-SMABj-TaS7MF8nH2lpTw-1; Fri, 13 Nov 2015 17:11:19 +0000 Received: from [10.2.206.40] ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 13 Nov 2015 17:11:18 +0000 Message-ID: <564619AE.4020108@arm.com> Date: Fri, 13 Nov 2015 17:11:10 +0000 From: Szabolcs Nagy User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: "H.J. Lu" , Rich Felker Subject: [PATCH, x86] Fix posix_memalign declaration in mm_malloc.h X-MC-Unique: u-SMABj-TaS7MF8nH2lpTw-1 X-IsSubscribed: yes Followup to https://gcc.gnu.org/ml/gcc-patches/2015-05/msg01433.html The posix_memalign declaration is incompatible with musl libc in C++, because of the exception specification (matters with -std=c++11 -pedantic-errors). It also pollutes the namespace and lacks protection against a potential macro definition that is allowed by POSIX. The fix avoids source level namespace pollution but retains the dependency on the posix_memalign extern libc symbol. Added a test case for the namespace issue. OK for trunk? gcc/ChangeLog: 2015-11-13 Szabolcs Nagy * config/i386/pmm_malloc.h (posix_memalign): Renamed to ... (_mm_posix_memalign): This. Use posix_memalign as extern symbol only. gcc/testsuite/ChangeLog: 2015-11-13 Szabolcs Nagy * g++.dg/other/mm_malloc.C: New. diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h index 901001b..0696c20 100644 --- a/gcc/config/i386/pmm_malloc.h +++ b/gcc/config/i386/pmm_malloc.h @@ -27,12 +27,13 @@ #include /* We can't depend on since the prototype of posix_memalign - may not be visible. */ + may not be visible and we can't pollute the namespace either. */ #ifndef __cplusplus -extern int posix_memalign (void **, size_t, size_t); +extern int _mm_posix_memalign (void **, size_t, size_t) #else -extern "C" int posix_memalign (void **, size_t, size_t) throw (); +extern "C" int _mm_posix_memalign (void **, size_t, size_t) throw () #endif +__asm__("posix_memalign"); static __inline void * _mm_malloc (size_t size, size_t alignment) @@ -42,7 +43,7 @@ _mm_malloc (size_t size, size_t alignment) return malloc (size); if (alignment == 2 || (sizeof (void *) == 8 && alignment == 4)) alignment = sizeof (void *); - if (posix_memalign (&ptr, alignment, size) == 0) + if (_mm_posix_memalign (&ptr, alignment, size) == 0) return ptr; else return NULL; diff --git a/gcc/testsuite/g++.dg/other/mm_malloc.C b/gcc/testsuite/g++.dg/other/mm_malloc.C new file mode 100644 index 0000000..00582cc --- /dev/null +++ b/gcc/testsuite/g++.dg/other/mm_malloc.C @@ -0,0 +1,17 @@ +/* { dg-do compile { target i?86-*-* x86_64-*-* } } */ +/* { dg-options "-std=c++11" } */ + +/* Suppress POSIX declarations in libc headers in standard C++ mode. */ +#undef _GNU_SOURCE + +#define posix_memalign user_can_do_this + +#include + +void * +foo () +{ + return _mm_malloc (16, 16); +} + +/* { dg-final { scan-assembler "call\\tposix_memalign" } } */