Skip to content

Commit

Permalink
[#213] Changes that let YottaDB be built and run correctly on Alpine
Browse files Browse the repository at this point in the history
Note while the build part seems to work well, there are a number of tests that do not
yet run correctly so this work is only partially complete but is ongoing as a background
(not prioritized) activity. But we got this far so wanted to merge it since it does not
affect the other platforms.

We would like to thank Matthew Hughes (@matt312@gitlab) for the initial mods to allow
YottaDB to build on Alpine (MR !835). Certain of those changes were pulled into this merge
which contains additional changes that allow at least some parts of our test regression
suite to run. They will all run before this is a supportable platform - this is just the
first wave of changes.

Alpine uses the musl libc instead of GNU's glibc. This is a "bare-bones" version of libc
without many of glibc's extensions. Alpine also uses "BusyBox" (generally for embedded
systems) to provide many of the common system utility commands. For example, "ping" is
a root-only command in Alpine. Several options on the ps and ls commands are also either
different or missing. The entire output of the ls command is different so tests looking
for information in files or processes have to be modified to be able to work correctly
on Alpine.

Change summary:

- CMakeLists.txt - Added messages suggested by @nars1 so we could see what libraries were
  being used.
- sr_linux/caller_id.c - Treat a musl build much like cygwin (no backtrace supported).
- sr_port/dse_chng_fhead.c - Just moving gtm_string.h include to where it belongs. Out of
  order build caused issues on Alpine.
- sr_port/dse_rest.c - Same.
- sr_port/dse_save.c - Same.
- sr_port/gtm_malloc_src.h - The mallopt() call does not exist on Alpine so adjust #ifdef
- sr_port/iosocket_snr.c - Include the correct include - a gtm_poll.h version was available
- sr_port/iosocket_wait.c - Same.
- sr_port/mdef.h - Define __MUSL for Alpine builds, some mitigation of memcpy() macro
  issues because of how sched.h gets included (see comments in mdef.h).
- sr_port/repl_comm.c - Include the correct include - a gtm_poll.h version was available
- sr_port/repl_filter.c - Move an #ifdef/#include to avoid build errors on alpine.
- sr_unix/configure.gtc - Use gold loader to build shared libraries on alpine. When the
  regular loader built a shared library from M program object code, the MUSL version of
  dlopen() was unable to load the created shared library. The gold loader fixes this issue.
- sr_unix/gtm_filter_command.c - Move mdef.h to top of include list (build issues).
- sr_unix/iormdef.h - Make assert GLIBC only as Alpine does not have the fields used in
  the assert.
- sr_unix/mdefsp.h - Alpinemusl uses va_copy differently than does glibc.
  • Loading branch information
estess committed Dec 14, 2020
1 parent c7fd760 commit 65751cd
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ foreach(gpglib gpg-error gpgme gcrypt config)
find_library(GPGLIB_${gpglib} NAME ${gpglib} PATHS ${CMAKE_LIBRARY_PATH})
# Append the found library to the list
set(GPG_LIBRARIES ${GPG_LIBRARIES} ${GPGLIB_${gpglib}})
message(STATUS "GPGLIB_${gpglib}=${GPGLIB_${gpglib}}")
endforeach()

# Iterate over the list of SSL related libraries
Expand All @@ -484,6 +485,7 @@ foreach(tlslib ssl crypto config)
find_library(TLSLIB_${tlslib} NAME ${tlslib} PATHS ${CMAKE_LIBRARY_PATH})
# Append the found library to the list
set(TLS_LIBRARIES ${TLS_LIBRARIES} ${TLSLIB_${tlslib}})
message(STATUS "TLSLIB_${tlslib}=${TLSLIB_${tlslib}}")
endforeach()

# Building the three encryption libraries could by a loop of some sort, but
Expand Down
12 changes: 8 additions & 4 deletions sr_linux/caller_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright (c) 2008-2015 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2020 YottaDB LLC and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
Expand All @@ -29,7 +32,8 @@

#include "gtm_stdlib.h"
#include "gtm_signal.h"
#ifndef __CYGWIN__
/* Note the use of __GLIBC__ here precludes this include on CYGWIN and Alpine(MUSL environments */
#ifdef __GLIBC__
#include <execinfo.h>
#endif

Expand Down Expand Up @@ -74,16 +78,16 @@ caddr_t caller_id(void)
if (blocksig_initialized)
SIGPROCMASK(SIG_BLOCK, &block_sigsent, &savemask, rc);
caller_id_reent = TRUE;
#ifndef __CYGWIN__
#ifdef __GLIBC__
trace_size = backtrace(trace, MAX_TRACE_DEPTH);
#else
/* Cygwin does not support backtrace() */
/* Neither Cygwin (newlib based libc) or Alpine (musl libc) support backtrace() which is a GNU extension */
trace_size = 0;
#endif
caller_id_reent = FALSE;
if (blocksig_initialized)
SIGPROCMASK(SIG_SETMASK, &savemask, NULL, rc);
/* backtrace will return call stack with address.*/
/* Backtrace will return call stack with address */
if (RETURN_ADDRESS_DEPTH <= trace_size)
return (caddr_t)trace[RETURN_ADDRESS_DEPTH];
else
Expand Down
6 changes: 4 additions & 2 deletions sr_port/dse_chng_fhead.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2001-2018 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2018-2019 YottaDB LLC and/or its subsidiaries. *
* Copyright (c) 2018-2020 YottaDB LLC and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
Expand All @@ -28,11 +28,13 @@
*
*******************************************************************************/

