Go言語は「シングルなバイナリを生成でき、どの環境でも動作できる」という売り文句だが
$ go version
go version go1.13.8 linux/amd64
$ file gin-app001
gin-app001: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go BuildID=rYlgip7RIOd4XpYQd2pN/ofDQrNujbWzDObeO2gkc/4s61rKSmKtzyDOUuiyIv/4WBpQNeAyOafVYP87dDC, not stripped
$ ldd gin-app001
linux-vdso.so.1 (0x00007fff32774000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fdacdc5b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdacda69000)
/lib64/ld-linux-x86-64.so.2 (0x00007fdacdc88000)
FROM gcr.io/gcp-runtimes/go1-builder:1.14
Step 5/10 : RUN ldd app
---> Running in 045b031fdc5c
linux-vdso.so.1 => (0x00007ffe4a9cc000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f41a6067000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f41a5c9d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f41a6284000)
FROM golang:1.14-alpine3.12
Step 5/10 : RUN ldd app
---> Running in 8dc704f4fc2f
/lib/ld-musl-x86_64.so.1 (0x7f5b13261000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f5b13261000)
ここまでやってから、golangにおいてAlpineは非推奨であることに気付きました。
golang:<version>-alpine…
This variant is highly experimental, and not officially supported by the Go project (see golang/go#19938 for details).
golang – Docker Hub
静的リンクにおける問題点
StaticLinking – Debian Wikiによると、いくつか問題点がある。
- It requires rebuilding the world when the libraries change.
- It is harder to track than dynamic linking.
- It prevents memory sharing between different executables using the same code.
- It renders some security measure less effective (ASLR for example).
- To comply with the DFSG and GNU GPL, we need to keep old source around.
- Possible to ship incomplete libs. Eg. foo() depends on bar() but bar() not present at link time.
aaa
参考リンク
- golangで書いたアプリケーションのstatic link化 – okzkメモ
http://okzk.hatenablog.com/entry/2016/08/03/234738
Leave a Reply