Skip to content

Commit

Permalink
recordmcount: arm64: Replace the ignored mcount call into nop
Browse files Browse the repository at this point in the history
By now, the recordmcount only records the function that in
following sections:
.text/.ref.text/.sched.text/.spinlock.text/.irqentry.text/
.kprobes.text/.text.unlikely

For the function that not in these sections, the call mcount
will be in place and not be replaced when kernel boot up. And
it will bring performance overhead, such as do_mem_abort (in
.exception.text section). This patch make the call mcount to
nop for this case in recordmcount.

Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]

Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]> # 3.18+
Acked-by: Will Deacon <[email protected]>
Signed-off-by: Li Bin <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
libin2015 authored and rostedt committed Nov 3, 2015
1 parent c84da8b commit 2ee8a74
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion scripts/recordmcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#ifndef EM_AARCH64
#define EM_AARCH64 183
#define R_AARCH64_NONE 0
#define R_AARCH64_ABS64 257
#endif

Expand Down Expand Up @@ -160,6 +161,22 @@ static int make_nop_x86(void *map, size_t const offset)
return 0;
}

static unsigned char ideal_nop4_arm64[4] = {0x1f, 0x20, 0x03, 0xd5};
static int make_nop_arm64(void *map, size_t const offset)
{
uint32_t *ptr;

ptr = map + offset;
/* bl <_mcount> is 0x94000000 before relocation */
if (*ptr != 0x94000000)
return -1;

/* Convert to nop */
ulseek(fd_map, offset, SEEK_SET);
uwrite(fd_map, ideal_nop, 4);
return 0;
}

/*
* Get the whole file as a programming convenience in order to avoid
* malloc+lseek+read+free of many pieces. If successful, then mmap
Expand Down Expand Up @@ -354,7 +371,12 @@ do_file(char const *const fname)
altmcount = "__gnu_mcount_nc";
break;
case EM_AARCH64:
reltype = R_AARCH64_ABS64; gpfx = '_'; break;
reltype = R_AARCH64_ABS64;
make_nop = make_nop_arm64;
rel_type_nop = R_AARCH64_NONE;
ideal_nop = ideal_nop4_arm64;
gpfx = '_';
break;
case EM_IA_64: reltype = R_IA64_IMM64; gpfx = '_'; break;
case EM_METAG: reltype = R_METAG_ADDR32;
altmcount = "_mcount_wrapper";
Expand Down

0 comments on commit 2ee8a74

Please sign in to comment.