Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Go language CPU dependent?

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.

like image 739
Shuriken Avatar asked Jan 03 '14 12:01

Shuriken


1 Answers

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.

like image 178
justinas Avatar answered Oct 13 '22 01:10

justinas