From owner-freebsd-hackers@FreeBSD.ORG Wed Jan 21 23:26:11 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4F50D106564A for ; Wed, 21 Jan 2009 23:26:11 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from mail-fx0-f11.google.com (mail-fx0-f11.google.com [209.85.220.11]) by mx1.freebsd.org (Postfix) with ESMTP id A9B5F8FC08 for ; Wed, 21 Jan 2009 23:26:10 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: by fxm4 with SMTP id 4so973517fxm.19 for ; Wed, 21 Jan 2009 15:26:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=nTnxSF+6Ntb4BIbyBn+MHaHZp6gPGuagHsbLvVOzdeE=; b=AExo+/5x3dnOuP2wKEIKqmu5iEwSalZt8//fCRalLVwhFmAEd14jvWzlkUOjIV/vEc RFiuRfvl9BHngJuondd2AI7OkKQ9rOqm2NJFuyC9BuWXIXd9mrbW1DzN17swcxAOqc7+ vrVug1oQ5nNK7c5LDTwt0iGa+xEGDAMJL5egc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=v/c0RMZ/IKCD1lkCmgvGKDDT5w+ks9EmPoSA3t6BABrjmYJJQDGkxgfrp9jocDJ55N A51sIPZ+hqnOkE2ZNAJtEoij8t6lS96c2RSmufkgxRswNDgWMzcgjwHs3RquuebYv/mI xKnJqOBfD7hFHGLtto4h39KPUOXactaDNqWuY= MIME-Version: 1.0 Received: by 10.181.137.17 with SMTP id p17mr3060666bkn.193.1232580369399; Wed, 21 Jan 2009 15:26:09 -0800 (PST) In-Reply-To: References: Date: Wed, 21 Jan 2009 15:26:09 -0800 Message-ID: <7d6fde3d0901211526x26e03968n658874fe7a7b85cf@mail.gmail.com> From: Garrett Cooper To: Andrew Brampton Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org Subject: Re: Kernel Module - GCC Requires memmove X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jan 2009 23:26:11 -0000 On Wed, Jan 21, 2009 at 4:12 AM, Andrew Brampton wrote: > Hi, > I'm doing the unusual task of converting some c++ code into a FreeBSD > kernel module. Now all has been going great, and thus far I've been > able to debug quite a bit of it using printfs. However, I decided to > start using a kernel debugger, and to make this easier I passed g++ > the =96O0 flag, to make it compile without optimisations. > > Bang, I hit a problem. All of a sudden when using the =96O0 my module > wouldn't load because it was missing an undefined reference to > memmove. I found the specific object file which was using memmove. I > did that by doing objdump =96t *.o and finding which file had an > undefined symbol memmove. Once I found the object file I grepped the > associated source and I was sure I was not using memmove. I then got > gcc to output both the post-processed source, as well as the asm. > > The .ii file (post-processed source) did NOT mention memmove at all. > So I found it very odd that an undefined symbol existed in the object > file. So then I looked in the .s file (asm), and it was clearing > making a single call to memmove. > > So after a few hours of pulling my hair out I found this in the gcc manua= l: > "-nostdlib .... The compiler may generate calls to memcmp, memset, > memcpy and memmove. These entries are usually resolved by entries in > libc. These entry points should be supplied through some other > mechanism when this option is specified." > > So it appears that gcc may add calls to those four functions even if > you don't use them yourself? I assume this has not been a problem for > anyone yet due to only crazy people trying to use c++ in the kernel, > and the specific set of gcc options I'm using. > > For the moment I have fixed this problem now by defining my own memmove l= ike so: > > extern "C" void * memmove(void * dst, const void * src, size_t len) { > bcopy(src, dst, len); > return dst; > } > > But I was wondering if those four functions should be defined in the > kernel? I notice that memcpy and memset are already defined by the > kernel somewhere, so perhaps memmove and memcmp should join them? > > Oh I should mention this was happening with the default gcc under FreeBSD= 7.1. > > Thanks > Andrew And you #include'd string.h? -Garrett