duanshaiduhao2471 2013-12-04 07:03
浏览 143
已采纳

gccgo -static与-static-libgo

What is the difference between -static and -static-libgo for gccgo? The documentation doesn't seem to really shed light on what is going on:

  • Use the -static-libgo option to link statically against the compiled packages.
  • Use the -static option to do a fully static link (the default for the gc compiler).

Is -static-libgo only static linking libgo.a only? While -static is full glibc library?

  • 写回答

1条回答 默认 最新

  • douhuangjie4503 2014-02-25 10:40
    关注

    Check the dynamic linkage in the generated ELFs:

    gc builds statically:

    $ go build hello.go
    $ readelf -d hello
    There is no dynamic section in this file.
    

    gccgo links dynamically against libgo, libc etc. by default:

    $ go build -compiler gccgo hello.go
    $ readelf -d hello
    Dynamic section at offset 0x36e0 contains 29 entries:
      Tag        Type                         Name/Value
     0x0000000000000001 (NEEDED)             Shared library: [libgo.so.5]
     0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
     0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
     0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
    

    Bake libgo inside the executable, but still link dynamically to libc and friends:

    $ go build -compiler gccgo -gccgoflags '-static-libgo' hello.go
    $ readelf -d hello
    Dynamic section at offset 0x128068 contains 28 entries:
      Tag        Type                         Name/Value
     0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
     0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
     0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2] 
    

    Link everything statically:

    $ go build -compiler gccgo -gccgoflags '-static' hello.go
    $ readelf -d hello
    There is no dynamic section in this file.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