Skip to contentSkip to conversation

objtool: Fixup alternate feature relative addresses

RFC PATCH Superseded Sathvika Vasireddy 4 participants 9 messages Sep 29, 2025 – Oct 13, 2025

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover objtool: Fixup alternate feature relative addresses

This patch series implements build-time fixup of alternate feature relative addresses for powerpc.

Previously, Nicholas Piggin proposed a build-time solution using a custom PowerPC tool [1], which provided the foundation for this approach. The current implementation leverages objtool's existing ELF parsing infrastructure to do the same.

This patchset applies atop powerpc/merge branch.

Links and History:
[1] Original PowerPC tool approach:

    http://patchwork.ozlabs.org/project/linuxppc-dev/patch/[email protected]/
[2] Initial RFC v1:
    https://lore.kernel.org/linuxppc-dev/[email protected]/T/#t
[3] PowerPC instruction decoder borrowed from:
    https://lore.kernel.org/linuxppc-dev/bfa8364da047d8610a09458a1cd924a0566aedbb.1736955567.git.christophe.leroy@csgroup.eu/#Z31tools:objtool:arch:powerpc:decode.c

Testing:
Build and Boot tested on ppc64le, ppc64be, and ppc32be configs.

Changes in V2:
- Added implementation support for ppc64 LE, BE, ppc32 BE.

Sathvika Vasireddy (3):
objtool/powerpc: Enhance objtool to fixup alternate feature relative
addresses
kbuild: Add objtool integration for PowerPC feature fixups
powerpc: Enable build-time feature fixup processing by default

 Makefile                                  |   7 +
 arch/Kconfig                              |   3 +
 arch/powerpc/Kconfig                      |   3 +
 arch/powerpc/Makefile                     |   5 +
 arch/powerpc/include/asm/feature-fixups.h |   2 +-
 arch/powerpc/kernel/vmlinux.lds.S         |   8 +-
 arch/powerpc/lib/feature-fixups.c         |  12 -
 scripts/Makefile.lib                      |   5 +-
 scripts/Makefile.vmlinux                  |  13 +-
 tools/objtool/arch/powerpc/decode.c       |  15 +-
 tools/objtool/arch/powerpc/special.c      | 436 ++++++++++++++++++++++
 tools/objtool/builtin-check.c             |   2 +
 tools/objtool/check.c                     |  48 ++-
 tools/objtool/elf.c                       |   4 +
 tools/objtool/include/objtool/builtin.h   |   1 +
 tools/objtool/include/objtool/special.h   |  56 +++
 16 files changed, 593 insertions(+), 27 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH v2 1/3 objtool/powerpc: Enhance objtool to fixup alternate feature relative addresses

Implement build-time fixup of alternate feature relative addresses for the out-of-line (else) patch code. Initial posting to achieve the same using another tool can be found at [1]. Idea is to implement this using objtool instead of introducing another tool since it already has elf parsing and processing covered.

Introduce --ftr-fixup as an option to objtool to do feature fixup at build-time.

Couple of issues and warnings encountered while implementing feature fixup using objtool are as follows:

1. libelf is creating corrupted vmlinux file after writing necessary changes to the file. Due to this, kexec is not able to load new kernel.

It gives the following error:
ELF Note corrupted !
Cannot determine the file type of vmlinux

To fix this issue, after opening vmlinux file, make a call to elf_flagelf (e, ELF_C_SET, ELF_F_LAYOUT). This instructs libelf not to touch the segment and section layout. It informs the library that the application will take responsibility for the layout of the file and that the library should not insert any padding between sections.

2. Fix can't find starting instruction warnings when run on vmlinux

Objtool throws a lot of can't find starting instruction warnings when run on vmlinux with --ftr-fixup option.

These warnings are seen because find_insn() function looks for instructions at offsets that are relative to the start of the section. In case of individual object files (.o), there are no can't find starting instruction warnings seen because the actual offset associated with an instruction is itself a relative offset since the sections start at offset 0x0.

However, in case of vmlinux, find_insn() function fails to find instructions at the actual offset associated with an instruction since the sections in vmlinux do not start at offset 0x0. Due to this, find_insn() will look for absolute offset and not the relative offset. This is resulting in a lot of can't find starting instruction warnings when objtool is run on vmlinux.

To fix this, pass offset that is relative to the start of the section to find_insn().

find_insn() is also looking for symbols of size 0. But, objtool does not store empty STT_NOTYPE symbols in the rbtree. Due to this, for empty symbols, objtool is throwing can't find starting instruction warnings. Fix this by ignoring symbols that are of size 0 since objtool does not add them to the rbtree.

3. Objtool is throwing unannotated intra-function call warnings when run on vmlinux with --ftr-fixup option.

One such example:

vmlinux: warning: objtool: .text+0x3d94:
unannotated intra-function call

.text + 0x3d94 = c000000000008000 + 3d94 = c0000000000081d4

