Embedded compiler: development [#CLICKHOUSE-3396].

This commit is contained in:
Alexey Milovidov 2017-11-12 09:46:42 +03:00
parent 5074301f8d
commit 6d84a88629
3 changed files with 35 additions and 25 deletions

View File

@ -12,9 +12,7 @@ endif ()
set (INTERNAL_COMPILER_NO_WARNING OFF CACHE BOOL "")
#original string:
# -x c++ -std=gnu++1y -O3 -g -Wall -Werror -Wnon-virtual-dtor -march=native -msse4 -mpopcnt -D NDEBUG -D_GLIBCXX_USE_CXX11_ABI=0 -shared -fPIC -fvisibility=hidden -fno-implement-inlines
set (INTERNAL_COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${CXX_FLAGS_INTERNAL_COMPILER} -x c++ -march=native -shared -fPIC -fvisibility=hidden -fno-implement-inlines " CACHE STRING "")
set (INTERNAL_COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${CXX_FLAGS_INTERNAL_COMPILER} -x c++ -march=native -fPIC -fvisibility=hidden -fno-implement-inlines " CACHE STRING "")
string(REPLACE "-no-pie" "" INTERNAL_COMPILER_FLAGS ${INTERNAL_COMPILER_FLAGS})
if (INTERNAL_COMPILER_NO_WARNING)
string (REPLACE "-Wall" "" INTERNAL_COMPILER_FLAGS ${INTERNAL_COMPILER_FLAGS})

View File

@ -203,6 +203,7 @@ void Compiler::compile(
std::string prefix = path + "/" + file_name;
std::string cpp_file_path = prefix + ".cpp";
std::string o_file_path = prefix + ".o";
std::string so_file_path = prefix + ".so";
std::string so_tmp_file_path = prefix + ".so.tmp";
@ -217,10 +218,10 @@ void Compiler::compile(
/// Slightly unconvenient.
command <<
"("
INTERNAL_COMPILER_EXECUTABLE
" -fuse-ld=" INTERNAL_LINKER_EXECUTABLE
" " INTERNAL_COMPILER_FLAGS
#if INTERNAL_COMPILER_CUSTOM_ROOT
#if INTERNAL_COMPILER_CUSTOM_ROOT
" -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/local/include/"
" -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/"
" -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/c++/*/"
@ -228,7 +229,7 @@ void Compiler::compile(
" -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/x86_64-linux-gnu/c++/*/"
" -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/local/lib/clang/*/include/"
" -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/lib/clang/*/include/"
#endif
#endif
" -I " INTERNAL_COMPILER_HEADERS "/dbms/src/"
" -I " INTERNAL_COMPILER_HEADERS "/contrib/libcityhash/include/"
" -I " INTERNAL_COMPILER_HEADERS "/contrib/libpcg-random/include/"
@ -237,8 +238,15 @@ void Compiler::compile(
" -I " INTERNAL_Boost_INCLUDE_DIRS
" -I " INTERNAL_COMPILER_HEADERS "/libs/libcommon/include/"
" " << additional_compiler_flags <<
" -o " << so_tmp_file_path << " " << cpp_file_path
<< " 2>&1 || echo Exit code: $?";
" -c -o " << o_file_path << " " << cpp_file_path
<< " 2>&1"
") && ("
INTERNAL_LINKER_EXECUTABLE
" -shared"
" -o " << so_tmp_file_path
<< " " << o_file_path
<< " 2>&1"
") || echo Return code: $?";
std::string compile_result;
@ -253,6 +261,7 @@ void Compiler::compile(
/// If there was an error before, the file with the code remains for viewing.
Poco::File(cpp_file_path).remove();
Poco::File(o_file_path).remove();
Poco::File(so_tmp_file_path).renameTo(so_file_path);
SharedLibraryPtr lib(new SharedLibrary(so_file_path));

View File

@ -82,6 +82,9 @@ bool isClickhouseApp(const std::string & app_suffix, std::vector<char *> & argv)
int main(int argc_, char ** argv_)
{
if (argc_ >= 2 && 0 == strcmp(argv_[1], "-cc1"))
return mainEntryClickHouseClang(argc_, argv_);
#if USE_TCMALLOC
/** Without this option, tcmalloc returns memory to OS too frequently for medium-sized memory allocations
* (like IO buffers, column vectors, hash tables, etc.),