Skip to content

Commit 562e14f

Browse files
committed
ftrace/x86: Remove mcount support
There's two methods of enabling function tracing in Linux on x86. One is with just "gcc -pg" and the other is "gcc -pg -mfentry". The former will use calls to a special function "mcount" after the frame is set up in all C functions. The latter will add calls to a special function called "fentry" as the very first instruction of all C functions. At compile time, there is a check to see if gcc supports, -mfentry, and if it does, it will use that, because it is more versatile and less error prone for function tracing. Starting with v4.19, the minimum gcc supported to build the Linux kernel, was raised to version 4.6. That also happens to be the first gcc version to support -mfentry. Since on x86, using gcc versions from 4.6 and beyond will unconditionally enable the -mfentry, it will no longer use mcount as the method for inserting calls into the C functions of the kernel. This means that there is no point in continuing to maintain mcount in x86. Remove support for using mcount. This makes the code less complex, and will also allow it to be simplified in the future. Acked-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Jiri Kosina <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 518049d commit 562e14f

File tree

4 files changed

+9
-66
lines changed

4 files changed

+9
-66
lines changed

arch/x86/include/asm/ftrace.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
#define _ASM_X86_FTRACE_H
44

55
#ifdef CONFIG_FUNCTION_TRACER
6-
#ifdef CC_USING_FENTRY
7-
# define MCOUNT_ADDR ((unsigned long)(__fentry__))
8-
#else
9-
# define MCOUNT_ADDR ((unsigned long)(mcount))
10-
# define HAVE_FUNCTION_GRAPH_FP_TEST
6+
#ifndef CC_USING_FENTRY
7+
# error Compiler does not support fentry?
118
#endif
9+
# define MCOUNT_ADDR ((unsigned long)(__fentry__))
1210
#define MCOUNT_INSN_SIZE 5 /* sizeof mcount call */
1311

1412
#ifdef CONFIG_DYNAMIC_FTRACE

arch/x86/include/asm/livepatch.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626

2727
static inline int klp_check_compiler_support(void)
2828
{
29-
#ifndef CC_USING_FENTRY
30-
return 1;
31-
#endif
3229
return 0;
3330
}
3431

arch/x86/kernel/ftrace_32.S

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,10 @@
1010
#include <asm/ftrace.h>
1111
#include <asm/nospec-branch.h>
1212

13-
#ifdef CC_USING_FENTRY
1413
# define function_hook __fentry__
1514
EXPORT_SYMBOL(__fentry__)
16-
#else
17-
# define function_hook mcount
18-
EXPORT_SYMBOL(mcount)
19-
#endif
20-
21-
/* mcount uses a frame pointer even if CONFIG_FRAME_POINTER is not set */
22-
#if !defined(CC_USING_FENTRY) || defined(CONFIG_FRAME_POINTER)
23-
# define USING_FRAME_POINTER
24-
#endif
2515

26-
#ifdef USING_FRAME_POINTER
16+
#ifdef CONFIG_FRAME_POINTER
2717
# define MCOUNT_FRAME 1 /* using frame = true */
2818
#else
2919
# define MCOUNT_FRAME 0 /* using frame = false */
@@ -35,8 +25,7 @@ END(function_hook)
3525

3626
ENTRY(ftrace_caller)
3727

38-
#ifdef USING_FRAME_POINTER
39-
# ifdef CC_USING_FENTRY
28+
#ifdef CONFIG_FRAME_POINTER
4029
/*
4130
* Frame pointers are of ip followed by bp.
4231
* Since fentry is an immediate jump, we are left with
@@ -47,7 +36,7 @@ ENTRY(ftrace_caller)
4736
pushl %ebp
4837
movl %esp, %ebp
4938
pushl 2*4(%esp) /* function ip */
50-
# endif
39+
5140
/* For mcount, the function ip is directly above */
5241
pushl %ebp
5342
movl %esp, %ebp
@@ -57,7 +46,7 @@ ENTRY(ftrace_caller)
5746
pushl %edx
5847
pushl $0 /* Pass NULL as regs pointer */
5948

60-
#ifdef USING_FRAME_POINTER
49+
#ifdef CONFIG_FRAME_POINTER
6150
/* Load parent ebp into edx */
6251
movl 4*4(%esp), %edx
6352
#else
@@ -80,13 +69,11 @@ ftrace_call:
8069
popl %edx
8170
popl %ecx
8271
popl %eax
83-
#ifdef USING_FRAME_POINTER
72+
#ifdef CONFIG_FRAME_POINTER
8473
popl %ebp
85-
# ifdef CC_USING_FENTRY
8674
addl $4,%esp /* skip function ip */
8775
popl %ebp /* this is the orig bp */
8876
addl $4, %esp /* skip parent ip */
89-
# endif
9077
#endif
9178
.Lftrace_ret:
9279
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
@@ -131,11 +118,7 @@ ENTRY(ftrace_regs_caller)
131118