c0000000000081d4: 45 24 02 48 bl c00000000002a618 <system_reset_exception+0x8>

c00000000002a610 <system_reset_exception>:
c00000000002a610: 0e 01 4c 3c addis r2,r12,270

                        c00000000002a610: R_PPC64_REL16_HA    .TOC.
c00000000002a614:       f0 6c 42 38     addi    r2,r2,27888
                        c00000000002a614: R_PPC64_REL16_LO    .TOC.+0x4

c00000000002a618: a6 02 08 7c mflr r0

This is happening because we should be looking for destination symbols that are at absolute offsets instead of relative offsets. After fixing dest_off to point to absolute offset, there are still a lot of these warnings shown.

In the above example, objtool is computing the destination offset to be c00000000002a618, which points to a completely different instruction. find_call_destination() is looking for this offset and failing. Instead, we should be looking for destination offset c00000000002a610 which points to system_reset_exception function.

Even after fixing the way destination offset is computed, and after looking for dest_off - 0x8 in cases where the original offset is not found, there are still a lot of unannotated intra-function call warnings generated. This is due to symbols that are not properly annotated.

So, for now, as a hack to curb these warnings, do not emit unannotated intra-function call warnings when objtool is run with --ftr-fixup option.

[1]
https://lore.kernel.org/linuxppc-dev/[email protected]/

---
 tools/objtool/arch/powerpc/decode.c     |  15 +-
 tools/objtool/arch/powerpc/special.c    | 436 ++++++++++++++++++++++++
 tools/objtool/builtin-check.c           |   2 +
 tools/objtool/check.c                   |  48 ++-
 tools/objtool/elf.c                     |   4 +
 tools/objtool/include/objtool/builtin.h |   1 +
 tools/objtool/include/objtool/special.h |  56 +++
 7 files changed, 553 insertions(+), 9 deletions(-)
tools/objtool/arch/powerpc/decode.c +14 -1
index c851c51d4bd3..a508d50a54d6 100644
@@ -47,13 +47,26 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 	enum insn_type typ;
 	unsigned long imm;
 	u32 ins;
+	unsigned int aa;
 
 	ins = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
 	opcode = ins >> 26;
 	typ = INSN_OTHER;
 	imm = 0;
+	aa = ins & 2;
 
 	switch (opcode) {
+	case 16:
+		if (ins & 1)
+			typ = INSN_OTHER;
+		else
+			typ = INSN_JUMP_CONDITIONAL;
+		imm = ins & 0xfffc;
+		if (imm & 0x8000)
+			imm -= 0x10000;
+		insn->immediate = imm | aa;
+		break;
+
 	case 18: /* b[l][a] */
 		if (ins == 0x48000005)	/* bl .+4 */
 			typ = INSN_OTHER;
@@ -65,7 +78,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 		imm = ins & 0x3fffffc;
 		if (imm & 0x2000000)
 			imm -= 0x4000000;
-		imm |= ins & 2;	/* AA flag */
+		insn->immediate = imm | aa;
 		break;
 	}
 
tools/objtool/arch/powerpc/special.c +436 -0

446 lines not on this page · raw message

