[RFC][PATCH 1/6] x86: Annotate _THIS_IP_

From: Peter Zijlstra
Date: Mon Nov 22 2021 - 12:14:16 EST


In order to find _THIS_IP_ code references in objtool, annotate them.

Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
arch/x86/include/asm/linkage.h | 11 +++++++++++
include/linux/instruction_pointer.h | 5 +++++
2 files changed, 16 insertions(+)

--- a/arch/x86/include/asm/linkage.h
+++ b/arch/x86/include/asm/linkage.h
@@ -3,10 +3,21 @@
#define _ASM_X86_LINKAGE_H

#include <linux/stringify.h>
+#include <asm/asm.h>

#undef notrace
#define notrace __attribute__((no_instrument_function))

+#define _THIS_IP_ \
+ ({ __label__ __here; \
+ __here: \
+ asm_volatile_goto ( \
+ ".pushsection .discard.this_ip\n\t" \
+ _ASM_PTR " %l[__here]\n\t" \
+ ".popsection\n\t" \
+ : : : : __here); \
+ (unsigned long)&&__here; })
+
#ifdef CONFIG_X86_32
#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
#endif /* CONFIG_X86_32 */
--- a/include/linux/instruction_pointer.h
+++ b/include/linux/instruction_pointer.h
@@ -2,7 +2,12 @@
#ifndef _LINUX_INSTRUCTION_POINTER_H
#define _LINUX_INSTRUCTION_POINTER_H

+#include <asm/linkage.h>
+
#define _RET_IP_ (unsigned long)__builtin_return_address(0)
+
+#ifndef _THIS_IP_
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
+#endif

#endif /* _LINUX_INSTRUCTION_POINTER_H */