Skip to content

question: ARM v5 not working on Android with clang #29729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
axet opened this issue Jan 14, 2019 · 10 comments
Closed

question: ARM v5 not working on Android with clang #29729

axet opened this issue Jan 14, 2019 · 10 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile

Comments

@axet
Copy link

axet commented Jan 14, 2019

What version of Go are you using (go version)?

go version go1.11.4 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
GOARCH="amd64"
GOBIN="/Users/axet/.go/bin"
GOCACHE="/Users/axet/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/axet/.go"
GOPROXY=""
GORACE=""
GOROOT="/opt/local/lib/go"
GOTMPDIR=""
GOTOOLDIR="/opt/local/lib/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="/usr/bin/clang"
CXX="clang++"
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 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lv/m63vrmx5375dgk4jhc05ww000000gn/T/go-build890369140=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Trying to run "hello world" on armv6l, crosscompiling as ARMV5, getting SIGILL or SIGSEGV

package main
import "fmt"
func main() {
	fmt.Println("123")
}

Using NDK r16b:

# build/tools/make_standalone_toolchain.py  --arch arm --api 14 --install-dir tools
# CC=$PWD/../tools/bin/arm-linux-androideabi-clang CXX=$PWD/../tools/bin/arm-linux-androideabi-clang++ CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=5 go build .

Officially ARMv5 supported by Golang, and I'd like to see CPU supported list expanding and not shrinking. Golang promising, and can be better then 'C' unless it will not stop growing...