132119
movl 12*4(%esp), %eax /* Load ip (1st parameter) */
133120
subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
134-
#ifdef CC_USING_FENTRY
135121
movl 15*4(%esp), %edx /* Load parent ip (2nd parameter) */
136-
#else
137-
movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
138-
#endif
139122
movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
140123
pushl %esp /* Save pt_regs as 4th parameter */
141124

@@ -176,13 +159,8 @@ ENTRY(ftrace_graph_caller)
176159
pushl %edx
177160
movl 3*4(%esp), %eax
178161
/* Even with frame pointers, fentry doesn't have one here */
179-
#ifdef CC_USING_FENTRY
180162
lea 4*4(%esp), %edx
181163
movl $0, %ecx
182-
#else
183-
lea 0x4(%ebp), %edx
184-
movl (%ebp), %ecx
185-
#endif
186164
subl $MCOUNT_INSN_SIZE, %eax
187165
call prepare_ftrace_return
188166
popl %edx
@@ -195,11 +173,7 @@ END(ftrace_graph_caller)
195173
return_to_handler:
196174
pushl %eax
197175
pushl %edx
198-
#ifdef CC_USING_FENTRY
199176
movl $0, %eax
200-
#else
201-
movl %ebp, %eax
202-
#endif
203177
call ftrace_return_to_handler
204178
movl %eax, %ecx
205179
popl %edx

arch/x86/kernel/ftrace_64.S

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,12 @@
1313
.code64
1414
.section .entry.text, "ax"
1515

16-
#ifdef CC_USING_FENTRY
1716
# define function_hook __fentry__
1817
EXPORT_SYMBOL(__fentry__)
19-
#else
20-
# define function_hook mcount
21-
EXPORT_SYMBOL(mcount)
22-
#endif
2318

2419
#ifdef CONFIG_FRAME_POINTER
25-
# ifdef CC_USING_FENTRY
2620
/* Save parent and function stack frames (rip and rbp) */
2721
# define MCOUNT_FRAME_SIZE (8+16*2)
28-
# else
29-
/* Save just function stack frame (rip and rbp) */
30-
# define MCOUNT_FRAME_SIZE (8+16)
31-
# endif
3222
#else
3323
/* No need to save a stack frame */
3424
# define MCOUNT_FRAME_SIZE 0
@@ -75,17 +65,13 @@ EXPORT_SYMBOL(mcount)
7565
* fentry is called before the stack frame is set up, where as mcount
7666
* is called afterward.
7767
*/
78-
#ifdef CC_USING_FENTRY
68+
7969
/* Save the parent pointer (skip orig rbp and our return address) */
8070
pushq \added+8*2(%rsp)
8171
pushq %rbp
8272
movq %rsp, %rbp
8373
/* Save the return address (now skip orig rbp, rbp and parent) */
8474
pushq \added+8*3(%rsp)
85-
#else
86-
/* Can't assume that rip is before this (unless added was zero) */
87-
pushq \added+8(%rsp)
88-
#endif
8975
pushq %rbp
9076
movq %rsp, %rbp
9177
#endif /* CONFIG_FRAME_POINTER */
@@ -113,12 +99,7 @@ EXPORT_SYMBOL(mcount)
11399
movq %rdx, RBP(%rsp)
114100

115101
/* Copy the parent address into %rsi (second parameter) */
116-
#ifdef CC_USING_FENTRY
117102
movq MCOUNT_REG_SIZE+8+\added(%rsp), %rsi
118-
#else
119-
/* %rdx contains original %rbp */
120-
movq 8(%rdx), %rsi
121-
#endif
122103

123104
/* Move RIP to its proper location */
124105
movq MCOUNT_REG_SIZE+\added(%rsp), %rdi
@@ -303,15 +284,8 @@ ENTRY(ftrace_graph_caller)
303284
/* Saves rbp into %rdx and fills first parameter */
304285
save_mcount_regs
305286

306-
#ifdef CC_USING_FENTRY
307287
leaq MCOUNT_REG_SIZE+8(%rsp), %rsi
308288
movq $0, %rdx /* No framepointers needed */
309-
#else
310-
/* Save address of the return address of traced function */
311-
leaq 8(%rdx), %rsi
312-
/* ftrace does sanity checks against frame pointers */
313-
movq (%rdx), %rdx
314-
#endif
315289
call prepare_ftrace_return
316290

317291
restore_mcount_regs

0 commit comments

Comments
 (0)