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

This reapplies 1e1d75b190, which was reverted in ce1a4d5323 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.
This commit is contained in:
Lang Hames 2021-04-23 21:14:56 -07:00
parent 6fca189532
commit 5e537ea1d7
12 changed files with 198 additions and 0 deletions

View File

@ -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")

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
void placeholder(void) {}

View File

@ -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()

View File

@ -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")

View File

@ -0,0 +1,2 @@
if config.root.host_os != 'Darwin':
config.unsupported = True

View File

@ -0,0 +1,2 @@
if config.root.host_arch != 'x86_64':
config.unsupported = True

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,14 @@
@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")