History

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.

Steven Rostedt committed 1 year ago

Commit dc208c61 parent 46514b31 file · +6 −1Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/sorttable.c+6−1
@@ -611,13 +611,16 @@ static int add_field(uint64_t addr, uint64_t size) · 610 unmodified lines
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) · 629 unmodified lines
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: