duanjiaoxi4928 2014-01-03 12:48
浏览 60
已采纳

Go语言的CPU是否依赖?

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.

  • 写回答

1条回答 默认 最新

  • douou8954 2014-01-03 12:57
    关注

    Go is compiled, so the end result is indeed (CPU-specific) machine code.

    $ echo 'package main
    func 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题