How to use multiple source files in a single module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Hi!

I have a short utility program which has been written to be used both 
for normal user space apps , as well a kernel modules. Now, the code
is #def'ed to use the correct kernel equivalents(like kmalloc()) for module
compilations, and libc equivalents(like malloc()) and so it is safe enough.

My problem is that I need to use the utility functions of this code in just
one module, without polluting the kernel symbol table with the
function identifiers. So I made the storage class of the functions
depend on the context it is being compiled in. In __KERNEL__ mode, it
is #defined to "static" and in normal applications it is defined as
"extern". This is because in all cases this utility file is separetely
compiled as an object file.

 e.g.
     kgcc -Wall -DMODULE -D__KERNEL__ -c util.c
     kgcc -Wall -DMODULE -D__KERNEL__ -c _mymodule.c
     ld -m elf_i386 -o mymodule.o _mymodule.o util.o 

    for the module compilations

 and
    touch util.c
     kgcc  -Wall -c util.c
     kgcc  -Wall -c _myapp.c
     ld -m elf_i386 -o myapp.o _myapp.o util.o 

    for the app compilations


Is this at all sane? If I define the storage class of the util.c
functions as static, they _should_not_ be exported to the mymodule.c
module. But it compiles and links. :)

If I leave them as static always, the userspace app compilations would
warn me saying that while compiling the util.c program the functions
were declared static but never used. A warning that i can ignore,
... but then I hate _any_ warnings during compilations. ;)

How do you make a kernel module with multiple source files anyway,
without exporting all the symbols to the kernel symbol table? Is this
the reason why _most_ of the kernel modules are single source files?

- Sandip



-- 
-------------------------------------
Sandip Bhattacharya 
sandipb @ bigfoot.com
http://www.sandipb.net
-------------------------------------


-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux