From b71c4e613f9ce3bb2ab8b5a198a8bdcbdc1e9ec4 Mon Sep 17 00:00:00 2001 From: dx9 Date: Fri, 22 Apr 2016 19:49:12 -0400 Subject: [PATCH] Alpine Linux Build (#990) * Musl libc does not provide adaptive mutex. Added feature test for PTHREAD_MUTEX_ADAPTIVE_NP. * Musl libc does not provide backtrace(3). Added a feature check for backtrace(3). * Fixed compiler error. * Musl libc does not implement backtrace(3). Added platform check for libexecinfo. * Alpine does not appear to support gcc -pg option. By default (gcc has PIE option enabled) it fails with: gcc: error: -pie and -pg|p|profile are incompatible when linking When -fno-PIE and -nopie are used it fails with: /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find gcrt1.o: No such file or directory Added gcc -pg platform test and output PROFILING_FLAGS accordingly. Replaced pg var in Makefile with PROFILING_FLAGS. * fix segfault when TEST_IOCTL_FRIENDLY_TMPDIR is undefined and default candidates are not suitable * use ASSERT_DOUBLE_EQ instead of ASSERT_EQ * When compiled with ROCKSDB_MALLOC_USABLE_SIZE UniversalCompactionFourPaths and UniversalCompactionSecondPathRatio tests fail due to premature memtable flushes on systems with 16-byte alignment. Arena runs out of block space before GenerateNewFile() completes. Increased options.write_buffer_size. --- Makefile | 8 ++-- build_tools/build_detect_platform | 51 ++++++++++++++++++++++++ db/db_universal_compaction_test.cc | 5 +-- port/port_posix.cc | 6 +-- port/stack_trace.cc | 2 +- util/env_test.cc | 2 +- utilities/document/json_document_test.cc | 2 +- 7 files changed, 62 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index cd5e3a5dd..c5dff2b74 100644 --- a/Makefile +++ b/Makefile @@ -171,9 +171,7 @@ ifdef COMPILE_WITH_TSAN PLATFORM_CXXFLAGS += -fsanitize=thread -fPIC -DROCKSDB_TSAN_RUN # Turn off -pg when enabling TSAN testing, because that induces # a link failure. TODO: find the root cause - pg = -else - pg = -pg + PROFILING_FLAGS = endif # USAN doesn't work well with jemalloc. If we're compiling with USAN, we should use regular malloc. @@ -918,7 +916,7 @@ db_table_properties_test: db/db_table_properties_test.o db/db_test_util.o $(LIBO $(AM_LINK) log_write_bench: util/log_write_bench.o $(LIBOBJECTS) $(TESTHARNESS) - $(AM_LINK) $(pg) + $(AM_LINK) $(PROFILING_FLAGS) plain_table_db_test: db/plain_table_db_test.o $(LIBOBJECTS) $(TESTHARNESS) $(AM_LINK) @@ -927,7 +925,7 @@ comparator_db_test: db/comparator_db_test.o $(LIBOBJECTS) $(TESTHARNESS) $(AM_LINK) table_reader_bench: table/table_reader_bench.o $(LIBOBJECTS) $(TESTHARNESS) - $(AM_LINK) $(pg) + $(AM_LINK) $(PROFILING_FLAGS) perf_context_test: db/perf_context_test.o $(LIBOBJECTS) $(TESTHARNESS) $(AM_V_CCLD)$(CXX) $^ $(EXEC_LDFLAGS) -o $@ $(LDFLAGS) diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index 10a4d497f..d1a5f4221 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -322,6 +322,55 @@ EOF if [ "$?" = 0 ]; then COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_MALLOC_USABLE_SIZE" fi + + # Test whether PTHREAD_MUTEX_ADAPTIVE_NP mutex type is available + $CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null < + int main() { + int x = PTHREAD_MUTEX_ADAPTIVE_NP; + return 0; + } +EOF + if [ "$?" = 0 ]; then + COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_PTHREAD_ADAPTIVE_MUTEX" + fi + + # Test whether backtrace is available + $CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <> + int main() { + void* frames[1]; + backtrace_symbols(frames, backtrace(frames, 1)); + return 0; + } +EOF + if [ "$?" = 0 ]; then + COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_BACKTRACE" + else + # Test whether execinfo library is installed + $CXX $CFLAGS -lexecinfo -x c++ - -o /dev/null 2>/dev/null < + int main() { + void* frames[1]; + backtrace_symbols(frames, backtrace(frames, 1)); + } +EOF + if [ "$?" = 0 ]; then + COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_BACKTRACE" + PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lexecinfo" + JAVA_LDFLAGS="$JAVA_LDFLAGS -lexecinfo" + fi + fi + + # Test if -pg is supported + $CXX $CFLAGS -pg -x c++ - -o /dev/null 2>/dev/null <> "$OUTPUT" echo "ROCKSDB_PATCH=$ROCKSDB_PATCH" >> "$OUTPUT" echo "CLANG_SCAN_BUILD=$CLANG_SCAN_BUILD" >> "$OUTPUT" echo "CLANG_ANALYZER=$CLANG_ANALYZER" >> "$OUTPUT" +echo "PROFILING_FLAGS=$PROFILING_FLAGS" >> "$OUTPUT" + diff --git a/db/db_universal_compaction_test.cc b/db/db_universal_compaction_test.cc index 868039a5c..ce73a69c3 100644 --- a/db/db_universal_compaction_test.cc +++ b/db/db_universal_compaction_test.cc @@ -955,7 +955,7 @@ TEST_P(DBTestUniversalCompaction, UniversalCompactionFourPaths) { new SpecialSkipListFactory(KNumKeysByGenerateNewFile - 1)); options.compaction_style = kCompactionStyleUniversal; options.compaction_options_universal.size_ratio = 5; - options.write_buffer_size = 110 << 10; // 105KB + options.write_buffer_size = 111 << 10; // 114KB options.arena_block_size = 4 << 10; options.level0_file_num_compaction_trigger = 2; options.num_levels = 1; @@ -1153,8 +1153,7 @@ TEST_P(DBTestUniversalCompaction, UniversalCompactionSecondPathRatio) { options.db_paths.emplace_back(dbname_ + "_2", 1024 * 1024 * 1024); options.compaction_style = kCompactionStyleUniversal; options.compaction_options_universal.size_ratio = 5; - options.write_buffer_size = 110 << 10; // 105KB - options.arena_block_size = 4 * 1024; + options.write_buffer_size = 111 << 10; // 114KB options.arena_block_size = 4 << 10; options.level0_file_num_compaction_trigger = 2; options.num_levels = 1; diff --git a/port/port_posix.cc b/port/port_posix.cc index ca1909bf6..1ad81ad88 100644 --- a/port/port_posix.cc +++ b/port/port_posix.cc @@ -35,7 +35,7 @@ static int PthreadCall(const char* label, int result) { } Mutex::Mutex(bool adaptive) { -#ifdef OS_LINUX +#ifdef ROCKSDB_PTHREAD_ADAPTIVE_MUTEX if (!adaptive) { PthreadCall("init mutex", pthread_mutex_init(&mu_, nullptr)); } else { @@ -48,9 +48,9 @@ Mutex::Mutex(bool adaptive) { PthreadCall("destroy mutex attr", pthread_mutexattr_destroy(&mutex_attr)); } -#else // ignore adaptive for non-linux platform +#else PthreadCall("init mutex", pthread_mutex_init(&mu_, nullptr)); -#endif // OS_LINUX +#endif // ROCKSDB_PTHREAD_ADAPTIVE_MUTEX } Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } diff --git a/port/stack_trace.cc b/port/stack_trace.cc index debeb5a46..be8be9825 100644 --- a/port/stack_trace.cc +++ b/port/stack_trace.cc @@ -5,7 +5,7 @@ // #include "port/stack_trace.h" -#if defined(ROCKSDB_LITE) || !(defined(OS_LINUX) || defined(OS_MACOSX)) || \ +#if defined(ROCKSDB_LITE) || !(defined(ROCKSDB_BACKTRACE) || defined(OS_MACOSX)) || \ defined(CYGWIN) // noop diff --git a/util/env_test.cc b/util/env_test.cc index ab4976df8..a151428ba 100644 --- a/util/env_test.cc +++ b/util/env_test.cc @@ -514,7 +514,7 @@ class IoctlFriendlyTmpdir { } else { // Diagnose ioctl-related failure only if this is the // directory specified via that envvar. - if (tmp == d) { + if (tmp && tmp == d) { fprintf(stderr, "TEST_IOCTL_FRIENDLY_TMPDIR-specified directory is " "not suitable: %s\n", d.c_str()); } diff --git a/utilities/document/json_document_test.cc b/utilities/document/json_document_test.cc index f8c11d9cf..7eb4033be 100644 --- a/utilities/document/json_document_test.cc +++ b/utilities/document/json_document_test.cc @@ -46,7 +46,7 @@ void AssertField(const JSONDocument& json, const std::string& field, double expected) { ASSERT_TRUE(json.Contains(field)); ASSERT_TRUE(json[field].IsDouble()); - ASSERT_EQ(expected, json[field].GetDouble()); + ASSERT_DOUBLE_EQ(expected, json[field].GetDouble()); } } // namespace -- GitLab