scripts/sorttable: Fix endianness handling in build-time mcount sort
PATCH 1/1 scripts/sorttable: Fix endianness handling in build-time mcount sort
Kernel cross-compilation with BUILDTIME_MCOUNT_SORT produces zeroed mcount values if the build-host endianness does not match the ELF file endianness.
The mcount values array is converted from ELF file
endianness to build-host endianness during initialization in fill_relocs()/fill_addrs(). Avoid extra conversion of these values during weak-function zeroing; otherwise, they do not match nm-parsed addresses and all mcount values are zeroed out.
--- scripts/sorttable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/sorttable.c +1 -1
@@ -857,7 +857,7 @@ static void *sort_mcount_loc(void *arg)for (void *ptr = vals; ptr < vals + size; ptr += long_size) {uint64_t key; - key = long_size ==4 ?r ((uint32_t *)ptr) :r8 ((uint64_t *)ptr); + key = long_size ==4 ? *(uint32_t *)ptr : *(uint64_t *)ptr;if (!find_func (key)) {if (long_size ==4 ) *(uint32_t *)ptr =0 ;
Signature · 1 line
2.48.1
Quoted 24 lines · Vasily Gorbik
Kernel cross-compilation with
BUILDTIME_MCOUNT_SORTproduces zeroed mcount values if the build-host endianness does not match the ELF file endianness.The mcount values array is converted from ELF file
endianness to build-host endianness during initialization in fill_relocs()/fill_addrs(). Avoid extra conversion of these values during weak-function zeroing; otherwise, they do not match nm-parsed addresses and all mcount values are zeroed out.Fixes ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")Reported-by Ilya Leoshkevich <[email protected]>Reported-by Ihor Solodrai <[email protected]>Signed-off-by Vasily Gorbik <[email protected]>--- scripts/sorttable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/sorttable.c +0
-0
scripts/sorttable.c static void *sort_mcount_loc(void *arg) · line 863
Quoted 8 lines
scripts/sorttable.c +1
-1@@ -857,7 +857,7 @@ static void *sort_mcount_loc(void *arg)for (void *ptr = vals; ptr < vals + size; ptr += long_size) {uint64_t key; - key = long_size ==4 ?r ((uint32_t *)ptr) :r8 ((uint64_t *)ptr); + key = long_size ==4 ? *(uint32_t *)ptr : *(uint64_t *)ptr;if (!find_func (key)) {if (long_size ==4 ) *(uint32_t *)ptr =0 ;
Hi Vasily,
I can confirm that this patch fixes BPF selftests on s390x:
https://github.com/kernel-patches/vmtest/actions/runs/14231181710
Thank you!
Quoted 6 lines · On Wed, 02 Apr 2025 23:22:40 +0000 "Ihor Solodrai" <[email protected]>…
Hi Vasily,
I can confirm that this patch fixes BPF selftests on s390x:
https://github.com/kernel-patches/vmtest/actions/runs/14231181710Tested-by Ihor Solodrai <[email protected]>
Thanks, but I already submitted a pull request that includes this fix, as it looked pretty obvious (I did run it through all my normal tests, but just didn't test the big/little endian case).
https://lore.kernel.org/all/[email protected]/
-- Steve
Ihor Solodrai
reviewerQuoted 8 lines · Steven Rostedt
Quoted 5 lines · On Wed, 02 Apr 2025 23:22:40 +0000 "Ihor Solodrai" <[email protected]>…
Hi Vasily,
I can confirm that this patch fixes BPF selftests on s390x:
https://github.com/kernel-patches/vmtest/actions/runs/14231181710
Quoted 7 lines
Quoted 1 line
Tested-by Ihor Solodrai <[email protected]>Thanks, but I already submitted a pull request that includes this fix, as it looked pretty obvious (I did run it through all my normal tests, but just didn't test the big/little endian case).
Sure, that's fine. I had to test it anyway, so that a revert fa1518875286 patch could be removed from CI. Just sharing a data point.
Thank you.
Quoted 2 lines
-- Steve