Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add patch for arm64 Ubuntu 22.04 in UnwindContext
authorMaxwell Pirtle <maxwellpirtle@gmail.com>
Wed, 1 Feb 2023 13:52:53 +0000 (14:52 +0100)
committerMaxwell Pirtle <maxwellpirtle@gmail.com>
Thu, 9 Feb 2023 10:04:48 +0000 (11:04 +0100)
The `mcontext_t` struct on Ubuntu 22.04
running on arm64 is missing the `fregs`
field. This causes a compilation failure
in `src/mc/inspect/mc_unw.cpp` since the
code there assumes the field exists on
linux-arm64.

This commit adds a new CMake variable
SIMGRID_PROCESSOR_arm64 to account for
the additional architecture more
explicitly and to better fit the context
surrounding the code where the fix was made

CMakeLists.txt
src/internal_config.h.in
src/mc/inspect/mc_unw.cpp

index 84fe7f3..366f0e3 100644 (file)
@@ -184,19 +184,28 @@ IF(CMAKE_SYSTEM_PROCESSOR MATCHES ".86|AMD64|amd64")
     message(STATUS "System processor: i686 (${CMAKE_SYSTEM_PROCESSOR}, 32 bits)")
     set(SIMGRID_PROCESSOR_i686 1)
     set(SIMGRID_PROCESSOR_x86_64 0)
+    set(SIMGRID_PROCESSOR_arm64 0)
   ELSE()
     message(STATUS "System processor: x86_64 (${CMAKE_SYSTEM_PROCESSOR}, 64 bits)")
     set(SIMGRID_PROCESSOR_i686 0)
     set(SIMGRID_PROCESSOR_x86_64 1)
+    set(SIMGRID_PROCESSOR_arm64 0)
   ENDIF()
   if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
     message(STATUS "Disable fast raw contexts on x32 ABI.")
   else()
     set(HAVE_RAW_CONTEXTS 1)
   endif()
+ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
+  message(STATUS "System processor: arm64 (${CMAKE_SYSTEM_PROCESSOR}, 64 bits)")
+  set(SIMGRID_PROCESSOR_i686 0)
+  set(SIMGRID_PROCESSOR_x86_64 0)
+  set(SIMGRID_PROCESSOR_arm64 1)
 ELSE()
+  message(STATUS "System processor (${CMAKE_SYSTEM_PROCESSOR}) not explicitly accounted for")
   set(SIMGRID_PROCESSOR_i686 0)
   set(SIMGRID_PROCESSOR_x86_64 0)
+  set(SIMGRID_PROCESSOR_arm64 0)
 ENDIF()
 
 include(CheckFunctionExists)
index a6dcbd5..e13c6ff 100644 (file)
@@ -48,6 +48,7 @@
 /* Variables for the raw contexts (to select the right assembly code) */
 #cmakedefine01 SIMGRID_PROCESSOR_i686
 #cmakedefine01 SIMGRID_PROCESSOR_x86_64
+#cmakedefine01 SIMGRID_PROCESSOR_arm64
 
 /* Variables for the SysV contexts */
 @sg_makecontext_stack_addr@
index 2c66603..746fb31 100644 (file)
@@ -225,7 +225,7 @@ void UnwindContext::initialize(simgrid::mc::RemoteProcess* process, unw_context_
 
   // Take a copy of the context for our own purpose:
   this->unwind_context_ = *c;
-#if SIMGRID_PROCESSOR_x86_64 || SIMGRID_PROCESSOR_i686 || defined(__aarch64__)
+#if SIMGRID_PROCESSOR_x86_64 || SIMGRID_PROCESSOR_i686
 #ifdef __linux__
   // On x86_64, ucontext_t contains a pointer to itself for FP registers.
   // We don't really need support for FR registers as they are caller saved
@@ -234,6 +234,12 @@ void UnwindContext::initialize(simgrid::mc::RemoteProcess* process, unw_context_
   // Let's ignore this and see what happens:
   this->unwind_context_.uc_mcontext.fpregs = nullptr;
 #endif
+#elif SIMGRID_PROCESSOR_arm64
+#ifdef __linux__
+  // On ARM64, ucontext_t doesn't contain `fpregs` and the FP registers
+  // are instead held in the `__reserved` field of the struct. It doesn't
+  // appear anything needs to be done here, although this should be verified
+#endif
 #else
   // Do we need to do any fixup like this?
 #error Target CPU type is not handled.