#include "gtm_string.h"
#include "mdef.h"

#include "gtm_stdlib.h"
#include "gtm_unistd.h"
#include "gtm_stdio.h"
#include "gtm_string.h"

#include "gdsroot.h"
#include "gtm_facility.h"
#include "fileinfo.h"
Expand Down
8 changes: 6 additions & 2 deletions sr_port/dse_rest.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/****************************************************************
* *
* Copyright 2001, 2014 Fidelity Information Services, Inc *
* Copyright 2001, 2014 Fidelity Information Services, Inc *
* *
* Copyright (c) 2020 YottaDB LLC and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
Expand All @@ -9,9 +12,10 @@
* *
****************************************************************/

#include "gtm_string.h"
#include "mdef.h"

#include "gtm_string.h"

#include "gdsroot.h"
#include "gtm_facility.h"
#include "fileinfo.h"
Expand Down
7 changes: 6 additions & 1 deletion sr_port/dse_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
* Copyright (c) 2001-2018 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2020 YottaDB LLC and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
* the license, please stop and do not read further. *
* *
****************************************************************/

#include "gtm_string.h"
#include "mdef.h"

#include "gtm_string.h"

#include "gdsroot.h"
#include "gtm_facility.h"
#include "fileinfo.h"
Expand Down
6 changes: 3 additions & 3 deletions sr_port/gtm_malloc_src.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2001-2019 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2017-2019 YottaDB LLC and/or its subsidiaries. *
* Copyright (c) 2017-2020 YottaDB LLC and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
Expand Down Expand Up @@ -486,15 +486,15 @@ void gtmSmInit(void) /* Note renamed to gtmSmInit_dbg when included in gtm_mallo
* are setup nor (potentially) most of the GTM runtime.
*/
assert(MINTWO == TwoTable[0]);
# if defined(__linux__) && !defined(__i386)
# if defined(__linux__) && !defined(__i386) && !defined(__MUSL)
/* This will make sure that all the memory allocated using 'malloc' will be in heap and no 'mmap' is used.
* This is needed to make sure that the offset calculation that we do at places(que_ent, chache_que, etc..)
* using 2 'malloc'ed memory can be hold in an integer. Though this will work without any problem as the
* current GT.M will not allocate memory more than 4GB, we should find a permanant solution by migrating those
* offset fields to long and make sure all other related application logic works fine.
*/
mallopt(M_MMAP_MAX, 0);
# endif /* __linux__ && !__i386 */
# endif /* __linux__ && !__i386 && !__MUSL */
/* Check that the storage queue offset in a storage element has sufficient reach
* to cover an extent.
*/
Expand Down
4 changes: 3 additions & 1 deletion sr_port/iosocket_snr.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* -- if the device buffer is used, move it over to the return buffer and update the device buffer pointer
*/
#include "mdef.h"

#include <sys/types.h>
#include <errno.h>
#include "gtm_stdio.h"
Expand All @@ -53,10 +54,11 @@ static int fcntl_res;
#include <sys/time.h> /* for gettimeofday */
#endif
#ifdef GTM_USE_POLL_FOR_SUBSECOND_SELECT
#include <sys/poll.h>
#include "gtm_poll.h"
#endif
#endif
#include "gtm_select.h"

#include "eintr_wrappers.h"
#include "gt_timer.h"
#include "io.h"
Expand Down
4 changes: 3 additions & 1 deletion sr_port/iosocket_wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
* timeout -- set $Test to 1
*/
#include "mdef.h"

#include <errno.h>
#include "gtm_socket.h"
#include "gtm_inet.h"
#include "gtm_stdio.h"
#include "gtm_string.h"
#include "gtm_unistd.h"
#include <sys/poll.h>
#include "gtm_poll.h"

#include "io_params.h"
#include "gt_timer.h"
#include "io.h"
Expand Down
32 changes: 29 additions & 3 deletions sr_port/mdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,31 @@
#endif

#ifdef __linux__
#define CRIT_USE_PTHREAD_MUTEX
# include <features.h> /* Needed to define __GLIBC__ if it exists */
# define CRIT_USE_PTHREAD_MUTEX
# if defined(__GLIBC__)
# define GLIBC_ONLY(X) X
# define NON_GLIBC_ONLY(X)
# else
# if !defined(__CYGWIN__)
/* Note: MUSL's lack of a way to definitelively identify it (no #define) has generated significant discussion
* on MUSL discussion threads but to date, none exists. So our methodology here is if it isn't GLIBC and isn't
* CYGWIN, then it must be Alpine/MUSL. Best we can do under the circumstances.
*/
# define __MUSL
/* Define this to bypass the redefine of memcpy() as a macro. This causes problems when pthread.h includes sched.h
* on Alpine Linux as it has a declaration for memcpy in it that causes major conflicts with the override of memcpy()
* in gtm_string.h
*/
# define BYPASS_MEMCPY_OVERRIDE
# endif
# define GLIBC_ONLY(X)
# define NON_GLIBC_ONLY(X) X
# endif
#else
/* For non-Linux builds, treat as if GLIBC */
# GLIBC_ONLY(X) X
# NON_GLIBC_ONLY(X)
#endif

