Repository: racket/racket

Issue #2797: cannot build on alpinelinux
Created: 2019-08-27T10:44:07Z
$ docker run -it --rm alpine
# wget -O - https://mirror.racket-lang.org/installers/7.4/racket-minimal-7.4-src-builtpkgs.tgz | tar -xvz
# apk add gcc libc-dev binutils make
# cd racket-7.4/src
# ./configure
# make -j4
......
gcc -Wall  -I./.. -I./../include  -I./../../rktio -I../../rktio -g -O2  -pthread  -DUSE_SENORA_GC  -c ./syntax.c -o syntax.o
gcc -Wall  -I./.. -I./../include  -I./../../rktio -I../../rktio -g -O2  -pthread  -DUSE_SENORA_GC  -c ./thread.c -o thread.o
gcc -Wall  -I./.. -I./../include  -I./../../rktio -I../../rktio -g -O2  -pthread  -DUSE_SENORA_GC  -c ./type.c -o type.o
gcc -Wall  -I./.. -I./../include  -I./../../rktio -I../../rktio -g -O2  -pthread  -DUSE_SENORA_GC  -c ./unwind/libunwind.c -o unwind.o
In file included from ./unwind/libunwind_i.h:45,
                 from ./unwind/libunwind.c:31:
./unwind/libunwind.h:60: warning: "_XOPEN_SOURCE" redefined
 # define _XOPEN_SOURCE /* needed for Mac OS X */

In file included from /usr/include/inttypes.h:8,
                 from ./unwind/../../mzconfig.h:33,
                 from ./unwind/../../sconfig.h:20,
                 from ./unwind/libunwind.c:26:
/usr/include/features.h:16: note: this is the location of the previous definition
 #define _XOPEN_SOURCE 700

In file included from ./unwind/libunwind.c:31:
./unwind/libunwind_i.h:54: warning: "__BYTE_ORDER" redefined
 # define __BYTE_ORDER __LITTLE_ENDIAN

In file included from /usr/include/sys/types.h:70,
                 from ./unwind/libunwind_i.h:42,
                 from ./unwind/libunwind.c:31:
/usr/include/endian.h:11: note: this is the location of the previous definition
 #define __BYTE_ORDER __BYTE_ORDER__

./unwind/libunwind.c: In function '_Ux86_64_uc_addr':
./unwind/libunwind.c:3085:55: error: 'REG_R8' undeclared (first use in this function); did you mean 'EM_RX'?
     case UNW_X86_64_R8: addr = &uc->uc_mcontext.gregs[REG_R8]; break;
                                                       ^~~~~~
                                                       EM_RX
./unwind/libunwind.c:3085:55: note: each undeclared identifier is reported only once for each function it appears in
./unwind/libunwind.c:3086:55: error: 'REG_R9' undeclared (first use in this function); did you mean 'EM_RX'?
     case UNW_X86_64_R9: addr = &uc->uc_mcontext.gregs[REG_R9]; break;
                                                       ^~~~~~
                                                       EM_RX
./unwind/libunwind.c:3087:56: error: 'REG_R10' undeclared (first use in this function)
     case UNW_X86_64_R10: addr = &uc->uc_mcontext.gregs[REG_R10]; break;
                                                        ^~~~~~~
./unwind/libunwind.c:3088:56: error: 'REG_R11' undeclared (first use in this function)
     case UNW_X86_64_R11: addr = &uc->uc_mcontext.gregs[REG_R11]; break;
                                                        ^~~~~~~
./unwind/libunwind.c:3089:56: error: 'REG_R12' undeclared (first use in this function)
     case UNW_X86_64_R12: addr = &uc->uc_mcontext.gregs[REG_R12]; break;
                                                        ^~~~~~~
./unwind/libunwind.c:3090:56: error: 'REG_R13' undeclared (first use in this function)
     case UNW_X86_64_R13: addr = &uc->uc_mcontext.gregs[REG_R13]; break;
                                                        ^~~~~~~
