Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PowerPC] call to _mcount emitted by -pg needs to be emitted BEFORE function prolog #63220

Open
nickdesaulniers opened this issue Jun 9, 2023 · 7 comments · May be fixed by #92997
Open

[PowerPC] call to _mcount emitted by -pg needs to be emitted BEFORE function prolog #63220

nickdesaulniers opened this issue Jun 9, 2023 · 7 comments · May be fixed by #92997
Assignees

Comments

@nickdesaulniers
Copy link
Member

nickdesaulniers commented Jun 9, 2023

From an LKML thread: https://lore.kernel.org/llvm/20230609034501.407971-1-naveen@kernel.org/

Ftrace on ppc32 expects a three instruction sequence at the beginning of
each function when specifying -pg:
	mflr	r0
	stw	r0,4(r1)
	bl	_mcount

This is the case with all supported versions of gcc. Clang however emits
a branch to _mcount after the function prologue

Example: https://godbolt.org/z/8r83PKorK

As a result, support for function tracing is being disabled in the linux kernel for ppc32 when built with clang.

cc @nemanjai @nemanja-ibm

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 9, 2023

@llvm/issue-subscribers-backend-powerpc

mpe pushed a commit to linuxppc/linux-ci that referenced this issue Jun 14, 2023
Ftrace on ppc32 expects a three instruction sequence at the beginning of
each function when specifying -pg:
	mflr	r0
	stw	r0,4(r1)
	bl	_mcount

This is the case with all supported versions of gcc. Clang however emits
a branch to _mcount after the function prologue, similar to the pre
-mprofile-kernel ABI on ppc64. This is not supported.

Disable ftrace on ppc32 if using clang for now. This can be re-enabled
later if clang picks up support for -fpatchable-function-entry on ppc32.

Signed-off-by: Naveen N Rao <naveen@kernel.org>
Acked-by: Nick Desaulniers <ndesaulniers@google.com>
Link: llvm/llvm-project#63220
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230609034501.407971-1-naveen@kernel.org
mpe pushed a commit to linuxppc/linux-ci that referenced this issue Jun 15, 2023
Ftrace on ppc32 expects a three instruction sequence at the beginning of
each function when specifying -pg:
	mflr	r0
	stw	r0,4(r1)
	bl	_mcount

This is the case with all supported versions of gcc. Clang however emits
a branch to _mcount after the function prologue, similar to the pre
-mprofile-kernel ABI on ppc64. This is not supported.

Disable ftrace on ppc32 if using clang for now. This can be re-enabled
later if clang picks up support for -fpatchable-function-entry on ppc32.

Signed-off-by: Naveen N Rao <naveen@kernel.org>
Acked-by: Nick Desaulniers <ndesaulniers@google.com>
Link: llvm/llvm-project#63220
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230609034501.407971-1-naveen@kernel.org
mpe pushed a commit to linuxppc/linux that referenced this issue Jun 19, 2023
Ftrace on ppc32 expects a three instruction sequence at the beginning of
each function when specifying -pg:
	mflr	r0
	stw	r0,4(r1)
	bl	_mcount

This is the case with all supported versions of gcc. Clang however emits
a branch to _mcount after the function prologue, similar to the pre
-mprofile-kernel ABI on ppc64. This is not supported.

Disable ftrace on ppc32 if using clang for now. This can be re-enabled
later if clang picks up support for -fpatchable-function-entry on ppc32.

Signed-off-by: Naveen N Rao <naveen@kernel.org>
Acked-by: Nick Desaulniers <ndesaulniers@google.com>
Link: llvm/llvm-project#63220
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230609034501.407971-1-naveen@kernel.org
@chenzheng1030
Copy link
Collaborator

@nickdesaulniers Hi thanks for reporting this issue. Does this issue still matter? If so, maybe I can make a fix.

@chenzheng1030
Copy link
Collaborator

With latest clang, bl _mcount is still after the whole prologue.

@chenzheng1030 chenzheng1030 self-assigned this May 20, 2024
@nickdesaulniers
Copy link
Member Author

Probably. cc @nathanchance who can follow up.

@chenzheng1030
Copy link
Collaborator

On PPC, there is a codegen improvement that moves stw away from its feeder mflr because mflr might have long latency. This will break the expected instructions.

Must these three instructions be in the sequence in the description? What's the relationship between this task and the -fpatchable-function-entry support on ppc32? In https://lore.kernel.org/llvm/20230609034501.407971-1-naveen@kernel.org/, it says "This can be re-enabled
later if clang picks up support for -fpatchable-function-entry on ppc32.", so we can also fix this by supporting -fpatchable-function-entry on ppc32?

@nickdesaulniers @nathanchance

@rnav
Copy link

rnav commented May 21, 2024

Yes, adding support for -fpatchable-function-entry would be the right way to address this. Support for that was introduced in the kernel with the below commit:
https://lore.kernel.org/linuxppc-dev/68586d22981a2c3bb45f27a2b621173d10a7d092.1687166935.git.naveen@kernel.org/

Support for that is being discussed in #57031

chenzheng1030 added a commit to chenzheng1030/llvm-project that referenced this issue May 22, 2024
For now only PPC big endian Linux is supported.
PPC little endian Linux has XRAY support for 64-bit.
PPC AIX has different patchable function entry implementations.

Fixes llvm#63220
Fixes llvm#57031
@chenzheng1030 chenzheng1030 linked a pull request May 22, 2024 that will close this issue
@chenzheng1030
Copy link
Collaborator

#92997 is created for this issue.

chenzheng1030 added a commit to chenzheng1030/llvm-project that referenced this issue May 23, 2024
For now only PPC big endian Linux is supported.
PPC little endian Linux has XRAY support for 64-bit.
PPC AIX has different patchable function entry implementations.

Fixes llvm#63220
Fixes llvm#57031
chenzheng1030 added a commit to chenzheng1030/llvm-project that referenced this issue May 24, 2024
For now only PPC big endian Linux is supported.
PPC little endian Linux has XRAY support for 64-bit.
PPC AIX has different patchable function entry implementations.

Fixes llvm#63220
Fixes llvm#57031
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants