Go language compilation

Source: Internet
Author: User

The compilation of the Go language is based on the compilation of Plan 9, but there are some differences. The main difference is that the Go language assembly instructions do not necessarily correspond directly to the machine representation. There are some direct correspondence, some are not.

Another difference between the Go language assembly and Plan 9 is the precedence of the operator. For example 3&1<<2 is interpreted as (3&1) <<2.

Introduced:

The compiler produces the middle code of some forces, and the specific machine instructions are determined after the assembly is generated (linker's work).

Funcdata and Pcdata are compiler-generated to hold some information about garbage collection.

Symbol:

The go language has 4 pseudo registers:

FP: Frame pointers, saving parameters and local variables

PC: Program pointer, responsible for jump and process Control

SB: Static base pointer, global variable

SP: Stack pointer, stack top

All of the symbols are in the form of the offset of Ctrip FP and SB.

The SB pseudo register is used to represent global variables or functions, as Foo (SB) is used to represent Foo's address. Add <> symbol is visible in this file.

The FP is used to hold parameters. (0) FP is the first parameter (8) FP is the second (if 64-bit machine).

The SP points to the top of the local stack, using x-8 (SP) and y-4 (SP) to represent the variable.

A direct jmp or call instruction can only point to the text symbol, not the offset of the symbol.

Instructions:

The text directive defines a symbol followed by the body of the function.

The data directive defines a section of memory that is not initialized.

DATA    Symbol+offset (SB)/width, value

The global directive defines a symbol that is globally

Globl divtab<> (SB), Rodata, $globl runtime Tlsoffset (SB), Noptr, $4

Divtab is a 64byte form of the system that preserves 4 byte of shaping. Tlsoffset Yes, 4byte no pointers

Directive Modifiers:

Dupok: Allows multiple instances in a binary file

Nosplit:for Text,routine or routine, you must fill the stack with the head of the space to protect the stack separation

Rodata:for Data/globl, put the data in a read-only segment

Noptr:for Data/globl, no pointers to data, no need to be scanned by garbage collection

Wrapper:for text,wrapper function, does not need to be disabled recover count

Needctxt:for TEXT, closures

Runtime Collaboration:

Noptr and Rodata data do not need to be garbage collected. Data that is smaller than the pointer is also treated as noptr. Do not write non-read-only data in the go assembly.

Go language compilation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.