Skip to contentSkip to conversation

fix kbuild module names (was: Re: oom-killer problem)

PATCH In review Daniel Ritz 3 participants 3 messages Jun 28, 2006 – Jun 30, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix kbuild module names (was: Re: oom-killer problem)

hi

had a look again. this one on top of "kbuild: fix make -rR breakage" (ie. revert the revert) should fix the module nameing.

Sam if you agree, please add your signed-off-by and forward to Linus.

rgds
-daniel

---

[PATCH] kbuild: fix module names

commit e5c44fd88c146755da6941d047de4d97651404a9 (kbuild: fix make -rR breakage) replaced the usage of the $(*F) variable with $(basetarget) which is defined as

	 basetarget = $(basename $(notdir $@))

to get the same, but without using the stem $(*F) because make not always correctly supplys it. the problem are the module names which depend on the name of 'foo.mod.o'. the original usage of the stem $(*F) gave 'foo' in this case, but the new $(basetarget) does not. example from a
make -p SUBDIRS=drivers/pcmcia modules

drivers/pcmcia/pcmcia.mod.o: drivers/pcmcia/pcmcia.mod.c FORCE # Implicit rule search has not been done.
# Implicit/static pattern stem: `drivers/pcmcia/pcmcia' # Last modified 2006-06-28 16:00:14
# File has been updated.
# Successfully updated.
# automatic
# @ := drivers/pcmcia/pcmcia.mod.o
# automatic
# % :=
# automatic
# * := drivers/pcmcia/pcmcia
[snip]

so the stem for 'drivers/pcmcia/pcmcia.mod.o' is just 'drivers/pcmcia/pcmcia' which gives the correct module name. so to get back the "old" behaviour without using the stem do an additional patsubst to get rid of the '.mod'

scripts/Kbuild.include +1 -1
index ac5f275..af3c1b6 100644
@@ -15,7 +15,7 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F
 ###
 # basetarget equals the filename of the target with no extension.
 # So 'foo/bar.o' becomes 'bar'
-basetarget = $(basename $(notdir $@))
+basetarget = $(patsubst %.mod,%,$(basename $(notdir $@)))
 
 ###
 # Escape single quote for use in echo statements
#1 lore raw
Quoted 5 lines · Daniel Ritz

had a look again. this one on top of "kbuild: fix make -rR breakage" (ie. revert the revert) should fix the module nameing.

Sam if you agree, please add your signed-off-by and forward to Linus.

Btw, I suspect I was wrong on the use of basename.

Yeah, you can do it carefully with that $(patsubst %.mod,%,..) thing, but boy is that ugly and hard to read. Since the whole point was to hopefully be safer, being "ugly and hard to read" is not exactly good, and I suspect the original $(basename ..) was simply better.

Linus

#2 lore raw
Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Daniel Ritz

had a look again. this one on top of "kbuild: fix make -rR breakage" (ie. revert the revert) should fix the module nameing.

Quoted 8 lines
Quoted 1 line

Sam if you agree, please add your signed-off-by and forward to Linus.

Btw, I suspect I was wrong on the use of basename.

Yeah, you can do it carefully with that $(patsubst %.mod,%,..) thing, but boy is that ugly and hard to read. Since the whole point was to hopefully be safer, being "ugly and hard to read" is not exactly good, and I suspect the original $(basename ..) was simply better.

Following is my take on it. In most cases $(basename $(notdir $@)) do the trick. Only in Makefile.modpost we do some special to get rid of .mod.o. That part is not nice but local to Makefile.modpost.

I will push it as soon as I get a confirmation that ia64 is fixed with this fix.

Sam

