Commit Graph

33 Commits

Author SHA1 Message Date
Alexander Tokmakov
f1df91cd09
Merge pull request #47659 from ClickHouse/fix_993
Fixes for 993 and friends
2023-03-18 14:46:43 +03:00
Robert Schulze
f72a337074
Remove cruft from build
No need to check compiler flags, clang >= 15 supports all of them.
2023-03-17 13:44:04 +00:00
Alexander Tokmakov
d621b2c4ad fix intersecting parts, better fault injections 2023-03-16 21:28:07 +01:00
Suzy Wang
1176260b3c
Merge branch 'master' into z-build-0120 2023-01-24 01:14:42 -05:00
Suzy Wang
19d26828a0 s390x build support 2023-01-20 21:16:55 +00:00
Azat Khuzhin
bdeb5514c5 Fix ASan builds for glibc 2.36+ (use RTLD_NEXT for ThreadFuzzer interceptors)
Recently I noticed that clickhouse compiled with ASan does not work with
newer glibc 2.36+, before I though that this was only about compiling
with old but using new, however that was not correct, ASan simply does
not work with glibc 2.36+.

Here is a simple reproducer [1]:

    $ cat > test-asan.cpp <<EOL
    #include <pthread.h>
    int main()
    {
        // something broken in ASan in interceptor for __pthread_mutex_lock
        // and only since glibc 2.36, and for pthread_mutex_lock everything is OK
        pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
        return __pthread_mutex_lock(&mutex);
    }
    EOL
    $ clang -g3 -o test-asan test-asan.cpp -fsanitize=address
    $ ./test-asan
    AddressSanitizer:DEADLYSIGNAL
    =================================================================
    ==15659==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000000000 bp 0x7fffffffccb0 sp 0x7fffffffcb98 T0)
    ==15659==Hint: pc points to the zero page.
    ==15659==The signal is caused by a READ memory access.
    ==15659==Hint: address points to the zero page.
        #0 0x0  (<unknown module>)
        #1 0x7ffff7cda28f  (/usr/lib/libc.so.6+0x2328f) (BuildId: 1e94beb079e278ac4f2c8bce1f53091548ea1584)

    AddressSanitizer can not provide additional info.
    SUMMARY: AddressSanitizer: SEGV (<unknown module>)
    ==15659==ABORTING

  [1]: https://gist.github.com/azat/af073e57a248e04488b21068643f079e

I've started observing glibc code, there was some changes in glibc, that
moves pthread functions out from libpthread.so.0 into libc.so.6
(somewhere between 2.31 and 2.35), but
the problem pops up only with 2.36, 2.35 works fine.

After this I've looked into changes between 2.35 and 2.36, and found
this patch [2] - "dlsym: Make RTLD_NEXT prefer default version
definition [BZ #14932]", that fixes this bug [3].

  [2]: https://sourceware.org/git/?p=glibc.git;a=commit;h=efa7936e4c91b1c260d03614bb26858fbb8a0204
  [3]: https://sourceware.org/bugzilla/show_bug.cgi?id=14932

The problem with using DL_LOOKUP_RETURN_NEWEST flag for RTLD_NEXT is
that it does not resolve hidden symbols (and __pthread_mutex_lock is
indeed hidden).

Here is a sample that will show the difference [4]:

    $ cat > test-dlsym.c <<EOL
    #define _GNU_SOURCE
    #include <dlfcn.h>
    #include <stdio.h>

    int main()
    {
        void *p = dlsym(RTLD_NEXT, "__pthread_mutex_lock");
        printf("__pthread_mutex_lock: %p (via RTLD_NEXT)\n", p);
        return 0;
    }
    EOL

    # glibc 2.35: __pthread_mutex_lock: 0x7ffff7e27f70 (via RTLD_NEXT)
    # glibc 2.36: __pthread_mutex_lock: (nil) (via RTLD_NEXT)

  [4]: https://gist.github.com/azat/3b5f2ae6011bef2ae86392cea7789eb7

But ThreadFuzzer uses internal symbols to wrap
pthread_mutex_lock/pthread_mutex_unlock, which are intercepted by ASan
and this leads to NULL dereference.

The fix was obvious - just use dlsym(RTLD_NEXT), however on older
glibc's this leads to endless recursion (see commits in the code). But
only for jemalloc [5], and even though sanitizers does not uses jemalloc
the code of ThreadFuzzer is generic and I don't want to guard it with
more preprocessors macros.

  [5]: https://gist.github.com/azat/588d9c72c1e70fc13ebe113197883aa2

So we have to use RTLD_NEXT only for ASan.

There is also one more interesting issue, if you will compile with clang
that itself had been compiled with newer libc (i.e. 2.36), you will get
the following error:

    $ podman run --privileged -v $PWD/.cmake-asan/programs:/root/bin -e PATH=/bin:/root/bin -e --rm -it ubuntu-dev-v3 clickhouse
    ==1==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
    ...
    ==1==End of process memory map.
    AddressSanitizer: CHECK failed: sanitizer_common.cpp:53 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) (tid=1)
        <empty stack>

The problem is that since GLIBC_2.31, `SIGSTKSZ` is a call to
`getconf(_SC_MINSIGSTKSZ)`, but older glibc does not have it, so `-1`
will be returned and used as `SIGSTKSZ` instead.

The workaround to disable alternative stack:

    $ podman run --privileged -v $PWD/.cmake-asan/programs:/root/bin -e PATH=/bin:/root/bin -e ASAN_OPTIONS=use_sigaltstack=0 --rm -it ubuntu-dev-v3 clickhouse client --version
    ClickHouse client version 22.13.1.1.

