linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: Christophe Leroy <christophe.leroy@csgroup.eu>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	npiggin@gmail.com, shuah@kernel.org
Cc: linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] selftest/powerpc/benchmark: remove requirement libc-dev
Date: Mon, 12 Aug 2024 10:21:19 +1000	[thread overview]
Message-ID: <87seva8ubk.fsf@mail.lhotse> (raw)
In-Reply-To: <f4ae0d9e-5d1f-4b5e-92b9-aabb513e3097@csgroup.eu>

Christophe Leroy <christophe.leroy@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@ellerman.id.au>
>> Signed-off-by: Madhavan Srinivasan <maddy@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

      parent reply	other threads:[~2024-08-12  0:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-05  8:30 [PATCH] selftest/powerpc/benchmark: remove requirement libc-dev Madhavan Srinivasan
2024-08-06  6:54 ` Christophe Leroy
2024-08-09  4:25   ` Madhavan Srinivasan
2024-08-09  4:54     ` Christophe Leroy
2024-08-09  5:32       ` Madhavan Srinivasan
2024-08-12  0:21   ` Michael Ellerman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87seva8ubk.fsf@mail.lhotse \
    --to=mpe@ellerman.id.au \
    --cc=christophe.leroy@csgroup.eu \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).