mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-10-22 16:30:49 +00:00
Merge branch 'master' of github.com:yandex/ClickHouse
This commit is contained in:
commit
d8f8d2e5e8
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -97,9 +97,9 @@
|
|||||||
[submodule "contrib/rapidjson"]
|
[submodule "contrib/rapidjson"]
|
||||||
path = contrib/rapidjson
|
path = contrib/rapidjson
|
||||||
url = https://github.com/Tencent/rapidjson
|
url = https://github.com/Tencent/rapidjson
|
||||||
[submodule "contrib/mimalloc"]
|
|
||||||
path = contrib/mimalloc
|
|
||||||
url = https://github.com/ClickHouse-Extras/mimalloc
|
|
||||||
[submodule "contrib/fastops"]
|
[submodule "contrib/fastops"]
|
||||||
path = contrib/fastops
|
path = contrib/fastops
|
||||||
url = https://github.com/ClickHouse-Extras/fastops
|
url = https://github.com/ClickHouse-Extras/fastops
|
||||||
|
[submodule "contrib/orc"]
|
||||||
|
path = contrib/orc
|
||||||
|
url = https://github.com/apache/orc
|
||||||
|
20
CHANGELOG.md
20
CHANGELOG.md
@ -1,3 +1,13 @@
|
|||||||
|
## ClickHouse release 19.13.3.26, 2019-08-22
|
||||||
|
|
||||||
|
### Bug Fix
|
||||||
|
* Fix `ALTER TABLE ... UPDATE` query for tables with `enable_mixed_granularity_parts=1`. [#6543](https://github.com/yandex/ClickHouse/pull/6543) ([alesapin](https://github.com/alesapin))
|
||||||
|
* Fix NPE when using IN clause with a subquery with a tuple. [#6125](https://github.com/yandex/ClickHouse/issues/6125) [#6550](https://github.com/yandex/ClickHouse/pull/6550) ([tavplubix](https://github.com/tavplubix))
|
||||||
|
* Fixed an issue that if a stale replica becomes alive, it may still have data parts that were removed by DROP PARTITION. [#6522](https://github.com/yandex/ClickHouse/issues/6522) [#6523](https://github.com/yandex/ClickHouse/pull/6523) ([tavplubix](https://github.com/tavplubix))
|
||||||
|
* Fixed issue with parsing CSV [#6426](https://github.com/yandex/ClickHouse/issues/6426) [#6559](https://github.com/yandex/ClickHouse/pull/6559) ([tavplubix](https://github.com/tavplubix))
|
||||||
|
* Fixed data race in system.parts table and ALTER query. This fixes [#6245](https://github.com/yandex/ClickHouse/issues/6245). [#6513](https://github.com/yandex/ClickHouse/pull/6513) ([alexey-milovidov](https://github.com/alexey-milovidov))
|
||||||
|
* Fixed wrong code in mutations that may lead to memory corruption. Fixed segfault with read of address `0x14c0` that may happed due to concurrent `DROP TABLE` and `SELECT` from `system.parts` or `system.parts_columns`. Fixed race condition in preparation of mutation queries. Fixed deadlock caused by `OPTIMIZE` of Replicated tables and concurrent modification operations like ALTERs. [#6514](https://github.com/yandex/ClickHouse/pull/6514) ([alexey-milovidov](https://github.com/alexey-milovidov))
|
||||||
|
|
||||||
## ClickHouse release 19.13.2.19, 2019-08-14
|
## ClickHouse release 19.13.2.19, 2019-08-14
|
||||||
|
|
||||||
### New Feature
|
### New Feature
|
||||||
@ -31,6 +41,16 @@
|
|||||||
* Fix build with external `libcxx` [#6010](https://github.com/yandex/ClickHouse/pull/6010) ([Ivan](https://github.com/abyss7))
|
* Fix build with external `libcxx` [#6010](https://github.com/yandex/ClickHouse/pull/6010) ([Ivan](https://github.com/abyss7))
|
||||||
* Fix shared build with `rdkafka` library [#6101](https://github.com/yandex/ClickHouse/pull/6101) ([Ivan](https://github.com/abyss7))
|
* Fix shared build with `rdkafka` library [#6101](https://github.com/yandex/ClickHouse/pull/6101) ([Ivan](https://github.com/abyss7))
|
||||||
|
|
||||||
|
## ClickHouse release 19.11.8.46, 2019-08-22
|
||||||
|
|
||||||
|
### Bug Fix
|
||||||
|
* Fix `ALTER TABLE ... UPDATE` query for tables with `enable_mixed_granularity_parts=1`. [#6543](https://github.com/yandex/ClickHouse/pull/6543) ([alesapin](https://github.com/alesapin))
|
||||||
|
* Fix NPE when using IN clause with a subquery with a tuple. [#6125](https://github.com/yandex/ClickHouse/issues/6125) [#6550](https://github.com/yandex/ClickHouse/pull/6550) ([tavplubix](https://github.com/tavplubix))
|
||||||
|
* Fixed an issue that if a stale replica becomes alive, it may still have data parts that were removed by DROP PARTITION. [#6522](https://github.com/yandex/ClickHouse/issues/6522) [#6523](https://github.com/yandex/ClickHouse/pull/6523) ([tavplubix](https://github.com/tavplubix))
|
||||||
|
* Fixed issue with parsing CSV [#6426](https://github.com/yandex/ClickHouse/issues/6426) [#6559](https://github.com/yandex/ClickHouse/pull/6559) ([tavplubix](https://github.com/tavplubix))
|
||||||
|
* Fixed data race in system.parts table and ALTER query. This fixes [#6245](https://github.com/yandex/ClickHouse/issues/6245). [#6513](https://github.com/yandex/ClickHouse/pull/6513) ([alexey-milovidov](https://github.com/alexey-milovidov))
|
||||||
|
* Fixed wrong code in mutations that may lead to memory corruption. Fixed segfault with read of address `0x14c0` that may happed due to concurrent `DROP TABLE` and `SELECT` from `system.parts` or `system.parts_columns`. Fixed race condition in preparation of mutation queries. Fixed deadlock caused by `OPTIMIZE` of Replicated tables and concurrent modification operations like ALTERs. [#6514](https://github.com/yandex/ClickHouse/pull/6514) ([alexey-milovidov](https://github.com/alexey-milovidov))
|
||||||
|
|
||||||
## ClickHouse release 19.11.7.40, 2019-08-14
|
## ClickHouse release 19.11.7.40, 2019-08-14
|
||||||
|
|
||||||
### Bug fix
|
### Bug fix
|
||||||
|
255
CMakeLists.txt
255
CMakeLists.txt
@ -1,15 +1,23 @@
|
|||||||
project(ClickHouse)
|
|
||||||
cmake_minimum_required(VERSION 3.3)
|
|
||||||
|
|
||||||
foreach(policy
|
foreach(policy
|
||||||
CMP0023
|
CMP0023
|
||||||
|
CMP0048 # CMake 3.0
|
||||||
CMP0074 # CMake 3.12
|
CMP0074 # CMake 3.12
|
||||||
|
CMP0077
|
||||||
|
CMP0079
|
||||||
)
|
)
|
||||||
if(POLICY ${policy})
|
if(POLICY ${policy})
|
||||||
cmake_policy(SET ${policy} NEW)
|
cmake_policy(SET ${policy} NEW)
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
project(ClickHouse)
|
||||||
|
cmake_minimum_required(VERSION 3.3)
|
||||||
|
|
||||||
|
# Ignore export() since we don't use it,
|
||||||
|
# but it gets broken with a global targets via link_libraries()
|
||||||
|
macro (export)
|
||||||
|
endmacro ()
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS 1) # Write compile_commands.json
|
set(CMAKE_EXPORT_COMPILE_COMMANDS 1) # Write compile_commands.json
|
||||||
set(CMAKE_LINK_DEPENDS_NO_SHARED 1) # Do not relink all depended targets on .so
|
set(CMAKE_LINK_DEPENDS_NO_SHARED 1) # Do not relink all depended targets on .so
|
||||||
@ -128,12 +136,6 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
|||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (GLIBC_COMPATIBILITY)
|
|
||||||
set (USE_INTERNAL_MEMCPY ON)
|
|
||||||
else ()
|
|
||||||
message (WARNING "Option GLIBC_COMPATIBILITY must be turned on for production builds.")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
string(REGEX MATCH "-?[0-9]+(.[0-9]+)?$" COMPILER_POSTFIX ${CMAKE_CXX_COMPILER})
|
string(REGEX MATCH "-?[0-9]+(.[0-9]+)?$" COMPILER_POSTFIX ${CMAKE_CXX_COMPILER})
|
||||||
|
|
||||||
find_program (LLD_PATH NAMES "lld${COMPILER_POSTFIX}" "lld")
|
find_program (LLD_PATH NAMES "lld${COMPILER_POSTFIX}" "lld")
|
||||||
@ -172,20 +174,15 @@ if (ARCH_NATIVE)
|
|||||||
set (COMPILER_FLAGS "${COMPILER_FLAGS} -march=native")
|
set (COMPILER_FLAGS "${COMPILER_FLAGS} -march=native")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Special options for better optimized code with clang
|
|
||||||
#if (COMPILER_CLANG)
|
|
||||||
# set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Wno-unused-command-line-argument -mllvm -inline-threshold=10000")
|
|
||||||
#endif ()
|
|
||||||
|
|
||||||
if (CMAKE_VERSION VERSION_LESS "3.8.0")
|
if (CMAKE_VERSION VERSION_LESS "3.8.0")
|
||||||
if (NOT MSVC)
|
if (NOT MSVC)
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
||||||
endif ()
|
endif ()
|
||||||
else ()
|
else ()
|
||||||
set (CMAKE_CXX_STANDARD 17)
|
set (CMAKE_CXX_STANDARD 17)
|
||||||
set (CMAKE_CXX_EXTENSIONS 0) # https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html#prop_tgt:CXX_EXTENSIONS
|
set (CMAKE_CXX_EXTENSIONS 0) # https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html#prop_tgt:CXX_EXTENSIONS
|
||||||
set (CMAKE_CXX_STANDARD_REQUIRED ON)
|
set (CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set (CXX_FLAGS_INTERNAL_COMPILER "-std=c++1z")
|
set (CXX_FLAGS_INTERNAL_COMPILER "-std=c++17")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (COMPILER_GCC OR COMPILER_CLANG)
|
if (COMPILER_GCC OR COMPILER_CLANG)
|
||||||
@ -207,17 +204,13 @@ endif()
|
|||||||
|
|
||||||
set (CMAKE_BUILD_COLOR_MAKEFILE ON)
|
set (CMAKE_BUILD_COLOR_MAKEFILE ON)
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS} ${PLATFORM_EXTRA_CXX_FLAG} -fno-omit-frame-pointer ${COMMON_WARNING_FLAGS} ${CXX_WARNING_FLAGS}")
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS} ${PLATFORM_EXTRA_CXX_FLAG} -fno-omit-frame-pointer ${COMMON_WARNING_FLAGS} ${CXX_WARNING_FLAGS}")
|
||||||
#set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_ADD}")
|
|
||||||
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 ${CMAKE_CXX_FLAGS_ADD}")
|
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 ${CMAKE_CXX_FLAGS_ADD}")
|
||||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -ggdb3 -fno-inline ${CMAKE_CXX_FLAGS_ADD}")
|
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -ggdb3 -fno-inline ${CMAKE_CXX_FLAGS_ADD}")
|
||||||
|
|
||||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS} -fno-omit-frame-pointer ${COMMON_WARNING_FLAGS} ${CMAKE_C_FLAGS_ADD}")
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS} -fno-omit-frame-pointer ${COMMON_WARNING_FLAGS} ${CMAKE_C_FLAGS_ADD}")
|
||||||
#set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_ADD}")
|
|
||||||
set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3 ${CMAKE_C_FLAGS_ADD}")
|
set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3 ${CMAKE_C_FLAGS_ADD}")
|
||||||
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3 -ggdb3 -fno-inline ${CMAKE_C_FLAGS_ADD}")
|
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3 -ggdb3 -fno-inline ${CMAKE_C_FLAGS_ADD}")
|
||||||
|
|
||||||
# Uses MAKE_STATIC_LIBRARIES
|
|
||||||
|
|
||||||
|
|
||||||
option (UNBUNDLED "Try find all libraries in system. We recommend to avoid this mode for production builds, because we cannot guarantee exact versions and variants of libraries your system has installed. This mode exists for enthusiastic developers who search for trouble. Also it is useful for maintainers of OS packages." OFF)
|
option (UNBUNDLED "Try find all libraries in system. We recommend to avoid this mode for production builds, because we cannot guarantee exact versions and variants of libraries your system has installed. This mode exists for enthusiastic developers who search for trouble. Also it is useful for maintainers of OS packages." OFF)
|
||||||
if (UNBUNDLED)
|
if (UNBUNDLED)
|
||||||
@ -225,150 +218,28 @@ if (UNBUNDLED)
|
|||||||
else ()
|
else ()
|
||||||
set(NOT_UNBUNDLED 1)
|
set(NOT_UNBUNDLED 1)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Using system libs can cause lot of warnings in includes.
|
# Using system libs can cause lot of warnings in includes.
|
||||||
if (UNBUNDLED OR NOT (OS_LINUX OR APPLE) OR ARCH_32)
|
if (UNBUNDLED OR NOT (OS_LINUX OR APPLE) OR ARCH_32)
|
||||||
option (NO_WERROR "Disable -Werror compiler option" ON)
|
option (NO_WERROR "Disable -Werror compiler option" ON)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
# Make this extra-checks for correct library dependencies.
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
if (NOT SANITIZE)
|
||||||
find_package (Threads)
|
|
||||||
|
|
||||||
include (cmake/find_cxx.cmake)
|
|
||||||
|
|
||||||
include (cmake/test_compiler.cmake)
|
|
||||||
|
|
||||||
if (OS_LINUX AND COMPILER_CLANG AND USE_STATIC_LIBRARIES)
|
|
||||||
option (USE_LIBCXX "Use libc++ and libc++abi instead of libstdc++ (only make sense on Linux)" ${HAVE_LIBCXX})
|
|
||||||
|
|
||||||
if (USE_LIBCXX)
|
|
||||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_DEBUG=0") # More checks in debug build.
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (USE_LIBCXX)
|
|
||||||
set (STATIC_STDLIB_FLAGS "")
|
|
||||||
else ()
|
|
||||||
set (STATIC_STDLIB_FLAGS "-static-libgcc -static-libstdc++")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (MAKE_STATIC_LIBRARIES AND NOT APPLE AND NOT (COMPILER_CLANG AND OS_FREEBSD))
|
|
||||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${STATIC_STDLIB_FLAGS}")
|
|
||||||
|
|
||||||
# Along with executables, we also build example of shared library for "library dictionary source"; and it also should be self-contained.
|
|
||||||
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${STATIC_STDLIB_FLAGS}")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (USE_STATIC_LIBRARIES AND HAVE_NO_PIE)
|
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG_NO_PIE}")
|
|
||||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG_NO_PIE}")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# TODO: only make this extra-checks in CI builds, since a lot of contrib libs won't link -
|
|
||||||
# CI works around this problem by explicitly adding GLIBC_COMPATIBILITY flag.
|
|
||||||
if (NOT SANITIZE AND YANDEX_OFFICIAL_BUILD)
|
|
||||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
|
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
|
||||||
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
|
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
include (cmake/find_unwind.cmake)
|
include(cmake/dbms_glob_sources.cmake)
|
||||||
|
include(cmake/default_libs.cmake)
|
||||||
|
|
||||||
if (USE_INTERNAL_UNWIND_LIBRARY)
|
######################################
|
||||||
option (USE_INTERNAL_UNWIND_LIBRARY_FOR_EXCEPTION_HANDLING "Use internal unwind library for exception handling" ${USE_STATIC_LIBRARIES})
|
### Add targets below this comment ###
|
||||||
endif ()
|
######################################
|
||||||
|
|
||||||
|
|
||||||
# Set standard, system and compiler libraries explicitly.
|
|
||||||
# This is intended for more control of what we are linking.
|
|
||||||
|
|
||||||
string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
|
string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
|
||||||
set (CMAKE_POSTFIX_VARIABLE "CMAKE_${CMAKE_BUILD_TYPE_UC}_POSTFIX")
|
set (CMAKE_POSTFIX_VARIABLE "CMAKE_${CMAKE_BUILD_TYPE_UC}_POSTFIX")
|
||||||
|
|
||||||
set (DEFAULT_LIBS "")
|
|
||||||
if (OS_LINUX AND NOT UNBUNDLED AND (GLIBC_COMPATIBILITY OR USE_INTERNAL_UNWIND_LIBRARY_FOR_EXCEPTION_HANDLING OR USE_LIBCXX))
|
|
||||||
# Note: this probably has no effect, but I'm not an expert in CMake.
|
|
||||||
set (CMAKE_C_IMPLICIT_LINK_LIBRARIES "")
|
|
||||||
set (CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
|
|
||||||
|
|
||||||
# Disable default linked libraries.
|
|
||||||
set (DEFAULT_LIBS "-nodefaultlibs")
|
|
||||||
|
|
||||||
# We need builtins from Clang's RT even without libcxx - for ubsan+int128. See https://bugs.llvm.org/show_bug.cgi?id=16404
|
|
||||||
set (BUILTINS_LIB_PATH "")
|
|
||||||
if (COMPILER_CLANG)
|
|
||||||
execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.builtins-${CMAKE_SYSTEM_PROCESSOR}.a OUTPUT_VARIABLE BUILTINS_LIB_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
else ()
|
|
||||||
set (BUILTINS_LIB_PATH "-lgcc")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
|
|
||||||
set (CMAKE_POSTFIX_VARIABLE "CMAKE_${CMAKE_BUILD_TYPE_UC}_POSTFIX")
|
|
||||||
|
|
||||||
# Add C++ libraries.
|
|
||||||
#
|
|
||||||
# This consist of:
|
|
||||||
# - C++ standard library (like implementation of std::string);
|
|
||||||
# - C++ ABI implementation (functions for exceptions like __cxa_throw, RTTI, etc);
|
|
||||||
# - functions for internal implementation of exception handling (stack unwinding based on DWARF info; TODO replace with bundled libunwind);
|
|
||||||
# - compiler builtins (example: functions for implementation of __int128 operations);
|
|
||||||
#
|
|
||||||
# There are two variants of C++ library: libc++ (from LLVM compiler infrastructure) and libstdc++ (from GCC).
|
|
||||||
|
|
||||||
if (USE_INTERNAL_UNWIND_LIBRARY_FOR_EXCEPTION_HANDLING)
|
|
||||||
if (USE_STATIC_LIBRARIES)
|
|
||||||
set (EXCEPTION_HANDLING_LIBRARY "${ClickHouse_BINARY_DIR}/contrib/libunwind-cmake/libunwind_static${${CMAKE_POSTFIX_VARIABLE}}.a")
|
|
||||||
else ()
|
|
||||||
set (EXCEPTION_HANDLING_LIBRARY "${ClickHouse_BINARY_DIR}/contrib/libunwind-cmake/libunwind_shared${${CMAKE_POSTFIX_VARIABLE}}.so")
|
|
||||||
endif ()
|
|
||||||
else ()
|
|
||||||
set (EXCEPTION_HANDLING_LIBRARY "-lgcc_eh")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
message (STATUS "Using exception handling library: ${EXCEPTION_HANDLING_LIBRARY}")
|
|
||||||
|
|
||||||
if (USE_LIBCXX)
|
|
||||||
if (USE_INTERNAL_LIBCXX_LIBRARY)
|
|
||||||
set (LIBCXX_LIBS "${ClickHouse_BINARY_DIR}/contrib/libcxx-cmake/libcxx_static${${CMAKE_POSTFIX_VARIABLE}}.a ${ClickHouse_BINARY_DIR}/contrib/libcxxabi-cmake/libcxxabi_static${${CMAKE_POSTFIX_VARIABLE}}.a")
|
|
||||||
else ()
|
|
||||||
set (LIBCXX_LIBS "-lc++ -lc++abi -lc++fs")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
set (DEFAULT_LIBS "${DEFAULT_LIBS} -Wl,-Bstatic ${LIBCXX_LIBS} ${EXCEPTION_HANDLING_LIBRARY} ${BUILTINS_LIB_PATH} -Wl,-Bdynamic")
|
|
||||||
else ()
|
|
||||||
set (DEFAULT_LIBS "${DEFAULT_LIBS} -Wl,-Bstatic -lstdc++ -lstdc++fs ${EXCEPTION_HANDLING_LIBRARY} ${COVERAGE_OPTION} ${BUILTINS_LIB_PATH} -Wl,-Bdynamic")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# Linking with GLIBC prevents portability of binaries to older systems.
|
|
||||||
# We overcome this behaviour by statically linking with our own implementation of all new symbols (that don't exist in older Libc or have infamous "symbol versioning").
|
|
||||||
# The order of linking is important: 'glibc-compatibility' must be before libc but after all other libraries.
|
|
||||||
if (GLIBC_COMPATIBILITY)
|
|
||||||
message (STATUS "Some symbols from glibc will be replaced for compatibility")
|
|
||||||
|
|
||||||
string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
|
|
||||||
set (CMAKE_POSTFIX_VARIABLE "CMAKE_${CMAKE_BUILD_TYPE_UC}_POSTFIX")
|
|
||||||
|
|
||||||
# FIXME: glibc-compatibility may be non-static in some builds!
|
|
||||||
set (DEFAULT_LIBS "${DEFAULT_LIBS} ${ClickHouse_BINARY_DIR}/libs/libglibc-compatibility/libglibc-compatibility${${CMAKE_POSTFIX_VARIABLE}}.a")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# Add Libc. GLIBC is actually a collection of interdependent libraries.
|
|
||||||
set (DEFAULT_LIBS "${DEFAULT_LIBS} -lrt -ldl -lpthread -lm -lc")
|
|
||||||
|
|
||||||
# Note: we'd rather use Musl libc library, but it's little bit more difficult to use.
|
|
||||||
|
|
||||||
message(STATUS "Default libraries: ${DEFAULT_LIBS}")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (NOT GLIBC_COMPATIBILITY)
|
|
||||||
set (M_LIBRARY m)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (DEFAULT_LIBS)
|
|
||||||
# Add default libs to all targets as the last dependency.
|
|
||||||
set(CMAKE_CXX_STANDARD_LIBRARIES ${DEFAULT_LIBS})
|
|
||||||
set(CMAKE_C_STANDARD_LIBRARIES ${DEFAULT_LIBS})
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (NOT MAKE_STATIC_LIBRARIES)
|
if (NOT MAKE_STATIC_LIBRARIES)
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
endif ()
|
endif ()
|
||||||
@ -421,20 +292,12 @@ if (UNBUNDLED)
|
|||||||
else ()
|
else ()
|
||||||
set(NOT_UNBUNDLED 1)
|
set(NOT_UNBUNDLED 1)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Using system libs can cause lot of warnings in includes.
|
# Using system libs can cause lot of warnings in includes.
|
||||||
if (UNBUNDLED OR NOT (OS_LINUX OR APPLE) OR ARCH_32)
|
if (UNBUNDLED OR NOT (OS_LINUX OR APPLE) OR ARCH_32)
|
||||||
option (NO_WERROR "Disable -Werror compiler option" ON)
|
option (NO_WERROR "Disable -Werror compiler option" ON)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (USE_LIBCXX)
|
|
||||||
set (HAVE_LIBCXX 1)
|
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (USE_LIBCXX AND USE_INTERNAL_LIBCXX_LIBRARY)
|
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++ -isystem ${LIBCXX_INCLUDE_DIR} -isystem ${LIBCXXABI_INCLUDE_DIR}")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
message (STATUS "Building for: ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_LIBRARY_ARCHITECTURE} ; USE_STATIC_LIBRARIES=${USE_STATIC_LIBRARIES} MAKE_STATIC_LIBRARIES=${MAKE_STATIC_LIBRARIES} SPLIT_SHARED=${SPLIT_SHARED_LIBRARIES} UNBUNDLED=${UNBUNDLED} CCACHE=${CCACHE_FOUND} ${CCACHE_VERSION}")
|
message (STATUS "Building for: ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_LIBRARY_ARCHITECTURE} ; USE_STATIC_LIBRARIES=${USE_STATIC_LIBRARIES} MAKE_STATIC_LIBRARIES=${MAKE_STATIC_LIBRARIES} SPLIT_SHARED=${SPLIT_SHARED_LIBRARIES} UNBUNDLED=${UNBUNDLED} CCACHE=${CCACHE_FOUND} ${CCACHE_VERSION}")
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
@ -477,10 +340,10 @@ include (cmake/find_consistent-hashing.cmake)
|
|||||||
include (cmake/find_base64.cmake)
|
include (cmake/find_base64.cmake)
|
||||||
include (cmake/find_parquet.cmake)
|
include (cmake/find_parquet.cmake)
|
||||||
include (cmake/find_hyperscan.cmake)
|
include (cmake/find_hyperscan.cmake)
|
||||||
include (cmake/find_mimalloc.cmake)
|
|
||||||
include (cmake/find_simdjson.cmake)
|
include (cmake/find_simdjson.cmake)
|
||||||
include (cmake/find_rapidjson.cmake)
|
include (cmake/find_rapidjson.cmake)
|
||||||
include (cmake/find_fastops.cmake)
|
include (cmake/find_fastops.cmake)
|
||||||
|
include (cmake/find_orc.cmake)
|
||||||
|
|
||||||
find_contrib_lib(cityhash)
|
find_contrib_lib(cityhash)
|
||||||
find_contrib_lib(farmhash)
|
find_contrib_lib(farmhash)
|
||||||
@ -499,79 +362,11 @@ include (libs/libmysqlxx/cmake/find_mysqlclient.cmake)
|
|||||||
|
|
||||||
include (cmake/print_flags.cmake)
|
include (cmake/print_flags.cmake)
|
||||||
|
|
||||||
|
install (EXPORT global DESTINATION cmake)
|
||||||
|
|
||||||
add_subdirectory (contrib EXCLUDE_FROM_ALL)
|
add_subdirectory (contrib EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory (libs)
|
add_subdirectory (libs)
|
||||||
add_subdirectory (utils)
|
add_subdirectory (utils)
|
||||||
add_subdirectory (dbms)
|
add_subdirectory (dbms)
|
||||||
|
|
||||||
include (cmake/print_include_directories.cmake)
|
include (cmake/print_include_directories.cmake)
|
||||||
|
|
||||||
if (GLIBC_COMPATIBILITY OR USE_INTERNAL_UNWIND_LIBRARY_FOR_EXCEPTION_HANDLING)
|
|
||||||
# FIXME: actually glibc-compatibility should always be built first,
|
|
||||||
# because it's unconditionally linked via $DEFAULT_LIBS,
|
|
||||||
# and these looks like the first places that get linked.
|
|
||||||
function (add_default_dependencies target_name)
|
|
||||||
if (TARGET ${target_name})
|
|
||||||
if (GLIBC_COMPATIBILITY)
|
|
||||||
add_dependencies(${target_name} glibc-compatibility)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (USE_LIBCXX AND USE_INTERNAL_LIBCXX_LIBRARY)
|
|
||||||
add_dependencies(${target_name} cxx_static cxxabi_static)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (USE_INTERNAL_UNWIND_LIBRARY_FOR_EXCEPTION_HANDLING)
|
|
||||||
add_dependencies(${target_name} unwind_static)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
endfunction ()
|
|
||||||
|
|
||||||
add_default_dependencies(ltdl)
|
|
||||||
add_default_dependencies(zlibstatic)
|
|
||||||
add_default_dependencies(jemalloc)
|
|
||||||
add_default_dependencies(memcpy)
|
|
||||||
add_default_dependencies(Foundation)
|
|
||||||
add_default_dependencies(common)
|
|
||||||
add_default_dependencies(gtest)
|
|
||||||
add_default_dependencies(lz4)
|
|
||||||
add_default_dependencies(zstd)
|
|
||||||
add_default_dependencies(snappy)
|
|
||||||
add_default_dependencies(arrow)
|
|
||||||
add_default_dependencies(protoc)
|
|
||||||
add_default_dependencies(thrift_static)
|
|
||||||
add_default_dependencies(cityhash)
|
|
||||||
add_default_dependencies(farmhash)
|
|
||||||
add_default_dependencies(murmurhash)
|
|
||||||
add_default_dependencies(metrohash)
|
|
||||||
add_default_dependencies(metrohash128)
|
|
||||||
add_default_dependencies(consistent-hashing)
|
|
||||||
add_default_dependencies(double-conversion)
|
|
||||||
add_default_dependencies(cctz)
|
|
||||||
add_default_dependencies(kj)
|
|
||||||
add_default_dependencies(simdjson)
|
|
||||||
add_default_dependencies(apple_rt)
|
|
||||||
add_default_dependencies(h3)
|
|
||||||
add_default_dependencies(re2)
|
|
||||||
add_default_dependencies(re2_st)
|
|
||||||
add_default_dependencies(hs_compile_shared)
|
|
||||||
add_default_dependencies(hs_exec_shared)
|
|
||||||
add_default_dependencies(hs_shared)
|
|
||||||
add_default_dependencies(widechar_width)
|
|
||||||
add_default_dependencies(string_utils)
|
|
||||||
add_default_dependencies(consistent-hashing-sumbur)
|
|
||||||
add_default_dependencies(boost_program_options_internal)
|
|
||||||
add_default_dependencies(boost_system_internal)
|
|
||||||
add_default_dependencies(boost_regex_internal)
|
|
||||||
add_default_dependencies(roaring)
|
|
||||||
add_default_dependencies(btrie)
|
|
||||||
add_default_dependencies(cpuid)
|
|
||||||
add_default_dependencies(mysqlclient)
|
|
||||||
add_default_dependencies(zlib)
|
|
||||||
add_default_dependencies(thrift)
|
|
||||||
add_default_dependencies(brotli)
|
|
||||||
add_default_dependencies(libprotobuf)
|
|
||||||
add_default_dependencies(base64)
|
|
||||||
add_default_dependencies(readpassphrase)
|
|
||||||
add_default_dependencies(unwind_static)
|
|
||||||
add_default_dependencies(fastops)
|
|
||||||
endif ()
|
|
||||||
|
@ -14,6 +14,7 @@ ClickHouse is an open-source column-oriented database management system that all
|
|||||||
|
|
||||||
## Upcoming Events
|
## Upcoming Events
|
||||||
* [ClickHouse Meetup in Moscow](https://yandex.ru/promo/clickhouse/moscow-2019) on September 5.
|
* [ClickHouse Meetup in Moscow](https://yandex.ru/promo/clickhouse/moscow-2019) on September 5.
|
||||||
|
* [ClickHouse Meetup in Munich](https://www.meetup.com/ClickHouse-Meetup-Munich/events/264185199/) on September 17.
|
||||||
* [ClickHouse Meetup in Paris](https://www.eventbrite.com/e/clickhouse-paris-meetup-2019-registration-68493270215) on October 3.
|
* [ClickHouse Meetup in Paris](https://www.eventbrite.com/e/clickhouse-paris-meetup-2019-registration-68493270215) on October 3.
|
||||||
* [ClickHouse Meetup in Hong Kong](https://www.meetup.com/Hong-Kong-Machine-Learning-Meetup/events/263580542/) on October 17.
|
* [ClickHouse Meetup in Hong Kong](https://www.meetup.com/Hong-Kong-Machine-Learning-Meetup/events/263580542/) on October 17.
|
||||||
* [ClickHouse Meetup in Shenzhen](https://www.huodongxing.com/event/3483759917300) on October 20.
|
* [ClickHouse Meetup in Shenzhen](https://www.huodongxing.com/event/3483759917300) on October 20.
|
||||||
|
48
cmake/default_libs.cmake
Normal file
48
cmake/default_libs.cmake
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# Set standard, system and compiler libraries explicitly.
|
||||||
|
# This is intended for more control of what we are linking.
|
||||||
|
|
||||||
|
set (DEFAULT_LIBS "-nodefaultlibs")
|
||||||
|
|
||||||
|
if (OS_LINUX)
|
||||||
|
# We need builtins from Clang's RT even without libcxx - for ubsan+int128.
|
||||||
|
# See https://bugs.llvm.org/show_bug.cgi?id=16404
|
||||||
|
if (COMPILER_CLANG)
|
||||||
|
execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.builtins-${CMAKE_SYSTEM_PROCESSOR}.a OUTPUT_VARIABLE BUILTINS_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
else ()
|
||||||
|
set (BUILTINS_LIBRARY "-lgcc")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set (DEFAULT_LIBS "${DEFAULT_LIBS} ${BUILTINS_LIBRARY} ${COVERAGE_OPTION} -lc -lm -lrt -lpthread -ldl")
|
||||||
|
|
||||||
|
message(STATUS "Default libraries: ${DEFAULT_LIBS}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD_LIBRARIES ${DEFAULT_LIBS})
|
||||||
|
set(CMAKE_C_STANDARD_LIBRARIES ${DEFAULT_LIBS})
|
||||||
|
|
||||||
|
# Global libraries
|
||||||
|
|
||||||
|
add_library(global-libs INTERFACE)
|
||||||
|
|
||||||
|
# Unfortunately '-pthread' doesn't work with '-nodefaultlibs'.
|
||||||
|
# Just make sure we have pthreads at all.
|
||||||
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
|
add_subdirectory(libs/libglibc-compatibility)
|
||||||
|
include (cmake/find_unwind.cmake)
|
||||||
|
include (cmake/find_cxx.cmake)
|
||||||
|
|
||||||
|
add_library(global-group INTERFACE)
|
||||||
|
target_link_libraries(global-group INTERFACE
|
||||||
|
-Wl,--start-group
|
||||||
|
$<TARGET_PROPERTY:global-libs,INTERFACE_LINK_LIBRARIES>
|
||||||
|
-Wl,--end-group
|
||||||
|
)
|
||||||
|
|
||||||
|
link_libraries(global-group)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS global-group global-libs
|
||||||
|
EXPORT global
|
||||||
|
)
|
@ -1,50 +1,20 @@
|
|||||||
option (ENABLE_CAPNP "Enable Cap'n Proto" ON)
|
option (USE_CAPNP "Enable Cap'n Proto" ON)
|
||||||
|
|
||||||
if (ENABLE_CAPNP)
|
|
||||||
# cmake 3.5.1 bug:
|
|
||||||
# capnproto uses this cmake feature:
|
|
||||||
# target_compile_features(kj PUBLIC cxx_constexpr)
|
|
||||||
# old cmake adds -std=gnu++11 to end of all compile commands (even if -std=gnu++17 already present in compile string)
|
|
||||||
# cmake 3.9.1 (ubuntu artful) have no this bug (c++17 support added to cmake 3.8.2)
|
|
||||||
if (CMAKE_VERSION VERSION_LESS "3.8.0")
|
|
||||||
set (USE_INTERNAL_CAPNP_LIBRARY_DEFAULT 0)
|
|
||||||
set (MISSING_INTERNAL_CAPNP_LIBRARY 1)
|
|
||||||
else ()
|
|
||||||
set (USE_INTERNAL_CAPNP_LIBRARY_DEFAULT ${NOT_UNBUNDLED})
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
option (USE_INTERNAL_CAPNP_LIBRARY "Set to FALSE to use system capnproto library instead of bundled" ${USE_INTERNAL_CAPNP_LIBRARY_DEFAULT})
|
|
||||||
|
|
||||||
if (NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/capnproto/c++/CMakeLists.txt")
|
|
||||||
if (USE_INTERNAL_CAPNP_LIBRARY)
|
|
||||||
message (WARNING "submodule contrib/capnproto is missing. to fix try run: \n git submodule update --init --recursive")
|
|
||||||
endif ()
|
|
||||||
set (USE_INTERNAL_CAPNP_LIBRARY 0)
|
|
||||||
set (MISSING_INTERNAL_CAPNP_LIBRARY 1)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (NOT USE_INTERNAL_CAPNP_LIBRARY)
|
|
||||||
set (CAPNP_PATHS "/usr/local/opt/capnp/lib")
|
|
||||||
set (CAPNP_INCLUDE_PATHS "/usr/local/opt/capnp/include")
|
|
||||||
find_library (CAPNP capnp PATHS ${CAPNP_PATHS})
|
|
||||||
find_library (CAPNPC capnpc PATHS ${CAPNP_PATHS})
|
|
||||||
find_library (KJ kj PATHS ${CAPNP_PATHS})
|
|
||||||
set (CAPNP_LIBRARY ${CAPNPC} ${CAPNP} ${KJ})
|
|
||||||
find_path (CAPNP_INCLUDE_DIR NAMES capnp/schema-parser.h PATHS ${CAPNP_INCLUDE_PATHS})
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (CAPNP_INCLUDE_DIR AND CAPNP_LIBRARY)
|
|
||||||
set(USE_CAPNP 1)
|
|
||||||
elseif (NOT MISSING_INTERNAL_CAPNP_LIBRARY)
|
|
||||||
set (USE_INTERNAL_CAPNP_LIBRARY 1)
|
|
||||||
set (CAPNP_INCLUDE_DIR "${ClickHouse_SOURCE_DIR}/contrib/capnproto/c++/src")
|
|
||||||
set (CAPNP_LIBRARY capnpc)
|
|
||||||
set (USE_CAPNP 1)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (USE_CAPNP)
|
if (USE_CAPNP)
|
||||||
message (STATUS "Using capnp=${USE_CAPNP}: ${CAPNP_INCLUDE_DIR} : ${CAPNP_LIBRARY}")
|
option (USE_INTERNAL_CAPNP_LIBRARY "Set to FALSE to use system capnproto library instead of bundled" ${NOT_UNBUNDLED})
|
||||||
else ()
|
|
||||||
message (STATUS "Build without capnp (support for Cap'n Proto format will be disabled)")
|
# FIXME: refactor to use `add_library(… IMPORTED)` if possible.
|
||||||
|
if (NOT USE_INTERNAL_CAPNP_LIBRARY)
|
||||||
|
find_library (KJ kj)
|
||||||
|
find_library (CAPNP capnp)
|
||||||
|
find_library (CAPNPC capnpc)
|
||||||
|
|
||||||
|
set (CAPNP_LIBRARIES ${CAPNPC} ${CAPNP} ${KJ})
|
||||||
|
else ()
|
||||||
|
add_subdirectory(contrib/capnproto-cmake)
|
||||||
|
|
||||||
|
set (CAPNP_LIBRARIES capnpc)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
message (STATUS "Using capnp: ${CAPNP_LIBRARIES}")
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
find_program (CCACHE_FOUND ccache)
|
find_program (CCACHE_FOUND ccache)
|
||||||
|
|
||||||
if (CCACHE_FOUND AND NOT CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache" AND NOT CMAKE_CXX_COMPILER MATCHES "ccache")
|
if (CCACHE_FOUND AND NOT CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache" AND NOT CMAKE_CXX_COMPILER MATCHES "ccache")
|
||||||
execute_process(COMMAND ${CCACHE_FOUND} "-V" OUTPUT_VARIABLE CCACHE_VERSION)
|
execute_process(COMMAND ${CCACHE_FOUND} "-V" OUTPUT_VARIABLE CCACHE_VERSION)
|
||||||
string(REGEX REPLACE "ccache version ([0-9\\.]+).*" "\\1" CCACHE_VERSION ${CCACHE_VERSION})
|
string(REGEX REPLACE "ccache version ([0-9\\.]+).*" "\\1" CCACHE_VERSION ${CCACHE_VERSION})
|
||||||
|
@ -1,26 +1,50 @@
|
|||||||
if (NOT APPLE)
|
if (OS_LINUX AND COMPILER_CLANG)
|
||||||
|
option (USE_LIBCXX "Use libc++ and libc++abi instead of libstdc++" ON)
|
||||||
option (USE_INTERNAL_LIBCXX_LIBRARY "Set to FALSE to use system libcxx and libcxxabi libraries instead of bundled" ${NOT_UNBUNDLED})
|
option (USE_INTERNAL_LIBCXX_LIBRARY "Set to FALSE to use system libcxx and libcxxabi libraries instead of bundled" ${NOT_UNBUNDLED})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (USE_LIBCXX)
|
||||||
|
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_DEBUG=0") # More checks in debug build.
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
# FIXME: make better check for submodule presence
|
||||||
if (USE_INTERNAL_LIBCXX_LIBRARY AND NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/libcxx/include/vector")
|
if (USE_INTERNAL_LIBCXX_LIBRARY AND NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/libcxx/include/vector")
|
||||||
message (WARNING "submodule contrib/libcxx is missing. to fix try run: \n git submodule update --init --recursive")
|
message (WARNING "submodule contrib/libcxx is missing. to fix try run: \n git submodule update --init --recursive")
|
||||||
set (USE_INTERNAL_LIBCXX_LIBRARY 0)
|
set (USE_INTERNAL_LIBCXX_LIBRARY 0)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
# FIXME: make better check for submodule presence
|
||||||
if (USE_INTERNAL_LIBCXX_LIBRARY AND NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/libcxxabi/src")
|
if (USE_INTERNAL_LIBCXX_LIBRARY AND NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/libcxxabi/src")
|
||||||
message (WARNING "submodule contrib/libcxxabi is missing. to fix try run: \n git submodule update --init --recursive")
|
message (WARNING "submodule contrib/libcxxabi is missing. to fix try run: \n git submodule update --init --recursive")
|
||||||
set (USE_INTERNAL_LIBCXXABI_LIBRARY 0)
|
set (USE_INTERNAL_LIBCXX_LIBRARY 0)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT USE_INTERNAL_LIBCXX_LIBRARY)
|
if (USE_LIBCXX)
|
||||||
|
if (NOT USE_INTERNAL_LIBCXX_LIBRARY)
|
||||||
find_library (LIBCXX_LIBRARY c++)
|
find_library (LIBCXX_LIBRARY c++)
|
||||||
|
find_library (LIBCXXFS_LIBRARY c++fs)
|
||||||
find_library (LIBCXXABI_LIBRARY c++abi)
|
find_library (LIBCXXABI_LIBRARY c++abi)
|
||||||
else ()
|
|
||||||
set (LIBCXX_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxx/include)
|
|
||||||
set (LIBCXXABI_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxxabi/include)
|
|
||||||
set (LIBCXX_LIBRARY cxx_static)
|
|
||||||
set (LIBCXXABI_LIBRARY cxxabi_static)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
message (STATUS "Using libcxx: ${LIBCXX_LIBRARY}")
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||||
message (STATUS "Using libcxxabi: ${LIBCXXABI_LIBRARY}")
|
|
||||||
|
target_link_libraries(global-libs INTERFACE ${EXCEPTION_HANDLING_LIBRARY})
|
||||||
|
else ()
|
||||||
|
set (LIBCXX_LIBRARY cxx)
|
||||||
|
set (LIBCXXABI_LIBRARY cxxabi)
|
||||||
|
add_subdirectory(contrib/libcxxabi-cmake)
|
||||||
|
add_subdirectory(contrib/libcxx-cmake)
|
||||||
|
|
||||||
|
# Exception handling library is embedded into libcxxabi.
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
target_link_libraries(global-libs INTERFACE ${LIBCXX_LIBRARY} ${LIBCXXABI_LIBRARY} ${LIBCXXFS_LIBRARY})
|
||||||
|
|
||||||
|
set (HAVE_LIBCXX 1)
|
||||||
|
|
||||||
|
message (STATUS "Using libcxx: ${LIBCXX_LIBRARY}")
|
||||||
|
message (STATUS "Using libcxxfs: ${LIBCXXFS_LIBRARY}")
|
||||||
|
message (STATUS "Using libcxxabi: ${LIBCXXABI_LIBRARY}")
|
||||||
|
else ()
|
||||||
|
target_link_libraries(global-libs INTERFACE -l:libstdc++.a -l:libstdc++fs.a) # Always link these libraries as static
|
||||||
|
target_link_libraries(global-libs INTERFACE ${EXCEPTION_HANDLING_LIBRARY})
|
||||||
|
endif ()
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
if (OS_LINUX AND NOT SANITIZE AND NOT ARCH_ARM AND NOT ARCH_32 AND NOT ARCH_PPC64LE)
|
|
||||||
option (ENABLE_MIMALLOC "Set to FALSE to disable usage of mimalloc for internal ClickHouse caches" FALSE)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/mimalloc/include/mimalloc.h")
|
|
||||||
message (WARNING "submodule contrib/mimalloc is missing. to fix try run: \n git submodule update --init --recursive")
|
|
||||||
return()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (ENABLE_MIMALLOC)
|
|
||||||
message (FATAL_ERROR "Mimalloc is not production ready. (Disable with cmake -D ENABLE_MIMALLOC=0). If you want to use mimalloc, you must manually remove this message.")
|
|
||||||
|
|
||||||
set (MIMALLOC_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/mimalloc/include)
|
|
||||||
set (USE_MIMALLOC 1)
|
|
||||||
set (MIMALLOC_LIBRARY mimalloc-static)
|
|
||||||
message (STATUS "Using mimalloc: ${MIMALLOC_INCLUDE_DIR} : ${MIMALLOC_LIBRARY}")
|
|
||||||
endif ()
|
|
8
cmake/find_orc.cmake
Normal file
8
cmake/find_orc.cmake
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
##TODO replace hardcode to find procedure
|
||||||
|
|
||||||
|
set(USE_ORC 0)
|
||||||
|
set(USE_INTERNAL_ORC_LIBRARY ON)
|
||||||
|
|
||||||
|
if (ARROW_LIBRARY)
|
||||||
|
set(USE_ORC 1)
|
||||||
|
endif()
|
@ -1,59 +1,17 @@
|
|||||||
include (CMakePushCheckState)
|
option (USE_UNWIND "Enable libunwind (better stacktraces)" ON)
|
||||||
cmake_push_check_state ()
|
|
||||||
|
|
||||||
option (ENABLE_UNWIND "Enable libunwind (better stacktraces)" ON)
|
if (NOT CMAKE_SYSTEM MATCHES "Linux" OR ARCH_ARM OR ARCH_32)
|
||||||
|
set (USE_UNWIND OFF)
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (ENABLE_UNWIND)
|
if (USE_UNWIND)
|
||||||
|
add_subdirectory(contrib/libunwind-cmake)
|
||||||
|
set (UNWIND_LIBRARIES unwind)
|
||||||
|
set (EXCEPTION_HANDLING_LIBRARY ${UNWIND_LIBRARIES})
|
||||||
|
|
||||||
if (CMAKE_SYSTEM MATCHES "Linux" AND NOT ARCH_ARM AND NOT ARCH_32)
|
message (STATUS "Using libunwind: ${UNWIND_LIBRARIES}")
|
||||||
option (USE_INTERNAL_UNWIND_LIBRARY "Set to FALSE to use system unwind library instead of bundled" ${NOT_UNBUNDLED})
|
|
||||||
else ()
|
else ()
|
||||||
option (USE_INTERNAL_UNWIND_LIBRARY "Set to FALSE to use system unwind library instead of bundled" OFF)
|
set (EXCEPTION_HANDLING_LIBRARY gcc_eh)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT USE_INTERNAL_UNWIND_LIBRARY)
|
message (STATUS "Using exception handler: ${EXCEPTION_HANDLING_LIBRARY}")
|
||||||
find_library (UNWIND_LIBRARY unwind)
|
|
||||||
find_path (UNWIND_INCLUDE_DIR NAMES unwind.h PATHS ${UNWIND_INCLUDE_PATHS})
|
|
||||||
|
|
||||||
include (CheckCXXSourceCompiles)
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${UNWIND_INCLUDE_DIR})
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES ${UNWIND_LIBRARY})
|
|
||||||
check_cxx_source_compiles("
|
|
||||||
#include <ucontext.h>
|
|
||||||
#define UNW_LOCAL_ONLY
|
|
||||||
#include <libunwind.h>
|
|
||||||
int main () {
|
|
||||||
ucontext_t context;
|
|
||||||
unw_cursor_t cursor;
|
|
||||||
unw_init_local(&cursor, &context);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
" HAVE_UNW_INIT_LOCAL)
|
|
||||||
if (NOT HAVE_UNW_INIT_LOCAL)
|
|
||||||
set(UNWIND_LIBRARY "")
|
|
||||||
set(UNWIND_INCLUDE_DIR "")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (UNWIND_LIBRARY AND UNWIND_INCLUDE_DIR)
|
|
||||||
set (USE_UNWIND 1)
|
|
||||||
elseif (CMAKE_SYSTEM MATCHES "Linux" AND NOT ARCH_ARM AND NOT ARCH_32 AND NOT UNBUNDLED)
|
|
||||||
set (USE_INTERNAL_UNWIND_LIBRARY 1)
|
|
||||||
|
|
||||||
set (PACKAGE_VERSION "9.0.0svn" CACHE STRING "")
|
|
||||||
|
|
||||||
set (UNWIND_INCLUDE_DIR "${ClickHouse_SOURCE_DIR}/contrib/libunwind/include")
|
|
||||||
|
|
||||||
set (LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
|
|
||||||
set (LIBUNWIND_ENABLE_STATIC ON CACHE BOOL "")
|
|
||||||
set (UNWIND_LIBRARY unwind_static)
|
|
||||||
|
|
||||||
set (USE_UNWIND 1)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
message (STATUS "Using unwind=${USE_UNWIND}: ${UNWIND_INCLUDE_DIR} : ${UNWIND_LIBRARY}")
|
|
||||||
|
|
||||||
cmake_pop_check_state ()
|
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
include (CheckCXXSourceCompiles)
|
|
||||||
include (CMakePushCheckState)
|
|
||||||
|
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
||||||
find_package(Threads)
|
|
||||||
|
|
||||||
cmake_push_check_state ()
|
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
||||||
# clang4 : -no-pie cause error
|
|
||||||
# clang6 : -no-pie cause warning
|
|
||||||
|
|
||||||
if (MAKE_STATIC_LIBRARIES)
|
|
||||||
set (TEST_FLAG "-Wl,-Bstatic -stdlib=libc++ -lc++ -lc++abi -Wl,-Bdynamic")
|
|
||||||
else ()
|
|
||||||
set (TEST_FLAG "-stdlib=libc++ -lc++ -lc++abi")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
set (CMAKE_REQUIRED_FLAGS "${TEST_FLAG}")
|
|
||||||
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} Threads::Threads)
|
|
||||||
|
|
||||||
check_cxx_source_compiles("
|
|
||||||
#include <iostream>
|
|
||||||
int main() {
|
|
||||||
std::cerr << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
" HAVE_LIBCXX)
|
|
||||||
|
|
||||||
else ()
|
|
||||||
|
|
||||||
set (TEST_FLAG "-no-pie")
|
|
||||||
set (CMAKE_REQUIRED_FLAGS "${TEST_FLAG}")
|
|
||||||
|
|
||||||
check_cxx_source_compiles("
|
|
||||||
int main() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
" HAVE_NO_PIE)
|
|
||||||
|
|
||||||
if (HAVE_NO_PIE)
|
|
||||||
set (FLAG_NO_PIE ${TEST_FLAG})
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
cmake_pop_check_state ()
|
|
29
contrib/CMakeLists.txt
vendored
29
contrib/CMakeLists.txt
vendored
@ -10,17 +10,19 @@ endif ()
|
|||||||
|
|
||||||
set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL 1)
|
set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL 1)
|
||||||
|
|
||||||
|
if (USE_INTERNAL_ORC_LIBRARY)
|
||||||
if (USE_INTERNAL_UNWIND_LIBRARY)
|
set(BUILD_JAVA OFF)
|
||||||
add_subdirectory (libunwind-cmake)
|
set (ANALYZE_JAVA OFF)
|
||||||
endif ()
|
set (BUILD_CPP_TESTS OFF)
|
||||||
|
set (BUILD_TOOLS OFF)
|
||||||
if (USE_LIBCXX AND USE_INTERNAL_LIBCXX_LIBRARY)
|
option(BUILD_JAVA OFF)
|
||||||
add_subdirectory(libcxx-cmake)
|
option (ANALYZE_JAVA OFF)
|
||||||
add_subdirectory(libcxxabi-cmake)
|
option (BUILD_CPP_TESTS OFF)
|
||||||
|
option (BUILD_TOOLS OFF)
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/contrib/orc/cmake_modules")
|
||||||
|
add_subdirectory(orc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if (USE_INTERNAL_BOOST_LIBRARY)
|
if (USE_INTERNAL_BOOST_LIBRARY)
|
||||||
add_subdirectory (boost-cmake)
|
add_subdirectory (boost-cmake)
|
||||||
endif ()
|
endif ()
|
||||||
@ -160,15 +162,6 @@ if (ENABLE_ODBC AND USE_INTERNAL_ODBC_LIBRARY)
|
|||||||
add_library(ODBC::ODBC ALIAS ${ODBC_LIBRARIES})
|
add_library(ODBC::ODBC ALIAS ${ODBC_LIBRARIES})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (ENABLE_CAPNP AND USE_INTERNAL_CAPNP_LIBRARY)
|
|
||||||
set (BUILD_TESTING 0 CACHE INTERNAL "")
|
|
||||||
set (_save ${CMAKE_CXX_EXTENSIONS})
|
|
||||||
set (CMAKE_CXX_EXTENSIONS)
|
|
||||||
add_subdirectory (capnproto/c++)
|
|
||||||
set (CMAKE_CXX_EXTENSIONS ${_save})
|
|
||||||
target_include_directories(${CAPNP_LIBRARY} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/capnproto/c++/src>)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (USE_INTERNAL_PARQUET_LIBRARY)
|
if (USE_INTERNAL_PARQUET_LIBRARY)
|
||||||
if (USE_INTERNAL_PARQUET_LIBRARY_NATIVE_CMAKE)
|
if (USE_INTERNAL_PARQUET_LIBRARY_NATIVE_CMAKE)
|
||||||
# We dont use arrow's cmakefiles because they uses too many depends and download some libs in compile time
|
# We dont use arrow's cmakefiles because they uses too many depends and download some libs in compile time
|
||||||
|
@ -44,9 +44,73 @@ set( thriftcpp_threads_SOURCES
|
|||||||
add_library(${THRIFT_LIBRARY} ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
|
add_library(${THRIFT_LIBRARY} ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
|
||||||
set_target_properties(${THRIFT_LIBRARY} PROPERTIES CXX_STANDARD 14) # REMOVE after https://github.com/apache/thrift/pull/1641
|
set_target_properties(${THRIFT_LIBRARY} PROPERTIES CXX_STANDARD 14) # REMOVE after https://github.com/apache/thrift/pull/1641
|
||||||
target_include_directories(${THRIFT_LIBRARY} SYSTEM PUBLIC ${ClickHouse_SOURCE_DIR}/contrib/thrift/lib/cpp/src PRIVATE ${Boost_INCLUDE_DIRS})
|
target_include_directories(${THRIFT_LIBRARY} SYSTEM PUBLIC ${ClickHouse_SOURCE_DIR}/contrib/thrift/lib/cpp/src PRIVATE ${Boost_INCLUDE_DIRS})
|
||||||
target_link_libraries(${THRIFT_LIBRARY} PRIVATE Threads::Threads)
|
|
||||||
|
|
||||||
|
|
||||||
|
# === orc
|
||||||
|
|
||||||
|
set(ORC_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/orc/c++)
|
||||||
|
set(ORC_INCLUDE_DIR ${ORC_SOURCE_DIR}/include)
|
||||||
|
set(ORC_SOURCE_SRC_DIR ${ORC_SOURCE_DIR}/src)
|
||||||
|
set(ORC_SOURCE_WRAP_DIR ${ORC_SOURCE_DIR}/wrap)
|
||||||
|
|
||||||
|
set(ORC_BUILD_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/../orc/c++/src)
|
||||||
|
set(ORC_BUILD_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/../orc/c++/include)
|
||||||
|
|
||||||
|
set(GOOGLE_PROTOBUF_DIR ${ClickHouse_SOURCE_DIR}/contrib/protobuf/src/)
|
||||||
|
set(ORC_ADDITION_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
set(ARROW_SRC_DIR ${ClickHouse_SOURCE_DIR}/contrib/arrow/cpp/src)
|
||||||
|
|
||||||
|
set(PROTOBUF_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/../protobuf/cmake/protoc)
|
||||||
|
set(PROTO_DIR ${ORC_SOURCE_DIR}/../proto)
|
||||||
|
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT orc_proto.pb.h orc_proto.pb.cc
|
||||||
|
COMMAND ${PROTOBUF_EXECUTABLE}
|
||||||
|
-I ${PROTO_DIR}
|
||||||
|
--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
"${PROTO_DIR}/orc_proto.proto")
|
||||||
|
|
||||||
|
include_directories(SYSTEM ${ORC_INCLUDE_DIR})
|
||||||
|
include_directories(SYSTEM ${ORC_SOURCE_SRC_DIR})
|
||||||
|
include_directories(SYSTEM ${ORC_SOURCE_WRAP_DIR})
|
||||||
|
include_directories(SYSTEM ${GOOGLE_PROTOBUF_DIR})
|
||||||
|
include_directories(SYSTEM ${ORC_BUILD_SRC_DIR})
|
||||||
|
include_directories(SYSTEM ${ORC_BUILD_INCLUDE_DIR})
|
||||||
|
include_directories(SYSTEM ${ORC_ADDITION_SOURCE_DIR})
|
||||||
|
include_directories(SYSTEM ${ARROW_SRC_DIR})
|
||||||
|
|
||||||
|
|
||||||
|
set(ORC_SRCS
|
||||||
|
${ARROW_SRC_DIR}/arrow/adapters/orc/adapter.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Exceptions.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/OrcFile.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Reader.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/ByteRLE.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/ColumnPrinter.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/ColumnReader.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/ColumnWriter.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Common.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Compression.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Exceptions.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Int128.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/LzoDecompressor.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/MemoryPool.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/OrcFile.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Reader.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/RLE.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/RLEv1.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/RLEv2.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Statistics.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/StripeStream.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Timezone.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/TypeImpl.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Vector.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/Writer.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/io/InputStream.cc
|
||||||
|
${ORC_SOURCE_SRC_DIR}/io/OutputStream.cc
|
||||||
|
${ORC_ADDITION_SOURCE_DIR}/orc_proto.pb.cc
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# === arrow
|
# === arrow
|
||||||
|
|
||||||
@ -103,6 +167,7 @@ set(ARROW_SRCS
|
|||||||
${LIBRARY_DIR}/util/thread-pool.cc
|
${LIBRARY_DIR}/util/thread-pool.cc
|
||||||
${LIBRARY_DIR}/util/trie.cc
|
${LIBRARY_DIR}/util/trie.cc
|
||||||
${LIBRARY_DIR}/util/utf8.cc
|
${LIBRARY_DIR}/util/utf8.cc
|
||||||
|
${ORC_SRCS}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(ARROW_SRCS ${ARROW_SRCS}
|
set(ARROW_SRCS ${ARROW_SRCS}
|
||||||
@ -151,8 +216,9 @@ endif()
|
|||||||
|
|
||||||
|
|
||||||
add_library(${ARROW_LIBRARY} ${ARROW_SRCS})
|
add_library(${ARROW_LIBRARY} ${ARROW_SRCS})
|
||||||
|
add_dependencies(${ARROW_LIBRARY} protoc)
|
||||||
target_include_directories(${ARROW_LIBRARY} SYSTEM PUBLIC ${ClickHouse_SOURCE_DIR}/contrib/arrow/cpp/src PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src ${Boost_INCLUDE_DIRS})
|
target_include_directories(${ARROW_LIBRARY} SYSTEM PUBLIC ${ClickHouse_SOURCE_DIR}/contrib/arrow/cpp/src PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src ${Boost_INCLUDE_DIRS})
|
||||||
target_link_libraries(${ARROW_LIBRARY} PRIVATE ${DOUBLE_CONVERSION_LIBRARIES} Threads::Threads)
|
target_link_libraries(${ARROW_LIBRARY} PRIVATE ${DOUBLE_CONVERSION_LIBRARIES} ${Protobuf_LIBRARY})
|
||||||
if (ARROW_WITH_LZ4)
|
if (ARROW_WITH_LZ4)
|
||||||
target_link_libraries(${ARROW_LIBRARY} PRIVATE ${LZ4_LIBRARY})
|
target_link_libraries(${ARROW_LIBRARY} PRIVATE ${LZ4_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
|
69
contrib/capnproto-cmake/CMakeLists.txt
Normal file
69
contrib/capnproto-cmake/CMakeLists.txt
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
set (CAPNPROTO_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/capnproto/c++/src)
|
||||||
|
|
||||||
|
set (KJ_SRCS
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/array.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/common.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/debug.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/exception.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/io.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/memory.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/mutex.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/string.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/hash.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/table.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/thread.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/main.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/arena.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/test-helpers.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/units.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/encoding.c++
|
||||||
|
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/refcount.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/string-tree.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/time.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/filesystem.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/filesystem-disk-unix.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/filesystem-disk-win32.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/kj/parse/char.c++
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(kj ${KJ_SRCS})
|
||||||
|
target_include_directories(kj PUBLIC ${CAPNPROTO_SOURCE_DIR})
|
||||||
|
target_compile_options(kj PUBLIC -Wno-non-virtual-dtor)
|
||||||
|
|
||||||
|
set (CAPNP_SRCS
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/c++.capnp.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/blob.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/arena.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/layout.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/list.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/any.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/message.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/schema.capnp.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/serialize.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/serialize-packed.c++
|
||||||
|
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/schema.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/schema-loader.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/dynamic.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/stringify.c++
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(capnp ${CAPNP_SRCS})
|
||||||
|
target_link_libraries(capnp PUBLIC kj)
|
||||||
|
|
||||||
|
set (CAPNPC_SRCS
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/compiler/type-id.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/compiler/error-reporter.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/compiler/lexer.capnp.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/compiler/lexer.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/compiler/grammar.capnp.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/compiler/parser.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/compiler/node-translator.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/compiler/compiler.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/schema-parser.c++
|
||||||
|
${CAPNPROTO_SOURCE_DIR}/capnp/serialize-text.c++
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(capnpc ${CAPNPC_SRCS})
|
||||||
|
target_link_libraries(capnpc PUBLIC capnp)
|
@ -59,7 +59,6 @@ if (CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG")
|
|||||||
|
|
||||||
if (USE_UNWIND)
|
if (USE_UNWIND)
|
||||||
target_compile_definitions (jemalloc PRIVATE -DJEMALLOC_PROF_LIBUNWIND=1)
|
target_compile_definitions (jemalloc PRIVATE -DJEMALLOC_PROF_LIBUNWIND=1)
|
||||||
target_include_directories (jemalloc BEFORE PRIVATE ${UNWIND_INCLUDE_DIR})
|
target_link_libraries (jemalloc PRIVATE ${UNWIND_LIBRARIES})
|
||||||
target_link_libraries (jemalloc PRIVATE ${UNWIND_LIBRARY})
|
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
set(LIBCXX_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxx)
|
set(LIBCXX_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxx)
|
||||||
#set(LIBCXX_BINARY_DIR ${ClickHouse_BINARY_DIR}/contrib/libcxx)
|
|
||||||
|
|
||||||
set(SRCS
|
set(SRCS
|
||||||
${LIBCXX_SOURCE_DIR}/src/optional.cpp
|
${LIBCXX_SOURCE_DIR}/src/optional.cpp
|
||||||
@ -16,10 +15,6 @@ ${LIBCXX_SOURCE_DIR}/src/condition_variable.cpp
|
|||||||
${LIBCXX_SOURCE_DIR}/src/hash.cpp
|
${LIBCXX_SOURCE_DIR}/src/hash.cpp
|
||||||
${LIBCXX_SOURCE_DIR}/src/string.cpp
|
${LIBCXX_SOURCE_DIR}/src/string.cpp
|
||||||
${LIBCXX_SOURCE_DIR}/src/debug.cpp
|
${LIBCXX_SOURCE_DIR}/src/debug.cpp
|
||||||
#${LIBCXX_SOURCE_DIR}/src/support/win32/support.cpp
|
|
||||||
#${LIBCXX_SOURCE_DIR}/src/support/win32/locale_win32.cpp
|
|
||||||
#${LIBCXX_SOURCE_DIR}/src/support/win32/thread_win32.cpp
|
|
||||||
#${LIBCXX_SOURCE_DIR}/src/support/solaris/xlocale.cpp
|
|
||||||
${LIBCXX_SOURCE_DIR}/src/stdexcept.cpp
|
${LIBCXX_SOURCE_DIR}/src/stdexcept.cpp
|
||||||
${LIBCXX_SOURCE_DIR}/src/utility.cpp
|
${LIBCXX_SOURCE_DIR}/src/utility.cpp
|
||||||
${LIBCXX_SOURCE_DIR}/src/any.cpp
|
${LIBCXX_SOURCE_DIR}/src/any.cpp
|
||||||
@ -43,9 +38,17 @@ ${LIBCXX_SOURCE_DIR}/src/system_error.cpp
|
|||||||
${LIBCXX_SOURCE_DIR}/src/random.cpp
|
${LIBCXX_SOURCE_DIR}/src/random.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(cxx_static ${SRCS})
|
add_library(cxx ${SRCS})
|
||||||
|
|
||||||
target_include_directories(cxx_static PUBLIC ${LIBCXX_SOURCE_DIR}/include)
|
target_include_directories(cxx SYSTEM BEFORE PUBLIC $<BUILD_INTERFACE:${LIBCXX_SOURCE_DIR}/include>)
|
||||||
target_compile_definitions(cxx_static PRIVATE -D_LIBCPP_BUILDING_LIBRARY -DLIBCXX_BUILDING_LIBCXXABI)
|
target_compile_definitions(cxx PRIVATE -D_LIBCPP_BUILDING_LIBRARY -DLIBCXX_BUILDING_LIBCXXABI)
|
||||||
target_compile_options(cxx_static PRIVATE -nostdinc++)
|
target_compile_options(cxx PUBLIC -nostdinc++ -Wno-reserved-id-macro)
|
||||||
|
target_link_libraries(cxx PUBLIC cxxabi)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS cxx
|
||||||
|
EXPORT global
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
RUNTIME DESTINATION lib
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
)
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
set(LIBCXXABI_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxxabi)
|
set(LIBCXXABI_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxxabi)
|
||||||
set(LIBCXX_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxx)
|
|
||||||
#set(LIBCXXABI_BINARY_DIR ${ClickHouse_BINARY_DIR}/contrib/libcxxabi)
|
|
||||||
|
|
||||||
set(SRCS
|
set(SRCS
|
||||||
${LIBCXXABI_SOURCE_DIR}/src/stdlib_stdexcept.cpp
|
${LIBCXXABI_SOURCE_DIR}/src/stdlib_stdexcept.cpp
|
||||||
${LIBCXXABI_SOURCE_DIR}/src/cxa_virtual.cpp
|
${LIBCXXABI_SOURCE_DIR}/src/cxa_virtual.cpp
|
||||||
${LIBCXXABI_SOURCE_DIR}/src/cxa_thread_atexit.cpp
|
${LIBCXXABI_SOURCE_DIR}/src/cxa_thread_atexit.cpp
|
||||||
${LIBCXXABI_SOURCE_DIR}/src/fallback_malloc.cpp
|
${LIBCXXABI_SOURCE_DIR}/src/fallback_malloc.cpp
|
||||||
#${LIBCXXABI_SOURCE_DIR}/src/cxa_noexception.cpp
|
|
||||||
${LIBCXXABI_SOURCE_DIR}/src/cxa_guard.cpp
|
${LIBCXXABI_SOURCE_DIR}/src/cxa_guard.cpp
|
||||||
${LIBCXXABI_SOURCE_DIR}/src/cxa_default_handlers.cpp
|
${LIBCXXABI_SOURCE_DIR}/src/cxa_default_handlers.cpp
|
||||||
${LIBCXXABI_SOURCE_DIR}/src/cxa_personality.cpp
|
${LIBCXXABI_SOURCE_DIR}/src/cxa_personality.cpp
|
||||||
@ -25,10 +22,20 @@ ${LIBCXXABI_SOURCE_DIR}/src/cxa_vector.cpp
|
|||||||
${LIBCXXABI_SOURCE_DIR}/src/stdlib_new_delete.cpp
|
${LIBCXXABI_SOURCE_DIR}/src/stdlib_new_delete.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(cxxabi_static ${SRCS})
|
add_library(cxxabi ${SRCS})
|
||||||
|
|
||||||
target_include_directories(cxxabi_static PUBLIC ${LIBCXXABI_SOURCE_DIR}/include ${LIBCXX_SOURCE_DIR}/include)
|
|
||||||
target_compile_definitions(cxxabi_static PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
|
|
||||||
target_compile_options(cxxabi_static PRIVATE -nostdinc++ -fno-sanitize=undefined) # If we don't disable UBSan, infinite recursion happens in dynamic_cast.
|
|
||||||
|
|
||||||
|
target_include_directories(cxxabi SYSTEM BEFORE
|
||||||
|
PUBLIC $<BUILD_INTERFACE:${LIBCXXABI_SOURCE_DIR}/include>
|
||||||
|
PRIVATE $<BUILD_INTERFACE:${LIBCXXABI_SOURCE_DIR}/../libcxx/include>
|
||||||
|
)
|
||||||
|
target_compile_definitions(cxxabi PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
|
||||||
|
target_compile_options(cxxabi PRIVATE -nostdinc++ -fno-sanitize=undefined -Wno-macro-redefined) # If we don't disable UBSan, infinite recursion happens in dynamic_cast.
|
||||||
|
target_link_libraries(cxxabi PUBLIC ${EXCEPTION_HANDLING_LIBRARY})
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS cxxabi
|
||||||
|
EXPORT global
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
RUNTIME DESTINATION lib
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
)
|
||||||
|
@ -65,7 +65,7 @@ add_library(rdkafka ${SRCS})
|
|||||||
target_include_directories(rdkafka SYSTEM PUBLIC include)
|
target_include_directories(rdkafka SYSTEM PUBLIC include)
|
||||||
target_include_directories(rdkafka SYSTEM PUBLIC ${RDKAFKA_SOURCE_DIR}) # Because weird logic with "include_next" is used.
|
target_include_directories(rdkafka SYSTEM PUBLIC ${RDKAFKA_SOURCE_DIR}) # Because weird logic with "include_next" is used.
|
||||||
target_include_directories(rdkafka SYSTEM PRIVATE ${ZSTD_INCLUDE_DIR}/common) # Because wrong path to "zstd_errors.h" is used.
|
target_include_directories(rdkafka SYSTEM PRIVATE ${ZSTD_INCLUDE_DIR}/common) # Because wrong path to "zstd_errors.h" is used.
|
||||||
target_link_libraries(rdkafka PRIVATE ${ZLIB_LIBRARIES} ${ZSTD_LIBRARY} ${LZ4_LIBRARY} ${LIBGSASL_LIBRARY} Threads::Threads)
|
target_link_libraries(rdkafka PRIVATE ${ZLIB_LIBRARIES} ${ZSTD_LIBRARY} ${LZ4_LIBRARY} ${LIBGSASL_LIBRARY})
|
||||||
if(OPENSSL_SSL_LIBRARY AND OPENSSL_CRYPTO_LIBRARY)
|
if(OPENSSL_SSL_LIBRARY AND OPENSSL_CRYPTO_LIBRARY)
|
||||||
target_link_libraries(rdkafka PRIVATE ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
|
target_link_libraries(rdkafka PRIVATE ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
|
@ -24,9 +24,15 @@ set(LIBUNWIND_SOURCES
|
|||||||
${LIBUNWIND_C_SOURCES}
|
${LIBUNWIND_C_SOURCES}
|
||||||
${LIBUNWIND_ASM_SOURCES})
|
${LIBUNWIND_ASM_SOURCES})
|
||||||
|
|
||||||
add_library(unwind_static ${LIBUNWIND_SOURCES})
|
add_library(unwind ${LIBUNWIND_SOURCES})
|
||||||
|
|
||||||
target_include_directories(unwind_static SYSTEM BEFORE PUBLIC ${LIBUNWIND_SOURCE_DIR}/include)
|
target_include_directories(unwind SYSTEM BEFORE PUBLIC $<BUILD_INTERFACE:${LIBUNWIND_SOURCE_DIR}/include>)
|
||||||
target_compile_definitions(unwind_static PRIVATE -D_LIBUNWIND_NO_HEAP=1 -D_DEBUG -D_LIBUNWIND_IS_NATIVE_ONLY)
|
target_compile_definitions(unwind PRIVATE -D_LIBUNWIND_NO_HEAP=1 -D_DEBUG -D_LIBUNWIND_IS_NATIVE_ONLY)
|
||||||
target_compile_options(unwind_static PRIVATE -fno-exceptions -funwind-tables -fno-sanitize=all -nostdinc++ -fno-rtti)
|
target_compile_options(unwind PRIVATE -fno-exceptions -funwind-tables -fno-sanitize=all -nostdinc++ -fno-rtti)
|
||||||
target_link_libraries(unwind_static PRIVATE Threads::Threads ${CMAKE_DL_LIBS})
|
|
||||||
|
install(
|
||||||
|
TARGETS unwind
|
||||||
|
EXPORT global
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
)
|
||||||
|
@ -62,11 +62,6 @@ endif()
|
|||||||
|
|
||||||
add_library(mysqlclient ${SRCS})
|
add_library(mysqlclient ${SRCS})
|
||||||
|
|
||||||
target_link_libraries(mysqlclient PRIVATE ${CMAKE_DL_LIBS} Threads::Threads)
|
|
||||||
if(M_LIBRARY)
|
|
||||||
target_link_libraries(mysqlclient PRIVATE ${M_LIBRARY})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(OPENSSL_LIBRARIES)
|
if(OPENSSL_LIBRARIES)
|
||||||
target_link_libraries(mysqlclient PRIVATE ${OPENSSL_LIBRARIES})
|
target_link_libraries(mysqlclient PRIVATE ${OPENSSL_LIBRARIES})
|
||||||
target_compile_definitions(mysqlclient PRIVATE -D HAVE_OPENSSL -D HAVE_TLS)
|
target_compile_definitions(mysqlclient PRIVATE -D HAVE_OPENSSL -D HAVE_TLS)
|
||||||
|
1
contrib/mimalloc
vendored
1
contrib/mimalloc
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit a787bdebce94bf3776dc0d1ad597917f479ab8d5
|
|
1
contrib/orc
vendored
Submodule
1
contrib/orc
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 5981208e39447df84827f6a961d1da76bacb6078
|
@ -97,8 +97,6 @@ add_subdirectory (src)
|
|||||||
set(dbms_headers)
|
set(dbms_headers)
|
||||||
set(dbms_sources)
|
set(dbms_sources)
|
||||||
|
|
||||||
include(../cmake/dbms_glob_sources.cmake)
|
|
||||||
|
|
||||||
add_headers_and_sources(clickhouse_common_io src/Common)
|
add_headers_and_sources(clickhouse_common_io src/Common)
|
||||||
add_headers_and_sources(clickhouse_common_io src/Common/HashTable)
|
add_headers_and_sources(clickhouse_common_io src/Common/HashTable)
|
||||||
add_headers_and_sources(clickhouse_common_io src/IO)
|
add_headers_and_sources(clickhouse_common_io src/IO)
|
||||||
@ -114,6 +112,7 @@ add_headers_and_sources(dbms src/Columns)
|
|||||||
add_headers_and_sources(dbms src/Storages)
|
add_headers_and_sources(dbms src/Storages)
|
||||||
add_headers_and_sources(dbms src/Storages/Distributed)
|
add_headers_and_sources(dbms src/Storages/Distributed)
|
||||||
add_headers_and_sources(dbms src/Storages/MergeTree)
|
add_headers_and_sources(dbms src/Storages/MergeTree)
|
||||||
|
add_headers_and_sources(dbms src/Storages/LiveView)
|
||||||
add_headers_and_sources(dbms src/Client)
|
add_headers_and_sources(dbms src/Client)
|
||||||
add_headers_and_sources(dbms src/Formats)
|
add_headers_and_sources(dbms src/Formats)
|
||||||
add_headers_and_sources(dbms src/Processors)
|
add_headers_and_sources(dbms src/Processors)
|
||||||
@ -162,9 +161,7 @@ if (OS_FREEBSD)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (USE_UNWIND)
|
if (USE_UNWIND)
|
||||||
if (NOT USE_INTERNAL_UNWIND_LIBRARY_FOR_EXCEPTION_HANDLING)
|
target_link_libraries (clickhouse_common_io PRIVATE ${UNWIND_LIBRARIES})
|
||||||
target_link_libraries (clickhouse_common_io PRIVATE ${UNWIND_LIBRARY})
|
|
||||||
endif ()
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
add_subdirectory(src/Common/ZooKeeper)
|
add_subdirectory(src/Common/ZooKeeper)
|
||||||
@ -240,15 +237,10 @@ target_link_libraries(clickhouse_common_io
|
|||||||
${EXECINFO_LIBRARIES}
|
${EXECINFO_LIBRARIES}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${Boost_SYSTEM_LIBRARY}
|
${Boost_SYSTEM_LIBRARY}
|
||||||
|
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
apple_rt
|
apple_rt
|
||||||
PUBLIC
|
PUBLIC
|
||||||
Threads::Threads
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_DL_LIBS}
|
|
||||||
PRIVATE
|
|
||||||
rt
|
|
||||||
PUBLIC
|
|
||||||
roaring
|
roaring
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -264,11 +256,6 @@ if(RE2_INCLUDE_DIR)
|
|||||||
target_include_directories(clickhouse_common_io SYSTEM BEFORE PUBLIC ${RE2_INCLUDE_DIR})
|
target_include_directories(clickhouse_common_io SYSTEM BEFORE PUBLIC ${RE2_INCLUDE_DIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (USE_MIMALLOC)
|
|
||||||
target_include_directories (clickhouse_common_io SYSTEM BEFORE PUBLIC ${MIMALLOC_INCLUDE_DIR})
|
|
||||||
target_link_libraries (clickhouse_common_io PRIVATE ${MIMALLOC_LIBRARY})
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if(CPUID_LIBRARY)
|
if(CPUID_LIBRARY)
|
||||||
target_link_libraries(clickhouse_common_io PRIVATE ${CPUID_LIBRARY})
|
target_link_libraries(clickhouse_common_io PRIVATE ${CPUID_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
@ -296,7 +283,6 @@ target_link_libraries (dbms
|
|||||||
${Boost_FILESYSTEM_LIBRARY}
|
${Boost_FILESYSTEM_LIBRARY}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${Boost_SYSTEM_LIBRARY}
|
${Boost_SYSTEM_LIBRARY}
|
||||||
Threads::Threads
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(dbms PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/src/Core/include)
|
target_include_directories(dbms PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/src/Core/include)
|
||||||
@ -363,10 +349,7 @@ if (USE_ICU)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (USE_CAPNP)
|
if (USE_CAPNP)
|
||||||
target_link_libraries (dbms PRIVATE ${CAPNP_LIBRARY})
|
target_link_libraries (dbms PRIVATE ${CAPNP_LIBRARIES})
|
||||||
if (NOT USE_INTERNAL_CAPNP_LIBRARY)
|
|
||||||
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${CAPNP_INCLUDE_DIR})
|
|
||||||
endif ()
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (USE_PARQUET)
|
if (USE_PARQUET)
|
||||||
@ -379,7 +362,6 @@ endif ()
|
|||||||
if(OPENSSL_CRYPTO_LIBRARY)
|
if(OPENSSL_CRYPTO_LIBRARY)
|
||||||
target_link_libraries(dbms PRIVATE ${OPENSSL_CRYPTO_LIBRARY})
|
target_link_libraries(dbms PRIVATE ${OPENSSL_CRYPTO_LIBRARY})
|
||||||
endif ()
|
endif ()
|
||||||
target_link_libraries(dbms PRIVATE Threads::Threads)
|
|
||||||
|
|
||||||
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${DIVIDE_INCLUDE_DIR})
|
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${DIVIDE_INCLUDE_DIR})
|
||||||
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${SPARCEHASH_INCLUDE_DIR})
|
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${SPARCEHASH_INCLUDE_DIR})
|
||||||
|
@ -81,7 +81,6 @@ add_subdirectory (extract-from-config)
|
|||||||
add_subdirectory (compressor)
|
add_subdirectory (compressor)
|
||||||
add_subdirectory (copier)
|
add_subdirectory (copier)
|
||||||
add_subdirectory (format)
|
add_subdirectory (format)
|
||||||
add_subdirectory (clang)
|
|
||||||
add_subdirectory (obfuscator)
|
add_subdirectory (obfuscator)
|
||||||
|
|
||||||
if (ENABLE_CLICKHOUSE_ODBC_BRIDGE)
|
if (ENABLE_CLICKHOUSE_ODBC_BRIDGE)
|
||||||
@ -89,25 +88,21 @@ if (ENABLE_CLICKHOUSE_ODBC_BRIDGE)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (CLICKHOUSE_ONE_SHARED)
|
if (CLICKHOUSE_ONE_SHARED)
|
||||||
add_library(clickhouse-lib SHARED ${CLICKHOUSE_SERVER_SOURCES} ${CLICKHOUSE_CLIENT_SOURCES} ${CLICKHOUSE_LOCAL_SOURCES} ${CLICKHOUSE_BENCHMARK_SOURCES} ${CLICKHOUSE_PERFORMANCE_TEST_SOURCES} ${CLICKHOUSE_COPIER_SOURCES} ${CLICKHOUSE_EXTRACT_FROM_CONFIG_SOURCES} ${CLICKHOUSE_COMPRESSOR_SOURCES} ${CLICKHOUSE_FORMAT_SOURCES} ${CLICKHOUSE_OBFUSCATOR_SOURCES} ${CLICKHOUSE_COMPILER_SOURCES} ${CLICKHOUSE_ODBC_BRIDGE_SOURCES})
|
add_library(clickhouse-lib SHARED ${CLICKHOUSE_SERVER_SOURCES} ${CLICKHOUSE_CLIENT_SOURCES} ${CLICKHOUSE_LOCAL_SOURCES} ${CLICKHOUSE_BENCHMARK_SOURCES} ${CLICKHOUSE_PERFORMANCE_TEST_SOURCES} ${CLICKHOUSE_COPIER_SOURCES} ${CLICKHOUSE_EXTRACT_FROM_CONFIG_SOURCES} ${CLICKHOUSE_COMPRESSOR_SOURCES} ${CLICKHOUSE_FORMAT_SOURCES} ${CLICKHOUSE_OBFUSCATOR_SOURCES} ${CLICKHOUSE_ODBC_BRIDGE_SOURCES})
|
||||||
target_link_libraries(clickhouse-lib ${CLICKHOUSE_SERVER_LINK} ${CLICKHOUSE_CLIENT_LINK} ${CLICKHOUSE_LOCAL_LINK} ${CLICKHOUSE_BENCHMARK_LINK} ${CLICKHOUSE_PERFORMANCE_TEST_LINK} ${CLICKHOUSE_COPIER_LINK} ${CLICKHOUSE_EXTRACT_FROM_CONFIG_LINK} ${CLICKHOUSE_COMPRESSOR_LINK} ${CLICKHOUSE_FORMAT_LINK} ${CLICKHOUSE_OBFUSCATOR_LINK} ${CLICKHOUSE_COMPILER_LINK} ${CLICKHOUSE_ODBC_BRIDGE_LINK})
|
target_link_libraries(clickhouse-lib ${CLICKHOUSE_SERVER_LINK} ${CLICKHOUSE_CLIENT_LINK} ${CLICKHOUSE_LOCAL_LINK} ${CLICKHOUSE_BENCHMARK_LINK} ${CLICKHOUSE_PERFORMANCE_TEST_LINK} ${CLICKHOUSE_COPIER_LINK} ${CLICKHOUSE_EXTRACT_FROM_CONFIG_LINK} ${CLICKHOUSE_COMPRESSOR_LINK} ${CLICKHOUSE_FORMAT_LINK} ${CLICKHOUSE_OBFUSCATOR_LINK} ${CLICKHOUSE_ODBC_BRIDGE_LINK})
|
||||||
target_include_directories(clickhouse-lib ${CLICKHOUSE_SERVER_INCLUDE} ${CLICKHOUSE_CLIENT_INCLUDE} ${CLICKHOUSE_LOCAL_INCLUDE} ${CLICKHOUSE_BENCHMARK_INCLUDE} ${CLICKHOUSE_PERFORMANCE_TEST_INCLUDE} ${CLICKHOUSE_COPIER_INCLUDE} ${CLICKHOUSE_EXTRACT_FROM_CONFIG_INCLUDE} ${CLICKHOUSE_COMPRESSOR_INCLUDE} ${CLICKHOUSE_FORMAT_INCLUDE} ${CLICKHOUSE_OBFUSCATOR_INCLUDE} ${CLICKHOUSE_COMPILER_INCLUDE} ${CLICKHOUSE_ODBC_BRIDGE_INCLUDE})
|
target_include_directories(clickhouse-lib ${CLICKHOUSE_SERVER_INCLUDE} ${CLICKHOUSE_CLIENT_INCLUDE} ${CLICKHOUSE_LOCAL_INCLUDE} ${CLICKHOUSE_BENCHMARK_INCLUDE} ${CLICKHOUSE_PERFORMANCE_TEST_INCLUDE} ${CLICKHOUSE_COPIER_INCLUDE} ${CLICKHOUSE_EXTRACT_FROM_CONFIG_INCLUDE} ${CLICKHOUSE_COMPRESSOR_INCLUDE} ${CLICKHOUSE_FORMAT_INCLUDE} ${CLICKHOUSE_OBFUSCATOR_INCLUDE} ${CLICKHOUSE_ODBC_BRIDGE_INCLUDE})
|
||||||
set_target_properties(clickhouse-lib PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR} VERSION ${VERSION_SO} OUTPUT_NAME clickhouse DEBUG_POSTFIX "")
|
set_target_properties(clickhouse-lib PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR} VERSION ${VERSION_SO} OUTPUT_NAME clickhouse DEBUG_POSTFIX "")
|
||||||
install (TARGETS clickhouse-lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT clickhouse)
|
install (TARGETS clickhouse-lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT clickhouse)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (CLICKHOUSE_SPLIT_BINARY)
|
if (CLICKHOUSE_SPLIT_BINARY)
|
||||||
set (CLICKHOUSE_ALL_TARGETS clickhouse-server clickhouse-client clickhouse-local clickhouse-benchmark clickhouse-performance-test
|
set (CLICKHOUSE_ALL_TARGETS clickhouse-server clickhouse-client clickhouse-local clickhouse-benchmark clickhouse-performance-test
|
||||||
clickhouse-extract-from-config clickhouse-compressor clickhouse-format clickhouse-copier)
|
clickhouse-extract-from-config clickhouse-compressor clickhouse-format clickhouse-obfuscator clickhouse-copier)
|
||||||
|
|
||||||
if (ENABLE_CLICKHOUSE_ODBC_BRIDGE)
|
if (ENABLE_CLICKHOUSE_ODBC_BRIDGE)
|
||||||
list (APPEND CLICKHOUSE_ALL_TARGETS clickhouse-odbc-bridge)
|
list (APPEND CLICKHOUSE_ALL_TARGETS clickhouse-odbc-bridge)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (USE_EMBEDDED_COMPILER)
|
|
||||||
list (APPEND CLICKHOUSE_ALL_TARGETS clickhouse-clang clickhouse-lld)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
set_target_properties(${CLICKHOUSE_ALL_TARGETS} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..)
|
set_target_properties(${CLICKHOUSE_ALL_TARGETS} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..)
|
||||||
|
|
||||||
add_custom_target (clickhouse-bundle ALL DEPENDS ${CLICKHOUSE_ALL_TARGETS})
|
add_custom_target (clickhouse-bundle ALL DEPENDS ${CLICKHOUSE_ALL_TARGETS})
|
||||||
@ -115,10 +110,6 @@ if (CLICKHOUSE_SPLIT_BINARY)
|
|||||||
|
|
||||||
install(PROGRAMS clickhouse-split-helper DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME clickhouse COMPONENT clickhouse)
|
install(PROGRAMS clickhouse-split-helper DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME clickhouse COMPONENT clickhouse)
|
||||||
else ()
|
else ()
|
||||||
if (USE_EMBEDDED_COMPILER)
|
|
||||||
# before add_executable !
|
|
||||||
link_directories (${LLVM_LIBRARY_DIRS})
|
|
||||||
endif ()
|
|
||||||
add_executable (clickhouse main.cpp)
|
add_executable (clickhouse main.cpp)
|
||||||
target_link_libraries (clickhouse PRIVATE clickhouse_common_io string_utils)
|
target_link_libraries (clickhouse PRIVATE clickhouse_common_io string_utils)
|
||||||
target_include_directories (clickhouse BEFORE PRIVATE ${COMMON_INCLUDE_DIR})
|
target_include_directories (clickhouse BEFORE PRIVATE ${COMMON_INCLUDE_DIR})
|
||||||
@ -154,9 +145,6 @@ else ()
|
|||||||
if (ENABLE_CLICKHOUSE_OBFUSCATOR)
|
if (ENABLE_CLICKHOUSE_OBFUSCATOR)
|
||||||
clickhouse_target_link_split_lib(clickhouse obfuscator)
|
clickhouse_target_link_split_lib(clickhouse obfuscator)
|
||||||
endif ()
|
endif ()
|
||||||
if (USE_EMBEDDED_COMPILER)
|
|
||||||
target_link_libraries(clickhouse PRIVATE clickhouse-compiler-lib)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
set (CLICKHOUSE_BUNDLE)
|
set (CLICKHOUSE_BUNDLE)
|
||||||
if (ENABLE_CLICKHOUSE_SERVER)
|
if (ENABLE_CLICKHOUSE_SERVER)
|
||||||
@ -213,18 +201,8 @@ else ()
|
|||||||
list(APPEND CLICKHOUSE_BUNDLE clickhouse-odbc-bridge)
|
list(APPEND CLICKHOUSE_BUNDLE clickhouse-odbc-bridge)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# install always because depian package want this files:
|
|
||||||
add_custom_target (clickhouse-clang ALL COMMAND ${CMAKE_COMMAND} -E create_symlink clickhouse clickhouse-clang DEPENDS clickhouse)
|
|
||||||
add_custom_target (clickhouse-lld ALL COMMAND ${CMAKE_COMMAND} -E create_symlink clickhouse clickhouse-lld DEPENDS clickhouse)
|
|
||||||
list(APPEND CLICKHOUSE_BUNDLE clickhouse-clang clickhouse-lld)
|
|
||||||
|
|
||||||
install (TARGETS clickhouse RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse)
|
install (TARGETS clickhouse RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse)
|
||||||
|
|
||||||
install (FILES
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/clickhouse-clang
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/clickhouse-lld
|
|
||||||
DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse)
|
|
||||||
|
|
||||||
add_custom_target (clickhouse-bundle ALL DEPENDS ${CLICKHOUSE_BUNDLE})
|
add_custom_target (clickhouse-bundle ALL DEPENDS ${CLICKHOUSE_BUNDLE})
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#include <Client/Connection.h>
|
#include <Client/Connection.h>
|
||||||
#include <Common/InterruptListener.h>
|
#include <Common/InterruptListener.h>
|
||||||
#include <Common/Config/configReadClient.h>
|
#include <Common/Config/configReadClient.h>
|
||||||
|
#include <Common/TerminalSize.h>
|
||||||
|
#include <Common/StudentTTest.h>
|
||||||
|
|
||||||
|
|
||||||
/** A tool for evaluating ClickHouse performance.
|
/** A tool for evaluating ClickHouse performance.
|
||||||
@ -41,6 +43,8 @@
|
|||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
|
||||||
|
using Ports = std::vector<UInt16>;
|
||||||
|
|
||||||
namespace ErrorCodes
|
namespace ErrorCodes
|
||||||
{
|
{
|
||||||
extern const int BAD_ARGUMENTS;
|
extern const int BAD_ARGUMENTS;
|
||||||
@ -50,17 +54,34 @@ namespace ErrorCodes
|
|||||||
class Benchmark : public Poco::Util::Application
|
class Benchmark : public Poco::Util::Application
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Benchmark(unsigned concurrency_, double delay_,
|
Benchmark(unsigned concurrency_, double delay_, Strings && hosts_, Ports && ports_,
|
||||||
const String & host_, UInt16 port_, bool secure_, const String & default_database_,
|
bool cumulative_, bool secure_, const String & default_database_,
|
||||||
const String & user_, const String & password_, const String & stage,
|
const String & user_, const String & password_, const String & stage,
|
||||||
bool randomize_, size_t max_iterations_, double max_time_,
|
bool randomize_, size_t max_iterations_, double max_time_,
|
||||||
const String & json_path_, const Settings & settings_)
|
const String & json_path_, size_t confidence_, const Settings & settings_)
|
||||||
:
|
:
|
||||||
concurrency(concurrency_), delay(delay_), queue(concurrency),
|
concurrency(concurrency_), delay(delay_), queue(concurrency), randomize(randomize_),
|
||||||
connections(concurrency, host_, port_, default_database_, user_, password_, "benchmark", Protocol::Compression::Enable, secure_ ? Protocol::Secure::Enable : Protocol::Secure::Disable),
|
cumulative(cumulative_), max_iterations(max_iterations_), max_time(max_time_),
|
||||||
randomize(randomize_), max_iterations(max_iterations_), max_time(max_time_),
|
confidence(confidence_), json_path(json_path_), settings(settings_),
|
||||||
json_path(json_path_), settings(settings_), global_context(Context::createGlobal()), pool(concurrency)
|
global_context(Context::createGlobal()), pool(concurrency)
|
||||||
{
|
{
|
||||||
|
const auto secure = secure_ ? Protocol::Secure::Enable : Protocol::Secure::Disable;
|
||||||
|
size_t connections_cnt = std::max(ports_.size(), hosts_.size());
|
||||||
|
|
||||||
|
connections.reserve(connections_cnt);
|
||||||
|
comparison_info_total.reserve(connections_cnt);
|
||||||
|
comparison_info_per_interval.reserve(connections_cnt);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < connections_cnt; ++i)
|
||||||
|
{
|
||||||
|
UInt16 cur_port = i >= ports_.size() ? 9000 : ports_[i];
|
||||||
|
std::string cur_host = i >= hosts_.size() ? "localhost" : hosts_[i];
|
||||||
|
|
||||||
|
connections.emplace_back(std::make_unique<ConnectionPool>(concurrency, cur_host, cur_port, default_database_, user_, password_, "benchmark", Protocol::Compression::Enable, secure));
|
||||||
|
comparison_info_per_interval.emplace_back(std::make_shared<Stats>());
|
||||||
|
comparison_info_total.emplace_back(std::make_shared<Stats>());
|
||||||
|
}
|
||||||
|
|
||||||
global_context.makeGlobalContext();
|
global_context.makeGlobalContext();
|
||||||
|
|
||||||
std::cerr << std::fixed << std::setprecision(3);
|
std::cerr << std::fixed << std::setprecision(3);
|
||||||
@ -101,21 +122,29 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Query = std::string;
|
using Entry = ConnectionPool::Entry;
|
||||||
|
using EntryPtr = std::shared_ptr<Entry>;
|
||||||
|
using EntryPtrs = std::vector<EntryPtr>;
|
||||||
|
|
||||||
unsigned concurrency;
|
unsigned concurrency;
|
||||||
double delay;
|
double delay;
|
||||||
|
|
||||||
|
using Query = std::string;
|
||||||
using Queries = std::vector<Query>;
|
using Queries = std::vector<Query>;
|
||||||
Queries queries;
|
Queries queries;
|
||||||
|
|
||||||
using Queue = ConcurrentBoundedQueue<Query>;
|
using Queue = ConcurrentBoundedQueue<Query>;
|
||||||
Queue queue;
|
Queue queue;
|
||||||
|
|
||||||
ConnectionPool connections;
|
using ConnectionPoolUniq = std::unique_ptr<ConnectionPool>;
|
||||||
|
using ConnectionPoolUniqs = std::vector<ConnectionPoolUniq>;
|
||||||
|
ConnectionPoolUniqs connections;
|
||||||
|
|
||||||
bool randomize;
|
bool randomize;
|
||||||
|
bool cumulative;
|
||||||
size_t max_iterations;
|
size_t max_iterations;
|
||||||
double max_time;
|
double max_time;
|
||||||
|
size_t confidence;
|
||||||
String json_path;
|
String json_path;
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Context global_context;
|
Context global_context;
|
||||||
@ -128,12 +157,12 @@ private:
|
|||||||
|
|
||||||
struct Stats
|
struct Stats
|
||||||
{
|
{
|
||||||
Stopwatch watch;
|
|
||||||
std::atomic<size_t> queries{0};
|
std::atomic<size_t> queries{0};
|
||||||
size_t read_rows = 0;
|
size_t read_rows = 0;
|
||||||
size_t read_bytes = 0;
|
size_t read_bytes = 0;
|
||||||
size_t result_rows = 0;
|
size_t result_rows = 0;
|
||||||
size_t result_bytes = 0;
|
size_t result_bytes = 0;
|
||||||
|
double work_time = 0;
|
||||||
|
|
||||||
using Sampler = ReservoirSampler<double>;
|
using Sampler = ReservoirSampler<double>;
|
||||||
Sampler sampler {1 << 16};
|
Sampler sampler {1 << 16};
|
||||||
@ -141,6 +170,7 @@ private:
|
|||||||
void add(double seconds, size_t read_rows_inc, size_t read_bytes_inc, size_t result_rows_inc, size_t result_bytes_inc)
|
void add(double seconds, size_t read_rows_inc, size_t read_bytes_inc, size_t result_rows_inc, size_t result_bytes_inc)
|
||||||
{
|
{
|
||||||
++queries;
|
++queries;
|
||||||
|
work_time += seconds;
|
||||||
read_rows += read_rows_inc;
|
read_rows += read_rows_inc;
|
||||||
read_bytes += read_bytes_inc;
|
read_bytes += read_bytes_inc;
|
||||||
result_rows += result_rows_inc;
|
result_rows += result_rows_inc;
|
||||||
@ -150,8 +180,8 @@ private:
|
|||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
watch.restart();
|
|
||||||
queries = 0;
|
queries = 0;
|
||||||
|
work_time = 0;
|
||||||
read_rows = 0;
|
read_rows = 0;
|
||||||
read_bytes = 0;
|
read_bytes = 0;
|
||||||
result_rows = 0;
|
result_rows = 0;
|
||||||
@ -160,15 +190,18 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Stats info_per_interval;
|
using MultiStats = std::vector<std::shared_ptr<Stats>>;
|
||||||
Stats info_total;
|
MultiStats comparison_info_per_interval;
|
||||||
|
MultiStats comparison_info_total;
|
||||||
|
StudentTTest t_test;
|
||||||
|
|
||||||
|
Stopwatch total_watch;
|
||||||
Stopwatch delay_watch;
|
Stopwatch delay_watch;
|
||||||
|
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
|
|
||||||
ThreadPool pool;
|
ThreadPool pool;
|
||||||
|
|
||||||
|
|
||||||
void readQueries()
|
void readQueries()
|
||||||
{
|
{
|
||||||
ReadBufferFromFileDescriptor in(STDIN_FILENO);
|
ReadBufferFromFileDescriptor in(STDIN_FILENO);
|
||||||
@ -213,7 +246,7 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max_time > 0 && info_total.watch.elapsedSeconds() >= max_time)
|
if (max_time > 0 && total_watch.elapsedSeconds() >= max_time)
|
||||||
{
|
{
|
||||||
std::cout << "Stopping launch of queries. Requested time limit is exhausted.\n";
|
std::cout << "Stopping launch of queries. Requested time limit is exhausted.\n";
|
||||||
return false;
|
return false;
|
||||||
@ -227,8 +260,8 @@ private:
|
|||||||
|
|
||||||
if (delay > 0 && delay_watch.elapsedSeconds() > delay)
|
if (delay > 0 && delay_watch.elapsedSeconds() > delay)
|
||||||
{
|
{
|
||||||
printNumberOfQueriesExecuted(info_total.queries);
|
printNumberOfQueriesExecuted(queries_executed);
|
||||||
report(info_per_interval);
|
cumulative ? report(comparison_info_total) : report(comparison_info_per_interval);
|
||||||
delay_watch.restart();
|
delay_watch.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,11 +275,17 @@ private:
|
|||||||
std::uniform_int_distribution<size_t> distribution(0, queries.size() - 1);
|
std::uniform_int_distribution<size_t> distribution(0, queries.size() - 1);
|
||||||
|
|
||||||
for (size_t i = 0; i < concurrency; ++i)
|
for (size_t i = 0; i < concurrency; ++i)
|
||||||
pool.schedule(std::bind(&Benchmark::thread, this,
|
{
|
||||||
connections.get(ConnectionTimeouts::getTCPTimeoutsWithoutFailover(settings))));
|
EntryPtrs connection_entries;
|
||||||
|
connection_entries.reserve(connections.size());
|
||||||
|
|
||||||
|
for (const auto & connection : connections)
|
||||||
|
connection_entries.emplace_back(std::make_shared<Entry>(connection->get(ConnectionTimeouts::getTCPTimeoutsWithoutFailover(settings))));
|
||||||
|
|
||||||
|
pool.schedule(std::bind(&Benchmark::thread, this, connection_entries));
|
||||||
|
}
|
||||||
|
|
||||||
InterruptListener interrupt_listener;
|
InterruptListener interrupt_listener;
|
||||||
info_per_interval.watch.restart();
|
|
||||||
delay_watch.restart();
|
delay_watch.restart();
|
||||||
|
|
||||||
/// Push queries into queue
|
/// Push queries into queue
|
||||||
@ -262,20 +301,24 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
pool.wait();
|
pool.wait();
|
||||||
info_total.watch.stop();
|
total_watch.stop();
|
||||||
|
|
||||||
if (!json_path.empty())
|
if (!json_path.empty())
|
||||||
reportJSON(info_total, json_path);
|
reportJSON(comparison_info_total, json_path);
|
||||||
|
|
||||||
printNumberOfQueriesExecuted(info_total.queries);
|
printNumberOfQueriesExecuted(queries_executed);
|
||||||
report(info_total);
|
report(comparison_info_total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void thread(ConnectionPool::Entry connection)
|
void thread(EntryPtrs & connection_entries)
|
||||||
{
|
{
|
||||||
Query query;
|
Query query;
|
||||||
|
|
||||||
|
/// Randomly choosing connection index
|
||||||
|
pcg64 generator(randomSeed());
|
||||||
|
std::uniform_int_distribution<size_t> distribution(0, connection_entries.size() - 1);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
/// In these threads we do not accept INT signal.
|
/// In these threads we do not accept INT signal.
|
||||||
@ -296,8 +339,7 @@ private:
|
|||||||
if (shutdown || (max_iterations && queries_executed == max_iterations))
|
if (shutdown || (max_iterations && queries_executed == max_iterations))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
execute(connection_entries, query, distribution(generator));
|
||||||
execute(connection, query);
|
|
||||||
++queries_executed;
|
++queries_executed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,20 +351,19 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void execute(EntryPtrs & connection_entries, Query & query, size_t connection_index)
|
||||||
void execute(ConnectionPool::Entry & connection, Query & query)
|
|
||||||
{
|
{
|
||||||
Stopwatch watch;
|
Stopwatch watch;
|
||||||
RemoteBlockInputStream stream(
|
RemoteBlockInputStream stream(
|
||||||
*connection,
|
*(*connection_entries[connection_index]),
|
||||||
query, {}, global_context, &settings, nullptr, Tables(), query_processing_stage);
|
query, {}, global_context, &settings, nullptr, Tables(), query_processing_stage);
|
||||||
|
|
||||||
Progress progress;
|
Progress progress;
|
||||||
stream.setProgressCallback([&progress](const Progress & value) { progress.incrementPiecewiseAtomically(value); });
|
stream.setProgressCallback([&progress](const Progress & value) { progress.incrementPiecewiseAtomically(value); });
|
||||||
|
|
||||||
stream.readPrefix();
|
stream.readPrefix();
|
||||||
while (Block block = stream.read())
|
while (Block block = stream.read());
|
||||||
;
|
|
||||||
stream.readSuffix();
|
stream.readSuffix();
|
||||||
|
|
||||||
const BlockStreamProfileInfo & info = stream.getProfileInfo();
|
const BlockStreamProfileInfo & info = stream.getProfileInfo();
|
||||||
@ -330,33 +371,47 @@ private:
|
|||||||
double seconds = watch.elapsedSeconds();
|
double seconds = watch.elapsedSeconds();
|
||||||
|
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
info_per_interval.add(seconds, progress.read_rows, progress.read_bytes, info.rows, info.bytes);
|
|
||||||
info_total.add(seconds, progress.read_rows, progress.read_bytes, info.rows, info.bytes);
|
comparison_info_per_interval[connection_index]->add(seconds, progress.read_rows, progress.read_bytes, info.rows, info.bytes);
|
||||||
|
comparison_info_total[connection_index]->add(seconds, progress.read_rows, progress.read_bytes, info.rows, info.bytes);
|
||||||
|
t_test.add(connection_index, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void report(MultiStats & infos)
|
||||||
void report(Stats & info)
|
|
||||||
{
|
{
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
|
|
||||||
|
std::cerr << "\n";
|
||||||
|
for (size_t i = 0; i < infos.size(); ++i)
|
||||||
|
{
|
||||||
|
const auto & info = infos[i];
|
||||||
|
|
||||||
/// Avoid zeros, nans or exceptions
|
/// Avoid zeros, nans or exceptions
|
||||||
if (0 == info.queries)
|
if (0 == info->queries)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
double seconds = info.watch.elapsedSeconds();
|
double seconds = info->work_time / concurrency;
|
||||||
|
|
||||||
std::cerr
|
std::cerr
|
||||||
<< "\n"
|
<< connections[i]->getDescription() << ", "
|
||||||
<< "QPS: " << (info.queries / seconds) << ", "
|
<< "queries " << info->queries << ", "
|
||||||
<< "RPS: " << (info.read_rows / seconds) << ", "
|
<< "QPS: " << (info->queries / seconds) << ", "
|
||||||
<< "MiB/s: " << (info.read_bytes / seconds / 1048576) << ", "
|
<< "RPS: " << (info->read_rows / seconds) << ", "
|
||||||
<< "result RPS: " << (info.result_rows / seconds) << ", "
|
<< "MiB/s: " << (info->read_bytes / seconds / 1048576) << ", "
|
||||||
<< "result MiB/s: " << (info.result_bytes / seconds / 1048576) << "."
|
<< "result RPS: " << (info->result_rows / seconds) << ", "
|
||||||
|
<< "result MiB/s: " << (info->result_bytes / seconds / 1048576) << "."
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
}
|
||||||
|
std::cerr << "\n";
|
||||||
|
|
||||||
auto print_percentile = [&](double percent)
|
auto print_percentile = [&](double percent)
|
||||||
{
|
{
|
||||||
std::cerr << percent << "%\t" << info.sampler.quantileInterpolated(percent / 100.0) << " sec." << std::endl;
|
std::cerr << percent << "%\t\t";
|
||||||
|
for (const auto & info : infos)
|
||||||
|
{
|
||||||
|
std::cerr << info->sampler.quantileInterpolated(percent / 100.0) << " sec." << "\t";
|
||||||
|
}
|
||||||
|
std::cerr << "\n";
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int percent = 0; percent <= 90; percent += 10)
|
for (int percent = 0; percent <= 90; percent += 10)
|
||||||
@ -367,10 +422,16 @@ private:
|
|||||||
print_percentile(99.9);
|
print_percentile(99.9);
|
||||||
print_percentile(99.99);
|
print_percentile(99.99);
|
||||||
|
|
||||||
info.clear();
|
std::cerr << "\n" << t_test.compareAndReport(confidence).second << "\n";
|
||||||
|
|
||||||
|
if (!cumulative)
|
||||||
|
{
|
||||||
|
for (auto & info : infos)
|
||||||
|
info->clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reportJSON(Stats & info, const std::string & filename)
|
void reportJSON(MultiStats & infos, const std::string & filename)
|
||||||
{
|
{
|
||||||
WriteBufferFromFile json_out(filename);
|
WriteBufferFromFile json_out(filename);
|
||||||
|
|
||||||
@ -381,36 +442,41 @@ private:
|
|||||||
json_out << double_quote << key << ": " << value << (with_comma ? ",\n" : "\n");
|
json_out << double_quote << key << ": " << value << (with_comma ? ",\n" : "\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
auto print_percentile = [&json_out, &info](auto percent, bool with_comma = true)
|
auto print_percentile = [&json_out](Stats & info, auto percent, bool with_comma = true)
|
||||||
{
|
{
|
||||||
json_out << "\"" << percent << "\"" << ": " << info.sampler.quantileInterpolated(percent / 100.0) << (with_comma ? ",\n" : "\n");
|
json_out << "\"" << percent << "\"" << ": " << info.sampler.quantileInterpolated(percent / 100.0) << (with_comma ? ",\n" : "\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
json_out << "{\n";
|
json_out << "{\n";
|
||||||
|
|
||||||
|
for (size_t i = 0; i < infos.size(); ++i)
|
||||||
|
{
|
||||||
|
const auto & info = infos[i];
|
||||||
|
|
||||||
|
json_out << double_quote << connections[i]->getDescription() << ": {\n";
|
||||||
json_out << double_quote << "statistics" << ": {\n";
|
json_out << double_quote << "statistics" << ": {\n";
|
||||||
|
|
||||||
double seconds = info.watch.elapsedSeconds();
|
print_key_value("QPS", info->queries / info->work_time);
|
||||||
print_key_value("QPS", info.queries / seconds);
|
print_key_value("RPS", info->read_rows / info->work_time);
|
||||||
print_key_value("RPS", info.read_rows / seconds);
|
print_key_value("MiBPS", info->read_bytes / info->work_time);
|
||||||
print_key_value("MiBPS", info.read_bytes / seconds);
|
print_key_value("RPS_result", info->result_rows / info->work_time);
|
||||||
print_key_value("RPS_result", info.result_rows / seconds);
|
print_key_value("MiBPS_result", info->result_bytes / info->work_time);
|
||||||
print_key_value("MiBPS_result", info.result_bytes / seconds);
|
print_key_value("num_queries", info->queries.load(), false);
|
||||||
print_key_value("num_queries", info.queries.load(), false);
|
|
||||||
|
|
||||||
json_out << "},\n";
|
json_out << "},\n";
|
||||||
|
|
||||||
json_out << double_quote << "query_time_percentiles" << ": {\n";
|
json_out << double_quote << "query_time_percentiles" << ": {\n";
|
||||||
|
|
||||||
for (int percent = 0; percent <= 90; percent += 10)
|
for (int percent = 0; percent <= 90; percent += 10)
|
||||||
print_percentile(percent);
|
print_percentile(*info, percent);
|
||||||
|
|
||||||
print_percentile(95);
|
print_percentile(*info, 95);
|
||||||
print_percentile(99);
|
print_percentile(*info, 99);
|
||||||
print_percentile(99.9);
|
print_percentile(*info, 99.9);
|
||||||
print_percentile(99.99, false);
|
print_percentile(*info, 99.99, false);
|
||||||
|
|
||||||
json_out << "}\n";
|
json_out << "}\n";
|
||||||
|
json_out << (i == infos.size() - 1 ? "}\n" : "},\n");
|
||||||
|
}
|
||||||
|
|
||||||
json_out << "}\n";
|
json_out << "}\n";
|
||||||
}
|
}
|
||||||
@ -439,7 +505,7 @@ int mainEntryClickHouseBenchmark(int argc, char ** argv)
|
|||||||
{
|
{
|
||||||
using boost::program_options::value;
|
using boost::program_options::value;
|
||||||
|
|
||||||
boost::program_options::options_description desc("Allowed options");
|
boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth());
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
("help", "produce help message")
|
("help", "produce help message")
|
||||||
("concurrency,c", value<unsigned>()->default_value(1), "number of parallel queries")
|
("concurrency,c", value<unsigned>()->default_value(1), "number of parallel queries")
|
||||||
@ -449,13 +515,15 @@ int mainEntryClickHouseBenchmark(int argc, char ** argv)
|
|||||||
("timelimit,t", value<double>()->default_value(0.), "stop launch of queries after specified time limit")
|
("timelimit,t", value<double>()->default_value(0.), "stop launch of queries after specified time limit")
|
||||||
("randomize,r", value<bool>()->default_value(false), "randomize order of execution")
|
("randomize,r", value<bool>()->default_value(false), "randomize order of execution")
|
||||||
("json", value<std::string>()->default_value(""), "write final report to specified file in JSON format")
|
("json", value<std::string>()->default_value(""), "write final report to specified file in JSON format")
|
||||||
("host,h", value<std::string>()->default_value("localhost"), "")
|
("host,h", value<Strings>()->multitoken(), "")
|
||||||
("port", value<UInt16>()->default_value(9000), "")
|
("port,p", value<Ports>()->multitoken(), "")
|
||||||
|
("cumulative", "prints cumulative data instead of data per interval")
|
||||||
("secure,s", "Use TLS connection")
|
("secure,s", "Use TLS connection")
|
||||||
("user", value<std::string>()->default_value("default"), "")
|
("user", value<std::string>()->default_value("default"), "")
|
||||||
("password", value<std::string>()->default_value(""), "")
|
("password", value<std::string>()->default_value(""), "")
|
||||||
("database", value<std::string>()->default_value("default"), "")
|
("database", value<std::string>()->default_value("default"), "")
|
||||||
("stacktrace", "print stack traces of exceptions")
|
("stacktrace", "print stack traces of exceptions")
|
||||||
|
("confidence", value<size_t>()->default_value(5), "set the level of confidence for T-test [0=80%, 1=90%, 2=95%, 3=98%, 4=99%, 5=99.5%(default)")
|
||||||
;
|
;
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
@ -475,12 +543,15 @@ int mainEntryClickHouseBenchmark(int argc, char ** argv)
|
|||||||
print_stacktrace = options.count("stacktrace");
|
print_stacktrace = options.count("stacktrace");
|
||||||
|
|
||||||
UseSSL use_ssl;
|
UseSSL use_ssl;
|
||||||
|
Ports ports = options.count("port") ? options["port"].as<Ports>() : Ports({9000});
|
||||||
|
Strings hosts = options.count("host") ? options["host"].as<Strings>() : Strings({"localhost"});
|
||||||
|
|
||||||
Benchmark benchmark(
|
Benchmark benchmark(
|
||||||
options["concurrency"].as<unsigned>(),
|
options["concurrency"].as<unsigned>(),
|
||||||
options["delay"].as<double>(),
|
options["delay"].as<double>(),
|
||||||
options["host"].as<std::string>(),
|
std::move(hosts),
|
||||||
options["port"].as<UInt16>(),
|
std::move(ports),
|
||||||
|
options.count("cumulative"),
|
||||||
options.count("secure"),
|
options.count("secure"),
|
||||||
options["database"].as<std::string>(),
|
options["database"].as<std::string>(),
|
||||||
options["user"].as<std::string>(),
|
options["user"].as<std::string>(),
|
||||||
@ -490,6 +561,7 @@ int mainEntryClickHouseBenchmark(int argc, char ** argv)
|
|||||||
options["iterations"].as<size_t>(),
|
options["iterations"].as<size_t>(),
|
||||||
options["timelimit"].as<double>(),
|
options["timelimit"].as<double>(),
|
||||||
options["json"].as<std::string>(),
|
options["json"].as<std::string>(),
|
||||||
|
options["confidence"].as<size_t>(),
|
||||||
settings);
|
settings);
|
||||||
return benchmark.run();
|
return benchmark.run();
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
if (USE_EMBEDDED_COMPILER)
|
|
||||||
add_subdirectory ("Compiler-${LLVM_VERSION}")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (CLICKHOUSE_SPLIT_BINARY)
|
|
||||||
if (USE_EMBEDDED_COMPILER)
|
|
||||||
link_directories (${LLVM_LIBRARY_DIRS})
|
|
||||||
add_executable (clickhouse-clang clickhouse-clang.cpp)
|
|
||||||
target_link_libraries (clickhouse-clang PRIVATE clickhouse-compiler-lib)
|
|
||||||
add_executable (clickhouse-lld clickhouse-lld.cpp)
|
|
||||||
target_link_libraries (clickhouse-lld PRIVATE clickhouse-compiler-lib)
|
|
||||||
install (TARGETS clickhouse-clang clickhouse-lld RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
set (TMP_HEADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/${INTERNAL_COMPILER_HEADERS_RELATIVE}")
|
|
||||||
# Make and install empty dir for debian package if compiler disabled
|
|
||||||
add_custom_target (make-headers-directory ALL COMMAND ${CMAKE_COMMAND} -E make_directory ${TMP_HEADERS_DIR})
|
|
||||||
install (DIRECTORY ${TMP_HEADERS_DIR} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/clickhouse/${INTERNAL_COMPILER_HEADERS_DIR} COMPONENT clickhouse)
|
|
||||||
# TODO: fix on macos copy_headers.sh: sed --posix
|
|
||||||
|
|
||||||
if (USE_EMBEDDED_COMPILER)
|
|
||||||
set (COPY_HEADERS_COMPILER "${CMAKE_CURRENT_BINARY_DIR}/../${INTERNAL_COMPILER_EXECUTABLE}")
|
|
||||||
set (COPY_HEADERS_DEPENDS clickhouse-clang)
|
|
||||||
elseif (EXISTS ${INTERNAL_COMPILER_BIN_ROOT}${INTERNAL_COMPILER_EXECUTABLE})
|
|
||||||
set (COPY_HEADERS_COMPILER "${INTERNAL_COMPILER_BIN_ROOT}${INTERNAL_COMPILER_EXECUTABLE}")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (COPY_HEADERS_COMPILER)
|
|
||||||
add_custom_target (copy-headers [ -f ${TMP_HEADERS_DIR}/dbms/src/Interpreters/SpecializedAggregator.h ] || env CLANG=${COPY_HEADERS_COMPILER} BUILD_PATH=${ClickHouse_BINARY_DIR} DESTDIR=${ClickHouse_SOURCE_DIR} CMAKE_CXX_COMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION} ${CMAKE_CURRENT_SOURCE_DIR}/copy_headers.sh ${ClickHouse_SOURCE_DIR} ${TMP_HEADERS_DIR} DEPENDS ${COPY_HEADERS_DEPENDS} WORKING_DIRECTORY ${ClickHouse_SOURCE_DIR} SOURCES copy_headers.sh)
|
|
||||||
|
|
||||||
if (USE_INTERNAL_LLVM_LIBRARY)
|
|
||||||
set (CLANG_HEADERS_DIR "${ClickHouse_SOURCE_DIR}/contrib/llvm/clang/lib/Headers")
|
|
||||||
set (CLANG_HEADERS_DEST "${TMP_HEADERS_DIR}/usr/local/lib/clang/${LLVM_VERSION}/include") # original: ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include
|
|
||||||
add_custom_target (copy-headers-clang ${CMAKE_COMMAND} -E make_directory ${CLANG_HEADERS_DEST} && ${CMAKE_COMMAND} -E copy_if_different ${CLANG_HEADERS_DIR}/* ${CLANG_HEADERS_DEST} )
|
|
||||||
add_dependencies (copy-headers copy-headers-clang)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
@ -1,53 +0,0 @@
|
|||||||
add_definitions(-Wno-error -Wno-unused-parameter -Wno-non-virtual-dtor -U_LIBCPP_DEBUG)
|
|
||||||
|
|
||||||
link_directories(${LLVM_LIBRARY_DIRS})
|
|
||||||
|
|
||||||
add_library(clickhouse-compiler-lib
|
|
||||||
driver.cpp
|
|
||||||
cc1_main.cpp
|
|
||||||
cc1as_main.cpp
|
|
||||||
lld.cpp)
|
|
||||||
|
|
||||||
target_compile_options(clickhouse-compiler-lib PRIVATE -fno-rtti -fno-exceptions -g0)
|
|
||||||
|
|
||||||
string(REPLACE "${INCLUDE_DEBUG_HELPERS}" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # cant compile with -fno-rtti
|
|
||||||
|
|
||||||
llvm_libs_all(REQUIRED_LLVM_LIBRARIES)
|
|
||||||
|
|
||||||
message(STATUS "Using LLVM ${LLVM_VERSION}: ${LLVM_INCLUDE_DIRS} : ${REQUIRED_LLVM_LIBRARIES}")
|
|
||||||
|
|
||||||
target_include_directories(clickhouse-compiler-lib SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
# This is extracted almost directly from CMakeFiles/.../link.txt in LLVM build directory.
|
|
||||||
|
|
||||||
target_link_libraries(clickhouse-compiler-lib PRIVATE
|
|
||||||
|
|
||||||
clangBasic clangCodeGen clangDriver clangFrontend clangFrontendTool
|
|
||||||
clangRewriteFrontend clangARCMigrate clangStaticAnalyzerFrontend
|
|
||||||
clangParse clangSerialization clangSema clangEdit clangStaticAnalyzerCheckers
|
|
||||||
clangASTMatchers clangStaticAnalyzerCore clangAnalysis clangAST clangRewrite clangLex clangBasic
|
|
||||||
|
|
||||||
lldCOFF
|
|
||||||
lldDriver
|
|
||||||
lldELF
|
|
||||||
#lldMinGW
|
|
||||||
lldMachO
|
|
||||||
lldReaderWriter
|
|
||||||
lldYAML
|
|
||||||
#lldCommon
|
|
||||||
lldCore
|
|
||||||
lldConfig
|
|
||||||
|
|
||||||
${REQUIRED_LLVM_LIBRARIES}
|
|
||||||
|
|
||||||
LLVMSupport
|
|
||||||
|
|
||||||
#Polly
|
|
||||||
#PollyISL
|
|
||||||
#PollyPPCG
|
|
||||||
|
|
||||||
PUBLIC ${ZLIB_LIBRARIES} ${EXECINFO_LIBRARIES} Threads::Threads
|
|
||||||
${MALLOC_LIBRARIES}
|
|
||||||
${GLIBC_COMPATIBILITY_LIBRARIES}
|
|
||||||
${MEMCPY_LIBRARIES}
|
|
||||||
)
|
|
@ -1,63 +0,0 @@
|
|||||||
==============================================================================
|
|
||||||
LLVM Release License
|
|
||||||
==============================================================================
|
|
||||||
University of Illinois/NCSA
|
|
||||||
Open Source License
|
|
||||||
|
|
||||||
Copyright (c) 2007-2016 University of Illinois at Urbana-Champaign.
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Developed by:
|
|
||||||
|
|
||||||
LLVM Team
|
|
||||||
|
|
||||||
University of Illinois at Urbana-Champaign
|
|
||||||
|
|
||||||
http://llvm.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal with
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
||||||
of the Software, and to permit persons to whom the Software is furnished to do
|
|
||||||
so, subject to the following conditions:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimers.
|
|
||||||
|
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimers in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
* Neither the names of the LLVM Team, University of Illinois at
|
|
||||||
Urbana-Champaign, nor the names of its contributors may be used to
|
|
||||||
endorse or promote products derived from this Software without specific
|
|
||||||
prior written permission.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
==============================================================================
|
|
||||||
The LLVM software contains code written by third parties. Such software will
|
|
||||||
have its own individual LICENSE.TXT file in the directory in which it appears.
|
|
||||||
This file will describe the copyrights, license, and restrictions which apply
|
|
||||||
to that code.
|
|
||||||
|
|
||||||
The disclaimer of warranty in the University of Illinois Open Source License
|
|
||||||
applies to all code in the LLVM Distribution, and nothing in any of the
|
|
||||||
other licenses gives permission to use the names of the LLVM Team or the
|
|
||||||
University of Illinois to endorse or promote products derived from this
|
|
||||||
Software.
|
|
||||||
|
|
||||||
The following pieces of software have additional or alternate copyrights,
|
|
||||||
licenses, and/or restrictions:
|
|
||||||
|
|
||||||
Program Directory
|
|
||||||
------- ---------
|
|
||||||
<none yet>
|
|
||||||
|
|
@ -1,242 +0,0 @@
|
|||||||
//===-- cc1_main.cpp - Clang CC1 Compiler Frontend ------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang -cc1 functionality, which implements the
|
|
||||||
// core compiler functionality along with a number of additional tools for
|
|
||||||
// demonstration and testing purposes.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "llvm/Option/Arg.h"
|
|
||||||
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
|
|
||||||
#include "clang/Config/config.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Frontend/CompilerInstance.h"
|
|
||||||
#include "clang/Frontend/CompilerInvocation.h"
|
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "clang/FrontendTool/Utils.h"
|
|
||||||
#include "llvm/ADT/Statistic.h"
|
|
||||||
#include "llvm/LinkAllPasses.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Support/Compiler.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#ifdef CLANG_HAVE_RLIMITS
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// have no .a version in packages
|
|
||||||
#undef LINK_POLLY_INTO_TOOLS
|
|
||||||
|
|
||||||
using namespace clang;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// Main driver
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
static void LLVMErrorHandler(void *UserData, const std::string &Message,
|
|
||||||
bool GenCrashDiag) {
|
|
||||||
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
|
|
||||||
|
|
||||||
Diags.Report(diag::err_fe_error_backend) << Message;
|
|
||||||
|
|
||||||
// Run the interrupt handlers to make sure any special cleanups get done, in
|
|
||||||
// particular that we remove files registered with RemoveFileOnSignal.
|
|
||||||
llvm::sys::RunInterruptHandlers();
|
|
||||||
|
|
||||||
// We cannot recover from llvm errors. When reporting a fatal error, exit
|
|
||||||
// with status 70 to generate crash diagnostics. For BSD systems this is
|
|
||||||
// defined as an internal software error. Otherwise, exit with status 1.
|
|
||||||
exit(GenCrashDiag ? 70 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LINK_POLLY_INTO_TOOLS
|
|
||||||
namespace polly {
|
|
||||||
void initializePollyPasses(llvm::PassRegistry &Registry);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CLANG_HAVE_RLIMITS
|
|
||||||
// The amount of stack we think is "sufficient". If less than this much is
|
|
||||||
// available, we may be unable to reach our template instantiation depth
|
|
||||||
// limit and other similar limits.
|
|
||||||
// FIXME: Unify this with the stack we request when spawning a thread to build
|
|
||||||
// a module.
|
|
||||||
static const int kSufficientStack = 8 << 20;
|
|
||||||
|
|
||||||
#if defined(__linux__) && defined(__PIE__)
|
|
||||||
static size_t getCurrentStackAllocation() {
|
|
||||||
// If we can't compute the current stack usage, allow for 512K of command
|
|
||||||
// line arguments and environment.
|
|
||||||
size_t Usage = 512 * 1024;
|
|
||||||
if (FILE *StatFile = fopen("/proc/self/stat", "r")) {
|
|
||||||
// We assume that the stack extends from its current address to the end of
|
|
||||||
// the environment space. In reality, there is another string literal (the
|
|
||||||
// program name) after the environment, but this is close enough (we only
|
|
||||||
// need to be within 100K or so).
|
|
||||||
unsigned long StackPtr, EnvEnd;
|
|
||||||
// Disable silly GCC -Wformat warning that complains about length
|
|
||||||
// modifiers on ignored format specifiers. We want to retain these
|
|
||||||
// for documentation purposes even though they have no effect.
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wformat"
|
|
||||||
#endif
|
|
||||||
if (fscanf(StatFile,
|
|
||||||
"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %*lu "
|
|
||||||
"%*lu %*ld %*ld %*ld %*ld %*ld %*ld %*llu %*lu %*ld %*lu %*lu "
|
|
||||||
"%*lu %*lu %lu %*lu %*lu %*lu %*lu %*lu %*llu %*lu %*lu %*d %*d "
|
|
||||||
"%*u %*u %*llu %*lu %*ld %*lu %*lu %*lu %*lu %*lu %*lu %lu %*d",
|
|
||||||
&StackPtr, &EnvEnd) == 2) {
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
Usage = StackPtr < EnvEnd ? EnvEnd - StackPtr : StackPtr - EnvEnd;
|
|
||||||
}
|
|
||||||
fclose(StatFile);
|
|
||||||
}
|
|
||||||
return Usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <alloca.h>
|
|
||||||
|
|
||||||
LLVM_ATTRIBUTE_NOINLINE
|
|
||||||
static void ensureStackAddressSpace(int ExtraChunks = 0) {
|
|
||||||
// Linux kernels prior to 4.1 will sometimes locate the heap of a PIE binary
|
|
||||||
// relatively close to the stack (they are only guaranteed to be 128MiB
|
|
||||||
// apart). This results in crashes if we happen to heap-allocate more than
|
|
||||||
// 128MiB before we reach our stack high-water mark.
|
|
||||||
//
|
|
||||||
// To avoid these crashes, ensure that we have sufficient virtual memory
|
|
||||||
// pages allocated before we start running.
|
|
||||||
size_t Curr = getCurrentStackAllocation();
|
|
||||||
const int kTargetStack = kSufficientStack - 256 * 1024;
|
|
||||||
if (Curr < kTargetStack) {
|
|
||||||
volatile char *volatile Alloc =
|
|
||||||
static_cast<volatile char *>(alloca(kTargetStack - Curr));
|
|
||||||
Alloc[0] = 0;
|
|
||||||
Alloc[kTargetStack - Curr - 1] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static void ensureStackAddressSpace() {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Attempt to ensure that we have at least 8MiB of usable stack space.
|
|
||||||
static void ensureSufficientStack() {
|
|
||||||
struct rlimit rlim;
|
|
||||||
if (getrlimit(RLIMIT_STACK, &rlim) != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Increase the soft stack limit to our desired level, if necessary and
|
|
||||||
// possible.
|
|
||||||
if (rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur < kSufficientStack) {
|
|
||||||
// Try to allocate sufficient stack.
|
|
||||||
if (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_max >= kSufficientStack)
|
|
||||||
rlim.rlim_cur = kSufficientStack;
|
|
||||||
else if (rlim.rlim_cur == rlim.rlim_max)
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
rlim.rlim_cur = rlim.rlim_max;
|
|
||||||
|
|
||||||
if (setrlimit(RLIMIT_STACK, &rlim) != 0 ||
|
|
||||||
rlim.rlim_cur != kSufficientStack)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should now have a stack of size at least kSufficientStack. Ensure
|
|
||||||
// that we can actually use that much, if necessary.
|
|
||||||
ensureStackAddressSpace();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static void ensureSufficientStack() {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|
||||||
ensureSufficientStack();
|
|
||||||
|
|
||||||
std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
|
|
||||||
// Register the support for object-file-wrapped Clang modules.
|
|
||||||
auto PCHOps = Clang->getPCHContainerOperations();
|
|
||||||
PCHOps->registerWriter(llvm::make_unique<ObjectFilePCHContainerWriter>());
|
|
||||||
PCHOps->registerReader(llvm::make_unique<ObjectFilePCHContainerReader>());
|
|
||||||
|
|
||||||
// Initialize targets first, so that --version shows registered targets.
|
|
||||||
llvm::InitializeAllTargets();
|
|
||||||
llvm::InitializeAllTargetMCs();
|
|
||||||
llvm::InitializeAllAsmPrinters();
|
|
||||||
llvm::InitializeAllAsmParsers();
|
|
||||||
|
|
||||||
#ifdef LINK_POLLY_INTO_TOOLS
|
|
||||||
llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
|
|
||||||
polly::initializePollyPasses(Registry);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Buffer diagnostics from argument parsing so that we can output them using a
|
|
||||||
// well formed diagnostic object.
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
|
||||||
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
|
|
||||||
bool Success = CompilerInvocation::CreateFromArgs(
|
|
||||||
Clang->getInvocation(), Argv.begin(), Argv.end(), Diags);
|
|
||||||
|
|
||||||
// Infer the builtin include path if unspecified.
|
|
||||||
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
|
|
||||||
Clang->getHeaderSearchOpts().ResourceDir.empty())
|
|
||||||
Clang->getHeaderSearchOpts().ResourceDir =
|
|
||||||
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
|
|
||||||
|
|
||||||
// Create the actual diagnostics engine.
|
|
||||||
Clang->createDiagnostics();
|
|
||||||
if (!Clang->hasDiagnostics())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
|
||||||
// error handler.
|
|
||||||
llvm::install_fatal_error_handler(LLVMErrorHandler,
|
|
||||||
static_cast<void*>(&Clang->getDiagnostics()));
|
|
||||||
|
|
||||||
DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
|
|
||||||
if (!Success)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Execute the frontend actions.
|
|
||||||
Success = ExecuteCompilerInvocation(Clang.get());
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now. This happens in -disable-free mode.
|
|
||||||
llvm::TimerGroup::printAll(llvm::errs());
|
|
||||||
|
|
||||||
// Our error handler depends on the Diagnostics object, which we're
|
|
||||||
// potentially about to delete. Uninstall the handler now so that any
|
|
||||||
// later errors use the default handling behavior instead.
|
|
||||||
llvm::remove_fatal_error_handler();
|
|
||||||
|
|
||||||
// When running with -disable-free, don't do any destruction or shutdown.
|
|
||||||
if (Clang->getFrontendOpts().DisableFree) {
|
|
||||||
BuryPointer(std::move(Clang));
|
|
||||||
return !Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !Success;
|
|
||||||
}
|
|
@ -1,540 +0,0 @@
|
|||||||
//===-- cc1as_main.cpp - Clang Assembler ---------------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang -cc1as functionality, which implements
|
|
||||||
// the direct interface to the LLVM MC based assembler.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "clang/Basic/Diagnostic.h"
|
|
||||||
#include "clang/Basic/DiagnosticOptions.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
|
||||||
#include "llvm/ADT/Triple.h"
|
|
||||||
#include "llvm/IR/DataLayout.h"
|
|
||||||
#include "llvm/MC/MCAsmBackend.h"
|
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
|
||||||
#include "llvm/MC/MCCodeEmitter.h"
|
|
||||||
#include "llvm/MC/MCContext.h"
|
|
||||||
#include "llvm/MC/MCInstrInfo.h"
|
|
||||||
#include "llvm/MC/MCObjectFileInfo.h"
|
|
||||||
#include "llvm/MC/MCParser/MCAsmParser.h"
|
|
||||||
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
|
|
||||||
#include "llvm/MC/MCRegisterInfo.h"
|
|
||||||
#include "llvm/MC/MCStreamer.h"
|
|
||||||
#include "llvm/MC/MCSubtargetInfo.h"
|
|
||||||
#include "llvm/MC/MCTargetOptions.h"
|
|
||||||
#include "llvm/Option/Arg.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
|
||||||
#include "llvm/Support/FormattedStream.h"
|
|
||||||
#include "llvm/Support/Host.h"
|
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/SourceMgr.h"
|
|
||||||
#include "llvm/Support/TargetRegistry.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <system_error>
|
|
||||||
using namespace clang;
|
|
||||||
using namespace clang::driver;
|
|
||||||
using namespace clang::driver::options;
|
|
||||||
using namespace llvm;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
/// \brief Helper class for representing a single invocation of the assembler.
|
|
||||||
struct AssemblerInvocation {
|
|
||||||
/// @name Target Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// The name of the target triple to assemble for.
|
|
||||||
std::string Triple;
|
|
||||||
|
|
||||||
/// If given, the name of the target CPU to determine which instructions
|
|
||||||
/// are legal.
|
|
||||||
std::string CPU;
|
|
||||||
|
|
||||||
/// The list of target specific features to enable or disable -- this should
|
|
||||||
/// be a list of strings starting with '+' or '-'.
|
|
||||||
std::vector<std::string> Features;
|
|
||||||
|
|
||||||
/// The list of symbol definitions.
|
|
||||||
std::vector<std::string> SymbolDefs;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Language Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
std::vector<std::string> IncludePaths;
|
|
||||||
unsigned NoInitialTextSection : 1;
|
|
||||||
unsigned SaveTemporaryLabels : 1;
|
|
||||||
unsigned GenDwarfForAssembly : 1;
|
|
||||||
unsigned RelaxELFRelocations : 1;
|
|
||||||
unsigned DwarfVersion;
|
|
||||||
std::string DwarfDebugFlags;
|
|
||||||
std::string DwarfDebugProducer;
|
|
||||||
std::string DebugCompilationDir;
|
|
||||||
llvm::DebugCompressionType CompressDebugSections =
|
|
||||||
llvm::DebugCompressionType::None;
|
|
||||||
std::string MainFileName;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Frontend Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
std::string InputFile;
|
|
||||||
std::vector<std::string> LLVMArgs;
|
|
||||||
std::string OutputPath;
|
|
||||||
enum FileType {
|
|
||||||
FT_Asm, ///< Assembly (.s) output, transliterate mode.
|
|
||||||
FT_Null, ///< No output, for timing purposes.
|
|
||||||
FT_Obj ///< Object file output.
|
|
||||||
};
|
|
||||||
FileType OutputType;
|
|
||||||
unsigned ShowHelp : 1;
|
|
||||||
unsigned ShowVersion : 1;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Transliterate Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
unsigned OutputAsmVariant;
|
|
||||||
unsigned ShowEncoding : 1;
|
|
||||||
unsigned ShowInst : 1;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Assembler Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
unsigned RelaxAll : 1;
|
|
||||||
unsigned NoExecStack : 1;
|
|
||||||
unsigned FatalWarnings : 1;
|
|
||||||
unsigned IncrementalLinkerCompatible : 1;
|
|
||||||
|
|
||||||
/// The name of the relocation model to use.
|
|
||||||
std::string RelocationModel;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
public:
|
|
||||||
AssemblerInvocation() {
|
|
||||||
Triple = "";
|
|
||||||
NoInitialTextSection = 0;
|
|
||||||
InputFile = "-";
|
|
||||||
OutputPath = "-";
|
|
||||||
OutputType = FT_Asm;
|
|
||||||
OutputAsmVariant = 0;
|
|
||||||
ShowInst = 0;
|
|
||||||
ShowEncoding = 0;
|
|
||||||
RelaxAll = 0;
|
|
||||||
NoExecStack = 0;
|
|
||||||
FatalWarnings = 0;
|
|
||||||
IncrementalLinkerCompatible = 0;
|
|
||||||
DwarfVersion = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool CreateFromArgs(AssemblerInvocation &Res,
|
|
||||||
ArrayRef<const char *> Argv,
|
|
||||||
DiagnosticsEngine &Diags);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
|
|
||||||
ArrayRef<const char *> Argv,
|
|
||||||
DiagnosticsEngine &Diags) {
|
|
||||||
bool Success = true;
|
|
||||||
|
|
||||||
// Parse the arguments.
|
|
||||||
std::unique_ptr<OptTable> OptTbl(createDriverOptTable());
|
|
||||||
|
|
||||||
const unsigned IncludedFlagsBitmask = options::CC1AsOption;
|
|
||||||
unsigned MissingArgIndex, MissingArgCount;
|
|
||||||
InputArgList Args = OptTbl->ParseArgs(Argv, MissingArgIndex, MissingArgCount,
|
|
||||||
IncludedFlagsBitmask);
|
|
||||||
|
|
||||||
// Check for missing argument error.
|
|
||||||
if (MissingArgCount) {
|
|
||||||
Diags.Report(diag::err_drv_missing_argument)
|
|
||||||
<< Args.getArgString(MissingArgIndex) << MissingArgCount;
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Issue errors on unknown arguments.
|
|
||||||
for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct the invocation.
|
|
||||||
|
|
||||||
// Target Options
|
|
||||||
Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
|
|
||||||
Opts.CPU = Args.getLastArgValue(OPT_target_cpu);
|
|
||||||
Opts.Features = Args.getAllArgValues(OPT_target_feature);
|
|
||||||
|
|
||||||
// Use the default target triple if unspecified.
|
|
||||||
if (Opts.Triple.empty())
|
|
||||||
Opts.Triple = llvm::sys::getDefaultTargetTriple();
|
|
||||||
|
|
||||||
// Language Options
|
|
||||||
Opts.IncludePaths = Args.getAllArgValues(OPT_I);
|
|
||||||
Opts.NoInitialTextSection = Args.hasArg(OPT_n);
|
|
||||||
Opts.SaveTemporaryLabels = Args.hasArg(OPT_msave_temp_labels);
|
|
||||||
// Any DebugInfoKind implies GenDwarfForAssembly.
|
|
||||||
Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ);
|
|
||||||
|
|
||||||
if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections,
|
|
||||||
OPT_compress_debug_sections_EQ)) {
|
|
||||||
if (A->getOption().getID() == OPT_compress_debug_sections) {
|
|
||||||
// TODO: be more clever about the compression type auto-detection
|
|
||||||
Opts.CompressDebugSections = llvm::DebugCompressionType::GNU;
|
|
||||||
} else {
|
|
||||||
Opts.CompressDebugSections =
|
|
||||||
llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue())
|
|
||||||
.Case("none", llvm::DebugCompressionType::None)
|
|
||||||
.Case("zlib", llvm::DebugCompressionType::Z)
|
|
||||||
.Case("zlib-gnu", llvm::DebugCompressionType::GNU)
|
|
||||||
.Default(llvm::DebugCompressionType::None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
|
|
||||||
Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
|
|
||||||
Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
|
|
||||||
Opts.DwarfDebugProducer = Args.getLastArgValue(OPT_dwarf_debug_producer);
|
|
||||||
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
|
|
||||||
Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
|
|
||||||
|
|
||||||
// Frontend Options
|
|
||||||
if (Args.hasArg(OPT_INPUT)) {
|
|
||||||
bool First = true;
|
|
||||||
for (const Arg *A : Args.filtered(OPT_INPUT)) {
|
|
||||||
if (First) {
|
|
||||||
Opts.InputFile = A->getValue();
|
|
||||||
First = false;
|
|
||||||
} else {
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
|
|
||||||
Opts.OutputPath = Args.getLastArgValue(OPT_o);
|
|
||||||
if (Arg *A = Args.getLastArg(OPT_filetype)) {
|
|
||||||
StringRef Name = A->getValue();
|
|
||||||
unsigned OutputType = StringSwitch<unsigned>(Name)
|
|
||||||
.Case("asm", FT_Asm)
|
|
||||||
.Case("null", FT_Null)
|
|
||||||
.Case("obj", FT_Obj)
|
|
||||||
.Default(~0U);
|
|
||||||
if (OutputType == ~0U) {
|
|
||||||
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
|
|
||||||
Success = false;
|
|
||||||
} else
|
|
||||||
Opts.OutputType = FileType(OutputType);
|
|
||||||
}
|
|
||||||
Opts.ShowHelp = Args.hasArg(OPT_help);
|
|
||||||
Opts.ShowVersion = Args.hasArg(OPT_version);
|
|
||||||
|
|
||||||
// Transliterate Options
|
|
||||||
Opts.OutputAsmVariant =
|
|
||||||
getLastArgIntValue(Args, OPT_output_asm_variant, 0, Diags);
|
|
||||||
Opts.ShowEncoding = Args.hasArg(OPT_show_encoding);
|
|
||||||
Opts.ShowInst = Args.hasArg(OPT_show_inst);
|
|
||||||
|
|
||||||
// Assemble Options
|
|
||||||
Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
|
|
||||||
Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
|
|
||||||
Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
|
|
||||||
Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
|
|
||||||
Opts.IncrementalLinkerCompatible =
|
|
||||||
Args.hasArg(OPT_mincremental_linker_compatible);
|
|
||||||
Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::unique_ptr<raw_fd_ostream>
|
|
||||||
getOutputStream(AssemblerInvocation &Opts, DiagnosticsEngine &Diags,
|
|
||||||
bool Binary) {
|
|
||||||
if (Opts.OutputPath.empty())
|
|
||||||
Opts.OutputPath = "-";
|
|
||||||
|
|
||||||
// Make sure that the Out file gets unlinked from the disk if we get a
|
|
||||||
// SIGINT.
|
|
||||||
if (Opts.OutputPath != "-")
|
|
||||||
sys::RemoveFileOnSignal(Opts.OutputPath);
|
|
||||||
|
|
||||||
std::error_code EC;
|
|
||||||
auto Out = llvm::make_unique<raw_fd_ostream>(
|
|
||||||
Opts.OutputPath, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text));
|
|
||||||
if (EC) {
|
|
||||||
Diags.Report(diag::err_fe_unable_to_open_output) << Opts.OutputPath
|
|
||||||
<< EC.message();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Out;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ExecuteAssembler(AssemblerInvocation &Opts,
|
|
||||||
DiagnosticsEngine &Diags) {
|
|
||||||
// Get the target specific parser.
|
|
||||||
std::string Error;
|
|
||||||
const Target *TheTarget = TargetRegistry::lookupTarget(Opts.Triple, Error);
|
|
||||||
if (!TheTarget)
|
|
||||||
return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
|
|
||||||
|
|
||||||
ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
|
|
||||||
MemoryBuffer::getFileOrSTDIN(Opts.InputFile);
|
|
||||||
|
|
||||||
if (std::error_code EC = Buffer.getError()) {
|
|
||||||
Error = EC.message();
|
|
||||||
return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
SourceMgr SrcMgr;
|
|
||||||
|
|
||||||
// Tell SrcMgr about this buffer, which is what the parser will pick up.
|
|
||||||
SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc());
|
|
||||||
|
|
||||||
// Record the location of the include directories so that the lexer can find
|
|
||||||
// it later.
|
|
||||||
SrcMgr.setIncludeDirs(Opts.IncludePaths);
|
|
||||||
|
|
||||||
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(Opts.Triple));
|
|
||||||
assert(MRI && "Unable to create target register info!");
|
|
||||||
|
|
||||||
std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, Opts.Triple));
|
|
||||||
assert(MAI && "Unable to create target asm info!");
|
|
||||||
|
|
||||||
// Ensure MCAsmInfo initialization occurs before any use, otherwise sections
|
|
||||||
// may be created with a combination of default and explicit settings.
|
|
||||||
MAI->setCompressDebugSections(Opts.CompressDebugSections);
|
|
||||||
|
|
||||||
MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations);
|
|
||||||
|
|
||||||
bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj;
|
|
||||||
std::unique_ptr<raw_fd_ostream> FDOS = getOutputStream(Opts, Diags, IsBinary);
|
|
||||||
if (!FDOS)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
|
|
||||||
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
|
|
||||||
std::unique_ptr<MCObjectFileInfo> MOFI(new MCObjectFileInfo());
|
|
||||||
|
|
||||||
MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr);
|
|
||||||
|
|
||||||
bool PIC = false;
|
|
||||||
if (Opts.RelocationModel == "static") {
|
|
||||||
PIC = false;
|
|
||||||
} else if (Opts.RelocationModel == "pic") {
|
|
||||||
PIC = true;
|
|
||||||
} else {
|
|
||||||
assert(Opts.RelocationModel == "dynamic-no-pic" &&
|
|
||||||
"Invalid PIC model!");
|
|
||||||
PIC = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), PIC, CodeModel::Default, Ctx);
|
|
||||||
if (Opts.SaveTemporaryLabels)
|
|
||||||
Ctx.setAllowTemporaryLabels(false);
|
|
||||||
if (Opts.GenDwarfForAssembly)
|
|
||||||
Ctx.setGenDwarfForAssembly(true);
|
|
||||||
if (!Opts.DwarfDebugFlags.empty())
|
|
||||||
Ctx.setDwarfDebugFlags(StringRef(Opts.DwarfDebugFlags));
|
|
||||||
if (!Opts.DwarfDebugProducer.empty())
|
|
||||||
Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
|
|
||||||
if (!Opts.DebugCompilationDir.empty())
|
|
||||||
Ctx.setCompilationDir(Opts.DebugCompilationDir);
|
|
||||||
if (!Opts.MainFileName.empty())
|
|
||||||
Ctx.setMainFileName(StringRef(Opts.MainFileName));
|
|
||||||
Ctx.setDwarfVersion(Opts.DwarfVersion);
|
|
||||||
|
|
||||||
// Build up the feature string from the target feature list.
|
|
||||||
std::string FS;
|
|
||||||
if (!Opts.Features.empty()) {
|
|
||||||
FS = Opts.Features[0];
|
|
||||||
for (unsigned i = 1, e = Opts.Features.size(); i != e; ++i)
|
|
||||||
FS += "," + Opts.Features[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<MCStreamer> Str;
|
|
||||||
|
|
||||||
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
|
|
||||||
std::unique_ptr<MCSubtargetInfo> STI(
|
|
||||||
TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS));
|
|
||||||
|
|
||||||
raw_pwrite_stream *Out = FDOS.get();
|
|
||||||
std::unique_ptr<buffer_ostream> BOS;
|
|
||||||
|
|
||||||
// FIXME: There is a bit of code duplication with addPassesToEmitFile.
|
|
||||||
if (Opts.OutputType == AssemblerInvocation::FT_Asm) {
|
|
||||||
MCInstPrinter *IP = TheTarget->createMCInstPrinter(
|
|
||||||
llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI);
|
|
||||||
MCCodeEmitter *CE = nullptr;
|
|
||||||
MCAsmBackend *MAB = nullptr;
|
|
||||||
if (Opts.ShowEncoding) {
|
|
||||||
CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx);
|
|
||||||
MCTargetOptions Options;
|
|
||||||
MAB = TheTarget->createMCAsmBackend(*MRI, Opts.Triple, Opts.CPU, Options);
|
|
||||||
}
|
|
||||||
auto FOut = llvm::make_unique<formatted_raw_ostream>(*Out);
|
|
||||||
Str.reset(TheTarget->createAsmStreamer(
|
|
||||||
Ctx, std::move(FOut), /*asmverbose*/ true,
|
|
||||||
/*useDwarfDirectory*/ true, IP, CE, MAB, Opts.ShowInst));
|
|
||||||
} else if (Opts.OutputType == AssemblerInvocation::FT_Null) {
|
|
||||||
Str.reset(createNullStreamer(Ctx));
|
|
||||||
} else {
|
|
||||||
assert(Opts.OutputType == AssemblerInvocation::FT_Obj &&
|
|
||||||
"Invalid file type!");
|
|
||||||
if (!FDOS->supportsSeeking()) {
|
|
||||||
BOS = make_unique<buffer_ostream>(*FDOS);
|
|
||||||
Out = BOS.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx);
|
|
||||||
MCTargetOptions Options;
|
|
||||||
MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*MRI, Opts.Triple,
|
|
||||||
Opts.CPU, Options);
|
|
||||||
Triple T(Opts.Triple);
|
|
||||||
Str.reset(TheTarget->createMCObjectStreamer(
|
|
||||||
T, Ctx, *MAB, *Out, CE, *STI, Opts.RelaxAll,
|
|
||||||
Opts.IncrementalLinkerCompatible,
|
|
||||||
/*DWARFMustBeAtTheEnd*/ true));
|
|
||||||
Str.get()->InitSections(Opts.NoExecStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Failed = false;
|
|
||||||
|
|
||||||
std::unique_ptr<MCAsmParser> Parser(
|
|
||||||
createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI));
|
|
||||||
|
|
||||||
// FIXME: init MCTargetOptions from sanitizer flags here.
|
|
||||||
MCTargetOptions Options;
|
|
||||||
std::unique_ptr<MCTargetAsmParser> TAP(
|
|
||||||
TheTarget->createMCAsmParser(*STI, *Parser, *MCII, Options));
|
|
||||||
if (!TAP)
|
|
||||||
Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
|
|
||||||
|
|
||||||
// Set values for symbols, if any.
|
|
||||||
for (auto &S : Opts.SymbolDefs) {
|
|
||||||
auto Pair = StringRef(S).split('=');
|
|
||||||
auto Sym = Pair.first;
|
|
||||||
auto Val = Pair.second;
|
|
||||||
int64_t Value;
|
|
||||||
// We have already error checked this in the driver.
|
|
||||||
Val.getAsInteger(0, Value);
|
|
||||||
Ctx.setSymbolValue(Parser->getStreamer(), Sym, Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Failed) {
|
|
||||||
Parser->setTargetParser(*TAP.get());
|
|
||||||
Failed = Parser->Run(Opts.NoInitialTextSection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close Streamer first.
|
|
||||||
// It might have a reference to the output stream.
|
|
||||||
Str.reset();
|
|
||||||
// Close the output stream early.
|
|
||||||
BOS.reset();
|
|
||||||
FDOS.reset();
|
|
||||||
|
|
||||||
// Delete output file if there were errors.
|
|
||||||
if (Failed && Opts.OutputPath != "-")
|
|
||||||
sys::fs::remove(Opts.OutputPath);
|
|
||||||
|
|
||||||
return Failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void LLVMErrorHandler(void *UserData, const std::string &Message,
|
|
||||||
bool GenCrashDiag) {
|
|
||||||
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
|
|
||||||
|
|
||||||
Diags.Report(diag::err_fe_error_backend) << Message;
|
|
||||||
|
|
||||||
// We cannot recover from llvm errors.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|
||||||
// Initialize targets and assembly printers/parsers.
|
|
||||||
InitializeAllTargetInfos();
|
|
||||||
InitializeAllTargetMCs();
|
|
||||||
InitializeAllAsmParsers();
|
|
||||||
|
|
||||||
// Construct our diagnostic client.
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
|
||||||
TextDiagnosticPrinter *DiagClient
|
|
||||||
= new TextDiagnosticPrinter(errs(), &*DiagOpts);
|
|
||||||
DiagClient->setPrefix("clang -cc1as");
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
|
||||||
|
|
||||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
|
||||||
// error handler.
|
|
||||||
ScopedFatalErrorHandler FatalErrorHandler
|
|
||||||
(LLVMErrorHandler, static_cast<void*>(&Diags));
|
|
||||||
|
|
||||||
// Parse the arguments.
|
|
||||||
AssemblerInvocation Asm;
|
|
||||||
if (!AssemblerInvocation::CreateFromArgs(Asm, Argv, Diags))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (Asm.ShowHelp) {
|
|
||||||
std::unique_ptr<OptTable> Opts(driver::createDriverOptTable());
|
|
||||||
Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
|
|
||||||
/*Include=*/driver::options::CC1AsOption, /*Exclude=*/0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Honor -version.
|
|
||||||
//
|
|
||||||
// FIXME: Use a better -version message?
|
|
||||||
if (Asm.ShowVersion) {
|
|
||||||
llvm::cl::PrintVersionMessage();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Honor -mllvm.
|
|
||||||
//
|
|
||||||
// FIXME: Remove this, one day.
|
|
||||||
if (!Asm.LLVMArgs.empty()) {
|
|
||||||
unsigned NumArgs = Asm.LLVMArgs.size();
|
|
||||||
auto Args = llvm::make_unique<const char*[]>(NumArgs + 2);
|
|
||||||
Args[0] = "clang (LLVM option parsing)";
|
|
||||||
for (unsigned i = 0; i != NumArgs; ++i)
|
|
||||||
Args[i + 1] = Asm.LLVMArgs[i].c_str();
|
|
||||||
Args[NumArgs + 1] = nullptr;
|
|
||||||
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the invocation, unless there were parsing errors.
|
|
||||||
bool Failed = Diags.hasErrorOccurred() || ExecuteAssembler(Asm, Diags);
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now.
|
|
||||||
TimerGroup::printAll(errs());
|
|
||||||
|
|
||||||
return !!Failed;
|
|
||||||
}
|
|
@ -1,519 +0,0 @@
|
|||||||
//===-- driver.cpp - Clang GCC-Compatible Driver --------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang driver; it is a thin wrapper
|
|
||||||
// for functionality in the Driver clang library.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "clang/Basic/DiagnosticOptions.h"
|
|
||||||
#include "clang/Driver/Compilation.h"
|
|
||||||
#include "clang/Driver/Driver.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Driver/ToolChain.h"
|
|
||||||
#include "clang/Frontend/ChainedDiagnosticConsumer.h"
|
|
||||||
#include "clang/Frontend/CompilerInvocation.h"
|
|
||||||
#include "clang/Frontend/SerializedDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
|
||||||
#include "llvm/ADT/SmallString.h"
|
|
||||||
#include "llvm/ADT/SmallVector.h"
|
|
||||||
#include "llvm/Config/llvm-config.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Option/Option.h"
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
|
||||||
#include "llvm/Support/Host.h"
|
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/PrettyStackTrace.h"
|
|
||||||
#include "llvm/Support/Process.h"
|
|
||||||
#include "llvm/Support/Program.h"
|
|
||||||
#include "llvm/Support/Regex.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/StringSaver.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <set>
|
|
||||||
#include <system_error>
|
|
||||||
using namespace clang;
|
|
||||||
using namespace clang::driver;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
|
|
||||||
if (!CanonicalPrefixes) {
|
|
||||||
SmallString<128> ExecutablePath(Argv0);
|
|
||||||
// Do a PATH lookup if Argv0 isn't a valid path.
|
|
||||||
if (!llvm::sys::fs::exists(ExecutablePath))
|
|
||||||
if (llvm::ErrorOr<std::string> P =
|
|
||||||
llvm::sys::findProgramByName(ExecutablePath))
|
|
||||||
ExecutablePath = *P;
|
|
||||||
return ExecutablePath.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This just needs to be some symbol in the binary; C++ doesn't
|
|
||||||
// allow taking the address of ::main however.
|
|
||||||
void *P = (void*) (intptr_t) GetExecutablePath;
|
|
||||||
return llvm::sys::fs::getMainExecutable(Argv0, P);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *GetStableCStr(std::set<std::string> &SavedStrings,
|
|
||||||
StringRef S) {
|
|
||||||
return SavedStrings.insert(S).first->c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ApplyQAOverride - Apply a list of edits to the input argument lists.
|
|
||||||
///
|
|
||||||
/// The input string is a space separate list of edits to perform,
|
|
||||||
/// they are applied in order to the input argument lists. Edits
|
|
||||||
/// should be one of the following forms:
|
|
||||||
///
|
|
||||||
/// '#': Silence information about the changes to the command line arguments.
|
|
||||||
///
|
|
||||||
/// '^': Add FOO as a new argument at the beginning of the command line.
|
|
||||||
///
|
|
||||||
/// '+': Add FOO as a new argument at the end of the command line.
|
|
||||||
///
|
|
||||||
/// 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
|
|
||||||
/// line.
|
|
||||||
///
|
|
||||||
/// 'xOPTION': Removes all instances of the literal argument OPTION.
|
|
||||||
///
|
|
||||||
/// 'XOPTION': Removes all instances of the literal argument OPTION,
|
|
||||||
/// and the following argument.
|
|
||||||
///
|
|
||||||
/// 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
|
|
||||||
/// at the end of the command line.
|
|
||||||
///
|
|
||||||
/// \param OS - The stream to write edit information to.
|
|
||||||
/// \param Args - The vector of command line arguments.
|
|
||||||
/// \param Edit - The override command to perform.
|
|
||||||
/// \param SavedStrings - Set to use for storing string representations.
|
|
||||||
static void ApplyOneQAOverride(raw_ostream &OS,
|
|
||||||
SmallVectorImpl<const char*> &Args,
|
|
||||||
StringRef Edit,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
// This does not need to be efficient.
|
|
||||||
|
|
||||||
if (Edit[0] == '^') {
|
|
||||||
const char *Str =
|
|
||||||
GetStableCStr(SavedStrings, Edit.substr(1));
|
|
||||||
OS << "### Adding argument " << Str << " at beginning\n";
|
|
||||||
Args.insert(Args.begin() + 1, Str);
|
|
||||||
} else if (Edit[0] == '+') {
|
|
||||||
const char *Str =
|
|
||||||
GetStableCStr(SavedStrings, Edit.substr(1));
|
|
||||||
OS << "### Adding argument " << Str << " at end\n";
|
|
||||||
Args.push_back(Str);
|
|
||||||
} else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
|
|
||||||
Edit.slice(2, Edit.size()-1).find('/') != StringRef::npos) {
|
|
||||||
StringRef MatchPattern = Edit.substr(2).split('/').first;
|
|
||||||
StringRef ReplPattern = Edit.substr(2).split('/').second;
|
|
||||||
ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1);
|
|
||||||
|
|
||||||
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
|
|
||||||
// Ignore end-of-line response file markers
|
|
||||||
if (Args[i] == nullptr)
|
|
||||||
continue;
|
|
||||||
std::string Repl = llvm::Regex(MatchPattern).sub(ReplPattern, Args[i]);
|
|
||||||
|
|
||||||
if (Repl != Args[i]) {
|
|
||||||
OS << "### Replacing '" << Args[i] << "' with '" << Repl << "'\n";
|
|
||||||
Args[i] = GetStableCStr(SavedStrings, Repl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (Edit[0] == 'x' || Edit[0] == 'X') {
|
|
||||||
auto Option = Edit.substr(1);
|
|
||||||
for (unsigned i = 1; i < Args.size();) {
|
|
||||||
if (Option == Args[i]) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
if (Edit[0] == 'X') {
|
|
||||||
if (i < Args.size()) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
} else
|
|
||||||
OS << "### Invalid X edit, end of command line!\n";
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
} else if (Edit[0] == 'O') {
|
|
||||||
for (unsigned i = 1; i < Args.size();) {
|
|
||||||
const char *A = Args[i];
|
|
||||||
// Ignore end-of-line response file markers
|
|
||||||
if (A == nullptr)
|
|
||||||
continue;
|
|
||||||
if (A[0] == '-' && A[1] == 'O' &&
|
|
||||||
(A[2] == '\0' ||
|
|
||||||
(A[3] == '\0' && (A[2] == 's' || A[2] == 'z' ||
|
|
||||||
('0' <= A[2] && A[2] <= '9'))))) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
} else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
OS << "### Adding argument " << Edit << " at end\n";
|
|
||||||
Args.push_back(GetStableCStr(SavedStrings, '-' + Edit.str()));
|
|
||||||
} else {
|
|
||||||
OS << "### Unrecognized edit: " << Edit << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ApplyQAOverride - Apply a comma separate list of edits to the
|
|
||||||
/// input argument lists. See ApplyOneQAOverride.
|
|
||||||
static void ApplyQAOverride(SmallVectorImpl<const char*> &Args,
|
|
||||||
const char *OverrideStr,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
raw_ostream *OS = &llvm::errs();
|
|
||||||
|
|
||||||
if (OverrideStr[0] == '#') {
|
|
||||||
++OverrideStr;
|
|
||||||
OS = &llvm::nulls();
|
|
||||||
}
|
|
||||||
|
|
||||||
*OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
|
|
||||||
|
|
||||||
// This does not need to be efficient.
|
|
||||||
|
|
||||||
const char *S = OverrideStr;
|
|
||||||
while (*S) {
|
|
||||||
const char *End = ::strchr(S, ' ');
|
|
||||||
if (!End)
|
|
||||||
End = S + strlen(S);
|
|
||||||
if (End != S)
|
|
||||||
ApplyOneQAOverride(*OS, Args, std::string(S, End), SavedStrings);
|
|
||||||
S = End;
|
|
||||||
if (*S != '\0')
|
|
||||||
++S;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0,
|
|
||||||
void *MainAddr);
|
|
||||||
extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0,
|
|
||||||
void *MainAddr);
|
|
||||||
|
|
||||||
static void insertTargetAndModeArgs(StringRef Target, StringRef Mode,
|
|
||||||
SmallVectorImpl<const char *> &ArgVector,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
if (!Mode.empty()) {
|
|
||||||
// Add the mode flag to the arguments.
|
|
||||||
auto it = ArgVector.begin();
|
|
||||||
if (it != ArgVector.end())
|
|
||||||
++it;
|
|
||||||
ArgVector.insert(it, GetStableCStr(SavedStrings, Mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Target.empty()) {
|
|
||||||
auto it = ArgVector.begin();
|
|
||||||
if (it != ArgVector.end())
|
|
||||||
++it;
|
|
||||||
const char *arr[] = {"-target", GetStableCStr(SavedStrings, Target)};
|
|
||||||
ArgVector.insert(it, std::begin(arr), std::end(arr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void getCLEnvVarOptions(std::string &EnvValue, llvm::StringSaver &Saver,
|
|
||||||
SmallVectorImpl<const char *> &Opts) {
|
|
||||||
llvm::cl::TokenizeWindowsCommandLine(EnvValue, Saver, Opts);
|
|
||||||
// The first instance of '#' should be replaced with '=' in each option.
|
|
||||||
for (const char *Opt : Opts)
|
|
||||||
if (char *NumberSignPtr = const_cast<char *>(::strchr(Opt, '#')))
|
|
||||||
*NumberSignPtr = '=';
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) {
|
|
||||||
// Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
|
|
||||||
TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
|
|
||||||
if (TheDriver.CCPrintOptions)
|
|
||||||
TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE");
|
|
||||||
|
|
||||||
// Handle CC_PRINT_HEADERS and CC_PRINT_HEADERS_FILE.
|
|
||||||
TheDriver.CCPrintHeaders = !!::getenv("CC_PRINT_HEADERS");
|
|
||||||
if (TheDriver.CCPrintHeaders)
|
|
||||||
TheDriver.CCPrintHeadersFilename = ::getenv("CC_PRINT_HEADERS_FILE");
|
|
||||||
|
|
||||||
// Handle CC_LOG_DIAGNOSTICS and CC_LOG_DIAGNOSTICS_FILE.
|
|
||||||
TheDriver.CCLogDiagnostics = !!::getenv("CC_LOG_DIAGNOSTICS");
|
|
||||||
if (TheDriver.CCLogDiagnostics)
|
|
||||||
TheDriver.CCLogDiagnosticsFilename = ::getenv("CC_LOG_DIAGNOSTICS_FILE");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
|
|
||||||
const std::string &Path) {
|
|
||||||
// If the clang binary happens to be named cl.exe for compatibility reasons,
|
|
||||||
// use clang-cl.exe as the prefix to avoid confusion between clang and MSVC.
|
|
||||||
StringRef ExeBasename(llvm::sys::path::filename(Path));
|
|
||||||
if (ExeBasename.equals_lower("cl.exe"))
|
|
||||||
ExeBasename = "clang-cl.exe";
|
|
||||||
DiagClient->setPrefix(ExeBasename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This lets us create the DiagnosticsEngine with a properly-filled-out
|
|
||||||
// DiagnosticOptions instance.
|
|
||||||
static DiagnosticOptions *
|
|
||||||
CreateAndPopulateDiagOpts(ArrayRef<const char *> argv) {
|
|
||||||
auto *DiagOpts = new DiagnosticOptions;
|
|
||||||
std::unique_ptr<OptTable> Opts(createDriverOptTable());
|
|
||||||
unsigned MissingArgIndex, MissingArgCount;
|
|
||||||
InputArgList Args =
|
|
||||||
Opts->ParseArgs(argv.slice(1), MissingArgIndex, MissingArgCount);
|
|
||||||
// We ignore MissingArgCount and the return value of ParseDiagnosticArgs.
|
|
||||||
// Any errors that would be diagnosed here will also be diagnosed later,
|
|
||||||
// when the DiagnosticsEngine actually exists.
|
|
||||||
(void)ParseDiagnosticArgs(*DiagOpts, Args);
|
|
||||||
return DiagOpts;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetInstallDir(SmallVectorImpl<const char *> &argv,
|
|
||||||
Driver &TheDriver, bool CanonicalPrefixes) {
|
|
||||||
// Attempt to find the original path used to invoke the driver, to determine
|
|
||||||
// the installed path. We do this manually, because we want to support that
|
|
||||||
// path being a symlink.
|
|
||||||
SmallString<128> InstalledPath(argv[0]);
|
|
||||||
|
|
||||||
// Do a PATH lookup, if there are no directory components.
|
|
||||||
if (llvm::sys::path::filename(InstalledPath) == InstalledPath)
|
|
||||||
if (llvm::ErrorOr<std::string> Tmp = llvm::sys::findProgramByName(
|
|
||||||
llvm::sys::path::filename(InstalledPath.str())))
|
|
||||||
InstalledPath = *Tmp;
|
|
||||||
|
|
||||||
// FIXME: We don't actually canonicalize this, we just make it absolute.
|
|
||||||
if (CanonicalPrefixes)
|
|
||||||
llvm::sys::fs::make_absolute(InstalledPath);
|
|
||||||
|
|
||||||
StringRef InstalledPathParent(llvm::sys::path::parent_path(InstalledPath));
|
|
||||||
if (llvm::sys::fs::exists(InstalledPathParent))
|
|
||||||
TheDriver.setInstalledDir(InstalledPathParent);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ExecuteCC1Tool(ArrayRef<const char *> argv, StringRef Tool) {
|
|
||||||
void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath;
|
|
||||||
if (Tool == "")
|
|
||||||
return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP);
|
|
||||||
if (Tool == "as")
|
|
||||||
return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
|
|
||||||
|
|
||||||
// Reject unknown tools.
|
|
||||||
llvm::errs() << "error: unknown integrated tool '" << Tool << "'\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mainEntryClickHouseClang(int argc_, char **argv_) {
|
|
||||||
llvm::sys::PrintStackTraceOnErrorSignal(argv_[0]);
|
|
||||||
llvm::PrettyStackTraceProgram X(argc_, argv_);
|
|
||||||
llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
|
||||||
|
|
||||||
if (llvm::sys::Process::FixupStandardFileDescriptors())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
SmallVector<const char *, 256> argv;
|
|
||||||
llvm::SpecificBumpPtrAllocator<char> ArgAllocator;
|
|
||||||
std::error_code EC = llvm::sys::Process::GetArgumentVector(
|
|
||||||
argv, llvm::makeArrayRef(argv_, argc_), ArgAllocator);
|
|
||||||
if (EC) {
|
|
||||||
llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n';
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm::InitializeAllTargets();
|
|
||||||
std::string ProgName = argv[0];
|
|
||||||
std::pair<std::string, std::string> TargetAndMode =
|
|
||||||
ToolChain::getTargetAndModeFromProgramName(ProgName);
|
|
||||||
|
|
||||||
llvm::BumpPtrAllocator A;
|
|
||||||
llvm::StringSaver Saver(A);
|
|
||||||
|
|
||||||
// Parse response files using the GNU syntax, unless we're in CL mode. There
|
|
||||||
// are two ways to put clang in CL compatibility mode: argv[0] is either
|
|
||||||
// clang-cl or cl, or --driver-mode=cl is on the command line. The normal
|
|
||||||
// command line parsing can't happen until after response file parsing, so we
|
|
||||||
// have to manually search for a --driver-mode=cl argument the hard way.
|
|
||||||
// Finally, our -cc1 tools don't care which tokenization mode we use because
|
|
||||||
// response files written by clang will tokenize the same way in either mode.
|
|
||||||
bool ClangCLMode = false;
|
|
||||||
if (TargetAndMode.second == "--driver-mode=cl" ||
|
|
||||||
std::find_if(argv.begin(), argv.end(), [](const char *F) {
|
|
||||||
return F && strcmp(F, "--driver-mode=cl") == 0;
|
|
||||||
}) != argv.end()) {
|
|
||||||
ClangCLMode = true;
|
|
||||||
}
|
|
||||||
enum { Default, POSIX, Windows } RSPQuoting = Default;
|
|
||||||
for (const char *F : argv) {
|
|
||||||
if (strcmp(F, "--rsp-quoting=posix") == 0)
|
|
||||||
RSPQuoting = POSIX;
|
|
||||||
else if (strcmp(F, "--rsp-quoting=windows") == 0)
|
|
||||||
RSPQuoting = Windows;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determines whether we want nullptr markers in argv to indicate response
|
|
||||||
// files end-of-lines. We only use this for the /LINK driver argument with
|
|
||||||
// clang-cl.exe on Windows.
|
|
||||||
bool MarkEOLs = ClangCLMode;
|
|
||||||
|
|
||||||
llvm::cl::TokenizerCallback Tokenizer;
|
|
||||||
if (RSPQuoting == Windows || (RSPQuoting == Default && ClangCLMode))
|
|
||||||
Tokenizer = &llvm::cl::TokenizeWindowsCommandLine;
|
|
||||||
else
|
|
||||||
Tokenizer = &llvm::cl::TokenizeGNUCommandLine;
|
|
||||||
|
|
||||||
if (MarkEOLs && argv.size() > 1 && StringRef(argv[1]).startswith("-cc1"))
|
|
||||||
MarkEOLs = false;
|
|
||||||
llvm::cl::ExpandResponseFiles(Saver, Tokenizer, argv, MarkEOLs);
|
|
||||||
|
|
||||||
// Handle -cc1 integrated tools, even if -cc1 was expanded from a response
|
|
||||||
// file.
|
|
||||||
auto FirstArg = std::find_if(argv.begin() + 1, argv.end(),
|
|
||||||
[](const char *A) { return A != nullptr; });
|
|
||||||
if (FirstArg != argv.end() && StringRef(*FirstArg).startswith("-cc1")) {
|
|
||||||
// If -cc1 came from a response file, remove the EOL sentinels.
|
|
||||||
if (MarkEOLs) {
|
|
||||||
auto newEnd = std::remove(argv.begin(), argv.end(), nullptr);
|
|
||||||
argv.resize(newEnd - argv.begin());
|
|
||||||
}
|
|
||||||
return ExecuteCC1Tool(argv, argv[1] + 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CanonicalPrefixes = true;
|
|
||||||
for (int i = 1, size = argv.size(); i < size; ++i) {
|
|
||||||
// Skip end-of-line response file markers
|
|
||||||
if (argv[i] == nullptr)
|
|
||||||
continue;
|
|
||||||
if (StringRef(argv[i]) == "-no-canonical-prefixes") {
|
|
||||||
CanonicalPrefixes = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle CL and _CL_ which permits additional command line options to be
|
|
||||||
// prepended or appended.
|
|
||||||
if (ClangCLMode) {
|
|
||||||
// Arguments in "CL" are prepended.
|
|
||||||
llvm::Optional<std::string> OptCL = llvm::sys::Process::GetEnv("CL");
|
|
||||||
if (OptCL.hasValue()) {
|
|
||||||
SmallVector<const char *, 8> PrependedOpts;
|
|
||||||
getCLEnvVarOptions(OptCL.getValue(), Saver, PrependedOpts);
|
|
||||||
|
|
||||||
// Insert right after the program name to prepend to the argument list.
|
|
||||||
argv.insert(argv.begin() + 1, PrependedOpts.begin(), PrependedOpts.end());
|
|
||||||
}
|
|
||||||
// Arguments in "_CL_" are appended.
|
|
||||||
llvm::Optional<std::string> Opt_CL_ = llvm::sys::Process::GetEnv("_CL_");
|
|
||||||
if (Opt_CL_.hasValue()) {
|
|
||||||
SmallVector<const char *, 8> AppendedOpts;
|
|
||||||
getCLEnvVarOptions(Opt_CL_.getValue(), Saver, AppendedOpts);
|
|
||||||
|
|
||||||
// Insert at the end of the argument list to append.
|
|
||||||
argv.append(AppendedOpts.begin(), AppendedOpts.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<std::string> SavedStrings;
|
|
||||||
// Handle CCC_OVERRIDE_OPTIONS, used for editing a command line behind the
|
|
||||||
// scenes.
|
|
||||||
if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
|
|
||||||
// FIXME: Driver shouldn't take extra initial argument.
|
|
||||||
ApplyQAOverride(argv, OverrideStr, SavedStrings);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Path = GetExecutablePath(argv[0], CanonicalPrefixes);
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
|
|
||||||
CreateAndPopulateDiagOpts(argv);
|
|
||||||
|
|
||||||
TextDiagnosticPrinter *DiagClient
|
|
||||||
= new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
|
|
||||||
FixupDiagPrefixExeName(DiagClient, Path);
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
|
||||||
|
|
||||||
if (!DiagOpts->DiagnosticSerializationFile.empty()) {
|
|
||||||
auto SerializedConsumer =
|
|
||||||
clang::serialized_diags::create(DiagOpts->DiagnosticSerializationFile,
|
|
||||||
&*DiagOpts, /*MergeChildRecords=*/true);
|
|
||||||
Diags.setClient(new ChainedDiagnosticConsumer(
|
|
||||||
Diags.takeClient(), std::move(SerializedConsumer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
|
|
||||||
|
|
||||||
Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
|
|
||||||
SetInstallDir(argv, TheDriver, CanonicalPrefixes);
|
|
||||||
|
|
||||||
insertTargetAndModeArgs(TargetAndMode.first, TargetAndMode.second, argv,
|
|
||||||
SavedStrings);
|
|
||||||
|
|
||||||
SetBackdoorDriverOutputsFromEnvVars(TheDriver);
|
|
||||||
|
|
||||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(argv));
|
|
||||||
int Res = 1;
|
|
||||||
if (C && !C->containsError()) {
|
|
||||||
SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
|
|
||||||
Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
|
|
||||||
|
|
||||||
// Force a crash to test the diagnostics.
|
|
||||||
if (TheDriver.GenReproducer) {
|
|
||||||
Diags.Report(diag::err_drv_force_crash)
|
|
||||||
<< !::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH");
|
|
||||||
|
|
||||||
// Pretend that every command failed.
|
|
||||||
FailingCommands.clear();
|
|
||||||
for (const auto &J : C->getJobs())
|
|
||||||
if (const Command *C = dyn_cast<Command>(&J))
|
|
||||||
FailingCommands.push_back(std::make_pair(-1, C));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &P : FailingCommands) {
|
|
||||||
int CommandRes = P.first;
|
|
||||||
const Command *FailingCommand = P.second;
|
|
||||||
if (!Res)
|
|
||||||
Res = CommandRes;
|
|
||||||
|
|
||||||
// If result status is < 0, then the driver command signalled an error.
|
|
||||||
// If result status is 70, then the driver command reported a fatal error.
|
|
||||||
// On Windows, abort will return an exit code of 3. In these cases,
|
|
||||||
// generate additional diagnostic information if possible.
|
|
||||||
bool DiagnoseCrash = CommandRes < 0 || CommandRes == 70;
|
|
||||||
#ifdef LLVM_ON_WIN32
|
|
||||||
DiagnoseCrash |= CommandRes == 3;
|
|
||||||
#endif
|
|
||||||
if (DiagnoseCrash) {
|
|
||||||
TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Diags.getClient()->finish();
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now. This happens in -disable-free mode.
|
|
||||||
llvm::TimerGroup::printAll(llvm::errs());
|
|
||||||
|
|
||||||
#ifdef LLVM_ON_WIN32
|
|
||||||
// Exit status should not be negative on Win32, unless abnormal termination.
|
|
||||||
// Once abnormal termiation was caught, negative status should not be
|
|
||||||
// propagated.
|
|
||||||
if (Res < 0)
|
|
||||||
Res = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// If we have multiple failing commands, we return the result of the first
|
|
||||||
// failing command.
|
|
||||||
return Res;
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
#include "lld/Driver/Driver.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
|
||||||
#include "llvm/ADT/Twine.h"
|
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/PrettyStackTrace.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
|
|
||||||
using namespace lld;
|
|
||||||
using namespace llvm;
|
|
||||||
using namespace llvm::sys;
|
|
||||||
|
|
||||||
int mainEntryClickHouseLLD(int Argc, char **Argv)
|
|
||||||
{
|
|
||||||
// Standard set up, so program fails gracefully.
|
|
||||||
sys::PrintStackTraceOnErrorSignal(Argv[0]);
|
|
||||||
PrettyStackTraceProgram StackPrinter(Argc, Argv);
|
|
||||||
llvm_shutdown_obj Shutdown;
|
|
||||||
|
|
||||||
std::vector<const char *> Args(Argv, Argv + Argc);
|
|
||||||
return !elf::link(Args, true);
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
Compiler-5.0.0
|
|
@ -1 +0,0 @@
|
|||||||
Compiler-5.0.0
|
|
@ -1,54 +0,0 @@
|
|||||||
|
|
||||||
add_definitions(-Wno-error -Wno-unused-parameter -Wno-non-virtual-dtor -U_LIBCPP_DEBUG)
|
|
||||||
|
|
||||||
link_directories(${LLVM_LIBRARY_DIRS})
|
|
||||||
|
|
||||||
add_library(clickhouse-compiler-lib
|
|
||||||
driver.cpp
|
|
||||||
cc1_main.cpp
|
|
||||||
cc1as_main.cpp
|
|
||||||
lld.cpp)
|
|
||||||
|
|
||||||
target_compile_options(clickhouse-compiler-lib PRIVATE -fno-rtti -fno-exceptions -g0)
|
|
||||||
|
|
||||||
string(REPLACE "${INCLUDE_DEBUG_HELPERS}" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # cant compile with -fno-rtti
|
|
||||||
|
|
||||||
llvm_libs_all(REQUIRED_LLVM_LIBRARIES)
|
|
||||||
|
|
||||||
message(STATUS "Using LLVM ${LLVM_VERSION}: ${LLVM_INCLUDE_DIRS} : ${REQUIRED_LLVM_LIBRARIES}")
|
|
||||||
|
|
||||||
target_include_directories(clickhouse-compiler-lib SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
# This is extracted almost directly from CMakeFiles/.../link.txt in LLVM build directory.
|
|
||||||
|
|
||||||
target_link_libraries(clickhouse-compiler-lib PRIVATE
|
|
||||||
|
|
||||||
clangBasic clangCodeGen clangDriver
|
|
||||||
clangFrontend
|
|
||||||
clangFrontendTool
|
|
||||||
clangRewriteFrontend clangARCMigrate clangStaticAnalyzerFrontend
|
|
||||||
clangParse clangSerialization clangSema clangEdit clangStaticAnalyzerCheckers
|
|
||||||
clangASTMatchers clangStaticAnalyzerCore clangAnalysis clangAST clangRewrite clangLex clangBasic
|
|
||||||
|
|
||||||
lldCOFF
|
|
||||||
lldDriver
|
|
||||||
lldELF
|
|
||||||
lldMinGW
|
|
||||||
lldMachO
|
|
||||||
lldReaderWriter
|
|
||||||
lldYAML
|
|
||||||
lldCommon
|
|
||||||
lldCore
|
|
||||||
#lldWasm
|
|
||||||
|
|
||||||
${REQUIRED_LLVM_LIBRARIES}
|
|
||||||
|
|
||||||
#Polly
|
|
||||||
#PollyISL
|
|
||||||
#PollyPPCG
|
|
||||||
|
|
||||||
PUBLIC ${ZLIB_LIBRARIES} ${EXECINFO_LIBRARIES} Threads::Threads
|
|
||||||
${MALLOC_LIBRARIES}
|
|
||||||
${GLIBC_COMPATIBILITY_LIBRARIES}
|
|
||||||
${MEMCPY_LIBRARIES}
|
|
||||||
)
|
|
@ -1,63 +0,0 @@
|
|||||||
==============================================================================
|
|
||||||
LLVM Release License
|
|
||||||
==============================================================================
|
|
||||||
University of Illinois/NCSA
|
|
||||||
Open Source License
|
|
||||||
|
|
||||||
Copyright (c) 2007-2016 University of Illinois at Urbana-Champaign.
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Developed by:
|
|
||||||
|
|
||||||
LLVM Team
|
|
||||||
|
|
||||||
University of Illinois at Urbana-Champaign
|
|
||||||
|
|
||||||
http://llvm.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal with
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
||||||
of the Software, and to permit persons to whom the Software is furnished to do
|
|
||||||
so, subject to the following conditions:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimers.
|
|
||||||
|
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimers in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
* Neither the names of the LLVM Team, University of Illinois at
|
|
||||||
Urbana-Champaign, nor the names of its contributors may be used to
|
|
||||||
endorse or promote products derived from this Software without specific
|
|
||||||
prior written permission.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
==============================================================================
|
|
||||||
The LLVM software contains code written by third parties. Such software will
|
|
||||||
have its own individual LICENSE.TXT file in the directory in which it appears.
|
|
||||||
This file will describe the copyrights, license, and restrictions which apply
|
|
||||||
to that code.
|
|
||||||
|
|
||||||
The disclaimer of warranty in the University of Illinois Open Source License
|
|
||||||
applies to all code in the LLVM Distribution, and nothing in any of the
|
|
||||||
other licenses gives permission to use the names of the LLVM Team or the
|
|
||||||
University of Illinois to endorse or promote products derived from this
|
|
||||||
Software.
|
|
||||||
|
|
||||||
The following pieces of software have additional or alternate copyrights,
|
|
||||||
licenses, and/or restrictions:
|
|
||||||
|
|
||||||
Program Directory
|
|
||||||
------- ---------
|
|
||||||
<none yet>
|
|
||||||
|
|
@ -1,242 +0,0 @@
|
|||||||
//===-- cc1_main.cpp - Clang CC1 Compiler Frontend ------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang -cc1 functionality, which implements the
|
|
||||||
// core compiler functionality along with a number of additional tools for
|
|
||||||
// demonstration and testing purposes.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "llvm/Option/Arg.h"
|
|
||||||
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
|
|
||||||
#include "clang/Config/config.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Frontend/CompilerInstance.h"
|
|
||||||
#include "clang/Frontend/CompilerInvocation.h"
|
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "clang/FrontendTool/Utils.h"
|
|
||||||
#include "llvm/ADT/Statistic.h"
|
|
||||||
#include "llvm/LinkAllPasses.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Support/Compiler.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#ifdef CLANG_HAVE_RLIMITS
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// have no .a version in packages
|
|
||||||
#undef LINK_POLLY_INTO_TOOLS
|
|
||||||
|
|
||||||
using namespace clang;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// Main driver
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
static void LLVMErrorHandler(void *UserData, const std::string &Message,
|
|
||||||
bool GenCrashDiag) {
|
|
||||||
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
|
|
||||||
|
|
||||||
Diags.Report(diag::err_fe_error_backend) << Message;
|
|
||||||
|
|
||||||
// Run the interrupt handlers to make sure any special cleanups get done, in
|
|
||||||
// particular that we remove files registered with RemoveFileOnSignal.
|
|
||||||
llvm::sys::RunInterruptHandlers();
|
|
||||||
|
|
||||||
// We cannot recover from llvm errors. When reporting a fatal error, exit
|
|
||||||
// with status 70 to generate crash diagnostics. For BSD systems this is
|
|
||||||
// defined as an internal software error. Otherwise, exit with status 1.
|
|
||||||
exit(GenCrashDiag ? 70 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LINK_POLLY_INTO_TOOLS
|
|
||||||
namespace polly {
|
|
||||||
void initializePollyPasses(llvm::PassRegistry &Registry);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CLANG_HAVE_RLIMITS
|
|
||||||
// The amount of stack we think is "sufficient". If less than this much is
|
|
||||||
// available, we may be unable to reach our template instantiation depth
|
|
||||||
// limit and other similar limits.
|
|
||||||
// FIXME: Unify this with the stack we request when spawning a thread to build
|
|
||||||
// a module.
|
|
||||||
static const int kSufficientStack = 8 << 20;
|
|
||||||
|
|
||||||
#if defined(__linux__) && defined(__PIE__)
|
|
||||||
static size_t getCurrentStackAllocation() {
|
|
||||||
// If we can't compute the current stack usage, allow for 512K of command
|
|
||||||
// line arguments and environment.
|
|
||||||
size_t Usage = 512 * 1024;
|
|
||||||
if (FILE *StatFile = fopen("/proc/self/stat", "r")) {
|
|
||||||
// We assume that the stack extends from its current address to the end of
|
|
||||||
// the environment space. In reality, there is another string literal (the
|
|
||||||
// program name) after the environment, but this is close enough (we only
|
|
||||||
// need to be within 100K or so).
|
|
||||||
unsigned long StackPtr, EnvEnd;
|
|
||||||
// Disable silly GCC -Wformat warning that complains about length
|
|
||||||
// modifiers on ignored format specifiers. We want to retain these
|
|
||||||
// for documentation purposes even though they have no effect.
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wformat"
|
|
||||||
#endif
|
|
||||||
if (fscanf(StatFile,
|
|
||||||
"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %*lu "
|
|
||||||
"%*lu %*ld %*ld %*ld %*ld %*ld %*ld %*llu %*lu %*ld %*lu %*lu "
|
|
||||||
"%*lu %*lu %lu %*lu %*lu %*lu %*lu %*lu %*llu %*lu %*lu %*d %*d "
|
|
||||||
"%*u %*u %*llu %*lu %*ld %*lu %*lu %*lu %*lu %*lu %*lu %lu %*d",
|
|
||||||
&StackPtr, &EnvEnd) == 2) {
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
Usage = StackPtr < EnvEnd ? EnvEnd - StackPtr : StackPtr - EnvEnd;
|
|
||||||
}
|
|
||||||
fclose(StatFile);
|
|
||||||
}
|
|
||||||
return Usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <alloca.h>
|
|
||||||
|
|
||||||
LLVM_ATTRIBUTE_NOINLINE
|
|
||||||
static void ensureStackAddressSpace(int ExtraChunks = 0) {
|
|
||||||
// Linux kernels prior to 4.1 will sometimes locate the heap of a PIE binary
|
|
||||||
// relatively close to the stack (they are only guaranteed to be 128MiB
|
|
||||||
// apart). This results in crashes if we happen to heap-allocate more than
|
|
||||||
// 128MiB before we reach our stack high-water mark.
|
|
||||||
//
|
|
||||||
// To avoid these crashes, ensure that we have sufficient virtual memory
|
|
||||||
// pages allocated before we start running.
|
|
||||||
size_t Curr = getCurrentStackAllocation();
|
|
||||||
const int kTargetStack = kSufficientStack - 256 * 1024;
|
|
||||||
if (Curr < kTargetStack) {
|
|
||||||
volatile char *volatile Alloc =
|
|
||||||
static_cast<volatile char *>(alloca(kTargetStack - Curr));
|
|
||||||
Alloc[0] = 0;
|
|
||||||
Alloc[kTargetStack - Curr - 1] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static void ensureStackAddressSpace() {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Attempt to ensure that we have at least 8MiB of usable stack space.
|
|
||||||
static void ensureSufficientStack() {
|
|
||||||
struct rlimit rlim;
|
|
||||||
if (getrlimit(RLIMIT_STACK, &rlim) != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Increase the soft stack limit to our desired level, if necessary and
|
|
||||||
// possible.
|
|
||||||
if (rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur < kSufficientStack) {
|
|
||||||
// Try to allocate sufficient stack.
|
|
||||||
if (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_max >= kSufficientStack)
|
|
||||||
rlim.rlim_cur = kSufficientStack;
|
|
||||||
else if (rlim.rlim_cur == rlim.rlim_max)
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
rlim.rlim_cur = rlim.rlim_max;
|
|
||||||
|
|
||||||
if (setrlimit(RLIMIT_STACK, &rlim) != 0 ||
|
|
||||||
rlim.rlim_cur != kSufficientStack)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should now have a stack of size at least kSufficientStack. Ensure
|
|
||||||
// that we can actually use that much, if necessary.
|
|
||||||
ensureStackAddressSpace();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static void ensureSufficientStack() {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|
||||||
ensureSufficientStack();
|
|
||||||
|
|
||||||
std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
|
|
||||||
// Register the support for object-file-wrapped Clang modules.
|
|
||||||
auto PCHOps = Clang->getPCHContainerOperations();
|
|
||||||
PCHOps->registerWriter(llvm::make_unique<ObjectFilePCHContainerWriter>());
|
|
||||||
PCHOps->registerReader(llvm::make_unique<ObjectFilePCHContainerReader>());
|
|
||||||
|
|
||||||
// Initialize targets first, so that --version shows registered targets.
|
|
||||||
llvm::InitializeAllTargets();
|
|
||||||
llvm::InitializeAllTargetMCs();
|
|
||||||
llvm::InitializeAllAsmPrinters();
|
|
||||||
llvm::InitializeAllAsmParsers();
|
|
||||||
|
|
||||||
#ifdef LINK_POLLY_INTO_TOOLS
|
|
||||||
llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
|
|
||||||
polly::initializePollyPasses(Registry);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Buffer diagnostics from argument parsing so that we can output them using a
|
|
||||||
// well formed diagnostic object.
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
|
||||||
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
|
|
||||||
bool Success = CompilerInvocation::CreateFromArgs(
|
|
||||||
Clang->getInvocation(), Argv.begin(), Argv.end(), Diags);
|
|
||||||
|
|
||||||
// Infer the builtin include path if unspecified.
|
|
||||||
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
|
|
||||||
Clang->getHeaderSearchOpts().ResourceDir.empty())
|
|
||||||
Clang->getHeaderSearchOpts().ResourceDir =
|
|
||||||
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
|
|
||||||
|
|
||||||
// Create the actual diagnostics engine.
|
|
||||||
Clang->createDiagnostics();
|
|
||||||
if (!Clang->hasDiagnostics())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
|
||||||
// error handler.
|
|
||||||
llvm::install_fatal_error_handler(LLVMErrorHandler,
|
|
||||||
static_cast<void*>(&Clang->getDiagnostics()));
|
|
||||||
|
|
||||||
DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
|
|
||||||
if (!Success)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Execute the frontend actions.
|
|
||||||
Success = ExecuteCompilerInvocation(Clang.get());
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now. This happens in -disable-free mode.
|
|
||||||
llvm::TimerGroup::printAll(llvm::errs());
|
|
||||||
|
|
||||||
// Our error handler depends on the Diagnostics object, which we're
|
|
||||||
// potentially about to delete. Uninstall the handler now so that any
|
|
||||||
// later errors use the default handling behavior instead.
|
|
||||||
llvm::remove_fatal_error_handler();
|
|
||||||
|
|
||||||
// When running with -disable-free, don't do any destruction or shutdown.
|
|
||||||
if (Clang->getFrontendOpts().DisableFree) {
|
|
||||||
BuryPointer(std::move(Clang));
|
|
||||||
return !Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !Success;
|
|
||||||
}
|
|
@ -1,540 +0,0 @@
|
|||||||
//===-- cc1as_main.cpp - Clang Assembler ---------------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang -cc1as functionality, which implements
|
|
||||||
// the direct interface to the LLVM MC based assembler.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "clang/Basic/Diagnostic.h"
|
|
||||||
#include "clang/Basic/DiagnosticOptions.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
|
||||||
#include "llvm/ADT/Triple.h"
|
|
||||||
#include "llvm/IR/DataLayout.h"
|
|
||||||
#include "llvm/MC/MCAsmBackend.h"
|
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
|
||||||
#include "llvm/MC/MCCodeEmitter.h"
|
|
||||||
#include "llvm/MC/MCContext.h"
|
|
||||||
#include "llvm/MC/MCInstrInfo.h"
|
|
||||||
#include "llvm/MC/MCObjectFileInfo.h"
|
|
||||||
#include "llvm/MC/MCParser/MCAsmParser.h"
|
|
||||||
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
|
|
||||||
#include "llvm/MC/MCRegisterInfo.h"
|
|
||||||
#include "llvm/MC/MCStreamer.h"
|
|
||||||
#include "llvm/MC/MCSubtargetInfo.h"
|
|
||||||
#include "llvm/MC/MCTargetOptions.h"
|
|
||||||
#include "llvm/Option/Arg.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
|
||||||
#include "llvm/Support/FormattedStream.h"
|
|
||||||
#include "llvm/Support/Host.h"
|
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/SourceMgr.h"
|
|
||||||
#include "llvm/Support/TargetRegistry.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <system_error>
|
|
||||||
using namespace clang;
|
|
||||||
using namespace clang::driver;
|
|
||||||
using namespace clang::driver::options;
|
|
||||||
using namespace llvm;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
/// \brief Helper class for representing a single invocation of the assembler.
|
|
||||||
struct AssemblerInvocation {
|
|
||||||
/// @name Target Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// The name of the target triple to assemble for.
|
|
||||||
std::string Triple;
|
|
||||||
|
|
||||||
/// If given, the name of the target CPU to determine which instructions
|
|
||||||
/// are legal.
|
|
||||||
std::string CPU;
|
|
||||||
|
|
||||||
/// The list of target specific features to enable or disable -- this should
|
|
||||||
/// be a list of strings starting with '+' or '-'.
|
|
||||||
std::vector<std::string> Features;
|
|
||||||
|
|
||||||
/// The list of symbol definitions.
|
|
||||||
std::vector<std::string> SymbolDefs;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Language Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
std::vector<std::string> IncludePaths;
|
|
||||||
unsigned NoInitialTextSection : 1;
|
|
||||||
unsigned SaveTemporaryLabels : 1;
|
|
||||||
unsigned GenDwarfForAssembly : 1;
|
|
||||||
unsigned RelaxELFRelocations : 1;
|
|
||||||
unsigned DwarfVersion;
|
|
||||||
std::string DwarfDebugFlags;
|
|
||||||
std::string DwarfDebugProducer;
|
|
||||||
std::string DebugCompilationDir;
|
|
||||||
llvm::DebugCompressionType CompressDebugSections =
|
|
||||||
llvm::DebugCompressionType::None;
|
|
||||||
std::string MainFileName;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Frontend Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
std::string InputFile;
|
|
||||||
std::vector<std::string> LLVMArgs;
|
|
||||||
std::string OutputPath;
|
|
||||||
enum FileType {
|
|
||||||
FT_Asm, ///< Assembly (.s) output, transliterate mode.
|
|
||||||
FT_Null, ///< No output, for timing purposes.
|
|
||||||
FT_Obj ///< Object file output.
|
|
||||||
};
|
|
||||||
FileType OutputType;
|
|
||||||
unsigned ShowHelp : 1;
|
|
||||||
unsigned ShowVersion : 1;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Transliterate Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
unsigned OutputAsmVariant;
|
|
||||||
unsigned ShowEncoding : 1;
|
|
||||||
unsigned ShowInst : 1;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Assembler Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
unsigned RelaxAll : 1;
|
|
||||||
unsigned NoExecStack : 1;
|
|
||||||
unsigned FatalWarnings : 1;
|
|
||||||
unsigned IncrementalLinkerCompatible : 1;
|
|
||||||
|
|
||||||
/// The name of the relocation model to use.
|
|
||||||
std::string RelocationModel;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
public:
|
|
||||||
AssemblerInvocation() {
|
|
||||||
Triple = "";
|
|
||||||
NoInitialTextSection = 0;
|
|
||||||
InputFile = "-";
|
|
||||||
OutputPath = "-";
|
|
||||||
OutputType = FT_Asm;
|
|
||||||
OutputAsmVariant = 0;
|
|
||||||
ShowInst = 0;
|
|
||||||
ShowEncoding = 0;
|
|
||||||
RelaxAll = 0;
|
|
||||||
NoExecStack = 0;
|
|
||||||
FatalWarnings = 0;
|
|
||||||
IncrementalLinkerCompatible = 0;
|
|
||||||
DwarfVersion = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool CreateFromArgs(AssemblerInvocation &Res,
|
|
||||||
ArrayRef<const char *> Argv,
|
|
||||||
DiagnosticsEngine &Diags);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
|
|
||||||
ArrayRef<const char *> Argv,
|
|
||||||
DiagnosticsEngine &Diags) {
|
|
||||||
bool Success = true;
|
|
||||||
|
|
||||||
// Parse the arguments.
|
|
||||||
std::unique_ptr<OptTable> OptTbl(createDriverOptTable());
|
|
||||||
|
|
||||||
const unsigned IncludedFlagsBitmask = options::CC1AsOption;
|
|
||||||
unsigned MissingArgIndex, MissingArgCount;
|
|
||||||
InputArgList Args = OptTbl->ParseArgs(Argv, MissingArgIndex, MissingArgCount,
|
|
||||||
IncludedFlagsBitmask);
|
|
||||||
|
|
||||||
// Check for missing argument error.
|
|
||||||
if (MissingArgCount) {
|
|
||||||
Diags.Report(diag::err_drv_missing_argument)
|
|
||||||
<< Args.getArgString(MissingArgIndex) << MissingArgCount;
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Issue errors on unknown arguments.
|
|
||||||
for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct the invocation.
|
|
||||||
|
|
||||||
// Target Options
|
|
||||||
Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
|
|
||||||
Opts.CPU = Args.getLastArgValue(OPT_target_cpu);
|
|
||||||
Opts.Features = Args.getAllArgValues(OPT_target_feature);
|
|
||||||
|
|
||||||
// Use the default target triple if unspecified.
|
|
||||||
if (Opts.Triple.empty())
|
|
||||||
Opts.Triple = llvm::sys::getDefaultTargetTriple();
|
|
||||||
|
|
||||||
// Language Options
|
|
||||||
Opts.IncludePaths = Args.getAllArgValues(OPT_I);
|
|
||||||
Opts.NoInitialTextSection = Args.hasArg(OPT_n);
|
|
||||||
Opts.SaveTemporaryLabels = Args.hasArg(OPT_msave_temp_labels);
|
|
||||||
// Any DebugInfoKind implies GenDwarfForAssembly.
|
|
||||||
Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ);
|
|
||||||
|
|
||||||
if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections,
|
|
||||||
OPT_compress_debug_sections_EQ)) {
|
|
||||||
if (A->getOption().getID() == OPT_compress_debug_sections) {
|
|
||||||
// TODO: be more clever about the compression type auto-detection
|
|
||||||
Opts.CompressDebugSections = llvm::DebugCompressionType::GNU;
|
|
||||||
} else {
|
|
||||||
Opts.CompressDebugSections =
|
|
||||||
llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue())
|
|
||||||
.Case("none", llvm::DebugCompressionType::None)
|
|
||||||
.Case("zlib", llvm::DebugCompressionType::Z)
|
|
||||||
.Case("zlib-gnu", llvm::DebugCompressionType::GNU)
|
|
||||||
.Default(llvm::DebugCompressionType::None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
|
|
||||||
Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
|
|
||||||
Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
|
|
||||||
Opts.DwarfDebugProducer = Args.getLastArgValue(OPT_dwarf_debug_producer);
|
|
||||||
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
|
|
||||||
Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
|
|
||||||
|
|
||||||
// Frontend Options
|
|
||||||
if (Args.hasArg(OPT_INPUT)) {
|
|
||||||
bool First = true;
|
|
||||||
for (const Arg *A : Args.filtered(OPT_INPUT)) {
|
|
||||||
if (First) {
|
|
||||||
Opts.InputFile = A->getValue();
|
|
||||||
First = false;
|
|
||||||
} else {
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
|
|
||||||
Opts.OutputPath = Args.getLastArgValue(OPT_o);
|
|
||||||
if (Arg *A = Args.getLastArg(OPT_filetype)) {
|
|
||||||
StringRef Name = A->getValue();
|
|
||||||
unsigned OutputType = StringSwitch<unsigned>(Name)
|
|
||||||
.Case("asm", FT_Asm)
|
|
||||||
.Case("null", FT_Null)
|
|
||||||
.Case("obj", FT_Obj)
|
|
||||||
.Default(~0U);
|
|
||||||
if (OutputType == ~0U) {
|
|
||||||
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
|
|
||||||
Success = false;
|
|
||||||
} else
|
|
||||||
Opts.OutputType = FileType(OutputType);
|
|
||||||
}
|
|
||||||
Opts.ShowHelp = Args.hasArg(OPT_help);
|
|
||||||
Opts.ShowVersion = Args.hasArg(OPT_version);
|
|
||||||
|
|
||||||
// Transliterate Options
|
|
||||||
Opts.OutputAsmVariant =
|
|
||||||
getLastArgIntValue(Args, OPT_output_asm_variant, 0, Diags);
|
|
||||||
Opts.ShowEncoding = Args.hasArg(OPT_show_encoding);
|
|
||||||
Opts.ShowInst = Args.hasArg(OPT_show_inst);
|
|
||||||
|
|
||||||
// Assemble Options
|
|
||||||
Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
|
|
||||||
Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
|
|
||||||
Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
|
|
||||||
Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
|
|
||||||
Opts.IncrementalLinkerCompatible =
|
|
||||||
Args.hasArg(OPT_mincremental_linker_compatible);
|
|
||||||
Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::unique_ptr<raw_fd_ostream>
|
|
||||||
getOutputStream(AssemblerInvocation &Opts, DiagnosticsEngine &Diags,
|
|
||||||
bool Binary) {
|
|
||||||
if (Opts.OutputPath.empty())
|
|
||||||
Opts.OutputPath = "-";
|
|
||||||
|
|
||||||
// Make sure that the Out file gets unlinked from the disk if we get a
|
|
||||||
// SIGINT.
|
|
||||||
if (Opts.OutputPath != "-")
|
|
||||||
sys::RemoveFileOnSignal(Opts.OutputPath);
|
|
||||||
|
|
||||||
std::error_code EC;
|
|
||||||
auto Out = llvm::make_unique<raw_fd_ostream>(
|
|
||||||
Opts.OutputPath, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text));
|
|
||||||
if (EC) {
|
|
||||||
Diags.Report(diag::err_fe_unable_to_open_output) << Opts.OutputPath
|
|
||||||
<< EC.message();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Out;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ExecuteAssembler(AssemblerInvocation &Opts,
|
|
||||||
DiagnosticsEngine &Diags) {
|
|
||||||
// Get the target specific parser.
|
|
||||||
std::string Error;
|
|
||||||
const Target *TheTarget = TargetRegistry::lookupTarget(Opts.Triple, Error);
|
|
||||||
if (!TheTarget)
|
|
||||||
return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
|
|
||||||
|
|
||||||
ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
|
|
||||||
MemoryBuffer::getFileOrSTDIN(Opts.InputFile);
|
|
||||||
|
|
||||||
if (std::error_code EC = Buffer.getError()) {
|
|
||||||
Error = EC.message();
|
|
||||||
return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
SourceMgr SrcMgr;
|
|
||||||
|
|
||||||
// Tell SrcMgr about this buffer, which is what the parser will pick up.
|
|
||||||
SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc());
|
|
||||||
|
|
||||||
// Record the location of the include directories so that the lexer can find
|
|
||||||
// it later.
|
|
||||||
SrcMgr.setIncludeDirs(Opts.IncludePaths);
|
|
||||||
|
|
||||||
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(Opts.Triple));
|
|
||||||
assert(MRI && "Unable to create target register info!");
|
|
||||||
|
|
||||||
std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, Opts.Triple));
|
|
||||||
assert(MAI && "Unable to create target asm info!");
|
|
||||||
|
|
||||||
// Ensure MCAsmInfo initialization occurs before any use, otherwise sections
|
|
||||||
// may be created with a combination of default and explicit settings.
|
|
||||||
MAI->setCompressDebugSections(Opts.CompressDebugSections);
|
|
||||||
|
|
||||||
MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations);
|
|
||||||
|
|
||||||
bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj;
|
|
||||||
std::unique_ptr<raw_fd_ostream> FDOS = getOutputStream(Opts, Diags, IsBinary);
|
|
||||||
if (!FDOS)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
|
|
||||||
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
|
|
||||||
std::unique_ptr<MCObjectFileInfo> MOFI(new MCObjectFileInfo());
|
|
||||||
|
|
||||||
MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr);
|
|
||||||
|
|
||||||
bool PIC = false;
|
|
||||||
if (Opts.RelocationModel == "static") {
|
|
||||||
PIC = false;
|
|
||||||
} else if (Opts.RelocationModel == "pic") {
|
|
||||||
PIC = true;
|
|
||||||
} else {
|
|
||||||
assert(Opts.RelocationModel == "dynamic-no-pic" &&
|
|
||||||
"Invalid PIC model!");
|
|
||||||
PIC = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), PIC, Ctx);
|
|
||||||
if (Opts.SaveTemporaryLabels)
|
|
||||||
Ctx.setAllowTemporaryLabels(false);
|
|
||||||
if (Opts.GenDwarfForAssembly)
|
|
||||||
Ctx.setGenDwarfForAssembly(true);
|
|
||||||
if (!Opts.DwarfDebugFlags.empty())
|
|
||||||
Ctx.setDwarfDebugFlags(StringRef(Opts.DwarfDebugFlags));
|
|
||||||
if (!Opts.DwarfDebugProducer.empty())
|
|
||||||
Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
|
|
||||||
if (!Opts.DebugCompilationDir.empty())
|
|
||||||
Ctx.setCompilationDir(Opts.DebugCompilationDir);
|
|
||||||
if (!Opts.MainFileName.empty())
|
|
||||||
Ctx.setMainFileName(StringRef(Opts.MainFileName));
|
|
||||||
Ctx.setDwarfVersion(Opts.DwarfVersion);
|
|
||||||
|
|
||||||
// Build up the feature string from the target feature list.
|
|
||||||
std::string FS;
|
|
||||||
if (!Opts.Features.empty()) {
|
|
||||||
FS = Opts.Features[0];
|
|
||||||
for (unsigned i = 1, e = Opts.Features.size(); i != e; ++i)
|
|
||||||
FS += "," + Opts.Features[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<MCStreamer> Str;
|
|
||||||
|
|
||||||
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
|
|
||||||
std::unique_ptr<MCSubtargetInfo> STI(
|
|
||||||
TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS));
|
|
||||||
|
|
||||||
raw_pwrite_stream *Out = FDOS.get();
|
|
||||||
std::unique_ptr<buffer_ostream> BOS;
|
|
||||||
|
|
||||||
// FIXME: There is a bit of code duplication with addPassesToEmitFile.
|
|
||||||
if (Opts.OutputType == AssemblerInvocation::FT_Asm) {
|
|
||||||
MCInstPrinter *IP = TheTarget->createMCInstPrinter(
|
|
||||||
llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI);
|
|
||||||
MCCodeEmitter *CE = nullptr;
|
|
||||||
MCAsmBackend *MAB = nullptr;
|
|
||||||
if (Opts.ShowEncoding) {
|
|
||||||
CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx);
|
|
||||||
MCTargetOptions Options;
|
|
||||||
MAB = TheTarget->createMCAsmBackend(*STI, *MRI, Options);
|
|
||||||
}
|
|
||||||
auto FOut = llvm::make_unique<formatted_raw_ostream>(*Out);
|
|
||||||
Str.reset(TheTarget->createAsmStreamer(
|
|
||||||
Ctx, std::move(FOut), /*asmverbose*/ true,
|
|
||||||
/*useDwarfDirectory*/ true, IP, CE, MAB, Opts.ShowInst));
|
|
||||||
} else if (Opts.OutputType == AssemblerInvocation::FT_Null) {
|
|
||||||
Str.reset(createNullStreamer(Ctx));
|
|
||||||
} else {
|
|
||||||
assert(Opts.OutputType == AssemblerInvocation::FT_Obj &&
|
|
||||||
"Invalid file type!");
|
|
||||||
if (!FDOS->supportsSeeking()) {
|
|
||||||
BOS = make_unique<buffer_ostream>(*FDOS);
|
|
||||||
Out = BOS.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx);
|
|
||||||
MCTargetOptions Options;
|
|
||||||
MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*STI, *MRI, Options);
|
|
||||||
Triple T(Opts.Triple);
|
|
||||||
Str.reset(TheTarget->createMCObjectStreamer(
|
|
||||||
T, Ctx, std::unique_ptr<MCAsmBackend>(MAB), *Out, std::unique_ptr<MCCodeEmitter>(CE), *STI,
|
|
||||||
Opts.RelaxAll, Opts.IncrementalLinkerCompatible,
|
|
||||||
/*DWARFMustBeAtTheEnd*/ true));
|
|
||||||
Str.get()->InitSections(Opts.NoExecStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Failed = false;
|
|
||||||
|
|
||||||
std::unique_ptr<MCAsmParser> Parser(
|
|
||||||
createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI));
|
|
||||||
|
|
||||||
// FIXME: init MCTargetOptions from sanitizer flags here.
|
|
||||||
MCTargetOptions Options;
|
|
||||||
std::unique_ptr<MCTargetAsmParser> TAP(
|
|
||||||
TheTarget->createMCAsmParser(*STI, *Parser, *MCII, Options));
|
|
||||||
if (!TAP)
|
|
||||||
Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
|
|
||||||
|
|
||||||
// Set values for symbols, if any.
|
|
||||||
for (auto &S : Opts.SymbolDefs) {
|
|
||||||
auto Pair = StringRef(S).split('=');
|
|
||||||
auto Sym = Pair.first;
|
|
||||||
auto Val = Pair.second;
|
|
||||||
int64_t Value = 0;
|
|
||||||
// We have already error checked this in the driver.
|
|
||||||
Val.getAsInteger(0, Value);
|
|
||||||
Ctx.setSymbolValue(Parser->getStreamer(), Sym, Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Failed) {
|
|
||||||
Parser->setTargetParser(*TAP.get());
|
|
||||||
Failed = Parser->Run(Opts.NoInitialTextSection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close Streamer first.
|
|
||||||
// It might have a reference to the output stream.
|
|
||||||
Str.reset();
|
|
||||||
// Close the output stream early.
|
|
||||||
BOS.reset();
|
|
||||||
FDOS.reset();
|
|
||||||
|
|
||||||
// Delete output file if there were errors.
|
|
||||||
if (Failed && Opts.OutputPath != "-")
|
|
||||||
sys::fs::remove(Opts.OutputPath);
|
|
||||||
|
|
||||||
return Failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void LLVMErrorHandler(void *UserData, const std::string &Message,
|
|
||||||
bool GenCrashDiag) {
|
|
||||||
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
|
|
||||||
|
|
||||||
Diags.Report(diag::err_fe_error_backend) << Message;
|
|
||||||
|
|
||||||
// We cannot recover from llvm errors.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|
||||||
// Initialize targets and assembly printers/parsers.
|
|
||||||
InitializeAllTargetInfos();
|
|
||||||
InitializeAllTargetMCs();
|
|
||||||
InitializeAllAsmParsers();
|
|
||||||
|
|
||||||
// Construct our diagnostic client.
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
|
||||||
TextDiagnosticPrinter *DiagClient
|
|
||||||
= new TextDiagnosticPrinter(errs(), &*DiagOpts);
|
|
||||||
DiagClient->setPrefix("clang -cc1as");
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
|
||||||
|
|
||||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
|
||||||
// error handler.
|
|
||||||
ScopedFatalErrorHandler FatalErrorHandler
|
|
||||||
(LLVMErrorHandler, static_cast<void*>(&Diags));
|
|
||||||
|
|
||||||
// Parse the arguments.
|
|
||||||
AssemblerInvocation Asm;
|
|
||||||
if (!AssemblerInvocation::CreateFromArgs(Asm, Argv, Diags))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (Asm.ShowHelp) {
|
|
||||||
std::unique_ptr<OptTable> Opts(driver::createDriverOptTable());
|
|
||||||
Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
|
|
||||||
/*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
|
|
||||||
/*ShowAllAliases=*/false);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Honor -version.
|
|
||||||
//
|
|
||||||
// FIXME: Use a better -version message?
|
|
||||||
if (Asm.ShowVersion) {
|
|
||||||
llvm::cl::PrintVersionMessage();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Honor -mllvm.
|
|
||||||
//
|
|
||||||
// FIXME: Remove this, one day.
|
|
||||||
if (!Asm.LLVMArgs.empty()) {
|
|
||||||
unsigned NumArgs = Asm.LLVMArgs.size();
|
|
||||||
auto Args = llvm::make_unique<const char*[]>(NumArgs + 2);
|
|
||||||
Args[0] = "clang (LLVM option parsing)";
|
|
||||||
for (unsigned i = 0; i != NumArgs; ++i)
|
|
||||||
Args[i + 1] = Asm.LLVMArgs[i].c_str();
|
|
||||||
Args[NumArgs + 1] = nullptr;
|
|
||||||
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the invocation, unless there were parsing errors.
|
|
||||||
bool Failed = Diags.hasErrorOccurred() || ExecuteAssembler(Asm, Diags);
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now.
|
|
||||||
TimerGroup::printAll(errs());
|
|
||||||
|
|
||||||
return !!Failed;
|
|
||||||
}
|
|
@ -1,520 +0,0 @@
|
|||||||
//===-- driver.cpp - Clang GCC-Compatible Driver --------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang driver; it is a thin wrapper
|
|
||||||
// for functionality in the Driver clang library.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "clang/Basic/DiagnosticOptions.h"
|
|
||||||
#include "clang/Driver/Compilation.h"
|
|
||||||
#include "clang/Driver/Driver.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Driver/ToolChain.h"
|
|
||||||
#include "clang/Frontend/ChainedDiagnosticConsumer.h"
|
|
||||||
#include "clang/Frontend/CompilerInvocation.h"
|
|
||||||
#include "clang/Frontend/SerializedDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
|
||||||
#include "llvm/ADT/SmallString.h"
|
|
||||||
#include "llvm/ADT/SmallVector.h"
|
|
||||||
#include "llvm/Config/llvm-config.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Option/Option.h"
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
|
||||||
#include "llvm/Support/Host.h"
|
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/PrettyStackTrace.h"
|
|
||||||
#include "llvm/Support/Process.h"
|
|
||||||
#include "llvm/Support/Program.h"
|
|
||||||
#include "llvm/Support/Regex.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/StringSaver.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <set>
|
|
||||||
#include <system_error>
|
|
||||||
using namespace clang;
|
|
||||||
using namespace clang::driver;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
|
|
||||||
if (!CanonicalPrefixes) {
|
|
||||||
SmallString<128> ExecutablePath(Argv0);
|
|
||||||
// Do a PATH lookup if Argv0 isn't a valid path.
|
|
||||||
if (!llvm::sys::fs::exists(ExecutablePath))
|
|
||||||
if (llvm::ErrorOr<std::string> P =
|
|
||||||
llvm::sys::findProgramByName(ExecutablePath))
|
|
||||||
ExecutablePath = *P;
|
|
||||||
return ExecutablePath.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This just needs to be some symbol in the binary; C++ doesn't
|
|
||||||
// allow taking the address of ::main however.
|
|
||||||
void *P = (void*) (intptr_t) GetExecutablePath;
|
|
||||||
return llvm::sys::fs::getMainExecutable(Argv0, P);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *GetStableCStr(std::set<std::string> &SavedStrings,
|
|
||||||
StringRef S) {
|
|
||||||
return SavedStrings.insert(S).first->c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ApplyQAOverride - Apply a list of edits to the input argument lists.
|
|
||||||
///
|
|
||||||
/// The input string is a space separate list of edits to perform,
|
|
||||||
/// they are applied in order to the input argument lists. Edits
|
|
||||||
/// should be one of the following forms:
|
|
||||||
///
|
|
||||||
/// '#': Silence information about the changes to the command line arguments.
|
|
||||||
///
|
|
||||||
/// '^': Add FOO as a new argument at the beginning of the command line.
|
|
||||||
///
|
|
||||||
/// '+': Add FOO as a new argument at the end of the command line.
|
|
||||||
///
|
|
||||||
/// 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
|
|
||||||
/// line.
|
|
||||||
///
|
|
||||||
/// 'xOPTION': Removes all instances of the literal argument OPTION.
|
|
||||||
///
|
|
||||||
/// 'XOPTION': Removes all instances of the literal argument OPTION,
|
|
||||||
/// and the following argument.
|
|
||||||
///
|
|
||||||
/// 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
|
|
||||||
/// at the end of the command line.
|
|
||||||
///
|
|
||||||
/// \param OS - The stream to write edit information to.
|
|
||||||
/// \param Args - The vector of command line arguments.
|
|
||||||
/// \param Edit - The override command to perform.
|
|
||||||
/// \param SavedStrings - Set to use for storing string representations.
|
|
||||||
static void ApplyOneQAOverride(raw_ostream &OS,
|
|
||||||
SmallVectorImpl<const char*> &Args,
|
|
||||||
StringRef Edit,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
// This does not need to be efficient.
|
|
||||||
|
|
||||||
if (Edit[0] == '^') {
|
|
||||||
const char *Str =
|
|
||||||
GetStableCStr(SavedStrings, Edit.substr(1));
|
|
||||||
OS << "### Adding argument " << Str << " at beginning\n";
|
|
||||||
Args.insert(Args.begin() + 1, Str);
|
|
||||||
} else if (Edit[0] == '+') {
|
|
||||||
const char *Str =
|
|
||||||
GetStableCStr(SavedStrings, Edit.substr(1));
|
|
||||||
OS << "### Adding argument " << Str << " at end\n";
|
|
||||||
Args.push_back(Str);
|
|
||||||
} else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
|
|
||||||
Edit.slice(2, Edit.size()-1).find('/') != StringRef::npos) {
|
|
||||||
StringRef MatchPattern = Edit.substr(2).split('/').first;
|
|
||||||
StringRef ReplPattern = Edit.substr(2).split('/').second;
|
|
||||||
ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1);
|
|
||||||
|
|
||||||
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
|
|
||||||
// Ignore end-of-line response file markers
|
|
||||||
if (Args[i] == nullptr)
|
|
||||||
continue;
|
|
||||||
std::string Repl = llvm::Regex(MatchPattern).sub(ReplPattern, Args[i]);
|
|
||||||
|
|
||||||
if (Repl != Args[i]) {
|
|
||||||
OS << "### Replacing '" << Args[i] << "' with '" << Repl << "'\n";
|
|
||||||
Args[i] = GetStableCStr(SavedStrings, Repl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (Edit[0] == 'x' || Edit[0] == 'X') {
|
|
||||||
auto Option = Edit.substr(1);
|
|
||||||
for (unsigned i = 1; i < Args.size();) {
|
|
||||||
if (Option == Args[i]) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
if (Edit[0] == 'X') {
|
|
||||||
if (i < Args.size()) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
} else
|
|
||||||
OS << "### Invalid X edit, end of command line!\n";
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
} else if (Edit[0] == 'O') {
|
|
||||||
for (unsigned i = 1; i < Args.size();) {
|
|
||||||
const char *A = Args[i];
|
|
||||||
// Ignore end-of-line response file markers
|
|
||||||
if (A == nullptr)
|
|
||||||
continue;
|
|
||||||
if (A[0] == '-' && A[1] == 'O' &&
|
|
||||||
(A[2] == '\0' ||
|
|
||||||
(A[3] == '\0' && (A[2] == 's' || A[2] == 'z' ||
|
|
||||||
('0' <= A[2] && A[2] <= '9'))))) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
} else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
OS << "### Adding argument " << Edit << " at end\n";
|
|
||||||
Args.push_back(GetStableCStr(SavedStrings, '-' + Edit.str()));
|
|
||||||
} else {
|
|
||||||
OS << "### Unrecognized edit: " << Edit << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ApplyQAOverride - Apply a comma separate list of edits to the
|
|
||||||
/// input argument lists. See ApplyOneQAOverride.
|
|
||||||
static void ApplyQAOverride(SmallVectorImpl<const char*> &Args,
|
|
||||||
const char *OverrideStr,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
raw_ostream *OS = &llvm::errs();
|
|
||||||
|
|
||||||
if (OverrideStr[0] == '#') {
|
|
||||||
++OverrideStr;
|
|
||||||
OS = &llvm::nulls();
|
|
||||||
}
|
|
||||||
|
|
||||||
*OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
|
|
||||||
|
|
||||||
// This does not need to be efficient.
|
|
||||||
|
|
||||||
const char *S = OverrideStr;
|
|
||||||
while (*S) {
|
|
||||||
const char *End = ::strchr(S, ' ');
|
|
||||||
if (!End)
|
|
||||||
End = S + strlen(S);
|
|
||||||
if (End != S)
|
|
||||||
ApplyOneQAOverride(*OS, Args, std::string(S, End), SavedStrings);
|
|
||||||
S = End;
|
|
||||||
if (*S != '\0')
|
|
||||||
++S;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0,
|
|
||||||
void *MainAddr);
|
|
||||||
extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0,
|
|
||||||
void *MainAddr);
|
|
||||||
|
|
||||||
static void insertTargetAndModeArgs(const ParsedClangName &NameParts,
|
|
||||||
SmallVectorImpl<const char *> &ArgVector,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
// Put target and mode arguments at the start of argument list so that
|
|
||||||
// arguments specified in command line could override them. Avoid putting
|
|
||||||
// them at index 0, as an option like '-cc1' must remain the first.
|
|
||||||
auto InsertionPoint = ArgVector.begin();
|
|
||||||
if (InsertionPoint != ArgVector.end())
|
|
||||||
++InsertionPoint;
|
|
||||||
|
|
||||||
if (NameParts.DriverMode) {
|
|
||||||
// Add the mode flag to the arguments.
|
|
||||||
ArgVector.insert(InsertionPoint,
|
|
||||||
GetStableCStr(SavedStrings, NameParts.DriverMode));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NameParts.TargetIsValid) {
|
|
||||||
const char *arr[] = {"-target", GetStableCStr(SavedStrings,
|
|
||||||
NameParts.TargetPrefix)};
|
|
||||||
ArgVector.insert(InsertionPoint, std::begin(arr), std::end(arr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void getCLEnvVarOptions(std::string &EnvValue, llvm::StringSaver &Saver,
|
|
||||||
SmallVectorImpl<const char *> &Opts) {
|
|
||||||
llvm::cl::TokenizeWindowsCommandLine(EnvValue, Saver, Opts);
|
|
||||||
// The first instance of '#' should be replaced with '=' in each option.
|
|
||||||
for (const char *Opt : Opts)
|
|
||||||
if (char *NumberSignPtr = const_cast<char *>(::strchr(Opt, '#')))
|
|
||||||
*NumberSignPtr = '=';
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) {
|
|
||||||
// Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
|
|
||||||
TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
|
|
||||||
if (TheDriver.CCPrintOptions)
|
|
||||||
TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE");
|
|
||||||
|
|
||||||
// Handle CC_PRINT_HEADERS and CC_PRINT_HEADERS_FILE.
|
|
||||||
TheDriver.CCPrintHeaders = !!::getenv("CC_PRINT_HEADERS");
|
|
||||||
if (TheDriver.CCPrintHeaders)
|
|
||||||
TheDriver.CCPrintHeadersFilename = ::getenv("CC_PRINT_HEADERS_FILE");
|
|
||||||
|
|
||||||
// Handle CC_LOG_DIAGNOSTICS and CC_LOG_DIAGNOSTICS_FILE.
|
|
||||||
TheDriver.CCLogDiagnostics = !!::getenv("CC_LOG_DIAGNOSTICS");
|
|
||||||
if (TheDriver.CCLogDiagnostics)
|
|
||||||
TheDriver.CCLogDiagnosticsFilename = ::getenv("CC_LOG_DIAGNOSTICS_FILE");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
|
|
||||||
const std::string &Path) {
|
|
||||||
// If the clang binary happens to be named cl.exe for compatibility reasons,
|
|
||||||
// use clang-cl.exe as the prefix to avoid confusion between clang and MSVC.
|
|
||||||
StringRef ExeBasename(llvm::sys::path::filename(Path));
|
|
||||||
if (ExeBasename.equals_lower("cl.exe"))
|
|
||||||
ExeBasename = "clang-cl.exe";
|
|
||||||
DiagClient->setPrefix(ExeBasename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This lets us create the DiagnosticsEngine with a properly-filled-out
|
|
||||||
// DiagnosticOptions instance.
|
|
||||||
static DiagnosticOptions *
|
|
||||||
CreateAndPopulateDiagOpts(ArrayRef<const char *> argv) {
|
|
||||||
auto *DiagOpts = new DiagnosticOptions;
|
|
||||||
std::unique_ptr<OptTable> Opts(createDriverOptTable());
|
|
||||||
unsigned MissingArgIndex, MissingArgCount;
|
|
||||||
InputArgList Args =
|
|
||||||
Opts->ParseArgs(argv.slice(1), MissingArgIndex, MissingArgCount);
|
|
||||||
// We ignore MissingArgCount and the return value of ParseDiagnosticArgs.
|
|
||||||
// Any errors that would be diagnosed here will also be diagnosed later,
|
|
||||||
// when the DiagnosticsEngine actually exists.
|
|
||||||
(void)ParseDiagnosticArgs(*DiagOpts, Args);
|
|
||||||
return DiagOpts;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetInstallDir(SmallVectorImpl<const char *> &argv,
|
|
||||||
Driver &TheDriver, bool CanonicalPrefixes) {
|
|
||||||
// Attempt to find the original path used to invoke the driver, to determine
|
|
||||||
// the installed path. We do this manually, because we want to support that
|
|
||||||
// path being a symlink.
|
|
||||||
SmallString<128> InstalledPath(argv[0]);
|
|
||||||
|
|
||||||
// Do a PATH lookup, if there are no directory components.
|
|
||||||
if (llvm::sys::path::filename(InstalledPath) == InstalledPath)
|
|
||||||
if (llvm::ErrorOr<std::string> Tmp = llvm::sys::findProgramByName(
|
|
||||||
llvm::sys::path::filename(InstalledPath.str())))
|
|
||||||
InstalledPath = *Tmp;
|
|
||||||
|
|
||||||
// FIXME: We don't actually canonicalize this, we just make it absolute.
|
|
||||||
if (CanonicalPrefixes)
|
|
||||||
llvm::sys::fs::make_absolute(InstalledPath);
|
|
||||||
|
|
||||||
StringRef InstalledPathParent(llvm::sys::path::parent_path(InstalledPath));
|
|
||||||
if (llvm::sys::fs::exists(InstalledPathParent))
|
|
||||||
TheDriver.setInstalledDir(InstalledPathParent);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ExecuteCC1Tool(ArrayRef<const char *> argv, StringRef Tool) {
|
|
||||||
void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath;
|
|
||||||
if (Tool == "")
|
|
||||||
return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP);
|
|
||||||
if (Tool == "as")
|
|
||||||
return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
|
|
||||||
|
|
||||||
// Reject unknown tools.
|
|
||||||
llvm::errs() << "error: unknown integrated tool '" << Tool << "'\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mainEntryClickHouseClang(int argc_, char **argv_) {
|
|
||||||
llvm::sys::PrintStackTraceOnErrorSignal(argv_[0]);
|
|
||||||
llvm::PrettyStackTraceProgram X(argc_, argv_);
|
|
||||||
llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
|
||||||
|
|
||||||
if (llvm::sys::Process::FixupStandardFileDescriptors())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
SmallVector<const char *, 256> argv;
|
|
||||||
llvm::SpecificBumpPtrAllocator<char> ArgAllocator;
|
|
||||||
std::error_code EC = llvm::sys::Process::GetArgumentVector(
|
|
||||||
argv, llvm::makeArrayRef(argv_, argc_), ArgAllocator);
|
|
||||||
if (EC) {
|
|
||||||
llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n';
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm::InitializeAllTargets();
|
|
||||||
auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(argv[0]);
|
|
||||||
|
|
||||||
llvm::BumpPtrAllocator A;
|
|
||||||
llvm::StringSaver Saver(A);
|
|
||||||
|
|
||||||
// Parse response files using the GNU syntax, unless we're in CL mode. There
|
|
||||||
// are two ways to put clang in CL compatibility mode: argv[0] is either
|
|
||||||
// clang-cl or cl, or --driver-mode=cl is on the command line. The normal
|
|
||||||
// command line parsing can't happen until after response file parsing, so we
|
|
||||||
// have to manually search for a --driver-mode=cl argument the hard way.
|
|
||||||
// Finally, our -cc1 tools don't care which tokenization mode we use because
|
|
||||||
// response files written by clang will tokenize the same way in either mode.
|
|
||||||
bool ClangCLMode = false;
|
|
||||||
if (StringRef(TargetAndMode.DriverMode).equals("--driver-mode=cl") ||
|
|
||||||
std::find_if(argv.begin(), argv.end(), [](const char *F) {
|
|
||||||
return F && strcmp(F, "--driver-mode=cl") == 0;
|
|
||||||
}) != argv.end()) {
|
|
||||||
ClangCLMode = true;
|
|
||||||
}
|
|
||||||
enum { Default, POSIX, Windows } RSPQuoting = Default;
|
|
||||||
for (const char *F : argv) {
|
|
||||||
if (strcmp(F, "--rsp-quoting=posix") == 0)
|
|
||||||
RSPQuoting = POSIX;
|
|
||||||
else if (strcmp(F, "--rsp-quoting=windows") == 0)
|
|
||||||
RSPQuoting = Windows;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determines whether we want nullptr markers in argv to indicate response
|
|
||||||
// files end-of-lines. We only use this for the /LINK driver argument with
|
|
||||||
// clang-cl.exe on Windows.
|
|
||||||
bool MarkEOLs = ClangCLMode;
|
|
||||||
|
|
||||||
llvm::cl::TokenizerCallback Tokenizer;
|
|
||||||
if (RSPQuoting == Windows || (RSPQuoting == Default && ClangCLMode))
|
|
||||||
Tokenizer = &llvm::cl::TokenizeWindowsCommandLine;
|
|
||||||
else
|
|
||||||
Tokenizer = &llvm::cl::TokenizeGNUCommandLine;
|
|
||||||
|
|
||||||
if (MarkEOLs && argv.size() > 1 && StringRef(argv[1]).startswith("-cc1"))
|
|
||||||
MarkEOLs = false;
|
|
||||||
llvm::cl::ExpandResponseFiles(Saver, Tokenizer, argv, MarkEOLs);
|
|
||||||
|
|
||||||
// Handle -cc1 integrated tools, even if -cc1 was expanded from a response
|
|
||||||
// file.
|
|
||||||
auto FirstArg = std::find_if(argv.begin() + 1, argv.end(),
|
|
||||||
[](const char *A) { return A != nullptr; });
|
|
||||||
if (FirstArg != argv.end() && StringRef(*FirstArg).startswith("-cc1")) {
|
|
||||||
// If -cc1 came from a response file, remove the EOL sentinels.
|
|
||||||
if (MarkEOLs) {
|
|
||||||
auto newEnd = std::remove(argv.begin(), argv.end(), nullptr);
|
|
||||||
argv.resize(newEnd - argv.begin());
|
|
||||||
}
|
|
||||||
return ExecuteCC1Tool(argv, argv[1] + 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CanonicalPrefixes = true;
|
|
||||||
for (int i = 1, size = argv.size(); i < size; ++i) {
|
|
||||||
// Skip end-of-line response file markers
|
|
||||||
if (argv[i] == nullptr)
|
|
||||||
continue;
|
|
||||||
if (StringRef(argv[i]) == "-no-canonical-prefixes") {
|
|
||||||
CanonicalPrefixes = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle CL and _CL_ which permits additional command line options to be
|
|
||||||
// prepended or appended.
|
|
||||||
if (ClangCLMode) {
|
|
||||||
// Arguments in "CL" are prepended.
|
|
||||||
llvm::Optional<std::string> OptCL = llvm::sys::Process::GetEnv("CL");
|
|
||||||
if (OptCL.hasValue()) {
|
|
||||||
SmallVector<const char *, 8> PrependedOpts;
|
|
||||||
getCLEnvVarOptions(OptCL.getValue(), Saver, PrependedOpts);
|
|
||||||
|
|
||||||
// Insert right after the program name to prepend to the argument list.
|
|
||||||
argv.insert(argv.begin() + 1, PrependedOpts.begin(), PrependedOpts.end());
|
|
||||||
}
|
|
||||||
// Arguments in "_CL_" are appended.
|
|
||||||
llvm::Optional<std::string> Opt_CL_ = llvm::sys::Process::GetEnv("_CL_");
|
|
||||||
if (Opt_CL_.hasValue()) {
|
|
||||||
SmallVector<const char *, 8> AppendedOpts;
|
|
||||||
getCLEnvVarOptions(Opt_CL_.getValue(), Saver, AppendedOpts);
|
|
||||||
|
|
||||||
// Insert at the end of the argument list to append.
|
|
||||||
argv.append(AppendedOpts.begin(), AppendedOpts.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<std::string> SavedStrings;
|
|
||||||
// Handle CCC_OVERRIDE_OPTIONS, used for editing a command line behind the
|
|
||||||
// scenes.
|
|
||||||
if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
|
|
||||||
// FIXME: Driver shouldn't take extra initial argument.
|
|
||||||
ApplyQAOverride(argv, OverrideStr, SavedStrings);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Path = GetExecutablePath(argv[0], CanonicalPrefixes);
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
|
|
||||||
CreateAndPopulateDiagOpts(argv);
|
|
||||||
|
|
||||||
TextDiagnosticPrinter *DiagClient
|
|
||||||
= new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
|
|
||||||
FixupDiagPrefixExeName(DiagClient, Path);
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
|
||||||
|
|
||||||
if (!DiagOpts->DiagnosticSerializationFile.empty()) {
|
|
||||||
auto SerializedConsumer =
|
|
||||||
clang::serialized_diags::create(DiagOpts->DiagnosticSerializationFile,
|
|
||||||
&*DiagOpts, /*MergeChildRecords=*/true);
|
|
||||||
Diags.setClient(new ChainedDiagnosticConsumer(
|
|
||||||
Diags.takeClient(), std::move(SerializedConsumer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
|
|
||||||
|
|
||||||
Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
|
|
||||||
SetInstallDir(argv, TheDriver, CanonicalPrefixes);
|
|
||||||
TheDriver.setTargetAndMode(TargetAndMode);
|
|
||||||
|
|
||||||
insertTargetAndModeArgs(TargetAndMode, argv, SavedStrings);
|
|
||||||
|
|
||||||
SetBackdoorDriverOutputsFromEnvVars(TheDriver);
|
|
||||||
|
|
||||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(argv));
|
|
||||||
int Res = 1;
|
|
||||||
if (C && !C->containsError()) {
|
|
||||||
SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
|
|
||||||
Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
|
|
||||||
|
|
||||||
// Force a crash to test the diagnostics.
|
|
||||||
if (TheDriver.GenReproducer) {
|
|
||||||
Diags.Report(diag::err_drv_force_crash)
|
|
||||||
<< !::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH");
|
|
||||||
|
|
||||||
// Pretend that every command failed.
|
|
||||||
FailingCommands.clear();
|
|
||||||
for (const auto &J : C->getJobs())
|
|
||||||
if (const Command *C = dyn_cast<Command>(&J))
|
|
||||||
FailingCommands.push_back(std::make_pair(-1, C));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &P : FailingCommands) {
|
|
||||||
int CommandRes = P.first;
|
|
||||||
const Command *FailingCommand = P.second;
|
|
||||||
if (!Res)
|
|
||||||
Res = CommandRes;
|
|
||||||
|
|
||||||
// If result status is < 0, then the driver command signalled an error.
|
|
||||||
// If result status is 70, then the driver command reported a fatal error.
|
|
||||||
// On Windows, abort will return an exit code of 3. In these cases,
|
|
||||||
// generate additional diagnostic information if possible.
|
|
||||||
bool DiagnoseCrash = CommandRes < 0 || CommandRes == 70;
|
|
||||||
#ifdef LLVM_ON_WIN32
|
|
||||||
DiagnoseCrash |= CommandRes == 3;
|
|
||||||
#endif
|
|
||||||
if (DiagnoseCrash) {
|
|
||||||
TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Diags.getClient()->finish();
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now. This happens in -disable-free mode.
|
|
||||||
llvm::TimerGroup::printAll(llvm::errs());
|
|
||||||
|
|
||||||
#ifdef LLVM_ON_WIN32
|
|
||||||
// Exit status should not be negative on Win32, unless abnormal termination.
|
|
||||||
// Once abnormal termiation was caught, negative status should not be
|
|
||||||
// propagated.
|
|
||||||
if (Res < 0)
|
|
||||||
Res = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// If we have multiple failing commands, we return the result of the first
|
|
||||||
// failing command.
|
|
||||||
return Res;
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
#include "lld/Common/Driver.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
|
||||||
#include "llvm/ADT/Twine.h"
|
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/PrettyStackTrace.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
|
|
||||||
using namespace lld;
|
|
||||||
using namespace llvm;
|
|
||||||
using namespace llvm::sys;
|
|
||||||
|
|
||||||
int mainEntryClickHouseLLD(int Argc, char **Argv)
|
|
||||||
{
|
|
||||||
// Standard set up, so program fails gracefully.
|
|
||||||
sys::PrintStackTraceOnErrorSignal(Argv[0]);
|
|
||||||
PrettyStackTraceProgram StackPrinter(Argc, Argv);
|
|
||||||
llvm_shutdown_obj Shutdown;
|
|
||||||
|
|
||||||
std::vector<const char *> Args(Argv, Argv + Argc);
|
|
||||||
return !elf::link(Args, true);
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
Compiler-6.0.0
|
|
@ -1 +0,0 @@
|
|||||||
Compiler-6.0.0
|
|
@ -1,49 +0,0 @@
|
|||||||
add_definitions(-Wno-error -Wno-unused-parameter -Wno-non-virtual-dtor -U_LIBCPP_DEBUG)
|
|
||||||
|
|
||||||
link_directories(${LLVM_LIBRARY_DIRS})
|
|
||||||
|
|
||||||
add_library(clickhouse-compiler-lib
|
|
||||||
driver.cpp
|
|
||||||
cc1_main.cpp
|
|
||||||
cc1gen_reproducer_main.cpp
|
|
||||||
cc1as_main.cpp
|
|
||||||
lld.cpp)
|
|
||||||
|
|
||||||
target_compile_options(clickhouse-compiler-lib PRIVATE -fno-rtti -fno-exceptions -g0)
|
|
||||||
|
|
||||||
string(REPLACE "${INCLUDE_DEBUG_HELPERS}" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # cant compile with -fno-rtti
|
|
||||||
|
|
||||||
llvm_libs_all(REQUIRED_LLVM_LIBRARIES)
|
|
||||||
|
|
||||||
message(STATUS "Using LLVM ${LLVM_VERSION}: ${LLVM_INCLUDE_DIRS} : ${REQUIRED_LLVM_LIBRARIES}")
|
|
||||||
|
|
||||||
target_include_directories(clickhouse-compiler-lib SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
# This is extracted almost directly from CMakeFiles/.../link.txt in LLVM build directory.
|
|
||||||
|
|
||||||
target_link_libraries(clickhouse-compiler-lib PRIVATE
|
|
||||||
clangBasic clangCodeGen clangDriver
|
|
||||||
clangFrontend
|
|
||||||
clangFrontendTool
|
|
||||||
clangRewriteFrontend clangARCMigrate clangStaticAnalyzerFrontend
|
|
||||||
clangParse clangSerialization clangSema clangEdit clangStaticAnalyzerCheckers
|
|
||||||
clangASTMatchers clangStaticAnalyzerCore clangAnalysis clangAST clangRewrite clangLex clangBasic
|
|
||||||
clangCrossTU clangIndex
|
|
||||||
|
|
||||||
lldCOFF
|
|
||||||
lldDriver
|
|
||||||
lldELF
|
|
||||||
lldMinGW
|
|
||||||
lldMachO
|
|
||||||
lldReaderWriter
|
|
||||||
lldYAML
|
|
||||||
lldCommon
|
|
||||||
lldCore
|
|
||||||
|
|
||||||
${REQUIRED_LLVM_LIBRARIES}
|
|
||||||
|
|
||||||
PUBLIC ${ZLIB_LIBRARIES} ${EXECINFO_LIBRARIES} Threads::Threads
|
|
||||||
${MALLOC_LIBRARIES}
|
|
||||||
${GLIBC_COMPATIBILITY_LIBRARIES}
|
|
||||||
${MEMCPY_LIBRARIES}
|
|
||||||
)
|
|
@ -1,239 +0,0 @@
|
|||||||
//===-- cc1_main.cpp - Clang CC1 Compiler Frontend ------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang -cc1 functionality, which implements the
|
|
||||||
// core compiler functionality along with a number of additional tools for
|
|
||||||
// demonstration and testing purposes.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "llvm/Option/Arg.h"
|
|
||||||
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
|
|
||||||
#include "clang/Config/config.h"
|
|
||||||
#include "clang/Basic/Stack.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Frontend/CompilerInstance.h"
|
|
||||||
#include "clang/Frontend/CompilerInvocation.h"
|
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "clang/FrontendTool/Utils.h"
|
|
||||||
#include "llvm/ADT/Statistic.h"
|
|
||||||
#include "llvm/Config/llvm-config.h"
|
|
||||||
#include "llvm/LinkAllPasses.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Support/Compiler.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#ifdef CLANG_HAVE_RLIMITS
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// have no .a version in packages
|
|
||||||
#undef LINK_POLLY_INTO_TOOLS
|
|
||||||
|
|
||||||
using namespace clang;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// Main driver
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
static void LLVMErrorHandler(void *UserData, const std::string &Message,
|
|
||||||
bool GenCrashDiag) {
|
|
||||||
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
|
|
||||||
|
|
||||||
Diags.Report(diag::err_fe_error_backend) << Message;
|
|
||||||
|
|
||||||
// Run the interrupt handlers to make sure any special cleanups get done, in
|
|
||||||
// particular that we remove files registered with RemoveFileOnSignal.
|
|
||||||
llvm::sys::RunInterruptHandlers();
|
|
||||||
|
|
||||||
// We cannot recover from llvm errors. When reporting a fatal error, exit
|
|
||||||
// with status 70 to generate crash diagnostics. For BSD systems this is
|
|
||||||
// defined as an internal software error. Otherwise, exit with status 1.
|
|
||||||
exit(GenCrashDiag ? 70 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LINK_POLLY_INTO_TOOLS
|
|
||||||
namespace polly {
|
|
||||||
void initializePollyPasses(llvm::PassRegistry &Registry);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CLANG_HAVE_RLIMITS
|
|
||||||
#if defined(__linux__) && defined(__PIE__)
|
|
||||||
static size_t getCurrentStackAllocation() {
|
|
||||||
// If we can't compute the current stack usage, allow for 512K of command
|
|
||||||
// line arguments and environment.
|
|
||||||
size_t Usage = 512 * 1024;
|
|
||||||
if (FILE *StatFile = fopen("/proc/self/stat", "r")) {
|
|
||||||
// We assume that the stack extends from its current address to the end of
|
|
||||||
// the environment space. In reality, there is another string literal (the
|
|
||||||
// program name) after the environment, but this is close enough (we only
|
|
||||||
// need to be within 100K or so).
|
|
||||||
unsigned long StackPtr, EnvEnd;
|
|
||||||
// Disable silly GCC -Wformat warning that complains about length
|
|
||||||
// modifiers on ignored format specifiers. We want to retain these
|
|
||||||
// for documentation purposes even though they have no effect.
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wformat"
|
|
||||||
#endif
|
|
||||||
if (fscanf(StatFile,
|
|
||||||
"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %*lu "
|
|
||||||
"%*lu %*ld %*ld %*ld %*ld %*ld %*ld %*llu %*lu %*ld %*lu %*lu "
|
|
||||||
"%*lu %*lu %lu %*lu %*lu %*lu %*lu %*lu %*llu %*lu %*lu %*d %*d "
|
|
||||||
"%*u %*u %*llu %*lu %*ld %*lu %*lu %*lu %*lu %*lu %*lu %lu %*d",
|
|
||||||
&StackPtr, &EnvEnd) == 2) {
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
Usage = StackPtr < EnvEnd ? EnvEnd - StackPtr : StackPtr - EnvEnd;
|
|
||||||
}
|
|
||||||
fclose(StatFile);
|
|
||||||
}
|
|
||||||
return Usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <alloca.h>
|
|
||||||
|
|
||||||
LLVM_ATTRIBUTE_NOINLINE
|
|
||||||
static void ensureStackAddressSpace() {
|
|
||||||
// Linux kernels prior to 4.1 will sometimes locate the heap of a PIE binary
|
|
||||||
// relatively close to the stack (they are only guaranteed to be 128MiB
|
|
||||||
// apart). This results in crashes if we happen to heap-allocate more than
|
|
||||||
// 128MiB before we reach our stack high-water mark.
|
|
||||||
//
|
|
||||||
// To avoid these crashes, ensure that we have sufficient virtual memory
|
|
||||||
// pages allocated before we start running.
|
|
||||||
size_t Curr = getCurrentStackAllocation();
|
|
||||||
const int kTargetStack = DesiredStackSize - 256 * 1024;
|
|
||||||
if (Curr < kTargetStack) {
|
|
||||||
volatile char *volatile Alloc =
|
|
||||||
static_cast<volatile char *>(alloca(kTargetStack - Curr));
|
|
||||||
Alloc[0] = 0;
|
|
||||||
Alloc[kTargetStack - Curr - 1] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static void ensureStackAddressSpace() {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Attempt to ensure that we have at least 8MiB of usable stack space.
|
|
||||||
static void ensureSufficientStack() {
|
|
||||||
struct rlimit rlim;
|
|
||||||
if (getrlimit(RLIMIT_STACK, &rlim) != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Increase the soft stack limit to our desired level, if necessary and
|
|
||||||
// possible.
|
|
||||||
if (rlim.rlim_cur != RLIM_INFINITY &&
|
|
||||||
rlim.rlim_cur < rlim_t(DesiredStackSize)) {
|
|
||||||
// Try to allocate sufficient stack.
|
|
||||||
if (rlim.rlim_max == RLIM_INFINITY ||
|
|
||||||
rlim.rlim_max >= rlim_t(DesiredStackSize))
|
|
||||||
rlim.rlim_cur = DesiredStackSize;
|
|
||||||
else if (rlim.rlim_cur == rlim.rlim_max)
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
rlim.rlim_cur = rlim.rlim_max;
|
|
||||||
|
|
||||||
if (setrlimit(RLIMIT_STACK, &rlim) != 0 ||
|
|
||||||
rlim.rlim_cur != DesiredStackSize)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should now have a stack of size at least DesiredStackSize. Ensure
|
|
||||||
// that we can actually use that much, if necessary.
|
|
||||||
ensureStackAddressSpace();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static void ensureSufficientStack() {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|
||||||
ensureSufficientStack();
|
|
||||||
|
|
||||||
std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
|
|
||||||
// Register the support for object-file-wrapped Clang modules.
|
|
||||||
auto PCHOps = Clang->getPCHContainerOperations();
|
|
||||||
PCHOps->registerWriter(llvm::make_unique<ObjectFilePCHContainerWriter>());
|
|
||||||
PCHOps->registerReader(llvm::make_unique<ObjectFilePCHContainerReader>());
|
|
||||||
|
|
||||||
// Initialize targets first, so that --version shows registered targets.
|
|
||||||
llvm::InitializeAllTargets();
|
|
||||||
llvm::InitializeAllTargetMCs();
|
|
||||||
llvm::InitializeAllAsmPrinters();
|
|
||||||
llvm::InitializeAllAsmParsers();
|
|
||||||
|
|
||||||
#ifdef LINK_POLLY_INTO_TOOLS
|
|
||||||
llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
|
|
||||||
polly::initializePollyPasses(Registry);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Buffer diagnostics from argument parsing so that we can output them using a
|
|
||||||
// well formed diagnostic object.
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
|
||||||
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
|
|
||||||
bool Success = CompilerInvocation::CreateFromArgs(
|
|
||||||
Clang->getInvocation(), Argv.begin(), Argv.end(), Diags);
|
|
||||||
|
|
||||||
// Infer the builtin include path if unspecified.
|
|
||||||
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
|
|
||||||
Clang->getHeaderSearchOpts().ResourceDir.empty())
|
|
||||||
Clang->getHeaderSearchOpts().ResourceDir =
|
|
||||||
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
|
|
||||||
|
|
||||||
// Create the actual diagnostics engine.
|
|
||||||
Clang->createDiagnostics();
|
|
||||||
if (!Clang->hasDiagnostics())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
|
||||||
// error handler.
|
|
||||||
llvm::install_fatal_error_handler(LLVMErrorHandler,
|
|
||||||
static_cast<void*>(&Clang->getDiagnostics()));
|
|
||||||
|
|
||||||
DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
|
|
||||||
if (!Success)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Execute the frontend actions.
|
|
||||||
Success = ExecuteCompilerInvocation(Clang.get());
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now. This happens in -disable-free mode.
|
|
||||||
llvm::TimerGroup::printAll(llvm::errs());
|
|
||||||
|
|
||||||
// Our error handler depends on the Diagnostics object, which we're
|
|
||||||
// potentially about to delete. Uninstall the handler now so that any
|
|
||||||
// later errors use the default handling behavior instead.
|
|
||||||
llvm::remove_fatal_error_handler();
|
|
||||||
|
|
||||||
// When running with -disable-free, don't do any destruction or shutdown.
|
|
||||||
if (Clang->getFrontendOpts().DisableFree) {
|
|
||||||
BuryPointer(std::move(Clang));
|
|
||||||
return !Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !Success;
|
|
||||||
}
|
|
@ -1,572 +0,0 @@
|
|||||||
//===-- cc1as_main.cpp - Clang Assembler ---------------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang -cc1as functionality, which implements
|
|
||||||
// the direct interface to the LLVM MC based assembler.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "clang/Basic/Diagnostic.h"
|
|
||||||
#include "clang/Basic/DiagnosticOptions.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
|
||||||
#include "llvm/ADT/Triple.h"
|
|
||||||
#include "llvm/IR/DataLayout.h"
|
|
||||||
#include "llvm/MC/MCAsmBackend.h"
|
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
|
||||||
#include "llvm/MC/MCCodeEmitter.h"
|
|
||||||
#include "llvm/MC/MCContext.h"
|
|
||||||
#include "llvm/MC/MCInstrInfo.h"
|
|
||||||
#include "llvm/MC/MCObjectFileInfo.h"
|
|
||||||
#include "llvm/MC/MCObjectWriter.h"
|
|
||||||
#include "llvm/MC/MCParser/MCAsmParser.h"
|
|
||||||
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
|
|
||||||
#include "llvm/MC/MCRegisterInfo.h"
|
|
||||||
#include "llvm/MC/MCStreamer.h"
|
|
||||||
#include "llvm/MC/MCSubtargetInfo.h"
|
|
||||||
#include "llvm/MC/MCTargetOptions.h"
|
|
||||||
#include "llvm/Option/Arg.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
|
||||||
#include "llvm/Support/FormattedStream.h"
|
|
||||||
#include "llvm/Support/Host.h"
|
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/SourceMgr.h"
|
|
||||||
#include "llvm/Support/TargetRegistry.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <system_error>
|
|
||||||
using namespace clang;
|
|
||||||
using namespace clang::driver;
|
|
||||||
using namespace clang::driver::options;
|
|
||||||
using namespace llvm;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
/// Helper class for representing a single invocation of the assembler.
|
|
||||||
struct AssemblerInvocation {
|
|
||||||
/// @name Target Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// The name of the target triple to assemble for.
|
|
||||||
std::string Triple;
|
|
||||||
|
|
||||||
/// If given, the name of the target CPU to determine which instructions
|
|
||||||
/// are legal.
|
|
||||||
std::string CPU;
|
|
||||||
|
|
||||||
/// The list of target specific features to enable or disable -- this should
|
|
||||||
/// be a list of strings starting with '+' or '-'.
|
|
||||||
std::vector<std::string> Features;
|
|
||||||
|
|
||||||
/// The list of symbol definitions.
|
|
||||||
std::vector<std::string> SymbolDefs;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Language Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
std::vector<std::string> IncludePaths;
|
|
||||||
unsigned NoInitialTextSection : 1;
|
|
||||||
unsigned SaveTemporaryLabels : 1;
|
|
||||||
unsigned GenDwarfForAssembly : 1;
|
|
||||||
unsigned RelaxELFRelocations : 1;
|
|
||||||
unsigned DwarfVersion;
|
|
||||||
std::string DwarfDebugFlags;
|
|
||||||
std::string DwarfDebugProducer;
|
|
||||||
std::string DebugCompilationDir;
|
|
||||||
std::map<const std::string, const std::string> DebugPrefixMap;
|
|
||||||
llvm::DebugCompressionType CompressDebugSections =
|
|
||||||
llvm::DebugCompressionType::None;
|
|
||||||
std::string MainFileName;
|
|
||||||
std::string SplitDwarfFile;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Frontend Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
std::string InputFile;
|
|
||||||
std::vector<std::string> LLVMArgs;
|
|
||||||
std::string OutputPath;
|
|
||||||
enum FileType {
|
|
||||||
FT_Asm, ///< Assembly (.s) output, transliterate mode.
|
|
||||||
FT_Null, ///< No output, for timing purposes.
|
|
||||||
FT_Obj ///< Object file output.
|
|
||||||
};
|
|
||||||
FileType OutputType;
|
|
||||||
unsigned ShowHelp : 1;
|
|
||||||
unsigned ShowVersion : 1;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Transliterate Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
unsigned OutputAsmVariant;
|
|
||||||
unsigned ShowEncoding : 1;
|
|
||||||
unsigned ShowInst : 1;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Assembler Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
unsigned RelaxAll : 1;
|
|
||||||
unsigned NoExecStack : 1;
|
|
||||||
unsigned FatalWarnings : 1;
|
|
||||||
unsigned IncrementalLinkerCompatible : 1;
|
|
||||||
|
|
||||||
/// The name of the relocation model to use.
|
|
||||||
std::string RelocationModel;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
public:
|
|
||||||
AssemblerInvocation() {
|
|
||||||
Triple = "";
|
|
||||||
NoInitialTextSection = 0;
|
|
||||||
InputFile = "-";
|
|
||||||
OutputPath = "-";
|
|
||||||
OutputType = FT_Asm;
|
|
||||||
OutputAsmVariant = 0;
|
|
||||||
ShowInst = 0;
|
|
||||||
ShowEncoding = 0;
|
|
||||||
RelaxAll = 0;
|
|
||||||
NoExecStack = 0;
|
|
||||||
FatalWarnings = 0;
|
|
||||||
IncrementalLinkerCompatible = 0;
|
|
||||||
DwarfVersion = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool CreateFromArgs(AssemblerInvocation &Res,
|
|
||||||
ArrayRef<const char *> Argv,
|
|
||||||
DiagnosticsEngine &Diags);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
|
|
||||||
ArrayRef<const char *> Argv,
|
|
||||||
DiagnosticsEngine &Diags) {
|
|
||||||
bool Success = true;
|
|
||||||
|
|
||||||
// Parse the arguments.
|
|
||||||
std::unique_ptr<OptTable> OptTbl(createDriverOptTable());
|
|
||||||
|
|
||||||
const unsigned IncludedFlagsBitmask = options::CC1AsOption;
|
|
||||||
unsigned MissingArgIndex, MissingArgCount;
|
|
||||||
InputArgList Args = OptTbl->ParseArgs(Argv, MissingArgIndex, MissingArgCount,
|
|
||||||
IncludedFlagsBitmask);
|
|
||||||
|
|
||||||
// Check for missing argument error.
|
|
||||||
if (MissingArgCount) {
|
|
||||||
Diags.Report(diag::err_drv_missing_argument)
|
|
||||||
<< Args.getArgString(MissingArgIndex) << MissingArgCount;
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Issue errors on unknown arguments.
|
|
||||||
for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
|
|
||||||
auto ArgString = A->getAsString(Args);
|
|
||||||
std::string Nearest;
|
|
||||||
if (OptTbl->findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument) << ArgString;
|
|
||||||
else
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
|
|
||||||
<< ArgString << Nearest;
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct the invocation.
|
|
||||||
|
|
||||||
// Target Options
|
|
||||||
Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
|
|
||||||
Opts.CPU = Args.getLastArgValue(OPT_target_cpu);
|
|
||||||
Opts.Features = Args.getAllArgValues(OPT_target_feature);
|
|
||||||
|
|
||||||
// Use the default target triple if unspecified.
|
|
||||||
if (Opts.Triple.empty())
|
|
||||||
Opts.Triple = llvm::sys::getDefaultTargetTriple();
|
|
||||||
|
|
||||||
// Language Options
|
|
||||||
Opts.IncludePaths = Args.getAllArgValues(OPT_I);
|
|
||||||
Opts.NoInitialTextSection = Args.hasArg(OPT_n);
|
|
||||||
Opts.SaveTemporaryLabels = Args.hasArg(OPT_msave_temp_labels);
|
|
||||||
// Any DebugInfoKind implies GenDwarfForAssembly.
|
|
||||||
Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ);
|
|
||||||
|
|
||||||
if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections,
|
|
||||||
OPT_compress_debug_sections_EQ)) {
|
|
||||||
if (A->getOption().getID() == OPT_compress_debug_sections) {
|
|
||||||
// TODO: be more clever about the compression type auto-detection
|
|
||||||
Opts.CompressDebugSections = llvm::DebugCompressionType::GNU;
|
|
||||||
} else {
|
|
||||||
Opts.CompressDebugSections =
|
|
||||||
llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue())
|
|
||||||
.Case("none", llvm::DebugCompressionType::None)
|
|
||||||
.Case("zlib", llvm::DebugCompressionType::Z)
|
|
||||||
.Case("zlib-gnu", llvm::DebugCompressionType::GNU)
|
|
||||||
.Default(llvm::DebugCompressionType::None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
|
|
||||||
Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
|
|
||||||
Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
|
|
||||||
Opts.DwarfDebugProducer = Args.getLastArgValue(OPT_dwarf_debug_producer);
|
|
||||||
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
|
|
||||||
Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
|
|
||||||
|
|
||||||
for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
|
|
||||||
Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));
|
|
||||||
|
|
||||||
// Frontend Options
|
|
||||||
if (Args.hasArg(OPT_INPUT)) {
|
|
||||||
bool First = true;
|
|
||||||
for (const Arg *A : Args.filtered(OPT_INPUT)) {
|
|
||||||
if (First) {
|
|
||||||
Opts.InputFile = A->getValue();
|
|
||||||
First = false;
|
|
||||||
} else {
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
|
|
||||||
Opts.OutputPath = Args.getLastArgValue(OPT_o);
|
|
||||||
Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
|
|
||||||
if (Arg *A = Args.getLastArg(OPT_filetype)) {
|
|
||||||
StringRef Name = A->getValue();
|
|
||||||
unsigned OutputType = StringSwitch<unsigned>(Name)
|
|
||||||
.Case("asm", FT_Asm)
|
|
||||||
.Case("null", FT_Null)
|
|
||||||
.Case("obj", FT_Obj)
|
|
||||||
.Default(~0U);
|
|
||||||
if (OutputType == ~0U) {
|
|
||||||
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
|
|
||||||
Success = false;
|
|
||||||
} else
|
|
||||||
Opts.OutputType = FileType(OutputType);
|
|
||||||
}
|
|
||||||
Opts.ShowHelp = Args.hasArg(OPT_help);
|
|
||||||
Opts.ShowVersion = Args.hasArg(OPT_version);
|
|
||||||
|
|
||||||
// Transliterate Options
|
|
||||||
Opts.OutputAsmVariant =
|
|
||||||
getLastArgIntValue(Args, OPT_output_asm_variant, 0, Diags);
|
|
||||||
Opts.ShowEncoding = Args.hasArg(OPT_show_encoding);
|
|
||||||
Opts.ShowInst = Args.hasArg(OPT_show_inst);
|
|
||||||
|
|
||||||
// Assemble Options
|
|
||||||
Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
|
|
||||||
Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
|
|
||||||
Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
|
|
||||||
Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
|
|
||||||
Opts.IncrementalLinkerCompatible =
|
|
||||||
Args.hasArg(OPT_mincremental_linker_compatible);
|
|
||||||
Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::unique_ptr<raw_fd_ostream>
|
|
||||||
getOutputStream(StringRef Path, DiagnosticsEngine &Diags, bool Binary) {
|
|
||||||
// Make sure that the Out file gets unlinked from the disk if we get a
|
|
||||||
// SIGINT.
|
|
||||||
if (Path != "-")
|
|
||||||
sys::RemoveFileOnSignal(Path);
|
|
||||||
|
|
||||||
std::error_code EC;
|
|
||||||
auto Out = llvm::make_unique<raw_fd_ostream>(
|
|
||||||
Path, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text));
|
|
||||||
if (EC) {
|
|
||||||
Diags.Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Out;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ExecuteAssembler(AssemblerInvocation &Opts,
|
|
||||||
DiagnosticsEngine &Diags) {
|
|
||||||
// Get the target specific parser.
|
|
||||||
std::string Error;
|
|
||||||
const Target *TheTarget = TargetRegistry::lookupTarget(Opts.Triple, Error);
|
|
||||||
if (!TheTarget)
|
|
||||||
return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
|
|
||||||
|
|
||||||
ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
|
|
||||||
MemoryBuffer::getFileOrSTDIN(Opts.InputFile);
|
|
||||||
|
|
||||||
if (std::error_code EC = Buffer.getError()) {
|
|
||||||
Error = EC.message();
|
|
||||||
return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
SourceMgr SrcMgr;
|
|
||||||
|
|
||||||
// Tell SrcMgr about this buffer, which is what the parser will pick up.
|
|
||||||
SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc());
|
|
||||||
|
|
||||||
// Record the location of the include directories so that the lexer can find
|
|
||||||
// it later.
|
|
||||||
SrcMgr.setIncludeDirs(Opts.IncludePaths);
|
|
||||||
|
|
||||||
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(Opts.Triple));
|
|
||||||
assert(MRI && "Unable to create target register info!");
|
|
||||||
|
|
||||||
std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, Opts.Triple));
|
|
||||||
assert(MAI && "Unable to create target asm info!");
|
|
||||||
|
|
||||||
// Ensure MCAsmInfo initialization occurs before any use, otherwise sections
|
|
||||||
// may be created with a combination of default and explicit settings.
|
|
||||||
MAI->setCompressDebugSections(Opts.CompressDebugSections);
|
|
||||||
|
|
||||||
MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations);
|
|
||||||
|
|
||||||
bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj;
|
|
||||||
if (Opts.OutputPath.empty())
|
|
||||||
Opts.OutputPath = "-";
|
|
||||||
std::unique_ptr<raw_fd_ostream> FDOS =
|
|
||||||
getOutputStream(Opts.OutputPath, Diags, IsBinary);
|
|
||||||
if (!FDOS)
|
|
||||||
return true;
|
|
||||||
std::unique_ptr<raw_fd_ostream> DwoOS;
|
|
||||||
if (!Opts.SplitDwarfFile.empty())
|
|
||||||
DwoOS = getOutputStream(Opts.SplitDwarfFile, Diags, IsBinary);
|
|
||||||
|
|
||||||
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
|
|
||||||
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
|
|
||||||
std::unique_ptr<MCObjectFileInfo> MOFI(new MCObjectFileInfo());
|
|
||||||
|
|
||||||
MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr);
|
|
||||||
|
|
||||||
bool PIC = false;
|
|
||||||
if (Opts.RelocationModel == "static") {
|
|
||||||
PIC = false;
|
|
||||||
} else if (Opts.RelocationModel == "pic") {
|
|
||||||
PIC = true;
|
|
||||||
} else {
|
|
||||||
assert(Opts.RelocationModel == "dynamic-no-pic" &&
|
|
||||||
"Invalid PIC model!");
|
|
||||||
PIC = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), PIC, Ctx);
|
|
||||||
if (Opts.SaveTemporaryLabels)
|
|
||||||
Ctx.setAllowTemporaryLabels(false);
|
|
||||||
if (Opts.GenDwarfForAssembly)
|
|
||||||
Ctx.setGenDwarfForAssembly(true);
|
|
||||||
if (!Opts.DwarfDebugFlags.empty())
|
|
||||||
Ctx.setDwarfDebugFlags(StringRef(Opts.DwarfDebugFlags));
|
|
||||||
if (!Opts.DwarfDebugProducer.empty())
|
|
||||||
Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
|
|
||||||
if (!Opts.DebugCompilationDir.empty())
|
|
||||||
Ctx.setCompilationDir(Opts.DebugCompilationDir);
|
|
||||||
if (!Opts.DebugPrefixMap.empty())
|
|
||||||
for (const auto &KV : Opts.DebugPrefixMap)
|
|
||||||
Ctx.addDebugPrefixMapEntry(KV.first, KV.second);
|
|
||||||
if (!Opts.MainFileName.empty())
|
|
||||||
Ctx.setMainFileName(StringRef(Opts.MainFileName));
|
|
||||||
Ctx.setDwarfVersion(Opts.DwarfVersion);
|
|
||||||
|
|
||||||
// Build up the feature string from the target feature list.
|
|
||||||
std::string FS;
|
|
||||||
if (!Opts.Features.empty()) {
|
|
||||||
FS = Opts.Features[0];
|
|
||||||
for (unsigned i = 1, e = Opts.Features.size(); i != e; ++i)
|
|
||||||
FS += "," + Opts.Features[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<MCStreamer> Str;
|
|
||||||
|
|
||||||
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
|
|
||||||
std::unique_ptr<MCSubtargetInfo> STI(
|
|
||||||
TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS));
|
|
||||||
|
|
||||||
raw_pwrite_stream *Out = FDOS.get();
|
|
||||||
std::unique_ptr<buffer_ostream> BOS;
|
|
||||||
|
|
||||||
// FIXME: There is a bit of code duplication with addPassesToEmitFile.
|
|
||||||
if (Opts.OutputType == AssemblerInvocation::FT_Asm) {
|
|
||||||
MCInstPrinter *IP = TheTarget->createMCInstPrinter(
|
|
||||||
llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI);
|
|
||||||
|
|
||||||
std::unique_ptr<MCCodeEmitter> CE;
|
|
||||||
if (Opts.ShowEncoding)
|
|
||||||
CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
|
|
||||||
MCTargetOptions MCOptions;
|
|
||||||
std::unique_ptr<MCAsmBackend> MAB(
|
|
||||||
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
|
|
||||||
|
|
||||||
auto FOut = llvm::make_unique<formatted_raw_ostream>(*Out);
|
|
||||||
Str.reset(TheTarget->createAsmStreamer(
|
|
||||||
Ctx, std::move(FOut), /*asmverbose*/ true,
|
|
||||||
/*useDwarfDirectory*/ true, IP, std::move(CE), std::move(MAB),
|
|
||||||
Opts.ShowInst));
|
|
||||||
} else if (Opts.OutputType == AssemblerInvocation::FT_Null) {
|
|
||||||
Str.reset(createNullStreamer(Ctx));
|
|
||||||
} else {
|
|
||||||
assert(Opts.OutputType == AssemblerInvocation::FT_Obj &&
|
|
||||||
"Invalid file type!");
|
|
||||||
if (!FDOS->supportsSeeking()) {
|
|
||||||
BOS = make_unique<buffer_ostream>(*FDOS);
|
|
||||||
Out = BOS.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<MCCodeEmitter> CE(
|
|
||||||
TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
|
|
||||||
MCTargetOptions MCOptions;
|
|
||||||
std::unique_ptr<MCAsmBackend> MAB(
|
|
||||||
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
|
|
||||||
std::unique_ptr<MCObjectWriter> OW =
|
|
||||||
DwoOS ? MAB->createDwoObjectWriter(*Out, *DwoOS)
|
|
||||||
: MAB->createObjectWriter(*Out);
|
|
||||||
|
|
||||||
Triple T(Opts.Triple);
|
|
||||||
Str.reset(TheTarget->createMCObjectStreamer(
|
|
||||||
T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI,
|
|
||||||
Opts.RelaxAll, Opts.IncrementalLinkerCompatible,
|
|
||||||
/*DWARFMustBeAtTheEnd*/ true));
|
|
||||||
Str.get()->InitSections(Opts.NoExecStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assembly to object compilation should leverage assembly info.
|
|
||||||
Str->setUseAssemblerInfoForParsing(true);
|
|
||||||
|
|
||||||
bool Failed = false;
|
|
||||||
|
|
||||||
std::unique_ptr<MCAsmParser> Parser(
|
|
||||||
createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI));
|
|
||||||
|
|
||||||
// FIXME: init MCTargetOptions from sanitizer flags here.
|
|
||||||
MCTargetOptions Options;
|
|
||||||
std::unique_ptr<MCTargetAsmParser> TAP(
|
|
||||||
TheTarget->createMCAsmParser(*STI, *Parser, *MCII, Options));
|
|
||||||
if (!TAP)
|
|
||||||
Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
|
|
||||||
|
|
||||||
// Set values for symbols, if any.
|
|
||||||
for (auto &S : Opts.SymbolDefs) {
|
|
||||||
auto Pair = StringRef(S).split('=');
|
|
||||||
auto Sym = Pair.first;
|
|
||||||
auto Val = Pair.second;
|
|
||||||
int64_t Value = 1;
|
|
||||||
// We have already error checked this in the driver.
|
|
||||||
Val.getAsInteger(0, Value);
|
|
||||||
Ctx.setSymbolValue(Parser->getStreamer(), Sym, Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Failed) {
|
|
||||||
Parser->setTargetParser(*TAP.get());
|
|
||||||
Failed = Parser->Run(Opts.NoInitialTextSection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close Streamer first.
|
|
||||||
// It might have a reference to the output stream.
|
|
||||||
Str.reset();
|
|
||||||
// Close the output stream early.
|
|
||||||
BOS.reset();
|
|
||||||
FDOS.reset();
|
|
||||||
|
|
||||||
// Delete output file if there were errors.
|
|
||||||
if (Failed) {
|
|
||||||
if (Opts.OutputPath != "-")
|
|
||||||
sys::fs::remove(Opts.OutputPath);
|
|
||||||
if (!Opts.SplitDwarfFile.empty() && Opts.SplitDwarfFile != "-")
|
|
||||||
sys::fs::remove(Opts.SplitDwarfFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void LLVMErrorHandler(void *UserData, const std::string &Message,
|
|
||||||
bool GenCrashDiag) {
|
|
||||||
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
|
|
||||||
|
|
||||||
Diags.Report(diag::err_fe_error_backend) << Message;
|
|
||||||
|
|
||||||
// We cannot recover from llvm errors.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|
||||||
// Initialize targets and assembly printers/parsers.
|
|
||||||
InitializeAllTargetInfos();
|
|
||||||
InitializeAllTargetMCs();
|
|
||||||
InitializeAllAsmParsers();
|
|
||||||
|
|
||||||
// Construct our diagnostic client.
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
|
||||||
TextDiagnosticPrinter *DiagClient
|
|
||||||
= new TextDiagnosticPrinter(errs(), &*DiagOpts);
|
|
||||||
DiagClient->setPrefix("clang -cc1as");
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
|
||||||
|
|
||||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
|
||||||
// error handler.
|
|
||||||
ScopedFatalErrorHandler FatalErrorHandler
|
|
||||||
(LLVMErrorHandler, static_cast<void*>(&Diags));
|
|
||||||
|
|
||||||
// Parse the arguments.
|
|
||||||
AssemblerInvocation Asm;
|
|
||||||
if (!AssemblerInvocation::CreateFromArgs(Asm, Argv, Diags))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (Asm.ShowHelp) {
|
|
||||||
std::unique_ptr<OptTable> Opts(driver::createDriverOptTable());
|
|
||||||
Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
|
|
||||||
/*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
|
|
||||||
/*ShowAllAliases=*/false);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Honor -version.
|
|
||||||
//
|
|
||||||
// FIXME: Use a better -version message?
|
|
||||||
if (Asm.ShowVersion) {
|
|
||||||
llvm::cl::PrintVersionMessage();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Honor -mllvm.
|
|
||||||
//
|
|
||||||
// FIXME: Remove this, one day.
|
|
||||||
if (!Asm.LLVMArgs.empty()) {
|
|
||||||
unsigned NumArgs = Asm.LLVMArgs.size();
|
|
||||||
auto Args = llvm::make_unique<const char*[]>(NumArgs + 2);
|
|
||||||
Args[0] = "clang (LLVM option parsing)";
|
|
||||||
for (unsigned i = 0; i != NumArgs; ++i)
|
|
||||||
Args[i + 1] = Asm.LLVMArgs[i].c_str();
|
|
||||||
Args[NumArgs + 1] = nullptr;
|
|
||||||
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the invocation, unless there were parsing errors.
|
|
||||||
bool Failed = Diags.hasErrorOccurred() || ExecuteAssembler(Asm, Diags);
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now.
|
|
||||||
TimerGroup::printAll(errs());
|
|
||||||
|
|
||||||
return !!Failed;
|
|
||||||
}
|
|
@ -1,196 +0,0 @@
|
|||||||
//===-- cc1gen_reproducer_main.cpp - Clang reproducer generator ----------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang -cc1gen-reproducer functionality, which
|
|
||||||
// generates reproducers for invocations for clang-based tools.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "clang/Basic/Diagnostic.h"
|
|
||||||
#include "clang/Basic/LLVM.h"
|
|
||||||
#include "clang/Basic/VirtualFileSystem.h"
|
|
||||||
#include "clang/Driver/Compilation.h"
|
|
||||||
#include "clang/Driver/Driver.h"
|
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/YAMLTraits.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
|
|
||||||
using namespace clang;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
struct UnsavedFileHash {
|
|
||||||
std::string Name;
|
|
||||||
std::string MD5;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ClangInvocationInfo {
|
|
||||||
std::string Toolchain;
|
|
||||||
std::string LibclangOperation;
|
|
||||||
std::string LibclangOptions;
|
|
||||||
std::vector<std::string> Arguments;
|
|
||||||
std::vector<std::string> InvocationArguments;
|
|
||||||
std::vector<UnsavedFileHash> UnsavedFileHashes;
|
|
||||||
bool Dump = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end anonymous namespace
|
|
||||||
|
|
||||||
LLVM_YAML_IS_SEQUENCE_VECTOR(UnsavedFileHash)
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
namespace yaml {
|
|
||||||
|
|
||||||
template <> struct MappingTraits<UnsavedFileHash> {
|
|
||||||
static void mapping(IO &IO, UnsavedFileHash &Info) {
|
|
||||||
IO.mapRequired("name", Info.Name);
|
|
||||||
IO.mapRequired("md5", Info.MD5);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct MappingTraits<ClangInvocationInfo> {
|
|
||||||
static void mapping(IO &IO, ClangInvocationInfo &Info) {
|
|
||||||
IO.mapRequired("toolchain", Info.Toolchain);
|
|
||||||
IO.mapOptional("libclang.operation", Info.LibclangOperation);
|
|
||||||
IO.mapOptional("libclang.opts", Info.LibclangOptions);
|
|
||||||
IO.mapRequired("args", Info.Arguments);
|
|
||||||
IO.mapOptional("invocation-args", Info.InvocationArguments);
|
|
||||||
IO.mapOptional("unsaved_file_hashes", Info.UnsavedFileHashes);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace yaml
|
|
||||||
} // end namespace llvm
|
|
||||||
|
|
||||||
static std::string generateReproducerMetaInfo(const ClangInvocationInfo &Info) {
|
|
||||||
std::string Result;
|
|
||||||
llvm::raw_string_ostream OS(Result);
|
|
||||||
OS << '{';
|
|
||||||
bool NeedComma = false;
|
|
||||||
auto EmitKey = [&](StringRef Key) {
|
|
||||||
if (NeedComma)
|
|
||||||
OS << ", ";
|
|
||||||
NeedComma = true;
|
|
||||||
OS << '"' << Key << "\": ";
|
|
||||||
};
|
|
||||||
auto EmitStringKey = [&](StringRef Key, StringRef Value) {
|
|
||||||
if (Value.empty())
|
|
||||||
return;
|
|
||||||
EmitKey(Key);
|
|
||||||
OS << '"' << Value << '"';
|
|
||||||
};
|
|
||||||
EmitStringKey("libclang.operation", Info.LibclangOperation);
|
|
||||||
EmitStringKey("libclang.opts", Info.LibclangOptions);
|
|
||||||
if (!Info.InvocationArguments.empty()) {
|
|
||||||
EmitKey("invocation-args");
|
|
||||||
OS << '[';
|
|
||||||
for (const auto &Arg : llvm::enumerate(Info.InvocationArguments)) {
|
|
||||||
if (Arg.index())
|
|
||||||
OS << ',';
|
|
||||||
OS << '"' << Arg.value() << '"';
|
|
||||||
}
|
|
||||||
OS << ']';
|
|
||||||
}
|
|
||||||
OS << '}';
|
|
||||||
// FIXME: Compare unsaved file hashes and report mismatch in the reproducer.
|
|
||||||
if (Info.Dump)
|
|
||||||
llvm::outs() << "REPRODUCER METAINFO: " << OS.str() << "\n";
|
|
||||||
return std::move(OS.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generates a reproducer for a set of arguments from a specific invocation.
|
|
||||||
static llvm::Optional<driver::Driver::CompilationDiagnosticReport>
|
|
||||||
generateReproducerForInvocationArguments(ArrayRef<const char *> Argv,
|
|
||||||
const ClangInvocationInfo &Info) {
|
|
||||||
using namespace driver;
|
|
||||||
auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(Argv[0]);
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions;
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new IgnoringDiagConsumer());
|
|
||||||
ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
|
|
||||||
Driver TheDriver(Argv[0], llvm::sys::getDefaultTargetTriple(), Diags);
|
|
||||||
TheDriver.setTargetAndMode(TargetAndMode);
|
|
||||||
|
|
||||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(Argv));
|
|
||||||
if (C && !C->containsError()) {
|
|
||||||
for (const auto &J : C->getJobs()) {
|
|
||||||
if (const Command *Cmd = dyn_cast<Command>(&J)) {
|
|
||||||
Driver::CompilationDiagnosticReport Report;
|
|
||||||
TheDriver.generateCompilationDiagnostics(
|
|
||||||
*C, *Cmd, generateReproducerMetaInfo(Info), &Report);
|
|
||||||
return Report;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes);
|
|
||||||
|
|
||||||
static void printReproducerInformation(
|
|
||||||
llvm::raw_ostream &OS, const ClangInvocationInfo &Info,
|
|
||||||
const driver::Driver::CompilationDiagnosticReport &Report) {
|
|
||||||
OS << "REPRODUCER:\n";
|
|
||||||
OS << "{\n";
|
|
||||||
OS << R"("files":[)";
|
|
||||||
for (const auto &File : llvm::enumerate(Report.TemporaryFiles)) {
|
|
||||||
if (File.index())
|
|
||||||
OS << ',';
|
|
||||||
OS << '"' << File.value() << '"';
|
|
||||||
}
|
|
||||||
OS << "]\n}\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
int cc1gen_reproducer_main(ArrayRef<const char *> Argv, const char *Argv0,
|
|
||||||
void *MainAddr) {
|
|
||||||
if (Argv.size() < 1) {
|
|
||||||
llvm::errs() << "error: missing invocation file\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
// Parse the invocation descriptor.
|
|
||||||
StringRef Input = Argv[0];
|
|
||||||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
|
|
||||||
llvm::MemoryBuffer::getFile(Input);
|
|
||||||
if (!Buffer) {
|
|
||||||
llvm::errs() << "error: failed to read " << Input << ": "
|
|
||||||
<< Buffer.getError().message() << "\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
llvm::yaml::Input YAML(Buffer.get()->getBuffer());
|
|
||||||
ClangInvocationInfo InvocationInfo;
|
|
||||||
YAML >> InvocationInfo;
|
|
||||||
if (Argv.size() > 1 && Argv[1] == StringRef("-v"))
|
|
||||||
InvocationInfo.Dump = true;
|
|
||||||
|
|
||||||
// Create an invocation that will produce the reproducer.
|
|
||||||
std::vector<const char *> DriverArgs;
|
|
||||||
for (const auto &Arg : InvocationInfo.Arguments)
|
|
||||||
DriverArgs.push_back(Arg.c_str());
|
|
||||||
std::string Path = GetExecutablePath(Argv0, /*CanonicalPrefixes=*/true);
|
|
||||||
DriverArgs[0] = Path.c_str();
|
|
||||||
llvm::Optional<driver::Driver::CompilationDiagnosticReport> Report =
|
|
||||||
generateReproducerForInvocationArguments(DriverArgs, InvocationInfo);
|
|
||||||
|
|
||||||
// Emit the information about the reproduce files to stdout.
|
|
||||||
int Result = 1;
|
|
||||||
if (Report) {
|
|
||||||
printReproducerInformation(llvm::outs(), InvocationInfo, *Report);
|
|
||||||
Result = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the input file.
|
|
||||||
llvm::sys::fs::remove(Input);
|
|
||||||
return Result;
|
|
||||||
}
|
|
@ -1,514 +0,0 @@
|
|||||||
//===-- driver.cpp - Clang GCC-Compatible Driver --------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang driver; it is a thin wrapper
|
|
||||||
// for functionality in the Driver clang library.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "clang/Driver/Driver.h"
|
|
||||||
#include "clang/Basic/DiagnosticOptions.h"
|
|
||||||
#include "clang/Driver/Compilation.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Driver/ToolChain.h"
|
|
||||||
#include "clang/Frontend/ChainedDiagnosticConsumer.h"
|
|
||||||
#include "clang/Frontend/CompilerInvocation.h"
|
|
||||||
#include "clang/Frontend/SerializedDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
|
||||||
#include "llvm/ADT/SmallString.h"
|
|
||||||
#include "llvm/ADT/SmallVector.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Option/Option.h"
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
|
||||||
#include "llvm/Support/Host.h"
|
|
||||||
#include "llvm/Support/InitLLVM.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/Process.h"
|
|
||||||
#include "llvm/Support/Program.h"
|
|
||||||
#include "llvm/Support/Regex.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/StringSaver.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <set>
|
|
||||||
#include <system_error>
|
|
||||||
using namespace clang;
|
|
||||||
using namespace clang::driver;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
|
|
||||||
if (!CanonicalPrefixes) {
|
|
||||||
SmallString<128> ExecutablePath(Argv0);
|
|
||||||
// Do a PATH lookup if Argv0 isn't a valid path.
|
|
||||||
if (!llvm::sys::fs::exists(ExecutablePath))
|
|
||||||
if (llvm::ErrorOr<std::string> P =
|
|
||||||
llvm::sys::findProgramByName(ExecutablePath))
|
|
||||||
ExecutablePath = *P;
|
|
||||||
return ExecutablePath.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This just needs to be some symbol in the binary; C++ doesn't
|
|
||||||
// allow taking the address of ::main however.
|
|
||||||
void *P = (void*) (intptr_t) GetExecutablePath;
|
|
||||||
return llvm::sys::fs::getMainExecutable(Argv0, P);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *GetStableCStr(std::set<std::string> &SavedStrings,
|
|
||||||
StringRef S) {
|
|
||||||
return SavedStrings.insert(S).first->c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ApplyQAOverride - Apply a list of edits to the input argument lists.
|
|
||||||
///
|
|
||||||
/// The input string is a space separate list of edits to perform,
|
|
||||||
/// they are applied in order to the input argument lists. Edits
|
|
||||||
/// should be one of the following forms:
|
|
||||||
///
|
|
||||||
/// '#': Silence information about the changes to the command line arguments.
|
|
||||||
///
|
|
||||||
/// '^': Add FOO as a new argument at the beginning of the command line.
|
|
||||||
///
|
|
||||||
/// '+': Add FOO as a new argument at the end of the command line.
|
|
||||||
///
|
|
||||||
/// 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
|
|
||||||
/// line.
|
|
||||||
///
|
|
||||||
/// 'xOPTION': Removes all instances of the literal argument OPTION.
|
|
||||||
///
|
|
||||||
/// 'XOPTION': Removes all instances of the literal argument OPTION,
|
|
||||||
/// and the following argument.
|
|
||||||
///
|
|
||||||
/// 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
|
|
||||||
/// at the end of the command line.
|
|
||||||
///
|
|
||||||
/// \param OS - The stream to write edit information to.
|
|
||||||
/// \param Args - The vector of command line arguments.
|
|
||||||
/// \param Edit - The override command to perform.
|
|
||||||
/// \param SavedStrings - Set to use for storing string representations.
|
|
||||||
static void ApplyOneQAOverride(raw_ostream &OS,
|
|
||||||
SmallVectorImpl<const char*> &Args,
|
|
||||||
StringRef Edit,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
// This does not need to be efficient.
|
|
||||||
|
|
||||||
if (Edit[0] == '^') {
|
|
||||||
const char *Str =
|
|
||||||
GetStableCStr(SavedStrings, Edit.substr(1));
|
|
||||||
OS << "### Adding argument " << Str << " at beginning\n";
|
|
||||||
Args.insert(Args.begin() + 1, Str);
|
|
||||||
} else if (Edit[0] == '+') {
|
|
||||||
const char *Str =
|
|
||||||
GetStableCStr(SavedStrings, Edit.substr(1));
|
|
||||||
OS << "### Adding argument " << Str << " at end\n";
|
|
||||||
Args.push_back(Str);
|
|
||||||
} else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
|
|
||||||
Edit.slice(2, Edit.size()-1).find('/') != StringRef::npos) {
|
|
||||||
StringRef MatchPattern = Edit.substr(2).split('/').first;
|
|
||||||
StringRef ReplPattern = Edit.substr(2).split('/').second;
|
|
||||||
ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1);
|
|
||||||
|
|
||||||
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
|
|
||||||
// Ignore end-of-line response file markers
|
|
||||||
if (Args[i] == nullptr)
|
|
||||||
continue;
|
|
||||||
std::string Repl = llvm::Regex(MatchPattern).sub(ReplPattern, Args[i]);
|
|
||||||
|
|
||||||
if (Repl != Args[i]) {
|
|
||||||
OS << "### Replacing '" << Args[i] << "' with '" << Repl << "'\n";
|
|
||||||
Args[i] = GetStableCStr(SavedStrings, Repl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (Edit[0] == 'x' || Edit[0] == 'X') {
|
|
||||||
auto Option = Edit.substr(1);
|
|
||||||
for (unsigned i = 1; i < Args.size();) {
|
|
||||||
if (Option == Args[i]) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
if (Edit[0] == 'X') {
|
|
||||||
if (i < Args.size()) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
} else
|
|
||||||
OS << "### Invalid X edit, end of command line!\n";
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
} else if (Edit[0] == 'O') {
|
|
||||||
for (unsigned i = 1; i < Args.size();) {
|
|
||||||
const char *A = Args[i];
|
|
||||||
// Ignore end-of-line response file markers
|
|
||||||
if (A == nullptr)
|
|
||||||
continue;
|
|
||||||
if (A[0] == '-' && A[1] == 'O' &&
|
|
||||||
(A[2] == '\0' ||
|
|
||||||
(A[3] == '\0' && (A[2] == 's' || A[2] == 'z' ||
|
|
||||||
('0' <= A[2] && A[2] <= '9'))))) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
} else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
OS << "### Adding argument " << Edit << " at end\n";
|
|
||||||
Args.push_back(GetStableCStr(SavedStrings, '-' + Edit.str()));
|
|
||||||
} else {
|
|
||||||
OS << "### Unrecognized edit: " << Edit << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ApplyQAOverride - Apply a comma separate list of edits to the
|
|
||||||
/// input argument lists. See ApplyOneQAOverride.
|
|
||||||
static void ApplyQAOverride(SmallVectorImpl<const char*> &Args,
|
|
||||||
const char *OverrideStr,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
raw_ostream *OS = &llvm::errs();
|
|
||||||
|
|
||||||
if (OverrideStr[0] == '#') {
|
|
||||||
++OverrideStr;
|
|
||||||
OS = &llvm::nulls();
|
|
||||||
}
|
|
||||||
|
|
||||||
*OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
|
|
||||||
|
|
||||||
// This does not need to be efficient.
|
|
||||||
|
|
||||||
const char *S = OverrideStr;
|
|
||||||
while (*S) {
|
|
||||||
const char *End = ::strchr(S, ' ');
|
|
||||||
if (!End)
|
|
||||||
End = S + strlen(S);
|
|
||||||
if (End != S)
|
|
||||||
ApplyOneQAOverride(*OS, Args, std::string(S, End), SavedStrings);
|
|
||||||
S = End;
|
|
||||||
if (*S != '\0')
|
|
||||||
++S;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0,
|
|
||||||
void *MainAddr);
|
|
||||||
extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0,
|
|
||||||
void *MainAddr);
|
|
||||||
extern int cc1gen_reproducer_main(ArrayRef<const char *> Argv,
|
|
||||||
const char *Argv0, void *MainAddr);
|
|
||||||
|
|
||||||
static void insertTargetAndModeArgs(const ParsedClangName &NameParts,
|
|
||||||
SmallVectorImpl<const char *> &ArgVector,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
// Put target and mode arguments at the start of argument list so that
|
|
||||||
// arguments specified in command line could override them. Avoid putting
|
|
||||||
// them at index 0, as an option like '-cc1' must remain the first.
|
|
||||||
int InsertionPoint = 0;
|
|
||||||
if (ArgVector.size() > 0)
|
|
||||||
++InsertionPoint;
|
|
||||||
|
|
||||||
if (NameParts.DriverMode) {
|
|
||||||
// Add the mode flag to the arguments.
|
|
||||||
ArgVector.insert(ArgVector.begin() + InsertionPoint,
|
|
||||||
GetStableCStr(SavedStrings, NameParts.DriverMode));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NameParts.TargetIsValid) {
|
|
||||||
const char *arr[] = {"-target", GetStableCStr(SavedStrings,
|
|
||||||
NameParts.TargetPrefix)};
|
|
||||||
ArgVector.insert(ArgVector.begin() + InsertionPoint,
|
|
||||||
std::begin(arr), std::end(arr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void getCLEnvVarOptions(std::string &EnvValue, llvm::StringSaver &Saver,
|
|
||||||
SmallVectorImpl<const char *> &Opts) {
|
|
||||||
llvm::cl::TokenizeWindowsCommandLine(EnvValue, Saver, Opts);
|
|
||||||
// The first instance of '#' should be replaced with '=' in each option.
|
|
||||||
for (const char *Opt : Opts)
|
|
||||||
if (char *NumberSignPtr = const_cast<char *>(::strchr(Opt, '#')))
|
|
||||||
*NumberSignPtr = '=';
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) {
|
|
||||||
// Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
|
|
||||||
TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
|
|
||||||
if (TheDriver.CCPrintOptions)
|
|
||||||
TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE");
|
|
||||||
|
|
||||||
// Handle CC_PRINT_HEADERS and CC_PRINT_HEADERS_FILE.
|
|
||||||
TheDriver.CCPrintHeaders = !!::getenv("CC_PRINT_HEADERS");
|
|
||||||
if (TheDriver.CCPrintHeaders)
|
|
||||||
TheDriver.CCPrintHeadersFilename = ::getenv("CC_PRINT_HEADERS_FILE");
|
|
||||||
|
|
||||||
// Handle CC_LOG_DIAGNOSTICS and CC_LOG_DIAGNOSTICS_FILE.
|
|
||||||
TheDriver.CCLogDiagnostics = !!::getenv("CC_LOG_DIAGNOSTICS");
|
|
||||||
if (TheDriver.CCLogDiagnostics)
|
|
||||||
TheDriver.CCLogDiagnosticsFilename = ::getenv("CC_LOG_DIAGNOSTICS_FILE");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
|
|
||||||
const std::string &Path) {
|
|
||||||
// If the clang binary happens to be named cl.exe for compatibility reasons,
|
|
||||||
// use clang-cl.exe as the prefix to avoid confusion between clang and MSVC.
|
|
||||||
StringRef ExeBasename(llvm::sys::path::filename(Path));
|
|
||||||
if (ExeBasename.equals_lower("cl.exe"))
|
|
||||||
ExeBasename = "clang-cl.exe";
|
|
||||||
DiagClient->setPrefix(ExeBasename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This lets us create the DiagnosticsEngine with a properly-filled-out
|
|
||||||
// DiagnosticOptions instance.
|
|
||||||
static DiagnosticOptions *
|
|
||||||
CreateAndPopulateDiagOpts(ArrayRef<const char *> argv) {
|
|
||||||
auto *DiagOpts = new DiagnosticOptions;
|
|
||||||
std::unique_ptr<OptTable> Opts(createDriverOptTable());
|
|
||||||
unsigned MissingArgIndex, MissingArgCount;
|
|
||||||
InputArgList Args =
|
|
||||||
Opts->ParseArgs(argv.slice(1), MissingArgIndex, MissingArgCount);
|
|
||||||
// We ignore MissingArgCount and the return value of ParseDiagnosticArgs.
|
|
||||||
// Any errors that would be diagnosed here will also be diagnosed later,
|
|
||||||
// when the DiagnosticsEngine actually exists.
|
|
||||||
(void)ParseDiagnosticArgs(*DiagOpts, Args);
|
|
||||||
return DiagOpts;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetInstallDir(SmallVectorImpl<const char *> &argv,
|
|
||||||
Driver &TheDriver, bool CanonicalPrefixes) {
|
|
||||||
// Attempt to find the original path used to invoke the driver, to determine
|
|
||||||
// the installed path. We do this manually, because we want to support that
|
|
||||||
// path being a symlink.
|
|
||||||
SmallString<128> InstalledPath(argv[0]);
|
|
||||||
|
|
||||||
// Do a PATH lookup, if there are no directory components.
|
|
||||||
if (llvm::sys::path::filename(InstalledPath) == InstalledPath)
|
|
||||||
if (llvm::ErrorOr<std::string> Tmp = llvm::sys::findProgramByName(
|
|
||||||
llvm::sys::path::filename(InstalledPath.str())))
|
|
||||||
InstalledPath = *Tmp;
|
|
||||||
|
|
||||||
// FIXME: We don't actually canonicalize this, we just make it absolute.
|
|
||||||
if (CanonicalPrefixes)
|
|
||||||
llvm::sys::fs::make_absolute(InstalledPath);
|
|
||||||
|
|
||||||
StringRef InstalledPathParent(llvm::sys::path::parent_path(InstalledPath));
|
|
||||||
if (llvm::sys::fs::exists(InstalledPathParent))
|
|
||||||
TheDriver.setInstalledDir(InstalledPathParent);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ExecuteCC1Tool(ArrayRef<const char *> argv, StringRef Tool) {
|
|
||||||
void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath;
|
|
||||||
if (Tool == "")
|
|
||||||
return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP);
|
|
||||||
if (Tool == "as")
|
|
||||||
return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
|
|
||||||
if (Tool == "gen-reproducer")
|
|
||||||
return cc1gen_reproducer_main(argv.slice(2), argv[0], GetExecutablePathVP);
|
|
||||||
|
|
||||||
// Reject unknown tools.
|
|
||||||
llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
|
|
||||||
<< "Valid tools include '-cc1' and '-cc1as'.\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mainEntryClickHouseClang(int argc_, /* const */ char **argv_) {
|
|
||||||
llvm::InitLLVM X(argc_, argv_);
|
|
||||||
SmallVector<const char *, 256> argv(argv_, argv_ + argc_);
|
|
||||||
|
|
||||||
if (llvm::sys::Process::FixupStandardFileDescriptors())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
llvm::InitializeAllTargets();
|
|
||||||
auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(argv[0]);
|
|
||||||
|
|
||||||
llvm::BumpPtrAllocator A;
|
|
||||||
llvm::StringSaver Saver(A);
|
|
||||||
|
|
||||||
// Parse response files using the GNU syntax, unless we're in CL mode. There
|
|
||||||
// are two ways to put clang in CL compatibility mode: argv[0] is either
|
|
||||||
// clang-cl or cl, or --driver-mode=cl is on the command line. The normal
|
|
||||||
// command line parsing can't happen until after response file parsing, so we
|
|
||||||
// have to manually search for a --driver-mode=cl argument the hard way.
|
|
||||||
// Finally, our -cc1 tools don't care which tokenization mode we use because
|
|
||||||
// response files written by clang will tokenize the same way in either mode.
|
|
||||||
bool ClangCLMode = false;
|
|
||||||
if (StringRef(TargetAndMode.DriverMode).equals("--driver-mode=cl") ||
|
|
||||||
std::find_if(argv.begin(), argv.end(), [](const char *F) {
|
|
||||||
return F && strcmp(F, "--driver-mode=cl") == 0;
|
|
||||||
}) != argv.end()) {
|
|
||||||
ClangCLMode = true;
|
|
||||||
}
|
|
||||||
enum { Default, POSIX, Windows } RSPQuoting = Default;
|
|
||||||
for (const char *F : argv) {
|
|
||||||
if (strcmp(F, "--rsp-quoting=posix") == 0)
|
|
||||||
RSPQuoting = POSIX;
|
|
||||||
else if (strcmp(F, "--rsp-quoting=windows") == 0)
|
|
||||||
RSPQuoting = Windows;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determines whether we want nullptr markers in argv to indicate response
|
|
||||||
// files end-of-lines. We only use this for the /LINK driver argument with
|
|
||||||
// clang-cl.exe on Windows.
|
|
||||||
bool MarkEOLs = ClangCLMode;
|
|
||||||
|
|
||||||
llvm::cl::TokenizerCallback Tokenizer;
|
|
||||||
if (RSPQuoting == Windows || (RSPQuoting == Default && ClangCLMode))
|
|
||||||
Tokenizer = &llvm::cl::TokenizeWindowsCommandLine;
|
|
||||||
else
|
|
||||||
Tokenizer = &llvm::cl::TokenizeGNUCommandLine;
|
|
||||||
|
|
||||||
if (MarkEOLs && argv.size() > 1 && StringRef(argv[1]).startswith("-cc1"))
|
|
||||||
MarkEOLs = false;
|
|
||||||
llvm::cl::ExpandResponseFiles(Saver, Tokenizer, argv, MarkEOLs);
|
|
||||||
|
|
||||||
// Handle -cc1 integrated tools, even if -cc1 was expanded from a response
|
|
||||||
// file.
|
|
||||||
auto FirstArg = std::find_if(argv.begin() + 1, argv.end(),
|
|
||||||
[](const char *A) { return A != nullptr; });
|
|
||||||
if (FirstArg != argv.end() && StringRef(*FirstArg).startswith("-cc1")) {
|
|
||||||
// If -cc1 came from a response file, remove the EOL sentinels.
|
|
||||||
if (MarkEOLs) {
|
|
||||||
auto newEnd = std::remove(argv.begin(), argv.end(), nullptr);
|
|
||||||
argv.resize(newEnd - argv.begin());
|
|
||||||
}
|
|
||||||
return ExecuteCC1Tool(argv, argv[1] + 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CanonicalPrefixes = true;
|
|
||||||
for (int i = 1, size = argv.size(); i < size; ++i) {
|
|
||||||
// Skip end-of-line response file markers
|
|
||||||
if (argv[i] == nullptr)
|
|
||||||
continue;
|
|
||||||
if (StringRef(argv[i]) == "-no-canonical-prefixes") {
|
|
||||||
CanonicalPrefixes = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle CL and _CL_ which permits additional command line options to be
|
|
||||||
// prepended or appended.
|
|
||||||
if (ClangCLMode) {
|
|
||||||
// Arguments in "CL" are prepended.
|
|
||||||
llvm::Optional<std::string> OptCL = llvm::sys::Process::GetEnv("CL");
|
|
||||||
if (OptCL.hasValue()) {
|
|
||||||
SmallVector<const char *, 8> PrependedOpts;
|
|
||||||
getCLEnvVarOptions(OptCL.getValue(), Saver, PrependedOpts);
|
|
||||||
|
|
||||||
// Insert right after the program name to prepend to the argument list.
|
|
||||||
argv.insert(argv.begin() + 1, PrependedOpts.begin(), PrependedOpts.end());
|
|
||||||
}
|
|
||||||
// Arguments in "_CL_" are appended.
|
|
||||||
llvm::Optional<std::string> Opt_CL_ = llvm::sys::Process::GetEnv("_CL_");
|
|
||||||
if (Opt_CL_.hasValue()) {
|
|
||||||
SmallVector<const char *, 8> AppendedOpts;
|
|
||||||
getCLEnvVarOptions(Opt_CL_.getValue(), Saver, AppendedOpts);
|
|
||||||
|
|
||||||
// Insert at the end of the argument list to append.
|
|
||||||
argv.append(AppendedOpts.begin(), AppendedOpts.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<std::string> SavedStrings;
|
|
||||||
// Handle CCC_OVERRIDE_OPTIONS, used for editing a command line behind the
|
|
||||||
// scenes.
|
|
||||||
if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
|
|
||||||
// FIXME: Driver shouldn't take extra initial argument.
|
|
||||||
ApplyQAOverride(argv, OverrideStr, SavedStrings);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Path = GetExecutablePath(argv[0], CanonicalPrefixes);
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
|
|
||||||
CreateAndPopulateDiagOpts(argv);
|
|
||||||
|
|
||||||
TextDiagnosticPrinter *DiagClient
|
|
||||||
= new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
|
|
||||||
FixupDiagPrefixExeName(DiagClient, Path);
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
|
||||||
|
|
||||||
if (!DiagOpts->DiagnosticSerializationFile.empty()) {
|
|
||||||
auto SerializedConsumer =
|
|
||||||
clang::serialized_diags::create(DiagOpts->DiagnosticSerializationFile,
|
|
||||||
&*DiagOpts, /*MergeChildRecords=*/true);
|
|
||||||
Diags.setClient(new ChainedDiagnosticConsumer(
|
|
||||||
Diags.takeClient(), std::move(SerializedConsumer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
|
|
||||||
|
|
||||||
Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
|
|
||||||
SetInstallDir(argv, TheDriver, CanonicalPrefixes);
|
|
||||||
TheDriver.setTargetAndMode(TargetAndMode);
|
|
||||||
|
|
||||||
insertTargetAndModeArgs(TargetAndMode, argv, SavedStrings);
|
|
||||||
|
|
||||||
SetBackdoorDriverOutputsFromEnvVars(TheDriver);
|
|
||||||
|
|
||||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(argv));
|
|
||||||
int Res = 1;
|
|
||||||
if (C && !C->containsError()) {
|
|
||||||
SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
|
|
||||||
Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
|
|
||||||
|
|
||||||
// Force a crash to test the diagnostics.
|
|
||||||
if (TheDriver.GenReproducer) {
|
|
||||||
Diags.Report(diag::err_drv_force_crash)
|
|
||||||
<< !::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH");
|
|
||||||
|
|
||||||
// Pretend that every command failed.
|
|
||||||
FailingCommands.clear();
|
|
||||||
for (const auto &J : C->getJobs())
|
|
||||||
if (const Command *C = dyn_cast<Command>(&J))
|
|
||||||
FailingCommands.push_back(std::make_pair(-1, C));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &P : FailingCommands) {
|
|
||||||
int CommandRes = P.first;
|
|
||||||
const Command *FailingCommand = P.second;
|
|
||||||
if (!Res)
|
|
||||||
Res = CommandRes;
|
|
||||||
|
|
||||||
// If result status is < 0, then the driver command signalled an error.
|
|
||||||
// If result status is 70, then the driver command reported a fatal error.
|
|
||||||
// On Windows, abort will return an exit code of 3. In these cases,
|
|
||||||
// generate additional diagnostic information if possible.
|
|
||||||
bool DiagnoseCrash = CommandRes < 0 || CommandRes == 70;
|
|
||||||
#ifdef _WIN32
|
|
||||||
DiagnoseCrash |= CommandRes == 3;
|
|
||||||
#endif
|
|
||||||
if (DiagnoseCrash) {
|
|
||||||
TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Diags.getClient()->finish();
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now. This happens in -disable-free mode.
|
|
||||||
llvm::TimerGroup::printAll(llvm::errs());
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
// Exit status should not be negative on Win32, unless abnormal termination.
|
|
||||||
// Once abnormal termiation was caught, negative status should not be
|
|
||||||
// propagated.
|
|
||||||
if (Res < 0)
|
|
||||||
Res = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// If we have multiple failing commands, we return the result of the first
|
|
||||||
// failing command.
|
|
||||||
return Res;
|
|
||||||
}
|
|
@ -1,150 +0,0 @@
|
|||||||
//===- tools/lld/lld.cpp - Linker Driver Dispatcher -----------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Linker
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This file contains the main function of the lld executable. The main
|
|
||||||
// function is a thin wrapper which dispatches to the platform specific
|
|
||||||
// driver.
|
|
||||||
//
|
|
||||||
// lld is a single executable that contains four different linkers for ELF,
|
|
||||||
// COFF, WebAssembly and Mach-O. The main function dispatches according to
|
|
||||||
// argv[0] (i.e. command name). The most common name for each target is shown
|
|
||||||
// below:
|
|
||||||
//
|
|
||||||
// - ld.lld: ELF (Unix)
|
|
||||||
// - ld64: Mach-O (macOS)
|
|
||||||
// - lld-link: COFF (Windows)
|
|
||||||
// - ld-wasm: WebAssembly
|
|
||||||
//
|
|
||||||
// lld can be invoked as "lld" along with "-flavor" option. This is for
|
|
||||||
// backward compatibility and not recommended.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "lld/Common/Driver.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
|
||||||
#include "llvm/ADT/Twine.h"
|
|
||||||
#include "llvm/Support/InitLLVM.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include <cstdlib>
|
|
||||||
using namespace lld;
|
|
||||||
using namespace llvm;
|
|
||||||
using namespace llvm::sys;
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
enum Flavor {
|
|
||||||
Invalid,
|
|
||||||
Gnu, // -flavor gnu
|
|
||||||
WinLink, // -flavor link
|
|
||||||
Darwin, // -flavor darwin
|
|
||||||
Wasm, // -flavor wasm
|
|
||||||
};
|
|
||||||
|
|
||||||
LLVM_ATTRIBUTE_NORETURN static void die(const Twine &S) {
|
|
||||||
errs() << S << "\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Flavor getFlavor(StringRef S) {
|
|
||||||
return StringSwitch<Flavor>(S)
|
|
||||||
.CasesLower("ld", "ld.lld", "gnu", Gnu)
|
|
||||||
.CasesLower("wasm", "ld-wasm", Wasm)
|
|
||||||
.CaseLower("link", WinLink)
|
|
||||||
.CasesLower("ld64", "ld64.lld", "darwin", Darwin)
|
|
||||||
.Default(Invalid);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isPETarget(const std::vector<const char *> &V) {
|
|
||||||
for (auto It = V.begin(); It + 1 != V.end(); ++It) {
|
|
||||||
if (StringRef(*It) != "-m")
|
|
||||||
continue;
|
|
||||||
StringRef S = *(It + 1);
|
|
||||||
return S == "i386pe" || S == "i386pep" || S == "thumb2pe" || S == "arm64pe";
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Flavor parseProgname(StringRef Progname) {
|
|
||||||
#if __APPLE__
|
|
||||||
// Use Darwin driver for "ld" on Darwin.
|
|
||||||
if (Progname == "ld")
|
|
||||||
return Darwin;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LLVM_ON_UNIX
|
|
||||||
// Use GNU driver for "ld" on other Unix-like system.
|
|
||||||
if (Progname == "ld")
|
|
||||||
return Gnu;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Progname may be something like "lld-gnu". Parse it.
|
|
||||||
SmallVector<StringRef, 3> V;
|
|
||||||
Progname.split(V, "-");
|
|
||||||
for (StringRef S : V)
|
|
||||||
if (Flavor F = getFlavor(S))
|
|
||||||
return F;
|
|
||||||
return Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Flavor parseFlavor(std::vector<const char *> &V) {
|
|
||||||
// Parse -flavor option.
|
|
||||||
if (V.size() > 1 && V[1] == StringRef("-flavor")) {
|
|
||||||
if (V.size() <= 2)
|
|
||||||
die("missing arg value for '-flavor'");
|
|
||||||
Flavor F = getFlavor(V[2]);
|
|
||||||
if (F == Invalid)
|
|
||||||
die("Unknown flavor: " + StringRef(V[2]));
|
|
||||||
V.erase(V.begin() + 1, V.begin() + 3);
|
|
||||||
return F;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deduct the flavor from argv[0].
|
|
||||||
StringRef Arg0 = path::filename(V[0]);
|
|
||||||
if (Arg0.endswith_lower(".exe"))
|
|
||||||
Arg0 = Arg0.drop_back(4);
|
|
||||||
return parseProgname(Arg0);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// If this function returns true, lld calls _exit() so that it quickly
|
|
||||||
// exits without invoking destructors of globally allocated objects.
|
|
||||||
//
|
|
||||||
// We don't want to do that if we are running tests though, because
|
|
||||||
// doing that breaks leak sanitizer. So, lit sets this environment variable,
|
|
||||||
// and we use it to detect whether we are running tests or not.
|
|
||||||
static bool canExitEarly() { return StringRef(getenv("LLD_IN_TEST")) != "1"; }
|
|
||||||
|
|
||||||
/// Universal linker main(). This linker emulates the gnu, darwin, or
|
|
||||||
/// windows linker based on the argv[0] or -flavor option.
|
|
||||||
int mainEntryClickHouseLLD(int Argc, /* const */ char **Argv) {
|
|
||||||
InitLLVM X(Argc, Argv);
|
|
||||||
|
|
||||||
std::vector<const char *> Args(Argv, Argv + Argc);
|
|
||||||
/*
|
|
||||||
switch (parseFlavor(Args)) {
|
|
||||||
case Gnu:
|
|
||||||
if (isPETarget(Args))
|
|
||||||
return !mingw::link(Args);
|
|
||||||
*/
|
|
||||||
return !elf::link(Args, canExitEarly());
|
|
||||||
/*
|
|
||||||
case WinLink:
|
|
||||||
return !coff::link(Args, canExitEarly());
|
|
||||||
case Darwin:
|
|
||||||
return !mach_o::link(Args, canExitEarly());
|
|
||||||
case Wasm:
|
|
||||||
return !wasm::link(Args, canExitEarly());
|
|
||||||
default:
|
|
||||||
die("lld is a generic driver.\n"
|
|
||||||
"Invoke ld.lld (Unix), ld64.lld (macOS), lld-link (Windows), wasm-lld"
|
|
||||||
" (WebAssembly) instead");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
add_definitions(-Wno-error -Wno-unused-parameter -Wno-non-virtual-dtor -U_LIBCPP_DEBUG)
|
|
||||||
|
|
||||||
link_directories(${LLVM_LIBRARY_DIRS})
|
|
||||||
|
|
||||||
add_library(clickhouse-compiler-lib
|
|
||||||
driver.cpp
|
|
||||||
cc1_main.cpp
|
|
||||||
cc1as_main.cpp
|
|
||||||
lld.cpp)
|
|
||||||
|
|
||||||
target_compile_options(clickhouse-compiler-lib PRIVATE -fno-rtti -fno-exceptions -g0)
|
|
||||||
|
|
||||||
string(REPLACE "${INCLUDE_DEBUG_HELPERS}" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # cant compile with -fno-rtti
|
|
||||||
|
|
||||||
llvm_libs_all(REQUIRED_LLVM_LIBRARIES)
|
|
||||||
|
|
||||||
message(STATUS "Using LLVM ${LLVM_VERSION}: ${LLVM_INCLUDE_DIRS} : ${REQUIRED_LLVM_LIBRARIES}")
|
|
||||||
|
|
||||||
target_include_directories(clickhouse-compiler-lib SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
# This is extracted almost directly from CMakeFiles/.../link.txt in LLVM build directory.
|
|
||||||
|
|
||||||
target_link_libraries(clickhouse-compiler-lib PRIVATE
|
|
||||||
|
|
||||||
clangBasic clangCodeGen clangDriver
|
|
||||||
clangFrontend
|
|
||||||
clangFrontendTool
|
|
||||||
clangRewriteFrontend clangARCMigrate clangStaticAnalyzerFrontend
|
|
||||||
clangParse clangSerialization clangSema clangEdit clangStaticAnalyzerCheckers
|
|
||||||
clangASTMatchers clangStaticAnalyzerCore clangAnalysis clangAST clangRewrite clangLex clangBasic
|
|
||||||
clangCrossTU clangIndex
|
|
||||||
|
|
||||||
lldCOFF
|
|
||||||
lldDriver
|
|
||||||
lldELF
|
|
||||||
lldMinGW
|
|
||||||
lldMachO
|
|
||||||
lldReaderWriter
|
|
||||||
lldYAML
|
|
||||||
lldCommon
|
|
||||||
lldCore
|
|
||||||
|
|
||||||
${REQUIRED_LLVM_LIBRARIES}
|
|
||||||
|
|
||||||
PUBLIC ${ZLIB_LIBRARIES} ${EXECINFO_LIBRARIES} Threads::Threads
|
|
||||||
${MALLOC_LIBRARIES}
|
|
||||||
${GLIBC_COMPATIBILITY_LIBRARIES}
|
|
||||||
${MEMCPY_LIBRARIES}
|
|
||||||
)
|
|
@ -1,243 +0,0 @@
|
|||||||
//===-- cc1_main.cpp - Clang CC1 Compiler Frontend ------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang -cc1 functionality, which implements the
|
|
||||||
// core compiler functionality along with a number of additional tools for
|
|
||||||
// demonstration and testing purposes.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "llvm/Option/Arg.h"
|
|
||||||
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
|
|
||||||
#include "clang/Config/config.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Frontend/CompilerInstance.h"
|
|
||||||
#include "clang/Frontend/CompilerInvocation.h"
|
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "clang/FrontendTool/Utils.h"
|
|
||||||
#include "llvm/ADT/Statistic.h"
|
|
||||||
#include "llvm/Config/llvm-config.h"
|
|
||||||
#include "llvm/LinkAllPasses.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Support/Compiler.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#ifdef CLANG_HAVE_RLIMITS
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// have no .a version in packages
|
|
||||||
#undef LINK_POLLY_INTO_TOOLS
|
|
||||||
|
|
||||||
using namespace clang;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// Main driver
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
static void LLVMErrorHandler(void *UserData, const std::string &Message,
|
|
||||||
bool GenCrashDiag) {
|
|
||||||
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
|
|
||||||
|
|
||||||
Diags.Report(diag::err_fe_error_backend) << Message;
|
|
||||||
|
|
||||||
// Run the interrupt handlers to make sure any special cleanups get done, in
|
|
||||||
// particular that we remove files registered with RemoveFileOnSignal.
|
|
||||||
llvm::sys::RunInterruptHandlers();
|
|
||||||
|
|
||||||
// We cannot recover from llvm errors. When reporting a fatal error, exit
|
|
||||||
// with status 70 to generate crash diagnostics. For BSD systems this is
|
|
||||||
// defined as an internal software error. Otherwise, exit with status 1.
|
|
||||||
exit(GenCrashDiag ? 70 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LINK_POLLY_INTO_TOOLS
|
|
||||||
namespace polly {
|
|
||||||
void initializePollyPasses(llvm::PassRegistry &Registry);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CLANG_HAVE_RLIMITS
|
|
||||||
// The amount of stack we think is "sufficient". If less than this much is
|
|
||||||
// available, we may be unable to reach our template instantiation depth
|
|
||||||
// limit and other similar limits.
|
|
||||||
// FIXME: Unify this with the stack we request when spawning a thread to build
|
|
||||||
// a module.
|
|
||||||
static const int kSufficientStack = 8 << 20;
|
|
||||||
|
|
||||||
#if defined(__linux__) && defined(__PIE__)
|
|
||||||
static size_t getCurrentStackAllocation() {
|
|
||||||
// If we can't compute the current stack usage, allow for 512K of command
|
|
||||||
// line arguments and environment.
|
|
||||||
size_t Usage = 512 * 1024;
|
|
||||||
if (FILE *StatFile = fopen("/proc/self/stat", "r")) {
|
|
||||||
// We assume that the stack extends from its current address to the end of
|
|
||||||
// the environment space. In reality, there is another string literal (the
|
|
||||||
// program name) after the environment, but this is close enough (we only
|
|
||||||
// need to be within 100K or so).
|
|
||||||
unsigned long StackPtr, EnvEnd;
|
|
||||||
// Disable silly GCC -Wformat warning that complains about length
|
|
||||||
// modifiers on ignored format specifiers. We want to retain these
|
|
||||||
// for documentation purposes even though they have no effect.
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wformat"
|
|
||||||
#endif
|
|
||||||
if (fscanf(StatFile,
|
|
||||||
"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %*lu "
|
|
||||||
"%*lu %*ld %*ld %*ld %*ld %*ld %*ld %*llu %*lu %*ld %*lu %*lu "
|
|
||||||
"%*lu %*lu %lu %*lu %*lu %*lu %*lu %*lu %*llu %*lu %*lu %*d %*d "
|
|
||||||
"%*u %*u %*llu %*lu %*ld %*lu %*lu %*lu %*lu %*lu %*lu %lu %*d",
|
|
||||||
&StackPtr, &EnvEnd) == 2) {
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
Usage = StackPtr < EnvEnd ? EnvEnd - StackPtr : StackPtr - EnvEnd;
|
|
||||||
}
|
|
||||||
fclose(StatFile);
|
|
||||||
}
|
|
||||||
return Usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <alloca.h>
|
|
||||||
|
|
||||||
LLVM_ATTRIBUTE_NOINLINE
|
|
||||||
static void ensureStackAddressSpace(int ExtraChunks = 0) {
|
|
||||||
// Linux kernels prior to 4.1 will sometimes locate the heap of a PIE binary
|
|
||||||
// relatively close to the stack (they are only guaranteed to be 128MiB
|
|
||||||
// apart). This results in crashes if we happen to heap-allocate more than
|
|
||||||
// 128MiB before we reach our stack high-water mark.
|
|
||||||
//
|
|
||||||
// To avoid these crashes, ensure that we have sufficient virtual memory
|
|
||||||
// pages allocated before we start running.
|
|
||||||
size_t Curr = getCurrentStackAllocation();
|
|
||||||
const int kTargetStack = kSufficientStack - 256 * 1024;
|
|
||||||
if (Curr < kTargetStack) {
|
|
||||||
volatile char *volatile Alloc =
|
|
||||||
static_cast<volatile char *>(alloca(kTargetStack - Curr));
|
|
||||||
Alloc[0] = 0;
|
|
||||||
Alloc[kTargetStack - Curr - 1] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static void ensureStackAddressSpace() {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Attempt to ensure that we have at least 8MiB of usable stack space.
|
|
||||||
static void ensureSufficientStack() {
|
|
||||||
struct rlimit rlim;
|
|
||||||
if (getrlimit(RLIMIT_STACK, &rlim) != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Increase the soft stack limit to our desired level, if necessary and
|
|
||||||
// possible.
|
|
||||||
if (rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur < kSufficientStack) {
|
|
||||||
// Try to allocate sufficient stack.
|
|
||||||
if (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_max >= kSufficientStack)
|
|
||||||
rlim.rlim_cur = kSufficientStack;
|
|
||||||
else if (rlim.rlim_cur == rlim.rlim_max)
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
rlim.rlim_cur = rlim.rlim_max;
|
|
||||||
|
|
||||||
if (setrlimit(RLIMIT_STACK, &rlim) != 0 ||
|
|
||||||
rlim.rlim_cur != kSufficientStack)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should now have a stack of size at least kSufficientStack. Ensure
|
|
||||||
// that we can actually use that much, if necessary.
|
|
||||||
ensureStackAddressSpace();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static void ensureSufficientStack() {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|
||||||
ensureSufficientStack();
|
|
||||||
|
|
||||||
std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
|
|
||||||
// Register the support for object-file-wrapped Clang modules.
|
|
||||||
auto PCHOps = Clang->getPCHContainerOperations();
|
|
||||||
PCHOps->registerWriter(llvm::make_unique<ObjectFilePCHContainerWriter>());
|
|
||||||
PCHOps->registerReader(llvm::make_unique<ObjectFilePCHContainerReader>());
|
|
||||||
|
|
||||||
// Initialize targets first, so that --version shows registered targets.
|
|
||||||
llvm::InitializeAllTargets();
|
|
||||||
llvm::InitializeAllTargetMCs();
|
|
||||||
llvm::InitializeAllAsmPrinters();
|
|
||||||
llvm::InitializeAllAsmParsers();
|
|
||||||
|
|
||||||
#ifdef LINK_POLLY_INTO_TOOLS
|
|
||||||
llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
|
|
||||||
polly::initializePollyPasses(Registry);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Buffer diagnostics from argument parsing so that we can output them using a
|
|
||||||
// well formed diagnostic object.
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
|
||||||
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
|
|
||||||
bool Success = CompilerInvocation::CreateFromArgs(
|
|
||||||
Clang->getInvocation(), Argv.begin(), Argv.end(), Diags);
|
|
||||||
|
|
||||||
// Infer the builtin include path if unspecified.
|
|
||||||
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
|
|
||||||
Clang->getHeaderSearchOpts().ResourceDir.empty())
|
|
||||||
Clang->getHeaderSearchOpts().ResourceDir =
|
|
||||||
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
|
|
||||||
|
|
||||||
// Create the actual diagnostics engine.
|
|
||||||
Clang->createDiagnostics();
|
|
||||||
if (!Clang->hasDiagnostics())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
|
||||||
// error handler.
|
|
||||||
llvm::install_fatal_error_handler(LLVMErrorHandler,
|
|
||||||
static_cast<void*>(&Clang->getDiagnostics()));
|
|
||||||
|
|
||||||
DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
|
|
||||||
if (!Success)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Execute the frontend actions.
|
|
||||||
Success = ExecuteCompilerInvocation(Clang.get());
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now. This happens in -disable-free mode.
|
|
||||||
llvm::TimerGroup::printAll(llvm::errs());
|
|
||||||
|
|
||||||
// Our error handler depends on the Diagnostics object, which we're
|
|
||||||
// potentially about to delete. Uninstall the handler now so that any
|
|
||||||
// later errors use the default handling behavior instead.
|
|
||||||
llvm::remove_fatal_error_handler();
|
|
||||||
|
|
||||||
// When running with -disable-free, don't do any destruction or shutdown.
|
|
||||||
if (Clang->getFrontendOpts().DisableFree) {
|
|
||||||
BuryPointer(std::move(Clang));
|
|
||||||
return !Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !Success;
|
|
||||||
}
|
|
@ -1,555 +0,0 @@
|
|||||||
//===-- cc1as_main.cpp - Clang Assembler ---------------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang -cc1as functionality, which implements
|
|
||||||
// the direct interface to the LLVM MC based assembler.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "clang/Basic/Diagnostic.h"
|
|
||||||
#include "clang/Basic/DiagnosticOptions.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
|
||||||
#include "llvm/ADT/Triple.h"
|
|
||||||
#include "llvm/IR/DataLayout.h"
|
|
||||||
#include "llvm/MC/MCAsmBackend.h"
|
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
|
||||||
#include "llvm/MC/MCCodeEmitter.h"
|
|
||||||
#include "llvm/MC/MCContext.h"
|
|
||||||
#include "llvm/MC/MCInstrInfo.h"
|
|
||||||
#include "llvm/MC/MCObjectFileInfo.h"
|
|
||||||
#include "llvm/MC/MCParser/MCAsmParser.h"
|
|
||||||
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
|
|
||||||
#include "llvm/MC/MCRegisterInfo.h"
|
|
||||||
#include "llvm/MC/MCStreamer.h"
|
|
||||||
#include "llvm/MC/MCSubtargetInfo.h"
|
|
||||||
#include "llvm/MC/MCTargetOptions.h"
|
|
||||||
#include "llvm/Option/Arg.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
|
||||||
#include "llvm/Support/FormattedStream.h"
|
|
||||||
#include "llvm/Support/Host.h"
|
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/SourceMgr.h"
|
|
||||||
#include "llvm/Support/TargetRegistry.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <system_error>
|
|
||||||
using namespace clang;
|
|
||||||
using namespace clang::driver;
|
|
||||||
using namespace clang::driver::options;
|
|
||||||
using namespace llvm;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
/// \brief Helper class for representing a single invocation of the assembler.
|
|
||||||
struct AssemblerInvocation {
|
|
||||||
/// @name Target Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/// The name of the target triple to assemble for.
|
|
||||||
std::string Triple;
|
|
||||||
|
|
||||||
/// If given, the name of the target CPU to determine which instructions
|
|
||||||
/// are legal.
|
|
||||||
std::string CPU;
|
|
||||||
|
|
||||||
/// The list of target specific features to enable or disable -- this should
|
|
||||||
/// be a list of strings starting with '+' or '-'.
|
|
||||||
std::vector<std::string> Features;
|
|
||||||
|
|
||||||
/// The list of symbol definitions.
|
|
||||||
std::vector<std::string> SymbolDefs;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Language Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
std::vector<std::string> IncludePaths;
|
|
||||||
unsigned NoInitialTextSection : 1;
|
|
||||||
unsigned SaveTemporaryLabels : 1;
|
|
||||||
unsigned GenDwarfForAssembly : 1;
|
|
||||||
unsigned RelaxELFRelocations : 1;
|
|
||||||
unsigned DwarfVersion;
|
|
||||||
std::string DwarfDebugFlags;
|
|
||||||
std::string DwarfDebugProducer;
|
|
||||||
std::string DebugCompilationDir;
|
|
||||||
llvm::DebugCompressionType CompressDebugSections =
|
|
||||||
llvm::DebugCompressionType::None;
|
|
||||||
std::string MainFileName;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Frontend Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
std::string InputFile;
|
|
||||||
std::vector<std::string> LLVMArgs;
|
|
||||||
std::string OutputPath;
|
|
||||||
enum FileType {
|
|
||||||
FT_Asm, ///< Assembly (.s) output, transliterate mode.
|
|
||||||
FT_Null, ///< No output, for timing purposes.
|
|
||||||
FT_Obj ///< Object file output.
|
|
||||||
};
|
|
||||||
FileType OutputType;
|
|
||||||
unsigned ShowHelp : 1;
|
|
||||||
unsigned ShowVersion : 1;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Transliterate Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
unsigned OutputAsmVariant;
|
|
||||||
unsigned ShowEncoding : 1;
|
|
||||||
unsigned ShowInst : 1;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
/// @name Assembler Options
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
unsigned RelaxAll : 1;
|
|
||||||
unsigned NoExecStack : 1;
|
|
||||||
unsigned FatalWarnings : 1;
|
|
||||||
unsigned IncrementalLinkerCompatible : 1;
|
|
||||||
|
|
||||||
/// The name of the relocation model to use.
|
|
||||||
std::string RelocationModel;
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
public:
|
|
||||||
AssemblerInvocation() {
|
|
||||||
Triple = "";
|
|
||||||
NoInitialTextSection = 0;
|
|
||||||
InputFile = "-";
|
|
||||||
OutputPath = "-";
|
|
||||||
OutputType = FT_Asm;
|
|
||||||
OutputAsmVariant = 0;
|
|
||||||
ShowInst = 0;
|
|
||||||
ShowEncoding = 0;
|
|
||||||
RelaxAll = 0;
|
|
||||||
NoExecStack = 0;
|
|
||||||
FatalWarnings = 0;
|
|
||||||
IncrementalLinkerCompatible = 0;
|
|
||||||
DwarfVersion = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool CreateFromArgs(AssemblerInvocation &Res,
|
|
||||||
ArrayRef<const char *> Argv,
|
|
||||||
DiagnosticsEngine &Diags);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
|
|
||||||
ArrayRef<const char *> Argv,
|
|
||||||
DiagnosticsEngine &Diags) {
|
|
||||||
bool Success = true;
|
|
||||||
|
|
||||||
// Parse the arguments.
|
|
||||||
std::unique_ptr<OptTable> OptTbl(createDriverOptTable());
|
|
||||||
|
|
||||||
const unsigned IncludedFlagsBitmask = options::CC1AsOption;
|
|
||||||
unsigned MissingArgIndex, MissingArgCount;
|
|
||||||
InputArgList Args = OptTbl->ParseArgs(Argv, MissingArgIndex, MissingArgCount,
|
|
||||||
IncludedFlagsBitmask);
|
|
||||||
|
|
||||||
// Check for missing argument error.
|
|
||||||
if (MissingArgCount) {
|
|
||||||
Diags.Report(diag::err_drv_missing_argument)
|
|
||||||
<< Args.getArgString(MissingArgIndex) << MissingArgCount;
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Issue errors on unknown arguments.
|
|
||||||
for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
|
|
||||||
auto ArgString = A->getAsString(Args);
|
|
||||||
std::string Nearest;
|
|
||||||
if (OptTbl->findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument) << ArgString;
|
|
||||||
else
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
|
|
||||||
<< ArgString << Nearest;
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct the invocation.
|
|
||||||
|
|
||||||
// Target Options
|
|
||||||
Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
|
|
||||||
Opts.CPU = Args.getLastArgValue(OPT_target_cpu);
|
|
||||||
Opts.Features = Args.getAllArgValues(OPT_target_feature);
|
|
||||||
|
|
||||||
// Use the default target triple if unspecified.
|
|
||||||
if (Opts.Triple.empty())
|
|
||||||
Opts.Triple = llvm::sys::getDefaultTargetTriple();
|
|
||||||
|
|
||||||
// Language Options
|
|
||||||
Opts.IncludePaths = Args.getAllArgValues(OPT_I);
|
|
||||||
Opts.NoInitialTextSection = Args.hasArg(OPT_n);
|
|
||||||
Opts.SaveTemporaryLabels = Args.hasArg(OPT_msave_temp_labels);
|
|
||||||
// Any DebugInfoKind implies GenDwarfForAssembly.
|
|
||||||
Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ);
|
|
||||||
|
|
||||||
if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections,
|
|
||||||
OPT_compress_debug_sections_EQ)) {
|
|
||||||
if (A->getOption().getID() == OPT_compress_debug_sections) {
|
|
||||||
// TODO: be more clever about the compression type auto-detection
|
|
||||||
Opts.CompressDebugSections = llvm::DebugCompressionType::GNU;
|
|
||||||
} else {
|
|
||||||
Opts.CompressDebugSections =
|
|
||||||
llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue())
|
|
||||||
.Case("none", llvm::DebugCompressionType::None)
|
|
||||||
.Case("zlib", llvm::DebugCompressionType::Z)
|
|
||||||
.Case("zlib-gnu", llvm::DebugCompressionType::GNU)
|
|
||||||
.Default(llvm::DebugCompressionType::None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
|
|
||||||
Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
|
|
||||||
Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
|
|
||||||
Opts.DwarfDebugProducer = Args.getLastArgValue(OPT_dwarf_debug_producer);
|
|
||||||
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
|
|
||||||
Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
|
|
||||||
|
|
||||||
// Frontend Options
|
|
||||||
if (Args.hasArg(OPT_INPUT)) {
|
|
||||||
bool First = true;
|
|
||||||
for (const Arg *A : Args.filtered(OPT_INPUT)) {
|
|
||||||
if (First) {
|
|
||||||
Opts.InputFile = A->getValue();
|
|
||||||
First = false;
|
|
||||||
} else {
|
|
||||||
Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
|
|
||||||
Success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
|
|
||||||
Opts.OutputPath = Args.getLastArgValue(OPT_o);
|
|
||||||
if (Arg *A = Args.getLastArg(OPT_filetype)) {
|
|
||||||
StringRef Name = A->getValue();
|
|
||||||
unsigned OutputType = StringSwitch<unsigned>(Name)
|
|
||||||
.Case("asm", FT_Asm)
|
|
||||||
.Case("null", FT_Null)
|
|
||||||
.Case("obj", FT_Obj)
|
|
||||||
.Default(~0U);
|
|
||||||
if (OutputType == ~0U) {
|
|
||||||
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
|
|
||||||
Success = false;
|
|
||||||
} else
|
|
||||||
Opts.OutputType = FileType(OutputType);
|
|
||||||
}
|
|
||||||
Opts.ShowHelp = Args.hasArg(OPT_help);
|
|
||||||
Opts.ShowVersion = Args.hasArg(OPT_version);
|
|
||||||
|
|
||||||
// Transliterate Options
|
|
||||||
Opts.OutputAsmVariant =
|
|
||||||
getLastArgIntValue(Args, OPT_output_asm_variant, 0, Diags);
|
|
||||||
Opts.ShowEncoding = Args.hasArg(OPT_show_encoding);
|
|
||||||
Opts.ShowInst = Args.hasArg(OPT_show_inst);
|
|
||||||
|
|
||||||
// Assemble Options
|
|
||||||
Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
|
|
||||||
Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
|
|
||||||
Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
|
|
||||||
Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
|
|
||||||
Opts.IncrementalLinkerCompatible =
|
|
||||||
Args.hasArg(OPT_mincremental_linker_compatible);
|
|
||||||
Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::unique_ptr<raw_fd_ostream>
|
|
||||||
getOutputStream(AssemblerInvocation &Opts, DiagnosticsEngine &Diags,
|
|
||||||
bool Binary) {
|
|
||||||
if (Opts.OutputPath.empty())
|
|
||||||
Opts.OutputPath = "-";
|
|
||||||
|
|
||||||
// Make sure that the Out file gets unlinked from the disk if we get a
|
|
||||||
// SIGINT.
|
|
||||||
if (Opts.OutputPath != "-")
|
|
||||||
sys::RemoveFileOnSignal(Opts.OutputPath);
|
|
||||||
|
|
||||||
std::error_code EC;
|
|
||||||
auto Out = llvm::make_unique<raw_fd_ostream>(
|
|
||||||
Opts.OutputPath, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text));
|
|
||||||
if (EC) {
|
|
||||||
Diags.Report(diag::err_fe_unable_to_open_output) << Opts.OutputPath
|
|
||||||
<< EC.message();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Out;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ExecuteAssembler(AssemblerInvocation &Opts,
|
|
||||||
DiagnosticsEngine &Diags) {
|
|
||||||
// Get the target specific parser.
|
|
||||||
std::string Error;
|
|
||||||
const Target *TheTarget = TargetRegistry::lookupTarget(Opts.Triple, Error);
|
|
||||||
if (!TheTarget)
|
|
||||||
return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
|
|
||||||
|
|
||||||
ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
|
|
||||||
MemoryBuffer::getFileOrSTDIN(Opts.InputFile);
|
|
||||||
|
|
||||||
if (std::error_code EC = Buffer.getError()) {
|
|
||||||
Error = EC.message();
|
|
||||||
return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
SourceMgr SrcMgr;
|
|
||||||
|
|
||||||
// Tell SrcMgr about this buffer, which is what the parser will pick up.
|
|
||||||
SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc());
|
|
||||||
|
|
||||||
// Record the location of the include directories so that the lexer can find
|
|
||||||
// it later.
|
|
||||||
SrcMgr.setIncludeDirs(Opts.IncludePaths);
|
|
||||||
|
|
||||||
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(Opts.Triple));
|
|
||||||
assert(MRI && "Unable to create target register info!");
|
|
||||||
|
|
||||||
std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, Opts.Triple));
|
|
||||||
assert(MAI && "Unable to create target asm info!");
|
|
||||||
|
|
||||||
// Ensure MCAsmInfo initialization occurs before any use, otherwise sections
|
|
||||||
// may be created with a combination of default and explicit settings.
|
|
||||||
MAI->setCompressDebugSections(Opts.CompressDebugSections);
|
|
||||||
|
|
||||||
MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations);
|
|
||||||
|
|
||||||
bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj;
|
|
||||||
std::unique_ptr<raw_fd_ostream> FDOS = getOutputStream(Opts, Diags, IsBinary);
|
|
||||||
if (!FDOS)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
|
|
||||||
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
|
|
||||||
std::unique_ptr<MCObjectFileInfo> MOFI(new MCObjectFileInfo());
|
|
||||||
|
|
||||||
MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr);
|
|
||||||
|
|
||||||
bool PIC = false;
|
|
||||||
if (Opts.RelocationModel == "static") {
|
|
||||||
PIC = false;
|
|
||||||
} else if (Opts.RelocationModel == "pic") {
|
|
||||||
PIC = true;
|
|
||||||
} else {
|
|
||||||
assert(Opts.RelocationModel == "dynamic-no-pic" &&
|
|
||||||
"Invalid PIC model!");
|
|
||||||
PIC = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), PIC, Ctx);
|
|
||||||
if (Opts.SaveTemporaryLabels)
|
|
||||||
Ctx.setAllowTemporaryLabels(false);
|
|
||||||
if (Opts.GenDwarfForAssembly)
|
|
||||||
Ctx.setGenDwarfForAssembly(true);
|
|
||||||
if (!Opts.DwarfDebugFlags.empty())
|
|
||||||
Ctx.setDwarfDebugFlags(StringRef(Opts.DwarfDebugFlags));
|
|
||||||
if (!Opts.DwarfDebugProducer.empty())
|
|
||||||
Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
|
|
||||||
if (!Opts.DebugCompilationDir.empty())
|
|
||||||
Ctx.setCompilationDir(Opts.DebugCompilationDir);
|
|
||||||
if (!Opts.MainFileName.empty())
|
|
||||||
Ctx.setMainFileName(StringRef(Opts.MainFileName));
|
|
||||||
Ctx.setDwarfVersion(Opts.DwarfVersion);
|
|
||||||
|
|
||||||
// Build up the feature string from the target feature list.
|
|
||||||
std::string FS;
|
|
||||||
if (!Opts.Features.empty()) {
|
|
||||||
FS = Opts.Features[0];
|
|
||||||
for (unsigned i = 1, e = Opts.Features.size(); i != e; ++i)
|
|
||||||
FS += "," + Opts.Features[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<MCStreamer> Str;
|
|
||||||
|
|
||||||
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
|
|
||||||
std::unique_ptr<MCSubtargetInfo> STI(
|
|
||||||
TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS));
|
|
||||||
|
|
||||||
raw_pwrite_stream *Out = FDOS.get();
|
|
||||||
std::unique_ptr<buffer_ostream> BOS;
|
|
||||||
|
|
||||||
// FIXME: There is a bit of code duplication with addPassesToEmitFile.
|
|
||||||
if (Opts.OutputType == AssemblerInvocation::FT_Asm) {
|
|
||||||
MCInstPrinter *IP = TheTarget->createMCInstPrinter(
|
|
||||||
llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI);
|
|
||||||
|
|
||||||
std::unique_ptr<MCCodeEmitter> CE;
|
|
||||||
if (Opts.ShowEncoding)
|
|
||||||
CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
|
|
||||||
MCTargetOptions MCOptions;
|
|
||||||
std::unique_ptr<MCAsmBackend> MAB(
|
|
||||||
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
|
|
||||||
|
|
||||||
auto FOut = llvm::make_unique<formatted_raw_ostream>(*Out);
|
|
||||||
Str.reset(TheTarget->createAsmStreamer(
|
|
||||||
Ctx, std::move(FOut), /*asmverbose*/ true,
|
|
||||||
/*useDwarfDirectory*/ true, IP, std::move(CE), std::move(MAB),
|
|
||||||
Opts.ShowInst));
|
|
||||||
} else if (Opts.OutputType == AssemblerInvocation::FT_Null) {
|
|
||||||
Str.reset(createNullStreamer(Ctx));
|
|
||||||
} else {
|
|
||||||
assert(Opts.OutputType == AssemblerInvocation::FT_Obj &&
|
|
||||||
"Invalid file type!");
|
|
||||||
if (!FDOS->supportsSeeking()) {
|
|
||||||
BOS = make_unique<buffer_ostream>(*FDOS);
|
|
||||||
Out = BOS.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<MCCodeEmitter> CE(
|
|
||||||
TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
|
|
||||||
MCTargetOptions MCOptions;
|
|
||||||
std::unique_ptr<MCAsmBackend> MAB(
|
|
||||||
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
|
|
||||||
|
|
||||||
Triple T(Opts.Triple);
|
|
||||||
Str.reset(TheTarget->createMCObjectStreamer(
|
|
||||||
T, Ctx, std::move(MAB), *Out, std::move(CE), *STI, Opts.RelaxAll,
|
|
||||||
Opts.IncrementalLinkerCompatible,
|
|
||||||
/*DWARFMustBeAtTheEnd*/ true));
|
|
||||||
Str.get()->InitSections(Opts.NoExecStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assembly to object compilation should leverage assembly info.
|
|
||||||
Str->setUseAssemblerInfoForParsing(true);
|
|
||||||
|
|
||||||
bool Failed = false;
|
|
||||||
|
|
||||||
std::unique_ptr<MCAsmParser> Parser(
|
|
||||||
createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI));
|
|
||||||
|
|
||||||
// FIXME: init MCTargetOptions from sanitizer flags here.
|
|
||||||
MCTargetOptions Options;
|
|
||||||
std::unique_ptr<MCTargetAsmParser> TAP(
|
|
||||||
TheTarget->createMCAsmParser(*STI, *Parser, *MCII, Options));
|
|
||||||
if (!TAP)
|
|
||||||
Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
|
|
||||||
|
|
||||||
// Set values for symbols, if any.
|
|
||||||
for (auto &S : Opts.SymbolDefs) {
|
|
||||||
auto Pair = StringRef(S).split('=');
|
|
||||||
auto Sym = Pair.first;
|
|
||||||
auto Val = Pair.second;
|
|
||||||
int64_t Value;
|
|
||||||
// We have already error checked this in the driver.
|
|
||||||
Val.getAsInteger(0, Value);
|
|
||||||
Ctx.setSymbolValue(Parser->getStreamer(), Sym, Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Failed) {
|
|
||||||
Parser->setTargetParser(*TAP.get());
|
|
||||||
Failed = Parser->Run(Opts.NoInitialTextSection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close Streamer first.
|
|
||||||
// It might have a reference to the output stream.
|
|
||||||
Str.reset();
|
|
||||||
// Close the output stream early.
|
|
||||||
BOS.reset();
|
|
||||||
FDOS.reset();
|
|
||||||
|
|
||||||
// Delete output file if there were errors.
|
|
||||||
if (Failed && Opts.OutputPath != "-")
|
|
||||||
sys::fs::remove(Opts.OutputPath);
|
|
||||||
|
|
||||||
return Failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void LLVMErrorHandler(void *UserData, const std::string &Message,
|
|
||||||
bool /*GenCrashDiag*/) {
|
|
||||||
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
|
|
||||||
|
|
||||||
Diags.Report(diag::err_fe_error_backend) << Message;
|
|
||||||
|
|
||||||
// We cannot recover from llvm errors.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int cc1as_main(ArrayRef<const char *> Argv, const char */*Argv0*/, void */*MainAddr*/) {
|
|
||||||
// Initialize targets and assembly printers/parsers.
|
|
||||||
InitializeAllTargetInfos();
|
|
||||||
InitializeAllTargetMCs();
|
|
||||||
InitializeAllAsmParsers();
|
|
||||||
|
|
||||||
// Construct our diagnostic client.
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
|
||||||
TextDiagnosticPrinter *DiagClient
|
|
||||||
= new TextDiagnosticPrinter(errs(), &*DiagOpts);
|
|
||||||
DiagClient->setPrefix("clang -cc1as");
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
|
||||||
|
|
||||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
|
||||||
// error handler.
|
|
||||||
ScopedFatalErrorHandler FatalErrorHandler
|
|
||||||
(LLVMErrorHandler, static_cast<void*>(&Diags));
|
|
||||||
|
|
||||||
// Parse the arguments.
|
|
||||||
AssemblerInvocation Asm;
|
|
||||||
if (!AssemblerInvocation::CreateFromArgs(Asm, Argv, Diags))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (Asm.ShowHelp) {
|
|
||||||
std::unique_ptr<OptTable> Opts(driver::createDriverOptTable());
|
|
||||||
Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
|
|
||||||
/*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
|
|
||||||
/*ShowAllAliases=*/false);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Honor -version.
|
|
||||||
//
|
|
||||||
// FIXME: Use a better -version message?
|
|
||||||
if (Asm.ShowVersion) {
|
|
||||||
llvm::cl::PrintVersionMessage();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Honor -mllvm.
|
|
||||||
//
|
|
||||||
// FIXME: Remove this, one day.
|
|
||||||
if (!Asm.LLVMArgs.empty()) {
|
|
||||||
unsigned NumArgs = Asm.LLVMArgs.size();
|
|
||||||
auto Args = llvm::make_unique<const char*[]>(NumArgs + 2);
|
|
||||||
Args[0] = "clang (LLVM option parsing)";
|
|
||||||
for (unsigned i = 0; i != NumArgs; ++i)
|
|
||||||
Args[i + 1] = Asm.LLVMArgs[i].c_str();
|
|
||||||
Args[NumArgs + 1] = nullptr;
|
|
||||||
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the invocation, unless there were parsing errors.
|
|
||||||
bool Failed = Diags.hasErrorOccurred() || ExecuteAssembler(Asm, Diags);
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now.
|
|
||||||
TimerGroup::printAll(errs());
|
|
||||||
|
|
||||||
return !!Failed;
|
|
||||||
}
|
|
@ -1,512 +0,0 @@
|
|||||||
//===-- driver.cpp - Clang GCC-Compatible Driver --------------------------===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This is the entry point to the clang driver; it is a thin wrapper
|
|
||||||
// for functionality in the Driver clang library.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "clang/Driver/Driver.h"
|
|
||||||
#include "clang/Basic/DiagnosticOptions.h"
|
|
||||||
#include "clang/Driver/Compilation.h"
|
|
||||||
#include "clang/Driver/DriverDiagnostic.h"
|
|
||||||
#include "clang/Driver/Options.h"
|
|
||||||
#include "clang/Driver/ToolChain.h"
|
|
||||||
#include "clang/Frontend/ChainedDiagnosticConsumer.h"
|
|
||||||
#include "clang/Frontend/CompilerInvocation.h"
|
|
||||||
#include "clang/Frontend/SerializedDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
|
||||||
#include "clang/Frontend/Utils.h"
|
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
|
||||||
#include "llvm/ADT/SmallString.h"
|
|
||||||
#include "llvm/ADT/SmallVector.h"
|
|
||||||
#include "llvm/Option/ArgList.h"
|
|
||||||
#include "llvm/Option/OptTable.h"
|
|
||||||
#include "llvm/Option/Option.h"
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Support/FileSystem.h"
|
|
||||||
#include "llvm/Support/Host.h"
|
|
||||||
#include "llvm/Support/InitLLVM.h"
|
|
||||||
#include "llvm/Support/Path.h"
|
|
||||||
#include "llvm/Support/Process.h"
|
|
||||||
#include "llvm/Support/Program.h"
|
|
||||||
#include "llvm/Support/Regex.h"
|
|
||||||
#include "llvm/Support/Signals.h"
|
|
||||||
#include "llvm/Support/StringSaver.h"
|
|
||||||
#include "llvm/Support/TargetSelect.h"
|
|
||||||
#include "llvm/Support/Timer.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <set>
|
|
||||||
#include <system_error>
|
|
||||||
using namespace clang;
|
|
||||||
using namespace clang::driver;
|
|
||||||
using namespace llvm::opt;
|
|
||||||
|
|
||||||
std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
|
|
||||||
if (!CanonicalPrefixes) {
|
|
||||||
SmallString<128> ExecutablePath(Argv0);
|
|
||||||
// Do a PATH lookup if Argv0 isn't a valid path.
|
|
||||||
if (!llvm::sys::fs::exists(ExecutablePath))
|
|
||||||
if (llvm::ErrorOr<std::string> P =
|
|
||||||
llvm::sys::findProgramByName(ExecutablePath))
|
|
||||||
ExecutablePath = *P;
|
|
||||||
return ExecutablePath.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This just needs to be some symbol in the binary; C++ doesn't
|
|
||||||
// allow taking the address of ::main however.
|
|
||||||
void *P = (void*) (intptr_t) GetExecutablePath;
|
|
||||||
return llvm::sys::fs::getMainExecutable(Argv0, P);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *GetStableCStr(std::set<std::string> &SavedStrings,
|
|
||||||
StringRef S) {
|
|
||||||
return SavedStrings.insert(S).first->c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ApplyQAOverride - Apply a list of edits to the input argument lists.
|
|
||||||
///
|
|
||||||
/// The input string is a space separate list of edits to perform,
|
|
||||||
/// they are applied in order to the input argument lists. Edits
|
|
||||||
/// should be one of the following forms:
|
|
||||||
///
|
|
||||||
/// '#': Silence information about the changes to the command line arguments.
|
|
||||||
///
|
|
||||||
/// '^': Add FOO as a new argument at the beginning of the command line.
|
|
||||||
///
|
|
||||||
/// '+': Add FOO as a new argument at the end of the command line.
|
|
||||||
///
|
|
||||||
/// 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
|
|
||||||
/// line.
|
|
||||||
///
|
|
||||||
/// 'xOPTION': Removes all instances of the literal argument OPTION.
|
|
||||||
///
|
|
||||||
/// 'XOPTION': Removes all instances of the literal argument OPTION,
|
|
||||||
/// and the following argument.
|
|
||||||
///
|
|
||||||
/// 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
|
|
||||||
/// at the end of the command line.
|
|
||||||
///
|
|
||||||
/// \param OS - The stream to write edit information to.
|
|
||||||
/// \param Args - The vector of command line arguments.
|
|
||||||
/// \param Edit - The override command to perform.
|
|
||||||
/// \param SavedStrings - Set to use for storing string representations.
|
|
||||||
static void ApplyOneQAOverride(raw_ostream &OS,
|
|
||||||
SmallVectorImpl<const char*> &Args,
|
|
||||||
StringRef Edit,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
// This does not need to be efficient.
|
|
||||||
|
|
||||||
if (Edit[0] == '^') {
|
|
||||||
const char *Str =
|
|
||||||
GetStableCStr(SavedStrings, Edit.substr(1));
|
|
||||||
OS << "### Adding argument " << Str << " at beginning\n";
|
|
||||||
Args.insert(Args.begin() + 1, Str);
|
|
||||||
} else if (Edit[0] == '+') {
|
|
||||||
const char *Str =
|
|
||||||
GetStableCStr(SavedStrings, Edit.substr(1));
|
|
||||||
OS << "### Adding argument " << Str << " at end\n";
|
|
||||||
Args.push_back(Str);
|
|
||||||
} else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
|
|
||||||
Edit.slice(2, Edit.size()-1).find('/') != StringRef::npos) {
|
|
||||||
StringRef MatchPattern = Edit.substr(2).split('/').first;
|
|
||||||
StringRef ReplPattern = Edit.substr(2).split('/').second;
|
|
||||||
ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1);
|
|
||||||
|
|
||||||
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
|
|
||||||
// Ignore end-of-line response file markers
|
|
||||||
if (Args[i] == nullptr)
|
|
||||||
continue;
|
|
||||||
std::string Repl = llvm::Regex(MatchPattern).sub(ReplPattern, Args[i]);
|
|
||||||
|
|
||||||
if (Repl != Args[i]) {
|
|
||||||
OS << "### Replacing '" << Args[i] << "' with '" << Repl << "'\n";
|
|
||||||
Args[i] = GetStableCStr(SavedStrings, Repl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (Edit[0] == 'x' || Edit[0] == 'X') {
|
|
||||||
auto Option = Edit.substr(1);
|
|
||||||
for (unsigned i = 1; i < Args.size();) {
|
|
||||||
if (Option == Args[i]) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
if (Edit[0] == 'X') {
|
|
||||||
if (i < Args.size()) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
} else
|
|
||||||
OS << "### Invalid X edit, end of command line!\n";
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
} else if (Edit[0] == 'O') {
|
|
||||||
for (unsigned i = 1; i < Args.size();) {
|
|
||||||
const char *A = Args[i];
|
|
||||||
// Ignore end-of-line response file markers
|
|
||||||
if (A == nullptr)
|
|
||||||
continue;
|
|
||||||
if (A[0] == '-' && A[1] == 'O' &&
|
|
||||||
(A[2] == '\0' ||
|
|
||||||
(A[3] == '\0' && (A[2] == 's' || A[2] == 'z' ||
|
|
||||||
('0' <= A[2] && A[2] <= '9'))))) {
|
|
||||||
OS << "### Deleting argument " << Args[i] << '\n';
|
|
||||||
Args.erase(Args.begin() + i);
|
|
||||||
} else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
OS << "### Adding argument " << Edit << " at end\n";
|
|
||||||
Args.push_back(GetStableCStr(SavedStrings, '-' + Edit.str()));
|
|
||||||
} else {
|
|
||||||
OS << "### Unrecognized edit: " << Edit << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ApplyQAOverride - Apply a comma separate list of edits to the
|
|
||||||
/// input argument lists. See ApplyOneQAOverride.
|
|
||||||
static void ApplyQAOverride(SmallVectorImpl<const char*> &Args,
|
|
||||||
const char *OverrideStr,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
raw_ostream *OS = &llvm::errs();
|
|
||||||
|
|
||||||
if (OverrideStr[0] == '#') {
|
|
||||||
++OverrideStr;
|
|
||||||
OS = &llvm::nulls();
|
|
||||||
}
|
|
||||||
|
|
||||||
*OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
|
|
||||||
|
|
||||||
// This does not need to be efficient.
|
|
||||||
|
|
||||||
const char *S = OverrideStr;
|
|
||||||
while (*S) {
|
|
||||||
const char *End = ::strchr(S, ' ');
|
|
||||||
if (!End)
|
|
||||||
End = S + strlen(S);
|
|
||||||
if (End != S)
|
|
||||||
ApplyOneQAOverride(*OS, Args, std::string(S, End), SavedStrings);
|
|
||||||
S = End;
|
|
||||||
if (*S != '\0')
|
|
||||||
++S;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0,
|
|
||||||
void *MainAddr);
|
|
||||||
extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0,
|
|
||||||
void *MainAddr);
|
|
||||||
extern int cc1gen_reproducer_main(ArrayRef<const char *> Argv,
|
|
||||||
const char *Argv0, void *MainAddr);
|
|
||||||
|
|
||||||
static void insertTargetAndModeArgs(const ParsedClangName &NameParts,
|
|
||||||
SmallVectorImpl<const char *> &ArgVector,
|
|
||||||
std::set<std::string> &SavedStrings) {
|
|
||||||
// Put target and mode arguments at the start of argument list so that
|
|
||||||
// arguments specified in command line could override them. Avoid putting
|
|
||||||
// them at index 0, as an option like '-cc1' must remain the first.
|
|
||||||
int InsertionPoint = 0;
|
|
||||||
if (ArgVector.size() > 0)
|
|
||||||
++InsertionPoint;
|
|
||||||
|
|
||||||
if (NameParts.DriverMode) {
|
|
||||||
// Add the mode flag to the arguments.
|
|
||||||
ArgVector.insert(ArgVector.begin() + InsertionPoint,
|
|
||||||
GetStableCStr(SavedStrings, NameParts.DriverMode));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NameParts.TargetIsValid) {
|
|
||||||
const char *arr[] = {"-target", GetStableCStr(SavedStrings,
|
|
||||||
NameParts.TargetPrefix)};
|
|
||||||
ArgVector.insert(ArgVector.begin() + InsertionPoint,
|
|
||||||
std::begin(arr), std::end(arr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void getCLEnvVarOptions(std::string &EnvValue, llvm::StringSaver &Saver,
|
|
||||||
SmallVectorImpl<const char *> &Opts) {
|
|
||||||
llvm::cl::TokenizeWindowsCommandLine(EnvValue, Saver, Opts);
|
|
||||||
// The first instance of '#' should be replaced with '=' in each option.
|
|
||||||
for (const char *Opt : Opts)
|
|
||||||
if (char *NumberSignPtr = const_cast<char *>(::strchr(Opt, '#')))
|
|
||||||
*NumberSignPtr = '=';
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) {
|
|
||||||
// Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
|
|
||||||
TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
|
|
||||||
if (TheDriver.CCPrintOptions)
|
|
||||||
TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE");
|
|
||||||
|
|
||||||
// Handle CC_PRINT_HEADERS and CC_PRINT_HEADERS_FILE.
|
|
||||||
TheDriver.CCPrintHeaders = !!::getenv("CC_PRINT_HEADERS");
|
|
||||||
if (TheDriver.CCPrintHeaders)
|
|
||||||
TheDriver.CCPrintHeadersFilename = ::getenv("CC_PRINT_HEADERS_FILE");
|
|
||||||
|
|
||||||
// Handle CC_LOG_DIAGNOSTICS and CC_LOG_DIAGNOSTICS_FILE.
|
|
||||||
TheDriver.CCLogDiagnostics = !!::getenv("CC_LOG_DIAGNOSTICS");
|
|
||||||
if (TheDriver.CCLogDiagnostics)
|
|
||||||
TheDriver.CCLogDiagnosticsFilename = ::getenv("CC_LOG_DIAGNOSTICS_FILE");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
|
|
||||||
const std::string &Path) {
|
|
||||||
// If the clang binary happens to be named cl.exe for compatibility reasons,
|
|
||||||
// use clang-cl.exe as the prefix to avoid confusion between clang and MSVC.
|
|
||||||
StringRef ExeBasename(llvm::sys::path::filename(Path));
|
|
||||||
if (ExeBasename.equals_lower("cl.exe"))
|
|
||||||
ExeBasename = "clang-cl.exe";
|
|
||||||
DiagClient->setPrefix(ExeBasename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This lets us create the DiagnosticsEngine with a properly-filled-out
|
|
||||||
// DiagnosticOptions instance.
|
|
||||||
static DiagnosticOptions *
|
|
||||||
CreateAndPopulateDiagOpts(ArrayRef<const char *> argv) {
|
|
||||||
auto *DiagOpts = new DiagnosticOptions;
|
|
||||||
std::unique_ptr<OptTable> Opts(createDriverOptTable());
|
|
||||||
unsigned MissingArgIndex, MissingArgCount;
|
|
||||||
InputArgList Args =
|
|
||||||
Opts->ParseArgs(argv.slice(1), MissingArgIndex, MissingArgCount);
|
|
||||||
// We ignore MissingArgCount and the return value of ParseDiagnosticArgs.
|
|
||||||
// Any errors that would be diagnosed here will also be diagnosed later,
|
|
||||||
// when the DiagnosticsEngine actually exists.
|
|
||||||
(void)ParseDiagnosticArgs(*DiagOpts, Args);
|
|
||||||
return DiagOpts;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetInstallDir(SmallVectorImpl<const char *> &argv,
|
|
||||||
Driver &TheDriver, bool CanonicalPrefixes) {
|
|
||||||
// Attempt to find the original path used to invoke the driver, to determine
|
|
||||||
// the installed path. We do this manually, because we want to support that
|
|
||||||
// path being a symlink.
|
|
||||||
SmallString<128> InstalledPath(argv[0]);
|
|
||||||
|
|
||||||
// Do a PATH lookup, if there are no directory components.
|
|
||||||
if (llvm::sys::path::filename(InstalledPath) == InstalledPath)
|
|
||||||
if (llvm::ErrorOr<std::string> Tmp = llvm::sys::findProgramByName(
|
|
||||||
llvm::sys::path::filename(InstalledPath.str())))
|
|
||||||
InstalledPath = *Tmp;
|
|
||||||
|
|
||||||
// FIXME: We don't actually canonicalize this, we just make it absolute.
|
|
||||||
if (CanonicalPrefixes)
|
|
||||||
llvm::sys::fs::make_absolute(InstalledPath);
|
|
||||||
|
|
||||||
StringRef InstalledPathParent(llvm::sys::path::parent_path(InstalledPath));
|
|
||||||
if (llvm::sys::fs::exists(InstalledPathParent))
|
|
||||||
TheDriver.setInstalledDir(InstalledPathParent);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ExecuteCC1Tool(ArrayRef<const char *> argv, StringRef Tool) {
|
|
||||||
void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath;
|
|
||||||
if (Tool == "")
|
|
||||||
return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP);
|
|
||||||
if (Tool == "as")
|
|
||||||
return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
|
|
||||||
|
|
||||||
// Reject unknown tools.
|
|
||||||
llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
|
|
||||||
<< "Valid tools include '-cc1' and '-cc1as'.\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mainEntryClickHouseClang(int argc_, char **argv_) {
|
|
||||||
llvm::InitLLVM X(argc_, argv_);
|
|
||||||
SmallVector<const char *, 256> argv(argv_, argv_ + argc_);
|
|
||||||
|
|
||||||
if (llvm::sys::Process::FixupStandardFileDescriptors())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
llvm::InitializeAllTargets();
|
|
||||||
auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(argv[0]);
|
|
||||||
|
|
||||||
llvm::BumpPtrAllocator A;
|
|
||||||
llvm::StringSaver Saver(A);
|
|
||||||
|
|
||||||
// Parse response files using the GNU syntax, unless we're in CL mode. There
|
|
||||||
// are two ways to put clang in CL compatibility mode: argv[0] is either
|
|
||||||
// clang-cl or cl, or --driver-mode=cl is on the command line. The normal
|
|
||||||
// command line parsing can't happen until after response file parsing, so we
|
|
||||||
// have to manually search for a --driver-mode=cl argument the hard way.
|
|
||||||
// Finally, our -cc1 tools don't care which tokenization mode we use because
|
|
||||||
// response files written by clang will tokenize the same way in either mode.
|
|
||||||
bool ClangCLMode = false;
|
|
||||||
if (StringRef(TargetAndMode.DriverMode).equals("--driver-mode=cl") ||
|
|
||||||
std::find_if(argv.begin(), argv.end(), [](const char *F) {
|
|
||||||
return F && strcmp(F, "--driver-mode=cl") == 0;
|
|
||||||
}) != argv.end()) {
|
|
||||||
ClangCLMode = true;
|
|
||||||
}
|
|
||||||
enum { Default, POSIX, Windows } RSPQuoting = Default;
|
|
||||||
for (const char *F : argv) {
|
|
||||||
if (strcmp(F, "--rsp-quoting=posix") == 0)
|
|
||||||
RSPQuoting = POSIX;
|
|
||||||
else if (strcmp(F, "--rsp-quoting=windows") == 0)
|
|
||||||
RSPQuoting = Windows;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determines whether we want nullptr markers in argv to indicate response
|
|
||||||
// files end-of-lines. We only use this for the /LINK driver argument with
|
|
||||||
// clang-cl.exe on Windows.
|
|
||||||
bool MarkEOLs = ClangCLMode;
|
|
||||||
|
|
||||||
llvm::cl::TokenizerCallback Tokenizer;
|
|
||||||
if (RSPQuoting == Windows || (RSPQuoting == Default && ClangCLMode))
|
|
||||||
Tokenizer = &llvm::cl::TokenizeWindowsCommandLine;
|
|
||||||
else
|
|
||||||
Tokenizer = &llvm::cl::TokenizeGNUCommandLine;
|
|
||||||
|
|
||||||
if (MarkEOLs && argv.size() > 1 && StringRef(argv[1]).startswith("-cc1"))
|
|
||||||
MarkEOLs = false;
|
|
||||||
llvm::cl::ExpandResponseFiles(Saver, Tokenizer, argv, MarkEOLs);
|
|
||||||
|
|
||||||
// Handle -cc1 integrated tools, even if -cc1 was expanded from a response
|
|
||||||
// file.
|
|
||||||
auto FirstArg = std::find_if(argv.begin() + 1, argv.end(),
|
|
||||||
[](const char *A) { return A != nullptr; });
|
|
||||||
if (FirstArg != argv.end() && StringRef(*FirstArg).startswith("-cc1")) {
|
|
||||||
// If -cc1 came from a response file, remove the EOL sentinels.
|
|
||||||
if (MarkEOLs) {
|
|
||||||
auto newEnd = std::remove(argv.begin(), argv.end(), nullptr);
|
|
||||||
argv.resize(newEnd - argv.begin());
|
|
||||||
}
|
|
||||||
return ExecuteCC1Tool(argv, argv[1] + 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CanonicalPrefixes = true;
|
|
||||||
for (int i = 1, size = argv.size(); i < size; ++i) {
|
|
||||||
// Skip end-of-line response file markers
|
|
||||||
if (argv[i] == nullptr)
|
|
||||||
continue;
|
|
||||||
if (StringRef(argv[i]) == "-no-canonical-prefixes") {
|
|
||||||
CanonicalPrefixes = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle CL and _CL_ which permits additional command line options to be
|
|
||||||
// prepended or appended.
|
|
||||||
if (ClangCLMode) {
|
|
||||||
// Arguments in "CL" are prepended.
|
|
||||||
llvm::Optional<std::string> OptCL = llvm::sys::Process::GetEnv("CL");
|
|
||||||
if (OptCL.hasValue()) {
|
|
||||||
SmallVector<const char *, 8> PrependedOpts;
|
|
||||||
getCLEnvVarOptions(OptCL.getValue(), Saver, PrependedOpts);
|
|
||||||
|
|
||||||
// Insert right after the program name to prepend to the argument list.
|
|
||||||
argv.insert(argv.begin() + 1, PrependedOpts.begin(), PrependedOpts.end());
|
|
||||||
}
|
|
||||||
// Arguments in "_CL_" are appended.
|
|
||||||
llvm::Optional<std::string> Opt_CL_ = llvm::sys::Process::GetEnv("_CL_");
|
|
||||||
if (Opt_CL_.hasValue()) {
|
|
||||||
SmallVector<const char *, 8> AppendedOpts;
|
|
||||||
getCLEnvVarOptions(Opt_CL_.getValue(), Saver, AppendedOpts);
|
|
||||||
|
|
||||||
// Insert at the end of the argument list to append.
|
|
||||||
argv.append(AppendedOpts.begin(), AppendedOpts.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<std::string> SavedStrings;
|
|
||||||
// Handle CCC_OVERRIDE_OPTIONS, used for editing a command line behind the
|
|
||||||
// scenes.
|
|
||||||
if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
|
|
||||||
// FIXME: Driver shouldn't take extra initial argument.
|
|
||||||
ApplyQAOverride(argv, OverrideStr, SavedStrings);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Path = GetExecutablePath(argv[0], CanonicalPrefixes);
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
|
|
||||||
CreateAndPopulateDiagOpts(argv);
|
|
||||||
|
|
||||||
TextDiagnosticPrinter *DiagClient
|
|
||||||
= new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
|
|
||||||
FixupDiagPrefixExeName(DiagClient, Path);
|
|
||||||
|
|
||||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
||||||
|
|
||||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
|
||||||
|
|
||||||
if (!DiagOpts->DiagnosticSerializationFile.empty()) {
|
|
||||||
auto SerializedConsumer =
|
|
||||||
clang::serialized_diags::create(DiagOpts->DiagnosticSerializationFile,
|
|
||||||
&*DiagOpts, /*MergeChildRecords=*/true);
|
|
||||||
Diags.setClient(new ChainedDiagnosticConsumer(
|
|
||||||
Diags.takeClient(), std::move(SerializedConsumer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
|
|
||||||
|
|
||||||
Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
|
|
||||||
SetInstallDir(argv, TheDriver, CanonicalPrefixes);
|
|
||||||
TheDriver.setTargetAndMode(TargetAndMode);
|
|
||||||
|
|
||||||
insertTargetAndModeArgs(TargetAndMode, argv, SavedStrings);
|
|
||||||
|
|
||||||
SetBackdoorDriverOutputsFromEnvVars(TheDriver);
|
|
||||||
|
|
||||||
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(argv));
|
|
||||||
int Res = 1;
|
|
||||||
if (C && !C->containsError()) {
|
|
||||||
SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
|
|
||||||
Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
|
|
||||||
|
|
||||||
// Force a crash to test the diagnostics.
|
|
||||||
if (TheDriver.GenReproducer) {
|
|
||||||
Diags.Report(diag::err_drv_force_crash)
|
|
||||||
<< !::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH");
|
|
||||||
|
|
||||||
// Pretend that every command failed.
|
|
||||||
FailingCommands.clear();
|
|
||||||
for (const auto &J : C->getJobs())
|
|
||||||
if (const Command *C = dyn_cast<Command>(&J))
|
|
||||||
FailingCommands.push_back(std::make_pair(-1, C));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &P : FailingCommands) {
|
|
||||||
int CommandRes = P.first;
|
|
||||||
const Command *FailingCommand = P.second;
|
|
||||||
if (!Res)
|
|
||||||
Res = CommandRes;
|
|
||||||
|
|
||||||
// If result status is < 0, then the driver command signalled an error.
|
|
||||||
// If result status is 70, then the driver command reported a fatal error.
|
|
||||||
// On Windows, abort will return an exit code of 3. In these cases,
|
|
||||||
// generate additional diagnostic information if possible.
|
|
||||||
bool DiagnoseCrash = CommandRes < 0 || CommandRes == 70;
|
|
||||||
#ifdef _WIN32
|
|
||||||
DiagnoseCrash |= CommandRes == 3;
|
|
||||||
#endif
|
|
||||||
if (DiagnoseCrash) {
|
|
||||||
TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Diags.getClient()->finish();
|
|
||||||
|
|
||||||
// If any timers were active but haven't been destroyed yet, print their
|
|
||||||
// results now. This happens in -disable-free mode.
|
|
||||||
llvm::TimerGroup::printAll(llvm::errs());
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
// Exit status should not be negative on Win32, unless abnormal termination.
|
|
||||||
// Once abnormal termiation was caught, negative status should not be
|
|
||||||
// propagated.
|
|
||||||
if (Res < 0)
|
|
||||||
Res = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// If we have multiple failing commands, we return the result of the first
|
|
||||||
// failing command.
|
|
||||||
return Res;
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
#include "lld/Common/Driver.h"
|
|
||||||
#include "llvm/Support/InitLLVM.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
int mainEntryClickHouseLLD(int argc, char ** argv)
|
|
||||||
{
|
|
||||||
llvm::InitLLVM X(argc, argv);
|
|
||||||
std::vector<const char *> args(argv, argv + argc);
|
|
||||||
return !lld::elf::link(args, false);
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
Compiler-7.0.0
|
|
@ -1 +0,0 @@
|
|||||||
Compiler-7.0.0
|
|
@ -1,2 +0,0 @@
|
|||||||
int mainEntryClickHouseClang(int argc, char ** argv);
|
|
||||||
int main(int argc_, char ** argv_) { return mainEntryClickHouseClang(argc_, argv_); }
|
|
@ -1,2 +0,0 @@
|
|||||||
int mainEntryClickHouseLLD(int argc, char ** argv);
|
|
||||||
int main(int argc_, char ** argv_) { return mainEntryClickHouseLLD(argc_, argv_); }
|
|
@ -1,100 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
#set -x
|
|
||||||
#echo "Args: $*"; env | sort
|
|
||||||
|
|
||||||
# Этот скрипт собирает все заголовочные файлы, нужные для компиляции некоторого translation unit-а
|
|
||||||
# и копирует их с сохранением путей в директорию DST.
|
|
||||||
# Это затем может быть использовано, чтобы скомпилировать translation unit на другом сервере,
|
|
||||||
# используя ровно такой же набор заголовочных файлов.
|
|
||||||
#
|
|
||||||
# Требуется clang, желательно наиболее свежий (trunk).
|
|
||||||
#
|
|
||||||
# Используется при сборке пакетов.
|
|
||||||
# Заголовочные файлы записываются в пакет clickhouse-common, в директорию /usr/share/clickhouse/headers.
|
|
||||||
#
|
|
||||||
# Если вы хотите установить их самостоятельно, без сборки пакета,
|
|
||||||
# чтобы clickhouse-server видел их там, где ожидается, выполните:
|
|
||||||
#
|
|
||||||
# sudo ./copy_headers.sh . /usr/share/clickhouse/headers/
|
|
||||||
|
|
||||||
SOURCE_PATH=${1:-../../..}
|
|
||||||
DST=${2:-$SOURCE_PATH/../headers}
|
|
||||||
BUILD_PATH=${BUILD_PATH=${3:-$SOURCE_PATH/build}}
|
|
||||||
|
|
||||||
PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:$PATH"
|
|
||||||
|
|
||||||
if [[ -z $CLANG ]]; then
|
|
||||||
CLANG="clang"
|
|
||||||
fi
|
|
||||||
|
|
||||||
START_HEADERS=$(echo \
|
|
||||||
$BUILD_PATH/dbms/src/Common/config_version.h \
|
|
||||||
$SOURCE_PATH/dbms/src/Interpreters/SpecializedAggregator.h \
|
|
||||||
$SOURCE_PATH/dbms/src/AggregateFunctions/AggregateFunction*.h)
|
|
||||||
|
|
||||||
for header in $START_HEADERS; do
|
|
||||||
START_HEADERS_INCLUDE+="-include $header "
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
GCC_ROOT=`$CLANG -v 2>&1 | grep "Selected GCC installation"| sed -n -e 's/^.*: //p'`
|
|
||||||
|
|
||||||
# TODO: Does not work on macos?
|
|
||||||
GCC_ROOT=${GCC_ROOT:=/usr/lib/clang/${CMAKE_CXX_COMPILER_VERSION}}
|
|
||||||
|
|
||||||
# Опция -mcx16 для того, чтобы выбиралось больше заголовочных файлов (с запасом).
|
|
||||||
# The latter options are the same that are added while building packages.
|
|
||||||
for src_file in $(echo | $CLANG -M -xc++ -std=c++1z -Wall -Werror -msse2 -msse4 -mcx16 -mpopcnt -O3 -g -fPIC -fstack-protector -D_FORTIFY_SOURCE=2 \
|
|
||||||
-I $GCC_ROOT/include \
|
|
||||||
-I $GCC_ROOT/include-fixed \
|
|
||||||
$(cat "$BUILD_PATH/include_directories.txt") \
|
|
||||||
$START_HEADERS_INCLUDE \
|
|
||||||
- |
|
|
||||||
tr -d '\\' |
|
|
||||||
sed -E -e 's/^-\.o://');
|
|
||||||
do
|
|
||||||
dst_file=$src_file;
|
|
||||||
[ -n $BUILD_PATH ] && dst_file=$(echo $dst_file | sed -E -e "s!^$BUILD_PATH!!")
|
|
||||||
[ -n $DESTDIR ] && dst_file=$(echo $dst_file | sed -E -e "s!^$DESTDIR!!")
|
|
||||||
dst_file=$(echo $dst_file | sed -E -e 's/build\///') # for simplicity reasons, will put generated headers near the rest.
|
|
||||||
mkdir -p "$DST/$(echo $dst_file | sed -E -e 's/\/[^/]*$/\//')";
|
|
||||||
cp "$src_file" "$DST/$dst_file";
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# Копируем больше заголовочных файлов с интринсиками, так как на серверах, куда будут устанавливаться
|
|
||||||
# заголовочные файлы, будет использоваться опция -march=native.
|
|
||||||
|
|
||||||
for src_file in $(ls -1 $($CLANG -v -xc++ - <<<'' 2>&1 | grep '^ /' | grep 'include' | grep -E '/lib/clang/|/include/clang/')/*.h | grep -vE 'arm|altivec|Intrin');
|
|
||||||
do
|
|
||||||
dst_file=$src_file;
|
|
||||||
[ -n $BUILD_PATH ] && dst_file=$(echo $dst_file | sed -E -e "s!^$BUILD_PATH!!")
|
|
||||||
[ -n $DESTDIR ] && dst_file=$(echo $dst_file | sed -E -e "s!^$DESTDIR!!")
|
|
||||||
mkdir -p "$DST/$(echo $dst_file | sed -E -e 's/\/[^/]*$/\//')";
|
|
||||||
cp "$src_file" "$DST/$dst_file";
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -d "$SOURCE_PATH/contrib/boost/libs/smart_ptr/include/boost/smart_ptr/detail" ]; then
|
|
||||||
# Even more platform-specific headers
|
|
||||||
for src_file in $(ls -1 $SOURCE_PATH/contrib/boost/libs/smart_ptr/include/boost/smart_ptr/detail/*);
|
|
||||||
do
|
|
||||||
dst_file=$src_file;
|
|
||||||
[ -n $BUILD_PATH ] && dst_file=$(echo $dst_file | sed -E -e "s!^$BUILD_PATH!!")
|
|
||||||
[ -n $DESTDIR ] && dst_file=$(echo $dst_file | sed -E -e "s!^$DESTDIR!!")
|
|
||||||
mkdir -p "$DST/$(echo $dst_file | sed -E -e 's/\/[^/]*$/\//')";
|
|
||||||
cp "$src_file" "$DST/$dst_file";
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -d "$SOURCE_PATH/contrib/boost/boost/smart_ptr/detail" ]; then
|
|
||||||
for src_file in $(ls -1 $SOURCE_PATH/contrib/boost/boost/smart_ptr/detail/*);
|
|
||||||
do
|
|
||||||
dst_file=$src_file;
|
|
||||||
[ -n $BUILD_PATH ] && dst_file=$(echo $dst_file | sed -E -e "s!^$BUILD_PATH!!")
|
|
||||||
[ -n $DESTDIR ] && dst_file=$(echo $dst_file | sed -E -e "s!^$DESTDIR!!")
|
|
||||||
mkdir -p "$DST/$(echo $dst_file | sed -E -e 's/\/[^/]*$/\//')";
|
|
||||||
cp "$src_file" "$DST/$dst_file";
|
|
||||||
done
|
|
||||||
fi
|
|
@ -67,6 +67,7 @@
|
|||||||
#include <Common/Config/configReadClient.h>
|
#include <Common/Config/configReadClient.h>
|
||||||
#include <Storages/ColumnsDescription.h>
|
#include <Storages/ColumnsDescription.h>
|
||||||
#include <common/argsToConfig.h>
|
#include <common/argsToConfig.h>
|
||||||
|
#include <Common/TerminalSize.h>
|
||||||
|
|
||||||
#if USE_READLINE
|
#if USE_READLINE
|
||||||
#include "Suggest.h"
|
#include "Suggest.h"
|
||||||
@ -130,7 +131,7 @@ private:
|
|||||||
bool print_time_to_stderr = false; /// Output execution time to stderr in batch mode.
|
bool print_time_to_stderr = false; /// Output execution time to stderr in batch mode.
|
||||||
bool stdin_is_not_tty = false; /// stdin is not a terminal.
|
bool stdin_is_not_tty = false; /// stdin is not a terminal.
|
||||||
|
|
||||||
winsize terminal_size {}; /// Terminal size is needed to render progress bar.
|
uint16_t terminal_width = 0; /// Terminal width is needed to render progress bar.
|
||||||
|
|
||||||
std::unique_ptr<Connection> connection; /// Connection to DB.
|
std::unique_ptr<Connection> connection; /// Connection to DB.
|
||||||
String query_id; /// Current query_id.
|
String query_id; /// Current query_id.
|
||||||
@ -671,7 +672,7 @@ private:
|
|||||||
String text;
|
String text;
|
||||||
|
|
||||||
if (config().has("query"))
|
if (config().has("query"))
|
||||||
text = config().getString("query");
|
text = config().getRawString("query"); /// Poco configuration should not process substitutions in form of ${...} inside query.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/// If 'query' parameter is not set, read a query from stdin.
|
/// If 'query' parameter is not set, read a query from stdin.
|
||||||
@ -1465,7 +1466,7 @@ private:
|
|||||||
|
|
||||||
if (show_progress_bar)
|
if (show_progress_bar)
|
||||||
{
|
{
|
||||||
ssize_t width_of_progress_bar = static_cast<ssize_t>(terminal_size.ws_col) - written_progress_chars - strlen(" 99%");
|
ssize_t width_of_progress_bar = static_cast<ssize_t>(terminal_width) - written_progress_chars - strlen(" 99%");
|
||||||
if (width_of_progress_bar > 0)
|
if (width_of_progress_bar > 0)
|
||||||
{
|
{
|
||||||
std::string bar = UnicodeBar::render(UnicodeBar::getWidth(progress.read_rows, 0, total_rows_corrected, width_of_progress_bar));
|
std::string bar = UnicodeBar::render(UnicodeBar::getWidth(progress.read_rows, 0, total_rows_corrected, width_of_progress_bar));
|
||||||
@ -1642,22 +1643,13 @@ public:
|
|||||||
|
|
||||||
stdin_is_not_tty = !isatty(STDIN_FILENO);
|
stdin_is_not_tty = !isatty(STDIN_FILENO);
|
||||||
|
|
||||||
|
if (!stdin_is_not_tty)
|
||||||
|
terminal_width = getTerminalWidth();
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
unsigned line_length = po::options_description::m_default_line_length;
|
|
||||||
unsigned min_description_length = line_length / 2;
|
|
||||||
if (!stdin_is_not_tty)
|
|
||||||
{
|
|
||||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &terminal_size))
|
|
||||||
throwFromErrno("Cannot obtain terminal window size (ioctl TIOCGWINSZ)", ErrorCodes::SYSTEM_ERROR);
|
|
||||||
line_length = std::max(
|
|
||||||
static_cast<unsigned>(strlen("--http_native_compression_disable_checksumming_on_decompress ")),
|
|
||||||
static_cast<unsigned>(terminal_size.ws_col));
|
|
||||||
min_description_length = std::min(min_description_length, line_length - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Main commandline options related to client functionality and all parameters from Settings.
|
/// Main commandline options related to client functionality and all parameters from Settings.
|
||||||
po::options_description main_description("Main options", line_length, min_description_length);
|
po::options_description main_description = createOptionsDescription("Main options", terminal_width);
|
||||||
main_description.add_options()
|
main_description.add_options()
|
||||||
("help", "produce help message")
|
("help", "produce help message")
|
||||||
("config-file,C", po::value<std::string>(), "config-file path")
|
("config-file,C", po::value<std::string>(), "config-file path")
|
||||||
@ -1672,7 +1664,7 @@ public:
|
|||||||
* the "\n" is used to distinguish this case because there is hardly a chance an user would use "\n"
|
* the "\n" is used to distinguish this case because there is hardly a chance an user would use "\n"
|
||||||
* as the password.
|
* as the password.
|
||||||
*/
|
*/
|
||||||
("password", po::value<std::string>()->implicit_value("\n"), "password")
|
("password", po::value<std::string>()->implicit_value("\n", ""), "password")
|
||||||
("ask-password", "ask-password")
|
("ask-password", "ask-password")
|
||||||
("query_id", po::value<std::string>(), "query_id")
|
("query_id", po::value<std::string>(), "query_id")
|
||||||
("query,q", po::value<std::string>(), "query")
|
("query,q", po::value<std::string>(), "query")
|
||||||
@ -1703,7 +1695,7 @@ public:
|
|||||||
context.getSettingsRef().addProgramOptions(main_description);
|
context.getSettingsRef().addProgramOptions(main_description);
|
||||||
|
|
||||||
/// Commandline options related to external tables.
|
/// Commandline options related to external tables.
|
||||||
po::options_description external_description("External tables options");
|
po::options_description external_description = createOptionsDescription("External tables options", terminal_width);
|
||||||
external_description.add_options()
|
external_description.add_options()
|
||||||
("file", po::value<std::string>(), "data file or - for stdin")
|
("file", po::value<std::string>(), "data file or - for stdin")
|
||||||
("name", po::value<std::string>()->default_value("_data"), "name of the table")
|
("name", po::value<std::string>()->default_value("_data"), "name of the table")
|
||||||
|
@ -12,8 +12,9 @@
|
|||||||
#include <IO/copyData.h>
|
#include <IO/copyData.h>
|
||||||
#include <Parsers/parseQuery.h>
|
#include <Parsers/parseQuery.h>
|
||||||
#include <Parsers/ExpressionElementParsers.h>
|
#include <Parsers/ExpressionElementParsers.h>
|
||||||
|
|
||||||
#include <Compression/CompressionFactory.h>
|
#include <Compression/CompressionFactory.h>
|
||||||
|
#include <Common/TerminalSize.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
@ -59,7 +60,7 @@ void checkAndWriteHeader(DB::ReadBuffer & in, DB::WriteBuffer & out)
|
|||||||
|
|
||||||
int mainEntryClickHouseCompressor(int argc, char ** argv)
|
int mainEntryClickHouseCompressor(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
boost::program_options::options_description desc("Allowed options");
|
boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth());
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
("help,h", "produce help message")
|
("help,h", "produce help message")
|
||||||
("decompress,d", "decompress")
|
("decompress,d", "decompress")
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
#include <Parsers/ParserQuery.h>
|
#include <Parsers/ParserQuery.h>
|
||||||
#include <Parsers/parseQuery.h>
|
#include <Parsers/parseQuery.h>
|
||||||
#include <Parsers/formatAST.h>
|
#include <Parsers/formatAST.h>
|
||||||
|
#include <Common/TerminalSize.h>
|
||||||
|
|
||||||
int mainEntryClickHouseFormat(int argc, char ** argv)
|
int mainEntryClickHouseFormat(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
using namespace DB;
|
using namespace DB;
|
||||||
|
|
||||||
boost::program_options::options_description desc("Allowed options");
|
boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth());
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
("help,h", "produce help message")
|
("help,h", "produce help message")
|
||||||
("hilite", "add syntax highlight with ANSI terminal escape sequences")
|
("hilite", "add syntax highlight with ANSI terminal escape sequences")
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <boost/program_options/options_description.hpp>
|
#include <boost/program_options/options_description.hpp>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <common/argsToConfig.h>
|
#include <common/argsToConfig.h>
|
||||||
|
#include <Common/TerminalSize.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -267,7 +268,7 @@ void LocalServer::attachSystemTables()
|
|||||||
void LocalServer::processQueries()
|
void LocalServer::processQueries()
|
||||||
{
|
{
|
||||||
String initial_create_query = getInitialCreateTableQuery();
|
String initial_create_query = getInitialCreateTableQuery();
|
||||||
String queries_str = initial_create_query + config().getString("query");
|
String queries_str = initial_create_query + config().getRawString("query");
|
||||||
|
|
||||||
std::vector<String> queries;
|
std::vector<String> queries;
|
||||||
auto parse_res = splitMultipartQuery(queries_str, queries);
|
auto parse_res = splitMultipartQuery(queries_str, queries);
|
||||||
@ -409,17 +410,7 @@ void LocalServer::init(int argc, char ** argv)
|
|||||||
/// Don't parse options with Poco library, we prefer neat boost::program_options
|
/// Don't parse options with Poco library, we prefer neat boost::program_options
|
||||||
stopOptionsProcessing();
|
stopOptionsProcessing();
|
||||||
|
|
||||||
unsigned line_length = po::options_description::m_default_line_length;
|
po::options_description description = createOptionsDescription("Main options", getTerminalWidth());
|
||||||
unsigned min_description_length = line_length / 2;
|
|
||||||
if (isatty(STDIN_FILENO))
|
|
||||||
{
|
|
||||||
winsize terminal_size{};
|
|
||||||
ioctl(0, TIOCGWINSZ, &terminal_size);
|
|
||||||
line_length = std::max(3U, static_cast<unsigned>(terminal_size.ws_col));
|
|
||||||
min_description_length = std::min(min_description_length, line_length - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
po::options_description description("Main options", line_length, min_description_length);
|
|
||||||
description.add_options()
|
description.add_options()
|
||||||
("help", "produce help message")
|
("help", "produce help message")
|
||||||
("config-file,c", po::value<std::string>(), "config-file path")
|
("config-file,c", po::value<std::string>(), "config-file path")
|
||||||
|
@ -56,11 +56,6 @@ int mainEntryClickHouseObfuscator(int argc, char ** argv);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if USE_EMBEDDED_COMPILER
|
|
||||||
int mainEntryClickHouseClang(int argc, char ** argv);
|
|
||||||
int mainEntryClickHouseLLD(int argc, char ** argv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -100,12 +95,6 @@ std::pair<const char *, MainFunc> clickhouse_applications[] =
|
|||||||
#if ENABLE_CLICKHOUSE_OBFUSCATOR || !defined(ENABLE_CLICKHOUSE_OBFUSCATOR)
|
#if ENABLE_CLICKHOUSE_OBFUSCATOR || !defined(ENABLE_CLICKHOUSE_OBFUSCATOR)
|
||||||
{"obfuscator", mainEntryClickHouseObfuscator},
|
{"obfuscator", mainEntryClickHouseObfuscator},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if USE_EMBEDDED_COMPILER
|
|
||||||
{"clang", mainEntryClickHouseClang},
|
|
||||||
{"clang++", mainEntryClickHouseClang},
|
|
||||||
{"lld", mainEntryClickHouseLLD},
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -152,11 +141,6 @@ int main(int argc_, char ** argv_)
|
|||||||
/// will work only after additional call of this function.
|
/// will work only after additional call of this function.
|
||||||
updatePHDRCache();
|
updatePHDRCache();
|
||||||
|
|
||||||
#if USE_EMBEDDED_COMPILER
|
|
||||||
if (argc_ >= 2 && 0 == strcmp(argv_[1], "-cc1"))
|
|
||||||
return mainEntryClickHouseClang(argc_, argv_);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if USE_TCMALLOC
|
#if USE_TCMALLOC
|
||||||
/** Without this option, tcmalloc returns memory to OS too frequently for medium-sized memory allocations
|
/** Without this option, tcmalloc returns memory to OS too frequently for medium-sized memory allocations
|
||||||
* (like IO buffers, column vectors, hash tables, etc.),
|
* (like IO buffers, column vectors, hash tables, etc.),
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <Common/StringUtils/StringUtils.h>
|
#include <Common/StringUtils/StringUtils.h>
|
||||||
#include <Common/HashTable/HashMap.h>
|
#include <Common/HashTable/HashMap.h>
|
||||||
#include <Common/typeid_cast.h>
|
#include <Common/typeid_cast.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <Core/Block.h>
|
#include <Core/Block.h>
|
||||||
#include <common/StringRef.h>
|
#include <common/StringRef.h>
|
||||||
#include <common/DateLUT.h>
|
#include <common/DateLUT.h>
|
||||||
@ -36,6 +37,7 @@
|
|||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/container/flat_map.hpp>
|
#include <boost/container/flat_map.hpp>
|
||||||
|
#include <Common/TerminalSize.h>
|
||||||
|
|
||||||
|
|
||||||
static const char * documantation = R"(
|
static const char * documantation = R"(
|
||||||
@ -263,11 +265,11 @@ public:
|
|||||||
|
|
||||||
ColumnPtr generate(const IColumn & column) override
|
ColumnPtr generate(const IColumn & column) override
|
||||||
{
|
{
|
||||||
const auto & src_data = static_cast<const ColumnVector<Float> &>(column).getData();
|
const auto & src_data = assert_cast<const ColumnVector<Float> &>(column).getData();
|
||||||
size_t size = src_data.size();
|
size_t size = src_data.size();
|
||||||
|
|
||||||
auto res_column = ColumnVector<Float>::create(size);
|
auto res_column = ColumnVector<Float>::create(size);
|
||||||
auto & res_data = static_cast<ColumnVector<Float> &>(*res_column).getData();
|
auto & res_data = assert_cast<ColumnVector<Float> &>(*res_column).getData();
|
||||||
|
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
@ -355,7 +357,7 @@ public:
|
|||||||
|
|
||||||
ColumnPtr generate(const IColumn & column) override
|
ColumnPtr generate(const IColumn & column) override
|
||||||
{
|
{
|
||||||
const ColumnFixedString & column_fixed_string = static_cast<const ColumnFixedString &>(column);
|
const ColumnFixedString & column_fixed_string = assert_cast<const ColumnFixedString &>(column);
|
||||||
const size_t string_size = column_fixed_string.getN();
|
const size_t string_size = column_fixed_string.getN();
|
||||||
|
|
||||||
const auto & src_data = column_fixed_string.getChars();
|
const auto & src_data = column_fixed_string.getChars();
|
||||||
@ -392,11 +394,11 @@ public:
|
|||||||
|
|
||||||
ColumnPtr generate(const IColumn & column) override
|
ColumnPtr generate(const IColumn & column) override
|
||||||
{
|
{
|
||||||
const auto & src_data = static_cast<const ColumnVector<UInt32> &>(column).getData();
|
const auto & src_data = assert_cast<const ColumnVector<UInt32> &>(column).getData();
|
||||||
size_t size = src_data.size();
|
size_t size = src_data.size();
|
||||||
|
|
||||||
auto res_column = ColumnVector<UInt32>::create(size);
|
auto res_column = ColumnVector<UInt32>::create(size);
|
||||||
auto & res_data = static_cast<ColumnVector<UInt32> &>(*res_column).getData();
|
auto & res_data = assert_cast<ColumnVector<UInt32> &>(*res_column).getData();
|
||||||
|
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
@ -749,7 +751,7 @@ public:
|
|||||||
|
|
||||||
void train(const IColumn & column) override
|
void train(const IColumn & column) override
|
||||||
{
|
{
|
||||||
const ColumnString & column_string = static_cast<const ColumnString &>(column);
|
const ColumnString & column_string = assert_cast<const ColumnString &>(column);
|
||||||
size_t size = column_string.size();
|
size_t size = column_string.size();
|
||||||
|
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
@ -766,7 +768,7 @@ public:
|
|||||||
|
|
||||||
ColumnPtr generate(const IColumn & column) override
|
ColumnPtr generate(const IColumn & column) override
|
||||||
{
|
{
|
||||||
const ColumnString & column_string = static_cast<const ColumnString &>(column);
|
const ColumnString & column_string = assert_cast<const ColumnString &>(column);
|
||||||
size_t size = column_string.size();
|
size_t size = column_string.size();
|
||||||
|
|
||||||
auto res_column = ColumnString::create();
|
auto res_column = ColumnString::create();
|
||||||
@ -801,7 +803,7 @@ public:
|
|||||||
|
|
||||||
void train(const IColumn & column) override
|
void train(const IColumn & column) override
|
||||||
{
|
{
|
||||||
const ColumnArray & column_array = static_cast<const ColumnArray &>(column);
|
const ColumnArray & column_array = assert_cast<const ColumnArray &>(column);
|
||||||
const IColumn & nested_column = column_array.getData();
|
const IColumn & nested_column = column_array.getData();
|
||||||
|
|
||||||
nested_model->train(nested_column);
|
nested_model->train(nested_column);
|
||||||
@ -814,7 +816,7 @@ public:
|
|||||||
|
|
||||||
ColumnPtr generate(const IColumn & column) override
|
ColumnPtr generate(const IColumn & column) override
|
||||||
{
|
{
|
||||||
const ColumnArray & column_array = static_cast<const ColumnArray &>(column);
|
const ColumnArray & column_array = assert_cast<const ColumnArray &>(column);
|
||||||
const IColumn & nested_column = column_array.getData();
|
const IColumn & nested_column = column_array.getData();
|
||||||
|
|
||||||
ColumnPtr new_nested_column = nested_model->generate(nested_column);
|
ColumnPtr new_nested_column = nested_model->generate(nested_column);
|
||||||
@ -834,7 +836,7 @@ public:
|
|||||||
|
|
||||||
void train(const IColumn & column) override
|
void train(const IColumn & column) override
|
||||||
{
|
{
|
||||||
const ColumnNullable & column_nullable = static_cast<const ColumnNullable &>(column);
|
const ColumnNullable & column_nullable = assert_cast<const ColumnNullable &>(column);
|
||||||
const IColumn & nested_column = column_nullable.getNestedColumn();
|
const IColumn & nested_column = column_nullable.getNestedColumn();
|
||||||
|
|
||||||
nested_model->train(nested_column);
|
nested_model->train(nested_column);
|
||||||
@ -847,7 +849,7 @@ public:
|
|||||||
|
|
||||||
ColumnPtr generate(const IColumn & column) override
|
ColumnPtr generate(const IColumn & column) override
|
||||||
{
|
{
|
||||||
const ColumnNullable & column_nullable = static_cast<const ColumnNullable &>(column);
|
const ColumnNullable & column_nullable = assert_cast<const ColumnNullable &>(column);
|
||||||
const IColumn & nested_column = column_nullable.getNestedColumn();
|
const IColumn & nested_column = column_nullable.getNestedColumn();
|
||||||
|
|
||||||
ColumnPtr new_nested_column = nested_model->generate(nested_column);
|
ColumnPtr new_nested_column = nested_model->generate(nested_column);
|
||||||
@ -948,7 +950,7 @@ try
|
|||||||
using namespace DB;
|
using namespace DB;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
po::options_description description("Options");
|
po::options_description description = createOptionsDescription("Options", getTerminalWidth());
|
||||||
description.add_options()
|
description.add_options()
|
||||||
("help", "produce help message")
|
("help", "produce help message")
|
||||||
("structure,S", po::value<std::string>(), "structure of the initial table (list of column and type names)")
|
("structure,S", po::value<std::string>(), "structure of the initial table (list of column and type names)")
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <Columns/ColumnNullable.h>
|
#include <Columns/ColumnNullable.h>
|
||||||
#include <Columns/ColumnString.h>
|
#include <Columns/ColumnString.h>
|
||||||
#include <Columns/ColumnsNumber.h>
|
#include <Columns/ColumnsNumber.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <IO/ReadHelpers.h>
|
#include <IO/ReadHelpers.h>
|
||||||
#include <IO/WriteHelpers.h>
|
#include <IO/WriteHelpers.h>
|
||||||
#include <common/logger_useful.h>
|
#include <common/logger_useful.h>
|
||||||
@ -44,46 +45,46 @@ namespace
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ValueType::vtUInt8:
|
case ValueType::vtUInt8:
|
||||||
static_cast<ColumnUInt8 &>(column).insertValue(value.convert<UInt64>());
|
assert_cast<ColumnUInt8 &>(column).insertValue(value.convert<UInt64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtUInt16:
|
case ValueType::vtUInt16:
|
||||||
static_cast<ColumnUInt16 &>(column).insertValue(value.convert<UInt64>());
|
assert_cast<ColumnUInt16 &>(column).insertValue(value.convert<UInt64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtUInt32:
|
case ValueType::vtUInt32:
|
||||||
static_cast<ColumnUInt32 &>(column).insertValue(value.convert<UInt64>());
|
assert_cast<ColumnUInt32 &>(column).insertValue(value.convert<UInt64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtUInt64:
|
case ValueType::vtUInt64:
|
||||||
static_cast<ColumnUInt64 &>(column).insertValue(value.convert<UInt64>());
|
assert_cast<ColumnUInt64 &>(column).insertValue(value.convert<UInt64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtInt8:
|
case ValueType::vtInt8:
|
||||||
static_cast<ColumnInt8 &>(column).insertValue(value.convert<Int64>());
|
assert_cast<ColumnInt8 &>(column).insertValue(value.convert<Int64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtInt16:
|
case ValueType::vtInt16:
|
||||||
static_cast<ColumnInt16 &>(column).insertValue(value.convert<Int64>());
|
assert_cast<ColumnInt16 &>(column).insertValue(value.convert<Int64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtInt32:
|
case ValueType::vtInt32:
|
||||||
static_cast<ColumnInt32 &>(column).insertValue(value.convert<Int64>());
|
assert_cast<ColumnInt32 &>(column).insertValue(value.convert<Int64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtInt64:
|
case ValueType::vtInt64:
|
||||||
static_cast<ColumnInt64 &>(column).insertValue(value.convert<Int64>());
|
assert_cast<ColumnInt64 &>(column).insertValue(value.convert<Int64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtFloat32:
|
case ValueType::vtFloat32:
|
||||||
static_cast<ColumnFloat32 &>(column).insertValue(value.convert<Float64>());
|
assert_cast<ColumnFloat32 &>(column).insertValue(value.convert<Float64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtFloat64:
|
case ValueType::vtFloat64:
|
||||||
static_cast<ColumnFloat64 &>(column).insertValue(value.convert<Float64>());
|
assert_cast<ColumnFloat64 &>(column).insertValue(value.convert<Float64>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtString:
|
case ValueType::vtString:
|
||||||
static_cast<ColumnString &>(column).insert(value.convert<String>());
|
assert_cast<ColumnString &>(column).insert(value.convert<String>());
|
||||||
break;
|
break;
|
||||||
case ValueType::vtDate:
|
case ValueType::vtDate:
|
||||||
static_cast<ColumnUInt16 &>(column).insertValue(UInt16{LocalDate{value.convert<String>()}.getDayNum()});
|
assert_cast<ColumnUInt16 &>(column).insertValue(UInt16{LocalDate{value.convert<String>()}.getDayNum()});
|
||||||
break;
|
break;
|
||||||
case ValueType::vtDateTime:
|
case ValueType::vtDateTime:
|
||||||
static_cast<ColumnUInt32 &>(column).insertValue(time_t{LocalDateTime{value.convert<String>()}});
|
assert_cast<ColumnUInt32 &>(column).insertValue(time_t{LocalDateTime{value.convert<String>()}});
|
||||||
break;
|
break;
|
||||||
case ValueType::vtUUID:
|
case ValueType::vtUUID:
|
||||||
static_cast<ColumnUInt128 &>(column).insert(parse<UUID>(value.convert<std::string>()));
|
assert_cast<ColumnUInt128 &>(column).insert(parse<UUID>(value.convert<std::string>()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +115,7 @@ Block ODBCBlockInputStream::readImpl()
|
|||||||
{
|
{
|
||||||
if (description.types[idx].second)
|
if (description.types[idx].second)
|
||||||
{
|
{
|
||||||
ColumnNullable & column_nullable = static_cast<ColumnNullable &>(*columns[idx]);
|
ColumnNullable & column_nullable = assert_cast<ColumnNullable &>(*columns[idx]);
|
||||||
insertValue(column_nullable.getNestedColumn(), description.types[idx].first, value);
|
insertValue(column_nullable.getNestedColumn(), description.types[idx].first, value);
|
||||||
column_nullable.getNullMapData().emplace_back(0);
|
column_nullable.getNullMapData().emplace_back(0);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <Core/Settings.h>
|
#include <Core/Settings.h>
|
||||||
#include <Common/Exception.h>
|
#include <Common/Exception.h>
|
||||||
#include <Common/InterruptListener.h>
|
#include <Common/InterruptListener.h>
|
||||||
|
#include <Common/TerminalSize.h>
|
||||||
|
|
||||||
#include "TestStopConditions.h"
|
#include "TestStopConditions.h"
|
||||||
#include "TestStats.h"
|
#include "TestStats.h"
|
||||||
@ -324,7 +325,7 @@ try
|
|||||||
using po::value;
|
using po::value;
|
||||||
using Strings = DB::Strings;
|
using Strings = DB::Strings;
|
||||||
|
|
||||||
po::options_description desc("Allowed options");
|
po::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth());
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
("help", "produce help message")
|
("help", "produce help message")
|
||||||
("lite", "use lite version of output")
|
("lite", "use lite version of output")
|
||||||
|
@ -520,7 +520,18 @@ int Server::main(const std::vector<std::string> & /*args*/)
|
|||||||
|
|
||||||
/// Init trace collector only after trace_log system table was created
|
/// Init trace collector only after trace_log system table was created
|
||||||
/// Disable it if we collect test coverage information, because it will work extremely slow.
|
/// Disable it if we collect test coverage information, because it will work extremely slow.
|
||||||
#if USE_INTERNAL_UNWIND_LIBRARY && !WITH_COVERAGE
|
///
|
||||||
|
/// It also cannot work with sanitizers.
|
||||||
|
/// Sanitizers are using quick "frame walking" stack unwinding (this implies -fno-omit-frame-pointer)
|
||||||
|
/// And they do unwiding frequently (on every malloc/free, thread/mutex operations, etc).
|
||||||
|
/// They change %rbp during unwinding and it confuses libunwind if signal comes during sanitizer unwiding
|
||||||
|
/// and query profiler decide to unwind stack with libunwind at this moment.
|
||||||
|
///
|
||||||
|
/// Symptoms: you'll get silent Segmentation Fault - without sanitizer message and without usual ClickHouse diagnostics.
|
||||||
|
///
|
||||||
|
/// Look at compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
|
||||||
|
///
|
||||||
|
#if USE_UNWIND && !WITH_COVERAGE && !defined(SANITIZER)
|
||||||
/// QueryProfiler cannot work reliably with any other libunwind or without PHDR cache.
|
/// QueryProfiler cannot work reliably with any other libunwind or without PHDR cache.
|
||||||
if (hasPHDRCache())
|
if (hasPHDRCache())
|
||||||
global_context->initializeTraceCollector();
|
global_context->initializeTraceCollector();
|
||||||
|
@ -182,11 +182,11 @@ void TCPHandler::runImpl()
|
|||||||
/// Should we send internal logs to client?
|
/// Should we send internal logs to client?
|
||||||
const auto client_logs_level = query_context->getSettingsRef().send_logs_level;
|
const auto client_logs_level = query_context->getSettingsRef().send_logs_level;
|
||||||
if (client_revision >= DBMS_MIN_REVISION_WITH_SERVER_LOGS
|
if (client_revision >= DBMS_MIN_REVISION_WITH_SERVER_LOGS
|
||||||
&& client_logs_level.value != LogsLevel::none)
|
&& client_logs_level != LogsLevel::none)
|
||||||
{
|
{
|
||||||
state.logs_queue = std::make_shared<InternalTextLogsQueue>();
|
state.logs_queue = std::make_shared<InternalTextLogsQueue>();
|
||||||
state.logs_queue->max_priority = Poco::Logger::parseLevel(client_logs_level.toString());
|
state.logs_queue->max_priority = Poco::Logger::parseLevel(client_logs_level.toString());
|
||||||
CurrentThread::attachInternalTextLogsQueue(state.logs_queue, client_logs_level.value);
|
CurrentThread::attachInternalTextLogsQueue(state.logs_queue, client_logs_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
query_context->setExternalTablesInitializer([&connection_settings, this] (Context & context)
|
query_context->setExternalTablesInitializer([&connection_settings, this] (Context & context)
|
||||||
@ -329,7 +329,7 @@ void TCPHandler::readData(const Settings & connection_settings)
|
|||||||
const auto receive_timeout = query_context->getSettingsRef().receive_timeout.value;
|
const auto receive_timeout = query_context->getSettingsRef().receive_timeout.value;
|
||||||
|
|
||||||
/// Poll interval should not be greater than receive_timeout
|
/// Poll interval should not be greater than receive_timeout
|
||||||
const size_t default_poll_interval = connection_settings.poll_interval.value * 1000000;
|
const size_t default_poll_interval = connection_settings.poll_interval * 1000000;
|
||||||
size_t current_poll_interval = static_cast<size_t>(receive_timeout.totalMicroseconds());
|
size_t current_poll_interval = static_cast<size_t>(receive_timeout.totalMicroseconds());
|
||||||
constexpr size_t min_poll_interval = 5000; // 5 ms
|
constexpr size_t min_poll_interval = 5000; // 5 ms
|
||||||
size_t poll_interval = std::max(min_poll_interval, std::min(default_poll_interval, current_poll_interval));
|
size_t poll_interval = std::max(min_poll_interval, std::min(default_poll_interval, current_poll_interval));
|
||||||
@ -865,7 +865,7 @@ bool TCPHandler::receiveData()
|
|||||||
if (!(storage = query_context->tryGetExternalTable(external_table_name)))
|
if (!(storage = query_context->tryGetExternalTable(external_table_name)))
|
||||||
{
|
{
|
||||||
NamesAndTypesList columns = block.getNamesAndTypesList();
|
NamesAndTypesList columns = block.getNamesAndTypesList();
|
||||||
storage = StorageMemory::create("_external", external_table_name, ColumnsDescription{columns});
|
storage = StorageMemory::create("_external", external_table_name, ColumnsDescription{columns}, ConstraintsDescription{});
|
||||||
storage->startup();
|
storage->startup();
|
||||||
query_context->addExternalTable(external_table_name, storage);
|
query_context->addExternalTable(external_table_name, storage);
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,7 @@
|
|||||||
|
|
||||||
See https://clickhouse.yandex/docs/en/table_engines/replication/
|
See https://clickhouse.yandex/docs/en/table_engines/replication/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<zookeeper incl="zookeeper-servers" optional="true" />
|
<zookeeper incl="zookeeper-servers" optional="true" />
|
||||||
|
|
||||||
<!-- Substitutions for parameters of replicated tables.
|
<!-- Substitutions for parameters of replicated tables.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Columns/ColumnArray.h>
|
#include <Columns/ColumnArray.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <DataTypes/DataTypeArray.h>
|
#include <DataTypes/DataTypeArray.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <IO/WriteHelpers.h>
|
#include <IO/WriteHelpers.h>
|
||||||
@ -81,9 +82,9 @@ public:
|
|||||||
const IColumn * nested[num_arguments];
|
const IColumn * nested[num_arguments];
|
||||||
|
|
||||||
for (size_t i = 0; i < num_arguments; ++i)
|
for (size_t i = 0; i < num_arguments; ++i)
|
||||||
nested[i] = &static_cast<const ColumnArray &>(*columns[i]).getData();
|
nested[i] = &assert_cast<const ColumnArray &>(*columns[i]).getData();
|
||||||
|
|
||||||
const ColumnArray & first_array_column = static_cast<const ColumnArray &>(*columns[0]);
|
const ColumnArray & first_array_column = assert_cast<const ColumnArray &>(*columns[0]);
|
||||||
const IColumn::Offsets & offsets = first_array_column.getOffsets();
|
const IColumn::Offsets & offsets = first_array_column.getOffsets();
|
||||||
|
|
||||||
size_t begin = offsets[row_num - 1];
|
size_t begin = offsets[row_num - 1];
|
||||||
@ -92,7 +93,7 @@ public:
|
|||||||
/// Sanity check. NOTE We can implement specialization for a case with single argument, if the check will hurt performance.
|
/// Sanity check. NOTE We can implement specialization for a case with single argument, if the check will hurt performance.
|
||||||
for (size_t i = 1; i < num_arguments; ++i)
|
for (size_t i = 1; i < num_arguments; ++i)
|
||||||
{
|
{
|
||||||
const ColumnArray & ith_column = static_cast<const ColumnArray &>(*columns[i]);
|
const ColumnArray & ith_column = assert_cast<const ColumnArray &>(*columns[i]);
|
||||||
const IColumn::Offsets & ith_offsets = ith_column.getOffsets();
|
const IColumn::Offsets & ith_offsets = ith_column.getOffsets();
|
||||||
|
|
||||||
if (ith_offsets[row_num] != end || (row_num != 0 && ith_offsets[row_num - 1] != begin))
|
if (ith_offsets[row_num] != end || (row_num != 0 && ith_offsets[row_num - 1] != begin))
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <Columns/ColumnVector.h>
|
#include <Columns/ColumnVector.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||||
{
|
{
|
||||||
this->data(place).update(static_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num]);
|
this->data(place).update(assert_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
||||||
@ -75,7 +76,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnVector<T> &>(to).getData().push_back(this->data(place).value);
|
assert_cast<ColumnVector<T> &>(to).getData().push_back(this->data(place).value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override { return __FILE__; }
|
const char * getHeaderFilePath() const override { return __FILE__; }
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <IO/WriteHelpers.h>
|
#include <IO/WriteHelpers.h>
|
||||||
#include <AggregateFunctions/Helpers.h>
|
#include <AggregateFunctions/Helpers.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -151,7 +152,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnFloat64 &>(to).getData().push_back(getBoundingRatio(data(place)));
|
assert_cast<ColumnFloat64 &>(to).getData().push_back(getBoundingRatio(data(place)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override
|
const char * getHeaderFilePath() const override
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <Columns/ColumnNullable.h>
|
#include <Columns/ColumnNullable.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -59,7 +60,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnUInt64 &>(to).getData().push_back(data(place).count);
|
assert_cast<ColumnUInt64 &>(to).getData().push_back(data(place).count);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override { return __FILE__; }
|
const char * getHeaderFilePath() const override { return __FILE__; }
|
||||||
@ -86,7 +87,7 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||||
{
|
{
|
||||||
data(place).count += !static_cast<const ColumnNullable &>(*columns[0]).isNullAt(row_num);
|
data(place).count += !assert_cast<const ColumnNullable &>(*columns[0]).isNullAt(row_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
||||||
@ -106,7 +107,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnUInt64 &>(to).getData().push_back(data(place).count);
|
assert_cast<ColumnUInt64 &>(to).getData().push_back(data(place).count);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override { return __FILE__; }
|
const char * getHeaderFilePath() const override { return __FILE__; }
|
||||||
@ -143,7 +144,7 @@ public:
|
|||||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < number_of_arguments; ++i)
|
for (size_t i = 0; i < number_of_arguments; ++i)
|
||||||
if (is_nullable[i] && static_cast<const ColumnNullable &>(*columns[i]).isNullAt(row_num))
|
if (is_nullable[i] && assert_cast<const ColumnNullable &>(*columns[i]).isNullAt(row_num))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
++data(place).count;
|
++data(place).count;
|
||||||
@ -166,7 +167,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnUInt64 &>(to).getData().push_back(data(place).count);
|
assert_cast<ColumnUInt64 &>(to).getData().push_back(data(place).count);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override { return __FILE__; }
|
const char * getHeaderFilePath() const override { return __FILE__; }
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <AggregateFunctions/UniqVariadicHash.h>
|
#include <AggregateFunctions/UniqVariadicHash.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <Columns/ColumnVector.h>
|
#include <Columns/ColumnVector.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ public:
|
|||||||
if constexpr (!std::is_same_v<UInt128, Value>)
|
if constexpr (!std::is_same_v<UInt128, Value>)
|
||||||
{
|
{
|
||||||
/// Here we manage only with numerical types
|
/// Here we manage only with numerical types
|
||||||
const auto & column = static_cast<const ColumnVector <Value> &>(*columns[0]);
|
const auto & column = assert_cast<const ColumnVector <Value> &>(*columns[0]);
|
||||||
this->data(place).add(column.getData()[row_num]);
|
this->data(place).add(column.getData()[row_num]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -141,7 +142,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
auto & column = static_cast<ColumnVector<Float64> &>(to);
|
auto & column = assert_cast<ColumnVector<Float64> &>(to);
|
||||||
column.getData().push_back(this->data(place).get());
|
column.getData().push_back(this->data(place).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Columns/ColumnArray.h>
|
#include <Columns/ColumnArray.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <DataTypes/DataTypeArray.h>
|
#include <DataTypes/DataTypeArray.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
|
||||||
@ -149,9 +150,9 @@ public:
|
|||||||
const IColumn * nested[num_arguments];
|
const IColumn * nested[num_arguments];
|
||||||
|
|
||||||
for (size_t i = 0; i < num_arguments; ++i)
|
for (size_t i = 0; i < num_arguments; ++i)
|
||||||
nested[i] = &static_cast<const ColumnArray &>(*columns[i]).getData();
|
nested[i] = &assert_cast<const ColumnArray &>(*columns[i]).getData();
|
||||||
|
|
||||||
const ColumnArray & first_array_column = static_cast<const ColumnArray &>(*columns[0]);
|
const ColumnArray & first_array_column = assert_cast<const ColumnArray &>(*columns[0]);
|
||||||
const IColumn::Offsets & offsets = first_array_column.getOffsets();
|
const IColumn::Offsets & offsets = first_array_column.getOffsets();
|
||||||
|
|
||||||
size_t begin = offsets[row_num - 1];
|
size_t begin = offsets[row_num - 1];
|
||||||
@ -160,7 +161,7 @@ public:
|
|||||||
/// Sanity check. NOTE We can implement specialization for a case with single argument, if the check will hurt performance.
|
/// Sanity check. NOTE We can implement specialization for a case with single argument, if the check will hurt performance.
|
||||||
for (size_t i = 1; i < num_arguments; ++i)
|
for (size_t i = 1; i < num_arguments; ++i)
|
||||||
{
|
{
|
||||||
const ColumnArray & ith_column = static_cast<const ColumnArray &>(*columns[i]);
|
const ColumnArray & ith_column = assert_cast<const ColumnArray &>(*columns[i]);
|
||||||
const IColumn::Offsets & ith_offsets = ith_column.getOffsets();
|
const IColumn::Offsets & ith_offsets = ith_column.getOffsets();
|
||||||
|
|
||||||
if (ith_offsets[row_num] != end || (row_num != 0 && ith_offsets[row_num - 1] != begin))
|
if (ith_offsets[row_num] != end || (row_num != 0 && ith_offsets[row_num - 1] != begin))
|
||||||
@ -228,7 +229,7 @@ public:
|
|||||||
{
|
{
|
||||||
const AggregateFunctionForEachData & state = data(place);
|
const AggregateFunctionForEachData & state = data(place);
|
||||||
|
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
IColumn & elems_to = arr_to.getData();
|
IColumn & elems_to = arr_to.getData();
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <Columns/ColumnString.h>
|
#include <Columns/ColumnString.h>
|
||||||
|
|
||||||
#include <Common/ArenaAllocator.h>
|
#include <Common/ArenaAllocator.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ public:
|
|||||||
if (limit_num_elems && this->data(place).value.size() >= max_elems)
|
if (limit_num_elems && this->data(place).value.size() >= max_elems)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this->data(place).value.push_back(static_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num], arena);
|
this->data(place).value.push_back(assert_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num], arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||||
@ -119,14 +120,14 @@ public:
|
|||||||
const auto & value = this->data(place).value;
|
const auto & value = this->data(place).value;
|
||||||
size_t size = value.size();
|
size_t size = value.size();
|
||||||
|
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
|
|
||||||
offsets_to.push_back(offsets_to.back() + size);
|
offsets_to.push_back(offsets_to.back() + size);
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
{
|
{
|
||||||
typename ColumnVector<T>::Container & data_to = static_cast<ColumnVector<T> &>(arr_to.getData()).getData();
|
typename ColumnVector<T>::Container & data_to = assert_cast<ColumnVector<T> &>(arr_to.getData()).getData();
|
||||||
data_to.insert(this->data(place).value.begin(), this->data(place).value.end());
|
data_to.insert(this->data(place).value.begin(), this->data(place).value.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,7 +192,7 @@ struct GroupArrayListNodeString : public GroupArrayListNodeBase<GroupArrayListNo
|
|||||||
/// Create node from string
|
/// Create node from string
|
||||||
static Node * allocate(const IColumn & column, size_t row_num, Arena * arena)
|
static Node * allocate(const IColumn & column, size_t row_num, Arena * arena)
|
||||||
{
|
{
|
||||||
StringRef string = static_cast<const ColumnString &>(column).getDataAt(row_num);
|
StringRef string = assert_cast<const ColumnString &>(column).getDataAt(row_num);
|
||||||
|
|
||||||
Node * node = reinterpret_cast<Node *>(arena->alignedAlloc(sizeof(Node) + string.size, alignof(Node)));
|
Node * node = reinterpret_cast<Node *>(arena->alignedAlloc(sizeof(Node) + string.size, alignof(Node)));
|
||||||
node->next = nullptr;
|
node->next = nullptr;
|
||||||
@ -203,7 +204,7 @@ struct GroupArrayListNodeString : public GroupArrayListNodeBase<GroupArrayListNo
|
|||||||
|
|
||||||
void insertInto(IColumn & column)
|
void insertInto(IColumn & column)
|
||||||
{
|
{
|
||||||
static_cast<ColumnString &>(column).insertData(data(), size);
|
assert_cast<ColumnString &>(column).insertData(data(), size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -374,7 +375,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
auto & column_array = static_cast<ColumnArray &>(to);
|
auto & column_array = assert_cast<ColumnArray &>(to);
|
||||||
|
|
||||||
auto & offsets = column_array.getOffsets();
|
auto & offsets = column_array.getOffsets();
|
||||||
offsets.push_back(offsets.back() + data(place).elems);
|
offsets.push_back(offsets.back() + data(place).elems);
|
||||||
@ -383,7 +384,7 @@ public:
|
|||||||
|
|
||||||
if (std::is_same_v<Node, GroupArrayListNodeString>)
|
if (std::is_same_v<Node, GroupArrayListNodeString>)
|
||||||
{
|
{
|
||||||
auto & string_offsets = static_cast<ColumnString &>(column_data).getOffsets();
|
auto & string_offsets = assert_cast<ColumnString &>(column_data).getOffsets();
|
||||||
string_offsets.reserve(string_offsets.size() + data(place).elems);
|
string_offsets.reserve(string_offsets.size() + data(place).elems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <Columns/ColumnVector.h>
|
#include <Columns/ColumnVector.h>
|
||||||
|
|
||||||
#include <Common/FieldVisitors.h>
|
#include <Common/FieldVisitors.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <Interpreters/convertFieldToType.h>
|
#include <Interpreters/convertFieldToType.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
@ -180,7 +181,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
ColumnArray & to_array = static_cast<ColumnArray &>(to);
|
ColumnArray & to_array = assert_cast<ColumnArray &>(to);
|
||||||
IColumn & to_data = to_array.getData();
|
IColumn & to_data = to_array.getData();
|
||||||
ColumnArray::Offsets & to_offsets = to_array.getOffsets();
|
ColumnArray::Offsets & to_offsets = to_array.getOffsets();
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <Columns/ColumnArray.h>
|
#include <Columns/ColumnArray.h>
|
||||||
|
|
||||||
#include <Common/ArenaAllocator.h>
|
#include <Common/ArenaAllocator.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ public:
|
|||||||
const auto & data = this->data(place);
|
const auto & data = this->data(place);
|
||||||
size_t size = data.value.size();
|
size_t size = data.value.size();
|
||||||
|
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
|
|
||||||
offsets_to.push_back(offsets_to.back() + size);
|
offsets_to.push_back(offsets_to.back() + size);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Columns/ColumnVector.h>
|
#include <Columns/ColumnVector.h>
|
||||||
#include <boost/noncopyable.hpp>
|
#include <Common/assert_cast.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <AggregateFunctions/AggregateFunctionGroupBitmapData.h>
|
#include <AggregateFunctions/AggregateFunctionGroupBitmapData.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
@ -26,7 +26,7 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||||
{
|
{
|
||||||
this->data(place).rbs.add(static_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num]);
|
this->data(place).rbs.add(assert_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
||||||
@ -46,7 +46,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnVector<T> &>(to).getData().push_back(this->data(place).rbs.size());
|
assert_cast<ColumnVector<T> &>(to).getData().push_back(this->data(place).rbs.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override { return __FILE__; }
|
const char * getHeaderFilePath() const override { return __FILE__; }
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <Columns/ColumnArray.h>
|
#include <Columns/ColumnArray.h>
|
||||||
|
|
||||||
#include <Common/HashTable/HashSet.h>
|
#include <Common/HashTable/HashSet.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (limit_num_elems && this->data(place).value.size() >= max_elems)
|
if (limit_num_elems && this->data(place).value.size() >= max_elems)
|
||||||
return;
|
return;
|
||||||
this->data(place).value.insert(static_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num]);
|
this->data(place).value.insert(assert_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
||||||
@ -89,7 +90,7 @@ public:
|
|||||||
auto & set = this->data(place).value;
|
auto & set = this->data(place).value;
|
||||||
size_t size = set.size();
|
size_t size = set.size();
|
||||||
writeVarUInt(size, buf);
|
writeVarUInt(size, buf);
|
||||||
for (auto & elem : set)
|
for (const auto & elem : set)
|
||||||
writeIntBinary(elem, buf);
|
writeIntBinary(elem, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
|
|
||||||
const typename State::Set & set = this->data(place).value;
|
const typename State::Set & set = this->data(place).value;
|
||||||
@ -108,7 +109,7 @@ public:
|
|||||||
|
|
||||||
offsets_to.push_back(offsets_to.back() + size);
|
offsets_to.push_back(offsets_to.back() + size);
|
||||||
|
|
||||||
typename ColumnVector<T>::Container & data_to = static_cast<ColumnVector<T> &>(arr_to.getData()).getData();
|
typename ColumnVector<T>::Container & data_to = assert_cast<ColumnVector<T> &>(arr_to.getData()).getData();
|
||||||
size_t old_size = data_to.size();
|
size_t old_size = data_to.size();
|
||||||
data_to.resize(old_size + size);
|
data_to.resize(old_size + size);
|
||||||
|
|
||||||
@ -254,7 +255,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
IColumn & data_to = arr_to.getData();
|
IColumn & data_to = arr_to.getData();
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <Columns/ColumnVector.h>
|
#include <Columns/ColumnVector.h>
|
||||||
#include <Columns/ColumnTuple.h>
|
#include <Columns/ColumnTuple.h>
|
||||||
#include <Columns/ColumnArray.h>
|
#include <Columns/ColumnArray.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <DataTypes/DataTypeArray.h>
|
#include <DataTypes/DataTypeArray.h>
|
||||||
@ -333,7 +334,7 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||||
{
|
{
|
||||||
auto val = static_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num];
|
auto val = assert_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num];
|
||||||
this->data(place).add(static_cast<Data::Mean>(val), 1, max_bins);
|
this->data(place).add(static_cast<Data::Mean>(val), 1, max_bins);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,13 +357,13 @@ public:
|
|||||||
{
|
{
|
||||||
auto & data = this->data(const_cast<AggregateDataPtr>(place));
|
auto & data = this->data(const_cast<AggregateDataPtr>(place));
|
||||||
|
|
||||||
auto & to_array = static_cast<ColumnArray &>(to);
|
auto & to_array = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = to_array.getOffsets();
|
ColumnArray::Offsets & offsets_to = to_array.getOffsets();
|
||||||
auto & to_tuple = static_cast<ColumnTuple &>(to_array.getData());
|
auto & to_tuple = assert_cast<ColumnTuple &>(to_array.getData());
|
||||||
|
|
||||||
auto & to_lower = static_cast<ColumnVector<Data::Mean> &>(to_tuple.getColumn(0));
|
auto & to_lower = assert_cast<ColumnVector<Data::Mean> &>(to_tuple.getColumn(0));
|
||||||
auto & to_upper = static_cast<ColumnVector<Data::Mean> &>(to_tuple.getColumn(1));
|
auto & to_upper = assert_cast<ColumnVector<Data::Mean> &>(to_tuple.getColumn(1));
|
||||||
auto & to_weights = static_cast<ColumnVector<Data::Weight> &>(to_tuple.getColumn(2));
|
auto & to_weights = assert_cast<ColumnVector<Data::Weight> &>(to_tuple.getColumn(2));
|
||||||
data.insertResultInto(to_lower, to_upper, to_weights, max_bins);
|
data.insertResultInto(to_lower, to_upper, to_weights, max_bins);
|
||||||
|
|
||||||
offsets_to.push_back(to_tuple.size());
|
offsets_to.push_back(to_tuple.size());
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <Columns/ColumnsNumber.h>
|
#include <Columns/ColumnsNumber.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
||||||
{
|
{
|
||||||
if (static_cast<const ColumnUInt8 &>(*columns[num_arguments - 1]).getData()[row_num])
|
if (assert_cast<const ColumnUInt8 &>(*columns[num_arguments - 1]).getData()[row_num])
|
||||||
nested_func->add(place, columns, row_num, arena);
|
nested_func->add(place, columns, row_num, arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <Columns/ColumnTuple.h>
|
#include <Columns/ColumnTuple.h>
|
||||||
#include <Common/FieldVisitors.h>
|
#include <Common/FieldVisitors.h>
|
||||||
#include <Common/typeid_cast.h>
|
#include <Common/typeid_cast.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include "AggregateFunctionFactory.h"
|
#include "AggregateFunctionFactory.h"
|
||||||
#include "FactoryHelpers.h"
|
#include "FactoryHelpers.h"
|
||||||
#include "Helpers.h"
|
#include "Helpers.h"
|
||||||
@ -147,14 +148,14 @@ void LinearModelData::returnWeights(IColumn & to) const
|
|||||||
{
|
{
|
||||||
size_t size = weights.size() + 1;
|
size_t size = weights.size() + 1;
|
||||||
|
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
|
|
||||||
size_t old_size = offsets_to.back();
|
size_t old_size = offsets_to.back();
|
||||||
offsets_to.push_back(old_size + size);
|
offsets_to.push_back(old_size + size);
|
||||||
|
|
||||||
typename ColumnFloat64::Container & val_to
|
typename ColumnFloat64::Container & val_to
|
||||||
= static_cast<ColumnFloat64 &>(arr_to.getData()).getData();
|
= assert_cast<ColumnFloat64 &>(arr_to.getData()).getData();
|
||||||
|
|
||||||
val_to.reserve(old_size + size);
|
val_to.reserve(old_size + size);
|
||||||
for (size_t i = 0; i + 1 < size; ++i)
|
for (size_t i = 0; i + 1 < size; ++i)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <Common/ArenaAllocator.h>
|
#include <Common/ArenaAllocator.h>
|
||||||
#include <Common/NaNUtils.h>
|
#include <Common/NaNUtils.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
|
||||||
@ -88,8 +89,8 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
||||||
{
|
{
|
||||||
PointType left = static_cast<const ColumnVector<PointType> &>(*columns[0]).getData()[row_num];
|
PointType left = assert_cast<const ColumnVector<PointType> &>(*columns[0]).getData()[row_num];
|
||||||
PointType right = static_cast<const ColumnVector<PointType> &>(*columns[1]).getData()[row_num];
|
PointType right = assert_cast<const ColumnVector<PointType> &>(*columns[1]).getData()[row_num];
|
||||||
|
|
||||||
if (!isNaN(left))
|
if (!isNaN(left))
|
||||||
this->data(place).value.push_back(std::make_pair(left, Int64(1)), arena);
|
this->data(place).value.push_back(std::make_pair(left, Int64(1)), arena);
|
||||||
@ -152,12 +153,12 @@ public:
|
|||||||
|
|
||||||
if (kind == AggregateFunctionIntersectionsKind::Count)
|
if (kind == AggregateFunctionIntersectionsKind::Count)
|
||||||
{
|
{
|
||||||
auto & result_column = static_cast<ColumnUInt64 &>(to).getData();
|
auto & result_column = assert_cast<ColumnUInt64 &>(to).getData();
|
||||||
result_column.push_back(max_intersections);
|
result_column.push_back(max_intersections);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto & result_column = static_cast<ColumnVector<PointType> &>(to).getData();
|
auto & result_column = assert_cast<ColumnVector<PointType> &>(to).getData();
|
||||||
result_column.push_back(position_of_max_intersections);
|
result_column.push_back(position_of_max_intersections);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <Columns/ColumnAggregateFunction.h>
|
#include <Columns/ColumnAggregateFunction.h>
|
||||||
#include <Common/typeid_cast.h>
|
#include <Common/typeid_cast.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -70,7 +71,7 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
||||||
{
|
{
|
||||||
nested_func->merge(place, static_cast<const ColumnAggregateFunction &>(*columns[0]).getData()[row_num], arena);
|
nested_func->merge(place, assert_cast<const ColumnAggregateFunction &>(*columns[0]).getData()[row_num], arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <Columns/ColumnString.h>
|
#include <Columns/ColumnString.h>
|
||||||
#include <DataTypes/IDataType.h>
|
#include <DataTypes/IDataType.h>
|
||||||
#include <common/StringRef.h>
|
#include <common/StringRef.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
|
||||||
@ -38,9 +39,9 @@ public:
|
|||||||
void insertResultInto(IColumn & to) const
|
void insertResultInto(IColumn & to) const
|
||||||
{
|
{
|
||||||
if (has())
|
if (has())
|
||||||
static_cast<ColumnVector<T> &>(to).getData().push_back(value);
|
assert_cast<ColumnVector<T> &>(to).getData().push_back(value);
|
||||||
else
|
else
|
||||||
static_cast<ColumnVector<T> &>(to).insertDefault();
|
assert_cast<ColumnVector<T> &>(to).insertDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(WriteBuffer & buf, const IDataType & /*data_type*/) const
|
void write(WriteBuffer & buf, const IDataType & /*data_type*/) const
|
||||||
@ -61,7 +62,7 @@ public:
|
|||||||
void change(const IColumn & column, size_t row_num, Arena *)
|
void change(const IColumn & column, size_t row_num, Arena *)
|
||||||
{
|
{
|
||||||
has_value = true;
|
has_value = true;
|
||||||
value = static_cast<const ColumnVector<T> &>(column).getData()[row_num];
|
value = assert_cast<const ColumnVector<T> &>(column).getData()[row_num];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assuming to.has()
|
/// Assuming to.has()
|
||||||
@ -112,7 +113,7 @@ public:
|
|||||||
|
|
||||||
bool changeIfLess(const IColumn & column, size_t row_num, Arena * arena)
|
bool changeIfLess(const IColumn & column, size_t row_num, Arena * arena)
|
||||||
{
|
{
|
||||||
if (!has() || static_cast<const ColumnVector<T> &>(column).getData()[row_num] < value)
|
if (!has() || assert_cast<const ColumnVector<T> &>(column).getData()[row_num] < value)
|
||||||
{
|
{
|
||||||
change(column, row_num, arena);
|
change(column, row_num, arena);
|
||||||
return true;
|
return true;
|
||||||
@ -134,7 +135,7 @@ public:
|
|||||||
|
|
||||||
bool changeIfGreater(const IColumn & column, size_t row_num, Arena * arena)
|
bool changeIfGreater(const IColumn & column, size_t row_num, Arena * arena)
|
||||||
{
|
{
|
||||||
if (!has() || static_cast<const ColumnVector<T> &>(column).getData()[row_num] > value)
|
if (!has() || assert_cast<const ColumnVector<T> &>(column).getData()[row_num] > value)
|
||||||
{
|
{
|
||||||
change(column, row_num, arena);
|
change(column, row_num, arena);
|
||||||
return true;
|
return true;
|
||||||
@ -161,7 +162,7 @@ public:
|
|||||||
|
|
||||||
bool isEqualTo(const IColumn & column, size_t row_num) const
|
bool isEqualTo(const IColumn & column, size_t row_num) const
|
||||||
{
|
{
|
||||||
return has() && static_cast<const ColumnVector<T> &>(column).getData()[row_num] == value;
|
return has() && assert_cast<const ColumnVector<T> &>(column).getData()[row_num] == value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -204,9 +205,9 @@ public:
|
|||||||
void insertResultInto(IColumn & to) const
|
void insertResultInto(IColumn & to) const
|
||||||
{
|
{
|
||||||
if (has())
|
if (has())
|
||||||
static_cast<ColumnString &>(to).insertDataWithTerminatingZero(getData(), size);
|
assert_cast<ColumnString &>(to).insertDataWithTerminatingZero(getData(), size);
|
||||||
else
|
else
|
||||||
static_cast<ColumnString &>(to).insertDefault();
|
assert_cast<ColumnString &>(to).insertDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(WriteBuffer & buf, const IDataType & /*data_type*/) const
|
void write(WriteBuffer & buf, const IDataType & /*data_type*/) const
|
||||||
@ -281,7 +282,7 @@ public:
|
|||||||
|
|
||||||
void change(const IColumn & column, size_t row_num, Arena * arena)
|
void change(const IColumn & column, size_t row_num, Arena * arena)
|
||||||
{
|
{
|
||||||
changeImpl(static_cast<const ColumnString &>(column).getDataAtWithTerminatingZero(row_num), arena);
|
changeImpl(assert_cast<const ColumnString &>(column).getDataAtWithTerminatingZero(row_num), arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
void change(const Self & to, Arena * arena)
|
void change(const Self & to, Arena * arena)
|
||||||
@ -330,7 +331,7 @@ public:
|
|||||||
|
|
||||||
bool changeIfLess(const IColumn & column, size_t row_num, Arena * arena)
|
bool changeIfLess(const IColumn & column, size_t row_num, Arena * arena)
|
||||||
{
|
{
|
||||||
if (!has() || static_cast<const ColumnString &>(column).getDataAtWithTerminatingZero(row_num) < getStringRef())
|
if (!has() || assert_cast<const ColumnString &>(column).getDataAtWithTerminatingZero(row_num) < getStringRef())
|
||||||
{
|
{
|
||||||
change(column, row_num, arena);
|
change(column, row_num, arena);
|
||||||
return true;
|
return true;
|
||||||
@ -352,7 +353,7 @@ public:
|
|||||||
|
|
||||||
bool changeIfGreater(const IColumn & column, size_t row_num, Arena * arena)
|
bool changeIfGreater(const IColumn & column, size_t row_num, Arena * arena)
|
||||||
{
|
{
|
||||||
if (!has() || static_cast<const ColumnString &>(column).getDataAtWithTerminatingZero(row_num) > getStringRef())
|
if (!has() || assert_cast<const ColumnString &>(column).getDataAtWithTerminatingZero(row_num) > getStringRef())
|
||||||
{
|
{
|
||||||
change(column, row_num, arena);
|
change(column, row_num, arena);
|
||||||
return true;
|
return true;
|
||||||
@ -379,7 +380,7 @@ public:
|
|||||||
|
|
||||||
bool isEqualTo(const IColumn & column, size_t row_num) const
|
bool isEqualTo(const IColumn & column, size_t row_num) const
|
||||||
{
|
{
|
||||||
return has() && static_cast<const ColumnString &>(column).getDataAtWithTerminatingZero(row_num) == getStringRef();
|
return has() && assert_cast<const ColumnString &>(column).getDataAtWithTerminatingZero(row_num) == getStringRef();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <Columns/ColumnNullable.h>
|
#include <Columns/ColumnNullable.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <DataTypes/DataTypeNullable.h>
|
#include <DataTypes/DataTypeNullable.h>
|
||||||
#include <IO/ReadHelpers.h>
|
#include <IO/ReadHelpers.h>
|
||||||
#include <IO/WriteHelpers.h>
|
#include <IO/WriteHelpers.h>
|
||||||
@ -149,7 +150,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (result_is_nullable)
|
if (result_is_nullable)
|
||||||
{
|
{
|
||||||
ColumnNullable & to_concrete = static_cast<ColumnNullable &>(to);
|
ColumnNullable & to_concrete = assert_cast<ColumnNullable &>(to);
|
||||||
if (getFlag(place))
|
if (getFlag(place))
|
||||||
{
|
{
|
||||||
nested_function->insertResultInto(nestedPlace(place), to_concrete.getNestedColumn());
|
nested_function->insertResultInto(nestedPlace(place), to_concrete.getNestedColumn());
|
||||||
@ -194,7 +195,7 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
||||||
{
|
{
|
||||||
const ColumnNullable * column = static_cast<const ColumnNullable *>(columns[0]);
|
const ColumnNullable * column = assert_cast<const ColumnNullable *>(columns[0]);
|
||||||
if (!column->isNullAt(row_num))
|
if (!column->isNullAt(row_num))
|
||||||
{
|
{
|
||||||
this->setFlag(place);
|
this->setFlag(place);
|
||||||
@ -233,7 +234,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (is_nullable[i])
|
if (is_nullable[i])
|
||||||
{
|
{
|
||||||
const ColumnNullable & nullable_col = static_cast<const ColumnNullable &>(*columns[i]);
|
const ColumnNullable & nullable_col = assert_cast<const ColumnNullable &>(*columns[i]);
|
||||||
if (nullable_col.isNullAt(row_num))
|
if (nullable_col.isNullAt(row_num))
|
||||||
{
|
{
|
||||||
/// If at least one column has a null value in the current row,
|
/// If at least one column has a null value in the current row,
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <IO/ReadHelpers.h>
|
#include <IO/ReadHelpers.h>
|
||||||
#include <IO/WriteHelpers.h>
|
#include <IO/WriteHelpers.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
@ -143,7 +144,7 @@ public:
|
|||||||
|
|
||||||
if constexpr (returns_many)
|
if constexpr (returns_many)
|
||||||
{
|
{
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
|
|
||||||
size_t size = levels.size();
|
size_t size = levels.size();
|
||||||
@ -154,7 +155,7 @@ public:
|
|||||||
|
|
||||||
if constexpr (returns_float)
|
if constexpr (returns_float)
|
||||||
{
|
{
|
||||||
auto & data_to = static_cast<ColumnVector<FloatReturnType> &>(arr_to.getData()).getData();
|
auto & data_to = assert_cast<ColumnVector<FloatReturnType> &>(arr_to.getData()).getData();
|
||||||
size_t old_size = data_to.size();
|
size_t old_size = data_to.size();
|
||||||
data_to.resize(data_to.size() + size);
|
data_to.resize(data_to.size() + size);
|
||||||
|
|
||||||
@ -172,7 +173,7 @@ public:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if constexpr (returns_float)
|
if constexpr (returns_float)
|
||||||
static_cast<ColumnVector<FloatReturnType> &>(to).getData().push_back(data.getFloat(level));
|
assert_cast<ColumnVector<FloatReturnType> &>(to).getData().push_back(data.getFloat(level));
|
||||||
else
|
else
|
||||||
static_cast<ColVecType &>(to).getData().push_back(data.get(level));
|
static_cast<ColVecType &>(to).getData().push_back(data.get(level));
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <Columns/ColumnArray.h>
|
#include <Columns/ColumnArray.h>
|
||||||
#include <DataTypes/DataTypeArray.h>
|
#include <DataTypes/DataTypeArray.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -169,8 +170,8 @@ public:
|
|||||||
ConstAggregateDataPtr place,
|
ConstAggregateDataPtr place,
|
||||||
IColumn & to) const override
|
IColumn & to) const override
|
||||||
{
|
{
|
||||||
auto & col = static_cast<ColumnArray &>(to);
|
auto & col = assert_cast<ColumnArray &>(to);
|
||||||
auto & col_offsets = static_cast<ColumnArray::ColumnOffsets &>(col.getOffsetsColumn());
|
auto & col_offsets = assert_cast<ColumnArray::ColumnOffsets &>(col.getOffsetsColumn());
|
||||||
|
|
||||||
for (size_t i = 0; i < total; ++i)
|
for (size_t i = 0; i < total; ++i)
|
||||||
nested_function->insertResultInto(place + i * sod, col.getData());
|
nested_function->insertResultInto(place + i * sod, col.getData());
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <Columns/ColumnsNumber.h>
|
#include <Columns/ColumnsNumber.h>
|
||||||
#include <Columns/ColumnArray.h>
|
#include <Columns/ColumnArray.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <DataTypes/DataTypeArray.h>
|
#include <DataTypes/DataTypeArray.h>
|
||||||
#include <IO/ReadHelpers.h>
|
#include <IO/ReadHelpers.h>
|
||||||
@ -100,7 +101,7 @@ public:
|
|||||||
{
|
{
|
||||||
for (const auto i : ext::range(0, events_size))
|
for (const auto i : ext::range(0, events_size))
|
||||||
{
|
{
|
||||||
auto event = static_cast<const ColumnVector<UInt8> *>(columns[i])->getData()[row_num];
|
auto event = assert_cast<const ColumnVector<UInt8> *>(columns[i])->getData()[row_num];
|
||||||
if (event)
|
if (event)
|
||||||
{
|
{
|
||||||
this->data(place).add(i);
|
this->data(place).add(i);
|
||||||
@ -125,8 +126,8 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
auto & data_to = static_cast<ColumnUInt8 &>(static_cast<ColumnArray &>(to).getData()).getData();
|
auto & data_to = assert_cast<ColumnUInt8 &>(assert_cast<ColumnArray &>(to).getData()).getData();
|
||||||
auto & offsets_to = static_cast<ColumnArray &>(to).getOffsets();
|
auto & offsets_to = assert_cast<ColumnArray &>(to).getOffsets();
|
||||||
|
|
||||||
ColumnArray::Offset current_offset = data_to.size();
|
ColumnArray::Offset current_offset = data_to.size();
|
||||||
data_to.resize(current_offset + events_size);
|
data_to.resize(current_offset + events_size);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <DataTypes/DataTypeDateTime.h>
|
#include <DataTypes/DataTypeDateTime.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <Columns/ColumnsNumber.h>
|
#include <Columns/ColumnsNumber.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <ext/range.h>
|
#include <ext/range.h>
|
||||||
#include <Common/PODArray.h>
|
#include <Common/PODArray.h>
|
||||||
#include <IO/ReadHelpers.h>
|
#include <IO/ReadHelpers.h>
|
||||||
@ -152,12 +153,12 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num, Arena *) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num, Arena *) const override
|
||||||
{
|
{
|
||||||
const auto timestamp = static_cast<const ColumnVector<T> *>(columns[0])->getData()[row_num];
|
const auto timestamp = assert_cast<const ColumnVector<T> *>(columns[0])->getData()[row_num];
|
||||||
|
|
||||||
typename Data::Events events;
|
typename Data::Events events;
|
||||||
for (const auto i : ext::range(1, arg_count))
|
for (const auto i : ext::range(1, arg_count))
|
||||||
{
|
{
|
||||||
const auto event = static_cast<const ColumnUInt8 *>(columns[i])->getData()[row_num];
|
const auto event = assert_cast<const ColumnUInt8 *>(columns[i])->getData()[row_num];
|
||||||
events.set(i - 1, event);
|
events.set(i - 1, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,7 +575,7 @@ public:
|
|||||||
auto events_it = events_begin;
|
auto events_it = events_begin;
|
||||||
|
|
||||||
bool match = this->pattern_has_time ? this->backtrackingMatch(events_it, events_end) : this->dfaMatch(events_it, events_end);
|
bool match = this->pattern_has_time ? this->backtrackingMatch(events_it, events_end) : this->dfaMatch(events_it, events_end);
|
||||||
static_cast<ColumnUInt8 &>(to).getData().push_back(match);
|
assert_cast<ColumnUInt8 &>(to).getData().push_back(match);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -594,7 +595,7 @@ public:
|
|||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
const_cast<Data &>(this->data(place)).sort();
|
const_cast<Data &>(this->data(place)).sort();
|
||||||
static_cast<ColumnUInt64 &>(to).getData().push_back(count(place));
|
assert_cast<ColumnUInt64 &>(to).getData().push_back(count(place));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <Columns/ColumnVector.h>
|
#include <Columns/ColumnVector.h>
|
||||||
#include <Columns/ColumnTuple.h>
|
#include <Columns/ColumnTuple.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <DataTypes/DataTypeNullable.h>
|
#include <DataTypes/DataTypeNullable.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <DataTypes/DataTypeTuple.h>
|
#include <DataTypes/DataTypeTuple.h>
|
||||||
@ -120,8 +121,8 @@ public:
|
|||||||
Arena *
|
Arena *
|
||||||
) const override
|
) const override
|
||||||
{
|
{
|
||||||
auto col_x = static_cast<const ColumnVector<X> *>(columns[0]);
|
auto col_x = assert_cast<const ColumnVector<X> *>(columns[0]);
|
||||||
auto col_y = static_cast<const ColumnVector<Y> *>(columns[1]);
|
auto col_y = assert_cast<const ColumnVector<Y> *>(columns[1]);
|
||||||
|
|
||||||
X x = col_x->getData()[row_num];
|
X x = col_x->getData()[row_num];
|
||||||
Y y = col_y->getData()[row_num];
|
Y y = col_y->getData()[row_num];
|
||||||
@ -181,9 +182,9 @@ public:
|
|||||||
Ret k = this->data(place).getK();
|
Ret k = this->data(place).getK();
|
||||||
Ret b = this->data(place).getB(k);
|
Ret b = this->data(place).getB(k);
|
||||||
|
|
||||||
auto & col_tuple = static_cast<ColumnTuple &>(to);
|
auto & col_tuple = assert_cast<ColumnTuple &>(to);
|
||||||
auto & col_k = static_cast<ColumnVector<Ret> &>(col_tuple.getColumn(0));
|
auto & col_k = assert_cast<ColumnVector<Ret> &>(col_tuple.getColumn(0));
|
||||||
auto & col_b = static_cast<ColumnVector<Ret> &>(col_tuple.getColumn(1));
|
auto & col_b = assert_cast<ColumnVector<Ret> &>(col_tuple.getColumn(1));
|
||||||
|
|
||||||
col_k.getData().push_back(k);
|
col_k.getData().push_back(k);
|
||||||
col_b.getData().push_back(b);
|
col_b.getData().push_back(b);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <DataTypes/DataTypeAggregateFunction.h>
|
#include <DataTypes/DataTypeAggregateFunction.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <Columns/ColumnAggregateFunction.h>
|
#include <Columns/ColumnAggregateFunction.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -81,7 +82,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnAggregateFunction &>(to).getData().push_back(const_cast<AggregateDataPtr>(place));
|
assert_cast<ColumnAggregateFunction &>(to).getData().push_back(const_cast<AggregateDataPtr>(place));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Aggregate function or aggregate function state.
|
/// Aggregate function or aggregate function state.
|
||||||
|
@ -5,9 +5,11 @@
|
|||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <Columns/ColumnsNumber.h>
|
#include <Columns/ColumnsNumber.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ class AggregateFunctionVarianceData
|
|||||||
public:
|
public:
|
||||||
void update(const IColumn & column, size_t row_num)
|
void update(const IColumn & column, size_t row_num)
|
||||||
{
|
{
|
||||||
T received = static_cast<const ColumnVector<T> &>(column).getData()[row_num];
|
T received = assert_cast<const ColumnVector<T> &>(column).getData()[row_num];
|
||||||
Float64 val = static_cast<Float64>(received);
|
Float64 val = static_cast<Float64>(received);
|
||||||
Float64 delta = val - mean;
|
Float64 delta = val - mean;
|
||||||
|
|
||||||
@ -95,7 +97,7 @@ public:
|
|||||||
|
|
||||||
void publish(IColumn & to) const
|
void publish(IColumn & to) const
|
||||||
{
|
{
|
||||||
static_cast<ColumnFloat64 &>(to).getData().push_back(Op::apply(m2, count));
|
assert_cast<ColumnFloat64 &>(to).getData().push_back(Op::apply(m2, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -265,11 +267,11 @@ private:
|
|||||||
public:
|
public:
|
||||||
void update(const IColumn & column_left, const IColumn & column_right, size_t row_num)
|
void update(const IColumn & column_left, const IColumn & column_right, size_t row_num)
|
||||||
{
|
{
|
||||||
T left_received = static_cast<const ColumnVector<T> &>(column_left).getData()[row_num];
|
T left_received = assert_cast<const ColumnVector<T> &>(column_left).getData()[row_num];
|
||||||
Float64 left_val = static_cast<Float64>(left_received);
|
Float64 left_val = static_cast<Float64>(left_received);
|
||||||
Float64 left_delta = left_val - left_mean;
|
Float64 left_delta = left_val - left_mean;
|
||||||
|
|
||||||
U right_received = static_cast<const ColumnVector<U> &>(column_right).getData()[row_num];
|
U right_received = assert_cast<const ColumnVector<U> &>(column_right).getData()[row_num];
|
||||||
Float64 right_val = static_cast<Float64>(right_received);
|
Float64 right_val = static_cast<Float64>(right_received);
|
||||||
Float64 right_delta = right_val - right_mean;
|
Float64 right_delta = right_val - right_mean;
|
||||||
|
|
||||||
@ -345,9 +347,9 @@ public:
|
|||||||
void publish(IColumn & to) const
|
void publish(IColumn & to) const
|
||||||
{
|
{
|
||||||
if constexpr (compute_marginal_moments)
|
if constexpr (compute_marginal_moments)
|
||||||
static_cast<ColumnFloat64 &>(to).getData().push_back(Op::apply(co_moment, Base::left_m2, Base::right_m2, count));
|
assert_cast<ColumnFloat64 &>(to).getData().push_back(Op::apply(co_moment, Base::left_m2, Base::right_m2, count));
|
||||||
else
|
else
|
||||||
static_cast<ColumnFloat64 &>(to).getData().push_back(Op::apply(co_moment, count));
|
assert_cast<ColumnFloat64 &>(to).getData().push_back(Op::apply(co_moment, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <Columns/ColumnDecimal.h>
|
#include <Columns/ColumnDecimal.h>
|
||||||
|
|
||||||
#include <Common/FieldVisitors.h>
|
#include <Common/FieldVisitors.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ public:
|
|||||||
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num, Arena *) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num, Arena *) const override
|
||||||
{
|
{
|
||||||
// Column 0 contains array of keys of known type
|
// Column 0 contains array of keys of known type
|
||||||
const ColumnArray & array_column0 = static_cast<const ColumnArray &>(*columns[0]);
|
const ColumnArray & array_column0 = assert_cast<const ColumnArray &>(*columns[0]);
|
||||||
const IColumn::Offsets & offsets0 = array_column0.getOffsets();
|
const IColumn::Offsets & offsets0 = array_column0.getOffsets();
|
||||||
const auto & keys_vec = static_cast<const ColVecType &>(array_column0.getData());
|
const auto & keys_vec = static_cast<const ColVecType &>(array_column0.getData());
|
||||||
const size_t keys_vec_offset = offsets0[row_num - 1];
|
const size_t keys_vec_offset = offsets0[row_num - 1];
|
||||||
@ -94,7 +95,7 @@ public:
|
|||||||
for (size_t col = 0, size = values_types.size(); col < size; ++col)
|
for (size_t col = 0, size = values_types.size(); col < size; ++col)
|
||||||
{
|
{
|
||||||
Field value;
|
Field value;
|
||||||
const ColumnArray & array_column = static_cast<const ColumnArray &>(*columns[col + 1]);
|
const ColumnArray & array_column = assert_cast<const ColumnArray &>(*columns[col + 1]);
|
||||||
const IColumn::Offsets & offsets = array_column.getOffsets();
|
const IColumn::Offsets & offsets = array_column.getOffsets();
|
||||||
const size_t values_vec_offset = offsets[row_num - 1];
|
const size_t values_vec_offset = offsets[row_num - 1];
|
||||||
const size_t values_vec_size = (offsets[row_num] - values_vec_offset);
|
const size_t values_vec_size = (offsets[row_num] - values_vec_offset);
|
||||||
@ -228,8 +229,8 @@ public:
|
|||||||
|
|
||||||
size_t size = merged_maps.size();
|
size_t size = merged_maps.size();
|
||||||
|
|
||||||
auto & to_tuple = static_cast<ColumnTuple &>(to);
|
auto & to_tuple = assert_cast<ColumnTuple &>(to);
|
||||||
auto & to_keys_arr = static_cast<ColumnArray &>(to_tuple.getColumn(0));
|
auto & to_keys_arr = assert_cast<ColumnArray &>(to_tuple.getColumn(0));
|
||||||
auto & to_keys_col = to_keys_arr.getData();
|
auto & to_keys_col = to_keys_arr.getData();
|
||||||
|
|
||||||
// Advance column offsets
|
// Advance column offsets
|
||||||
@ -239,7 +240,7 @@ public:
|
|||||||
|
|
||||||
for (size_t col = 0; col < values_types.size(); ++col)
|
for (size_t col = 0; col < values_types.size(); ++col)
|
||||||
{
|
{
|
||||||
auto & to_values_arr = static_cast<ColumnArray &>(to_tuple.getColumn(col + 1));
|
auto & to_values_arr = assert_cast<ColumnArray &>(to_tuple.getColumn(col + 1));
|
||||||
auto & to_values_offsets = to_values_arr.getOffsets();
|
auto & to_values_offsets = to_values_arr.getOffsets();
|
||||||
to_values_offsets.push_back(to_values_offsets.back() + size);
|
to_values_offsets.push_back(to_values_offsets.back() + size);
|
||||||
to_values_arr.getData().reserve(size);
|
to_values_arr.getData().reserve(size);
|
||||||
@ -254,7 +255,7 @@ public:
|
|||||||
// Write 0..n arrays of values
|
// Write 0..n arrays of values
|
||||||
for (size_t col = 0; col < values_types.size(); ++col)
|
for (size_t col = 0; col < values_types.size(); ++col)
|
||||||
{
|
{
|
||||||
auto & to_values_col = static_cast<ColumnArray &>(to_tuple.getColumn(col + 1)).getData();
|
auto & to_values_col = assert_cast<ColumnArray &>(to_tuple.getColumn(col + 1)).getData();
|
||||||
to_values_col.insert(elem.second[col]);
|
to_values_col.insert(elem.second[col]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <IO/ReadHelpers.h>
|
#include <IO/ReadHelpers.h>
|
||||||
#include <IO/WriteHelpers.h>
|
#include <IO/WriteHelpers.h>
|
||||||
#include <Common/ArenaAllocator.h>
|
#include <Common/ArenaAllocator.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
#include <ext/range.h>
|
#include <ext/range.h>
|
||||||
#include "IAggregateFunction.h"
|
#include "IAggregateFunction.h"
|
||||||
|
|
||||||
@ -235,9 +236,9 @@ public:
|
|||||||
|
|
||||||
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num, Arena *) const override
|
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num, Arena *) const override
|
||||||
{
|
{
|
||||||
auto uid = static_cast<const ColumnVector<UInt64> *>(columns[0])->getData()[row_num];
|
auto uid = assert_cast<const ColumnVector<UInt64> *>(columns[0])->getData()[row_num];
|
||||||
auto ts = static_cast<const ColumnVector<Int64> *>(columns[1])->getData()[row_num];
|
auto ts = assert_cast<const ColumnVector<Int64> *>(columns[1])->getData()[row_num];
|
||||||
auto val = static_cast<const ColumnVector<Float64> *>(columns[2])->getData()[row_num];
|
auto val = assert_cast<const ColumnVector<Float64> *>(columns[2])->getData()[row_num];
|
||||||
if (uid && ts && val)
|
if (uid && ts && val)
|
||||||
{
|
{
|
||||||
this->data(place).add(uid, ts, val);
|
this->data(place).add(uid, ts, val);
|
||||||
@ -255,7 +256,7 @@ public:
|
|||||||
const auto & value = this->data(place).result;
|
const auto & value = this->data(place).result;
|
||||||
size_t size = value.size();
|
size_t size = value.size();
|
||||||
|
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
size_t old_size = offsets_to.back();
|
size_t old_size = offsets_to.back();
|
||||||
|
|
||||||
@ -264,9 +265,9 @@ public:
|
|||||||
if (size)
|
if (size)
|
||||||
{
|
{
|
||||||
typename ColumnInt64::Container & ts_to
|
typename ColumnInt64::Container & ts_to
|
||||||
= static_cast<ColumnInt64 &>(static_cast<ColumnTuple &>(arr_to.getData()).getColumn(0)).getData();
|
= assert_cast<ColumnInt64 &>(assert_cast<ColumnTuple &>(arr_to.getData()).getColumn(0)).getData();
|
||||||
typename ColumnFloat64::Container & val_to
|
typename ColumnFloat64::Container & val_to
|
||||||
= static_cast<ColumnFloat64 &>(static_cast<ColumnTuple &>(arr_to.getData()).getColumn(1)).getData();
|
= assert_cast<ColumnFloat64 &>(assert_cast<ColumnTuple &>(arr_to.getData()).getColumn(1)).getData();
|
||||||
ts_to.reserve(old_size + size);
|
ts_to.reserve(old_size + size);
|
||||||
val_to.reserve(old_size + size);
|
val_to.reserve(old_size + size);
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
#include <Columns/ColumnArray.h>
|
#include <Columns/ColumnArray.h>
|
||||||
|
|
||||||
#include <Common/SpaceSaving.h>
|
#include <Common/SpaceSaving.h>
|
||||||
|
|
||||||
#include <Common/FieldVisitors.h>
|
#include <Common/FieldVisitors.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
|
|
||||||
@ -62,9 +62,9 @@ public:
|
|||||||
set.resize(reserved);
|
set.resize(reserved);
|
||||||
|
|
||||||
if constexpr (is_weighted)
|
if constexpr (is_weighted)
|
||||||
set.insert(static_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num], columns[1]->getUInt(row_num));
|
set.insert(assert_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num], columns[1]->getUInt(row_num));
|
||||||
else
|
else
|
||||||
set.insert(static_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num]);
|
set.insert(assert_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override
|
||||||
@ -86,7 +86,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
|
|
||||||
const typename State::Set & set = this->data(place).value;
|
const typename State::Set & set = this->data(place).value;
|
||||||
@ -95,7 +95,7 @@ public:
|
|||||||
|
|
||||||
offsets_to.push_back(offsets_to.back() + size);
|
offsets_to.push_back(offsets_to.back() + size);
|
||||||
|
|
||||||
typename ColumnVector<T>::Container & data_to = static_cast<ColumnVector<T> &>(arr_to.getData()).getData();
|
typename ColumnVector<T>::Container & data_to = assert_cast<ColumnVector<T> &>(arr_to.getData()).getData();
|
||||||
size_t old_size = data_to.size();
|
size_t old_size = data_to.size();
|
||||||
data_to.resize(old_size + size);
|
data_to.resize(old_size + size);
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
ColumnArray & arr_to = assert_cast<ColumnArray &>(to);
|
||||||
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
ColumnArray::Offsets & offsets_to = arr_to.getOffsets();
|
||||||
IColumn & data_to = arr_to.getData();
|
IColumn & data_to = arr_to.getData();
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <Common/HyperLogLogWithSmallSetOptimization.h>
|
#include <Common/HyperLogLogWithSmallSetOptimization.h>
|
||||||
#include <Common/CombinedCardinalityEstimator.h>
|
#include <Common/CombinedCardinalityEstimator.h>
|
||||||
#include <Common/typeid_cast.h>
|
#include <Common/typeid_cast.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/UniquesHashSet.h>
|
#include <AggregateFunctions/UniquesHashSet.h>
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
@ -170,7 +171,7 @@ struct OneAdder
|
|||||||
{
|
{
|
||||||
if constexpr (!std::is_same_v<T, String>)
|
if constexpr (!std::is_same_v<T, String>)
|
||||||
{
|
{
|
||||||
const auto & value = static_cast<const ColumnVector<T> &>(column).getData()[row_num];
|
const auto & value = assert_cast<const ColumnVector<T> &>(column).getData()[row_num];
|
||||||
data.set.insert(AggregateFunctionUniqTraits<T>::hash(value));
|
data.set.insert(AggregateFunctionUniqTraits<T>::hash(value));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -183,7 +184,7 @@ struct OneAdder
|
|||||||
{
|
{
|
||||||
if constexpr (!std::is_same_v<T, String>)
|
if constexpr (!std::is_same_v<T, String>)
|
||||||
{
|
{
|
||||||
data.set.insert(static_cast<const ColumnVector<T> &>(column).getData()[row_num]);
|
data.set.insert(assert_cast<const ColumnVector<T> &>(column).getData()[row_num]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -240,7 +241,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).set.size());
|
assert_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).set.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override { return __FILE__; }
|
const char * getHeaderFilePath() const override { return __FILE__; }
|
||||||
@ -296,7 +297,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).set.size());
|
assert_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).set.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override { return __FILE__; }
|
const char * getHeaderFilePath() const override { return __FILE__; }
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <Common/FieldVisitors.h>
|
#include <Common/FieldVisitors.h>
|
||||||
#include <Common/SipHash.h>
|
#include <Common/SipHash.h>
|
||||||
#include <Common/typeid_cast.h>
|
#include <Common/typeid_cast.h>
|
||||||
|
#include <Common/assert_cast.h>
|
||||||
|
|
||||||
#include <DataTypes/DataTypeTuple.h>
|
#include <DataTypes/DataTypeTuple.h>
|
||||||
#include <DataTypes/DataTypeUUID.h>
|
#include <DataTypes/DataTypeUUID.h>
|
||||||
@ -131,7 +132,7 @@ public:
|
|||||||
{
|
{
|
||||||
if constexpr (!std::is_same_v<T, String>)
|
if constexpr (!std::is_same_v<T, String>)
|
||||||
{
|
{
|
||||||
const auto & value = static_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num];
|
const auto & value = assert_cast<const ColumnVector<T> &>(*columns[0]).getData()[row_num];
|
||||||
this->data(place).set.insert(detail::AggregateFunctionUniqCombinedTraits<T>::hash(value));
|
this->data(place).set.insert(detail::AggregateFunctionUniqCombinedTraits<T>::hash(value));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -158,7 +159,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).set.size());
|
assert_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).set.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override
|
const char * getHeaderFilePath() const override
|
||||||
@ -222,7 +223,7 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
static_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).set.size());
|
assert_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).set.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getHeaderFilePath() const override
|
const char * getHeaderFilePath() const override
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user