can't build linux arm

This issue has been created since 2020-10-26.

get this error when trying to build for arm64 or armv7
/usr/local/go/src/vendor/golang.org/x/crypto/poly1305/sum_noasm.go:10:7: undefined: newMAC

2020/10/25 17:59:15 [INFO] Temporary folder: /tmp/buildenv_2020-10-25-1759.651426086
2020/10/25 17:59:15 [INFO] Writing main module: /tmp/buildenv_2020-10-25-1759.651426086/main.go
2020/10/25 17:59:15 [INFO] Initializing Go module
2020/10/25 17:59:15 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init caddy

go: creating new go.mod: module caddy
2020/10/25 17:59:15 [INFO] Pinning versions
2020/10/25 17:59:15 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2
go: github.com/caddyserver/caddy/v2 upgrade => v2.2.1
2020/10/25 17:59:17 [INFO] Build environment ready
2020/10/25 17:59:17 [INFO] Building Caddy
2020/10/25 17:59:17 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /opt/caddy/build/bin/linux-arm64 -ldflags -w -s -trimpath
# vendor/golang.org/x/crypto/poly1305
/usr/local/go/src/vendor/golang.org/x/crypto/poly1305/sum_noasm.go:10:7: undefined: newMAC
2020/10/25 17:59:19 [INFO] Cleaning up temporary folder: /tmp/buildenv_2020-10-25-1759.651426086
2020/10/25 17:59:19 [FATAL] exit status 2

using
GOOS=linux GOARCH=arm64 /opt/caddy/build/bin/xcaddy build --output /opt/caddy/build/bin/linux-arm64

GOOS=linux GOARCH=arm GOARM=7 /opt/caddy/build/bin/xcaddy build --output /opt/caddy/build/bin/linux-arm-7

no problem buiding for linux amd64

using very latest xcaddy, latest golang on amd64 machine

am I missing some cross compile tool chain??

dkebler wrote this answer on 2020-10-26

related to this? golang/go#39760

mohammed90 wrote this answer on 2020-10-26

Do you have the CGO_ENABLED env var set? Can you please run go env CGO_ENABLED and echo $CGO_ENABLED and report the output

dkebler wrote this answer on 2020-10-26

go env CGO_ENABLED
1
echo $CGO_ENABLED
<null value>

I am running this via a bash script. so I added
export CGO_ENABLED=1
and got more explicit errors (for gcc)
my script is below this output

 ./build 
