Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Nov 2008 12:40:47 +0100
From:      =?UTF-8?Q?Nikola_Kne=C5=BEevi=C4=87?= <laladelausanne@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: How to build kernel module spread on subdirectories?
Message-ID:  <2A1A4C21-8A2D-4151-BCA0-5FAE1D3BBE86@gmail.com>
In-Reply-To: <711D7381-D852-4B6B-991A-84BA6DEFB679@gmail.com>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On 25 Nov 2008, at 15:20 , Nikola Knežević wrote:
> I tried to move from OBJS into SRCS (main BSDmakefile now has: SRCS+= 
> $(ELEMENT_SRCS)), by using something like:
> # subdir0
> ELEMENT_SRCS__x =\
> subdir1/file0.cc \
> subdir1/file1.cc
>
> ...
>
> But this fails during the linking phase, because the linker is  
> called with subdir1/file0.o, instead of just file0.o.
>
> To make something clear, I didn't just rewrite the GNUmakefile to  
> BSDmakefile, I also followed some of the logic used to build kernel  
> modules. I'm including bsd.kmod.ko, list sources in SRCS, don't have  
> any explicit rule to build .o out of .cc/.c. There is no all:  
> target, as well.

Hi,

since there were no replies, I went into the various .mk's, and I  
found some inconsistencies when building modules. If you have a file  
in a different directory, below the directory where you BSDmakefile  
is, objects won't be linked nor cleaned properly.

Default .c rule builds the object file in the .OBJDIR. But, when we  
have files with absolute paths in SRCS, they get transfered verbatim  
to OBJS, transforming only the suffix .c -> .o. When we want to build  
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,  
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,  
which resolves a problem when one uses g++ during a building of a  
kernel module.


Cheers,
Nikola

  
[-- Attachment #2 --]
--- 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

[-- Attachment #3 --]
--- 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
 
home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2A1A4C21-8A2D-4151-BCA0-5FAE1D3BBE86>