From bbd9d610fe62f1049ebbd810863ad2a345cc9f7e Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Thu, 15 Oct 2020 03:51:56 -0700 Subject: [PATCH] Add first bits to cross-compile the runtime for OSX Summary: Add first bits to cross-compile the runtime for OSX. (cherry picked from FBD24330977) --- bolt/runtime/CMakeLists.txt | 13 +++++++++++++ bolt/runtime/common.h | 6 ++++++ bolt/runtime/hugify.cpp | 4 ++++ bolt/runtime/instr.cpp | 10 ++++++++++ 4 files changed, 33 insertions(+) diff --git a/bolt/runtime/CMakeLists.txt b/bolt/runtime/CMakeLists.txt index a8786c8243a8..05eb0f057ba4 100644 --- a/bolt/runtime/CMakeLists.txt +++ b/bolt/runtime/CMakeLists.txt @@ -30,3 +30,16 @@ target_include_directories(bolt_rt_hugify PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) install(TARGETS bolt_rt_instr DESTINATION lib) install(TARGETS bolt_rt_hugify DESTINATION lib) +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_library(bolt_rt_instr_osx STATIC + instr.cpp + ${CMAKE_CURRENT_BINARY_DIR}/config.h + ) + target_include_directories(bolt_rt_instr_osx PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_compile_options(bolt_rt_instr_osx PRIVATE + -target x86_64-apple-darwin19.6.0 + -ffreestanding + -fno-exceptions + -fno-rtti) + install(TARGETS bolt_rt_instr_osx DESTINATION lib) +endif() diff --git a/bolt/runtime/common.h b/bolt/runtime/common.h index d6f240469739..5298ebaa5f48 100644 --- a/bolt/runtime/common.h +++ b/bolt/runtime/common.h @@ -1,5 +1,7 @@ +#if !defined(__APPLE__) #include #include +#endif #include "config.h" #ifdef HAVE_ELF_H @@ -44,6 +46,8 @@ "pop %%rbx\n" \ "pop %%rax\n" +#if !defined(__APPLE__) + // Anonymous namespace covering everything but our library entry point namespace { @@ -327,3 +331,5 @@ inline uint64_t alignTo(uint64_t Value, uint64_t Align) { return (Value + Align - 1) / Align * Align; } } // anonymous namespace + +#endif diff --git a/bolt/runtime/hugify.cpp b/bolt/runtime/hugify.cpp index 0a770a144d80..3d384fadfea2 100644 --- a/bolt/runtime/hugify.cpp +++ b/bolt/runtime/hugify.cpp @@ -9,6 +9,8 @@ // //===----------------------------------------------------------------------===// +#if !defined(__APPLE__) + #include "common.h" #include @@ -172,3 +174,5 @@ extern "C" __attribute((naked)) void __bolt_hugify_self() { "jmp *__bolt_hugify_init_ptr(%%rip)\n" :::); } + +#endif diff --git a/bolt/runtime/instr.cpp b/bolt/runtime/instr.cpp index c1401bcf0a25..e0401b8d572b 100644 --- a/bolt/runtime/instr.cpp +++ b/bolt/runtime/instr.cpp @@ -57,6 +57,8 @@ {} #endif +#if !defined(__APPLE__) + // Main counters inserted by instrumentation, incremented during runtime when // points of interest (locations) in the program are reached. Those are direct // calls and direct and indirect branches (local ones). There are also counters @@ -1460,3 +1462,11 @@ extern "C" void __bolt_instr_fini() { __bolt_instr_data_dump(); DEBUG(report("Finished.\n")); } + +#else + +// On OSX/iOS the final symbol name of an extern "C" function/variable contains +// one extra leading underscore: _bolt_instr_setup -> __bolt_instr_setup. +extern "C" __attribute((section("__TEXT,__setup"))) void _bolt_instr_setup() {} + +#endif