How to export a symbol from an external module?
Add this line at the very top of your Makefile for your hello module:
KBUILD_EXTRA_SYMBOLS := /home/your-user/path/to/printt/Module.symvers
(be sure to put in the correct path to your printt module).
Now rebuild your hello module and it will be loaded just fine.
For details see Documentation/kbuild/modules.txt, "6.3 Symbols From Another External Module".
How to call exported kernel module functions from another module?
From my research, it seems that those are the only three ways to handle this situation, and I've gotten each of them to work, so I think I'll just pick my favorite out of those.
How to export symbol from Linux kernel module in this case?
You may provide the callback function from module A. In that case you don't need to export each function you need to the kernel namespace. I presume you just could supply some structure to the B. Something like:
internal header:
struct possible_ops {
int (*xmit)(...);
};
A:
struct private {
struct possible_ops *ops;
};
...
ops = kzalloc(sizeof(*ops));
ops->xmit = xmit;
B:
whatever(struct possible_ops *ops) {
if (ops && ops->xmit) {
ret = ops->xmit();
...
}
}
Warning building a kernel module that uses exported symbols
This issue (and how to compile correctly in this case) is explained in http://www.kernel.org/doc/Documentation/kbuild/modules.txt
Sometimes, an external module uses exported symbols from another
external module. kbuild needs to have full knowledge of all symbols
to avoid spitting out warnings about undefined symbols. Three
solutions exist for this situation.NOTE: The method with a top-level kbuild file is recommended but may
be impractical in certain situations.Use a top-level kbuild file If you have two modules, foo.ko and
bar.ko, where foo.ko needs symbols from bar.ko, you can use a
common top-level kbuild file so both modules are compiled in the
same build. Consider the following directory layout:./foo/ <= contains foo.ko ./bar/ <= contains bar.ko
The top-level kbuild file would then look like:
#./Kbuild (or ./Makefile): obj-y := foo/ bar/
And executing
$ make -C $KDIR M=$PWD
will then do the expected and compile both modules with full
knowledge of symbols from either module.
Use an extra Module.symvers file When an external module is built,
a Module.symvers file is generated containing all exported symbols
which are not defined in the kernel. To get access to symbols from
bar.ko, copy the Module.symvers file from the compilation of bar.ko
to the directory where foo.ko is built. During the module build,
kbuild will read the Module.symvers file in the directory of the
external module, and when the build is finished, a new
Module.symvers file is created containing the sum of all symbols
defined and not part of the kernel.Use "make" variable KBUILD_EXTRA_SYMBOLS If it is impractical to
copy Module.symvers from another module, you can assign a space
separated list of files to KBUILD_EXTRA_SYMBOLS in your build file.
These files will be loaded by modpost during the initialization of
its symbol tables.
Exported variable cannot be named error with symbol
This is in fact already explained by the issue you pointed:
Declarations within a module are represented by two symbols, a local symbol and an export symbol.
p
in b.ts points to the local symbol of sy.
Where the ts compiler has a bug, is when b now looks up the local symbol of sy
in b.ts:
It traverses the exports of b.ts via aliases to find the symbol, but ends up with the declaration which is not equal to the local symbol.
This turn makes the compiler think symbol isn't visible, when, in fact, it is (because of the localSymbol/exportSymbol relationship).
Related Topics
Cdc_Acm: Failed to Set Dtr/Rts - Can Not Communicate with Usb Cdc Device
Recording from Alsa - Understanding Memory Mapping
How to Configure Gitlab as a Subdomain in Nginix.Conf
Can a Program Read Its Own Elf Section
.Htaccess Redirect Index.PHP to /
Check Library Version Netcdf Linux
How to Authenticate Username/Password Using Pam W/O Root Privileges
Reliably Kill Sleep Process After Usr1 Signal
Automate Scp with Multiple Files with Expect Script
How to View Dask Dashboard When Running on a Virtual Machine
Linux Umask for Sudo and Apache
Simplest Way to Build Dotnet Sdk Project Requiring Net461 on Macos
What Does "Private_Dirty" Memory Mean in Smaps
Jetty Bash Script Works Only with Root User
Change Conda Default Pkgs_Dirs and Envs Dirs