[PATCH] selftest/powerpc/benchmark: remove requirement libc-dev

Michael Ellerman mpe at ellerman.id.au
Mon Aug 12 10:21:19 AEST 2024


Christophe Leroy <christophe.leroy at csgroup.eu> writes:
> Le 05/08/2024 à 10:30, Madhavan Srinivasan a écrit :
>> Currently exec-target.c file is linked as static and this
>> post a requirement to install libc dev package to build.
>> Without it, build-breaks when compiling selftest/powerpc/benchmark.
>> 
>>    CC       exec_target
>> /usr/bin/ld: cannot find -lc: No such file or directory
>> collect2: error: ld returned 1 exit status
>> 
>> exec_target.c is using "syscall" library function which
>> could be replaced with a inline assembly and the same is
>> proposed as a fix here.
>> 
>> Suggested-by: Michael Ellerman <mpe at ellerman.id.au>
>> Signed-off-by: Madhavan Srinivasan <maddy at linux.ibm.com>
>> ---
>>   tools/testing/selftests/powerpc/benchmarks/Makefile    |  2 +-
>>   .../testing/selftests/powerpc/benchmarks/exec_target.c | 10 ++++++++--
>>   2 files changed, 9 insertions(+), 3 deletions(-)
>> 
>> diff --git a/tools/testing/selftests/powerpc/benchmarks/exec_target.c b/tools/testing/selftests/powerpc/benchmarks/exec_target.c
>> index c14b0fc1edde..20027a23b594 100644
>> --- a/tools/testing/selftests/powerpc/benchmarks/exec_target.c
>> +++ b/tools/testing/selftests/powerpc/benchmarks/exec_target.c
>> @@ -7,10 +7,16 @@
>>    */
>>   
>>   #define _GNU_SOURCE
>> -#include <unistd.h>
>>   #include <sys/syscall.h>
>>   
>>   void _start(void)
>>   {
>> -	syscall(SYS_exit, 0);
>> +	asm volatile (
>> +		"li %%r0, %[sys_exit];"
>> +		"li %%r3, 0;"
>> +		"sc;"
>> +		:
>> +		: [sys_exit] "i" (SYS_exit)
>> +		: "r0", "r3"
>> +	);
>
> That looks ok because SYS_exit() is not supposed to return, but in the 
> general case you should take a lot more precautions regarding which 
> registers get clobbered when using sc.

That's my fault for just blurting out that diff on slack without
thinking about it too hard.

We should probably just add the proper clobbers, in case anyone copies
it in future. Which should be:

	asm volatile (
		"li %%r0, %[sys_exit];"
		"li %%r3, 0;"
		"sc;"
		:
		: [sys_exit] "i" (SYS_exit)
		: "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
		  "r11", "r12", "r13", "cr0", "ctr", "xer", "memory"
	);

cheers


More information about the Linuxppc-dev mailing list