Skip to contentSkip to conversation

kbuild: Include external modules compile flags

PATCH In review Greg Rose 2 participants 7 messages Jan 27, 2020 – Feb 5, 2020 Kbuild

lore
Share & tools
lore

Greg Rose

author
#0 lore raw

PATCH 1/1 kbuild: Include external modules compile flags

Since this commit:
'commit 9b9a3f20cbe0 ("kbuild: split final module linking out into Makefile.modfinal")' at least one out-of-tree external kernel module build fails
during the modfinal make phase because Makefile.modfinal does
not include the ccflags-y variable from the exernal module's Kbuild.
Make sure to include the external kernel module's Kbuild so that the necessary command line flags from the external module are set.

---
 scripts/Makefile.modfinal | 4 ++++
 1 file changed, 4 insertions(+)
scripts/Makefile.modfinal +4 -0
index 411c1e60..a645ba6 100644
@@ -21,6 +21,10 @@ __modfinal: $(modules)
 modname = $(notdir $(@:.mod.o=))
 part-of-module = y
 
+# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
+include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
+             $(KBUILD_EXTMOD)/Kbuild)
+
 quiet_cmd_cc_o_c = CC [M]  $@
       cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · Greg Rose

Since this commit:
'commit 9b9a3f20cbe0 ("kbuild: split final module linking out into Makefile.modfinal")' at least one out-of-tree external kernel module build fails
during the modfinal make phase because Makefile.modfinal does
not include the ccflags-y variable from the exernal module's Kbuild.

ccflags-y is passed only for compiling C files in that directory.

It is not used for compiling *.mod.c
This is true for both in-kernel and external modules.

So, ccflags-y is not a good choice
for passing such flags that should be globally effective.

Maybe, KCFLAGS should work.

module:

       $(MAKE) KCFLAGS=...  M=$(PWD) -C /lib/modules/$(uname -r)/build modules
Quoted 28 lines

Make sure to include the external kernel module's Kbuild so that the necessary command line flags from the external module are set.

---
 scripts/Makefile.modfinal | 4 ++++
 1 file changed, 4 insertions(+)
scripts/Makefile.modfinal +4 -1
index 411c1e60..a645ba6 100644
@@ -21,6 +21,10 @@ __modfinal: $(modules)
 modname = $(notdir $(@:.mod.o=))
 part-of-module = y
 
+# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
+include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
+             $(KBUILD_EXTMOD)/Kbuild)
+
 quiet_cmd_cc_o_c = CC [M]  $@
       cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
 
--

1.8.3.1

Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw
Quoted 15 lines · Masahiro Yamada
Quoted 5 lines · Greg Rose

Since this commit:
'commit 9b9a3f20cbe0 ("kbuild: split final module linking out into Makefile.modfinal")' at least one out-of-tree external kernel module build fails
during the modfinal make phase because Makefile.modfinal does
not include the ccflags-y variable from the exernal module's Kbuild.

ccflags-y is passed only for compiling C files in that directory.

It is not used for compiling *.mod.c
This is true for both in-kernel and external modules.

So, ccflags-y is not a good choice
for passing such flags that should be globally effective.

Quoted 6 lines

Maybe, KCFLAGS should work.

module:

        $(MAKE) KCFLAGS=...  M=$(PWD) -C /lib/modules/$(uname -r)/build modules

Thanks,

I'll see if I can get that to work.

- Greg

Quoted 30 lines
Quoted 29 lines

Make sure to include the external kernel module's Kbuild so that the necessary command line flags from the external module are set.

---
  scripts/Makefile.modfinal | 4 ++++
  1 file changed, 4 insertions(+)
scripts/Makefile.modfinal +4 -1
index 411c1e60..a645ba6 100644
@@ -21,6 +21,10 @@ __modfinal: $(modules)
  modname = $(notdir $(@:.mod.o=))
  part-of-module = y
 
+# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
+include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
+             $(KBUILD_EXTMOD)/Kbuild)
+
  quiet_cmd_cc_o_c = CC [M]  $@
        cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
 
--

1.8.3.1

#3 lore raw
Quoted 16 lines · Gregory Rose
Quoted 15 lines · Masahiro Yamada
Quoted 5 lines · Greg Rose

Since this commit:
'commit 9b9a3f20cbe0 ("kbuild: split final module linking out into Makefile.modfinal")' at least one out-of-tree external kernel module build fails
during the modfinal make phase because Makefile.modfinal does
not include the ccflags-y variable from the exernal module's Kbuild.

ccflags-y is passed only for compiling C files in that directory.

It is not used for compiling *.mod.c
This is true for both in-kernel and external modules.

So, ccflags-y is not a good choice
for passing such flags that should be globally effective.

Quoted 7 lines
Quoted 7 lines

Maybe, KCFLAGS should work.

module:
        $(MAKE) KCFLAGS=...  M=$(PWD) -C /lib/modules/$(uname -r)/build modules

Hi Masahiro,

I'm unable to get that to work.  KCFLAGS does not seem to be used in Makefile.modfinal.

[snip]

Quoted 10 lines
Quoted 10 lines

scripts/Makefile.modfinal __modfinal: $(modules) · line 27

Quoted 10 lines
scripts/Makefile.modfinal +0 -0
@@ -21,6 +21,10 @@ __modfinal: $(modules)
   modname = $(notdir $(@:.mod.o=))

  part-of-module = y

scripts/Makefile.modfinal +4 -0
+# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
+include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
+             $(KBUILD_EXTMOD)/Kbuild)
+

I continue to wonder why this it is so bad to include the external module's Kbuild. It used to be included in Makefile.modpost and did no harm, and in fact was what made our external build work at all in the past.  Without the ability to define our local kernel module build environment during the modfinal make I see no way forward.

