Cgo build failure with android ndk since go1.10

For Syncthing a native Go application is cross-compiled with cgo for Android. Currently those builds still happen on go1.9. We thought the following problem was fixed in go1.11, but testing with beta 3 showed the problem persists. I am asking on the forum first, to check whether this is a user, ndk or golang problem.

The build process is generate a standalone ndk from 15b like so (values of env vars further below):

$NDK_HOME/build/tools/make_standalone_toolchain.py --arch $ARCH --api $MIN_SDK --install-dir $STANDALONE_NDK_DIR -v

Then install std tools:

CGO_ENABLED=1 CC=STANDALONE_NDK_DIR/android-$MIN_SDK-$GOARCH/bin/$CCBIN GOOS=android GOARCH=$GOARCH go install -v std

Then we build the application with a custom build script, which just does some housekeeping around calling go build:

CC=$STANDALONE_NDK_DIR/bin/$CCBIN go run build.go -goos android -goarch $GOARCH -no-upgrade build

This happens for different architectures with the following values:

    {
        'arch': 'arm',
        'goarch': 'arm',
        'ccbin': 'arm-linux-androideabi-clang',
        'min_sdk': 21,
    },
    {
        'arch': 'arm64',
        'goarch': 'arm64',
        'ccbin': 'aarch64-linux-android-clang',
        'min_sdk': 21,
    },
    {
        'arch': 'x86',
        'goarch': '386',
        'ccbin': 'i686-linux-android-clang',
        'min_sdk': 16,
    }

To make sure it’s not related to the ndk version, I also tried it with the most recent (17b).
In the last stage the following error comes up:
arm:

# runtime/cgo
In file included from gcc_libinit.c:8:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/pthread.h:37:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/time.h:33:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/sys/time.h:37:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/sys/select.h:36:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/signal.h:37:
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:79:20: error: expected ';' at end of declaration list
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/asm/signal.h:85:22: note: expanded from macro 'sa_handler'
In file included from gcc_libinit.c:8:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/pthread.h:37:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/time.h:33:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/sys/time.h:37:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/sys/select.h:36:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/signal.h:37:
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:79:20: error: expected ')'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/asm/signal.h:86:24: note: expanded from macro 'sa_sigaction'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:79:20: note: to match this '('
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:74:10: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:79:20: error: duplicate member '_u'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/asm/signal.h:86:22: note: expanded from macro 'sa_sigaction'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:79:20: note: previous declaration is here
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/asm/signal.h:85:20: note: expanded from macro 'sa_handler'
In file included from gcc_libinit.c:8:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/pthread.h:37:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/time.h:33:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/sys/time.h:37:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/sys/select.h:36:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/signal.h:37:
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:80:22: error: expected ';' at end of declaration list
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/asm/signal.h:85:22: note: expanded from macro 'sa_handler'
In file included from gcc_libinit.c:8:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/pthread.h:37:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/time.h:33:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/sys/time.h:37:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/sys/select.h:36:
In file included from /media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/signal.h:37:
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:80:22: error: expected ')'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/asm/signal.h:86:24: note: expanded from macro 'sa_sigaction'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:80:22: note: to match this '('
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:74:10: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:80:22: error: duplicate member '_u'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/asm/signal.h:86:22: note: expanded from macro 'sa_sigaction'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:80:22: note: previous declaration is here
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: expanded from macro '__SIGACTION_BODY'
/media/ext4_data/Coding/syncthing-android/syncthing/gobuild/standalone-ndk/android-16-arm/bin/../sysroot/usr/include/asm/signal.h:85:20: note: expanded from macro 'sa_handler'

Errors for 386 and arm64 left out for now.

Then I was thinking about how to get a reproducer not involving Syncthing, so I tried to cross compile go1.11 beta 3 like this (run in $GOROOT/src):

CC=$STANDALONE_NDK_DIR/bin/$CCBIN GOOS=android GOARCH=$GOARCH ./make.bash

resulting in the exact same failure as above.

With go 1.9 thinks work just fine. Any ideas where the problem might be?

Also should I add the results for arm64 and 386?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.