internal linking 和 external linking -extldflags "-static" 的区别,以及原理?

1. 运行环境

$ go version
go version go1.17.3 linux/amd64

2. 问题描述?

编译 kata-container runtime 时 Makefile 做了如下修改
@@ -486,6 +484,9 @@ BUILDTAGS :=

go build common flags

BUILDFLAGS := -buildmode=pie -mod=vendor ${BUILDTAGS}

+##fix me
+#KATA_LDFLAGS += -extldflags=–static
+

whether stipping the binary

ifeq ($(STRIP),yes)
KATA_LDFLAGS = -w -s

3. 您期望得到的结果?

期望结果是 编译出的静态二进制文件containerd-shim-kata-v2,应该比动态编译的二进制文件大才对

4. 您实际得到的结果?

实际的结果,静态链接containerd-shim-kata-v2是二进制文件大小
ls -lh containerd-shim-kata-v2
-rwxrwxr-x 1 wy wy 38M Jul 26 21:55 containerd-shim-kata-v2
$~/code/kata-containers/src/runtime$ ls -lh kata-runtime
-rwxrwxr-x 1 wy wy 39M Jul 26 21:55 kata-runtime
比动态链接的进制文件还小

动态链接的containerd-shim-kata-v2 二进制大小如下:
$ ls -lh containerd-shim-kata-v2
-rwxrwxr-x 1 wy wy 48M Jul 26 22:33 containerd-shim-kata-v2
$ ls -lh kata-runtime
-rwxrwxr-x 1 wy wy 49M Jul 26 22:33 kata-runtime

讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!