Skip to content

Clang++ C++ optimization crashes ClickHouse on PowerPC64le platform #102311

@HarryLeeIBM

Description

@HarryLeeIBM

I used Ubuntu clang version 18.1.4 to build ClickHouse(v24.7.x) using cross-compiling for PowerPC64le platform and found ClickHouse crashes. When I build ClickHouse with -O0 option it doesn't crash, so it could be a wrong optimization issue.

Tried to turn off optimization of file src/Processors/Executors/PipelineExecutor.cpp by adding #pragma clang optimize off after #include lines and adding #pragma clang optimize on at the end of the file, issue disappears.

To reproduce the issue, use the following steps:

  1. git clone ClickHouse and install necessary tools (see details: https://github.com/ClickHouse/ClickHouse/blob/master/docs/en/development/build.md).
  2. Use the following commands to do cross-compiling under ClickHouse folder:
     mkdir build
     cd build
     cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_OPTIM=ON -DGLIBC_COMPATIBILITY=OFF -DENABLE_RDKAFKA=ON -DBUILD_SHARED_LIBS=OFF -DITK_DYNAMIC_LOADING=OFF -DENABLE_AMQPCPP=OFF -DENABLE_AVRO=ON -DENABLE_CAPNP=OFF -DENABLE_CASSANDRA=OFF -DENABLE_H3=OFF -DENABLE_HDFS=OFF -DENABLE_MSGPACK=OFF -DENABLE_MYSQL=OFF -DENABLE_NLP=OFF -DENABLE_ODBC=OFF -DENABLE_ORC=OFF -DENABLE_PARQUET=OFF -DENABLE_ROCKSDB=OFF -DENABLE_SQLITE=OFF -DENABLE_SHELL_COMMANDS=0 -DENABLE_PLAY=0 -DADD_GDB_INDEX_FOR_GOLD=1 -DCLICKHOUSE_OFFICIAL_BUILD=1 -DCMAKE_TOOLCHAIN_FILE=cmake/linux/toolchain-ppc64le.cmake ..
  1. Copy clickhouse executable under build/progams to a power pc 64le machine.
  2. Run "clickhouse server" to start the ClickHouse server
  3. use another terminal to run "clickhouse client" to run ClickHouse client. Under the prompt, run SQL:

select if(in(dummy, tuple(0, 1)), 'ok', 'ok') from remote('localhost', system.one) settings legacy_column_name_of_tuple_literal=1, prefer_localhost_replica=0;

Then you will notice the server crashes and core dump is created. By analyzing the core dump, the stack trace is as following:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  std::__1::construct_at[abi:v15000]<DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node**>(DB::ExecutingGraph::Node**, DB::ExecutingGraph::Node*&&) (__location=0x7f43d378418304bc, __args=<optimized out>)
    at ./contrib/llvm-project/libcxx/include/__memory/construct_at.h:35

warning: 35	./contrib/llvm-project/libcxx/include/__memory/construct_at.h: No such file or directory
[Current thread is 1 (Thread 0x75a79cf69110 (LWP 262772))]
(gdb) bt
#0  std::__1::construct_at[abi:v15000]<DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node**>(DB::ExecutingGraph::Node**, DB::ExecutingGraph::Node*&&) (__location=0x7f43d378418304bc, __args=<optimized out>)
    at ./contrib/llvm-project/libcxx/include/__memory/construct_at.h:35
#1  std::__1::allocator_traits<AllocatorWithMemoryTracking<DB::ExecutingGraph::Node*> >::construct[abi:v15000]<DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node*, void, void>(AllocatorWithMemoryTracking<DB::ExecutingGraph::Node*>&, DB::ExecutingGraph::Node**, DB::ExecutingGraph::Node*&&) (__p=0x7f43d378418304bc, 
    __args=<optimized out>)
    at ./contrib/llvm-project/libcxx/include/__memory/allocator_traits.h:298
#2  std::__1::deque<DB::ExecutingGraph::Node*, AllocatorWithMemoryTracking<DB::ExecutingGraph::Node*> >::push_back (this=0x75a79cf67ee0, __v=<optimized out>)
    at ./contrib/llvm-project/libcxx/include/deque:1967
#3  std::__1::queue<DB::ExecutingGraph::Node*, std::__1::deque<DB::ExecutingGraph::Node*, AllocatorWithMemoryTracking<DB::ExecutingGraph::Node*> > >::push[abi:v15000](DB::ExecutingGraph::Node*&&) (this=0x75a79cf67ee0, __v=<optimized out>)
    at ./contrib/llvm-project/libcxx/include/queue:365
#4  DB::ExecutingGraph::updateNode (this=0x75a795831900, pid=0, queue=..., 
    async_queue=...)
    at ./ppc18-rel/./src/Processors/Executors/ExecutingGraph.cpp:344
#5  0x0000000022a67c74 in DB::PipelineExecutor::executeStepImpl (
    this=0x75a7958b2a18, thread_num=<optimized out>, yield_flag=0x0)
    at ./ppc18-rel/./src/Processors/Executors/PipelineExecutor.cpp:291
