From: Philipp Hahn <phahn-oss@avm.de>
To: Masahiro Yamada <masahiroy@kernel.org>,
Nicolas Schier <nicolas.schier@linux.dev>
Cc: linux-kernel@vger.kernel.org
Subject: genksyms vs. opaque struct *
Date: Thu, 13 Nov 2025 21:40:11 +0100 [thread overview]
Message-ID: <aRZCKwLVdpE_XjtA@mail-auth.avm.de> (raw)
Hello,
while building a Linux kernel module I stumbled over an issue with 'genksyms': Basically my modules uses an "opaque struct" and only gets a pointer to such an object. The header file declaring that struct did *not* #include all needed header files recursively, so some types remained unresolved.
For compiling the module this was not an issue as the compiler only needs to allocate space for an pointer to that nested struct and does not need more details.
Another module exists which uses that symbol and recorded the calculated CRC.
Then I changed my module and added some more #includes, which resulted into `genksyms` getting *more* details on the next run while the implementation actually did not change.
I only found out root cause of my problem after digging into the genksyms-machinery myself, where I found the option `--warnings`, which actually prints out such a warning in my case:
> /home/pmhahn/prog/my-modver/my-modver.c:8: expand undefined struct bar
In my example below it makes a difference if `-DDETAIL` is given or not:
> cpp -E -D__GENKSYMS__ …my-modver.c -DDETAIL | scripts/genksyms/genksyms -r /dev/null -w
> #SYMVER my_function 0x0cdb4509
> cpp -E -D__GENKSYMS__ …my-modver.c | scripts/genksyms/genksyms -r /dev/null -w
> #SYMVER my_function 0x87675506
I wonder, why that option is not enabled by default or if there is another solution to prevent such breaking changed by including more/less #includes? Are there any good/recommended practices?
Below is my simplified example with my two source files. Attached is the full output from running `genksyms`.
$ cat my-modver.c ####################
#include <linux/module.h>
#include <linux/printk.h>
#include "my-modver.h"
void my_function(struct foo *arg) {
printk(KERN_INFO "Hello %d", arg->value);
}
EXPORT_SYMBOL(my_function);
MODULE_LICENSE("MIT");
$ cat my-modver.h ####################
struct bar;
#ifdef DETAIL
struct bar {
int nested;
};
#endif
struct foo {
int value;
struct bar *nested;
};
void my_function(struct foo *arg);
Thanks in advance for your answer.
Philipp Hahn
next reply other threads:[~2025-11-13 20:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 20:40 Philipp Hahn [this message]
2025-11-26 15:22 ` genksyms vs. opaque struct * Nicolas Schier
2026-01-19 13:48 ` Philipp Hahn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aRZCKwLVdpE_XjtA@mail-auth.avm.de \
--to=phahn-oss@avm.de \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=nicolas.schier@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox