[RFC 1/4] objtool/klp: add --symvers option to klp diff

Joe Lawrence <[email protected]>
Newsgroups org.kernel.vger.live-patching
Message-ID <[email protected]>
Add a --symvers (-s) option that accepts a path to Module.symvers.  When
provided, it replaces the default "Module.symvers" filename used by the
auto-detection logic.

This decoupling helps to enable scenarios like out-of-tree module
patching and unit testing of klp-diff, where object files /
Module.symvers live outside the kernel tree.

The existing auto-detection behavior (try cwd, then top_level_dir()
fallback) is preserved regardless of whether --symvers is specified.

Assisted-by: Cursor:claude-4.6-opus
Signed-off-by: Joe Lawrence <[email protected]>
---
 tools/objtool/klp-diff.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index b9624bd9439b..bd8d64f2f3f6 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -34,6 +34,7 @@ struct export {
 	char *mod, *sym;
 };
 
+static const char *symvers_path = "Module.symvers";
 bool debug, debug_correlate, debug_clone;
 int indent;
 
@@ -47,6 +48,7 @@ static const struct option klp_diff_options[] = {
 	OPT_BOOLEAN('d', "debug", &debug, "enable all debug output"),
 	OPT_BOOLEAN(0, "debug-correlate", &debug_correlate, "enable correlation debug output"),
 	OPT_BOOLEAN(0, "debug-clone", &debug_clone, "enable cloning debug output"),
+	OPT_STRING('s', "symvers", &symvers_path, "path", "path to Module.symvers (default: Module.symvers)"),
 	OPT_END(),
 };
 
@@ -86,16 +88,15 @@ static char *escape_str(const char *orig)
 
 static int read_exports(void)
 {
-	const char *symvers = "Module.symvers";
 	char line[1024], *path = NULL;
 	unsigned int line_num = 1;
 	FILE *file;
 
-	file = fopen(symvers, "r");
+	file = fopen(symvers_path, "r");
 	if (!file) {
-		path = top_level_dir(symvers);
+		path = top_level_dir(symvers_path);
 		if (!path) {
-			ERROR("can't open '%s', \"objtool diff\" should be run from the kernel tree", symvers);
+			ERROR("can't open '%s', \"objtool diff\" should be run from the kernel tree", symvers_path);
 			return -1;
 		}
 
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.