Go Compiler How Work?!

582 views
Skip to first unread message

erfang...@gmail.com

unread,
Dec 12, 2017, 4:03:08 PM12/12/17
to golang-nuts
Hello,
Go Compiler How Work at Last Version of GoLang?!
i mean Go Compiler , Not GoLang.

at the last version of golang. go compiler , generate c code and compile using gcc?!





Ondrej Fabry

unread,
Dec 12, 2017, 4:30:22 PM12/12/17
to golang-nuts
Not sure what you mean but if you are asking if go compiler generates C code which is then compiled by gcc then not really. Since version go 1.5 even the compiler itself is written in pure Go and since then no C code is needed anymore.

erfang...@gmail.com

unread,
Dec 12, 2017, 4:34:30 PM12/12/17
to golang-nuts
How may a compiler made with itself!? this need a tools at first to build...

Tamás Gulácsi

unread,
Dec 12, 2017, 4:39:13 PM12/12/17
to golang-nuts
Yes. It compiles itself with a previous verson of the compiler first.

erfang...@gmail.com

unread,
Dec 12, 2017, 4:48:57 PM12/12/17
to golang-nuts
so Main compiler is at previous version and made with C? 

Shawn Milochik

unread,
Dec 12, 2017, 5:19:07 PM12/12/17
to golang-nuts
On Tue, Dec 12, 2017 at 4:48 PM, <erfang...@gmail.com> wrote:
so Main compiler is at previous version and made with C? 


erfang...@gmail.com

unread,
Dec 12, 2017, 5:24:13 PM12/12/17
to golang-nuts
how can use from them? i want not use from GOLANG. only use from GO COMPILER.
main compiler of Go:
go-go1.4.3/src/cmd/gc/go.y (parser)

erfang...@gmail.com

unread,
Dec 12, 2017, 5:28:53 PM12/12/17
to golang-nuts
so go compiler is made with c.

so go compiler how work : 
--------------
so in current golang version , golang generate c code and compile with c-compiler?

On Wednesday, December 13, 2017 at 1:49:07 AM UTC+3:30, Shawn Milochik wrote:

C Banning

unread,
Dec 12, 2017, 5:46:23 PM12/12/17
to golang-nuts
Well, GO_BOOTSTRAP lets you use any compiler after go1.4.  I usually build/install Go using the previous Go-built version - thus, I built/installed Go1.9 using the Go1.8.1 compiler.

erfang...@gmail.com

unread,
Dec 12, 2017, 5:51:43 PM12/12/17
to golang-nuts
so GOLANG will not work, if not install C-Compiler on system.

yeah?

C Banning

unread,
Dec 12, 2017, 6:00:41 PM12/12/17
to golang-nuts
Well, there are binary releases for the most HW/OS combinations - https://golang.org/dl/

erfang...@gmail.com

unread,
Dec 12, 2017, 6:12:49 PM12/12/17
to golang-nuts
example , when you want write a hello world application.
after this then you are write a `.go` file.
you should enter :
go build hello.go

if not installed c-compiler at now, what happen?!

c-compiler need at building golang?
or alwayse?
also when need use from golang?

Dave Cheney

unread,
Dec 12, 2017, 6:15:34 PM12/12/17
to golang-nuts
Hello,

Thanks for posting. To answer your question

1. The Go compiler used to be written in C, but was rewritten in Go in release 1.5

2. This means that to build a version of Go later than 1.4, you need a Go compiler.

3. The easiest way to do this is to us a version of Go from the golang.org website, the instructions are here https://golang.org/doc/install/source#go14

4. If you are new to Go I strongly do not recommend building from source, you should just use one of the pre compiled versions available on the website, they are extremely well tested and known to work on many systems. https://golang.org/doc/install

5. If you are trying to bootstrap Go on a system that we don't ship pre compiled binaries for you will have to produce a bootstrap cross compiler, so you will need to do step 3 then follow the instructions from the step "building go 1.5 from source" on this post, https://dave.cheney.net/2015/10/16/bootstrapping-go-1-5-on-non-intel-platforms

