News for hackers. Stuff that matters.
Re:Why are my Go executable files so large? by krasin on Sunday December 29, 2019 @02:19PM (#21907841)
I agree with some of your points; but zero-reliance on libc is the reason why it's so easy to use Go in containers; and Docker is one of the primary reasons why Go is popular. It's what they have got right.
Re:Why are my Go executable files so large? by Skunkleton on Sunday December 29, 2019 @02:25PM (#21907870)
You could statically link in libc and get the same effect.
Re:Why are my Go executable files so large? by Spivak on Sunday December 29, 2019 @05:21PM (#21908989)
Statically linking libc is it’s own minefield. It can and is done but even if you statically link everything else you should almost always dynamically link against your platform’s libc.
Re:Why are my Go executable files so large? by paulddraper on Sunday December 29, 2019 @05:52PM (#21909172)
Statically linking libc is harder than dynamically linking it, but certainly easier than rewriting it.
Re:Why are my Go executable files so large? by yencabulator on Thursday January 02, 2020 @12:29PM (#21937466)
Good thing we don't want to use much of libc functionality from Go, so nobody needs to reimplement all of it. It's not like people would be begging to call strcpy. All that's needed is the syscalls.
Re:Why are my Go executable files so large? by aratakareigen on Monday December 30, 2019 @03:55PM (#21916646)
Statically linking a libc seems equivalent to statically linking Go's standard library, but with a whole lot less effort (on the part of the Go developers, that is).
Re:Why are my Go executable files so large? by saagarjha on Monday December 30, 2019 @02:54AM (#21911585)
Why? I see no reason you couldn’t on platforms with a stable syscall ABI, other than the standard reasons against static linking.
Re:Why are my Go executable files so large? by thu2111 on Monday December 30, 2019 @04:49AM (#21912192)
It depends on the libc.

glibc doesn't really "want" to be statically linked. It can be done sometimes, depending on how it's used, the phase of the moon and so on, but breaks from time to time until it's repaired.

Some of the issues are fundamental. For instance the dynamic linker is a part of the C libraries. If you statically link libc and then dynamically load another shared library, you can end up with two copies of the C libraries loaded at once.

The C library expects various external files to be found on disk, in a format that isn't totally forwards/backwards compatible. That's reasonable when things are dynamically linked because the linker and C library abstract the developer from format changes. If you statically link you should really statically link the data files too, but the C toolchain has no provision for that.

Re:Why are my Go executable files so large? by pjmlp on Monday December 30, 2019 @08:02AM (#21913061)
The ISO C standard library has no such expectations regarding external files.
Re:Why are my Go executable files so large? by p_l on Sunday December 29, 2019 @06:57PM (#21909550)
Except glibc does not really support static linking of you want network support.
Re:Why are my Go executable files so large? by pjmlp on Monday December 30, 2019 @08:03AM (#21913066)
glibc is just one possible ISO C implementation with lots of extra stuff on top.
Re:Why are my Go executable files so large? by IshKebab on Sunday December 29, 2019 @05:37PM (#21909089)
Says someone who has never actually tried to do that. You can statically link with Musl. But you can't really statically link with Glibc.
Re:Why are my Go executable files so large? by josteink on Sunday December 29, 2019 @06:20PM (#21909344)
Technically speaking OP only suggested statically linking (a) libc, not glibc specifically, and musl is a libc.
Re:Why are my Go executable files so large? by Skunkleton on Sunday December 29, 2019 @08:20PM (#21909951)
Not sure what’s up with the combative tone? FWIW, I work as an operating systems developer. We sell several products incorporating a few in house libc variants. They are most certainly statically linked.
Re:Why are my Go executable files so large? by saagarjha on Monday December 30, 2019 @02:57AM (#21911597)
You can, it just might do some strange things when dealing with iconv.
Re:Why are my Go executable files so large? by labawi on Sunday December 29, 2019 @05:22PM (#21908998)
You'd still have to get a static libc (not usually preinstalled), possibly compile it for a different os/architecture..
Re:Why are my Go executable files so large? by stqism on Sunday December 29, 2019 @10:44PM (#21910661)
An issue here is that statically linking against glibc is generally regarded as a poor idea and I’ve seen a couple non trivial programs that refuse to run with other libc’s.
Re:Why are my Go executable files so large? by michaelcampbell on Sunday December 29, 2019 @05:16PM (#21908955)
> Docker is one of the primary reasons why Go is popular.

Based on what data?

Re:Why are my Go executable files so large? by twic on Sunday December 29, 2019 @06:22PM (#21909352)
I've deployed all sorts of things which dynamically link libc in containers. This just isn't an issue in practice.
Re:Why are my Go executable files so large? by rapsey on Sunday December 29, 2019 @02:26PM (#21907875)
If you want static linking use musl..
Re:Why are my Go executable files so large? by y4mi on Sunday December 29, 2019 @02:35PM (#21907936)
You'd supposedly sacrifice performance though.

At least that's the common complaint for Alpine docker images... It's based on musl and halve of the community always complains about serious performance degradation

Re:Why are my Go executable files so large? by rapsey on Sunday December 29, 2019 @02:40PM (#21907960)
Well if the performance difference matters, going to a GC language makes no sense.
Re:Why are my Go executable files so large? by y4mi on Sunday December 29, 2019 @04:20PM (#21908580)
Tell that to the go enthusiasts. They're all claiming it to be peak performance surpassing everything else.

though even java is faster in most benchmarks

Re:Why are my Go executable files so large? by pjmlp on Sunday December 29, 2019 @03:03PM (#21908080)
Except that Docker was originally written in Java by the former team that actually started the project, and nowadays contains modules written in OCaml taken from the MirageOS project, for the macOS and Windows variants of Docker.

So how much they got right regarding Docker's success and Go is a bit debatable.

Re:Why are my Go executable files so large? by ffk on Sunday December 29, 2019 @03:52PM (#21908385)
Docker was not written in Java. It was shell scripts, python, then go. Dotcloud was primarily a python shop.

Perhaps you are thinking of a different project?

Re:Why are my Go executable files so large? by jen20 on Sunday December 29, 2019 @03:59PM (#21908426)
Probably Kubernetes which was indeed Java in formative years.
Re:Why are my Go executable files so large? by smarterclayton on Sunday December 29, 2019 @06:05PM (#21909265)
Kubernetes was never publicly available (open source) in any other language than Go. Early internal prototypes may have been in Java, but those bear no more resemblance to current Kubernetes than Borg does.
Re:Why are my Go executable files so large? by pjmlp on Sunday December 29, 2019 @04:15PM (#21908542)
You are right, I got that wrong, too late to edit now.
Re:Why are my Go executable files so large? by sagichmal on Sunday December 29, 2019 @11:23PM (#21910794)
Kubernetes was never Java.
Re:Why are my Go executable files so large? by pjmlp on Monday December 30, 2019 @04:06AM (#21911940)
Re:Why are my Go executable files so large? by sagichmal on Monday December 30, 2019 @09:37AM (#21913571)
Unless she's talking about an internal prototype that never saw a public repository, Kris is wrong.

The original prototype that saw a public repo was written by Joe and Craig in Python (mostly Craig IIRC) and lasted for all of about a week before they switched to Go.

The original crew of contributors, all from Google, came from a Java background and definitely wrote Java-flavored Go, but no version of Kubernetes was ever written in Java.

Source: I know all the principals and was a contributing member when Kubernetes was initially released.

Re:Why are my Go executable files so large? by jen20 on Monday December 30, 2019 @05:36AM (#21912416)
Yup, watching that talk at last years FOSDEM is what informed me of that part of the history also. Great talk, too!
Re:Why are my Go executable files so large? by pjmlp on Sunday December 29, 2019 @04:16PM (#21908549)
Indeed, I got that wrong.
Re:Why are my Go executable files so large? by kjeetgill on Sunday December 29, 2019 @03:08PM (#21908109)
I think the parent was reffering to using Go in Docker containers, not using Go for implementing Docker itself.

That said, I agree that Docker was the first major project written in Go many people were exposed to and probably had some influence.

Re:Why are my Go executable files so large? by kick on Sunday December 29, 2019 @03:11PM (#21908120)
I'm just wondering, how is your line about the code taken from the MirageOS project relevant? Nobody uses the Windows and macOS variants of Docker in production.
Re:Why are my Go executable files so large? by pjmlp on Sunday December 29, 2019 @03:14PM (#21908139)
Windows shops do use Docker in production, there are plenty of them.

It is relevant in the sense that Docker isn't 100% Go nowadays.

Re:Why are my Go executable files so large? by kristianp on Sunday December 29, 2019 @03:54PM (#21908400)
As an aside, do they use Windows containers in that context? Otherwise why?
Re:Why are my Go executable files so large? by pjmlp on Sunday December 29, 2019 @04:15PM (#21908540)
Yes, for example in Azure deployments.