powerpc64/ftrace: fixes clang build issues
v2 cover powerpc64/ftrace: fixes clang build issues
Support for -fpatchable-function-entry on ppc64le was added in Clang with [1]. Faced a couple of issues while building the linux kernel with Clang though. Patches 1 & 2 address those issues. The last patch provides workaround to ensure, an open issue [2] in Clang with -fpatchable-function-entry support, does not impact the linux ftrace subsystem.
[1] https://github.com/llvm/llvm-project/pull/151569
[2] https://github.com/llvm/llvm-project/issues/163706
Hari Bathini (3):
powerpc64: make clang cross-build friendly powerpc64/ftrace: fix OOL stub count with clang powerpc64/ftrace: workaround clang recording GEP in
__patchable_function_entries
arch/powerpc/Kconfig | 4 +--
arch/powerpc/kernel/trace/ftrace.c | 26 ++++++++++++++++---
....sh => check-fpatchable-function-entry.sh} | 0
arch/powerpc/tools/ftrace-gen-ool-stubs.sh | 4 +--
4 files changed, 26 insertions(+), 8 deletions(-)
rename arch/powerpc/tools/{gcc-check-fpatchable-function-entry.sh => check-fpatchable-function-entry.sh} (100%)Signature · 1 line
2.52.0
PATCH v2 1/3 powerpc64: make clang cross-build friendly
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.
---
* Changes in v2:
- Use $(CLANG_FLAGS) instead of manually checking CC_IS_CLANG
arch/powerpc/Kconfig | 4 ++--
...e-function-entry.sh => check-fpatchable-function-entry.sh} | 0
2 files changed, 2 insertions(+), 2 deletions(-)
rename arch/powerpc/tools/{gcc-check-fpatchable-function-entry.sh => check-fpatchable-function-entry.sh} (100%)arch/powerpc/Kconfig +2 -2
@@ -571,8 +571,8 @@ 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) $(CLANG_FLAGS) -mlittle-endian) if PPC64 && CPU_LITTLE_ENDIAN + 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
arch/powerpc/tools/check-fpatchable-function-entry.sh renamed from arch/powerpc/tools/gcc-check-fpatchable-function-entry.sh +0 -0
Signature · 1 line
2.52.0
PATCH v2 2/3 powerpc64/ftrace: fix OOL stub count with clang
In reply to Hari BathiniThe 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.
---
* No changes since v1.
arch/powerpc/tools/ftrace-gen-ool-stubs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/tools/ftrace-gen-ool-stubs.sh +2 -2
@@ -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))
Signature · 1 line
2.52.0
PATCH v2 3/3 powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries
In reply to Hari BathiniSupport 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
---
* No changes since v1.
arch/powerpc/kernel/trace/ftrace.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
arch/powerpc/kernel/trace/ftrace.c +22 -4
@@ -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;
Signature · 1 line
2.52.0
Quoted 17 lines · Hari Bathini
Support for -fpatchable-function-entry on ppc64le was added in Clang with [1]. Faced a couple of issues while building the linux kernel with Clang though. Patches 1 & 2 address those issues. The last patch provides workaround to ensure, an open issue [2] in Clang with -fpatchable-function-entry support, does not impact the linux ftrace subsystem.
[1] https://github.com/llvm/llvm-project/pull/151569
[2] https://github.com/llvm/llvm-project/issues/163706Hari Bathini (3):
powerpc64: make clang cross-build friendly powerpc64/ftrace: fix OOL stub count with clang powerpc64/ftrace: workaround clang recording GEP in
__patchable_function_entries
Quoted 7 lines
arch/powerpc/Kconfig | 4 +-- arch/powerpc/kernel/trace/ftrace.c | 26 ++++++++++++++++--- ....sh => check-fpatchable-function-entry.sh} | 0 arch/powerpc/tools/ftrace-gen-ool-stubs.sh | 4 +-- 4 files changed, 26 insertions(+), 8 deletions(-)rename
arch/powerpc/tools/{gcc-check-fpatchable-function-entry.sh=>check-fpatchable-function-entry.sh} (100%)
Tested this patch series, and bulild is successful with both GCC and clang23.x version.
KERNEL PARAMETER enabled:
CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY=yCONFIG_PPC_FTRACE_OUT_OF_LINE=yCONFIG_PPC_FTRACE_OUT_OF_LINE_NUM_RESERVE=32768
clang version 23.0.0git
Please add below tag for the series.
Regards,
Venkat.
Quoted 8 lines · Hari Bathini
Support for -fpatchable-function-entry on ppc64le was added in Clang with [1]. Faced a couple of issues while building the linux kernel with Clang though. Patches 1 & 2 address those issues. The last patch provides workaround to ensure, an open issue [2] in Clang with -fpatchable-function-entry support, does not impact the linux ftrace subsystem.
[...]
Applied to powerpc/fixes.
[1/3] powerpc64: make clang cross-build friendly
https://git.kernel.org/powerpc/c/73cdf24e81e4eba52a40a6b10c6cf285d0ac23fd [2/3] powerpc64/ftrace: fix OOL stub count with clang https://git.kernel.org/powerpc/c/875612a7745013a43c67493cb0583ee3f7476344 [3/3] powerpc64/ftrace: workaround clang recording GEP in __patchable_function_entries https://git.kernel.org/powerpc/c/db54c28702f7270e74dce36c84cb0db4cec96389
cheers