./unwind/libunwind.c:3091:56: error: 'REG_R14' undeclared (first use in this function)
     case UNW_X86_64_R14: addr = &uc->uc_mcontext.gregs[REG_R14]; break;
                                                        ^~~~~~~
./unwind/libunwind.c:3092:56: error: 'REG_R15' undeclared (first use in this function)
     case UNW_X86_64_R15: addr = &uc->uc_mcontext.gregs[REG_R15]; break;
                                                        ^~~~~~~
./unwind/libunwind.c:3093:56: error: 'REG_RDI' undeclared (first use in this function)
     case UNW_X86_64_RDI: addr = &uc->uc_mcontext.gregs[REG_RDI]; break;
                                                        ^~~~~~~
./unwind/libunwind.c:3094:56: error: 'REG_RSI' undeclared (first use in this function)
     case UNW_X86_64_RSI: addr = &uc->uc_mcontext.gregs[REG_RSI]; break;
                                                        ^~~~~~~
./unwind/libunwind.c:3095:56: error: 'REG_RBP' undeclared (first use in this function)
     case UNW_X86_64_RBP: addr = &uc->uc_mcontext.gregs[REG_RBP]; break;
                                                        ^~~~~~~
./unwind/libunwind.c:3096:56: error: 'REG_RBX' undeclared (first use in this function); did you mean 'EM_RX'?
     case UNW_X86_64_RBX: addr = &uc->uc_mcontext.gregs[REG_RBX]; break;
                                                        ^~~~~~~
                                                        EM_RX
./unwind/libunwind.c:3097:56: error: 'REG_RDX' undeclared (first use in this function); did you mean 'EM_RX'?
     case UNW_X86_64_RDX: addr = &uc->uc_mcontext.gregs[REG_RDX]; break;
                                                        ^~~~~~~
                                                        EM_RX
./unwind/libunwind.c:3098:56: error: 'REG_RAX' undeclared (first use in this function); did you mean 'EM_RX'?
     case UNW_X86_64_RAX: addr = &uc->uc_mcontext.gregs[REG_RAX]; break;
                                                        ^~~~~~~
                                                        EM_RX
./unwind/libunwind.c:3099:56: error: 'REG_RCX' undeclared (first use in this function); did you mean 'EM_RCE'?
     case UNW_X86_64_RCX: addr = &uc->uc_mcontext.gregs[REG_RCX]; break;
                                                        ^~~~~~~
                                                        EM_RCE
./unwind/libunwind.c:3100:56: error: 'REG_RSP' undeclared (first use in this function); did you mean 'EM_ZSP'?
     case UNW_X86_64_RSP: addr = &uc->uc_mcontext.gregs[REG_RSP]; break;
                                                        ^~~~~~~
                                                        EM_ZSP
./unwind/libunwind.c:3101:56: error: 'REG_RIP' undeclared (first use in this function)
     case UNW_X86_64_RIP: addr = &uc->uc_mcontext.gregs[REG_RIP]; break;
                                                        ^~~~~~~
make[7]: *** [Makefile:295: unwind.o] Error 1
make[7]: *** Waiting for unfinished jobs....
make[7]: Leaving directory '/racket-7.4/src/racket/src'
make[6]: *** [Makefile:138: all] Error 2
make[6]: Leaving directory '/racket-7.4/src/racket/src'
make[5]: *** [Makefile:159: mzlibrary] Error 2
make[5]: Leaving directory '/racket-7.4/src/racket'
make[4]: *** [Makefile:99: cgc-core] Error 2
make[4]: Leaving directory '/racket-7.4/src/racket'
make[3]: *** [Makefile:93: cgc] Error 2
make[3]: Leaving directory '/racket-7.4/src/racket'
make[2]: *** [Makefile:107: 3m] Error 2
make[2]: Leaving directory '/racket-7.4/src/racket'
make[1]: *** [Makefile:61: 3m] Error 2
make[1]: Leaving directory '/racket-7.4/src'
make: *** [Makefile:51: all] Error 2

