* [PATCH 1/3] powerpc64: make clang cross-build friendly
2025-11-08 21:04 [PATCH 0/3] powerpc64/ftrace: fixes clang build issues Hari Bathini
@ 2025-11-08 21:04 ` Hari Bathini
2025-11-24 5:49 ` Naveen N Rao
2025-11-08 21:04 ` [PATCH 2/3] powerpc64/ftrace: fix OOL stub count with clang Hari Bathini
2025-11-08 21:04 ` [PATCH 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries Hari Bathini
2 siblings, 1 reply; 8+ messages in thread
From: Hari Bathini @ 2025-11-08 21:04 UTC (permalink / raw)
To: linuxppc-dev
Cc: Madhavan Srinivasan, Christophe Leroy, Naveen N. Rao,
Michael Ellerman, linux-trace-kernel, Mark Rutland,
Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas
ARCH_USING_PATCHABLE_FUNCTION_ENTRY depends on toolchain support for
-fpatchable-function-entry option. The current script that checks
for this support only handles GCC. Rename the script and extend it
to detect support for -fpatchable-function-entry with Clang as well,
allowing clean cross-compilation with Clang toolchains.
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
arch/powerpc/Kconfig | 5 +++--
...-function-entry.sh => check-fpatchable-function-entry.sh} | 0
2 files changed, 3 insertions(+), 2 deletions(-)
rename arch/powerpc/tools/{gcc-check-fpatchable-function-entry.sh => check-fpatchable-function-entry.sh} (100%)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 325c1171894d..dfb62e211c92 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -568,8 +568,9 @@ config ARCH_USING_PATCHABLE_FUNCTION_ENTRY
depends on FUNCTION_TRACER && (PPC32 || PPC64_ELF_ABI_V2)
depends on $(cc-option,-fpatchable-function-entry=2)
def_bool y if PPC32
- def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh $(CC) -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN
- def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh $(CC) -mbig-endian) if PPC64 && CPU_BIG_ENDIAN
+ def_bool $(success,$(srctree)/arch/powerpc/tools/check-fpatchable-function-entry.sh $(CC) -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN && CC_IS_GCC
+ def_bool $(success,$(srctree)/arch/powerpc/tools/check-fpatchable-function-entry.sh $(CC) -target ppc64le -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN && CC_IS_CLANG
+ def_bool $(success,$(srctree)/arch/powerpc/tools/check-fpatchable-function-entry.sh $(CC) -mbig-endian) if PPC64 && CPU_BIG_ENDIAN
config PPC_FTRACE_OUT_OF_LINE
def_bool PPC64 && ARCH_USING_PATCHABLE_FUNCTION_ENTRY
diff --git a/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh b/arch/powerpc/tools/check-fpatchable-function-entry.sh
similarity index 100%
rename from arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh
rename to arch/powerpc/tools/check-fpatchable-function-entry.sh
--
2.51.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/3] powerpc64: make clang cross-build friendly
2025-11-08 21:04 ` [PATCH 1/3] powerpc64: make clang cross-build friendly Hari Bathini
@ 2025-11-24 5:49 ` Naveen N Rao
2025-12-08 16:02 ` Hari Bathini
0 siblings, 1 reply; 8+ messages in thread
From: Naveen N Rao @ 2025-11-24 5:49 UTC (permalink / raw)
To: Hari Bathini
Cc: linuxppc-dev, Madhavan Srinivasan, Christophe Leroy,
Michael Ellerman, linux-trace-kernel, Mark Rutland,
Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas
On Sun, Nov 09, 2025 at 02:34:03AM +0530, Hari Bathini wrote:
> ARCH_USING_PATCHABLE_FUNCTION_ENTRY depends on toolchain support for
> -fpatchable-function-entry option. The current script that checks
> for this support only handles GCC. Rename the script and extend it
> to detect support for -fpatchable-function-entry with Clang as well,
> allowing clean cross-compilation with Clang toolchains.
>
> Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
> ---
> arch/powerpc/Kconfig | 5 +++--
> ...-function-entry.sh => check-fpatchable-function-entry.sh} | 0
> 2 files changed, 3 insertions(+), 2 deletions(-)
> rename arch/powerpc/tools/{gcc-check-fpatchable-function-entry.sh => check-fpatchable-function-entry.sh} (100%)
>
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 325c1171894d..dfb62e211c92 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -568,8 +568,9 @@ config ARCH_USING_PATCHABLE_FUNCTION_ENTRY
> depends on FUNCTION_TRACER && (PPC32 || PPC64_ELF_ABI_V2)
> depends on $(cc-option,-fpatchable-function-entry=2)
> def_bool y if PPC32
> - def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh $(CC) -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN
> - def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh $(CC) -mbig-endian) if PPC64 && CPU_BIG_ENDIAN
> + def_bool $(success,$(srctree)/arch/powerpc/tools/check-fpatchable-function-entry.sh $(CC) -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN && CC_IS_GCC
> + def_bool $(success,$(srctree)/arch/powerpc/tools/check-fpatchable-function-entry.sh $(CC) -target ppc64le -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN && CC_IS_CLANG
Can you instead pass $(CLANG_FLAGS) to retain the same command across
gcc/clang?
- Naveen
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 1/3] powerpc64: make clang cross-build friendly
2025-11-24 5:49 ` Naveen N Rao
@ 2025-12-08 16:02 ` Hari Bathini
0 siblings, 0 replies; 8+ messages in thread
From: Hari Bathini @ 2025-12-08 16:02 UTC (permalink / raw)
To: Naveen N Rao
Cc: linuxppc-dev, Madhavan Srinivasan, Christophe Leroy,
Michael Ellerman, linux-trace-kernel, Mark Rutland,
Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas
Thanks for the review, Naveen.
On 24/11/25 11:19 am, Naveen N Rao wrote:
> On Sun, Nov 09, 2025 at 02:34:03AM +0530, Hari Bathini wrote:
>> ARCH_USING_PATCHABLE_FUNCTION_ENTRY depends on toolchain support for
>> -fpatchable-function-entry option. The current script that checks
>> for this support only handles GCC. Rename the script and extend it
>> to detect support for -fpatchable-function-entry with Clang as well,
>> allowing clean cross-compilation with Clang toolchains.
>>
>> Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
>> ---
>> arch/powerpc/Kconfig | 5 +++--
>> ...-function-entry.sh => check-fpatchable-function-entry.sh} | 0
>> 2 files changed, 3 insertions(+), 2 deletions(-)
>> rename arch/powerpc/tools/{gcc-check-fpatchable-function-entry.sh => check-fpatchable-function-entry.sh} (100%)
>>
>> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
>> index 325c1171894d..dfb62e211c92 100644
>> --- a/arch/powerpc/Kconfig
>> +++ b/arch/powerpc/Kconfig
>> @@ -568,8 +568,9 @@ config ARCH_USING_PATCHABLE_FUNCTION_ENTRY
>> depends on FUNCTION_TRACER && (PPC32 || PPC64_ELF_ABI_V2)
>> depends on $(cc-option,-fpatchable-function-entry=2)
>> def_bool y if PPC32
>> - def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh $(CC) -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN
>> - def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh $(CC) -mbig-endian) if PPC64 && CPU_BIG_ENDIAN
>> + def_bool $(success,$(srctree)/arch/powerpc/tools/check-fpatchable-function-entry.sh $(CC) -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN && CC_IS_GCC
>> + def_bool $(success,$(srctree)/arch/powerpc/tools/check-fpatchable-function-entry.sh $(CC) -target ppc64le -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN && CC_IS_CLANG
>
> Can you instead pass $(CLANG_FLAGS) to retain the same command across
> gcc/clang?
Should work, I guess.
But do I need to test for any additional clang flags that
may interfere with what we are trying to check here?
- Hari
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] powerpc64/ftrace: fix OOL stub count with clang
2025-11-08 21:04 [PATCH 0/3] powerpc64/ftrace: fixes clang build issues Hari Bathini
2025-11-08 21:04 ` [PATCH 1/3] powerpc64: make clang cross-build friendly Hari Bathini
@ 2025-11-08 21:04 ` Hari Bathini
2025-11-08 21:04 ` [PATCH 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries Hari Bathini
2 siblings, 0 replies; 8+ messages in thread
From: Hari Bathini @ 2025-11-08 21:04 UTC (permalink / raw)
To: linuxppc-dev
Cc: Madhavan Srinivasan, Christophe Leroy, Naveen N. Rao,
Michael Ellerman, linux-trace-kernel, Mark Rutland,
Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas
The total number of out-of-line (OOL) stubs required for function
tracing is determined using the following command:
$(OBJDUMP) -r -j __patchable_function_entries vmlinux.o
While this works correctly with GNU objdump, llvm-objdump does not
list the expected relocation records for this section. Fix this by
using the -d option and counting R_PPC64_ADDR64 relocation entries.
This works as desired with both objdump and llvm-objdump.
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
arch/powerpc/tools/ftrace-gen-ool-stubs.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/tools/ftrace-gen-ool-stubs.sh b/arch/powerpc/tools/ftrace-gen-ool-stubs.sh
index bac186bdf64a..9218d43aeb54 100755
--- a/arch/powerpc/tools/ftrace-gen-ool-stubs.sh
+++ b/arch/powerpc/tools/ftrace-gen-ool-stubs.sh
@@ -15,9 +15,9 @@ if [ -z "$is_64bit" ]; then
RELOCATION=R_PPC_ADDR32
fi
-num_ool_stubs_total=$($objdump -r -j __patchable_function_entries "$vmlinux_o" |
+num_ool_stubs_total=$($objdump -r -j __patchable_function_entries -d "$vmlinux_o" |
grep -c "$RELOCATION")
-num_ool_stubs_inittext=$($objdump -r -j __patchable_function_entries "$vmlinux_o" |
+num_ool_stubs_inittext=$($objdump -r -j __patchable_function_entries -d "$vmlinux_o" |
grep -e ".init.text" -e ".text.startup" | grep -c "$RELOCATION")
num_ool_stubs_text=$((num_ool_stubs_total - num_ool_stubs_inittext))
--
2.51.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries
2025-11-08 21:04 [PATCH 0/3] powerpc64/ftrace: fixes clang build issues Hari Bathini
2025-11-08 21:04 ` [PATCH 1/3] powerpc64: make clang cross-build friendly Hari Bathini
2025-11-08 21:04 ` [PATCH 2/3] powerpc64/ftrace: fix OOL stub count with clang Hari Bathini
@ 2025-11-08 21:04 ` Hari Bathini
2025-11-24 5:55 ` Naveen N Rao
2 siblings, 1 reply; 8+ messages in thread
From: Hari Bathini @ 2025-11-08 21:04 UTC (permalink / raw)
To: linuxppc-dev
Cc: Madhavan Srinivasan, Christophe Leroy, Naveen N. Rao,
Michael Ellerman, linux-trace-kernel, Mark Rutland,
Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas
Support for -fpatchable-function-entry on ppc64le was added in Clang
with [1]. However, when no prefix NOPs are specified - as is the case
with CONFIG_PPC_FTRACE_OUT_OF_LINE - the first NOP is emitted at LEP,
but Clang records the Global Entry Point (GEP) unlike GCC which does
record the Local Entry Point (LEP). Issue [2] has been raised to align
Clang's behavior with GCC. As a temporary workaround to ensure ftrace
initialization works as expected with Clang, derive the LEP using
ppc_function_entry() for kernel symbols and by looking for the below
module GEP sequence for module addresses, until [2] is resolved:
ld r2, -8(r12)
add r2, r2, r12
[1] https://github.com/llvm/llvm-project/pull/151569
[2] https://github.com/llvm/llvm-project/issues/163706
Cc: Maryam Moghadas <maryammo@ca.ibm.com>
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
arch/powerpc/kernel/trace/ftrace.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c
index 841d077e2825..1b2f293e7dcb 100644
--- a/arch/powerpc/kernel/trace/ftrace.c
+++ b/arch/powerpc/kernel/trace/ftrace.c
@@ -37,11 +37,29 @@ unsigned long ftrace_call_adjust(unsigned long addr)
if (addr >= (unsigned long)__exittext_begin && addr < (unsigned long)__exittext_end)
return 0;
- if (IS_ENABLED(CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY) &&
- !IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE)) {
- addr += MCOUNT_INSN_SIZE;
- if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS))
+ if (IS_ENABLED(CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY)) {
+ if (!IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE)) {
addr += MCOUNT_INSN_SIZE;
+ if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS))
+ addr += MCOUNT_INSN_SIZE;
+ } else if (IS_ENABLED(CONFIG_CC_IS_CLANG) && IS_ENABLED(CONFIG_PPC64)) {
+ /*
+ * addr points to global entry point though the NOP was emitted at local
+ * entry point due to https://github.com/llvm/llvm-project/issues/163706
+ * Handle that here with ppc_function_entry() for kernel symbols while
+ * adjusting module addresses in the else case, by looking for the below
+ * module global entry point sequence:
+ * ld r2, -8(r12)
+ * add r2, r2, r12
+ */
+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
+ addr = ppc_function_entry((void *)addr);
+ else if ((ppc_inst_val(ppc_inst_read((u32 *)addr)) ==
+ PPC_RAW_LD(_R2, _R12, -8)) &&
+ (ppc_inst_val(ppc_inst_read((u32 *)(addr+4))) ==
+ PPC_RAW_ADD(_R2, _R2, _R12)))
+ addr += 8;
+ }
}
return addr;
--
2.51.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries
2025-11-08 21:04 ` [PATCH 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries Hari Bathini
@ 2025-11-24 5:55 ` Naveen N Rao
2025-12-08 16:08 ` Hari Bathini
0 siblings, 1 reply; 8+ messages in thread
From: Naveen N Rao @ 2025-11-24 5:55 UTC (permalink / raw)
To: Hari Bathini
Cc: linuxppc-dev, Madhavan Srinivasan, Christophe Leroy,
Michael Ellerman, linux-trace-kernel, Mark Rutland,
Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas
On Sun, Nov 09, 2025 at 02:34:05AM +0530, Hari Bathini wrote:
> Support for -fpatchable-function-entry on ppc64le was added in Clang
> with [1]. However, when no prefix NOPs are specified - as is the case
> with CONFIG_PPC_FTRACE_OUT_OF_LINE - the first NOP is emitted at LEP,
> but Clang records the Global Entry Point (GEP) unlike GCC which does
> record the Local Entry Point (LEP). Issue [2] has been raised to align
> Clang's behavior with GCC. As a temporary workaround to ensure ftrace
Any reason to put in a "temporary" workaround rather than waiting for
this to be fixed?
- Naveen
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries
2025-11-24 5:55 ` Naveen N Rao
@ 2025-12-08 16:08 ` Hari Bathini
0 siblings, 0 replies; 8+ messages in thread
From: Hari Bathini @ 2025-12-08 16:08 UTC (permalink / raw)
To: Naveen N Rao
Cc: linuxppc-dev, Madhavan Srinivasan, Christophe Leroy,
Michael Ellerman, linux-trace-kernel, Mark Rutland,
Steven Rostedt, Masami Hiramatsu, llvm, Maryam Moghadas
On 24/11/25 11:25 am, Naveen N Rao wrote:
> On Sun, Nov 09, 2025 at 02:34:05AM +0530, Hari Bathini wrote:
>> Support for -fpatchable-function-entry on ppc64le was added in Clang
>> with [1]. However, when no prefix NOPs are specified - as is the case
>> with CONFIG_PPC_FTRACE_OUT_OF_LINE - the first NOP is emitted at LEP,
>> but Clang records the Global Entry Point (GEP) unlike GCC which does
>> record the Local Entry Point (LEP). Issue [2] has been raised to align
>> Clang's behavior with GCC. As a temporary workaround to ensure ftrace
>
> Any reason to put in a "temporary" workaround rather than waiting for
> this to be fixed?
Pushing for this temporary workaround as the fix ETA for clang is not
available at the moment and the temporary workaround is likely
harmless even on a clang version with the fix included..
- Hari
^ permalink raw reply [flat|nested] 8+ messages in thread