From 6d84a8862900c6723e7b28fe52eca834d14a1dbc Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 12 Nov 2017 09:46:42 +0300 Subject: [PATCH] Embedded compiler: development [#CLICKHOUSE-3396]. --- dbms/src/Interpreters/CMakeLists.txt | 4 +-- dbms/src/Interpreters/Compiler.cpp | 53 ++++++++++++++++------------ dbms/src/Server/main.cpp | 3 ++ 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/dbms/src/Interpreters/CMakeLists.txt b/dbms/src/Interpreters/CMakeLists.txt index 264c84ac3c5..f1db1606786 100644 --- a/dbms/src/Interpreters/CMakeLists.txt +++ b/dbms/src/Interpreters/CMakeLists.txt @@ -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}) diff --git a/dbms/src/Interpreters/Compiler.cpp b/dbms/src/Interpreters/Compiler.cpp index e80a246929a..3e017d7be85 100644 --- a/dbms/src/Interpreters/Compiler.cpp +++ b/dbms/src/Interpreters/Compiler.cpp @@ -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,28 +218,35 @@ void Compiler::compile( /// Slightly unconvenient. command << - INTERNAL_COMPILER_EXECUTABLE - " -fuse-ld=" INTERNAL_LINKER_EXECUTABLE - " " INTERNAL_COMPILER_FLAGS -#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++/*/" - " -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/x86_64-linux-gnu/" - " -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 - " -I " INTERNAL_COMPILER_HEADERS "/dbms/src/" - " -I " INTERNAL_COMPILER_HEADERS "/contrib/libcityhash/include/" - " -I " INTERNAL_COMPILER_HEADERS "/contrib/libpcg-random/include/" - " -I " INTERNAL_DOUBLE_CONVERSION_INCLUDE_DIR - " -I " INTERNAL_Poco_Foundation_INCLUDE_DIR - " -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: $?"; + "(" + INTERNAL_COMPILER_EXECUTABLE + " " INTERNAL_COMPILER_FLAGS + #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++/*/" + " -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/x86_64-linux-gnu/" + " -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 + " -I " INTERNAL_COMPILER_HEADERS "/dbms/src/" + " -I " INTERNAL_COMPILER_HEADERS "/contrib/libcityhash/include/" + " -I " INTERNAL_COMPILER_HEADERS "/contrib/libpcg-random/include/" + " -I " INTERNAL_DOUBLE_CONVERSION_INCLUDE_DIR + " -I " INTERNAL_Poco_Foundation_INCLUDE_DIR + " -I " INTERNAL_Boost_INCLUDE_DIRS + " -I " INTERNAL_COMPILER_HEADERS "/libs/libcommon/include/" + " " << additional_compiler_flags << + " -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)); diff --git a/dbms/src/Server/main.cpp b/dbms/src/Server/main.cpp index 1b611d41523..fe034b96d85 100644 --- a/dbms/src/Server/main.cpp +++ b/dbms/src/Server/main.cpp @@ -82,6 +82,9 @@ bool isClickhouseApp(const std::string & app_suffix, std::vector & 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.),