That said, I'm no expert on the Linux kernel Makefile interdependencies.  If you have some other idea we could try I'm game.

Thanks,

- Greg

#4 lore raw
Quoted 28 lines · Gregory Rose
Quoted 17 lines · Gregory Rose
Quoted 16 lines · Masahiro Yamada
Quoted 6 lines · Greg Rose

Since this commit:
'commit 9b9a3f20cbe0 ("kbuild: split final module linking out into Makefile.modfinal")'
at least one out-of-tree external kernel module build fails during the modfinal make phase because Makefile.modfinal does not include the ccflags-y variable from the exernal module's Kbuild.

ccflags-y is passed only for compiling C files in that directory.

It is not used for compiling *.mod.c
This is true for both in-kernel and external modules.

So, ccflags-y is not a good choice
for passing such flags that should be globally effective.

Quoted 7 lines
Quoted 7 lines

Maybe, KCFLAGS should work.

module:

        $(MAKE) KCFLAGS=...  M=$(PWD) -C /lib/modules/$(uname

-r)/build modules

Quoted 4 lines

Hi Masahiro,

I'm unable to get that to work. KCFLAGS does not seem to be used in Makefile.modfinal.

I quickly tested it, and confirmed
KCFLAGS works for external modules, too.

Makefile.modfinal includes scripts/Makefile.lib

So, c_flags contains $(KCFLAGS)

c_flags -> KBUILD_CFLAGS -> KCFLAGS

Quoted 7 lines

[snip]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
scripts/Makefile.modfinal +0 -0
@@ -21,6 +21,10 @@ __modfinal: $(modules)
  modname = $(notdir $(@:.mod.o=))
  part-of-module = y
 
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

scripts/Makefile.modfinal __modfinal: $(modules) · line 27

Quoted 4 lines
scripts/Makefile.modfinal +4 -0
+# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
+include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
+             $(KBUILD_EXTMOD)/Kbuild)
+

I continue to wonder why this it is so bad to include the external module's Kbuild.

Because it is not correct behavior.

Quoted 6 lines

It used to be included in Makefile.modpost and did no harm, and in fact was what
made our external build work at all in the past. Without the ability to define our
local kernel module build environment during the modfinal make I see no way forward.

As I said, ccflags-y is not intended to be
passed to *.mod.c
Upstream modules never rely on it.

External module should not rely on it either.

Quoted 4 lines

That said, I'm no expert on the Linux kernel Makefile interdependencies. If you
have some other idea we could try I'm game.

Signature · 2 lines
Best Regards
Masahiro Yamada
#5 lore raw
Quoted 36 lines · Masahiro Yamada
Quoted 22 lines · Gregory Rose
Quoted 20 lines · Gregory Rose
Quoted 19 lines · Masahiro Yamada
Quoted 6 lines · Greg Rose

Since this commit:
'commit 9b9a3f20cbe0 ("kbuild: split final module linking out into Makefile.modfinal")'
at least one out-of-tree external kernel module build fails during the modfinal make phase because Makefile.modfinal does not include the ccflags-y variable from the exernal module's Kbuild.

ccflags-y is passed only for compiling C files in that directory.

It is not used for compiling *.mod.c
This is true for both in-kernel and external modules.

So, ccflags-y is not a good choice
for passing such flags that should be globally effective.

Maybe, KCFLAGS should work.

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

module:

         $(MAKE) KCFLAGS=...  M=$(PWD) -C /lib/modules/$(uname

-r)/build modules

Hi Masahiro,

I'm unable to get that to work. KCFLAGS does not seem to be used in Makefile.modfinal.

I quickly tested it, and confirmed
KCFLAGS works for external modules, too.

Quoted 7 lines

Makefile.modfinal includes scripts/Makefile.lib

So, c_flags contains $(KCFLAGS)

c_flags -> KBUILD_CFLAGS -> KCFLAGS

Hi Masahiro,

I must have missed  something then - again, my unfamiliarity with the Linux Makefiles is probably tripping me up.  I'll dig around and see if I can get that working.

Thanks for your help,

- Greg

#6 lore raw
In reply to Masahiro Yamada
Quoted 36 lines · Masahiro Yamada
Quoted 22 lines · Gregory Rose
Quoted 20 lines · Gregory Rose
Quoted 19 lines · Masahiro Yamada
Quoted 6 lines · Greg Rose

Since this commit:
'commit 9b9a3f20cbe0 ("kbuild: split final module linking out into Makefile.modfinal")'
at least one out-of-tree external kernel module build fails during the modfinal make phase because Makefile.modfinal does not include the ccflags-y variable from the exernal module's Kbuild.

ccflags-y is passed only for compiling C files in that directory.

It is not used for compiling *.mod.c
This is true for both in-kernel and external modules.

So, ccflags-y is not a good choice
for passing such flags that should be globally effective.

Maybe, KCFLAGS should work.

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

module:

         $(MAKE) KCFLAGS=...  M=$(PWD) -C /lib/modules/$(uname

-r)/build modules

Hi Masahiro,

I'm unable to get that to work. KCFLAGS does not seem to be used in Makefile.modfinal.

I quickly tested it, and confirmed
KCFLAGS works for external modules, too.

Quoted 8 lines

Makefile.modfinal includes scripts/Makefile.lib

So, c_flags contains $(KCFLAGS)

c_flags -> KBUILD_CFLAGS -> KCFLAGS

Hi Masahiro,

I found a way to make this work on the openvswitch out of tree kernel module.  KCFLAGS doesn't work because it is added at the end of the gcc command line and we need to add a '-include <file>' directive so that the include file comes *before* all other include files.  I fix this by inserting the '-include <file>' command line option to the beginning of our own Kbuild NOSTDINC variable.

Thanks for your help in debugging this.

- Greg