tools/objtool/builtin-check.c +2 -0
index 80239843e9f0..d081e07b0e93 100644
@@ -75,6 +75,7 @@ static const struct option check_options[] = {
 	OPT_GROUP("Actions:"),
 	OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake", "patch toolchain bugs/limitations", parse_hacks),
 	OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"),
+	OPT_BOOLEAN('f', "ftr-fixup", &opts.ftr_fixup, "feature fixup"),
 	OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls for ftrace"),
 	OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"),
 	OPT_BOOLEAN(0,   "orc", &opts.orc, "generate ORC metadata"),
@@ -160,6 +161,7 @@ static bool opts_valid(void)
 
 	if (opts.hack_jump_label	||
 	    opts.hack_noinstr		||
+	    opts.ftr_fixup		||
 	    opts.ibt			||
 	    opts.mcount			||
 	    opts.noinstr		||
tools/objtool/check.c +40 -8

78 lines not on this page · raw message

tools/objtool/elf.c +4 -0
index ca5d77db692a..860c0cde1b11 100644
@@ -1052,6 +1052,10 @@ struct elf *elf_open_read(const char *name, int flags)
 		cmd = ELF_C_WRITE;
 
 	elf->elf = elf_begin(elf->fd, cmd, NULL);
+
+	if (opts.ftr_fixup)
+		elf_flagelf(elf->elf, ELF_C_SET, ELF_F_LAYOUT);
+
 	if (!elf->elf) {
 		ERROR_ELF("elf_begin");
 		goto err;
tools/objtool/include/objtool/builtin.h +1 -0
index 6b08666fa69d..629af3c22f56 100644
@@ -11,6 +11,7 @@ struct opts {
 	/* actions: */
 	bool dump_orc;
 	bool hack_jump_label;
+	bool ftr_fixup;
 	bool hack_noinstr;
 	bool hack_skylake;
 	bool ibt;
tools/objtool/include/objtool/special.h +56 -0

72 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [RFC PATCH v2 1/3] objtool/powerpc: Enhance objtool to fixup alternate feature relative addresses

Quoted 93 lines · Sathvika Vasireddy

Implement build-time fixup of alternate feature relative addresses for the out-of-line (else) patch code. Initial posting to achieve the same using another tool can be found at [1]. Idea is to implement this using objtool instead of introducing another tool since it already has elf parsing and processing covered.

Introduce --ftr-fixup as an option to objtool to do feature fixup at build-time.

Couple of issues and warnings encountered while implementing feature fixup using objtool are as follows:

1. libelf is creating corrupted vmlinux file after writing necessary changes to the file. Due to this, kexec is not able to load new kernel.

It gives the following error:
ELF Note corrupted !
Cannot determine the file type of vmlinux

To fix this issue, after opening vmlinux file, make a call to elf_flagelf (e, ELF_C_SET, ELF_F_LAYOUT). This instructs libelf not to touch the segment and section layout. It informs the library that the application will take responsibility for the layout of the file and that the library should not insert any padding between sections.

2. Fix can't find starting instruction warnings when run on vmlinux

Objtool throws a lot of can't find starting instruction warnings when run on vmlinux with --ftr-fixup option.

These warnings are seen because find_insn() function looks for instructions at offsets that are relative to the start of the section. In case of individual object files (.o), there are no can't find starting instruction warnings seen because the actual offset associated with an instruction is itself a relative offset since the sections start at offset 0x0.

However, in case of vmlinux, find_insn() function fails to find instructions at the actual offset associated with an instruction since the sections in vmlinux do not start at offset 0x0. Due to this, find_insn() will look for absolute offset and not the relative offset. This is resulting in a lot of can't find starting instruction warnings when objtool is run on vmlinux.

To fix this, pass offset that is relative to the start of the section to find_insn().

find_insn() is also looking for symbols of size 0. But, objtool does not store empty STT_NOTYPE symbols in the rbtree. Due to this, for empty symbols, objtool is throwing can't find starting instruction warnings. Fix this by ignoring symbols that are of size 0 since objtool does not add them to the rbtree.

3. Objtool is throwing unannotated intra-function call warnings when run on vmlinux with --ftr-fixup option.

One such example:

vmlinux: warning: objtool: .text+0x3d94:
unannotated intra-function call

.text + 0x3d94 = c000000000008000 + 3d94 = c0000000000081d4

c0000000000081d4: 45 24 02 48 bl c00000000002a618 <system_reset_exception+0x8>

c00000000002a610 <system_reset_exception>:
c00000000002a610: 0e 01 4c 3c addis r2,r12,270

                        c00000000002a610: R_PPC64_REL16_HA    .TOC.
c00000000002a614:       f0 6c 42 38     addi    r2,r2,27888
                        c00000000002a614: R_PPC64_REL16_LO    .TOC.+0x4

c00000000002a618: a6 02 08 7c mflr r0

This is happening because we should be looking for destination symbols that are at absolute offsets instead of relative offsets. After fixing dest_off to point to absolute offset, there are still a lot of these warnings shown.

In the above example, objtool is computing the destination offset to be c00000000002a618, which points to a completely different instruction. find_call_destination() is looking for this offset and failing. Instead, we should be looking for destination offset c00000000002a610 which points to system_reset_exception function.

Even after fixing the way destination offset is computed, and after looking for dest_off - 0x8 in cases where the original offset is not found, there are still a lot of unannotated intra-function call warnings generated. This is due to symbols that are not properly annotated.

Quoted 3 lines

So, for now, as a hack to curb these warnings, do not emit unannotated intra-function call warnings when objtool is run with --ftr-fixup option.

Should not all those fixes be split out into separate patches? Also, Changelog seems to have lost the bit where you explain *why* you need this. IIRC Nick's original tool had a description of why this is needed.

Also, please see:

https://lkml.kernel.org/r/9500b90c4182b03da59472e1a27876818610b084.1758067942.git.jpoimboe@kernel.org

https://lkml.kernel.org/r/457c2e84b81bd6515aaa60ec8e9e0cc892ed7afa.1758067942.git.jpoimboe@kernel.org

#3 lore raw

Re: [RFC PATCH v2 1/3] objtool/powerpc: Enhance objtool to fixup alternate feature relative addresses

Hi Peter,

Quoted 94 lines · Peter Zijlstra
Quoted 93 lines · Sathvika Vasireddy

Implement build-time fixup of alternate feature relative addresses for the out-of-line (else) patch code. Initial posting to achieve the same using another tool can be found at [1]. Idea is to implement this using objtool instead of introducing another tool since it already has elf parsing and processing covered.

Introduce --ftr-fixup as an option to objtool to do feature fixup at build-time.

Couple of issues and warnings encountered while implementing feature fixup using objtool are as follows:

1. libelf is creating corrupted vmlinux file after writing necessary changes to the file. Due to this, kexec is not able to load new kernel.

It gives the following error:
ELF Note corrupted !
Cannot determine the file type of vmlinux

To fix this issue, after opening vmlinux file, make a call to elf_flagelf (e, ELF_C_SET, ELF_F_LAYOUT). This instructs libelf not to touch the segment and section layout. It informs the library that the application will take responsibility for the layout of the file and that the library should not insert any padding between sections.

2. Fix can't find starting instruction warnings when run on vmlinux

Objtool throws a lot of can't find starting instruction warnings when run on vmlinux with --ftr-fixup option.

These warnings are seen because find_insn() function looks for instructions at offsets that are relative to the start of the section. In case of individual object files (.o), there are no can't find starting instruction warnings seen because the actual offset associated with an instruction is itself a relative offset since the sections start at offset 0x0.

However, in case of vmlinux, find_insn() function fails to find instructions at the actual offset associated with an instruction since the sections in vmlinux do not start at offset 0x0. Due to this, find_insn() will look for absolute offset and not the relative offset. This is resulting in a lot of can't find starting instruction warnings when objtool is run on vmlinux.

To fix this, pass offset that is relative to the start of the section to find_insn().

find_insn() is also looking for symbols of size 0. But, objtool does not store empty STT_NOTYPE symbols in the rbtree. Due to this, for empty symbols, objtool is throwing can't find starting instruction warnings. Fix this by ignoring symbols that are of size 0 since objtool does not add them to the rbtree.

3. Objtool is throwing unannotated intra-function call warnings when run on vmlinux with --ftr-fixup option.

One such example:

vmlinux: warning: objtool: .text+0x3d94:
unannotated intra-function call

.text + 0x3d94 = c000000000008000 + 3d94 = c0000000000081d4

c0000000000081d4: 45 24 02 48 bl c00000000002a618 <system_reset_exception+0x8>

c00000000002a610 <system_reset_exception>:
c00000000002a610: 0e 01 4c 3c addis r2,r12,270

                         c00000000002a610: R_PPC64_REL16_HA    .TOC.
c00000000002a614:       f0 6c 42 38     addi    r2,r2,27888
                         c00000000002a614: R_PPC64_REL16_LO    .TOC.+0x4

c00000000002a618: a6 02 08 7c mflr r0

This is happening because we should be looking for destination symbols that are at absolute offsets instead of relative offsets. After fixing dest_off to point to absolute offset, there are still a lot of these warnings shown.

In the above example, objtool is computing the destination offset to be c00000000002a618, which points to a completely different instruction. find_call_destination() is looking for this offset and failing. Instead, we should be looking for destination offset c00000000002a610 which points to system_reset_exception function.

Even after fixing the way destination offset is computed, and after looking for dest_off - 0x8 in cases where the original offset is not found, there are still a lot of unannotated intra-function call warnings generated. This is due to symbols that are not properly annotated.

Quoted 4 lines
Quoted 3 lines

So, for now, as a hack to curb these warnings, do not emit unannotated intra-function call warnings when objtool is run with --ftr-fixup option.

Should not all those fixes be split out into separate patches?

Thank you for reviewing. You're right - these fixes should be split into separate patches.

Quoted 3 lines

Also,
Changelog seems to have lost the bit where you explain *why* you need this. IIRC Nick's original tool had a description of why this is needed.

Yes, Nick's original patch has the description on why this is needed: http://patchwork.ozlabs.org/project/linuxppc-dev/patch/[email protected]/

Currently __ftr_alt* sections must be near .text because they lack the executable attribute (preventing linker stubs), requiring branches to reach targets directly. This may cause build failures as the kernel grows. To solve this, the approach uses --emit-relocs to preserve relocation information, marks sections executable (allowing stubs), and fixes branch offsets at build time based on their runtime locations. This implementation uses objtool with the --ftr-fixup option instead of a new tool, since objtool already has ELF parsing and instruction patching infrastructure. I'll include the details of why this is needed in the Changelog in the next version I send.

Quoted 6 lines

Also, please see:

   https://lkml.kernel.org/r/9500b90c4182b03da59472e1a27876818610b084.1758067942.git.jpoimboe@kernel.org

   https://lkml.kernel.org/r/457c2e84b81bd6515aaa60ec8e9e0cc892ed7afa.1758067942.git.jpoimboe@kernel.org

Sure, will check.

Thanks,
Sathvika

#4 lore raw

Re: [RFC PATCH v2 1/3] objtool/powerpc: Enhance objtool to fixup alternate feature relative addresses

In reply to Sathvika Vasireddy
kernel test robot noticed the following build errors:

Hi Sathvika,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on powerpc/next]
[also build test ERROR on powerpc/fixes masahiroy-kbuild/for-next linus/master masahiroy-kbuild/fixes v6.17 next-20250929] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sathvika-Vasireddy/objtool-powerpc-Enhance-objtool-to-fixup-alternate-feature-relative-addresses/20250929-161302
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
patch link:    https://lore.kernel.org/r/20250929080456.26538-2-sv%40linux.ibm.com
patch subject: [RFC PATCH v2 1/3] objtool/powerpc: Enhance objtool to fixup alternate feature relative addresses

:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20251002/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251002/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

All errors (new ones prefixed by >>):

/usr/bin/ld: tools/objtool/objtool-in.o: in function `check':

>> tools/objtool/check.c:4710:(.text+0xeca9): undefined reference to `process_alt_data'
>> /usr/bin/ld: tools/objtool/check.c:4714:(.text+0xecb5): undefined reference to `process_fixup_entries'
>> /usr/bin/ld: tools/objtool/check.c:4718:(.text+0xecbe): undefined reference to `check_and_flatten_fixup_entries'
>> /usr/bin/ld: tools/objtool/check.c:4720:(.text+0xecc6): undefined reference to `process_exception_entries'
>> /usr/bin/ld: tools/objtool/check.c:4724:(.text+0xecd2): undefined reference to `process_bug_entries'
>> /usr/bin/ld: tools/objtool/check.c:4728:(.text+0xecde): undefined reference to `process_alt_relocations'

collect2: error: ld returned 1 exit status make[4]: *** [Makefile:70: tools/objtool/objtool] Error 1 make[4]: Target 'all' not remade because of errors. make[3]: *** [Makefile:73: objtool] Error 2 make[2]: *** [Makefile:1451: tools/objtool] Error 2 make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.

vim +4710 tools/objtool/check.c

d93b5935fd4700 Josh Poimboeuf     2023-05-30  4682  
d44becb9decf44 Julien Thierry     2020-08-25  4683  int check(struct objtool_file *file)
dcc914f44f065e Josh Poimboeuf     2017-06-28  4684  {
c5995abe154767 Josh Poimboeuf     2025-03-24  4685  	int ret = 0, warnings = 0;
dcc914f44f065e Josh Poimboeuf     2017-06-28  4686  
baa41469a7b992 Josh Poimboeuf     2017-06-28  4687  	arch_initial_func_cfi_state(&initial_func_cfi);
8b946cc38e063f Peter Zijlstra     2021-06-24  4688  	init_cfi_state(&init_cfi);
8b946cc38e063f Peter Zijlstra     2021-06-24  4689  	init_cfi_state(&func_cfi);
8b946cc38e063f Peter Zijlstra     2021-06-24  4690  	set_func_state(&func_cfi);
1e4b619185e83e Josh Poimboeuf     2023-06-05  4691  	init_cfi_state(&force_undefined_cfi);
1e4b619185e83e Josh Poimboeuf     2023-06-05  4692  	force_undefined_cfi.force_undefined = true;
8b946cc38e063f Peter Zijlstra     2021-06-24  4693  
b745962cb97569 Josh Poimboeuf     2025-03-14  4694  	if (!cfi_hash_alloc(1UL << (file->elf->symbol_bits - 3))) {
b745962cb97569 Josh Poimboeuf     2025-03-14  4695  		ret = -1;
8b946cc38e063f Peter Zijlstra     2021-06-24  4696  		goto out;
b745962cb97569 Josh Poimboeuf     2025-03-14  4697  	}
8b946cc38e063f Peter Zijlstra     2021-06-24  4698  
8b946cc38e063f Peter Zijlstra     2021-06-24  4699  	cfi_hash_add(&init_cfi);
8b946cc38e063f Peter Zijlstra     2021-06-24  4700  	cfi_hash_add(&func_cfi);
baa41469a7b992 Josh Poimboeuf     2017-06-28  4701  
6545eb030e6f14 Julien Thierry     2020-08-25  4702  	ret = decode_sections(file);
c5995abe154767 Josh Poimboeuf     2025-03-24  4703  	if (ret)
dcc914f44f065e Josh Poimboeuf     2017-06-28  4704  		goto out;
8b946cc38e063f Peter Zijlstra     2021-06-24  4705  
1c34496e585688 Peter Zijlstra     2023-02-08  4706  	if (!nr_insns)
baa41469a7b992 Josh Poimboeuf     2017-06-28  4707  		goto out;
baa41469a7b992 Josh Poimboeuf     2017-06-28  4708  
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4709  	if (opts.ftr_fixup) {
1512a02c86c678 Sathvika Vasireddy 2025-09-29 @4710  		ret = process_alt_data(file);
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4711  		if (ret < 0)
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4712  			return ret;
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4713  
1512a02c86c678 Sathvika Vasireddy 2025-09-29 @4714  		ret = process_fixup_entries(file);
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4715  		if (ret < 0)
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4716  			return ret;
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4717  
1512a02c86c678 Sathvika Vasireddy 2025-09-29 @4718  		check_and_flatten_fixup_entries();
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4719  
1512a02c86c678 Sathvika Vasireddy 2025-09-29 @4720  		ret = process_exception_entries(file);
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4721  		if (ret < 0)
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4722  			return ret;
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4723  
1512a02c86c678 Sathvika Vasireddy 2025-09-29 @4724  		ret = process_bug_entries(file);
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4725  		if (ret < 0)
1512a02c86c678 Sathvika Vasireddy 2025-09-29  4726  			return ret;

1512a02c86c678 Sathvika Vasireddy 2025-09-29 4727
1512a02c86c678 Sathvika Vasireddy 2025-09-29 @4728 ret = process_alt_relocations(file);

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

RFC PATCH v2 2/3 kbuild: Add objtool integration for PowerPC feature fixups

In reply to Sathvika Vasireddy

Add build system support for PowerPC feature fixup processing:

- Add HAVE_OBJTOOL_FTR_FIXUP config option for architectures that support build-time feature fixup processing
- Integrate objtool feature fixup processing into vmlinux build

---
 Makefile                 |  7 +++++++
 arch/Kconfig             |  3 +++
 scripts/Makefile.lib     |  5 +++--
 scripts/Makefile.vmlinux | 13 ++++++++++++-
 4 files changed, 25 insertions(+), 3 deletions(-)
Makefile +7 -0
index cf37b9407821..aa54e4348c8c 100644
@@ -1419,6 +1419,13 @@ ifdef CONFIG_OBJTOOL
 prepare: tools/objtool
 endif
 
+# CONFIG_OBJTOOL and CONFIG_HAVE_OBJTOOL_FTR_FIXUP are unrelated, separate
+# options. It was integrated in objtool in order to borrow the elf parser,
+# but this is different from how the other objtool commands are used.
+ifdef CONFIG_HAVE_OBJTOOL_FTR_FIXUP
+prepare: tools/objtool
+endif
+
 ifdef CONFIG_BPF
 ifdef CONFIG_DEBUG_INFO_BTF
 prepare: tools/bpf/resolve_btfids
arch/Kconfig +3 -0
index d1b4ffd6e085..d870aab17cba 100644
@@ -1334,6 +1334,9 @@ config HAVE_UACCESS_VALIDATION
 	bool
 	select OBJTOOL
 
+config HAVE_OBJTOOL_FTR_FIXUP
+	bool
+
 config HAVE_STACK_VALIDATION
 	bool
 	help
scripts/Makefile.lib +3 -2
index 1d581ba5df66..c77d4ceff2cc 100644
@@ -169,10 +169,10 @@ cpp_flags      = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
 
 ld_flags       = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
 
-ifdef CONFIG_OBJTOOL
-
 objtool := $(objtree)/tools/objtool/objtool
 
+ifdef CONFIG_OBJTOOL
+
 objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK)		+= --hacks=jump_label
 objtool-args-$(CONFIG_HAVE_NOINSTR_HACK)		+= --hacks=noinstr
 objtool-args-$(CONFIG_MITIGATION_CALL_DEPTH_TRACKING)	+= --hacks=skylake
@@ -200,6 +200,7 @@ objtool-args = $(objtool-args-y)					\
 delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
 
 cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
+
 cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
 
 objtool-enabled := y
scripts/Makefile.vmlinux +12 -1
index b64862dc6f08..94cc2bba929a 100644
@@ -84,7 +84,8 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
 # Final link of vmlinux with optional arch pass after final link
 cmd_link_vmlinux =							\
 	$< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@";	\
-	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)	\
+	$(cmd_objtool_vmlinux)
 
 targets += $(vmlinux-final)
 $(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
@@ -131,3 +132,13 @@ existing-targets := $(wildcard $(sort $(targets)))
 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
 
 .PHONY: $(PHONY)
+
+# objtool for vmlinux
+# ----------------------------------
+#
+#  For feature fixup, objtool does not run on individual
+#  translation units. Run this on vmlinux instead.
+
+ifdef CONFIG_HAVE_OBJTOOL_FTR_FIXUP
+cmd_objtool_vmlinux = ; $(objtool) --ftr-fixup --link $@
+endif
Signature · 1 line
2.43.0
maintainer
#6 lore raw

Re: [RFC PATCH v2 2/3] kbuild: Add objtool integration for PowerPC feature fixups

Quoted 15 lines · Sathvika Vasireddy

Add build system support for PowerPC feature fixup processing:

- Add HAVE_OBJTOOL_FTR_FIXUP config option for architectures that support build-time feature fixup processing
- Integrate objtool feature fixup processing into vmlinux build

---
 Makefile                 |  7 +++++++
 arch/Kconfig             |  3 +++
 scripts/Makefile.lib     |  5 +++--
 scripts/Makefile.vmlinux | 13 ++++++++++++-
 4 files changed, 25 insertions(+), 3 deletions(-)

...

arch/Kconfig config HAVE_UACCESS_VALIDATION · line 1337

Quoted 9 lines
arch/Kconfig +1 -0
index d1b4ffd6e085..d870aab17cba 100644
@@ -1334,6 +1334,9 @@ config HAVE_UACCESS_VALIDATION
 	bool
 	select OBJTOOL
 
+config HAVE_OBJTOOL_FTR_FIXUP

For me, FTR is not that natural to parse. Is there a reason for using FTR instead of FEATURE?

...

Quoted 17 lines
scripts/Makefile.vmlinux +2 -1
index b64862dc6f08..94cc2bba929a 100644
@@ -84,7 +84,8 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
 # Final link of vmlinux with optional arch pass after final link
 cmd_link_vmlinux =							\
 	$< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@";	\
-	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)	\
+	$(cmd_objtool_vmlinux)
 
 targets += $(vmlinux-final)
 $(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
@@ -131,3 +132,13 @@ existing-targets := $(wildcard $(sort $(targets)))
 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
 

scripts/Makefile.vmlinux existing-targets := $(wildcard $(sort $(targets))) · line 143

Quoted 10 lines
scripts/Makefile.vmlinux +9 -0
 .PHONY: $(PHONY)
+
+# objtool for vmlinux
+# ----------------------------------
+#
+#  For feature fixup, objtool does not run on individual
+#  translation units. Run this on vmlinux instead.
+
+ifdef CONFIG_HAVE_OBJTOOL_FTR_FIXUP
+cmd_objtool_vmlinux = ; $(objtool) --ftr-fixup --link $@

This cmd_* definition is broken as $(call cmd,objtool_vmlinux) would be evaluated to '... ; ; ...' (shell syntax error).

What about putting the objtool call right into cmd_link_vmlinux?

cmd_link_vmlinux =							\
	$< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@";	\
	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true);   \
	$(if $(CONFIG_HAVE_OBJTOOL_FTR_FIXUP), $(objtool) --ftr-fixup --link $@, true)

Kind regards,
Nicolas

#7 lore raw

Re: [RFC PATCH v2 2/3] kbuild: Add objtool integration for PowerPC feature fixups

Hi Nicolas,

Thank you for the review and suggestions!

Quoted 25 lines · Nicolas Schier
Quoted 15 lines · Sathvika Vasireddy

Add build system support for PowerPC feature fixup processing:

- Add HAVE_OBJTOOL_FTR_FIXUP config option for architectures that support build-time feature fixup processing
- Integrate objtool feature fixup processing into vmlinux build

---
  Makefile                 |  7 +++++++
  arch/Kconfig             |  3 +++
  scripts/Makefile.lib     |  5 +++--
  scripts/Makefile.vmlinux | 13 ++++++++++++-
  4 files changed, 25 insertions(+), 3 deletions(-)

...

Quoted 8 lines
arch/Kconfig +0 -0
index d1b4ffd6e085..d870aab17cba 100644
@@ -1334,6 +1334,9 @@ config HAVE_UACCESS_VALIDATION
  	bool
  	select OBJTOOL
 
Quoted 3 lines

arch/Kconfig config HAVE_UACCESS_VALIDATION · line 1337

Quoted 1 line
arch/Kconfig +1 -0
+config HAVE_OBJTOOL_FTR_FIXUP

For me, FTR is not that natural to parse. Is there a reason for using FTR instead of FEATURE?

The naming comes from the PowerPC-specific section names (__ftr_alt_*) , and (*ftr_fixup) in vmlinux. However, I agree that FEATURE is more readable and I'll update all references to use FEATURE_FIXUP instead.

Also, on a second thought, since feature fixup is PowerPC-specific and no other architecture has this mechanism (please correct me if I am wrong), I will move HAVE_OBJTOOL_FEATURE_FIXUP from arch/Kconfig to arch/powerpc/Kconfig in the next version.

Quoted 32 lines

...

Quoted 17 lines
scripts/Makefile.vmlinux +2 -1
index b64862dc6f08..94cc2bba929a 100644
@@ -84,7 +84,8 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
  # Final link of vmlinux with optional arch pass after final link
  cmd_link_vmlinux =							\
  	$< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@";	\
-	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)	\
+	$(cmd_objtool_vmlinux)
 
  targets += $(vmlinux-final)
  $(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
@@ -131,3 +132,13 @@ existing-targets := $(wildcard $(sort $(targets)))
  -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
 

scripts/Makefile.vmlinux existing-targets := $(wildcard $(sort $(targets))) · line 143

Quoted 10 lines
scripts/Makefile.vmlinux +9 -0
  .PHONY: $(PHONY)
+
+# objtool for vmlinux
+# ----------------------------------
+#
+#  For feature fixup, objtool does not run on individual
+#  translation units. Run this on vmlinux instead.
+
+ifdef CONFIG_HAVE_OBJTOOL_FTR_FIXUP
+cmd_objtool_vmlinux = ; $(objtool) --ftr-fixup --link $@

This cmd_* definition is broken as $(call cmd,objtool_vmlinux) would be evaluated to '... ; ; ...' (shell syntax error).

Quoted 1 line

What about putting the objtool call right into cmd_link_vmlinux?

Sure, I will include the changes to put the objtool call into cmd_link_vmlinux as suggested, in the next version.

Thanks, Sathvika

#8 lore raw

RFC PATCH v2 3/3 powerpc: Enable build-time feature fixup processing by default

In reply to Sathvika Vasireddy

Enable HAVE_OBJTOOL_FTR_FIXUP by default on PowerPC architecture.

- Remove runtime branch translation logic from patch_alt_instruction()
- Add --emit-relocs linker flags for post-link fixup processing
- Update ftr_alt section attributes to include executable flag

---
 arch/powerpc/Kconfig                      |  3 +++
 arch/powerpc/Makefile                     |  5 +++++
 arch/powerpc/include/asm/feature-fixups.h |  2 +-
 arch/powerpc/kernel/vmlinux.lds.S         |  8 ++++++--
 arch/powerpc/lib/feature-fixups.c         | 12 ------------
 5 files changed, 15 insertions(+), 15 deletions(-)
arch/powerpc/Kconfig +3 -0
index 325c1171894d..450b5822786d 100644
@@ -23,6 +23,9 @@ config 64BIT
 	bool
 	default y if PPC64
 
+config HAVE_OBJTOOL_FTR_FIXUP
+        def_bool y
+
 config LIVEPATCH_64
 	def_bool PPC64
 	depends on LIVEPATCH
arch/powerpc/Makefile +5 -0
index a58b1029592c..8e1dab5f3c9a 100644
@@ -105,6 +105,11 @@ LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie --no-dynamic-linker
 LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) += -z notext
 LDFLAGS_vmlinux	:= $(LDFLAGS_vmlinux-y)
 
+# --emit-relocs required for post-link fixup of alternate feature
+# text section relocations.
+LDFLAGS_vmlinux        += --emit-relocs
+KBUILD_LDFLAGS_MODULE += --emit-relocs
+
 ifdef CONFIG_PPC64
 ifndef CONFIG_PPC_KERNEL_PCREL
 	# -mcmodel=medium breaks modules because it uses 32bit offsets from
arch/powerpc/include/asm/feature-fixups.h +1 -1
index 756a6c694018..d6ae92a292ec 100644
@@ -32,7 +32,7 @@
 
 #define FTR_SECTION_ELSE_NESTED(label)			\
 label##2:						\
-	.pushsection __ftr_alt_##label,"a";		\
+	.pushsection __ftr_alt_##label, "ax";		\
 	.align 2;					\
 label##3:
 
arch/powerpc/kernel/vmlinux.lds.S +6 -2
index de6ee7d35cff..961ef49f8bd3 100644
@@ -99,8 +99,8 @@ SECTIONS
 	.text : AT(ADDR(.text) - LOAD_OFFSET) {
 		ALIGN_FUNCTION();
 #endif
-		/* careful! __ftr_alt_* sections need to be close to .text */
-		*(.text.hot .text.hot.* TEXT_MAIN .text.fixup .text.unlikely .text.unlikely.* .fixup __ftr_alt_* .ref.text);
+		*(.text.hot .text.hot.* TEXT_MAIN .text.fixup .text.unlikely
+			.text.unlikely.* .fixup .ref.text);
 		*(.tramp.ftrace.text);
 		NOINSTR_TEXT
 		SCHED_TEXT
@@ -267,6 +267,10 @@ SECTIONS
 		_einittext = .;
 	} :text
 
+	.__ftr_alternates.text : AT(ADDR(.__ftr_alternates.text) - LOAD_OFFSET) {
+		*(__ftr_alt*);
+	}
+
 	/* .exit.text is discarded at runtime, not link time,
 	 * to deal with references from __bug_table
 	 */
arch/powerpc/lib/feature-fixups.c +0 -12
index 587c8cf1230f..269e992b1631 100644
@@ -53,22 +53,10 @@ static u32 *calc_addr(struct fixup_entry *fcur, long offset)
 
 static int patch_alt_instruction(u32 *src, u32 *dest, u32 *alt_start, u32 *alt_end)
 {
-	int err;
 	ppc_inst_t instr;
 
 	instr = ppc_inst_read(src);
 
-	if (instr_is_relative_branch(ppc_inst_read(src))) {
-		u32 *target = (u32 *)branch_target(src);
-
-		/* Branch within the section doesn't need translating */
-		if (target < alt_start || target > alt_end) {
-			err = translate_branch(&instr, dest, src);
-			if (err)
-				return 1;
-		}
-	}
-
 	raw_patch_instruction(dest, instr);
 
 	return 0;
Signature · 1 line
2.43.0