Skip to content

Commit ea0eada

Browse files
herrerogctmarinas
authored andcommitted
recordmcount: only record relocation of type R_AARCH64_CALL26 on arm64.
Currently, if a section has a relocation to '_mcount' symbol, a new __mcount_loc entry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use. Such relocation could be generated with below code for example: bool is_mcount(unsigned long addr) { return (target == (unsigned long) &_mcount); } With this snippet of code, ftrace will try to patch the mcount location generated by this code on module load and fail with: Call trace: ftrace_bug+0xa0/0x28c ftrace_process_locs+0x2f4/0x430 ftrace_module_init+0x30/0x38 load_module+0x14f0/0x1e78 __do_sys_finit_module+0x100/0x11c __arm64_sys_finit_module+0x28/0x34 el0_svc_common+0x88/0x194 el0_svc_handler+0x38/0x8c el0_svc+0x8/0xc ---[ end trace d828d06b36ad9d59 ]--- ftrace failed to modify [<ffffa2dbf3a3a41c>] 0xffffa2dbf3a3a41c actual: 66:a9:3c:90 Initializing ftrace call sites ftrace record flags: 2000000 (0) expected tramp: ffffa2dc6cf66724 So Limit the relocation type to R_AARCH64_CALL26 as in perl version of recordmcount. Fixes: af64d2a ("ftrace: Add arm64 support to recordmcount") Signed-off-by: Gregory Herrero <[email protected]> Acked-by: Steven Rostedt (VMware) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent a46cec1 commit ea0eada

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

scripts/recordmcount.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)
434434
return 1;
435435
}
436436

437+
static int arm64_is_fake_mcount(Elf64_Rel const *rp)
438+
{
439+
return ELF64_R_TYPE(w(rp->r_info)) != R_AARCH64_CALL26;
440+
}
441+
437442
/* 64-bit EM_MIPS has weird ELF64_Rela.r_info.
438443
* http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf
439444
* We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40]
@@ -547,6 +552,7 @@ static int do_file(char const *const fname)
547552
make_nop = make_nop_arm64;
548553
rel_type_nop = R_AARCH64_NONE;
549554
ideal_nop = ideal_nop4_arm64;
555+
is_fake_mcount64 = arm64_is_fake_mcount;
550556
break;
551557
case EM_IA_64: reltype = R_IA64_IMM64; break;
552558
case EM_MIPS: /* reltype: e_class */ break;

0 commit comments

Comments
 (0)