sorttable hardcodes before_func to 8 bytes on arm64 (two prefix NOPs).
Make it configurable from CONFIG_ARM64_FUNCTION_PREFIX_NOPS instead.
kCFI kernels with CALL_OPS need three NOPs. The symbol does not exist
yet, so no functional change.

Reviewed-by: Ben Cressey <[email protected]>
Reviewed-by: Florent Revest (Anthropic) <[email protected]>
Assisted-by: LLM
Signed-off-by: Jose Fernandez (Anthropic) <[email protected]>
---
 scripts/Makefile    | 3 +++
 scripts/sorttable.c | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/scripts/Makefile b/scripts/Makefile
index 3434a82a119f0..366c6a35141a6 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -51,6 +51,9 @@ endif
 
 ifdef CONFIG_BUILDTIME_MCOUNT_SORT
 HOSTCFLAGS_sorttable.o += -DMCOUNT_SORT_ENABLED
+ifneq ($(filter-out 0,$(CONFIG_ARM64_FUNCTION_PREFIX_NOPS)),)
+HOSTCFLAGS_sorttable.o += -DFUNCTION_PREFIX_BYTES=$(shell expr 4 \* 
$(CONFIG_ARM64_FUNCTION_PREFIX_NOPS))
+endif
 endif
 
 # The following programs are only built on demand
diff --git a/scripts/sorttable.c b/scripts/sorttable.c
index d8dc2a1b7c312..925382bb23dcc 100644
--- a/scripts/sorttable.c
+++ b/scripts/sorttable.c
@@ -281,6 +281,11 @@ static int add_field(uint64_t addr, uint64_t size)
 /* Used for when mcount/fentry is before the function entry */
 static int before_func;
 
+/* How far before the function entry a patchable entry may be recorded */
+#ifndef FUNCTION_PREFIX_BYTES
+#define FUNCTION_PREFIX_BYTES  8
+#endif
+
 /* Only return match if the address lies inside the function size */
 static int cmp_func_addr(const void *K, const void *A)
 {
@@ -899,7 +904,7 @@ static int do_file(char const *const fname, void *addr)
                /* fallthrough */
        case EM_RISCV:
                /* arm64 and RISC-V place patchable entries before the 
function. */
-               before_func = 8;
+               before_func = FUNCTION_PREFIX_BYTES;
 #else
        case EM_AARCH64:
        case EM_RISCV:

-- 
2.52.0


Reply via email to