deleting any old executable linux-arm64
Building binary linux-arm64
GO environment before running xcaddy
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/home/david/.cache/go-build"
GOENV="/home/david/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/opt/caddy/build/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/opt/caddy/build"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build218015767=/tmp/go-build -gno-record-gcc-switches"
building with
/opt/caddy/build/bin/xcaddy build --output /opt/caddy/build/bin/linux-arm64
2020/10/26 13:20:31 [INFO] Temporary folder: /tmp/buildenv_2020-10-26-1320.497900426
2020/10/26 13:20:31 [INFO] Writing main module: /tmp/buildenv_2020-10-26-1320.497900426/main.go
2020/10/26 13:20:31 [INFO] Initializing Go module
2020/10/26 13:20:31 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init caddy 
go: creating new go.mod: module caddy
2020/10/26 13:20:31 [INFO] Pinning versions
2020/10/26 13:20:31 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2 
go: github.com/caddyserver/caddy/v2 upgrade => v2.2.1
2020/10/26 13:20:32 [INFO] Build environment ready
2020/10/26 13:20:32 [INFO] Building Caddy
2020/10/26 13:20:32 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /opt/caddy/build/bin/linux-arm64 -ldflags -w -s -trimpath 
# vendor/golang.org/x/crypto/poly1305
/usr/local/go/src/vendor/golang.org/x/crypto/poly1305/sum_noasm.go:10:7: undefined: newMAC
# runtime/cgo
gcc_arm64.S: Assembler messages:
gcc_arm64.S:28: Error: no such instruction: `stp x29,x30,[sp,'
gcc_arm64.S:32: Error: too many memory references for `mov'
gcc_arm64.S:34: Error: no such instruction: `stp x19,x20,[sp,'
gcc_arm64.S:37: Error: no such instruction: `stp x21,x22,[sp,'
gcc_arm64.S:40: Error: no such instruction: `stp x23,x24,[sp,'
gcc_arm64.S:43: Error: no such instruction: `stp x25,x26,[sp,'
gcc_arm64.S:46: Error: no such instruction: `stp x27,x28,[sp,'
gcc_arm64.S:50: Error: too many memory references for `mov'
gcc_arm64.S:51: Error: too many memory references for `mov'
gcc_arm64.S:52: Error: too many memory references for `mov'
gcc_arm64.S:54: Error: no such instruction: `blr x20'
gcc_arm64.S:55: Error: no such instruction: `blr x19'
gcc_arm64.S:57: Error: no such instruction: `ldp x27,x28,[sp,'
gcc_arm64.S:60: Error: no such instruction: `ldp x25,x26,[sp,'
gcc_arm64.S:63: Error: no such instruction: `ldp x23,x24,[sp,'
gcc_arm64.S:66: Error: no such instruction: `ldp x21,x22,[sp,'
gcc_arm64.S:69: Error: no such instruction: `ldp x19,x20,[sp,'
gcc_arm64.S:72: Error: no such instruction: `ldp x29,x30,[sp],'
2020/10/26 13:20:33 [INFO] Cleaning up temporary folder: /tmp/buildenv_2020-10-26-1320.497900426
2020/10/26 13:20:33 [FATAL] exit status 2
...done building

#!/bin/bash
DIR="$(dirname "$(readlink -f "$0")")"
export GOPATH=$DIR
# set a specific release
# REL=v2.0.0
PLUGINS=''
while IFS= read -r line; do
    [ $line ] && echo Using Plugin: $line
    PLUGINS=`[ $line ] && echo $PLUGINS' --with '$line`
done < $DIR/plugins.txt
# reading builds file
cat $DIR/builds.txt | while read GOOS GOARCH GOARM;
do
GOOS=${GOOS:-linux}
GOARCH=${GOARCH:-amd64}
BIN_NAME=$GOOS-$GOARCH`[ $GOARM ] && echo -$GOARM`
echo deleting any old executable $BIN_NAME
[ -f $DIR/bin/$BIN_NAME ] && rm $DIR/bin/$BIN_NAME
echo Building binary $BIN_NAME
export GOOS=$GOOS
export GOARCH=$GOARCH
export CGO_ENABLED=1
[ $GOARM ] && export GOARM=$GOARM
echo GO environment before running xcaddy
go env
echo building with
echo $DIR/bin/xcaddy build $REL \
   --output $DIR/bin/$BIN_NAME \
   $PLUGINS
$DIR/bin/xcaddy build $REL \
   --output $DIR/bin/$BIN_NAME \
   $PLUGINS
echo ...done building
[ -f $DIR/BIN/$ARCH ] && $DIR/bin/$ARCH version
done

mholt wrote this answer on 2020-10-27

Just for kicks, does it cross-compile fine without xcaddy (i.e. using go build)?

My guess is there's something wrong with a dependency or a compiler config somewhere, so I want to first rule out xcaddy if possible.

dkebler wrote this answer on 2020-10-28

Not a go coder so not played with go build much and not to cross compile. Caddy is my first attempt to cross compile anything in go
What would be the command sans xcaddy? Do I need to get/clone the Caddy source?

dkebler wrote this answer on 2020-10-28

Nevermind I got it figured out. Same exact error output though :( so not xcaddy

cloned source and then ran this script.

export GOOS=linux 
export GOARCH=arm64
export CGOENABLED=1
go env
go build

output

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/home/david/.cache/go-build"
GOENV="/home/david/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/opt/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/opt/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/opt/caddys/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build274847731=/tmp/go-build -gno-record-gcc-switches"
# vendor/golang.org/x/crypto/poly1305
/usr/local/go/src/vendor/golang.org/x/crypto/poly1305/sum_noasm.go:10:7: undefined: newMAC
# runtime/cgo
gcc_arm64.S: Assembler messages:
gcc_arm64.S:28: Error: no such instruction: `stp x29,x30,[sp,'
gcc_arm64.S:32: Error: too many memory references for `mov'
gcc_arm64.S:34: Error: no such instruction: `stp x19,x20,[sp,'
gcc_arm64.S:37: Error: no such instruction: `stp x21,x22,[sp,'
gcc_arm64.S:40: Error: no such instruction: `stp x23,x24,[sp,'
gcc_arm64.S:43: Error: no such instruction: `stp x25,x26,[sp,'
gcc_arm64.S:46: Error: no such instruction: `stp x27,x28,[sp,'
gcc_arm64.S:50: Error: too many memory references for `mov'
gcc_arm64.S:51: Error: too many memory references for `mov'
gcc_arm64.S:52: Error: too many memory references for `mov'
gcc_arm64.S:54: Error: no such instruction: `blr x20'
gcc_arm64.S:55: Error: no such instruction: `blr x19'
gcc_arm64.S:57: Error: no such instruction: `ldp x27,x28,[sp,'
gcc_arm64.S:60: Error: no such instruction: `ldp x25,x26,[sp,'
gcc_arm64.S:63: Error: no such instruction: `ldp x23,x24,[sp,'
gcc_arm64.S:66: Error: no such instruction: `ldp x21,x22,[sp,'
gcc_arm64.S:69: Error: no such instruction: `ldp x19,x20,[sp,'
gcc_arm64.S:72: Error: no such instruction: `ldp x29,x30,[sp],'

dkebler wrote this answer on 2020-10-28

I am running
go1.15.2 linux/amd64
but my gcc compiler is a bit stale (default for ubuntu 18.04)
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

just stabbing in the dark but maybe the gcc cross compile setup is not right. Apparently some modules that contain c code must be compiled for some architecture targets?

dkebler wrote this answer on 2020-10-28

see this. ethereum/go-ethereum#16818

"To build it, you need a full C cross compilation toolkit." is this what I am missing that is on your build machines?. Somehow I can't believe I am the first non dev to try an arm build. I am the first to not have his dev machine set up for full C cross compile?? I have build essential installed wonder what this toolkit is mentioned?

dkebler wrote this answer on 2020-10-28

This might be helpful to me. Looks like my CC=gcc is just pointing to plain gcc and not some cross compiler version although that was old advice pre 1.5
https://gist.github.com/steeve/6905542

mholt wrote this answer on 2020-10-28

Hmm I haven't had experience with these kinds of issues... we always build with CGO_ENABLED=0.

I'm glad it's not a bug in xcaddy though!

dkebler wrote this answer on 2020-10-28

I installed latest golang 1.15.3, gcc and g++ (9+) and set CGO_ENABLED=0 tried again.
TADA!

Tried xcaddy again TADA!

moved binary to my arm64 machine. ran caddy version and yes! I'm set now.

Do you all use latest golang and gcc when doing caddy development? If so I'll always use latest with xcaddy.

mholt wrote this answer on 2020-10-28

Great!

Lately, we require the newest minor version of Go minus one, so Go 1.14 is required for now.

Could have also been a bugfix in the latest patch release, I dunno. I'm more willing to suspect CGO_ENABLED was the real solution?

mohammed90 wrote this answer on 2020-10-28

You shouldn't need gcc (or g++) with CGO_ENABLED=0, unless one of the plugins/modules has C dependency. Plain Caddy with the standard modules doesn't need C, so you can just ditch gcc and compile everything statically with cgo disabled.

More Details About Repo
Owner Name caddyserver
Repo Name xcaddy
Full Name caddyserver/xcaddy
Language Go
Created Date 2020-03-21
Updated Date 2022-09-22
Star Count 381
Watcher Count 14
Fork Count 72
Issue Count 3

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
How to include a custom model? 7 2022-09-14 2022-09-23
Add a field `creator_name` in the issues and pull_requests table 1 2022-05-23 2022-09-16
network datashare_default not found during docker install when using docker-compose 2.x 0 2021-10-28 2022-05-20
Having "Creepers can't climb" enabled makes the player unable to climb aswell 0 2022-09-06 2022-09-16
spatial tutorial about np.concatenate 1 2020-12-02 2022-08-04
Defocused Image Generation 1 2021-08-20 2022-05-15
cannot download the dataset and pretrained_model 2 2021-06-01 2022-05-15
OneOf Subtyping - Generators were failing to generate proper discriminators 3 2021-03-08 2022-05-21
Problems in the inference stage 0 2021-10-11 2022-05-08
<a-dropdown-button>组件无法正常打包 0 2022-04-16 2022-09-13
chunjun1.12版本——执行MYSQL-DM时,任务一直处于执行状态(所提供日志最后一行),但是DM到其他库是没有问题 12 2022-07-12 2022-08-22
Not using singleton configuration 2 2021-07-01 2022-09-20
OMG Ghost! - Settings window freezes the OS 0 2019-12-13 2022-08-21
Visualize network traffic 8 2020-02-05 2022-09-20
ExifUtil.getExifOrientation does not work for images containing other exif data alongwith Orientation 13 2016-12-21 2022-09-14
translations not work 3 2021-05-29 2022-08-24
Mismatch between documentation's example and git repo's examples 1 2022-06-17 2022-08-30
bitte mal mit der neusten Version probieren :)Es gab ein fix: #472 https://github.com/iamnotturner/vaccipy/releases/tag/v1.2.11 1 2021-06-15 2022-08-22
How to get all retweets from a twitter user 6 2022-07-12 2022-09-05
there is a zombie process 2 2022-05-11 2022-09-06
When I add a cron job with a time in the past, I get a scheduled job in the future 1 2022-07-09 2022-09-25
逍遥模拟器和夜神模拟器里FakeLocation账户无法登陆,显示connect timed out 0 2021-04-25 2022-09-09
rewrite Curv to use WebGPU 0 2021-10-04 2022-09-28
much slower for 3D-tensor calculate 0 2022-05-14 2022-09-10
Orion: don't seem to work on windows 5 2022-03-03 2022-09-17
The latest Docker image is missing 'postgres' extra in the image prefecthq/prefect:latest-python3.8 3 2022-03-03 2022-09-17
Release namespace in conjunction with labels selector 1 2022-02-17 2022-09-21
🔥 connect/connect-servicenow-source 1 2022-05-11 2022-07-20
作者是外国人?还是写了给外国人用的? 10 2021-07-28 2022-01-13
Add [insert language name here] 0 2021-11-25 2022-09-20
replace PGBouncer's readinessProbe with startupProbe 0 2022-02-22 2022-08-19
How to upgrade from old Sandboxie? 1 2020-12-22 2022-09-19
call_user_func_array() expects parameter 1 to be a valid callback, class 'Google\Client' does not have a method 'getVideoInfo' 3 2021-07-18 2022-09-03
Cannot get it to work 13 2017-03-11 2022-09-27
Header & Footer Template Parts Auto Added to new Templates 0 2022-09-25 2022-09-19
List v2: Can't merge two consecutive List blocks 1 2022-09-24 2022-09-19
Add missing generics to API 2 2020-02-04 2022-09-06
[FR] Add option "Associate .gcode files to PrusaSlicer" 2 2021-10-31 2021-12-28
[Bug] Some dialogs remain in original language after a language change 8 2022-09-19 2022-09-27
Rule to enforce implementing `\Stringable` explicitly on `__toString()` implementations 5 2022-01-13 2022-09-28
InsufficientS3BucketPolicyException error following documentation 0 2021-12-02 2022-09-11
OpenCR Tools Error 1 2021-04-15 2022-01-16
User interface plugins 0 2021-10-15 2022-01-21
nacos2.0.1集群节点全部重启后,客户端无法主动注册到服务列表 5 2021-11-11 2022-08-29
Implement cute_sound precision timers for Apple/Linux 0 2017-11-03 2022-09-07
fuzz: failed to compile `f32.demote_f64 2 2022-08-10 2022-08-13
HTML entities may appear in output tab in node detail 0 2022-08-07 2022-09-16
有分布式DotNetSpider的demo吗? 1 2020-07-30 2022-08-28
怎么使用sqlserver数据库呢 2 2022-01-22 2022-08-28
Document opinion on focus ring suppression 1 2022-04-11 2022-09-26