gccgo-静态vs-静态libgo
gccgo-静态vs-静态libgo,go,static-linking,gccgo,Go,Static Linking,Gccgo,gccgo的-static和-static libgo之间有什么区别?文档似乎没有真正阐明正在发生的事情: 使用-static libgo选项静态链接已编译的包 使用-static选项执行完全静态链接(gc编译器的默认设置) -static libgo是否仅静态链接libgo.a仅?当glibc库已满时,检查生成的ELF中的动态链接: gc静态构建: $ go build hello.go $ readelf -d hello There is no dynamic section in t
gccgo
的-static
和-static libgo
之间有什么区别?文档似乎没有真正阐明正在发生的事情:
- 使用
选项静态链接已编译的包-static libgo
- 使用
选项执行完全静态链接(gc编译器的默认设置)-static
-static libgo
是否仅静态链接libgo.a
仅?当glibc库已满时,检查生成的ELF中的动态链接:
gc静态构建:
$ go build hello.go
$ readelf -d hello
There is no dynamic section in this file.
$ go build -compiler gccgo -gccgoflags '-static' hello.go
$ readelf -d hello
There is no dynamic section in this file.
默认情况下,gccgo根据libgo、libc等动态链接:
$ 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]
在可执行文件中烘焙libgo,但仍动态链接到libc和好友:
$ 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]
静态链接所有内容:
$ go build hello.go
$ readelf -d hello
There is no dynamic section in this file.
$ go build -compiler gccgo -gccgoflags '-static' hello.go
$ readelf -d hello
There is no dynamic section in this file.
我认为-static将尝试静态链接所有内容,而-static libgo要么只对Go包进行链接,要么只静态链接libgo.a。