From owner-freebsd-hackers@FreeBSD.ORG Mon Sep 8 17:01:45 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 738DE16A4BF for ; Mon, 8 Sep 2003 17:01:45 -0700 (PDT) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8E6A043F85 for ; Mon, 8 Sep 2003 17:01:44 -0700 (PDT) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.9/8.12.3) with ESMTP id h8901XTX005565; Mon, 8 Sep 2003 18:01:33 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Mon, 08 Sep 2003 18:01:01 -0600 (MDT) Message-Id: <20030908.180101.71186801.imp@bsdimp.com> To: John.Giacomoni@colorado.edu From: "M. Warner Losh" In-Reply-To: References: X-Mailer: Mew version 2.1 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit cc: freebsd-hackers@freebsd.org Subject: Re: C++ code in a kernel module? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Sep 2003 00:01:45 -0000 In message: John Giacomoni writes: : How would one go about creating a kernel module which utilizes : C++ code? That's a tough row to hoe. : I was planning on using the macro __cplusplus to toggle using : extern "C" { }, however the bsd.kmod.mk style Makefiles seem to : force the language to -std=c99 even when compiling with c++ . Sounds like a bug to me. : my initial steps have been as follows: : take a functioning C based kernel module and rename to .cc : added extern "C" around the includes. : #defined key words such as new to xxx_new : recompiled the new .cc file by hand without -std=c99, but : keeping all the flags as the Makefile set them. : then linked using the Makefile and finally loaded the module. Boom! That was the big booming sound I heard earlier in the day. : as long as I do not make any calls into kernel functions : things seem to work (load), however when I make a call to : mtx_init then on load i get the following error: : __gxx_personality_v0 undefined. You will need to add all the runtime support. You will need to compile w/o excetions in all likelihood, since it requires DWARF support, iirc. You may also to disable RTTI support. Templates may work, as long as they don't need run time linker support, best to avoid them. I don't know about __gxx_personaility_v0, but your best bet is to look at the .o's and find where it is referenced. Then back track it to what function, then to what construct and go from there. There be dragons here. You are about to become very familiar with the version of g++ that you are working with as well as subtle variations that happen with different compiler flags. I've tried it in the past and there are lots of issues. Warner