real talk, this is quite a complicate process and if english is not your native language you may be better served by finding a Go forum in your native language. I don't have any to recommend off hand, but maybe on the gophers slack you might be able to find someone to help you. Because slack is invite only you can request an invite using this automated application, https://invite.slack.golangbridge.org/

erfang...@gmail.com

unread,
Dec 12, 2017, 6:18:22 PM12/12/17
to golang-nuts
go-go1.4.3/src/cmd/gc$ make

----------------
go tool dist install -v
make: go: Command not found
../../Make.dist:13: recipe for target 'install' failed make: *** [install] Error 127
----------------

so gc also need go!? :||||

Dave Cheney

unread,
Dec 12, 2017, 6:20:29 PM12/12/17
to golang-nuts
Hello,

I appreciate that you're frustrated, but you need to follow the installation instructions _exactly_ to the letter or you will not succeed. 

The installation instructions are quite long, but they are well tested and if you follow them precisely you will be able to install Go on your computer.

erfang...@gmail.com

unread,
Dec 12, 2017, 6:22:14 PM12/12/17
to golang-nuts
im want test main go compiler.



name of main go compiler is GC?


On Wednesday, December 13, 2017 at 2:45:34 AM UTC+3:30, Dave Cheney wrote:

erfang...@gmail.com

unread,
Dec 12, 2017, 6:26:22 PM12/12/17
to golang-nuts
at https://storage.googleapis.com/golang/go1.4-bootstrap-20170531.tar.gz source , not available bootstrap.bash file.



so

bootstrap.bash 

only available at new version of golang.
not at go 1.4.

Dave Cheney

unread,
Dec 12, 2017, 6:29:46 PM12/12/17
to golang-nuts
Do this

cd $HOME
mv go go1.4
cd go1.4/src
env CGO_ENABLED=0 ./make.bash
cd $HOME
cd go/src
git checkout go1.9.2
env GOROOT_BOOTSTRAP=$HOME/go1.4 ./make.bash
echo '$PATH=$PATH:$HOME/go/bin" >> ~/.profile
source ~/.profile

erfang...@gmail.com

unread,
Dec 12, 2017, 6:30:06 PM12/12/17
to golang-nuts

tutorial : https://golang.org/doc/install/source#go14 is say then run : 

$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash

- bootstrap.bash file

this file not available at go https://storage.googleapis.com/golang/go1.4-bootstrap-20170531.tar.gz
this file only available at new version of golang.


On Wednesday, December 13, 2017 at 2:52:14 AM UTC+3:30, erfang...@gmail.com wrote:

Dave Cheney

unread,
Dec 12, 2017, 6:32:10 PM12/12/17
to golang-nuts
You need to install Go on an intel computer before preparing the bootstrap compiler for ppc64. Follow the steps above, you will find bootstrap.bash in the go 1.9.2 sources.

erfang...@gmail.com

unread,
Dec 12, 2017, 6:33:17 PM12/12/17
to golang-nuts
Wooow.

Question : Name of main go compiler is GC?

Dave Cheney

unread,
Dec 12, 2017, 6:34:42 PM12/12/17
to golang-nuts
Yup. This comes from the heritage of the plan 9 compilers.

The plan 9 c compilers were 6c for amd64, 8g for 386, 5g for arm, and so on. 

Because the go compiler can compile for all those targets it was called gc. 

People call it gc (lower case) and use GC (upper case) for "garbage collector"

erfang...@gmail.com

unread,
Dec 12, 2017, 6:38:37 PM12/12/17
to golang-nuts
but i want not install use GOLANG.
only want Go Compiler.
not may?

erfang...@gmail.com

unread,
Dec 12, 2017, 6:39:20 PM12/12/17
to golang-nuts
~/go1.4/bin$ ./go version
go version go1.4-bootstrap-20170531 linux/amd64

go1.4 installed.

erfang...@gmail.com

unread,
Dec 12, 2017, 6:41:57 PM12/12/17
to golang-nuts
at go1.4 version.
compiler and lexer,parser is write at C? or GO?

can check and change grammer at  /home/guest/go1.4/src/cmd/cc/cc.y ?