Duplicate issue #1638: Compile error building Racket 6.8 on Alpine Linux (3.4)
Created: 2017-03-21T05:22:17Z
Some interesting issue with gcc is showing up on Alpine (I don't see it on Ubuntu).
Question: Is this a subtle coding error, or is it something that needs to be worked around with a gcc flag of some kind?
I'm getting this warning (which leads to later errors) when building Racket 6.8 from source on Alpine Linux 3.4:
gcc -D_GNU_SOURCE   -Wall  -I./.. -I./../include -D_GNU_SOURCE -g -O2  -pthread  -DUSE_SENORA_GC  -c ./jitstack.c -o jitstack.o
In file included from ./jitstack.c:24:0:
./jitstack.c: In function 'scheme_native_stack_trace':
./unwind/libunwind.h:239:50: warning: right-hand operand of comma expression has no effect [-Wunused-value]
 #define unw_tdep_getcontext(uc)  (getcontext (uc), 0)
                                                  ^
./unwind/libunwind.h:456:29: note: in expansion of macro 'unw_tdep_getcontext'
 #define unw_getcontext(uc)  unw_tdep_getcontext(uc)
                             ^
./jitstack.c:201:3: note: in expansion of macro 'unw_getcontext'
   unw_getcontext(&cx);
   ^

which leads to this eventual error:
gcc -I. -I./include -D_GNU_SOURCE   -Wall   -D_GNU_SOURCE -g -O2  -pthread  -DUSE_SENORA_GC  -DINITIAL_COLLECTS_DIRECTORY='"'"`cd ./../../collects; pwd`"'"' -DINITIAL_CONFIG_DIRECTORY='"'"`cd ./../..; pwd`/etc"'"' -c ./main.c -o main.o
gcc -o racketcgc main.o  libracket.a libmzgc.a  -pthread -ldl -lm  -ldl -lm -rdynamic 
libracket.a(jitstack.o): In function `scheme_native_stack_trace':
/usr/src/racket/src/racket/src/./jitstack.c:201: undefined reference to `getcontext'
collect2: error: ld returned 1 exit status
make[5]: *** [racketcgc] Error 1

The GCC version is:
/ # gcc --version
gcc (Alpine 5.3.0) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I use this Dockerfile to perform the build (note that CFLAGS defines _GNU_SOURCE, something I don't have to do on Ubuntu, needed on Alpine to avoid other compile errors):
FROM alpine:3.4

# Update apk package indexes and install dependencies
#
RUN apk update \
    && apk add --no-cache ca-certificates openssl sqlite readline \
    && mkdir -p /xpt/local

# Copy racket source tarball from local directory to image
#
COPY tmp/racket-6.8-src-builtpkgs.tgz /tmp/delme/

# Install tar so we can extract source code
#
RUN set -ex \
    && apk add --no-cache --virtual .fetch-deps \
        tar \
    \
    # extract source code
    #
    && mkdir -p /usr/src/racket \
    && tar -xzC /usr/src/racket --strip-components=1 -f /tmp/delme/racket-6.8-src-builtpkgs.tgz \
    && rm -r /tmp/delme \
    \
    # install build tools
    #
    && apk add --no-cache  \
        gcc \
        g++ \
        gdbm-dev \
        linux-headers \
        make \
        musl-dev \
        openssl-dev \
        readline-dev \
        sqlite-dev \
    # add build deps before removing fetch deps in case there's overlap
    #
    # remove fetch dependencies
    #
    && apk del .fetch-deps

# build racket
#
RUN cd /usr/src/racket/src \
	&& ./configure --prefix=/xpt/local CFLAGS='-D_GNU_SOURCE ' CPPFLAGS='-D_GNU_SOURCE -g -O2 ' \
	&& make -j$(getconf _NPROCESSORS_ONLN) \
	&& make install

Closing comment (2019-12-19T09:20:31Z): Same as #2797
Fixed in 843824c