[compiler-rt] 5e537ea - [ORC-RT] Re-apply "Initial ORC Runtime directories and build..." with fixes.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 24 17:41:09 PDT 2021


Author: Lang Hames
Date: 2021-04-24T16:00:20-07:00
New Revision: 5e537ea1d7a937f848ff1c0fc691d5a5afdf2459

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

LOG: [ORC-RT] Re-apply "Initial ORC Runtime directories and build..." with fixes.

This reapplies 1e1d75b190c, which was reverted in ce1a4d53231 due to build
failures.

The unconditional dependencies on clang and llvm-jitlink in
compiler-rt/test/orc/CMakeLists.txt have been removed -- they don't appear to
be necessary, and I suspect they're the cause of the build failures seen
earlier.

Added: 
    compiler-rt/lib/orc/CMakeLists.txt
    compiler-rt/lib/orc/placeholder.cpp
    compiler-rt/test/orc/CMakeLists.txt
    compiler-rt/test/orc/TestCases/Darwin/lit.local.cfg.py
    compiler-rt/test/orc/TestCases/Darwin/x86-64/lit.local.cfg.py
    compiler-rt/test/orc/TestCases/Darwin/x86-64/placeholder_test.S
    compiler-rt/test/orc/lit.cfg.py
    compiler-rt/test/orc/lit.site.cfg.py.in

Modified: 
    compiler-rt/CMakeLists.txt
    compiler-rt/cmake/config-ix.cmake
    compiler-rt/lib/CMakeLists.txt
    compiler-rt/test/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 2d5fd9cc4d81..c9939acfd710 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -45,6 +45,8 @@ option(COMPILER_RT_BUILD_MEMPROF "Build memory profiling runtime" ON)
 mark_as_advanced(COMPILER_RT_BUILD_MEMPROF)
 option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
 mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
+option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON)
+mark_as_advanced(COMPILER_RT_BUILD_ORC)
 
 set(COMPILER_RT_ASAN_SHADOW_SCALE ""
     CACHE STRING "Override the shadow scale to be used in ASan runtime")

diff  --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 47039a312934..317c97e9e452 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -343,6 +343,10 @@ set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} powe
 endif()
 set(ALL_SHADOWCALLSTACK_SUPPORTED_ARCH ${ARM64})
 
+if (APPLE)
+set(ALL_ORC_SUPPORTED_ARCH ${X86_64})
+endif()
+
 if(APPLE)
   include(CompilerRTDarwinUtils)
 
@@ -399,6 +403,7 @@ if(APPLE)
   set(TSAN_SUPPORTED_OS osx)
   set(XRAY_SUPPORTED_OS osx)
   set(FUZZER_SUPPORTED_OS osx)
+  set(ORC_SUPPORTED_OS osx)
 
   # Note: In order to target x86_64h on OS X the minimum deployment target must
   # be 10.8 or higher.
@@ -587,6 +592,9 @@ if(APPLE)
   list_intersect(SHADOWCALLSTACK_SUPPORTED_ARCH
     ALL_SHADOWCALLSTACK_SUPPORTED_ARCH
     SANITIZER_COMMON_SUPPORTED_ARCH)
+  list_intersect(ORC_SUPPORTED_ARCH
+    ALL_ORC_SUPPORTED_ARCH
+    SANITIZER_COMMON_SUPPORTED_ARCH)
 
 else()
   filter_available_targets(CRT_SUPPORTED_ARCH ${ALL_CRT_SUPPORTED_ARCH})
@@ -618,6 +626,7 @@ else()
   filter_available_targets(SHADOWCALLSTACK_SUPPORTED_ARCH
     ${ALL_SHADOWCALLSTACK_SUPPORTED_ARCH})
   filter_available_targets(GWP_ASAN_SUPPORTED_ARCH ${ALL_GWP_ASAN_SUPPORTED_ARCH})
