On Mon, Feb 1, 2021 at 1:46 PM Ian Lance Taylor <[email protected]> wrote:
>
> On Sun, Jan 31, 2021 at 5:54 AM Hongyi Zhao <[email protected]> wrote:
> >
> > If the go program compiled by a completely static compiled version of go
> > binary compiler will also be static automatically? To be more specific, on
> > Ubuntu 20.04, I've compiled the latest git master version of go compiler in
> > a completely static manner as shown below:
> >
> > $ which go | xargs file
> > /home/werner/Public/repo/github.com/golang/go.git/bin/go: ELF 64-bit LSB
> > executable, x86-64, version 1 (SYSV), statically linked, Go
> > BuildID=5jq4NVhOUQBZ9qoSzZZP/ZGpiMeW1vV69o1mL-B9A/6YaUKXNOw58uUviv4EeO/4sUw0l9CinylaK_Pov59,
> > not stripped
> >
> > Then I try to build the dnsproxy by the following steps:
> >
> > $ git clone https://github.com/AdguardTeam/dnsproxy.git dnsproxy.git
> > $ cd dnsproxy.git
> > $ go build
> > $ file dnsproxy
> > dnsproxy: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically
> > linked, Go
> > BuildID=6mIriY-h59Wwm2_gwbk2/rXhgRt_o3oIf_KSuKKtt/BYmwRfWtoqym2xPocRBT/Z2CIkEn5HaeVqVhdwxYu,
> > not stripped
> >
> >
> > As you can see, the compiled dnsproxy with the completely static go
> > compiler binary will also generate a static go program. I'm not sure if
> > this is always true. Any hints will be highly appreciated.
>
> Whether the go tool itself is statically linked does not affect
> whether a Go program will be statically linked. However, the setting
> of "CGO_ENABLED" that is used when building the Go toolchain will
> become the default value of CGO_ENABLED when using that Go toolchain.
> That may be what is causing the effect that you are seeing. To build
> a dynamically linked program, try setting CGO_ENABLED=1 in the
> environment when running the go tool.
Thanks a lot. You're right. See the following for more detailed info:
$ CGO_ENABLED=1 go build
werner@X10DAi:~/Public/anti-gfw/dns/dnsproxy/dnsproxy.git$ ldd dnsproxy
linux-vdso.so.1 (0x00007fffcedc8000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
(0x00007f6e8eab2000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6e8e8c0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6e8eafd000)
Best
--
Assoc. Prof. Hongyi Zhao <[email protected]>
Theory and Simulation of Materials
Hebei Polytechnic University of Science and Technology engineering
NO. 552 North Gangtie Road, Xingtai, China
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/CAGP6POKzYyE0d_7vsbAgVVP-kJiHPnToURRDGV3LcphxzO%2BNMA%40mail.gmail.com.