Skip to contentSkip to conversation

Behaviour of kernel makefiles when entering a subdir using a config symbol = m

DISCUSSION Tomi Valkeinen 3 participants 5 messages Dec 9, 2015 – Dec 11, 2015 Kbuild

lore
Share & tools
lore
#0 lore raw

Hi,

I wonder if this is as designed, or a bug:

I have a makefile which has

obj-$(CONFIG_FOO) += foo/

In the foo directory, I have a makefile which has

obj-$(CONFIG_FOO_BAR) += bar.o

The values of the variables are

CONFIG_FOO=m
CONFIG_FOO_BAR=y

When building the kernel with the above setup, I would expect make to enter the foo/ directory, and build 'bar.o' into the kernel image.

And make does enter the directory, and does compile 'bar.o', but I think 'bar.o' doesn't end up anywhere. At least it's not compiled into the kernel image.

If CONFIG_FOO=y, then 'bar.o' will be built in to the kernel image.

Am I doing something wrong here?

Tomi

#1 lore raw
Quoted 17 lines · Tomi Valkeinen

Hi,

I wonder if this is as designed, or a bug:

I have a makefile which has

obj-$(CONFIG_FOO) += foo/

In the foo directory, I have a makefile which has

obj-$(CONFIG_FOO_BAR) += bar.o

The values of the variables are

CONFIG_FOO=m
CONFIG_FOO_BAR=y

Quoted 6 lines

When building the kernel with the above setup, I would expect make to enter the foo/ directory, and build 'bar.o' into the kernel image.

And make does enter the directory, and does compile 'bar.o', but I think 'bar.o' doesn't end up anywhere. At least it's not compiled into the kernel image.

kbuild may enter a sub directory for two purposes:
1) to build object files to be part of the final image Only subdirs specified using obj-y is visited.

2) to build object files that will be included in a module Subdirs specified with obj-y and obj-m is visited

Since you have the following code in your Makefile:

    obj-m += foo/

then foo/ is only visited to build modules.

So bar.o is built but is NOT included in the final image. This is also the behaviour you see.

Sam

#2 lore raw

Hi Sam,

Quoted 7 lines · Sam Ravnborg

kbuild may enter a sub directory for two purposes:
1) to build object files to be part of the final image Only subdirs specified using obj-y is visited.

2) to build object files that will be included in a module Subdirs specified with obj-y and obj-m is visited

Quoted 8 lines

Since you have the following code in your Makefile:

    obj-m += foo/

then foo/ is only visited to build modules.

So bar.o is built but is NOT included in the final image. This is also the behaviour you see.

Right.

We have three drivers (one fbdev, two drm), each of which can be built as a module. But each of them also may require small boot-time setup, which needs to be built-in.

I can get around the problem by entering the dir with obj-y, or by creating a new extra config define which is y/n, and using that in the makefile. The former makes make enter the dir even if the driver is not enabled, and latter creates a config symbol only to solve this problem.

So I'd rather use the normal obj-$(CONFIG_MYDRIVER), as that's used by all the fbdev and drm drivers, and (to me) makes most sense.

Is the purpose of the current behaviour to speed up the build when compiling only the modules? Or why does it behave that way?

Tomi

#3 lore raw
Quoted 22 lines · Tomi Valkeinen

Hi Sam,

Quoted 7 lines · Sam Ravnborg

kbuild may enter a sub directory for two purposes:
1) to build object files to be part of the final image Only subdirs specified using obj-y is visited.

2) to build object files that will be included in a module Subdirs specified with obj-y and obj-m is visited

Quoted 8 lines

Since you have the following code in your Makefile:

    obj-m += foo/

then foo/ is only visited to build modules.

So bar.o is built but is NOT included in the final image. This is also the behaviour you see.

Right.

Quoted 8 lines

We have three drivers (one fbdev, two drm), each of which can be built as a module. But each of them also may require small boot-time setup, which needs to be built-in.

I can get around the problem by entering the dir with obj-y, or by creating a new extra config define which is y/n, and using that in the makefile. The former makes make enter the dir even if the driver is not enabled, and latter creates a config symbol only to solve this problem.

The extra config symbol is the most elegant solution here IMO. Make sure to document that this config symbol enables the boot-time setup stuff.

Sam

#4 lore raw

Dne 10.12.2015 v 21:46 Sam Ravnborg napsal(a):

Quoted 5 lines · Tomi Valkeinen
Quoted 4 lines

We have three drivers (one fbdev, two drm), each of which can be built as a module. But each of them also may require small boot-time setup, which needs to be built-in.

Quoted 7 lines
Quoted 4 lines

I can get around the problem by entering the dir with obj-y, or by creating a new extra config define which is y/n, and using that in the makefile. The former makes make enter the dir even if the driver is not enabled, and latter creates a config symbol only to solve this problem.

The extra config symbol is the most elegant solution here IMO. Make sure to document that this config symbol enables the boot-time setup stuff.

Agreed. We could tech kbuild to look for built-in.o also in obj-m subdirs, but I'm quite sure it would break a Makefile or two. We had this case when adding support for modname-m recently, a couple of Makefiles did not expect this and broke.

Michal