+  filter_available_targets(ORC_SUPPORTED_ARCH ${ALL_ORC_SUPPORTED_ARCH})
 endif()
 
 if (MSVC)
@@ -778,6 +787,12 @@ else()
   set(COMPILER_RT_HAS_XRAY FALSE)
 endif()
 
+if (ORC_SUPPORTED_ARCH)
+  set(COMPILER_RT_HAS_ORC TRUE)
+else()
+  set(COMPILER_RT_HAS_ORC FALSE)
+endif()
+
 if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND
     OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD|Fuchsia|Windows")
   set(COMPILER_RT_HAS_FUZZER TRUE)

diff  --git a/compiler-rt/lib/CMakeLists.txt b/compiler-rt/lib/CMakeLists.txt
index c1c6880a4720..1437e37b86d9 100644
--- a/compiler-rt/lib/CMakeLists.txt
+++ b/compiler-rt/lib/CMakeLists.txt
@@ -66,6 +66,10 @@ if(COMPILER_RT_BUILD_MEMPROF AND COMPILER_RT_HAS_SANITIZER_COMMON)
   compiler_rt_build_runtime(memprof)
 endif()
 
+if(COMPILER_RT_BUILD_ORC)
+  compiler_rt_build_runtime(orc)
+endif()
+
 # It doesn't normally make sense to build runtimes when a sanitizer is enabled,
 # so we don't add_subdirectory the runtimes in that case. However, the opposite
 # is true for fuzzers that exercise parts of the runtime. So we add the fuzzer

diff  --git a/compiler-rt/lib/orc/CMakeLists.txt b/compiler-rt/lib/orc/CMakeLists.txt
new file mode 100644
index 000000000000..4007a46ca466
--- /dev/null
+++ b/compiler-rt/lib/orc/CMakeLists.txt
@@ -0,0 +1,84 @@
+# Build for all components of the ORC runtime support library.
+
+# ORC runtime library implementation files.
+set(ORC_SOURCES
+  placeholder.cpp
+  )
+
+# Implementation files for all ORC architectures.
+set(x86_64_SOURCES
+# x86-64 specific assembly files will go here.
+)
+
+set(ORC_IMPL_HEADERS
+# Implementation headers will go here.
+)
+
+# Create list of all source files for
+# consumption by tests.
+set(ORC_ALL_SOURCE_FILES
+  ${ORC_SOURCES}
+  ${x86_64_SOURCES}
+  ${ORC_IMPL_HEADERS}
+  )
+
+list(REMOVE_DUPLICATES ORC_ALL_SOURCE_FILES)
+
+# Now put it all together...
+include_directories(..)
+include_directories(../../include)
+
+set(ORC_CFLAGS ${COMPILER_RT_COMMON_CFLAGS})
+
+# Allow the ORC runtime to reference LLVM headers.
+foreach (DIR ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
+  list(APPEND ORC_CFLAGS -I${DIR})
+endforeach()
+
+add_compiler_rt_component(orc)
+
+# ORC uses C++ standard library headers.
+if (TARGET cxx-headers OR HAVE_LIBCXX)
+  set(ORC_DEPS cxx-headers)
+endif()
+
+if (APPLE)
+  add_compiler_rt_object_libraries(RTOrc
+    OS ${ORC_SUPPORTED_OS}
+    ARCHS ${ORC_SUPPORTED_ARCH}
+    SOURCES ${ORC_SOURCES} ${x86_64_SOURCES}
+    ADDITIONAL_HEADERS ${ORC_IMPL_HEADERS}
+    CFLAGS ${ORC_CFLAGS}
+    DEPS ${ORC_DEPS})
+
+  # We only support running on osx for now.
+  add_compiler_rt_runtime(clang_rt.orc
+    STATIC
+    OS ${ORC_SUPPORTED_OS}
+    ARCHS ${ORC_SUPPORTED_ARCH}
+    OBJECT_LIBS RTOrc
+    CFLAGS ${ORC_CFLAGS}
+    LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
+    LINK_LIBS ${ORC_LINK_LIBS}
+    PARENT_TARGET orc)
+else() # not Apple
+  foreach(arch ${ORC_SUPPORTED_ARCH})
+    if(NOT CAN_TARGET_${arch})
+      continue()
+    endif()
+    add_compiler_rt_object_libraries(RTOrc
+      ARCHS ${arch}
+      SOURCES ${ORC_SOURCES} ${${arch}_SOURCES}
+      ADDITIONAL_HEADERS ${ORC_IMPL_HEADERS}
+      CFLAGS $ORC_CFLAGS}
+      DEPS ${ORC_DEPS})
+
+    # Common ORC archive for instrumented binaries.
+    add_compiler_rt_runtime(clang_rt.orc
+     STATIC
+     ARCHS ${arch}
+     CFLAGS ${ORC_CFLAGS}
+     OBJECT_LIBS ${ORC_COMMON_RUNTIME_OBJECT_LIBS} RTOrc
+     PARENT_TARGET orc)
+  endforeach()
+endif() # not Apple

