]> www.infradead.org Git - users/willy/xarray.git/commitdiff
selftests/powerpc: Allow building without static libc
authorMadhavan Srinivasan <maddy@linux.ibm.com>
Mon, 12 Aug 2024 09:41:52 +0000 (15:11 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 9 Sep 2024 06:35:04 +0000 (16:35 +1000)
Currently exec-target.c is linked statically with libc, which on Fedora
at least requires installing an additional package (glibc-static).

If that package is not installed the build fails with:

    CC       exec_target
  /usr/bin/ld: cannot find -lc: No such file or directory
  collect2: error: ld returned 1 exit status

All exec_target.c does is call sys_exit, which can be done easily enough
using inline assembly, and removes the requirement for a static libc to
be installed.

Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240812094152.418586-1-maddy@linux.ibm.com
tools/testing/selftests/powerpc/benchmarks/Makefile
tools/testing/selftests/powerpc/benchmarks/exec_target.c

index 1321922038d0fe651681c1ca8b41aad92515b6dd..ca4483c238b9fe233736cfc02b443614dbbe455a 100644 (file)
@@ -18,4 +18,4 @@ $(OUTPUT)/context_switch: LDLIBS += -lpthread
 
 $(OUTPUT)/fork: LDLIBS += -lpthread
 
-$(OUTPUT)/exec_target: CFLAGS += -static -nostartfiles
+$(OUTPUT)/exec_target: CFLAGS += -nostartfiles
index c14b0fc1edde0ab67bebd1f63ecff99849b23ba1..a6408d3f26cdde10c7f2d551772028541d6efee4 100644 (file)
@@ -7,10 +7,22 @@
  */
 
 #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)
+               /*
+                * "sc" will clobber r0, r3-r13, cr0, ctr, xer and memory.
+                * Even though sys_exit never returns, handle clobber
+                * registers.
+                */
+               : "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
+                 "r11", "r12", "r13", "cr0", "ctr", "xer", "memory"
+       );
 }