Re: [PATCH v3 00/11] objtool/powerpc: Fix up feature section alternatives at build time

From: Shivang Upadhyay

Date: Thu Dec 03 2026 - 02:07:40 EST


On Wed, 2026-12-02 at 13:25 -0800, Josh Poimboeuf wrote:
> On Wed, Dec 02, 2026 at 01:10:47PM +0530, Shivang Upadhyay wrote:
> > The replacement code of a powerpc feature section
> > (BEGIN_FTR_SECTION /
> > FTR_SECTION_ELSE / ALT_FTR_SECTION_END macros) is emitted into a
> > __ftr_alt_*
> > section.  At boot, apply_feature_fixups() copies the replacement
> > code over it.
> > Since the copy lands at a different address than the one it was
> > linked for, the
> > PC-relative branches in it have to be translated, which is
> > currently done at
> > runtime by patch_feature_section().
> >
> > This has two drawbacks:
> >
> >  - __ftr_alt_* sections are allocatable but not executable, so the
> >    linker cannot insert branch stubs for them.  They therefore have
> > to
> >    be placed close to .text, and every branch in them must reach
> > its
> >    target directly.  This can break the build as the kernel grows.
>
> Is this a real issue or is it theoretical?
Hi Josh,

I haven't hit this myself, but Nick and Sathvika ran into it while
working on alt features. I believe the failing case was conditional
branches (bc, R_PPC_REL14), which can only reach ±32KB. On ppc64le the
sections are aligned to the page size, commonly 64KB, so a branch from
an alt section can easily end up out of range of its target, specially
when alt section adds length to top of head section.

>
> >  - The branches are translated on every boot, although everything
> >    needed to do it is known at link time.
>
> x86 also does something similar for its alternatives, I'm not sure
> that's much of a drawback though.
>
> Presumably objtool-on-vmlinux adds some slowness to the build.
>
Not much, There are not many instructions to patch.

time ./tools/objtool/objtool --link --alt-fixup ./vmlinux.unstripped

real 0m0.901s
user 0m0.582s
sys 0m0.309s

> > This series moves the translation to build time.  After vmlinux is
> > linked, objtool is run on it with the new --alt-fixup option.  It
> > parses
> > the __ftr_fixup, __mmu_ftr_fixup and __fw_ftr_fixup tables, and for
> > each
> > PC-relative relocation in the replacement code, asks the arch to
> > rewrite
> > the instruction so that it is valid at the place it will be copied
> > to.
> > With that, the __ftr_alt_* sections are marked executable and moved
> > out
> > of .text into their own output section, so the linker can insert
> > stubs
> > where needed.
> >
> > Objtool does not process modules or the VDSO, so the runtime
> > translation
> > is kept for those and only skipped for the core kernel.
>
> So now there are two translation methods of instead of one?
>
> Is there any reason why objtool coudn't be run on linked vDSO and
> modules as well?
>
It should not be hard to achieve. Currently I could not find any
example for alt feature implemented for VDSO or modules, to test.

~Shivang.
> > Previously, Nicholas Piggin proposed a build-time solution using a
> > custom
> > powerpc tool [1].  The approach here builds on that idea, but uses
> > objtool's existing ELF parsing and instruction patching
> > infrastructure
> > instead of a separate tool.
>
> I notice that last approach was almost 10 years ago, just wondering
> if
> this is a real problem that people are hitting.