From owner-freebsd-arch@FreeBSD.ORG Sat Feb 28 12:32:26 2009 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 91856106567A for ; Sat, 28 Feb 2009 12:32:26 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from fallbackmx06.syd.optusnet.com.au (fallbackmx06.syd.optusnet.com.au [211.29.132.8]) by mx1.freebsd.org (Postfix) with ESMTP id 706E78FC1A for ; Sat, 28 Feb 2009 12:32:24 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail03.syd.optusnet.com.au (mail03.syd.optusnet.com.au [211.29.132.184]) by fallbackmx06.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id n1S7iLYf021623 for ; Sat, 28 Feb 2009 18:44:21 +1100 Received: from c122-107-120-227.carlnfd1.nsw.optusnet.com.au (c122-107-120-227.carlnfd1.nsw.optusnet.com.au [122.107.120.227]) by mail03.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id n1S7hs0t026076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 28 Feb 2009 18:43:55 +1100 Date: Sat, 28 Feb 2009 18:43:54 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Alexander Kabaev In-Reply-To: <20090227132242.4ef6a633@kan.dnsalias.net> Message-ID: <20090228175724.D14305@delplex.bde.org> References: <20090227131155.GE19161@hoeg.nl> <20090227131221.GA60215@freebsd.org> <49A80F4D.8000406@icyb.net.ua> <20090227132242.4ef6a633@kan.dnsalias.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Ed Schouten , Roman Divacky , FreeBSD@freebsd.org, Andriy Gapon , Arch Subject: Re: Making LLVM happy: memmove() in the kernel X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Feb 2009 12:32:27 -0000 On Fri, 27 Feb 2009, Alexander Kabaev wrote: > On Fri, 27 Feb 2009 18:05:33 +0200 > Andriy Gapon wrote: > >> on 27/02/2009 15:12 Roman Divacky said the following: >>> On Fri, Feb 27, 2009 at 02:11:55PM +0100, Ed Schouten wrote: >>>> Hi all, >>>> >>>> The FreeBSD+LLVM folks* noticed Clang generates calls to memmove() >>>> by itself. I have yet to confirm this, but I assume this is done >>>> when performing copies of structs greater than a certain size. In Why would Clang be that broken? Structs cannot overlap, so they can be copied by memcpy() which should be faster. (However, in the FreeBSD kernel, use of memcpy() is only approved for fixed-sized copies small enough to be inlined, so memcpy() is only a placeholder for the non-inlined case and for abuse, and extensive optimizations are only applied to bcopy() and bcopy() might be faster; however2, the optimizations don't work for any current hardware so memcpy() should be faster than bcopy() because it is simpler. The inlining also fails in all cases since _all_ gcc builtins were turned off many years as a side effect of using -ffreestanding (see below for more details). The loss was so insignficant that no one noticed it. Even now, with the placeholders for memcpy() and memset() abused a lot, fixing their inlining makes no significant difference.) >>>> our kernel, we don't have a memmove() function, but we do have a >>>> bcopy(). >>> >>> also.. quoting from >>> (http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Standards.html): >>> >>> Most of the compiler support routines used by GCC are present in >>> libgcc, but there are a few exceptions. GCC requires the >>> freestanding environment provide memcpy, memmove, memset and memcmp. >>> >>> we were just lucky to not run into this Since this is a bug in gcc, we were unlucky to run into it. These functions are in the application namespace in freestanding environments. Compiler support functions must be named something like __memmove(). FreeBSD started using -ffreestanding mainly to avoid related bugs. The gcc builtin for printf() sometimes translates printf() to use puts() and perhaps any function in stdio. FreeBSD has printf() but not puts() in the kernel so linkage started failing when gcc implemented builtin printf (similarly for a couple of other standard library functions). The problem was fixed by compiling all FreeBSD kernels with -ffreestanding, which was implemented in gcc at about the same time that builtin printf was implemented. -ffreestanding must kill all standard library functions. But them it necessarily kills all builtins for such functions and thus prevents automatic inlining of everything in . >> Some people actually were not that lucky and had to use similar >> workarounds. > > I think we should use this opportunity and make sure we have external > symbols for all of the above mem* functions, not just memmove. Please :) How do you make them fully external so that they are only used by broken external software? Bruce