ANDROID: recordmcount: avoid STT_FILE as base for mcount offset relocation
This problem was observed with a kernel built using clang and LTO. When the section header index of a section that contains mcount calls coincides with SHN_ABS, recordmcount ends up selecting a STT_FILE symbol as the base for mcount offset relocation. Since the STT_FILE symbol value is 0, it's not a suitable candidate as the base for relocation and results in the __mcount_loc table containing an invalid entry causing kernel oops in ftrace_init(): [ 0.000000] ftrace: allocating 45789 entries in 179 pages [ 0.000000] ------------[ cut here ]------------ [ 0.000000] WARNING: CPU: 0 PID: 0 at arch/arm64/kernel/ftrace.c:172 ftrace_make_nop+0x11c/0x150 [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.4.69-0-1pre+ #1 [ 0.000000] Hardware name: BCM972180HB_V20 (DT) [ 0.000000] pstate: 20400085 (nzCv daIf +PAN -UAO) [ 0.000000] pc : ftrace_make_nop+0x11c/0x150 [ 0.000000] lr : ftrace_make_nop+0x5c/0x150 [ 0.000000] sp : ffffffc011a43ef0 [ 0.000000] x29: ffffffc011a43f00 x28: 0000000000000001 [ 0.000000] x27: ffffff8027801380 x26: 0000000000000000 [ 0.000000] x25: ffffff8027880008 x24: 0000000000000000 [ 0.000000] x23: 0000000000000000 x22: 0000000000000008 [ 0.000000] x21: ffffffc010f5acdc x20: 0000000000000000 [ 0.000000] x19: 0000000000000020 x18: ffffffc011a79020 [ 0.000000] x17: 000000000000003c x16: 0000000000000022 [ 0.000000] x15: dead000000000100 x14: 0000000000000001 [ 0.000000] x13: 0000000000000000 x12: 0000000000000000 [ 0.000000] x11: 0000000000000000 x10: 0000000008000000 [ 0.000000] x9 : 0000000000000002 x8 : 0000000000000001 [ 0.000000] x7 : 0000000000000000 x6 : 000000000000003f [ 0.000000] x5 : 00000000000235b8 x4 : 0000000000000001 [ 0.000000] x3 : 0000000000000001 x2 : ffffffc010f5acdc [ 0.000000] x1 : ffffff8027880000 x0 : 0000000000000001 [ 0.000000] Call trace: [ 0.000000] ftrace_make_nop+0x11c/0x150 [ 0.000000] ftrace_process_locs+0x338/0x3e0 [ 0.000000] ftrace_init+0xac/0xdc [ 0.000000] start_kernel+0x194/0x43c [ 0.000000] random: get_random_bytes called from __warn+0xe0/0x138 with crng_init=0 [ 0.000000] ---[ end trace a8999690c4edae16 ]--- [ 0.000000] ------------[ cut here ]------------ [ 0.000000] WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:2008 ftrace_bug+0x94/0x268 [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Tainted: G W 5.4.69-0-1pre+ #1 [ 0.000000] Hardware name: BCM972180HB_V20 (DT) [ 0.000000] pstate: 60400085 (nZCv daIf +PAN -UAO) [ 0.000000] pc : ftrace_bug+0x94/0x268 [ 0.000000] lr : ftrace_process_locs+0x364/0x3e0 [ 0.000000] sp : ffffffc011a43ef0 [ 0.000000] x29: ffffffc011a43ef0 x28: 0000000000000001 [ 0.000000] x27: ffffff8027801380 x26: 0000000000000000 [ 0.000000] x25: ffffff8027880008 x24: 0000000000000000 [ 0.000000] x23: 0000000000000000 x22: 0000000000000008 [ 0.000000] x21: ffffffc010f5acdc x20: 0000000000000020 [ 0.000000] x19: ffffff8027880000 x18: ffffffc011a79020 [ 0.000000] x17: 000000000000003c x16: 0000000000000022 [ 0.000000] x15: dead000000000100 x14: 0000000000000001 [ 0.000000] x13: 0000000000000000 x12: ffffffc010f5ed94 [ 0.000000] x11: ffffffc011a4f000 x10: ffffffc011a4f000 [ 0.000000] x9 : 0000000000000001 x8 : ffffffc011a4f000 [ 0.000000] x7 : 0000000000000000 x6 : 000000000000003f [ 0.000000] x5 : 00000000000235b8 x4 : 0000000000000001 [ 0.000000] x3 : 0000000000000001 x2 : ffffffc010f5acdc [ 0.000000] x1 : ffffff8027880000 x0 : ffffffc01151ade2 [ 0.000000] Call trace: [ 0.000000] ftrace_bug+0x94/0x268 [ 0.000000] ftrace_process_locs+0x364/0x3e0 [ 0.000000] ftrace_init+0xac/0xdc [ 0.000000] start_kernel+0x194/0x43c [ 0.000000] ---[ end trace a8999690c4edae17 ]--- [ 0.000000] ftrace failed to modify [ 0.000000] [<0000000000000020>] 0x20 [ 0.000000] actual: [ 0.000000] Unable to handle kernel read from unreadable memory at virtual address 0000000000000020 [ 0.000000] Mem abort info: [ 0.000000] ESR = 0x96000005 [ 0.000000] EC = 0x25: DABT (current EL), IL = 32 bits [ 0.000000] SET = 0, FnV = 0 [ 0.000000] EA = 0, S1PTW = 0 [ 0.000000] Data abort info: [ 0.000000] ISV = 0, ISS = 0x00000005 [ 0.000000] CM = 0, WnR = 0 [ 0.000000] [0000000000000020] user address but active_mm is swapper [ 0.000000] Internal error: Oops: 96000005 [#1] PREEMPT SMP [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Tainted: G W 5.4.69-0-1pre+ #1 [ 0.000000] Hardware name: BCM972180HB_V20 (DT) [ 0.000000] pstate: 60400085 (nZCv daIf +PAN -UAO) [ 0.000000] pc : print_ip_ins+0x48/0x80 [ 0.000000] lr : print_ip_ins+0x2c/0x80 [ 0.000000] sp : ffffffc011a43eb0 [ 0.000000] x29: ffffffc011a43eb0 x28: 0000000000000001 [ 0.000000] x27: ffffff8027801380 x26: 0000000000000000 [ 0.000000] x25: ffffff8027880008 x24: 0000000000000000 [ 0.000000] x23: ffffffc0115f1abc x22: ffffffc01160e929 [ 0.000000] x21: 0000000000000000 x20: ffffffc011577a9c [ 0.000000] x19: 0000000000000020 x18: ffffffc011a79028 [ 0.000000] x17: 000000000000002c x16: ffffffc010f33fec [ 0.000000] x15: 0000000000000004 x14: ffff0000ffffff00 [ 0.000000] x13: 0000000000000000 x12: 0000000000000000 [ 0.000000] x11: 0000000000000000 x10: 00000000ffffffff [ 0.000000] x9 : 0000000000000000 x8 : 0000000000000000 [ 0.000000] x7 : 3030303030303030 x6 : ffffffc011c031a3 [ 0.000000] x5 : 000000000000000b x4 : ffffffc011c00866 [ 0.000000] x3 : 0000000000000020 x2 : 000000000000000b [ 0.000000] x1 : ffffffc011c00871 x0 : 000000000000000b [ 0.000000] Call trace: [ 0.000000] print_ip_ins+0x48/0x80 [ 0.000000] ftrace_bug+0xcc/0x268 [ 0.000000] ftrace_process_locs+0x364/0x3e0 [ 0.000000] ftrace_init+0xac/0xdc [ 0.000000] start_kernel+0x194/0x43c [ 0.000000] Code: aa1f03f5 9124a6d6 912af2f7 912a7294 (38756a62) [ 0.000000] ---[ end trace a8999690c4edae18 ]--- [ 0.000000] Kernel panic - not syncing: Attempted to kill the idle task! This can be fixed by avoiding STT_FILE symbols as the base for mcount offset relocation. Bug: 168835511 Signed-off-by: Danesh Petigara <danesh.petigara@broadcom.com> Signed-off-by: Pierre Couillaud <pierre@broadcom.com> Change-Id: I9e73706d5104bfa81bccd091e956660364f294de
This commit is contained in:
parent
3f0fb2fde0
commit
2f397d4f68
@ -529,6 +529,9 @@ static int find_secsym_ndx(unsigned const txtndx,
|
||||
if (txtndx == get_symindex(symp, symtab, symtab_shndx)
|
||||
/* avoid STB_WEAK */
|
||||
&& (STB_LOCAL == st_bind || STB_GLOBAL == st_bind)) {
|
||||
/* avoid file symbols */
|
||||
if (ELF_ST_TYPE(symp->st_info) == STT_FILE)
|
||||
continue;
|
||||
/* function symbols on ARM have quirks, avoid them */
|
||||
if (w2(ehdr->e_machine) == EM_ARM
|
||||
&& ELF_ST_TYPE(symp->st_info) == STT_FUNC)
|
||||
|
Loading…
Reference in New Issue
Block a user