Skip to content

Commit

Permalink
Add first bits to cross-compile the runtime for OSX
Browse files Browse the repository at this point in the history
Summary: Add first bits to cross-compile the runtime for OSX.

(cherry picked from FBD24330977)
  • Loading branch information
Alexander Shaposhnikov authored and maksfb committed Oct 15, 2020
1 parent 0b6df06 commit bbd9d61
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bolt/runtime/CMakeLists.txt
Expand Up @@ -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()
6 changes: 6 additions & 0 deletions bolt/runtime/common.h
@@ -1,5 +1,7 @@
#if !defined(__APPLE__)
#include <cstddef>
#include <cstdint>
#endif

#include "config.h"
#ifdef HAVE_ELF_H
Expand Down Expand Up @@ -44,6 +46,8 @@
"pop %%rbx\n" \
"pop %%rax\n"

#if !defined(__APPLE__)

// Anonymous namespace covering everything but our library entry point
namespace {

Expand Down Expand Up @@ -327,3 +331,5 @@ inline uint64_t alignTo(uint64_t Value, uint64_t Align) {
return (Value + Align - 1) / Align * Align;
}
} // anonymous namespace

#endif
4 changes: 4 additions & 0 deletions bolt/runtime/hugify.cpp
Expand Up @@ -9,6 +9,8 @@
//
//===----------------------------------------------------------------------===//

#if !defined(__APPLE__)

#include "common.h"
#include <sys/mman.h>

Expand Down Expand Up @@ -172,3 +174,5 @@ extern "C" __attribute((naked)) void __bolt_hugify_self() {
"jmp *__bolt_hugify_init_ptr(%%rip)\n"
:::);
}

#endif
10 changes: 10 additions & 0 deletions bolt/runtime/instr.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit bbd9d61

Please sign in to comment.