crash Output
01-14 18:00:19.580 2230-2230/? A/libc: Fatal signal 11 (SIGSEGV) at 0x00154efc (code=1)
01-14 18:00:20.710 114-114/? I/DEBUG: pid: 2230, tid: 2230  >>> ./123 <<<
01-14 18:00:20.710 114-114/? I/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00154efc
01-14 18:00:20.710 114-114/? I/DEBUG:  r0 b00094fc  r1 00154efd  r2 b0006a54  r3 00154efc
01-14 18:00:20.710 114-114/? I/DEBUG:  r4 b0009d78  r5 70000001  r6 00000001  r7 b0009e74
01-14 18:00:20.710 114-114/? I/DEBUG:  r8 00000000  r9 00000000  10 00000000  fp 00000000
01-14 18:00:20.710 114-114/? I/DEBUG:  ip b0009e70  sp be977bb0  lr b00049eb  pc b00043a6  cpsr 00000030
01-14 18:00:20.710 114-114/? I/DEBUG:  d0  0000000000000000  d1  0000000000000000
01-14 18:00:20.710 114-114/? I/DEBUG:  d2  0000000000000000  d3  0000000000000000
01-14 18:00:20.710 114-114/? I/DEBUG:  d4  0000000000000000  d5  0000000000000000
01-14 18:00:20.710 114-114/? I/DEBUG:  d6  0000000000000000  d7  0000000000000000
01-14 18:00:20.710 114-114/? I/DEBUG:  d8  0000000000000000  d9  0000000000000000
01-14 18:00:20.710 114-114/? I/DEBUG:  d10 0000000000000000  d11 0000000000000000
01-14 18:00:20.710 114-114/? I/DEBUG:  d12 0000000000000000  d13 0000000000000000
01-14 18:00:20.720 114-114/? I/DEBUG:  d14 0000000000000000  d15 0000000000000000
01-14 18:00:20.720 114-114/? I/DEBUG:  scr 00000000
01-14 18:00:20.740 114-114/? I/DEBUG:          #00  pc b00043a6  /system/bin/linker
01-14 18:00:20.740 114-114/? I/DEBUG:          #01  lr b00049eb  /system/bin/linker
01-14 18:00:20.740 114-114/? I/DEBUG: code around pc:
01-14 18:00:20.740 114-114/? I/DEBUG: b0004384 378c1c27 683d685e e0031975 31dc1c21  '..7^h=hu...!..1
01-14 18:00:20.740 114-114/? I/DEBUG: b0004394 08ad685d 3308600d 4a5ae003 447a485a  ]h...`.3..ZJZHzD
01-14 18:00:20.740 114-114/? I/DEBUG: b00043a4 68194478 d0002900 1c20e77a 680330ac  xD.h.)..z. ..0.h
01-14 18:00:20.740 114-114/? I/DEBUG: b00043b4 d0042b00 31b01c21 2a00680a 4853d10a  .+..!..1.h.*..SH
01-14 18:00:20.740 114-114/? I/DEBUG: b00043c4 4b544a53 49554e54 447a4478 9600447b  SJTKTNUIxDzD{D..
01-14 18:00:20.740 114-114/? I/DEBUG: code around lr:
01-14 18:00:20.740 114-114/? I/DEBUG: b00049c8 5c140048 d0032c00 3e014b35 e001447b  H..\.,..5K.>{D..
01-14 18:00:20.740 114-114/? I/DEBUG: b00049d8 447b4b34 270000b6 1c2850f7 f7ff2100  4K{D...'.P(..!..
01-14 18:00:20.740 114-114/? I/DEBUG: b00049e8 2800fbe7 4930d019 ad054c30 22184479  ...(..0I0L..yD."
01-14 18:00:20.740 114-114/? I/DEBUG: b00049f8 1c28447c ec0af7fc f0011c20 1c21e904  |D(..... .....!.
01-14 18:00:20.740 114-114/? I/DEBUG: b0004a08 20021c02 eb54f7fc 1c292002 f7fc2218  ... ..T.. ).."..
01-14 18:00:20.740 114-114/? I/DEBUG: memory map around addr 00154efc:
01-14 18:00:20.740 114-114/? I/DEBUG: (no map below)
01-14 18:00:20.740 114-114/? I/DEBUG: (no map for address)
01-14 18:00:20.740 114-114/? I/DEBUG: 2a000000-2a0c1000 /data/local/tmp/123
01-14 18:00:20.740 114-114/? I/DEBUG: stack:
01-14 18:00:20.740 114-114/? I/DEBUG:     be977b70  00000000  
01-14 18:00:20.740 114-114/? I/DEBUG:     be977b74  00000000  
01-14 18:00:20.740 114-114/? I/DEBUG:     be977b78  00000000  
01-14 18:00:20.740 114-114/? I/DEBUG:     be977b7c  00000000  
01-14 18:00:20.740 114-114/? I/DEBUG:     be977b80  00000000  
01-14 18:00:20.740 114-114/? I/DEBUG:     be977b84  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977b88  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977b8c  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977b90  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977b94  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977b98  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977b9c  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977ba0  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977ba4  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977ba8  df0027ad  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bac  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG: #00 be977bb0  b0009d78  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bb4  b0009d78  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bb8  b0009e1c  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bbc  be977d36  [stack]
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bc0  b0009d78  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bc4  b0003beb  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bc8  be977c84  [stack]
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bcc  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bd0  be977c80  [stack]
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bd4  b0009918  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bd8  b0009d78  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bdc  00000008  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977be0  b0006f1f  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977be4  b00049eb  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977be8  00000017  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bec  b00094f0  /system/bin/linker
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bf0  00000000  
01-14 18:00:20.750 114-114/? I/DEBUG:     be977bf4  be977bf8  [stack]
--------- beginning of /dev/log/system

@kardianos
Copy link
Contributor

Did you set the GOARM env var?

https://github.com/golang/go/wiki/GoArm

@axet
Copy link
Author

axet commented Jan 14, 2019

Sure I did, check example commands. My guess 'go' using extended commands set even when limited by GOARM=5. I even tried to complie booth GOARM=5 and GOARM=7 - file size is different.

@bradfitz
Copy link
Contributor

We have a continuous build running against real ARMv5 hardware, so I suspect a problem with your environment.

When you say "Using NDK r16b", I assume that's some Android thing?

Maybe @eliasnaur can help. But we don't officially support the Android layers. ARMv5 works fine for the Go SDK, at least. Maybe you're missing some cross-compilation flags for clang.

@bradfitz bradfitz changed the title ARM v5 not working question: ARM v5 not working on Android with clang Jan 14, 2019
@bradfitz bradfitz added the mobile Android, iOS, and x/mobile label Jan 14, 2019
@eliasnaur
Copy link
Contributor

Support for the "armeabi" ABI that targets armv5 and armv6 was removed in the latest NDK, r17 ( https://developer.android.com/ndk/guides/abis). If Google doesn't want to support armeabi anymore, I don't think it is worth it for Go, sorry.
If you want to keep working on it, I think bradfitz is on to something: according to https://developer.android.com/ndk/guides/standalone_toolchain, arm standalone toolchains target armeabi-v7a by default and you'll need to pass -march or -mtarget to clang to override that. You can include arguments in the CC envrionment variable for Go.

@axet
Copy link
Author

axet commented Jan 15, 2019

Related to build issues, without CC 'go' also failed on OSX:

axet-laptop:~ axet$ CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=5 go build main.go 
# runtime/cgo
clang: error: argument unused during compilation: '-mno-thumb' [-Werror,-Wunused-command-line-argument]
axet-laptop:~ axet$ CGO_ENABLED=0 GOOS=android GOARCH=arm GOARM=5 go build main.go 
# command-line-arguments
/opt/local/lib/go/pkg/tool/darwin_amd64/link: running /usr/bin/clang failed: exit status 1
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@eliasnaur
Copy link
Contributor

That's expected; the macOS compiler can't target GOOS=android.

@axet
Copy link
Author

axet commented Jan 16, 2019

Ok. I figured it out. But here is a problem. When compiling a library 'go build' gives no flags to control '-Wl,-z,relro'. This flag should not be used when compiled for armv5 (otherwise it crahes). I have to modify toolchain to make it work. 'relro' hardcoded in golang source.

@ianlancetaylor
Copy link
Contributor

go build -ldflags=-extldflags=-Wl,-z,relro

@ianlancetaylor
Copy link
Contributor

Oh, sorry, we are passing relro, and you need to turn it off?

go build -ldflags=-extldflags=-Wl,-z,norelro

@axet
Copy link
Author

axet commented Jan 16, 2019

Yep, I need to turn it off. Here is no way except having standalone custom toolchain with cut the option using bash wrapper or recompiling golang from source.

PS: ok it working...

@golang golang locked and limited conversation to collaborators Jan 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

6 participants