Link an out-of-tree module into vmlinux
Alexei Colin
alexei at alexeicolin.com
Fri Sep 28 15:10:56 EDT 2012
Thank you for your reply. I am pursuing a slightly unusual goal:
On 09/28/2012 02:01 PM, Dave Hylands wrote:
> On Fri, Sep 28, 2012 at 9:01 AM, Alexei Colin <alexei at alexeicolin.com>
wrote:
>> Does the build system support building built-in components of vmlinux
>> out-of-tree?
>>
>> That is, I know that these two are possible:
>> (1) build out-of-tree code as a loadable kernel module (.ko) (use the
>> M=/path/to/out-of-tree/dir)
>> (2) build an in-tree module as a statically built-in component of
>> vmlinux instead of as a LKM (use the CONFIG_<module>=y, or otherwise add
>> the object files to obj-y instead of obj-m)
>>
>> The question is can you build an an _out-of-tree_ module as a statically
>> built-in component of vmlinux?
>
> You can build the entire kernel out-of-tree, and by that I mean have
> the object files go into a different tree than the source files.
Yes, the "O=" usage is clear, and I do use it.
> It depends on what you mean by "out-of-tree"
Sorry, by out-of-tree, I meant to refer to source code. For example, in
(1) above, the module's *code* can be out-of-tree: it can live outside
of the kernel source directory ($KDIR). The modules object files would
go into same place as its source.
> You can't build the static portions separate from the rest of the
> kernel, i.e. all of the objects are in the same tree, either the
> source tree, or some other tree.
In the case of out-of-tree modules, though, the objects do not have to
go to the same tree where the rest of the objects go. They end up in the
location specified by 'M='. That's were my inspiration comes from. In
fact 'M=' and 'obj-y' bring me half way there: I get a built-in.o in the
'M=' location. All I need the next step to be: link 'vmlinux' as usual,
except include the built-in.o from the 'M='.
To clarify: can I statically link some code into the kernel, but keep
this code (and its object files) in a directory that's not a descendant
of KDIR?
I can already accomplish this by editting root makefile and adding value
of an MBUILTIN variable to vmlinux-dirs list, e.g. via core-y, then, do
'make M=my-out-of-tree-dir && make MBUILTIN=my-out-of-tree-dir vmlinux'.
But I hoped there's some already supported MBUILTIN-like var that does
this in one step and without hacking the root makefile.
I realize that this is strange and has implications on prerequisite
checks -- introduces a strange dependency of vmlinux on something
outside of KDIR, which doesn't happen for modules, of course, because
vmlinux doesn't depend on them. But, this seems solvable by persisting
what went into the vmlinux link and invalidating if that list changes.
Thanks again.
-alexei
More information about the Kernelnewbies
mailing list