Hi Sasha,

On 3/7/26 18:20, Sasha Levin wrote:
Add CONFIG_KALLSYMS_LINEINFO, which embeds a compact address-to-line
lookup table in the kernel image so stack traces directly print source
file and line number information:

   root@localhost:~# echo c > /proc/sysrq-trigger
   [   11.201987] sysrq: Trigger a crash
   [   11.202831] Kernel panic - not syncing: sysrq triggered crash
   [   11.206218] Call Trace:
   [   11.206501]  <TASK>
   [   11.206749]  dump_stack_lvl+0x5d/0x80 (lib/dump_stack.c:94)
   [   11.207403]  vpanic+0x36e/0x620 (kernel/panic.c:650)
   [   11.208565]  ? __lock_acquire+0x465/0x2240 (kernel/locking/lockdep.c:4674)
[...]

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Sasha Levin <[email protected]>

Shows relative paths and works OK on 32- and 64-bit parisc kernel.
You may add
Tested-by: Helge Deller <[email protected]>

A few notes/suggestions below....


---
  Documentation/admin-guide/index.rst           |   1 +
  .../admin-guide/kallsyms-lineinfo.rst         |  72 +++
  MAINTAINERS                                   |   6 +
  include/linux/kallsyms.h                      |  32 +-
  init/Kconfig                                  |  20 +
  kernel/kallsyms.c                             |  61 +++
  kernel/kallsyms_internal.h                    |  11 +
  scripts/.gitignore                            |   1 +
  scripts/Makefile                              |   3 +
  scripts/gen_lineinfo.c                        | 510 ++++++++++++++++++
  scripts/kallsyms.c                            |  16 +
  scripts/link-vmlinux.sh                       |  70 ++-
  12 files changed, 799 insertions(+), 4 deletions(-)
  create mode 100644 Documentation/admin-guide/kallsyms-lineinfo.rst
  create mode 100644 scripts/gen_lineinfo.c

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index aec2f06858afd..c94d8f332c5df 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -467,6 +467,54 @@ static int append_buildid(char *buffer,   const char 
*modname,
#endif /* CONFIG_STACKTRACE_BUILD_ID */ +#ifdef CONFIG_KALLSYMS_LINEINFO
+bool kallsyms_lookup_lineinfo(unsigned long addr, unsigned long sym_start,
+                             const char **file, unsigned int *line)
+{
+       unsigned long long raw_offset;
+       unsigned int offset, low, high, mid, file_id;
+
+       if (!lineinfo_num_entries)
+               return false;

The "#ifdef CONFIG_KALLSYMS_LINEINFO" above prevents that this function
is compiled when the option is disabled.

Instead, you *could* move the "CONFIG_KALLSYMS_LINEINFO" option into
the function with "IS_ENABLED()", like this...:
+       if (!IS_ENABLED(CONFIG_KALLSYMS_LINEINFO) || !lineinfo_num_entries)
+               return false;

That way your code will always be compiled, and the code will be optimized
away by the compiler if the option is disabled. The huge benefit is, that
the compiler will do syntax-checking at every build, so you will see coding
bugs early.

You could use the same semantic at other places in your patches, and of
course you then need to remove the #ifdef ...

diff --git a/kernel/kallsyms_internal.h b/kernel/kallsyms_internal.h
index 81a867dbe57d4..982557aeff28d 100644
--- a/kernel/kallsyms_internal.h
+++ b/kernel/kallsyms_internal.h
@@ -15,4 +15,15 @@ extern const u16 kallsyms_token_index[];
  extern const unsigned int kallsyms_markers[];
  extern const u8 kallsyms_seqs_of_names[];
+#ifdef CONFIG_KALLSYMS_LINEINFO
+extern const u32 lineinfo_num_entries;
+extern const u32 lineinfo_addrs[];
^^ for exampe here...

Helge

Reply via email to