Discussion:
kernel module linking (general, ipfw table, netgraph)
freeuser
2018-09-06 12:02:29 UTC
Permalink
Hello,

I'm working on a netgraph kernel module that modifies ipfw table contents.
But i can not load the module, because
  kldload: an error occurred while loading the module. Please check
dmesg(8)
  for more details.

dmesg informs:
..
link_elf_obj: symbol add_table_entry undefined
linker_load_file: Unsupported file type

add_table_entry is a function that modifies ipfw table, the thing is that i
have included the relevant header files, but i don't understand how
should i
deal with linking. I assumed that this function will be available for
module
since "sysctl -b kern.function_list | tr '\0' '\n' | grep add_table" shows
it.

I am building my module using /usr/src/sys/modules/netgraph/sample and
/usr/src/sys/netgraph/ng_sample.* as templates. On the other hand,
ng_socket
uses kern_kldload, "sysctl -b kern.function_list | tr '\0' '\n' | grep
kern_kldload"
shows it and it works without any problems.

Why is that? What have i not noticed that must be done?

Thank you,
freeuser
Eugene Grosbein
2018-09-06 11:57:49 UTC
Permalink
Post by freeuser
Hello,
I'm working on a netgraph kernel module that modifies ipfw table contents.
But i can not load the module, because
kldload: an error occurred while loading the module. Please check
dmesg(8)
for more details.
..
link_elf_obj: symbol add_table_entry undefined
linker_load_file: Unsupported file type
add_table_entry is a function that modifies ipfw table, the thing is that i
have included the relevant header files, but i don't understand how
should i
deal with linking. I assumed that this function will be available for
module
since "sysctl -b kern.function_list | tr '\0' '\n' | grep add_table" shows
it.
I am building my module using /usr/src/sys/modules/netgraph/sample and
/usr/src/sys/netgraph/ng_sample.* as templates. On the other hand,
ng_socket
uses kern_kldload, "sysctl -b kern.function_list | tr '\0' '\n' | grep
kern_kldload"
shows it and it works without any problems.
Why is that? What have i not noticed that must be done?
Perhaps, this is KBI mismatch due to VIMAGE kernel option
that changes symbols like add_table_entry to V_add_table_entry
and your kernel module should be built WITH_VIMAGE defined too
to be loadable to such a kernel.
Andrey V. Elsukov
2018-09-06 13:23:11 UTC
Permalink
Post by Eugene Grosbein
Post by freeuser
I am building my module using /usr/src/sys/modules/netgraph/sample and
/usr/src/sys/netgraph/ng_sample.* as templates. On the other hand,
ng_socket
uses kern_kldload, "sysctl -b kern.function_list | tr '\0' '\n' | grep
kern_kldload"
shows it and it works without any problems.
Why is that? What have i not noticed that must be done?
Perhaps, this is KBI mismatch due to VIMAGE kernel option
that changes symbols like add_table_entry to V_add_table_entry
and your kernel module should be built WITH_VIMAGE defined too
to be loadable to such a kernel.
I think VIMAGE only affects variables, but not functions.
The problem is probably due to missing dependency. Look at ng_ipfw
implementation. It depends from ipfw kernel module. Try add such
dependency to your module.
--
WBR, Andrey V. Elsukov
freeuser
2018-09-06 17:02:40 UTC
Permalink
Post by Andrey V. Elsukov
Post by Eugene Grosbein
Post by freeuser
I am building my module using /usr/src/sys/modules/netgraph/sample and
/usr/src/sys/netgraph/ng_sample.* as templates. On the other hand,
ng_socket
uses kern_kldload, "sysctl -b kern.function_list | tr '\0' '\n' | grep
kern_kldload"
shows it and it works without any problems.
Why is that? What have i not noticed that must be done?
Perhaps, this is KBI mismatch due to VIMAGE kernel option
that changes symbols like add_table_entry to V_add_table_entry
and your kernel module should be built WITH_VIMAGE defined too
to be loadable to such a kernel.
I think VIMAGE only affects variables, but not functions.
The problem is probably due to missing dependency. Look at ng_ipfw
implementation. It depends from ipfw kernel module. Try add such
dependency to your module.
Yes, by adding "MODULE_DEPEND.." fixed linking issues. Thank you very much!
Loading...