Skip to content

Commit

Permalink
Prolog of hermetic build with GCC 11 and Clang 13.
Browse files Browse the repository at this point in the history
  • Loading branch information
amosbird committed Jan 13, 2022
1 parent ccb6c6a commit b845ca8
Show file tree
Hide file tree
Showing 37 changed files with 568 additions and 209 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING_CN.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
Expand Down Expand Up @@ -32,7 +32,7 @@ under the License.
初次来到 Doris 社区,您可以:

* 关注 Doris [Github 代码库](https://github.com/apache/incubator-doris)
* 订阅我们的 [邮件列表](./subscribe-mail-list.md)
* 订阅我们的 [邮件列表](./subscribe-mail-list.md)
* 加入 Doris 微信群(加微信号:morningman-cmy, 备注:加入Doris群) 随时提问;
* 进入 Doris 的 [Gitter](./gitter.md) 聊天室;

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The main advantages of Doris are the simplicity (of developing, deploying and us

[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)

> **Note**
> **Note**
> Some licenses of the third-party dependencies are not compatible with Apache 2.0 License. So you need to disable
some Doris features to be complied with Apache 2.0 License. For details, refer to the `thirdparty/LICENSE.txt`

Expand Down
48 changes: 25 additions & 23 deletions be/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@

cmake_minimum_required(VERSION 3.19.2)

# set CMAKE_C_COMPILER, this must set before project command
if (DEFINED ENV{DORIS_GCC_HOME})
set(CMAKE_C_COMPILER "$ENV{DORIS_GCC_HOME}/bin/gcc")
set(CMAKE_CXX_COMPILER "$ENV{DORIS_GCC_HOME}/bin/g++")
set(GCC_HOME $ENV{DORIS_GCC_HOME})
else()
message(FATAL_ERROR "DORIS_GCC_HOME environment variable is not set")
endif()

project(doris CXX C)

# Write compile_commands.json
Expand Down Expand Up @@ -95,8 +86,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(FATAL_ERROR "Need GCC version at least 7.3.0")
endif()
message(STATUS "GCC version is greater than 7.3.0, disable -Werror. Be careful with compile warnings.")
elseif (NOT APPLE)
message(FATAL_ERROR "Compiler should be GNU")
endif()

set(PIC_LIB_PATH "${THIRDPARTY_DIR}")
Expand Down Expand Up @@ -299,6 +288,9 @@ set_target_properties(aws-s2n PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib
add_library(minizip STATIC IMPORTED)
set_target_properties(minizip PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib64/libminizip.a)

add_library(idn STATIC IMPORTED)
set_target_properties(idn PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib64/libidn.a)

add_library(gsasl STATIC IMPORTED)
set_target_properties(gsasl PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib64/libgsasl.a)

Expand Down Expand Up @@ -499,6 +491,7 @@ set(COMMON_THIRDPARTY
lz4
libevent
libevent_pthreads
idn
gsasl
curl
${LIBZ}
Expand Down Expand Up @@ -530,13 +523,13 @@ set(COMMON_THIRDPARTY
if (${MAKE_TEST} STREQUAL "ON")
set(COMMON_THIRDPARTY
${COMMON_THIRDPARTY}
benchmark
benchmark
)
endif()

# thirdparties dependescies that can only run on X86 platform
set(X86_DEPENDENCIES
${COMMON_THIRDPARTY}
${COMMON_THIRDPARTY}
hdfs3
xml2
lzma
Expand Down Expand Up @@ -588,31 +581,41 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "BCC")
)
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(ASAN_LIBS -static-libasan)
set(LSAN_LIBS -static-liblsan)
set(UBSAN_LIBS -static-libubsan tcmalloc)
set(TSAN_LIBS -static-libtsan)
else ()
set(UBSAN_LIBS tcmalloc)
endif ()

# Add sanitize static link flags or tcmalloc
if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE" OR "${CMAKE_BUILD_TYPE}" STREQUAL "BCC")
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} tcmalloc)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "ASAN")
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} -static-libasan)
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} ${ASAN_LIBS})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "LSAN")
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} -static-liblsan)
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} ${LSAN_LIBS})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "UBSAN")
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} -static-libubsan tcmalloc)
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} ${UBSAN_LIBS})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "TSAN")
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} -static-libtsan)
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} ${TSAN_LIBS})
add_definitions("-DTHREAD_SANITIZER")
else()
message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
endif()

