[compiler-rt] be1b2ac - [compiler-rt][CMake] Multiarch build of XRay libraries

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 18:41:12 PDT 2023


Author: Oleksii Lozovskyi
Date: 2023-06-22T18:41:07-07:00
New Revision: be1b2ac9485746a79b92310b9d0ba505650ce53e

URL: https://github.com/llvm/llvm-project/commit/be1b2ac9485746a79b92310b9d0ba505650ce53e
DIFF: https://github.com/llvm/llvm-project/commit/be1b2ac9485746a79b92310b9d0ba505650ce53e.diff

LOG: [compiler-rt][CMake] Multiarch build of XRay libraries

Instead of dumping all sources into RTXray object library with a weird
special case for x86, handle multiarch builds better. Build a separate
object library for each arch with its arch-specific sources, then link
in all those libraries.

This fixes the build on platforms that produce fat binaries, such as new
macOS which expects both x86_64 and aarch64 objects in the same library
since Apple Silicon is a thing.

This only enables building XRay support for Apple Silicon. It does not
actually work yet on macOS, neither on Intel nor on Apple Silicon CPUs.
Thus the tests are still disabled.

Reviewed By: MaskRay, phosek

Differential Revision: https://reviews.llvm.org/D153221

Added: 
    

Modified: 
    compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
    compiler-rt/lib/xray/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 4c5081b76997b..e41bd306053d2 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -76,7 +76,7 @@ set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS64}
 set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
     ${MIPS32} ${MIPS64} ${PPC64} ${HEXAGON} ${LOONGARCH64} ${RISCV64})
 if(APPLE)
-set(ALL_XRAY_SUPPORTED_ARCH ${X86_64})
+set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM64})
 else()
 set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64}
 		powerpc64le ${HEXAGON})

diff  --git a/compiler-rt/lib/xray/CMakeLists.txt b/compiler-rt/lib/xray/CMakeLists.txt
index 421489cd816fc..e94d39ad6b03a 100644
--- a/compiler-rt/lib/xray/CMakeLists.txt
+++ b/compiler-rt/lib/xray/CMakeLists.txt
@@ -78,6 +78,19 @@ set(hexagon_SOURCES
   xray_trampoline_hexagon.S
   )
 
+set(XRAY_SOURCE_ARCHS
+  arm
+  armhf
+  aarch64
+  hexagon
+  mips
+  mipsel
+  mips64
+  mips64el
+  powerpc64le
+  x86_64
+  )
+
 set(XRAY_IMPL_HEADERS
   xray_allocator.h
   xray_basic_flags.h
@@ -171,19 +184,32 @@ if (TARGET cxx-headers OR HAVE_LIBCXX)
 endif()
 
 if (APPLE)
-  set(XRAY_ASM_SOURCES xray_trampoline_x86_64.S)
-
   add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
   add_weak_symbols("xray" WEAK_SYMBOL_LINK_FLAGS)
 
   add_compiler_rt_object_libraries(RTXray
     OS ${XRAY_SUPPORTED_OS}
     ARCHS ${XRAY_SUPPORTED_ARCH}
-    SOURCES ${XRAY_SOURCES} ${x86_64_SOURCES}
+    SOURCES ${XRAY_SOURCES}
     ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
     CFLAGS ${XRAY_CFLAGS}
     DEFS ${XRAY_COMMON_DEFINITIONS}
     DEPS ${XRAY_DEPS})
+  set(XRAY_RTXRAY_ARCH_LIBS "")
+  foreach(arch ${XRAY_SUPPORTED_ARCH})
+    if(NOT ${arch} IN_LIST XRAY_SOURCE_ARCHS)
+      continue()
+    endif()
+    add_compiler_rt_object_libraries(RTXray_${arch}
+      OS ${XRAY_SUPPORTED_OS}
+      ARCHS ${arch}
+      SOURCES ${${arch}_SOURCES}
+      ADDITIONAL_HEADERS ${XRAY_IMPL_HEADERS}
+      CFLAGS ${XRAY_CFLAGS}
+      DEFS ${XRAY_COMMON_DEFINITIONS}
+      DEPS ${XRAY_DEPS})
+    list(APPEND XRAY_RTXRAY_ARCH_LIBS RTXray_${arch})
+  endforeach()
   add_compiler_rt_object_libraries(RTXrayFDR
     OS ${XRAY_SUPPORTED_OS}
     ARCHS ${XRAY_SUPPORTED_ARCH}
@@ -214,9 +240,7 @@ if (APPLE)
     STATIC
     OS ${XRAY_SUPPORTED_OS}
     ARCHS ${XRAY_SUPPORTED_ARCH}
-    OBJECT_LIBS RTXray
-                RTSanitizerCommon
-                RTSanitizerCommonLibc
+    OBJECT_LIBS ${XRAY_COMMON_RUNTIME_OBJECT_LIBS} RTXray ${XRAY_RTXRAY_ARCH_LIBS}
     CFLAGS ${XRAY_CFLAGS}
     DEFS ${XRAY_COMMON_DEFINITIONS}
     LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}


        


More information about the llvm-commits mailing list