Skip to content

Commit

Permalink
Bug#35330950 Contribution: sql/memory: Fix build on musl
Browse files Browse the repository at this point in the history
Misc. fixes for Alpine Linux:
 - disable build-id
 - disable compiler option -ftls-model=initial-exec
 - add missing include of libgen.h
 - DNS resolver functions
 - include <unistd.h> rather than <sys/unistd.h>
 - include <sys/stat.h> to get definition of mode_t
 - misc sysconf() macros are only available with __GLIBC__
 - no backtrace/stacktrace on Alpine Linux
 - disable the unit test for segfault

The list of packages required or useful to build on Alpine:
 - BOOST version boost_1_77_0
 - bash
 - bison
 - build-base
 - cmake
 - curl-dev
 - cyrus-sasl-dev
 - cyrus-sasl-scram
 - emacs
 - gcc
 - gcompat
 - git
 - git-review
 - libaio
 - libc6-compat
 - libfido2-dev
 - libnsl
 - libpthread-stubs
 - libtirpc
 - libtirpc-dev
 - libudev-zero-dev
 - linux-headers
 - ncurses-dev
 - openldap-dev make
 - openssl
 - openssl-dev
 - perl
 - perl-app-cpanminus
 - perl-dbi
 - perl-dev
 - perl-devel-checklib
 - perl-expect
 - perl-json
 - protobuf-dev
 - rpcgen
 - zip

Change-Id: Iec8fc1617eb3fece5152b9b2a1221da45510562d
(cherry picked from commit 4cecfd91a6e8e1b29e835ca17e3da4c94065908f)
  • Loading branch information
Tor Didriksen committed Nov 23, 2023
1 parent c816527 commit dc6b9e2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -789,7 +789,7 @@ IF(WITH_DEFAULT_COMPILER_OPTIONS)
ENDIF()

# Assume, for now at least, that we want build-id for all kinds of Linux builds.
IF(LINUX)
IF(LINUX AND NOT LINUX_ALPINE)
OPTION(WITH_BUILD_ID "Add --build-id=sha1 to all executables." ON)
IF(WITH_BUILD_ID)
SET(HAVE_BUILD_ID_SUPPORT 1)
Expand Down
3 changes: 2 additions & 1 deletion cmake/build_configurations/compiler_options.cmake
Expand Up @@ -65,7 +65,8 @@ IF(UNIX)
ENDIF()

# Faster TLS model
IF(MY_COMPILER_IS_GNU_OR_CLANG AND NOT SOLARIS AND NOT LINUX_RHEL6)
IF(MY_COMPILER_IS_GNU_OR_CLANG
AND NOT SOLARIS AND NOT LINUX_RHEL6 AND NOT LINUX_ALPINE)
STRING_APPEND(COMMON_C_FLAGS " -ftls-model=initial-exec")
STRING_APPEND(COMMON_CXX_FLAGS " -ftls-model=initial-exec")
ENDIF()
Expand Down
14 changes: 13 additions & 1 deletion libmysql/dns_srv.cc
Expand Up @@ -40,16 +40,24 @@
// POSIX version

static bool get_dns_srv(Dns_srv_data &data, const char *dnsname, int &error) {
#ifdef LINUX_ALPINE
res_init();
#else
struct __res_state state {};
res_ninit(&state);
#endif
unsigned char query_buffer[NS_PACKETSZ];
bool ret = true;

data.clear();

#ifdef LINUX_ALPINE
int res = res_search(dnsname, ns_c_in, ns_t_srv, query_buffer,
sizeof(query_buffer));
#else
int res = res_nsearch(&state, dnsname, ns_c_in, ns_t_srv, query_buffer,
sizeof(query_buffer));

#endif
if (res >= 0) {
ns_msg msg;
ns_initparse(query_buffer, res, &msg);
Expand Down Expand Up @@ -84,7 +92,11 @@ static bool get_dns_srv(Dns_srv_data &data, const char *dnsname, int &error) {
error = h_errno;
}

#ifdef LINUX_ALPINE
// nothing
#else
res_nclose(&state);
#endif
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion router/src/harness/include/mysql/harness/access_rights.h
Expand Up @@ -32,7 +32,7 @@
#else
#include <sys/stat.h> // stat
#include <sys/types.h>
#include <sys/unistd.h>
#include <unistd.h>
#endif

#include <optional>
Expand Down
2 changes: 2 additions & 0 deletions router/src/router/include/mysqlrouter/utils.h
Expand Up @@ -27,6 +27,8 @@

#include "mysqlrouter/router_export.h"

#include <sys/stat.h> // mode_t

#include <chrono>
#include <cstdint>
#include <functional>
Expand Down
2 changes: 1 addition & 1 deletion sql/memory/aligned_atomic.h
Expand Up @@ -77,7 +77,7 @@ static inline size_t _cache_line_size() {
return line_size;
}

#elif defined(__linux__)
#elif defined(__GLIBC__)
static inline size_t _cache_line_size() {
long size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
if (size == -1) return 64;
Expand Down
6 changes: 6 additions & 0 deletions storage/ndb/src/common/portlib/ndb_stacktrace.cpp
Expand Up @@ -36,7 +36,9 @@
#include <link.h>
#endif

#ifdef HAVE_STACKTRACE
static unsigned long long ndb_get_program_base_address();
#endif

void ndb_init_stacktrace() {
#ifdef HAVE_STACKTRACE
Expand Down Expand Up @@ -76,6 +78,8 @@ unsigned long long ndb_get_program_base_address() {
#elif defined(_WIN32)
unsigned long long ndb_get_program_base_address() { return ULLONG_MAX; }
#else

#ifdef HAVE_STACKTRACE
static int ndb_get_program_base_address_callback(struct dl_phdr_info *info,
size_t /* size */,
void *data) {
Expand All @@ -90,6 +94,8 @@ unsigned long long ndb_get_program_base_address() {
dl_iterate_phdr(&ndb_get_program_base_address_callback, callback_data);
return base_address;
}
#endif // HAVE_STACKTRACE

#endif

#endif
4 changes: 4 additions & 0 deletions unittest/gunit/CMakeLists.txt
Expand Up @@ -307,6 +307,10 @@ SET(SERVER_TESTS
xid_extract
log_event_status_size
)
# Endless loop in FatalSignalDeathTest
IF(LINUX_ALPINE)
LIST(REMOVE_ITEM SERVER_TESTS segfault)
ENDIF()

IF(MY_COMPILER_IS_GNU AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
ADD_COMPILE_FLAGS(regexp_engine-t.cc COMPILE_FLAGS "-Wno-restrict")
Expand Down

0 comments on commit dc6b9e2

Please sign in to comment.