基于免费的鲲鹏服务器上编译go语言

举报
Jie.Niu 发表于 2020/04/30 17:44:32 2020/04/30
【摘要】 1、环境申请当前华为云学院有一个免费的公测:鲲鹏工具链将X86 Java代码迁移到鲲鹏平台2、查看环境信息这是基于CentOS 7.5版本的系统:[root@ecs-netty ~]# lsb_release -aLSB Version: :core-4.1-aarch64:core-4.1-noarchDistributor ID: CentOSDescription: CentOS Li...

1、环境申请

当前华为云学院有一个免费的公测:鲲鹏工具链将X86 Java代码迁移到鲲鹏平台


2、查看环境信息

这是基于CentOS 7.5版本的系统:

[root@ecs-netty ~]# lsb_release -a
LSB Version:	:core-4.1-aarch64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.5.1804 (AltArch) 
Release:	7.5.1804
Codename:	AltArch


Golang的版本信息:

[root@ecs-netty ~]# go version 
go version go1.13 linux/arm64
[root@ecs-netty ~]# which go
/usr/bin/go
[root@ecs-netty ~]#


设置GOPATH:

export GOPATH=/root/gopath
export GOROOT=/usr/lib/golang
export GOBIN=/usr/bin/go


3、编写简单的go程序

程序helloworld.go源码:

package main

import (
 "fmt"
)

func main() {
 fmt.Println("Hello Golang!")
}


编译程序:

[root@ecs-netty gopath]# vi helloworld.go 
[root@ecs-netty gopath]# go build -o helloworld helloworld.go 
[root@ecs-netty gopath]# ls
hello.txt  helloworld  helloworld.go  simple.go
[root@ecs-netty gopath]# ll
total 2032
-rw-r--r-- 1 root root      14 Apr 30 16:45 hello.txt
-rwxr-xr-x 1 root root 2097292 Apr 30 16:52 helloworld
-rw-r--r-- 1 root root      79 Apr 30 16:52 helloworld.go
-rw-r--r-- 1 root root     207 Apr 30 16:47 simple.go


执行程序:

[root@ecs-netty gopath]# ./helloworld 
Hello Golang!


4、Golang TCP Server的例子


package main
import (
	"flag"
	"fmt"
	"io"
	"net"
	"os"
)
var host = flag.String("host", "", "host")
var port = flag.String("port", "54321", "port")
func main() {
	flag.Parse()
	var l net.Listener
	var err error
	l, err = net.Listen("tcp", *host+":"+*port)
	if err != nil {
		fmt.Println("Error listening:", err)
		os.Exit(1)
	}
	defer l.Close()
	fmt.Println("Listening on " + *host + ":" + *port)
	for {
		conn, err := l.Accept()
		if err != nil {
			fmt.Println("Error accepting: ", err)
			os.Exit(1)
		}
		//logs an incoming message
		fmt.Printf("Received message %s -> %s \n", conn.RemoteAddr(), conn.LocalAddr())
		// Handle connections in a new goroutine.
		go handleRequest(conn)
	}
}
func handleRequest(conn net.Conn) {
	defer conn.Close()
	for {
		io.Copy(conn, conn)
	}
}



5、与X86上输出的汇编差异(待细化分析)



6、实验总结

    非常流畅,非常稳定。

  1. 实验的能力,很轻易就达到目标

    ① 使用Maven构建打包程序。
    ② 了解Netty打包过程及相关依赖。

  2. 看到里面有一个golang 1.13的环境,就做了简单的测试,发现以下问题

    发现golang的库有点问题。

    ① net库中,使用net.Dial函数,报错:undefined
    ② http库中,使用http.ListenAndServe时,报错:undefined

      因为时间问题,并没有挖出来根因。



附:helloworld的ARM的汇编文本输出

[root@ecs-netty gopath]# go build -gcflags -S helloworld.go 
# command-line-arguments
os.(*File).close STEXT dupok size=32 args=0x18 locals=0x0 leaf
	0x0000 00000 (<autogenerated>:1)	TEXT	os.(*File).close(SB), DUPOK|LEAF|NOFRAME|ABIInternal, $0-24
	0x0000 00000 (<autogenerated>:1)	FUNCDATA	ZR, gclocals·e6397a44f8e1b6e77d0f200b4fba5269(SB)
	0x0000 00000 (<autogenerated>:1)	FUNCDATA	$1, gclocals·69c1753bd5f81501d95132d08af04464(SB)
	0x0000 00000 (<autogenerated>:1)	FUNCDATA	$2, gclocals·9fb7f0986f647f17cb53dda1484e0f7a(SB)
	0x0000 00000 (<autogenerated>:1)	PCDATA	ZR, $1
	0x0000 00000 (<autogenerated>:1)	PCDATA	$1, $1
	0x0000 00000 (<autogenerated>:1)	MOVD	""..this(FP), R0
	0x0004 00004 (<autogenerated>:1)	MOVD	(R0), R0
	0x0008 00008 (<autogenerated>:1)	PCDATA	ZR, ZR
	0x0008 00008 (<autogenerated>:1)	PCDATA	$1, ZR
	0x0008 00008 (<autogenerated>:1)	MOVD	R0, ""..this(FP)
	0x000c 00012 (<autogenerated>:1)	STP	(ZR, ZR), "".~r0+8(FP)
	0x0010 00016 (<autogenerated>:1)	JMP	os.(*file).close(SB)
	0x0000 e0 07 40 f9 00 00 40 f9 e0 07 00 f9 ff 7f 01 a9  ..@...@.........
	0x0010 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00  ................
	rel 16+4 t=10 os.(*file).close+0
