All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dylan Hatch" <dylanbhatch@google.com>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>
Cc: "Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	"Weinan Liu" <wnliu@google.com>,
	"Jens Remus" <jremus@linux.ibm.com>,
	linux-kbuild@vger.kernel.org, linux-crypto@vger.kernel.org,
	"Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Ard Biesheuvel" <ardb@kernel.org>,
	"Indu Bhagat" <ibhagatgnu@gmail.com>,
	"Prasanna Kumar T S M" <ptsm@linux.microsoft.com>,
	live-patching@vger.kernel.org
Subject: Re: [RFC PATCH 06/12] scripts/gen_lr_unwind: add --dump option to inspect .lr_unwind tables
Date: Wed, 18 Nov 2026 04:36:12 +0000	[thread overview]
Message-ID: <sashiko-outbox-220109@kernel.org> (raw)
In-Reply-To: <20261117043504.1021063-7-dylanbhatch@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] scripts/gen_lr_unwind: missing SHN_XINDEX handling in
  dump_lr_unwind()
- [Low] scripts/gen_lr_unwind: broken dump_lr_unwind() on ET_EXEC/ET_DYN
  with relas
--

commit 28070d4daa3cf7bb2b0ad3b96252120bc29dcba2
Author: Dylan Hatch <dylanbhatch@google.com>

scripts/gen_lr_unwind: add --dump option to inspect .lr_unwind tables

This commit adds a --dump (-d) option to scripts/gen_lr_unwind to print
.lr_unwind FDEs and instruction ranges in human-readable form for both
relocatable and linked ELF files.

> diff --git a/scripts/gen_lr_unwind.c b/scripts/gen_lr_unwind.c
> index f65edd86ac78c..2058601ec6135 100644
> --- a/scripts/gen_lr_unwind.c
> +++ b/scripts/gen_lr_unwind.c

[ ... ]

