News for hackers. Stuff that matters.
Re:Go 1.9 is released by agnivade on Friday August 25, 2017 @01:42AM (#15096373)
> Aren't go programs statically linked?

Not by default. You have to set CGO_ENABLED=0 to statically link libc.

Re:Go 1.9 is released by arghwhat on Friday August 25, 2017 @04:47AM (#15097054)
Well, Go code is statically linked, but the runtime may try to dynamically load libc for DNS resolving. Use of cgo of course drastically change everything.
Re:Go 1.9 is released by pjmlp on Friday August 25, 2017 @06:16AM (#15097360)
By default, nowadays the toolchain also supports generating dynamic libraries.
Re:Go 1.9 is released by 4ad on Friday August 25, 2017 @10:52AM (#15098852)
And by default, this feature is not used.
Re:Go 1.9 is released by pjmlp on Friday August 25, 2017 @10:55AM (#15098870)
So what, it doesn't make this "Go code is statically linked" into a fact, given that it depends on compiler flags.

Now if it said "Go code is usually/by default statically linked", then yes.

Re:Go 1.9 is released by pmarin on Friday August 25, 2017 @01:58AM (#15096434)
Do native Go programs use libc?
Re:Go 1.9 is released by aleksi on Friday August 25, 2017 @02:37AM (#15096605)
For a few things like system DNS resolver in net package (can be switched to the pure Go version with compile-time or run-time switch) and getting user's home directory in os/user package.
Re:Go 1.9 is released by sebcat on Friday August 25, 2017 @04:12AM (#15096957)
To expand on this:

    $ cat foo.go 
    package main
    
    import (
     	"fmt"
    )
    
    func main() {
    	fmt.Println("Hello")
    }
    $ go build foo.go
    $ file foo
    foo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
compared to:

    $ cat bar.go
    package main
    
    import (
    	"os/user"
    	"fmt"
    )
    
    func main() {
    	u, err := user.Current()
    	fmt.Println(u, err)
    }
    $ go build bar.go
    $ file bar
    bar: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, not stripped
Re:Go 1.9 is released by ptman on Friday August 25, 2017 @05:07AM (#15097126)
You can usually build fully static by doing

    CGO_ENABLED=0 go build
even when using os/user or net/
Re:Go 1.9 is released by sebcat on Friday August 25, 2017 @01:54PM (#15100651)
At a computer with go1.4.2 freebsd/amd64 ATM (earlier was go1.8.1 linux/amd64 IIRC) and the above os/user example results in a dynamically linked ELF when built with CGO_ENABLED set to 0.
Re:Go 1.9 is released by folago on Friday August 25, 2017 @02:26AM (#15096554)
I am pretty sure they don't.
Re:Go 1.9 is released by agnivade on Friday August 25, 2017 @05:07AM (#15097127)
Nope.