Dave Cheney

unread,
Dec 12, 2017, 6:46:53 PM12/12/17
to golang-nuts
Follow all the steps here, https://groups.google.com/d/msg/golang-nuts/24pSm-B3FqU/a0XYG4SBCgAJ

then do this

cd $HOME/go/src
env GOOS=linux GOARCH=ppc64 ./bootstrap.bash 
scp ../../go-linux-ppc64-bootstrap.tbz _your host_
ssh _your host

# now on the ppc64 host
tar xfj go-linux-ppc64-bootstrap.tbz 
cd go/src
git checkout go1.9.2
env GOROOT_BOOTSTRAP=$HOME/go-linux-ppc64-bootstrap ./make.bash
echo '$PATH=$PATH:$HOME/go/bin' >> ~/.profile
source ~/.profile

Dave Cheney

unread,
Dec 12, 2017, 6:48:11 PM12/12/17
to golang-nuts
Sorry, Go 1.4 is no longer supported, it is only used for bootstrapping. We will not fix /home/guest/go1.4/src/cmd/cc/cc.y

erfang...@gmail.com

unread,
Dec 12, 2017, 6:53:45 PM12/12/17
to golang-nuts
im for test , want change

package token lex , to another text.

example change package to   testpackage.

-----------------------

lexer/grammer is write at C or GO?

erfang...@gmail.com

unread,
Dec 12, 2017, 6:54:25 PM12/12/17
to golang-nuts
example input:

testpackage main
import "fmt"
func main() {
    fmt.Println("hello world")

Dave Cheney

unread,
Dec 12, 2017, 7:13:00 PM12/12/17
to golang-nuts
In all the supported versions of Go, that is Go 1.9 and soon Go 1.10, the grammar is written in Go. You will find the source here https://github.com/golang/go/tree/master/src/cmd/compile/internal/syntax

Bruno Albuquerque

unread,
Dec 12, 2017, 8:10:43 PM12/12/17
to erfang...@gmail.com, golang-nuts
Most likely not. The current version was compiled with a previous version that was also written in Go. it you continue going down this chain you eventually get to a Go version that was compiled with a C compiler but this is only needed for platforms that do not have a Go version yet (which is also not strictly true anymore, as you can technically cross-compile Go from one existing platform to another one. Even one that Go does not support yet)

On Tue, Dec 12, 2017 at 1:49 PM <erfang...@gmail.com> wrote:
so Main compiler is at previous version and made with C? 


On Wednesday, December 13, 2017 at 1:09:13 AM UTC+3:30, Tamás Gulácsi wrote:
Yes. It compiles itself with a previous verson of the compiler first.

--
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 golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bruno Albuquerque

unread,
Dec 12, 2017, 8:11:02 PM12/12/17
to erfang...@gmail.com, golang-nuts
Why do you want to explicitly use an old go version? Why not 1.9.2?

You can find pre-compiled packages for various platforms here: https://golang.org/dl/





--

Bruno Albuquerque

unread,
Dec 12, 2017, 8:11:02 PM12/12/17
to erfang...@gmail.com, golang-nuts
Go will work fine without a C compiler. Only if you use CGO (https://blog.golang.org/c-go-cgo) you need one.

--

Bruno Albuquerque

unread,
Dec 12, 2017, 8:11:03 PM12/12/17
to erfang...@gmail.com, golang-nuts
No the compiler does not generate C code. The compiler compiles Go code to the actual final binary.

On Tue, Dec 12, 2017 at 2:28 PM <erfang...@gmail.com> wrote:
so go compiler is made with c.

so go compiler how work : 
--------------
so in current golang version , golang generate c code and compile with c-compiler?

On Wednesday, December 13, 2017 at 1:49:07 AM UTC+3:30, Shawn Milochik wrote:
On Tue, Dec 12, 2017 at 4:48 PM, <erfang...@gmail.com> wrote:
so Main compiler is at previous version and made with C? 


Bruno Albuquerque

unread,
Dec 12, 2017, 8:11:24 PM12/12/17
to erfang...@gmail.com, golang-nuts
What is expected (assuming the code is correctly written). An executable file is generated and can be run normally.

I am sorry but I could not parse your following questions, but I will try some general answers:

1 - No, you do not need a C compiler to compile recent Go versions. You do need an existing compiled Go version though.
2 - You do not need a C compiler to compile Go programs unless you are making use of CGO.

--

erfang...@gmail.com

unread,
Dec 13, 2017, 6:21:10 AM12/13/17
to golang-nuts
in GO 1.4 , grammer/lexer is write at GO or C or both?

erfang...@gmail.com

unread,
Dec 13, 2017, 6:22:32 AM12/13/17
to golang-nuts
i am want test Main Go Compiler. and check and test compilers.
not GoLang.

erfang...@gmail.com

unread,
Dec 13, 2017, 6:30:53 AM12/13/17
to golang-nuts
?!! how may be?
a software , for this then generate a binary file. need Asm or Assembler.... or another Compiler.

if gocompiler not use c-compiler for generate binary file.(for a test hello world golang appliaction)

so GoCompiler how generate binary file for any platform?!

may be explain me how gocompiler work?!

erfang...@gmail.com

unread,
Dec 13, 2017, 6:40:02 AM12/13/17
to golang-nuts
for compile a test,hello world application (.go file) with golang.
alwayse need cgo compiler or c compiler?

cgo compiler only generate c file. not generate binary executable file.
like https://github.com/xlab/c-for-go

Jérôme Champion

unread,
Dec 13, 2017, 6:43:22 AM12/13/17
to golang-nuts
I think it would be better if you explain what you want to do.

As example : "I want to compile a go program on a ppc64 architecture with operating system XY version Z."

erfang...@gmail.com

unread,
Dec 13, 2017, 6:47:56 AM12/13/17
to golang-nuts
now i am have question about golang/go-compiler work.

erfang...@gmail.com

unread,
Dec 13, 2017, 6:49:06 AM12/13/17
to golang-nuts
i want research about gocompiler and want recompile main go-compiler in gnu/linux operation system.(ubuntu/arch)
not recompile golang.


On Wednesday, December 13, 2017 at 3:13:22 PM UTC+3:30, Jérôme Champion wrote:

Chris Hopkins

unread,
Dec 13, 2017, 6:49:58 AM12/13/17
to golang-nuts
You keep asking the same question, I think we have a misunderstanding here. To grossly simplify:

Way back when, the first C compilers were written in Assembly. Then someone produced a C compiler that was written in C. Now you use a C compiler to build a C compiler.
Some time ago the go compiler was written in C. Then someone produced a Go compiler that was written in Go. Now you use a Go compiler to build a Go compiler.

In the same way you can compile a C compiler with a C compiler, now once you have a Go compiler you can make a new Go compiler.
Yes, you need a C compiler to make the very first Go compiler, but you also need a C compiler to make a C compiler. Unless you have the very first C compiler that was written in Assembler.*

But you now have an assembly version of the Go compiler for all popular platforms. So you can just download that,
If you want it for an unpopular platform, then cross-compile.
If you don't want to do that, then use a C compiler to build an early version of the Go compiler; then use that to build a modern version of the go compiler.

Does that make sense?

* I believe the actual first C compiler was written in another language, but as I'm a hardware engineer, not a software historian :-)

Chris

erfang...@gmail.com

unread,
Dec 13, 2017, 6:57:17 AM12/13/17
to golang-nuts
how can make a new compiler programming language using c without assembly?(a compiler then can produce executable file) ??

Chris Hopkins

unread,
Dec 13, 2017, 7:10:05 AM12/13/17
to golang-nuts
Before I answer anything else, I don't understand what you are saying with:


On Wednesday, 13 December 2017 11:49:06 UTC, erfang...@gmail.com wrote:
i want research about gocompiler and want recompile main go-compiler in gnu/linux operation system.(ubuntu/arch)
not recompile golang.

To my mind:
golang == gocompiler

(Yes one could argue golang is also the go tooling + the standard library + the open sourced packages + the community + ... but that's beside the point)

What do you mean by the differences between "main go-compiler" and "golang"

Regards

Chris

erfang...@gmail.com

unread,
Dec 13, 2017, 7:20:22 AM12/13/17
to golang-nuts
Could you first answer this question?
They question may also be answered.

how can make a new compiler programming language using c without assembly?(a compiler then can produce executable file) ??

Gianguido Sorà

unread,
Dec 13, 2017, 7:29:16 AM12/13/17
to erfang...@gmail.com, golang-nuts
The compiler does produce an executable without any C involved. 

--
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 golang-nuts+unsubscribe@googlegroups.com.

Jan Mercl

unread,
Dec 13, 2017, 7:31:35 AM12/13/17
to erfang...@gmail.com, golang-nuts
On Wed, Dec 13, 2017 at 1:20 PM <erfang...@gmail.com> wrote:

> Could you first answer this question?

The problem is that so far no one seems to be able to understand some/most of your questions. Please try asking using more words of explanation. The added context may hopefully help others to reconstruct the meaning.

Suggestion: using the word "golang" only adds ambiguity. Above the domain name of the project, it's meaning is pretty blurry. Anyway, most often it's used as an inappropriate name of the Go programming language. And then understanding text like "not recompile golang" becomes guesswork.

--

-j

erfang...@gmail.com

unread,
Dec 13, 2017, 7:35:17 AM12/13/17
to golang-nuts
i am not tell interpreter.
i am tell compiler for generate a cross executable file.
may be show me a tutorial/video or a sample small compiler Using C Without Assembly?
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Chris Hopkins

unread,
Dec 13, 2017, 7:35:52 AM12/13/17
to golang-nuts
I think we have a misunderstanding. If we don't clear up this misunderstanding then we will keep going around in circles. 
Not wishing to offend, this comes across as a fishing expedition not as a request for specific help; however under the assumption that this is not the case, I'll try and guess at what you mean.

"how can make a new compiler programming language using c without assembly?"

Forget C. There is nothing special about C. It's just a computer language like any other. Any language can be used to create a compiler, you are converting text into an AST then resolving that.
The question I think you are asking is:
"how can make a new compiler programming language using an existing language?"
or
"How can you write a program that will convert Text into Assembly?"

If this is what you are asking, then you are fundamentally asking me to describe how a compiler works, in the length of an email. There are books thousands of pages long written on this subject.
Before I even start to tackle that, can I confirm this is what you are asking?

Regards

Chris

erfang...@gmail.com

unread,
Dec 13, 2017, 7:40:18 AM12/13/17
to golang-nuts
How can write a compiler Using C as test.exe then can use from test.exe compiler any where... so can write a input file like hello world application and generate executable file using test.exe.

undrestand?

Chris Hopkins

unread,
Dec 13, 2017, 7:43:19 AM12/13/17
to golang-nuts


On Wednesday, 13 December 2017 12:35:17 UTC, erfang...@gmail.com wrote:
i am not tell interpreter.

I'm not sure if you mean interpreter here in the context of interpreted language, or interpreter, someone  who translates between human languages.
 
i am tell compiler for generate a cross executable file.
may be show me a tutorial/video or a sample small compiler Using C Without Assembly?

Right, so this isn't about Go specifically.
This seems to be about how a program on one system can build a program on another. The answer to that question is exactly the same as how a compiler takes text and produces ASM to run on itself.
There are tons of videos on youtube about this. Just search Compiler theory. Or if you prefer the breakthrough for me was understanding ASTs (Abstract Syntax Trees)

Assuming that is what you don't understand.

erfang...@gmail.com

unread,
Dec 13, 2017, 7:45:45 AM12/13/17
to golang-nuts
mean a compiler like golang , then for use no need any another compiler and tools. only itself.

hello.go file :

package main
import "fmt"
func main() {
    fmt.Println("hello world!")
}
------
$ go build hello.go

Chris Hopkins

unread,
Dec 13, 2017, 7:47:05 AM12/13/17
to golang-nuts


On Wednesday, 13 December 2017 12:40:18 UTC, erfang...@gmail.com wrote:
How can write a compiler Using C as test.exe then can use from test.exe compiler any where... so can write a input file like hello world application and generate executable file using test.exe.

the compiler is told what to target so rather than translate 

a = a + b
into e.g.
ADD R0, R0, R1  # the ASM for architecture A
it instead translates it to:
ADS R0,R1 # ASM for architecture B

That's all it is doing in the end, translating text from one form into another



erfang...@gmail.com

unread,
Dec 13, 2017, 7:49:58 AM12/13/17
to golang-nuts
if you write a software then can lex and parse a input file and next AST and generate a code.
so need another compiler for final compile...

so your software will need another tools/compiler.

erfang...@gmail.com

unread,
Dec 13, 2017, 7:53:24 AM12/13/17
to golang-nuts
you are tell then generate a ASM code?! this may be hard And waste of time.

At the top of the conversation, it was said that only the C language could write compiler without any tools/another compiler.
so why now tell ASM?!

erfang...@gmail.com

unread,
Dec 13, 2017, 8:00:52 AM12/13/17
to golang-nuts
are you sure GoCompiler/GoLang generate ASM code for build executable file from .go?

John McKown

unread,
Dec 13, 2017, 8:16:27 AM12/13/17
to erfang...@gmail.com, golang-nuts
On Wed, Dec 13, 2017 at 6:53 AM, <erfang...@gmail.com> wrote:
you are tell then generate a ASM code?! this may be hard And waste of time.

At the top of the conversation, it was said that only the C language could write compiler without any tools/another compiler.
so why now tell ASM?!

​Whoever said "only the C language could write ..." was simply _WRONG_. Period.​ They are probably confused because they only know about the C language tools, such as "lex" and "bison", which help create C language programs to make compilers for computer languages. 

Also: https://en.wikipedia.org/wiki/Bootstrapping_(compilers) which is about "self hosted" compilers, such as Go, where the compiler is, itself, written in the language to be compiled.  Like using the English language to explain the English language. 

I don't want to discourage you, but it seems to me that you need to get some basic compiler concepts down. For me, it was (and still is) a struggle.

--
I have a theory that it's impossible to prove anything, but I can't prove it.

Maranatha! <><
John McKown

Volker Dobler

unread,
Dec 13, 2017, 10:37:56 AM12/13/17
to golang-nuts

On Wednesday, 13 December 2017 13:40:18 UTC+1, erfang...@gmail.com wrote:
How can write a compiler Using C as test.exe then can use from test.exe compiler any where... so can write a input file like hello world application and generate executable file using test.exe.

undrestand?

Yes.

This task is simple.

1. Buy the Dragon Book (Aho, Ullman, et al.)
2. Read it.
3. Understand it.
4. Get CPU documentation for all architectures you want to support.
5. Get OS documentation on how loading and syscalls works.
6. Write your own cross compiler.

Depending on your preexisting knowhow this might take
from 12 month to 10 years. This isn't something which can
be explained in a mailing list.

V.

Compiler

unread,
Dec 13, 2017, 11:54:04 AM12/13/17
to golang-nuts
please answer this.

Bruno Albuquerque

unread,
Dec 13, 2017, 11:57:41 AM12/13/17
to Compiler, golang-nuts
It directly generates a binary suitable for the target platform, yes. Again, you do not need a C compiler to compile a Go program unless you are using CGO.


--

Compiler

unread,
Dec 13, 2017, 12:00:50 PM12/13/17
to golang-nuts
i am undrestand compiler steps.
only have problem in code generation step.
so best way is this then compiler generate code is ASM.
GOLANG also generate ASM.

yeah?

Andy Balholm

unread,
Dec 13, 2017, 12:18:30 PM12/13/17
to Compiler, golang-nuts
No, the Go compiler doesn’t actually generate ASM. It generates machine code. So it doesn’t need the help of another compiler or assembler.

Andy

Compiler

unread,
Dec 13, 2017, 12:31:44 PM12/13/17
to golang-nuts
Machine Code?!

please show me github link source file then at they is generate sample binary... at GOLANG sources.

Andy Balholm

unread,
Dec 13, 2017, 1:33:27 PM12/13/17
to Compiler, golang-nuts
By “Machine Code” I mean that “go build” or “go install” generates an executable file that is ready for the target operating system and CPU to run directly. On Windows, it generates a .EXE file. On Unix-like operating systems it generates a “binary executable” file (which is basically the same thing, but it doesn’t have a suffix to identify the file type like Windows uses). 

(Internally, this process is divided into two steps, called “compile” and “link.” The compile step generates the machine code needed by the target CPU; the link step arranges this machine code into the file format that the target operating system expects.)

Andy

Compiler

unread,
Dec 13, 2017, 1:55:15 PM12/13/17
to golang-nuts
may be show me github link source file then at they is generate binary... at GOLANG sources.

Bruno Albuquerque

unread,
Dec 13, 2017, 2:09:24 PM12/13/17
to Compiler, golang-nuts
Here is the entry point for the compiler code:


And here is the entry point for the linker code:


Note this is all non-trivial. You do need to know how compilers/linkers work before trying to understand this specific code.

Compiler

unread,
Dec 13, 2017, 2:16:16 PM12/13/17
to golang-nuts
please show me code of compiler , linker of go1.4.(Based on C)

Bruno Albuquerque

unread,
Dec 13, 2017, 2:27:55 PM12/13/17
to Compiler, golang-nuts

Bruno Albuquerque

unread,
Dec 13, 2017, 2:29:08 PM12/13/17
to Compiler, golang-nuts
Oh, and the generic compiler frontend:


Dave Cheney

unread,
Dec 13, 2017, 2:41:03 PM12/13/17
to golang-nuts
The code is inside the file you referenced. That is a tar ball of the source of the bootstrap 1.4.2 compiler.

David Chase

unread,
Dec 13, 2017, 2:52:50 PM12/13/17
to golang-nuts
I think one of the best references to this is "BCPL: The Language and Its Compiler".
It is shorter than the Dragon Book, accessible, historical, and very well written.
I think you can find the PDF online (maybe, not sure).


On Tuesday, December 12, 2017 at 4:03:08 PM UTC-5, Compiler wrote:
Hello,
Go Compiler How Work at Last Version of GoLang?!
i mean Go Compiler , Not GoLang.

at the last version of golang. go compiler , generate c code and compile using gcc?!





Compiler

unread,
Dec 13, 2017, 5:19:16 PM12/13/17
to golang-nuts
tanks you.
i not found complate book pdf file.
you not have file?!

Compiler

unread,
Dec 15, 2017, 6:45:01 PM12/15/17
to golang-nuts
Last Version of Go Compiler doing Generate `ASM Code` and next Linker... and final binary output file?


Go Compiler is use LLVM/IR?


go1.4/doc/go_faq.html : 

We considered using LLVM for <code>gc</code> but we felt it was too large and
slow to meet our performance goals.

Gianguido Sorà

unread,
Dec 15, 2017, 6:47:31 PM12/15/17
to Compiler, golang-nuts
No, Go doesn't use LLVM. 

To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.

Compiler

unread,
Dec 15, 2017, 6:49:53 PM12/15/17
to golang-nuts
Why not Use?!
This not more Easy?

Google Team/Co at RustLang is using LLVM.

andrey mirtchovski

unread,
Dec 15, 2017, 6:52:14 PM12/15/17
to Compiler, golang-nuts
> Why not Use?!

The Go team felt LLVM was too large and slow to meet their performance goals.

Compiler

unread,
Dec 15, 2017, 6:54:06 PM12/15/17
to golang-nuts
Tanks you.
please also answer my first question.


Last Version of Go Compiler doing Generate `ASM Code` and next Linker... and make final binary output file for they platform?


On Saturday, December 16, 2017 at 3:17:31 AM UTC+3:30, Gianguido Sorà wrote:

Compiler

unread,
Dec 15, 2017, 6:57:24 PM12/15/17
to golang-nuts
https://github.com/kostya/benchmarks

at many sample/tests Rust is better of Go.(Performance)

andrey mirtchovski

unread,
Dec 15, 2017, 7:00:14 PM12/15/17
to Compiler, golang-nuts
> Last Version of Go Compiler doing Generate `ASM Code` and next Linker... and make final binary output file for they platform?

The modern Go compilers (https://golang.org/cmd/compile/, gccgo) do
not generate "ASM Code" unless an appropriate flag is presented to
them. For the "compile" tool (go tool compile) that flag is -S. For
gccgo, I believe it is -S too.

Compiler

unread,
Dec 15, 2017, 7:02:14 PM12/15/17
to golang-nuts
If for use golang/compiler no need any tools and another compiler.
and if not generate ASM code.
so go compiler generate what?!

andrey mirtchovski

unread,
Dec 15, 2017, 7:04:27 PM12/15/17
to Compiler, golang-nuts
> so go compiler generate what?!

https://golang.org/cmd/compile/

Compile, typically invoked as “go tool compile,” compiles a single Go
package comprising the files named on the command line. It then writes
a single object file named for the basename of the first source file
with a .o suffix. The object file can then be combined with other
objects into a package archive or passed directly to the linker (“go
tool link”). If invoked with -pack, the compiler writes an archive
directly, bypassing the intermediate object file.

Compiler

unread,
Dec 15, 2017, 7:06:30 PM12/15/17
to golang-nuts
what you think about this?!

Compiler

unread,
Dec 15, 2017, 7:08:04 PM12/15/17
to golang-nuts
hmmm , 
what is name of this way for generate executable file at compiler?

Dave Cheney

unread,
Dec 15, 2017, 7:13:58 PM12/15/17
to golang-nuts
I think we should all switch to rust.

Compiler

unread,
Dec 15, 2017, 7:22:30 PM12/15/17
to golang-nuts
mean many go developer will switch to Rust?

but RUST is also google's Lang.
why when google have a good lang why begin write new lang(go)?!

Dave Cheney

unread,
Dec 15, 2017, 7:26:11 PM12/15/17
to golang-nuts
Just to be clear, I wasn’t being serious.

But then again, I’m starting to think that you aren’t being serious either.

Bakul Shah

unread,
Dec 15, 2017, 7:37:49 PM12/15/17
to Compiler, golang-nuts
Everything you have asked about has been covered multiple
times but you will have to do some research on your own.
May I suggest reading some documentation on the golang.org
website as well as watching go language related videos? You
can also search for related discussions on this mailing list.

Compiler

unread,
Dec 15, 2017, 7:51:09 PM12/15/17
to golang-nuts
Tanks You.

Rust in many tests/samples is better of Go.(Performance)

Compiler

unread,
Dec 15, 2017, 7:51:32 PM12/15/17
to golang-nuts
No Answer?!

Ian Lance Taylor

unread,
Dec 15, 2017, 8:33:45 PM12/15/17
to Compiler, golang-nuts
The technique of generating an object file directly from the compiler
does not have a name.

Many other compilers do the same thing For example, clang/LLVM does it.

These questions about how compilers work do not have anything to do
with Go, and I encourage you to take them to some other group.

Also, no offense, but I encourage you to find somebody who is fluent
in both your language and English to help you write these questions.
It is often very difficult to understand what you are asking.

Ian

Compiler

unread,
Dec 16, 2017, 4:21:15 AM12/16/17
to golang-nuts
Tanks you.

==> The technique of generating an object file directly from the compiler Without Generate ASM Code does not have a name.

+ May be show me a sample/source/tutorial of generate object file Using C?!

Volker Dobler

unread,
Dec 16, 2017, 4:54:10 AM12/16/17
to golang-nuts
On Saturday, 16 December 2017 10:21:15 UTC+1, Compiler wrote:
Tanks you.

==> The technique of generating an object file directly from the compiler Without Generate ASM Code does not have a name.

+ May be show me a sample/source/tutorial of generate object file Using C?!

This is really far of the topic of golang-nuts.

I'm sure you'll find an other mailing list or just
dig into any other compiler out there (LLVM,
Go < 1.4, gcc, whatnot).

V.
 
Reply all
Reply to author
Forward
0 new messages