set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS}
-lrt -l:libbfd.a -liberty -lc -lm -ldl -pthread
)

# NOTE(amos): This should come before -lc -lm to interpose symbols correctly.
if (GLIBC_COMPATIBILITY)
add_subdirectory(${SRC_DIR}/glibc-compatibility)
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} glibc-compatibility)
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} glibc-compatibility-getrandom glibc-compatibility)
endif()

set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS}
-lrt -l:libbfd.a -liberty -lc -lm -ldl -pthread
)

# Set libraries for test
set (TEST_LINK_LIBS ${DORIS_LINK_LIBS}
${WL_START_GROUP}
Expand Down Expand Up @@ -726,4 +729,3 @@ install(FILES
${BASE_DIR}/../conf/be.conf
${BASE_DIR}/../conf/odbcinst.ini
DESTINATION ${OUTPUT_DIR}/conf)

1 change: 1 addition & 0 deletions be/src/agent/topic_subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define DORIS_BE_SRC_AGENT_TOPIC_SUBSCRIBER_H

#include <map>
#include <mutex>
#include <shared_mutex>
#include <thread>

Expand Down
1 change: 1 addition & 0 deletions be/src/exec/olap_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ inline CompareLargeFunc get_compare_func(PrimitiveType type) {
default:
DCHECK(false) << "Unsupported Compare type";
}
__builtin_unreachable();
}

static const char* NEGATIVE_INFINITY = "-oo";
Expand Down
6 changes: 3 additions & 3 deletions be/src/exprs/runtime_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,11 @@ Status IRuntimeFilter::init_with_desc(const TRuntimeFilterDesc* desc, const TQue
}

Status IRuntimeFilter::serialize(PMergeFilterRequest* request, void** data, int* len) {
return _serialize(request, data, len);
return serialize_impl(request, data, len);
}

Status IRuntimeFilter::serialize(PPublishFilterRequest* request, void** data, int* len) {
return _serialize(request, data, len);
return serialize_impl(request, data, len);
}

