What are the consequences of changing a symbol from .globl to .weak?

After spending some time on the previous question , the user introduced me to the email regarding the problem below:

[PATCH] ftrace / x86: Fix function graph tracer reset path

On my system, just turning the graphical tracer feature on and off is a kernel crash. I donโ€™t know how it works so far.

ftrace_disable_ftrace_graph_caller() changes the jmp instruction to ftrace_graph_call , assuming it is 5 bytes around jmp (e9). However, this is a short jmp consisting of only 2 bytes (eb). And ftrace_stub() is located just below ftrace_graph_caller , so above it violates the instruction leading to ftrace_stub() with an invalid operation code, as shown below:

One solution to this problem is the following patch:

  diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S index ed48a9f465f8..e13a695c3084 100644 --- a/arch/x86/kernel/mcount_64.S +++ b/arch/x86/kernel/mcount_64.S @@ -182,7 +182,8 @@ GLOBAL(ftrace_graph_call) jmp ftrace_stub #endif -GLOBAL(ftrace_stub) +/* This is weak to keep gas from relaxing the jumps */ +WEAK(ftrace_stub) retq END(ftrace_caller) 

via https://lkml.org/lkml/2016/5/16/493

I do not understand that the effect is to replace GLOBAL(ftrace_stub) with WEAK(ftrace_stub) . Neither the comment included in the patch, nor the view of GLOBAL () and WEAK () helped me understand why this solution works.

My question, as the name suggests, is this: What are the consequences of changing a symbol from .globl to .weak? I would appreciate an answer that takes into account how replacing GLOBAL(ftrace_stub) with WEAK(ftrace_stub) can solve this problem.

+7
c assembly x86 linux linux-kernel
source share
1 answer

Since ftrace_stub defined in the current file, the assembler knows the distance and can use a shorter version of jmp , which has a limited range.

If it changes to weak , this means that the character cannot be resolved to the one that is in the current file, since another module can override it. An offset to this potential redefinition is unknown, so the assembler must use the full jmp range that the patch code expects.

+6
source share

All Articles