From owner-freebsd-hackers@FreeBSD.ORG Sat Nov 29 11:40:53 2008 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 5217D1065678 for ; Sat, 29 Nov 2008 11:40:53 +0000 (UTC) (envelope-from laladelausanne@gmail.com) Received: from yx-out-2324.google.com (yx-out-2324.google.com [74.125.44.28]) by mx1.freebsd.org (Postfix) with ESMTP id 011CB8FC1F for ; Sat, 29 Nov 2008 11:40:52 +0000 (UTC) (envelope-from laladelausanne@gmail.com) Received: by yx-out-2324.google.com with SMTP id 8so704671yxb.13 for ; Sat, 29 Nov 2008 03:40:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :in-reply-to:content-type:mime-version:subject:date:references :x-mailer; bh=UYIsVLXP8HVm9JOA3aFYdrWZgnQX0RFk2dUnqX8ngQQ=; b=OKqZrj6Fbw6NTAGFRFV7qoBOT/B3ykW10BNafFTIXP4DFL1QSVkc02feHlxXL40fvP wwDZv2vo/PCQgWeb17bD1xKxt6z27vscxNKKPpTWzhzwQwYJd6GsczTu7rAshe5oLvan yNJnn79+a9YdSGPljzo6CJfOm6yVs2neOKQgw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:in-reply-to:content-type:mime-version:subject :date:references:x-mailer; b=xogrQolLnAa+ZcgDbpL3tgq9ylmcEkp94rmfOm4P+ItIbvWNHx4FVy38fFVPq+3I91 MB80dsHF0s2/IKm/SorM4A11VjvLEB/9wRTtT/Y6NTMDx5Md3ey/nwzg8v4A/Llo2HBD YakYXZn9EjgUxpM4jhXJmHVL3cnbg5Bmrft2k= Received: by 10.103.171.20 with SMTP id y20mr3563280muo.122.1227958849941; Sat, 29 Nov 2008 03:40:49 -0800 (PST) Received: from ?192.168.1.11? (dyn.144-85-135-130.dsl.vtx.ch [144.85.135.130]) by mx.google.com with ESMTPS id u9sm2442036muf.4.2008.11.29.03.40.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 29 Nov 2008 03:40:49 -0800 (PST) Message-Id: <2A1A4C21-8A2D-4151-BCA0-5FAE1D3BBE86@gmail.com> From: =?UTF-8?Q?Nikola_Kne=C5=BEevi=C4=87?= To: freebsd-hackers@freebsd.org In-Reply-To: <711D7381-D852-4B6B-991A-84BA6DEFB679@gmail.com> Content-Type: multipart/mixed; boundary=Apple-Mail-17-543544471 Mime-Version: 1.0 (Apple Message framework v929.2) Date: Sat, 29 Nov 2008 12:40:47 +0100 References: <711D7381-D852-4B6B-991A-84BA6DEFB679@gmail.com> X-Mailer: Apple Mail (2.929.2) Subject: Re: How to build kernel module spread on subdirectories? 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: Sat, 29 Nov 2008 11:40:53 -0000 --Apple-Mail-17-543544471 Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable On 25 Nov 2008, at 15:20 , Nikola Kne=C5=BEevi=C4=87 wrote: > I tried to move from OBJS into SRCS (main BSDmakefile now has: SRCS+=3D=20= > $(ELEMENT_SRCS)), by using something like: > # subdir0 > ELEMENT_SRCS__x =3D\ > subdir1/file0.cc \ > subdir1/file1.cc > > ... > > But this fails during the linking phase, because the linker is =20 > called with subdir1/file0.o, instead of just file0.o. > > To make something clear, I didn't just rewrite the GNUmakefile to =20 > BSDmakefile, I also followed some of the logic used to build kernel =20= > modules. I'm including bsd.kmod.ko, list sources in SRCS, don't have =20= > any explicit rule to build .o out of .cc/.c. There is no all: =20 > target, as well. Hi, since there were no replies, I went into the various .mk's, and I =20 found some inconsistencies when building modules. If you have a file =20 in a different directory, below the directory where you BSDmakefile =20 is, objects won't be linked nor cleaned properly. Default .c rule builds the object file in the .OBJDIR. But, when we =20 have files with absolute paths in SRCS, they get transfered verbatim =20 to OBJS, transforming only the suffix .c -> .o. When we want to build =20= the module, final rule is (at least on amd64): ${FULLPROG}: ${OBJS} ${LD} ... -o ${.TARGET} ${OBJS} which is wrong, because linker gets the absolute paths to .o files, =20 which do not exist at that place. It would be better to use ${OBJS:T} So I propose the attached patch kmod.ko to circumvent this problem. While I'm at it, I've attached another patch for /usr/share/mk/sys.mk, =20= which resolves a problem when one uses g++ during a building of a =20 kernel module. Cheers, Nikola =20= --Apple-Mail-17-543544471 Content-Disposition: attachment; filename=kmod.mk.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="kmod.mk.patch" Content-Transfer-Encoding: 7bit --- kmod.mk.orig 2008-11-29 12:28:54.000000000 +0100 +++ kmod.mk 2008-11-29 12:27:26.000000000 +0100 @@ -193,7 +193,7 @@ .else ${FULLPROG}: ${OBJS} .endif - ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} + ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS:T} .if defined(EXPORT_SYMS) .if ${EXPORT_SYMS} != YES .if ${EXPORT_SYMS} == NO @@ -251,7 +251,7 @@ ${ECHO} ${.TARGET} "->" $$path ; \ ln -sf $$path ${.TARGET} -CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} +CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS:T} .if defined(DEBUG_FLAGS) CLEANFILES+= ${FULLPROG} ${PROG}.symbols --Apple-Mail-17-543544471 Content-Disposition: attachment; filename=sys.mk.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="sys.mk.patch" Content-Transfer-Encoding: 7bit --- sys.mk~ 2008-09-05 16:30:26.000000000 +0200 +++ sys.mk 2008-09-16 14:59:40.000000000 +0200 @@ -62,7 +62,7 @@ .endif CXX ?= c++ -CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign} +CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:S/-ffreestanding/-fno-builtin/g} CPP ?= cpp --Apple-Mail-17-543544471--