Fixes: #43426
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-01-20 13:09:13 +01:00
Alexander Tokmakov
00c9e50ee3 fix race between INSERT and ALTER PARTITION 2022-11-02 16:25:26 +01:00
Alexey Milovidov
fa62c7e982 Fix half of trash 2022-09-10 04:08:16 +02:00
Robert Schulze
e8b3f56733
Limit suppression to a specific warning 2022-08-21 18:24:17 +00:00
Alexey Milovidov
74e1f4dc61 Fix clang-tidy 2022-08-20 17:09:20 +02:00
Alexey Milovidov
d2c6fd90cb Fix clang-tidy-14, part 1 2022-05-27 22:51:37 +02:00
Robert Schulze
1b81bb49b4
Enable clang-tidy modernize-deprecated-headers & hicpp-deprecated-headers
Official docs:

  Some headers from C library were deprecated in C++ and are no longer
  welcome in C++ codebases. Some have no effect in C++. For more details
  refer to the C++ 14 Standard [depr.c.headers] section. This check
  replaces C standard library headers with their C++ alternatives and
  removes redundant ones.
2022-05-09 08:23:33 +02:00
Amos Bird
4a5e4274f0
base should not depend on Common 2022-04-29 10:26:35 +08:00
alesapin
f011864386 Build clickhouse-keeper with musl 2022-04-12 18:48:16 +02:00
alexey-milovidov
b6f511506b
Update ThreadFuzzer.cpp 2022-03-11 17:58:27 +03:00
Azat Khuzhin
9b749ae90b Fix undefined __pthread_mutex_lock/unlock for glibc 2.34+/DISABLE_HERMETIC_BUILD
Right now it fails with:

    ld.lld: error: undefined symbol: __pthread_mutex_lock
    >>> referenced by ThreadFuzzer.cpp:300 (./src/Common/ThreadFuzzer.cpp:300)
    >>> src/CMakeFiles/clickhouse_common_io.dir/Common/ThreadFuzzer.cpp.o:(pthread_mutex_lock)
    >>> did you mean: __pthread_mutex_lock@GLIBC_2.2.5
    >>> defined in: /usr/lib/libc.so.6

Here is the list of matched symbols for 2.35:

    $ nm -D /lib/libc.so.6 | fgrep pthread_mutex_lock
    00000000000908a0 T __pthread_mutex_lock@GLIBC_2.2.5
    00000000000908a0 T pthread_mutex_lock@@GLIBC_2.2.5

    $ nm -D /lib/libpthread.so.0 | fgrep -c pthread_mutex_lock
    0

And this is for 2.33:

    $ nm -D /lib/x86_64-linux-gnu/libc.so.6 | fgrep pthread_mutex_lock
    0000000000083eb0 T pthread_mutex_lock@@GLIBC_2.2.5

    $ nm -D /lib/x86_64-linux-gnu/libpthread.so.0 | fgrep pthread_mutex_lock
    000000000000af00 T __pthread_mutex_lock@@GLIBC_2.2.5
    000000000000af00 W pthread_mutex_lock@@GLIBC_2.2.5

Because "likely" starting from 27a448223cb2d3bab191c61303db48cee66f871c
("nptl: Move core mutex functions into libc") [1], __pthread_mutex_lock
is not exported anymore.

  [1]: https://sourceware.org/git/?p=glibc.git;a=commit;h=27a448223cb2d3bab191c61303db48cee66f871c

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2022-02-20 22:51:47 +03:00
Denis Glazachev
ca7b69b0f3 Manipulate with -Wreserved-identifier only if HAS_RESERVED_IDENTIFIER has been detected 2021-10-03 17:42:36 +04:00
Alexey Milovidov
fe6b7c77c7 Rename "common" to "base" 2021-10-02 10:13:14 +03:00
tavplubix
8adfb9b593
Stop ThreadFuzzer before hung check (#29167)
* stop ThreadFuzzer before hung check

* fix

* fix
2021-09-20 17:23:10 +03:00
Sergei Semin
39929e52bd add ignore of -Wreserved-identifier into LineReader.cpp, ThreadFuzzer.cpp, ReadBufferFromFileDescriptor.cpp 2021-09-09 23:51:47 +03:00
Alexander Tokmakov
ff6c3c75c2 add protection from unsafe allocations 2021-01-12 18:41:24 +03:00
alesapin
7f590090f6 Remove logs 2020-12-22 10:28:02 +03:00
alesapin
b10f13f34a More thread fuzzer 2020-12-21 23:24:16 +03:00
alexey-milovidov
2222122f9f
Update ThreadFuzzer.cpp 2020-12-21 20:02:59 +03:00
alesapin
8f2d4f2d1e Fix user 2020-12-21 18:46:36 +03:00
alesapin
b760d7d7d1 Remove more changes 2020-12-21 15:23:02 +03:00
alesapin
5a5fbf9eae Remove logs from thread fuzzer 2020-12-21 15:22:07 +03:00
alesapin
643739df6b Trying to enable thread fuzzer in flaky check 2020-12-21 13:06:36 +03:00
Nikita Mikhaylov
4d49d2c671 another removes 2020-07-30 13:31:14 +03:00
Alexey Milovidov
be22a4b94e Checkpoint 2020-04-22 08:39:31 +03:00
Alexey Milovidov
97c2d17e99 ThreadFuzzer: do not wrap pthread functions under thread and memory sanitizers 2020-04-08 05:32:33 +03:00
Ivan
f6b31f344d
Add cross-compile build for FreeBSD (#9643)
* Add toolchain to Docker image
2020-04-07 11:33:49 +03:00
Ivan Lezhankin
06446b4f08 dbms/ → src/ 2020-04-03 18:14:31 +03:00