Status IRuntimeFilter::create_wrapper(const MergeRuntimeFilterParams* param, MemTracker* tracker,
Expand Down Expand Up @@ -1000,7 +1000,7 @@ void batch_copy(PInFilter* filter, HybridSetBase::IteratorBase* it,
}

template <class T>
Status IRuntimeFilter::_serialize(T* request, void** data, int* len) {
Status IRuntimeFilter::serialize_impl(T* request, void** data, int* len) {
request->set_filter_type(get_type(_runtime_filter_type));

if (_runtime_filter_type == RuntimeFilterType::IN_FILTER) {
Expand Down
2 changes: 1 addition & 1 deletion be/src/exprs/runtime_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class IRuntimeFilter {
void to_protobuf(PMinMaxFilter* filter);

template <class T>
Status _serialize(T* request, void** data, int* len);
Status serialize_impl(T* request, void** data, int* len);

template <class T>
static Status _create_wrapper(const T* param, MemTracker* tracker, ObjectPool* pool,
Expand Down
4 changes: 2 additions & 2 deletions be/src/exprs/table_function/explode_split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Status ExplodeSplitTableFunction::open() {
// check if the delimiter argument(the 2nd arg) is constant.
// if yes, cache it
if (fn_ctx->is_arg_constant(1)) {
_is_delimiter_constant = true;
_is_delimiter_constant = true;
StringVal* delimiter = reinterpret_cast<StringVal*>(fn_ctx->get_constant_arg(1));
_const_delimter = StringPiece((char*) delimiter->ptr, delimiter->len);
}
Expand All @@ -65,7 +65,7 @@ Status ExplodeSplitTableFunction::process(TupleRow* tuple_row) {
StringVal delimiter = _expr_context->root()->get_child(1)->get_string_val(_expr_context, tuple_row);
_backup = strings::Split(StringPiece((char*) text.ptr, text.len), StringPiece((char*) delimiter.ptr, delimiter.len));
}
for (const std::string str : _backup) {
for (const std::string & str : _backup) {
_data.emplace_back(str);
}
_cur_size = _backup.size();
Expand Down
8 changes: 8 additions & 0 deletions be/src/glibc-compatibility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ if (GLIBC_COMPATIBILITY)
list(APPEND glibc_compatibility_sources musl/getentropy.c)
endif()

list(REMOVE_ITEM glibc_compatibility_sources musl/getrandom.c)

# Need to omit frame pointers to match the performance of glibc
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")

# NOTE(amos): getrandom is hard to interpose since we build thirdparty deps
# without glibc-compatibility. Also sanitizers might generate getrandom
# libcalls. Workaround: Use object file so that linker will always take a
# look at its symbol table.
add_library(glibc-compatibility-getrandom OBJECT musl/getrandom.c)
add_library(glibc-compatibility STATIC ${glibc_compatibility_sources})

if (COMPILER_CLANG)
Expand All @@ -60,6 +67,7 @@ if (GLIBC_COMPATIBILITY)
endif ()

target_include_directories(glibc-compatibility PRIVATE ${musl_arch_include_dir})
target_include_directories(glibc-compatibility-getrandom PRIVATE ${musl_arch_include_dir})

message (STATUS "Some symbols from glibc will be replaced for compatibility")
else()
Expand Down
50 changes: 50 additions & 0 deletions be/src/glibc-compatibility/glibc-compat-2.32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/// In glibc 2.32 new version of some symbols had been added [1]:
///
/// $ nm -D clickhouse | fgrep -e @GLIBC_2.32
/// U pthread_getattr_np@GLIBC_2.32
/// U pthread_sigmask@GLIBC_2.32
///
/// [1]: https://www.spinics.net/lists/fedora-devel/msg273044.html
///
/// Right now ubuntu 20.04 is used as official image for building
/// ClickHouse, however once it will be switched someone may not be happy
/// with that fact that he/she cannot use official binaries anymore because
/// they have glibc < 2.32.
///
/// To avoid this dependency, let's force previous version of those
/// symbols from glibc.
///
/// Also note, that the following approach had been tested:
/// a) -Wl,--wrap -- but it goes into endless recursion whey you try to do
/// something like this:
///
/// int __pthread_getattr_np_compact(pthread_t thread, pthread_attr_t *attr);
/// GLIBC_COMPAT_SYMBOL(__pthread_getattr_np_compact, pthread_getattr_np)
/// int __pthread_getattr_np_compact(pthread_t thread, pthread_attr_t *attr);
/// int __wrap_pthread_getattr_np(pthread_t thread, pthread_attr_t *attr)
/// {
/// return __pthread_getattr_np_compact(thread, attr);
/// }
///
/// int __pthread_sigmask_compact(int how, const sigset_t *set, sigset_t *oldset);
/// GLIBC_COMPAT_SYMBOL(__pthread_sigmask_compact, pthread_sigmask)
/// int __pthread_sigmask_compact(int how, const sigset_t *set, sigset_t *oldset);
/// int __wrap_pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset)
/// {
/// return __pthread_sigmask_compact(how, set, oldset);
/// }
///
/// b) -Wl,--defsym -- same problems (and you cannot use version of symbol with
/// version in the expression)
/// c) this approach -- simply add this file with -include directive.

#if defined(__amd64__)
#define GLIBC_COMPAT_SYMBOL(func) __asm__(".symver " #func "," #func "@GLIBC_2.2.5");
#elif defined(__aarch64__)
#define GLIBC_COMPAT_SYMBOL(func) __asm__(".symver " #func "," #func "@GLIBC_2.17");
#else
#error Your platform is not supported.
#endif

GLIBC_COMPAT_SYMBOL(pthread_sigmask)
GLIBC_COMPAT_SYMBOL(pthread_getattr_np)
9 changes: 2 additions & 7 deletions be/src/glibc-compatibility/glibc-compatibility.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
extern "C" {
#endif

#include <pthread.h>

size_t __pthread_get_minstack(const pthread_attr_t * attr)
{
return 1048576; /// This is a guess. Don't sure it is correct.
}

#include <signal.h>
#include <unistd.h>
#include <string.h>
Expand Down Expand Up @@ -141,6 +134,8 @@ int __open_2(const char *path, int oflag)
}


#include <pthread.h>

/// No-ops.
int pthread_setname_np(pthread_t thread, const char *name) { return 0; }
int pthread_getname_np(pthread_t thread, char *name, size_t len) { name[0] = '\0'; return 0; };
Expand Down
23 changes: 23 additions & 0 deletions be/src/glibc-compatibility/musl/eventfd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <sys/eventfd.h>
#include <unistd.h>
#include <errno.h>
#include "syscall.h"

int eventfd(unsigned int count, int flags)
{
int r = __syscall(SYS_eventfd2, count, flags);
#ifdef SYS_eventfd
if (r==-ENOSYS && !flags) r = __syscall(SYS_eventfd, count);
#endif
return __syscall_ret(r);
}

int eventfd_read(int fd, eventfd_t *value)
{
return (sizeof(*value) == read(fd, value, sizeof(*value))) ? 0 : -1;
}

int eventfd_write(int fd, eventfd_t value)
{
return (sizeof(value) == write(fd, &value, sizeof(value))) ? 0 : -1;
}
49 changes: 37 additions & 12 deletions be/src/glibc-compatibility/musl/getauxval.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <sys/auxv.h>
#include "atomic.h"
#include <unistd.h> // __environ
#include <errno.h>

Expand All @@ -17,18 +18,7 @@ static size_t __find_auxv(unsigned long type)
return (size_t) -1;
}

__attribute__((constructor)) static void __auxv_init()
{
size_t i;
for (i = 0; __environ[i]; i++);
__auxv = (unsigned long *) (__environ + i + 1);

size_t secure_idx = __find_auxv(AT_SECURE);
if (secure_idx != ((size_t) -1))
__auxv_secure = __auxv[secure_idx];
}

unsigned long getauxval(unsigned long type)
unsigned long __getauxval(unsigned long type)
{
if (type == AT_SECURE)
return __auxv_secure;
Expand All @@ -43,3 +33,38 @@ unsigned long getauxval(unsigned long type)
errno = ENOENT;
return 0;
}

static void * volatile getauxval_func;

static unsigned long __auxv_init(unsigned long type)
{
if (!__environ)
{
// __environ is not initialized yet so we can't initialize __auxv right now.
// That's normally occurred only when getauxval() is called from some sanitizer's internal code.
errno = ENOENT;
return 0;
}

// Initialize __auxv and __auxv_secure.
size_t i;
for (i = 0; __environ[i]; i++);
__auxv = (unsigned long *) (__environ + i + 1);

size_t secure_idx = __find_auxv(AT_SECURE);
if (secure_idx != ((size_t) -1))
__auxv_secure = __auxv[secure_idx];

// Now we've initialized __auxv, next time getauxval() will only call __get_auxval().
a_cas_p(&getauxval_func, (void *)__auxv_init, (void *)__getauxval);

return __getauxval(type);
}

// First time getauxval() will call __auxv_init().
static void * volatile getauxval_func = (void *)__auxv_init;

unsigned long getauxval(unsigned long type)
{
return ((unsigned long (*)(unsigned long))getauxval_func)(type);
}
Loading

0 comments on commit b845ca8

Please sign in to comment.