Skip to contentSkip to conversation

scripts/sorttable: Fix endianness handling in build-time mcount sort

PATCH In review Vasily Gorbik 3 participants 4 messages Apr 2, 2025 BPF

lore
Share & tools
lore
#0 lore raw

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.

Fixes ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")
---
 scripts/sorttable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/sorttable.c +1 -1
index 7b4b3714b1af..deed676bfe38 100644
@@ -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
reviewer Tested-by on v1 1/1
#1 lore raw
Quoted 24 lines · Vasily Gorbik

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.

Fixes ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")
---
 scripts/sorttable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/sorttable.c +0 -0
index 7b4b3714b1af..deed676bfe38 100644

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!

#2 lore raw
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/14231181710

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

reviewer
#3 lore raw
Quoted 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

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]/

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