Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the difference between `external linking` and `internal linking` program, and how do I make a choice between them? #35579

Closed
sanguohot opened this issue Nov 14, 2019 · 1 comment

Comments

@sanguohot
Copy link

@sanguohot sanguohot commented Nov 14, 2019

What version of Go are you using (go version)?

$ go version
1.12.4

Does this issue reproduce with the latest release?

not test

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/.gvm/pkgsets/go1.12.4/global"
GOPROXY="https://goproxy.cn"
GORACE=""
GOROOT="/root/.gvm/gos/go1.12.4"
GOTMPDIR=""
GOTOOLDIR="/root/.gvm/gos/go1.12.4/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/opt/sghproxy/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build427518459=/tmp/go-build -gno-record-gcc-switches"

go env Output
$ go env

What did you do?

CGO_ENABLED=0 go build -o client-s bin/client/app/client.go

ldd client-s

    not a dynamic executable

go build -o client-d bin/client/app/client.go

ldd client-d

    linux-vdso.so.1 =>  (0x00007ffc736b6000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb5f8788000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fb5f83b9000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fb5f89ac000)

go build --ldflags "-linkmode external -extldflags -static" -o client-s2 bin/client/app/client.go

command-line-arguments

/tmp/go-link-928793566/000019.o: In function mygetgrouplist': /workdir/go/src/os/user/getgrouplist_unix.go:16: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /tmp/go-link-928793566/000018.o: In function mygetgrgid_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:38: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-928793566/000018.o: In function mygetgrnam_r': /workdir/go/src/os/user/cgo_lookup_unix.go:43: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /tmp/go-link-928793566/000018.o: In function mygetpwnam_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:33: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-928793566/000018.o: In function mygetpwuid_r': /workdir/go/src/os/user/cgo_lookup_unix.go:28: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /tmp/go-link-928793566/000004.o: In function _cgo_7e1b3c2abc8d_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:57: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

ldd client-s2

    not a dynamic executable

ll

-rwxr-xr-x. 1 root root 13805987 Nov 14 09:14 client-d
-rwxr-xr-x. 1 root root 13728866 Nov 14 09:14 client-s
-rwxr-xr-x. 1 root root 21861154 Nov 14 09:15 client-s2

What did you expect to see?

Well, I think they are very nearly the same between client-s and client-s2.

What did you see instead?

Actually you could see that the size between client-s and client-s2 are large, so what is the difference between external linking and internal linking for the static linking program?
And how do I make a choice between them?
By the way, I could only use internal linking on macOS15.1.
Any help would be greatly appreciated.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 14, 2019

The Go project doesn't use the issue tracker for questions. You will get better and faster answers on a forum. Please see https://golang.org/wiki/Questions. Thanks.

External linking means that the final link is done using the system linker. Internal linking means that the final link is done using the Go linker. Most people shouldn't need to choose between them.

If this doesn't help, I suggest that you use a forum to ask your real question. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.