"".main STEXT size=144 args=0x0 locals=0x58
	0x0000 00000 (/root/gopath/helloworld.go:7)	TEXT	"".main(SB), ABIInternal, $96-0
	0x0000 00000 (/root/gopath/helloworld.go:7)	MOVD	16(g), R1
	0x0004 00004 (/root/gopath/helloworld.go:7)	MOVD	RSP, R2
	0x0008 00008 (/root/gopath/helloworld.go:7)	CMP	R1, R2
	0x000c 00012 (/root/gopath/helloworld.go:7)	BLS	120
	0x0010 00016 (/root/gopath/helloworld.go:7)	MOVD.W	R30, -96(RSP)
	0x0014 00020 (/root/gopath/helloworld.go:7)	MOVD	R29, -8(RSP)
	0x0018 00024 (/root/gopath/helloworld.go:7)	SUB	$8, RSP, R29
	0x001c 00028 (/root/gopath/helloworld.go:7)	FUNCDATA	ZR, gclocals·69c1753bd5f81501d95132d08af04464(SB)
	0x001c 00028 (/root/gopath/helloworld.go:7)	FUNCDATA	$1, gclocals·568470801006e5c0dc3947ea998fe279(SB)
	0x001c 00028 (/root/gopath/helloworld.go:7)	FUNCDATA	$2, gclocals·bfec7e55b3f043d1941c093912808913(SB)
	0x001c 00028 (/root/gopath/helloworld.go:7)	FUNCDATA	$3, "".main.stkobj(SB)
	0x001c 00028 (/root/gopath/helloworld.go:8)	PCDATA	ZR, ZR
	0x001c 00028 (/root/gopath/helloworld.go:8)	PCDATA	$1, $1
	0x001c 00028 (/root/gopath/helloworld.go:8)	STP	(ZR, ZR), ""..autotmp_11-16(SP)
	0x0020 00032 (/root/gopath/helloworld.go:8)	PCDATA	ZR, $1
	0x0020 00032 (/root/gopath/helloworld.go:8)	MOVD	$type.string(SB), R0
	0x0028 00040 (/root/gopath/helloworld.go:8)	PCDATA	ZR, ZR
	0x0028 00040 (/root/gopath/helloworld.go:8)	MOVD	R0, ""..autotmp_11-16(SP)
	0x002c 00044 (/root/gopath/helloworld.go:8)	PCDATA	ZR, $1
	0x002c 00044 (/root/gopath/helloworld.go:8)	MOVD	$""..stmp_0(SB), R0
	0x0034 00052 (/root/gopath/helloworld.go:8)	PCDATA	ZR, ZR
	0x0034 00052 (/root/gopath/helloworld.go:8)	MOVD	R0, ""..autotmp_11-8(SP)
	0x0038 00056 ($GOROOT/src/fmt/print.go:274)	PCDATA	ZR, $1
	0x0038 00056 ($GOROOT/src/fmt/print.go:274)	MOVD	os.Stdout(SB), R0
	0x0044 00068 ($GOROOT/src/fmt/print.go:274)	PCDATA	ZR, $2
	0x0044 00068 ($GOROOT/src/fmt/print.go:274)	MOVD	$go.itab.*os.File,io.Writer(SB), R1
	0x004c 00076 ($GOROOT/src/fmt/print.go:274)	PCDATA	ZR, $1
	0x004c 00076 ($GOROOT/src/fmt/print.go:274)	MOVD	R1, 8(RSP)
	0x0050 00080 ($GOROOT/src/fmt/print.go:274)	PCDATA	ZR, ZR
	0x0050 00080 ($GOROOT/src/fmt/print.go:274)	MOVD	R0, 16(RSP)
	0x0054 00084 ($GOROOT/src/fmt/print.go:274)	PCDATA	ZR, $1
	0x0054 00084 ($GOROOT/src/fmt/print.go:274)	PCDATA	$1, ZR
	0x0054 00084 ($GOROOT/src/fmt/print.go:274)	MOVD	$""..autotmp_11-16(SP), R0
	0x0058 00088 ($GOROOT/src/fmt/print.go:274)	PCDATA	ZR, ZR
	0x0058 00088 ($GOROOT/src/fmt/print.go:274)	MOVD	R0, 24(RSP)
	0x005c 00092 ($GOROOT/src/fmt/print.go:274)	MOVD	$1, R0
	0x0060 00096 ($GOROOT/src/fmt/print.go:274)	MOVD	R0, 32(RSP)
	0x0064 00100 ($GOROOT/src/fmt/print.go:274)	MOVD	R0, 40(RSP)
	0x0068 00104 ($GOROOT/src/fmt/print.go:274)	CALL	fmt.Fprintln(SB)
	0x006c 00108 (<unknown line number>)	MOVD	-8(RSP), R29
	0x0070 00112 (<unknown line number>)	MOVD.P	96(RSP), R30
	0x0074 00116 (<unknown line number>)	RET	(R30)
	0x0078 00120 (<unknown line number>)	NOP
	0x0078 00120 (/root/gopath/helloworld.go:7)	PCDATA	$1, $-1
	0x0078 00120 (/root/gopath/helloworld.go:7)	PCDATA	$0, $-1
	0x0078 00120 (/root/gopath/helloworld.go:7)	MOVD	R30, R3
	0x007c 00124 (/root/gopath/helloworld.go:7)	CALL	runtime.morestack_noctxt(SB)
	0x0080 00128 (/root/gopath/helloworld.go:7)	JMP	0
	0x0000 81 0b 40 f9 e2 03 00 91 5f 00 01 eb 69 03 00 54  ..@....._...i..T
	0x0010 fe 0f 1a f8 fd 83 1f f8 fd 23 00 d1 ff ff 04 a9  .........#......
	0x0020 00 00 00 90 00 00 00 91 e0 27 00 f9 00 00 00 90  .........'......
	0x0030 00 00 00 91 e0 2b 00 f9 1b 00 00 90 7b 03 00 91  .....+......{...
	0x0040 60 03 40 f9 01 00 00 90 21 00 00 91 e1 07 00 f9  `.@.....!.......
	0x0050 e0 0b 00 f9 e0 23 01 91 e0 0f 00 f9 e0 03 40 b2  .....#........@.
	0x0060 e0 13 00 f9 e0 17 00 f9 00 00 00 94 fd 83 5f f8  .............._.
	0x0070 fe 07 46 f8 c0 03 5f d6 e3 03 1e aa 00 00 00 94  ..F..._.........
	0x0080 e0 ff ff 17 00 00 00 00 00 00 00 00 00 00 00 00  ................
	rel 32+8 t=3 type.string+0
	rel 44+8 t=3 ""..stmp_0+0
	rel 56+8 t=3 os.Stdout+0
	rel 68+8 t=3 go.itab.*os.File,io.Writer+0
	rel 104+4 t=10 fmt.Fprintln+0
	rel 116+0 t=11 +0
	rel 124+4 t=10 runtime.morestack_noctxt+0
go.cuinfo.packagename.main SDWARFINFO dupok size=0
	0x0000 6d 61 69 6e                                      main
go.info.fmt.Println$abstract SDWARFINFO dupok size=42
	0x0000 04 66 6d 74 2e 50 72 69 6e 74 6c 6e 00 01 01 11  .fmt.Println....
	0x0010 61 00 00 00 00 00 00 11 6e 00 01 00 00 00 00 11  a.......n.......
	0x0020 65 72 72 00 01 00 00 00 00 00                    err.......
	rel 19+4 t=28 go.info.[]interface {}+0
	rel 27+4 t=28 go.info.int+0
	rel 37+4 t=28 go.info.error+0
go.loc.os.(*File).close SDWARFLOC dupok size=0
go.info.os.(*File).close SDWARFINFO dupok size=55
	0x0000 03 6f 73 2e 28 2a 46 69 6c 65 29 2e 63 6c 6f 73  .os.(*File).clos
	0x0010 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  e...............
	0x0020 00 00 01 9c 00 00 00 00 01 0f 7e 72 30 00 01 ec  ..........~r0...
	0x0030 01 00 00 00 00 00 00                             .......
	rel 18+8 t=1 os.(*File).close+0
	rel 26+8 t=1 os.(*File).close+32
	rel 36+4 t=29 gofile..<autogenerated>+0
	rel 49+4 t=28 go.info.error+0
go.range.os.(*File).close SDWARFRANGE dupok size=0
go.isstmt.os.(*File).close SDWARFMISC dupok size=0
	0x0000 04 01 01 03 02 04 00                             .......
go.string."Hello Golang!" SRODATA dupok size=13
	0x0000 48 65 6c 6c 6f 20 47 6f 6c 61 6e 67 21           Hello Golang!
go.loc."".main SDWARFLOC size=0
go.info."".main SDWARFINFO size=66
	0x0000 03 22 22 2e 6d 61 69 6e 00 00 00 00 00 00 00 00  ."".main........
	0x0010 00 00 00 00 00 00 00 00 00 01 9c 00 00 00 00 01  ................
	0x0020 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0030 00 00 00 00 00 00 00 00 00 08 12 00 00 00 00 00  ................
	0x0040 00 00                                            ..
	rel 9+8 t=1 "".main+0
	rel 17+8 t=1 "".main+144
	rel 27+4 t=29 gofile../root/gopath/helloworld.go+0
	rel 33+4 t=28 go.info.fmt.Println$abstract+0
	rel 37+8 t=1 "".main+56
	rel 45+8 t=1 "".main+108
	rel 53+4 t=29 gofile../root/gopath/helloworld.go+0
	rel 59+4 t=28 go.info.fmt.Println$abstract+15
go.range."".main SDWARFRANGE size=0
go.isstmt."".main SDWARFMISC size=0
	0x0000 04 08 01 06 02 03 01 09 02 01 01 03 02 06 00     ...............
runtime.gcbits.01 SRODATA dupok size=1
	0x0000 01                                               .
type..namedata.*interface {}- SRODATA dupok size=16
	0x0000 00 00 0d 2a 69 6e 74 65 72 66 61 63 65 20 7b 7d  ...*interface {}
type.*interface {} SRODATA dupok size=56
	0x0000 08 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00  ................
	0x0010 4f 0f 96 9d 00 08 08 36 00 00 00 00 00 00 00 00  O......6........
	0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0030 00 00 00 00 00 00 00 00                          ........
	rel 24+8 t=1 runtime.algarray+80
	rel 32+8 t=1 runtime.gcbits.01+0
	rel 40+4 t=5 type..namedata.*interface {}-+0
	rel 48+8 t=1 type.interface {}+0
runtime.gcbits.02 SRODATA dupok size=1
	0x0000 02                                               .
type.interface {} SRODATA dupok size=80
	0x0000 10 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00  ................
	0x0010 e7 57 a0 18 02 08 08 14 00 00 00 00 00 00 00 00  .W..............
	0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	rel 24+8 t=1 runtime.algarray+144
	rel 32+8 t=1 runtime.gcbits.02+0
	rel 40+4 t=5 type..namedata.*interface {}-+0
	rel 44+4 t=6 type.*interface {}+0
	rel 56+8 t=1 type.interface {}+80
type..namedata.*[]interface {}- SRODATA dupok size=18
	0x0000 00 00 0f 2a 5b 5d 69 6e 74 65 72 66 61 63 65 20  ...*[]interface 
	0x0010 7b 7d                                            {}
type.*[]interface {} SRODATA dupok size=56
	0x0000 08 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00  ................
	0x0010 f3 04 9a e7 00 08 08 36 00 00 00 00 00 00 00 00  .......6........
	0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0030 00 00 00 00 00 00 00 00                          ........
	rel 24+8 t=1 runtime.algarray+80
	rel 32+8 t=1 runtime.gcbits.01+0
	rel 40+4 t=5 type..namedata.*[]interface {}-+0
	rel 48+8 t=1 type.[]interface {}+0
type.[]interface {} SRODATA dupok size=56
	0x0000 18 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00  ................
	0x0010 70 93 ea 2f 02 08 08 17 00 00 00 00 00 00 00 00  p../............
	0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0030 00 00 00 00 00 00 00 00                          ........
	rel 24+8 t=1 runtime.algarray+0
	rel 32+8 t=1 runtime.gcbits.01+0
	rel 40+4 t=5 type..namedata.*[]interface {}-+0
	rel 44+4 t=6 type.*[]interface {}+0
	rel 48+8 t=1 type.interface {}+0
type..namedata.*[1]interface {}- SRODATA dupok size=19
	0x0000 00 00 10 2a 5b 31 5d 69 6e 74 65 72 66 61 63 65  ...*[1]interface
	0x0010 20 7b 7d                                          {}
type.*[1]interface {} SRODATA dupok size=56
	0x0000 08 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00  ................
	0x0010 bf 03 a8 35 00 08 08 36 00 00 00 00 00 00 00 00  ...5...6........
	0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0030 00 00 00 00 00 00 00 00                          ........
	rel 24+8 t=1 runtime.algarray+80
	rel 32+8 t=1 runtime.gcbits.01+0
	rel 40+4 t=5 type..namedata.*[1]interface {}-+0
	rel 48+8 t=1 type.[1]interface {}+0
type.[1]interface {} SRODATA dupok size=72
	0x0000 10 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00  ................
	0x0010 50 91 5b fa 02 08 08 11 00 00 00 00 00 00 00 00  P.[.............
	0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0040 01 00 00 00 00 00 00 00                          ........
	rel 24+8 t=1 runtime.algarray+144
	rel 32+8 t=1 runtime.gcbits.02+0
	rel 40+4 t=5 type..namedata.*[1]interface {}-+0
	rel 44+4 t=6 type.*[1]interface {}+0
	rel 48+8 t=1 type.interface {}+0
	rel 56+8 t=1 type.[]interface {}+0
""..inittask SNOPTRDATA size=32
	0x0000 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
	0x0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	rel 24+8 t=1 fmt..inittask+0
""..stmp_0 SRODATA size=16
	0x0000 00 00 00 00 00 00 00 00 0d 00 00 00 00 00 00 00  ................
	rel 0+8 t=1 go.string."Hello Golang!"+0
go.itab.*os.File,io.Writer SRODATA dupok size=32
	0x0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0010 44 b5 f3 33 00 00 00 00 00 00 00 00 00 00 00 00  D..3............
	rel 0+8 t=1 type.io.Writer+0
	rel 8+8 t=1 type.*os.File+0
	rel 24+8 t=1 os.(*File).Write+0
go.itablink.*os.File,io.Writer SRODATA dupok size=8
	0x0000 00 00 00 00 00 00 00 00                          ........
	rel 0+8 t=1 go.itab.*os.File,io.Writer+0
type..importpath.fmt. SRODATA dupok size=6
	0x0000 00 00 03 66 6d 74                                ...fmt
gclocals·e6397a44f8e1b6e77d0f200b4fba5269 SRODATA dupok size=10
	0x0000 02 00 00 00 03 00 00 00 01 00                    ..........
gclocals·69c1753bd5f81501d95132d08af04464 SRODATA dupok size=8
	0x0000 02 00 00 00 00 00 00 00                          ........
gclocals·9fb7f0986f647f17cb53dda1484e0f7a SRODATA dupok size=10
	0x0000 02 00 00 00 01 00 00 00 00 01                    ..........
gclocals·568470801006e5c0dc3947ea998fe279 SRODATA dupok size=10
	0x0000 02 00 00 00 02 00 00 00 00 02                    ..........
gclocals·bfec7e55b3f043d1941c093912808913 SRODATA dupok size=11
	0x0000 03 00 00 00 02 00 00 00 00 01 03                 ...........
"".main.stkobj SRODATA dupok size=24
	0x0000 01 00 00 00 00 00 00 00 f0 ff ff ff ff ff ff ff  ................
	0x0010 00 00 00 00 00 00 00 00                          ........
	rel 16+8 t=1 type.[1]interface {}+0



【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。