diff  --git a/compiler-rt/lib/orc/placeholder.cpp b/compiler-rt/lib/orc/placeholder.cpp
new file mode 100644
index 000000000000..c832f6007a7d
--- /dev/null
+++ b/compiler-rt/lib/orc/placeholder.cpp
@@ -0,0 +1 @@
+void placeholder(void) {}

diff  --git a/compiler-rt/test/CMakeLists.txt b/compiler-rt/test/CMakeLists.txt
index 1d123ed8cfb7..1020cc7ff827 100644
--- a/compiler-rt/test/CMakeLists.txt
+++ b/compiler-rt/test/CMakeLists.txt
@@ -78,6 +78,9 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS)
   if(COMPILER_RT_BUILD_XRAY)
     compiler_rt_test_runtime(xray)
   endif()
+  if(COMPILER_RT_BUILD_ORC)
+    compiler_rt_Test_runtime(orc)
+  endif()
   if(COMPILER_RT_BUILD_CRT AND COMPILER_RT_HAS_CRT)
     add_subdirectory(crt)
   endif()

diff  --git a/compiler-rt/test/orc/CMakeLists.txt b/compiler-rt/test/orc/CMakeLists.txt
new file mode 100644
index 000000000000..b2d31dc04691
--- /dev/null
+++ b/compiler-rt/test/orc/CMakeLists.txt
@@ -0,0 +1,25 @@
+set(ORC_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
+set(ORC_TESTSUITES)
+set(ORC_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
+
+set(ORC_TEST_ARCH ${ORC_SUPPORTED_ARCH})
+if (COMPILER_RT_BUILD_ORC AND COMPILER_RT_HAS_ORC)
+  foreach(arch ${ORC_TEST_ARCH})
+    set(ORC_TEST_TARGET_ARCH ${arch})
+    string(TOLOWER "-${arch}-${OS_NAME}" ORC_TEST_CONFIG_SUFFIX)
+    get_test_cc_for_arch(${arch} ORC_TEST_TARGET_CC ORC_TEST_TARGET_CFLAGS)
+    string(TOUPPER ${arch} ARCH_UPPER_CASE)
+    set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
+
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
+    list(APPEND ORC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+  endforeach()
+endif()
+
+add_lit_testsuite(check-orc "Running the ORC runtime tests"
+  ${ORC_TESTSUITES}
+  DEPENDS ${ORC_TEST_DEPS})
+set_target_properties(check-orc PROPERTIES FOLDER "Compiler-RT Misc")

diff  --git a/compiler-rt/test/orc/TestCases/Darwin/lit.local.cfg.py b/compiler-rt/test/orc/TestCases/Darwin/lit.local.cfg.py
new file mode 100644
index 000000000000..ffa8fd83cbf8
--- /dev/null
+++ b/compiler-rt/test/orc/TestCases/Darwin/lit.local.cfg.py
@@ -0,0 +1,2 @@
+if config.root.host_os != 'Darwin':
+  config.unsupported = True

diff  --git a/compiler-rt/test/orc/TestCases/Darwin/x86-64/lit.local.cfg.py b/compiler-rt/test/orc/TestCases/Darwin/x86-64/lit.local.cfg.py
new file mode 100644
index 000000000000..1b14fb647bf6
--- /dev/null
+++ b/compiler-rt/test/orc/TestCases/Darwin/x86-64/lit.local.cfg.py
@@ -0,0 +1,2 @@
+if config.root.host_arch != 'x86_64':
+  config.unsupported = True

diff  --git a/compiler-rt/test/orc/TestCases/Darwin/x86-64/placeholder_test.S b/compiler-rt/test/orc/TestCases/Darwin/x86-64/placeholder_test.S
new file mode 100644
index 000000000000..a794e10152e1
--- /dev/null
+++ b/compiler-rt/test/orc/TestCases/Darwin/x86-64/placeholder_test.S
@@ -0,0 +1,13 @@
+// RUN: %clang -c -o %t %s
+// RUN: %llvm_jitlink %t
+
+	.section	__TEXT,__text,regular,pure_instructions
+	.build_version macos, 11, 0	sdk_version 11, 3
+
+	.globl	_main
+	.p2align	4, 0x90
+_main:
+	xorl	%eax, %eax
+	retq
+
+.subsections_via_symbols

diff  --git a/compiler-rt/test/orc/lit.cfg.py b/compiler-rt/test/orc/lit.cfg.py
new file mode 100644
index 000000000000..4e395236f6bc
--- /dev/null
+++ b/compiler-rt/test/orc/lit.cfg.py
@@ -0,0 +1,33 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'ORC' + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+def build_invocation(compile_flags):
+  return ' ' + ' '.join([config.clang] + compile_flags) + ' '
+
+# Assume that llvm-jitlink is in the config.llvm_tools_dir.
+llvm_jitlink = os.path.join(config.llvm_tools_dir, 'llvm-jitlink')
+
+config.substitutions.append(
+    ('%clang ', build_invocation([config.target_cflags])))
+config.substitutions.append(
+    ('%clangxx ',
+     build_invocation(config.cxx_mode_flags + [config.target_cflags])))
+config.substitutions.append(
+    ('%llvm_jitlink', llvm_jitlink))
+config.substitutions.append(
+    ('%orc_rt',
+        ('-L%s -lclang_rt.orc%s')
+        % (config.compiler_rt_libdir, config.target_suffix)))
+
+# Default test suffixes.
+config.suffixes = ['.c', '.cpp', '.S']
+
+if config.host_os not in ['Darwin']:
+  config.unsupported = True

diff  --git a/compiler-rt/test/orc/lit.site.cfg.py.in b/compiler-rt/test/orc/lit.site.cfg.py.in
new file mode 100644
index 000000000000..d5bb51c9be80
--- /dev/null
+++ b/compiler-rt/test/orc/lit.site.cfg.py.in
@@ -0,0 +1,14 @@
+ at LIT_SITE_CFG_IN_HEADER@
+
+# Tool-specific config options.
+config.name_suffix = "@ORC_TEST_CONFIG_SUFFIX@"
+config.orc_lit_source_dir = "@ORC_LIT_SOURCE_DIR@"
+config.target_cflags = "@ORC_TEST_TARGET_CFLAGS@"
+config.target_arch = "@ORC_TEST_TARGET_ARCH@"
+config.built_with_llvm = ("@COMPILER_RT_STANDALONE_BUILD@" != "TRUE")
+
+# Load common config for all compiler-rt lit tests
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")


        


More information about the llvm-commits mailing list