[PATCH/submitted,3/5] sim: ppc: change SysV sem & shm tests to compile-time

Message ID 20240102053026.20425-3-vapier@gentoo.org
State New
Headers
Series [PATCH/submitted,1/5] sim: ppc: fix bad AC_CACHE_CHECK call with semun |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Mike Frysinger Jan. 2, 2024, 5:30 a.m. UTC
  Instead of executing code to see if SysV semaphores & shared memory
are available, switch to just a compile-time test.  The system used
to compile might not match the system used to run the code wrt the
current kernel & OS settings, but the library APIs should.  So move
the failures from compile-time to runtime so the program is more
portable, and works correctly even when cross-compiling.
---
 sim/ppc/configure    | 149 ++++++++++++++++++++-----------------------
 sim/ppc/configure.ac |  48 +++++---------
 2 files changed, 87 insertions(+), 110 deletions(-)
  

Patch

diff --git a/sim/ppc/configure.ac b/sim/ppc/configure.ac
index 50afce74303d..b78a09d9b587 100644
--- a/sim/ppc/configure.ac
+++ b/sim/ppc/configure.ac
@@ -111,10 +111,8 @@  AS_IF([test x"$ac_cv_has_union_semun" = x"yes"], [dnl
 ])
 
 AC_CACHE_CHECK([whether System V semaphores are supported],
-  ac_cv_sysv_sem,
-  [
-  AC_TRY_RUN(
-  [
+  [ac_cv_sysv_sem],
+  [AC_TRY_COMPILE([
   #include <sys/types.h>
   #include <sys/ipc.h>
   #include <sys/sem.h>
@@ -124,40 +122,28 @@  AC_CACHE_CHECK([whether System V semaphores are supported],
     struct semid_ds *buf;
     ushort *array;
   };
-#endif
-  int main () {
-    union semun arg ;
-
-    int id=semget(IPC_PRIVATE,1,IPC_CREAT|0400);
-    if (id == -1)
-      exit(1);
-    arg.val = 0; /* avoid implicit type cast to union */
-    if (semctl(id, 0, IPC_RMID, arg) == -1)
-      exit(1);
-    exit(0);
-  }
-  ],
-  ac_cv_sysv_sem="yes", ac_cv_sysv_sem="no", :)
-])
+#endif], [
+  union semun arg;
+  int id = semget(IPC_PRIVATE, 1, IPC_CREAT|0400);
+  if (id == -1)
+    return 1;
+  arg.val = 0; /* avoid implicit type cast to union */
+  if (semctl(id, 0, IPC_RMID, arg) == -1)
+    return 1;
+], [ac_cv_sysv_sem="yes"], [ac_cv_sysv_sem="no"])])
 
 AC_CACHE_CHECK(whether System V shared memory is supported,
 ac_cv_sysv_shm,
-[
-AC_TRY_RUN([
+[AC_TRY_COMPILE([
 #include <sys/types.h>
 #include <sys/ipc.h>
-#include <sys/shm.h>
-int main () {
-  int id=shmget(IPC_PRIVATE,1,IPC_CREAT|0400);
+#include <sys/shm.h>], [
+  int id = shmget(IPC_PRIVATE, 1, IPC_CREAT|0400);
   if (id == -1)
-    exit(1);
+    return 1;
   if (shmctl(id, IPC_RMID, 0) == -1)
-    exit(1);
-  exit(0);
-}
-],
-ac_cv_sysv_shm="yes", ac_cv_sysv_shm="no", :)
-])
+    return 1;
+], [ac_cv_sysv_shm="yes"], [ac_cv_sysv_shm="no"])])
 
 if test x"$ac_cv_sysv_shm" = x"yes" -a x"$ac_cv_sysv_sem" = x"yes" ; then
   sim_sysv_ipc_hw=",sem,shm";