Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Well, the Go runtime is written in Go itself. And you can write Go without the runtime, the same way the compiler is.

The hard part is that the runtime is indeed build on OS primitives (syscall mostly), that you have to implement yourself.

You have to forgo all the niceties of having a runtime but you can do it. Definitely not the most productive use of Go, but it's fun and you learn a lot.



> Well, the Go runtime is written in Go itself.

That's a bit of a stretch. The runtime uses special pragmas that are not available to normal programs. I don't think it would be possible to write Go's GC in Go unless these special pragmas existed:

https://github.com/golang/go/blob/57df2f802f0417f08100ff8002...

Also, there are magical variables in the runtime that the compiler knows about and special-cases: https://github.com/golang/go/blob/57df2f802f0417f08100ff8002...

> And you can write Go without the runtime, the same way the compiler is.

How would you write Go without using the GC?


That is the magic of cross compilation.

There is already a compiler that knows those special pragmas, one just needs to add a new bare-metal backed to it.

As for writing Go without a GC, just like in any other GC enabled systems programming language, by not using language features that require GC in the lowest layer, which the other packages then depend on.

Example in Oberon, https://people.inf.ethz.ch/wirth/ProjectOberon/Sources/Kerne...

Also even ANSI C requires some Assembly or compiler extensions to fully implement libc.


> And you can write Go without the runtime, the same way the compiler is.

The compiler does depend on the runtime AFAIK

> The hard part is that the runtime is indeed build on OS primitives (syscall mostly), that you have to implement yourself.

This is what I was referring to. I don't know how you would do this without patching the language.


By using a mix of cross-compiling and some Assembly help, just like C needs some help beyond what ANSI C specifies.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: