Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set libc++ as stdlib explicitly for clang under darwin #9665

Merged
merged 2 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ if (COMPILER_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer")
if (OS_DARWIN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-U,_inside_main")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wl,-U,_inside_main")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-U,_inside_main")
endif()
endif ()
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Common/QueryProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace
}
#else
UNUSED(info);
UNUSED(write_trace_iteration);
#endif

const auto signal_context = *reinterpret_cast<ucontext_t *>(context);
Expand Down
31 changes: 21 additions & 10 deletions dbms/src/Common/ThreadFuzzer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#if OS_LINUX
#if defined(OS_LINUX)
#include <sys/sysinfo.h>
#endif
#include <sched.h>
Expand All @@ -18,17 +18,13 @@

#include <Common/ThreadFuzzer.h>


/// We will also wrap some thread synchronization functions to inject sleep/migration before or after.
#if OS_LINUX
#if defined(OS_LINUX)
#define FOR_EACH_WRAPPED_FUNCTION(M) \
M(int, pthread_mutex_lock, pthread_mutex_t * arg) \
M(int, pthread_mutex_unlock, pthread_mutex_t * arg)
#else
#define FOR_EACH_WRAPPED_FUNCTION(M)
#endif


namespace DB
{

Expand Down Expand Up @@ -70,6 +66,7 @@ static void initFromEnv(std::atomic<T> & what, const char * name)

static std::atomic<int> num_cpus = 0;

#if defined(OS_LINUX)
#define DEFINE_WRAPPER_PARAMS(RET, NAME, ...) \
static std::atomic<double> NAME ## _before_yield_probability = 0; \
static std::atomic<double> NAME ## _before_migrate_probability = 0; \
Expand All @@ -84,11 +81,11 @@ static std::atomic<int> num_cpus = 0;
FOR_EACH_WRAPPED_FUNCTION(DEFINE_WRAPPER_PARAMS)

#undef DEFINE_WRAPPER_PARAMS

#endif

void ThreadFuzzer::initConfiguration()
{
#if OS_LINUX
#if defined(OS_LINUX)
num_cpus.store(get_nprocs(), std::memory_order_relaxed);
#else
(void)num_cpus;
Expand All @@ -100,6 +97,7 @@ void ThreadFuzzer::initConfiguration()
initFromEnv(sleep_probability, "THREAD_FUZZER_SLEEP_PROBABILITY");
initFromEnv(sleep_time_us, "THREAD_FUZZER_SLEEP_TIME_US");

#if defined(OS_LINUX)
#define INIT_WRAPPER_PARAMS(RET, NAME, ...) \
initFromEnv(NAME ## _before_yield_probability, "THREAD_FUZZER_" #NAME "_BEFORE_YIELD_PROBABILITY"); \
initFromEnv(NAME ## _before_migrate_probability, "THREAD_FUZZER_" #NAME "_BEFORE_MIGRATE_PROBABILITY"); \
Expand All @@ -114,11 +112,13 @@ void ThreadFuzzer::initConfiguration()
FOR_EACH_WRAPPED_FUNCTION(INIT_WRAPPER_PARAMS)

#undef INIT_WRAPPER_PARAMS
#endif
}


bool ThreadFuzzer::isEffective() const
{
#if defined(OS_LINUX)
#define CHECK_WRAPPER_PARAMS(RET, NAME, ...) \
if (NAME ## _before_yield_probability.load(std::memory_order_relaxed)) return true; \
if (NAME ## _before_migrate_probability.load(std::memory_order_relaxed)) return true; \
Expand All @@ -133,6 +133,7 @@ bool ThreadFuzzer::isEffective() const
FOR_EACH_WRAPPED_FUNCTION(CHECK_WRAPPER_PARAMS)

#undef INIT_WRAPPER_PARAMS
#endif

return cpu_time_period_us != 0
&& (yield_probability > 0
Expand All @@ -153,7 +154,7 @@ static void injection(
sched_yield();
}

#if OS_LINUX
#if defined(OS_LINUX)
int num_cpus_loaded = num_cpus.load(std::memory_order_relaxed);
if (num_cpus_loaded > 0
&& migrate_probability > 0
Expand All @@ -167,6 +168,8 @@ static void injection(

(void)sched_setaffinity(0, sizeof(set), &set);
}
#else
UNUSED(migrate_probability);
#endif

if (sleep_probability > 0
Expand Down Expand Up @@ -194,11 +197,17 @@ void ThreadFuzzer::setup()
sa.sa_handler = signalHandler;
sa.sa_flags = SA_RESTART;

#if defined(OS_LINUX)
if (sigemptyset(&sa.sa_mask))
throwFromErrno("Failed to clean signal mask for thread fuzzer", ErrorCodes::CANNOT_MANIPULATE_SIGSET);

if (sigaddset(&sa.sa_mask, SIGPROF))
throwFromErrno("Failed to add signal to mask for thread fuzzer", ErrorCodes::CANNOT_MANIPULATE_SIGSET);
#else
// the two following functions always return 0 under mac
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGPROF);
#endif

if (sigaction(SIGPROF, &sa, nullptr))
throwFromErrno("Failed to setup signal handler for thread fuzzer", ErrorCodes::CANNOT_SET_SIGNAL_HANDLER);
Expand All @@ -219,6 +228,7 @@ void ThreadFuzzer::setup()
/// We expect that for every function like pthread_mutex_lock there is the same function with two underscores prefix.
/// NOTE We cannot use dlsym(... RTLD_NEXT), because it will call pthread_mutex_lock and it will lead to infinite recursion.

#if defined(OS_LINUX)
#define MAKE_WRAPPER(RET, NAME, ...) \
extern "C" RET __ ## NAME(__VA_ARGS__); /* NOLINT */ \
extern "C" RET NAME(__VA_ARGS__) /* NOLINT */ \
Expand All @@ -240,8 +250,9 @@ void ThreadFuzzer::setup()
return ret; \
} \

FOR_EACH_WRAPPED_FUNCTION(MAKE_WRAPPER)
FOR_EACH_WRAPPED_FUNCTION(MAKE_WRAPPER)

#undef MAKE_WRAPPER
#endif

}