Skip to content

Commit 46514b3

Browse files
committed
scripts/sorttable: Use normal sort if theres no relocs in the mcount section
When ARM 64 is compiled with gcc, the mcount_loc section will be filled with zeros and the addresses will be located in the Elf_Rela sections. To sort the mcount_loc section, the addresses from the Elf_Rela need to be placed into an array and that is sorted. But when ARM 64 is compiled with clang, it does it the same way as other architectures and leaves the addresses as is in the mcount_loc section. To handle both cases, ARM 64 will first try to sort the Elf_Rela section, and if it doesn't find any functions, it will then fall back to the sorting of the addresses in the mcount_loc section itself. 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: Mark Brown <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: b3d09d0 ("arm64: scripts/sorttable: Implement sorting mcount_loc at boot for arm64") Reported-by: "Arnd Bergmann" <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent da0f622 commit 46514b3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

scripts/sorttable.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,14 @@ static void *sort_mcount_loc(void *arg)
827827
pthread_exit(m_err);
828828
}
829829

830-
if (sort_reloc)
830+
if (sort_reloc) {
831831
count = fill_relocs(vals, size, ehdr, emloc->start_mcount_loc);
832-
else
832+
/* gcc may use relocs to save the addresses, but clang does not. */
833+
if (!count) {
834+
count = fill_addrs(vals, size, start_loc);
835+
sort_reloc = 0;
836+
}
837+
} else
833838
count = fill_addrs(vals, size, start_loc);
834839

835840
if (count < 0) {

0 commit comments

Comments
 (0)