Is Go language CPU dependent?
I know it supports x86, x86_64 and ARM. Does it have some CPU depend code like assembler code blocks?
PS I was not clear enough. Does Go language implementation is CPU dependent?
I do not wish to add ARM assembly code in my program. I am wondering if Go program could be compiled on x86(_64) and ARM only and all other platforms are not supported.
Go is compiled, so the end result is indeed (CPU-specific) machine code.
$ echo 'package main\nfunc main(){ println("hello world") }' > hello.go
$ go build hello.go
$ objdump -D hello | head
hello: file format elf32-i386
Disassembly of section .text:
08048c00 <main.main>:
8048c00: 65 8b 0d 00 00 00 00 mov %gs:0x0,%ecx
8048c07: 8b 49 f8 mov -0x8(%ecx),%ecx
8048c0a: 3b 21 cmp (%ecx),%esp
So you won't be able to just take executable compiled for, say, ARM, and run it on x86.
Despite that, Go has excellent support for cross-compiling programs for different OSes and architectures, so in most cases you won't need a bunch of machines (virtual or real) running different OSes to compile your programs for those targets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With