Skip to content

Commit dc208c6

Browse files
committed
scripts/sorttable: Allow matches to functions before function entry
ARM 64 uses -fpatchable-function-entry=4,2 which adds padding before the function and the addresses in the mcount_loc point there instead of the function entry that is returned by nm. In order to find a function from nm to make sure it's not an unused weak function, the entries in the mcount_loc section needs to match the entries from nm. Since it can be an instruction before the entry, add a before_func variable that ARM 64 can set to 8, and if the mcount_loc entry is within 8 bytes of the nm function entry, then it will be considered a match. Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: "Arnd Bergmann" <[email protected]> Cc: Mark Brown <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: ef378c3 ("scripts/sorttable: Zero out weak functions in mcount_loc table") Tested-by: Nathan Chancellor <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 46514b3 commit dc208c6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

scripts/sorttable.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,16 @@ static int add_field(uint64_t addr, uint64_t size)
611611
return 0;
612612
}
613613

614+
/* Used for when mcount/fentry is before the function entry */
615+
static int before_func;
616+
614617
/* Only return match if the address lies inside the function size */
615618
static int cmp_func_addr(const void *K, const void *A)
616619
{
617620
uint64_t key = *(const uint64_t *)K;
618621
const struct func_info *a = A;
619622

620-
if (key < a->addr)
623+
if (key + before_func < a->addr)
621624
return -1;
622625
return key >= a->addr + a->size;
623626
}
@@ -1253,6 +1256,8 @@ static int do_file(char const *const fname, void *addr)
12531256
#ifdef MCOUNT_SORT_ENABLED
12541257
sort_reloc = true;
12551258
rela_type = 0x403;
1259+
/* arm64 uses patchable function entry placing before function */
1260+
before_func = 8;
12561261
#endif
12571262
/* fallthrough */
12581263
case EM_386:

0 commit comments

Comments
 (0)