--Type <RET> for more, q to quit, c to continue without paging--c
#6  0x0000000022a6728c in DB::PipelineExecutor::executeSingleThread (
    this=0x75a7958b2a18, thread_num=0)
    at ./ppc18-rel/./src/Processors/Executors/PipelineExecutor.cpp:238
#7  DB::PipelineExecutor::executeImpl (this=0x75a7958b2a18, 
    num_threads=<optimized out>, concurrency_control=<optimized out>)
    at ./ppc18-rel/./src/Processors/Executors/PipelineExecutor.cpp:410
#8  0x0000000022a66f74 in DB::PipelineExecutor::execute (this=0x75a7958b2a18, 
    num_threads=1, concurrency_control=<optimized out>)
    at ./ppc18-rel/./src/Processors/Executors/PipelineExecutor.cpp:110
#9  0x0000000022a77a64 in DB::threadFunction (data=..., thread_group=..., 
    num_threads=1, 
    concurrency_control=<error reading variable: Unable to access DWARF register number 73>)
    at ./ppc18-rel/./src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:83
#10 DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0::operator()() const (this=<optimized out>)
    at ./ppc18-rel/./src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:109
#11 std::__1::__invoke[abi:v15000]<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&) (__f=...)
    at ./contrib/llvm-project/libcxx/include/__functional/invoke.h:394
#12 _ZNSt3__118__apply_tuple_implB6v15000IRZN2DB28PullingAsyncPipelineExecutor4pullERNS1_5ChunkEmE3$_0RNS_5tupleIJEEETpTnmJEEEDcOT_OT0_NS_15__tuple_indicesIJXspT1_EEEE (__f=..., __t=...) at ./contrib/llvm-project/libcxx/include/tuple:1789
#13 std::__1::apply[abi:v15000]<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&, std::__1::tuple<>&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&, std::__1::tuple<>&) (__f=..., __t=...)
    at ./contrib/llvm-project/libcxx/include/tuple:1798
#14 ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}::operator()() (this=<optimized out>) at ./src/Common/ThreadPool.h:251
#15 std::__1::__invoke[abi:v15000]<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&) (__f=...)
    at ./contrib/llvm-project/libcxx/include/__functional/invoke.h:394
#16 std::__1::__invoke_void_return_wrapper<void, true>::__call<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}&>(ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}&) (__args=...)
    at ./contrib/llvm-project/libcxx/include/__functional/invoke.h:479
#17 std::__1::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}, void ()>::operator()[abi:v15000]() (
    this=<optimized out>)
    at ./contrib/llvm-project/libcxx/include/__functional/function.h:235
#18 std::__1::__function::__policy_invoker<void ()>::__call_impl<std::__1::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}, void ()> >(std::__1::__function::__policy_storage const*) (
    __buf=<optimized out>)
    at ./contrib/llvm-project/libcxx/include/__functional/function.h:716
#19 0x000000001ad690cc in std::__1::__function::__policy_func<void ()>::operator()[abi:v15000]() const (this=0x75a79cf68570)
    at ./contrib/llvm-project/libcxx/include/__functional/function.h:848
#20 std::__1::function<void()>::operator() (this=0x75a79cf68570)
    at ./contrib/llvm-project/libcxx/include/__functional/function.h:1187
#21 ThreadPoolImpl<std::__1::thread>::worker (this=0x75a97c042e40, 
    thread_it=...) at ./ppc18-rel/./src/Common/ThreadPool.cpp:462
#22 0x000000001ad6e274 in ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, Priority, std::__1::optional<unsigned long>, bool)::{lambda()#2}::operator()() const (this=0x75a7ab9f27c8)
    at ./ppc18-rel/./src/Common/ThreadPool.cpp:219
#23 std::__1::__invoke[abi:v15000]<ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, Priority, std::__1::optional<unsigned long>, bool)::{lambda()#2}>(ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, Priority, std::__1::optional<unsigned long>, bool)::{lambda()#2}&&) (__f=...)
    at ./contrib/llvm-project/libcxx/include/__functional/invoke.h:394
#24 _ZNSt3__116__thread_executeB6v15000INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZN14ThreadPoolImplINS_6threadEE12scheduleImplIvEET_NS_8functionIFvvEEE8PriorityNS_8optionalImEEbEUlvE0_JETpTnmJEEEvRNS_5tupleIJSA_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE (__t=...)
    at ./contrib/llvm-project/libcxx/include/thread:284
#25 std::__1::__thread_proxy[abi:v15000]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, Priority, std::__1::optional<unsigned long>, bool)::{lambda()#2}> >(void*) (
    __vp=0x75a7ab9f27c0) at ./contrib/llvm-project/libcxx/include/thread:295
#26 0x000075a97cdf8838 in start_thread ()
   from /lib/powerpc64le-linux-gnu/libpthread.so.0
#27 0x000075a97ccfba44 in clone () from /lib/powerpc64le-linux-gnu/libc.so.6

Metadata

Metadata

Assignees

Labels

backend:PowerPCconfirmedVerified by a second partyllvm:optimizationsmiscompilationneeds-reductionLarge reproducer that should be reduced into a simpler formquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions