From 35cce03125f9b1103930d06d9ee9438ecc437ca4 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 17 Sep 2022 03:02:34 +0200 Subject: [PATCH] Remove dlopen --- base/base/phdr_cache.h | 1 + programs/benchmark/clickhouse-benchmark.cpp | 1 - programs/client/clickhouse-client.cpp | 1 - programs/compressor/clickhouse-compressor.cpp | 1 - programs/copier/clickhouse-copier.cpp | 1 - programs/disks/clickhouse-disks.cpp | 1 - .../clickhouse-extract-from-config.cpp | 1 - programs/format/clickhouse-format.cpp | 1 - programs/git-import/clickhouse-git-import.cpp | 1 - .../clickhouse-keeper-converter.cpp | 1 - programs/library-bridge/CMakeLists.txt | 1 + .../library-bridge/CatBoostLibraryHandler.h | 3 ++- .../ExternalDictionaryLibraryHandler.h | 2 +- .../library-bridge}/SharedLibrary.cpp | 3 +-- .../library-bridge}/SharedLibrary.h | 0 programs/local/clickhouse-local.cpp | 1 - programs/main.cpp | 1 + programs/obfuscator/clickhouse-obfuscator.cpp | 2 -- programs/server/clickhouse-server.cpp | 23 ------------------- .../clickhouse-static-files-disk-uploader.cpp | 1 - programs/su/clickhouse-su.cpp | 1 - 21 files changed, 7 insertions(+), 41 deletions(-) rename {src/Common => programs/library-bridge}/SharedLibrary.cpp (95%) rename {src/Common => programs/library-bridge}/SharedLibrary.h (100%) diff --git a/base/base/phdr_cache.h b/base/base/phdr_cache.h index b522710c4c4..a6e129db34d 100644 --- a/base/base/phdr_cache.h +++ b/base/base/phdr_cache.h @@ -8,6 +8,7 @@ * As a drawback, this only works if no dynamic object unloading happens after this point. * This function is thread-safe. You should call it to update cache after loading new shared libraries. * Otherwise exception handling from dlopened libraries won't work (will call std::terminate immediately). + * NOTE: dlopen is forbidden in our code. * * NOTE: It is disabled with Thread Sanitizer because TSan can only use original "dl_iterate_phdr" function. */ diff --git a/programs/benchmark/clickhouse-benchmark.cpp b/programs/benchmark/clickhouse-benchmark.cpp index 6bcb6e19b88..d58dd4dfbe7 100644 --- a/programs/benchmark/clickhouse-benchmark.cpp +++ b/programs/benchmark/clickhouse-benchmark.cpp @@ -1,2 +1 @@ extern int mainEntryClickHouseBenchmark(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseBenchmark(argc_, argv_); } diff --git a/programs/client/clickhouse-client.cpp b/programs/client/clickhouse-client.cpp index 8f7da31d617..3e489c5ff15 100644 --- a/programs/client/clickhouse-client.cpp +++ b/programs/client/clickhouse-client.cpp @@ -1,2 +1 @@ int mainEntryClickHouseClient(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseClient(argc_, argv_); } diff --git a/programs/compressor/clickhouse-compressor.cpp b/programs/compressor/clickhouse-compressor.cpp index f7d8611eac5..13a00ab6aff 100644 --- a/programs/compressor/clickhouse-compressor.cpp +++ b/programs/compressor/clickhouse-compressor.cpp @@ -1,2 +1 @@ int mainEntryClickHouseCompressor(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseCompressor(argc_, argv_); } diff --git a/programs/copier/clickhouse-copier.cpp b/programs/copier/clickhouse-copier.cpp index 653a0128aa4..4dabb01775b 100644 --- a/programs/copier/clickhouse-copier.cpp +++ b/programs/copier/clickhouse-copier.cpp @@ -1,2 +1 @@ int mainEntryClickHouseClusterCopier(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseClusterCopier(argc_, argv_); } diff --git a/programs/disks/clickhouse-disks.cpp b/programs/disks/clickhouse-disks.cpp index 184de86ee77..67ace2ddfd3 100644 --- a/programs/disks/clickhouse-disks.cpp +++ b/programs/disks/clickhouse-disks.cpp @@ -1,2 +1 @@ int mainEntryClickHouseDisks(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseDisks(argc_, argv_); } diff --git a/programs/extract-from-config/clickhouse-extract-from-config.cpp b/programs/extract-from-config/clickhouse-extract-from-config.cpp index 95d119b0dad..9a384c8f2dc 100644 --- a/programs/extract-from-config/clickhouse-extract-from-config.cpp +++ b/programs/extract-from-config/clickhouse-extract-from-config.cpp @@ -1,2 +1 @@ int mainEntryClickHouseExtractFromConfig(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseExtractFromConfig(argc_, argv_); } diff --git a/programs/format/clickhouse-format.cpp b/programs/format/clickhouse-format.cpp index 6bda5c5e039..71f2a071312 100644 --- a/programs/format/clickhouse-format.cpp +++ b/programs/format/clickhouse-format.cpp @@ -1,2 +1 @@ int mainEntryClickHouseFormat(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseFormat(argc_, argv_); } diff --git a/programs/git-import/clickhouse-git-import.cpp b/programs/git-import/clickhouse-git-import.cpp index cfa06306604..57b66f3f77a 100644 --- a/programs/git-import/clickhouse-git-import.cpp +++ b/programs/git-import/clickhouse-git-import.cpp @@ -1,2 +1 @@ int mainEntryClickHouseGitImport(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseGitImport(argc_, argv_); } diff --git a/programs/keeper-converter/clickhouse-keeper-converter.cpp b/programs/keeper-converter/clickhouse-keeper-converter.cpp index 3cb6f99f837..c84fc51f8cc 100644 --- a/programs/keeper-converter/clickhouse-keeper-converter.cpp +++ b/programs/keeper-converter/clickhouse-keeper-converter.cpp @@ -1,2 +1 @@ int mainEntryClickHouseKeeperConverter(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseKeeperConverter(argc_, argv_); } diff --git a/programs/library-bridge/CMakeLists.txt b/programs/library-bridge/CMakeLists.txt index c5ef924b180..1cacc391ca5 100644 --- a/programs/library-bridge/CMakeLists.txt +++ b/programs/library-bridge/CMakeLists.txt @@ -9,6 +9,7 @@ set (CLICKHOUSE_LIBRARY_BRIDGE_SOURCES LibraryBridge.cpp LibraryBridgeHandlerFactory.cpp LibraryBridgeHandlers.cpp + SharedLibrary.cpp library-bridge.cpp ) diff --git a/programs/library-bridge/CatBoostLibraryHandler.h b/programs/library-bridge/CatBoostLibraryHandler.h index e0ff1d70250..a20e1412552 100644 --- a/programs/library-bridge/CatBoostLibraryHandler.h +++ b/programs/library-bridge/CatBoostLibraryHandler.h @@ -7,12 +7,13 @@ #include #include #include -#include #include +#include "SharedLibrary.h" #include #include + namespace DB { diff --git a/programs/library-bridge/ExternalDictionaryLibraryHandler.h b/programs/library-bridge/ExternalDictionaryLibraryHandler.h index d6d4f926f0f..77c9b9fdf39 100644 --- a/programs/library-bridge/ExternalDictionaryLibraryHandler.h +++ b/programs/library-bridge/ExternalDictionaryLibraryHandler.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "SharedLibrary.h" #include #include "ExternalDictionaryLibraryUtils.h" diff --git a/src/Common/SharedLibrary.cpp b/programs/library-bridge/SharedLibrary.cpp similarity index 95% rename from src/Common/SharedLibrary.cpp rename to programs/library-bridge/SharedLibrary.cpp index 6104c96676a..d70709474b5 100644 --- a/src/Common/SharedLibrary.cpp +++ b/programs/library-bridge/SharedLibrary.cpp @@ -1,8 +1,7 @@ #include "SharedLibrary.h" #include -#include #include -#include "Exception.h" +#include namespace DB diff --git a/src/Common/SharedLibrary.h b/programs/library-bridge/SharedLibrary.h similarity index 100% rename from src/Common/SharedLibrary.h rename to programs/library-bridge/SharedLibrary.h diff --git a/programs/local/clickhouse-local.cpp b/programs/local/clickhouse-local.cpp index 5cc98ab6067..4b17e89496d 100644 --- a/programs/local/clickhouse-local.cpp +++ b/programs/local/clickhouse-local.cpp @@ -1,2 +1 @@ int mainEntryClickHouseLocal(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseLocal(argc_, argv_); } diff --git a/programs/main.cpp b/programs/main.cpp index fef0ad688e2..f1a714a9af9 100644 --- a/programs/main.cpp +++ b/programs/main.cpp @@ -422,6 +422,7 @@ int main(int argc_, char ** argv_) /// PHDR cache is required for query profiler to work reliably /// It also speed up exception handling, but exceptions from dynamically loaded libraries (dlopen) /// will work only after additional call of this function. + /// Note: we forbid dlopen in our code. updatePHDRCache(); #ifndef DISABLE_HARMFUL_ENV_VAR_CHECK diff --git a/programs/obfuscator/clickhouse-obfuscator.cpp b/programs/obfuscator/clickhouse-obfuscator.cpp index e57fa6d1b54..1f494223150 100644 --- a/programs/obfuscator/clickhouse-obfuscator.cpp +++ b/programs/obfuscator/clickhouse-obfuscator.cpp @@ -1,3 +1 @@ int mainEntryClickHouseObfuscator(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseObfuscator(argc_, argv_); } - diff --git a/programs/server/clickhouse-server.cpp b/programs/server/clickhouse-server.cpp index f49dc21d9fe..a7a3d8f00e3 100644 --- a/programs/server/clickhouse-server.cpp +++ b/programs/server/clickhouse-server.cpp @@ -1,24 +1 @@ -#include - -#include - - int mainEntryClickHouseServer(int argc, char ** argv); - -/** - * This is the entry-point for the split build server. The initialization - * is copied from single-binary entry point in main.cpp. - */ -int main(int argc_, char ** argv_) -{ - /// Reset new handler to default (that throws std::bad_alloc) - /// It is needed because LLVM library clobbers it. - std::set_new_handler(nullptr); - - /// PHDR cache is required for query profiler to work reliably - /// It also speed up exception handling, but exceptions from dynamically loaded libraries (dlopen) - /// will work only after additional call of this function. - updatePHDRCache(); - - return mainEntryClickHouseServer(argc_, argv_); -} diff --git a/programs/static-files-disk-uploader/clickhouse-static-files-disk-uploader.cpp b/programs/static-files-disk-uploader/clickhouse-static-files-disk-uploader.cpp index 063604b10b1..cf271f16a76 100644 --- a/programs/static-files-disk-uploader/clickhouse-static-files-disk-uploader.cpp +++ b/programs/static-files-disk-uploader/clickhouse-static-files-disk-uploader.cpp @@ -1,2 +1 @@ int mainEntryClickHouseStaticFilesDiskUploader(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseStaticFilesDiskUploader(argc_, argv_); } diff --git a/programs/su/clickhouse-su.cpp b/programs/su/clickhouse-su.cpp index bb0967ca271..9459ccad0e8 100644 --- a/programs/su/clickhouse-su.cpp +++ b/programs/su/clickhouse-su.cpp @@ -1,2 +1 @@ int mainEntryClickHouseSU(int argc, char ** argv); -int main(int argc_, char ** argv_) { return mainEntryClickHouseSU(argc_, argv_); }