From: Jessica Yu <jeyu@kernel.org>
To: Lucas De Marchi <lucas.de.marchi@gmail.com>
Cc: Matthias Maennich <maennich@google.com>,
linux-modules@vger.kernel.org, Jessica Yu <jeyu@kernel.org>
Subject: [PATCH] depmod: account for new namespace field in Module.symvers (for kernel versions >= 5.4)
Date: Fri, 21 Feb 2020 17:52:43 +0100 [thread overview]
Message-ID: <20200221165243.25100-1-jeyu@kernel.org> (raw)
depmod -e -E is broken for kernel versions >= 5.4, because a new
namespace field was added to Module.symvers. Each line is tab delimited
with 5 fields in total. E.g.,
0xb352177e\tfind_first_bit\tnamespace\tvmlinux\tEXPORT_SYMBOL
When a symbol doesn't have a namespace, then the namespace field is empty:
0xb352177e\tfind_first_bit\t\tvmlinux\tEXPORT_SYMBOL
Fix up depmod_load_symvers() so it finds the crc, symbol, and module
("where") fields correctly. Since there can be empty fields, strsep() is
used instead of strtok(), since strtok() cannot handle empty fields
(i.e., two delimiters in succession).
Signed-off-by: Jessica Yu <jeyu@kernel.org>
---
Hi,
I was not sure what the best way of determining the symvers format was. I
guess counting delimiters isn't the prettiest way, but if anyone has a
better idea, let me know. Thanks!
tools/depmod.c | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/tools/depmod.c b/tools/depmod.c
index fbbce10..c5b9612 100644
--- a/tools/depmod.c
+++ b/tools/depmod.c
@@ -2577,7 +2577,9 @@ static int depmod_load_symvers(struct depmod *depmod, const char *filename)
{
char line[10240];
FILE *fp;
- unsigned int linenum = 0;
+ unsigned int linenum = 0, cnt = 0;
+ bool uses_namespaces = false;
+ char *ptr;
fp = fopen(filename, "r");
if (fp == NULL) {
@@ -2587,7 +2589,26 @@ static int depmod_load_symvers(struct depmod *depmod, const char *filename)
}
DBG("load symvers: %s\n", filename);
- /* eg. "0xb352177e\tfind_first_bit\tvmlinux\tEXPORT_SYMBOL" */
+ /*
+ * First, check for >=5.4 Module.symvers format:
+ * "0xb352177e\tfind_first_bit\tnamespace\tvmlinux\tEXPORT_SYMBOL"
+ * If there are 5 fields (4 tabs), assume we're using the new format.
+ */
+ fgets(line, sizeof(line), fp);
+ ptr = line;
+ while ((ptr = strchr(ptr, '\t')) != NULL) {
+ cnt++;
+ ptr++;
+ }
+ if (cnt > 3)
+ uses_namespaces = true;
+ rewind(fp);
+
+ /*
+ * eg. "0xb352177e\tfind_first_bit\tvmlinux\tEXPORT_SYMBOL"
+ * Or if kernel version >=5.4:
+ * "0xb352177e\tfind_first_bit\tnamespace\tvmlinux\tEXPORT_SYMBOL"
+ */
while (fgets(line, sizeof(line), fp) != NULL) {
const char *ver, *sym, *where;
char *verend;
@@ -2595,9 +2616,13 @@ static int depmod_load_symvers(struct depmod *depmod, const char *filename)
linenum++;
- ver = strtok(line, " \t");
- sym = strtok(NULL, " \t");
- where = strtok(NULL, " \t");
+ ptr = (char *)line;
+ ver = strsep(&ptr, "\t");
+ sym = strsep(&ptr, "\t");
+ if (uses_namespaces) /* skip namespace field */
+ strsep(&ptr, "\t");
+ where = strsep(&ptr, "\t");
+
if (!ver || !sym || !where)
continue;
--
2.16.4
next reply other threads:[~2020-02-21 16:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-21 16:52 Jessica Yu [this message]
2020-03-03 14:31 ` [PATCH] depmod: account for new namespace field in Module.symvers (for kernel versions >= 5.4) Jessica Yu
2020-03-04 6:28 ` Lucas De Marchi
2020-03-04 9:18 ` Jessica Yu
2020-03-04 11:34 ` Matthias Maennich
2020-03-06 0:10 ` Lucas De Marchi
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=20200221165243.25100-1-jeyu@kernel.org \
--to=jeyu@kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=lucas.de.marchi@gmail.com \
--cc=maennich@google.com \
/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;
as well as URLs for NNTP newsgroup(s).