Makefile +1 -1
index e9560c6..c4ea9cd 100644
@@ -1352,7 +1352,7 @@ quiet_cmd_rmfiles = $(if $(wildcard $(rm
 
 a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
 	  $(NOSTDINC_FLAGS) $(CPPFLAGS) \
-	  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
+	  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(notdir $@))
 
 quiet_cmd_as_o_S = AS      $@
 cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
arch/um/scripts/Makefile.rules +2 -2
index 1347dc6..813077f 100644
@@ -8,7 +8,7 @@ USER_OBJS += $(filter %_user.o,$(obj-y) 
 USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
 
 $(USER_OBJS:.o=.%): \
-	c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) $(CFLAGS_$(*F).o)
+	c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) $(CFLAGS_$(basetarget).o)
 $(USER_OBJS) : CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ \
 	-Dunix -D__unix__ -D__$(SUBARCH)__
 
@@ -17,7 +17,7 @@ # using it directly.
 UNPROFILE_OBJS := $(foreach file,$(UNPROFILE_OBJS),$(obj)/$(file))
 
 $(UNPROFILE_OBJS:.o=.%): \
-	c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) $(CFLAGS_$(*F).o)
+	c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) $(CFLAGS_$(basetarget).o)
 $(UNPROFILE_OBJS) : CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ \
 	-Dunix -D__unix__ -D__$(SUBARCH)__
 
scripts/Kbuild.include +4 -0
index b0d067b..2180c88 100644
@@ -13,6 +13,10 @@ # contain a comma
 depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
 
 ###
+# filename of target with directory and extension stripped
+basetarget = $(basename $(notdir $@))
+
+###
 # Escape single quote for use in echo statements
 escsq = $(subst $(squote),'\$(squote)',$1)
 
scripts/Makefile.build +1 -1
index 02a7eea..3cb445c 100644
@@ -117,7 +117,7 @@ quiet_modtag := $(empty)   $(empty)
 $(obj-m)              : quiet_modtag := [M]
 
 # Default for not multi-part modules
-modname = $(*F)
+modname = $(basetarget)
 
 $(multi-objs-m)         : modname = $(modname-multi)
 $(multi-objs-m:.o=.i)   : modname = $(modname-multi)
scripts/Makefile.host +4 -2
index 2b066d1..18ecd4d 100644
@@ -80,8 +80,10 @@ obj-dirs += $(host-objdirs)
 #####
 # Handle options to gcc. Support building with separate output directory
 
-_hostc_flags   = $(HOSTCFLAGS)   $(HOST_EXTRACFLAGS)   $(HOSTCFLAGS_$(*F).o)
-_hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) $(HOSTCXXFLAGS_$(*F).o)
+_hostc_flags   = $(HOSTCFLAGS)   $(HOST_EXTRACFLAGS)   \
+                 $(HOSTCFLAGS_$(basetarget).o)
+_hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
+                 $(HOSTCXXFLAGS_$(basetarget).o)
 
 ifeq ($(KBUILD_SRC),)
 __hostc_flags	= $(_hostc_flags)
scripts/Makefile.lib +3 -3
index 2cb4935..fc498fe 100644
@@ -82,12 +82,12 @@ # Note: It's possible that one object ge
 #       than one module. In that case KBUILD_MODNAME will be set to foo_bar,
 #       where foo and bar are the name of the modules.
 name-fix = $(subst $(comma),_,$(subst -,_,$1))
-basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(*F)))"
+basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))"
 modname_flags  = $(if $(filter 1,$(words $(modname))),\
                  -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
 
-_c_flags       = $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o)
-_a_flags       = $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
+_c_flags       = $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(basetarget).o)
+_a_flags       = $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(basetarget).o)
 _cpp_flags     = $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS_$(@F))
 
 # If building the kernel in a separate objtree expand all occurrences
scripts/Makefile.modpost +1 -1
index 576cce5..a495502 100644
@@ -72,7 +72,7 @@ # Declare generated files as targets for
 # Step 5), compile all *.mod.c files
 
 # modname is set to make c_flags define KBUILD_MODNAME
-modname = $(*F)
+modname = $(notdir $(@:.mod.o=))
 
 quiet_cmd_cc_o_c = CC      $@
       cmd_cc_o_c = $(CC) $(c_flags) $(CFLAGS_MODULE)	\