> @@ -478,6 +487,225 @@ static int emit_lr_unwind_sections(const char *fname, struct lr_unwind_ctx *ctx,
> +static int dump_lr_unwind(struct lr_unwind_ctx *ctx, const Elf64_Shdr *shdrs,
> +			  unsigned int shnum, const char *shstrtab)
> +{
> +	const struct lr_fde *fdes;
> +	const Elf64_Rela *relas = NULL;
> +	const lr_range_t *ranges = NULL;
> +	size_t nr_fdes, nr_ranges = 0;
> +	const Elf64_Sym *elf_syms = NULL;
> +	size_t nr_elf_syms = 0;
> +	const char *strtab = NULL;
> +	struct dump_sym *dsyms = NULL;
> +	size_t nr_dsyms = 0;
> +	bool is_rel = (((const Elf64_Ehdr *)ctx->map)->e_type == ET_REL);
> +
> +	if (ctx->fde_sec) {
> +		fdes = ctx->map + ctx->fde_sec->sh_offset;
> +		nr_fdes = ctx->fde_sec->sh_size / sizeof(struct lr_fde);
> +		if (ctx->rela_fde_sec)
> +			relas = ctx->map + ctx->rela_fde_sec->sh_offset;
> +		if (ctx->ranges_sec) {
> +			ranges = ctx->map + ctx->ranges_sec->sh_offset;
> +			nr_ranges = ctx->ranges_sec->sh_size / sizeof(lr_range_t);
> +		}
> +	} else {

[ ... ]

> +	if (ctx->symtab_shndx) {
> +		const Elf64_Shdr *sym_sec = &shdrs[ctx->symtab_shndx];
> +
> +		elf_syms = ctx->map + sym_sec->sh_offset;
> +		nr_elf_syms = sym_sec->sh_size / sizeof(Elf64_Sym);
> +		strtab = ctx->map + shdrs[sym_sec->sh_link].sh_offset;
> +
> +		dsyms = malloc(nr_elf_syms * sizeof(*dsyms));
> +		if (!dsyms)
> +			return -1;
> +
> +		for (size_t i = 0; i < nr_elf_syms; i++) {
> +			const Elf64_Sym *s = &elf_syms[i];
> +			unsigned char type = ELF64_ST_TYPE(s->st_info);
> +			const char *name = strtab + s->st_name;
> +
> +			if (s->st_shndx == SHN_UNDEF ||
> +			    s->st_shndx >= SHN_LORESERVE)
> +				continue;

[Severity: Low]
Does skipping symbols with st_shndx >= SHN_LORESERVE here and when
formatting FDE relocations below drop all sections at or above index
0xff00?

main() and emit_lr_unwind_sections() handle objects with >= SHN_LORESERVE
sections, such as vmlinux.o built with per-function sections, where symbols
in those sections have st_shndx == SHN_XINDEX and store their 32-bit
section index in the SHT_SYMTAB_SHNDX section.  Without resolving
SHN_XINDEX in both places, dump_lr_unwind() omits the section name, offset,
and function name for any FDE targeting a section >= SHN_LORESERVE.

> +			if (type != STT_FUNC && type != STT_NOTYPE)
> +				continue;
> +			if (!name[0] || name[0] == '$' ||
> +			    !strncmp(name, ".L", 2))
> +				continue;
> +
> +			dsyms[nr_dsyms++] = (struct dump_sym){
> +				.addr = s->st_value,
> +				.shndx = is_rel ? s->st_shndx : 0,
> +				.is_func = (type == STT_FUNC),
> +				.name = name,
> +			};
> +		}

[ ... ]

> +		printf("FDE[%zu] ", i);
> +		if (relas && elf_syms) {
> +			u32 sym_idx = ELF64_R_SYM(relas[i].r_info);
> +
> +			if (sym_idx < nr_elf_syms) {
> +				const Elf64_Sym *sym = &elf_syms[sym_idx];
> +				unsigned int shndx = sym->st_shndx;
> +				u64 off = sym->st_value + relas[i].r_addend;
> +
> +				if (shndx < shnum && shndx < SHN_LORESERVE) {
> +					const char *sec_name =
> +						shstrtab + shdrs[shndx].sh_name;
> +					const struct dump_sym *ds =
> +						find_dump_sym(dsyms, nr_dsyms,
> +							      shndx, off);

[Severity: Low]
On an ET_EXEC or ET_DYN binary linked with --emit-relocs so that
.rela.lr_unwind_fde is still present, does taking the relas branch break
symbol resolution and address output?

When !is_rel, dsyms entries are populated with .shndx = 0, so calling
find_dump_sym() here with non-zero sym->st_shndx never matches any symbol.
In addition, sym->st_value is already a virtual address rather than a
section-relative offset, and if .lr_unwind_fde has been sorted in place,
relas[i] no longer matches fdes[i].  Should relas only be used when is_rel
is true, falling back to the PC-relative fde->start_offset branch for
ET_EXEC and ET_DYN?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117043504.1021063-1-dylanbhatch@google.com?part=6

  reply	other threads:[~2026-11-18  4:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  4:34 [RFC PATCH 00/12] arm64, unwind: add .lr_unwind unwinder for reliable stacktrace Dylan Hatch
2026-11-17  4:34 ` [RFC PATCH 01/12] arm64, unwind: build with .eh_frame and add gen_lr_unwind skeleton Dylan Hatch
2026-11-18  4:36   ` sashiko-bot
2026-11-17  4:34 ` [RFC PATCH 02/12] arm64: factor .eh_frame parser out of patch-scs.c into <asm/eh_frame.h> Dylan Hatch
2026-11-18  4:36   ` sashiko-bot
2026-11-17  4:34 ` [RFC PATCH 03/12] arm64: eh_frame: track CFA and x29/x30 register state in CFI parser Dylan Hatch
2026-11-17  4:34 ` [RFC PATCH 04/12] arm64, unwind: parse .eh_frame into .lr_unwind entries in gen_lr_unwind Dylan Hatch
2026-11-17  4:34 ` [RFC PATCH 05/12] scripts/gen_lr_unwind: emit .lr_unwind_fde and .lr_unwind_ranges Dylan Hatch
2026-11-17  4:34 ` [RFC PATCH 06/12] scripts/gen_lr_unwind: add --dump option to inspect .lr_unwind tables Dylan Hatch
2026-11-18  4:36   ` sashiko-bot [this message]
2026-11-17  4:34 ` [RFC PATCH 07/12] scripts/sorttable: sort .lr_unwind_fde by start_offset Dylan Hatch
2026-11-17  4:35 ` [RFC PATCH 08/12] arm64, unwind: add in-kernel .lr_unwind lookup and validation Dylan Hatch
2026-11-17  4:35 ` [RFC PATCH 09/12] arm64/module, unwind: add .lr_unwind support for modules Dylan Hatch
2026-11-17  4:35 ` [RFC PATCH 10/12] arm64: entry: add unwind info for call_on_irq_stack() Dylan Hatch
2026-11-17  4:35 ` [RFC PATCH 11/12] arm64, crypto/lib: annotate leaf functions with CFI info Dylan Hatch
2026-11-18  5:07   ` Eric Biggers
2026-11-17  4:35 ` [RFC PATCH 12/12] unwind: arm64: use .lr_unwind to unwind interrupt frames Dylan Hatch
2026-11-18  4:36   ` sashiko-bot

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=sashiko-outbox-220109@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=davem@davemloft.net \
    --cc=dylanbhatch@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=ibhagatgnu@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=jremus@linux.ibm.com \
    --cc=justinstitt@google.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nsc@kernel.org \
    --cc=ptsm@linux.microsoft.com \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=will@kernel.org \
    --cc=wnliu@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.