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 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?