# define MSTR_CONST(name, string) mstr name = {0, LEN_AND_LIT(string)}
Expand Down Expand Up @@ -205,11 +229,13 @@ typedef UINTPTR_T uintszofptr_t;
#ifdef __linux__
# define LINUX_ONLY(X) X
# define NON_LINUX_ONLY(X)
# define YDB_USE_POSIX_TIMERS
# if !defined(__MUSL)
# /* Verify Alpine/MUSL can't use POSIX timers ##ALPINE_TODO## */
# define YDB_USE_POSIX_TIMERS
# endif
#else
# define LINUX_ONLY(X)
# define NON_LINUX_ONLY(X) X
# undef YDB_USE_POSIX_TIMERS
#endif

#ifdef __MVS__
Expand Down
3 changes: 1 addition & 2 deletions sr_port/repl_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <errno.h>
# include <sys/poll.h>

#include "gtm_poll.h"
#include "gtm_stdio.h"
#include "gtm_string.h"
#include "gtm_socket.h"
Expand Down
6 changes: 3 additions & 3 deletions sr_port/repl_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "gtm_stdio.h"
#include "gtm_select.h"
#include "gtm_ipc.h"
#ifdef GTM_USE_POLL_FOR_SUBSECOND_SELECT
#include "gtm_poll.h"
#endif

#include <sys/mman.h>
#include <sys/shm.h>
Expand Down Expand Up @@ -57,9 +60,6 @@
#include "gtm_c_stack_trace.h"
#include "fork_init.h"
#include "wbox_test_init.h"
#ifdef GTM_USE_POLL_FOR_SUBSECOND_SELECT
#include <sys/poll.h>
#endif
#ifdef GTM_TRIGGER
#include "trigger.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion sr_unix/configure.gtc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ elif [ "linux" = $arch ] ; then
if [ "$isarm_ydb" -eq 1 ] ; then
ldcmd="cc" # On Linux/ARM only cc (not ld) creates a valid ELF header when compiling M routines
else
ldcmd="ld" # Linux - all platforms
ldcmd="ld.gold" # Linux - all platforms
fi
else echo "Shared libary ldflags not set for this platform"; exit 1
fi
Expand Down
4 changes: 3 additions & 1 deletion sr_unix/gtm_filter_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
* the license, please stop and do not read further. *
* *
****************************************************************/
#include "mdef.h"

#include "gtm_filter_command.h"
#include "gtm_string.h"
#include "mdef.h"

#include "gtmmsg.h"
#include "send_msg.h"
#include "gtm_threadgbl.h"
Expand Down
9 changes: 6 additions & 3 deletions sr_unix/iormdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2001-2019 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* Copyright (c) 2019 YottaDB LLC and/or its subsidiaries. *
* Copyright (c) 2019-2020 YottaDB LLC and/or its subsidiaries. *
* All rights reserved. *
* *
* This source code contains the intellectual property *
Expand Down Expand Up @@ -85,8 +85,11 @@ error_def(ERR_CRYPTBADWRTPOS);
int fclose_res, rc, save_fd; \
\
if (NULL != D_RM->FILSTR) \
{ /* Since FCLOSE also closes the fd, reset FILDES (no need to close it separately). */ \
LINUX_ONLY(assert(D_RM->FILDES == D_RM->FILSTR->_fileno);) \
{ /* Since FCLOSE also closes the fd, reset FILDES (no need to close it separately). \
* Note this assert is bypassed on non-GLIBC platforms as the _fileno field does not \
* exist there. \
*/ \
GLIBC_ONLY(assert(D_RM->FILDES == D_RM->FILSTR->_fileno)); \
if (!process_exiting) \
{ /* Only do the actual FCLOSE() if the process is not exiting because a) the OS \
* takes care of opened file descriptors anyway; and b) we might have received \
Expand Down
7 changes: 6 additions & 1 deletion sr_unix/mdefsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ typedef uint4 mach_inst; /* machine instruction */
typedef unsigned short in_port_t;
#endif
#ifndef VAR_COPY
#define VAR_COPY(dst,src) __va_copy(dst, src)
/* Extra check for va_copy is because Alpine/musl does this differently than does glibc */
#ifndef va_copy
#define VAR_COPY(dst,src) __va_copy(dst, src)
#else
#define VAR_COPY(dst,src) va_copy(dst, src)
#endif
#endif
#ifdef __s390__
#ifndef Linux390
Expand Down

0 comments on commit 65751cd

Please sign in to comment.