search
HomeBackend DevelopmentGolangModify go to use Gem5 m5ops: go tool dist displays import message and then exits

修改go以使用Gem5 m5ops:go tool dist显示导入消息然后退出

php editor Apple is here to introduce to you a method of modifying the Go language to use Gem5 m5ops. Gem5 is a widely used emulator, and m5ops is a set of operating system interfaces in Gem5. By modifying the Go language, we can use Gem5's m5ops interface for performance analysis and debugging. The specific steps are to add support for m5ops to the Go tool chain, and then use the functions provided by m5ops for performance monitoring and debugging operations. In this way, we can better understand how the Go language is running in the simulation environment and perform corresponding optimization and debugging work.

Question content

I am still new to golang.

I'm trying to insert some c function calls (specifically m5ops) into golang's runtime (specifically src/proc.go).

I tried using cgo, which resulted in adding this import to the beginning of proc.go:

// #cgo cflags: -i$(gem5_path)/include -static
// #cgo ldflags: -l$(gem5_path)/util/m5/build/x86/out -lm5
// #include <gem5/m5ops.h>
import "c"

But when I try to rebuild using ./all.bash the script outputs and then exits:

./all.bash
building go cmd/dist using /usr/local/go. (go1.20.5 linux/amd64)
building go toolchain1 using /usr/local/go.
building go bootstrap cmd/go (go_bootstrap) using go toolchain1.
go tool dist: /home/landerx/goroot/src/runtime/proc.go imports c

A more detailed version of the above output:

./all.bash -v
Building Go cmd/dist using /usr/local/go. (go1.20.5 linux/amd64)
cmd/dist

Building Go toolchain1 using /usr/local/go.
internal/goarch
internal/coverage/rtcov
internal/goos
internal/race
internal/unsafeheader
internal/goexperiment
unicode
runtime/internal/syscall
sync/atomic
runtime/internal/atomic
internal/cpu
unicode/utf8
internal/itoa
math/bits
internal/abi
runtime/internal/math
runtime/internal/sys
bootstrap/internal/goarch
bootstrap/internal/goexperiment
bootstrap/math/bits
encoding
bootstrap/internal/unsafeheader
bootstrap/internal/platform
bootstrap/internal/coverage
internal/bytealg
bootstrap/internal/abi
math
unicode/utf16
bootstrap/internal/goversion
internal/goversion
bootstrap/internal/race
bootstrap/cmd/compile/internal/test
runtime
internal/reflectlite
runtime/metrics
sync
internal/testlog
internal/godebug
bootstrap/internal/bisect
math/rand
errors
sort
bootstrap/sort
io
internal/oserror
internal/safefilepath
path
strconv
bootstrap/strconv
syscall
bootstrap/container/heap
hash
text/tabwriter
bytes
strings
hash/adler32
hash/fnv
hash/crc32
crypto
reflect
bootstrap/internal/types/errors
go/build/constraint
bootstrap/go/build/constraint
bufio
regexp/syntax
html
internal/syscall/execenv
internal/syscall/unix
time
regexp
context
io/fs
internal/poll
internal/fmtsort
bootstrap/internal/saferio
encoding/binary
os
bootstrap/cmd/internal/notsha256
encoding/base64
bootstrap/cmd/internal/sys
crypto/md5
bootstrap/internal/lazyregexp
internal/lazyregexp
path/filepath
fmt
os/exec
log
bootstrap/internal/buildcfg
flag
bootstrap/cmd/internal/src
text/scanner
bootstrap/cmd/internal/edit
bootstrap/cmd/internal/pkgpath
go/token
bootstrap/compress/flate
bootstrap/internal/zstd
go/doc/comment
bootstrap/debug/dwarf
encoding/json
runtime/debug
bootstrap/math/big
bootstrap/cmd/internal/bio
net/url
go/scanner
bootstrap/cmd/internal/objabi
bootstrap/cmd/compile/internal/abt
bootstrap/cmd/internal/goobj
bootstrap/cmd/internal/gcprog
bootstrap/cmd/internal/quoted
bootstrap/compress/zlib
encoding/hex
compress/flate
go/ast
internal/buildcfg
internal/goroot
bootstrap/cmd/internal/dwarf
runtime/trace
bootstrap/cmd/internal/archive
bootstrap/cmd/internal/obj
bootstrap/debug/macho
bootstrap/debug/elf
bootstrap/debug/pe
bootstrap/internal/xcoff
bootstrap/cmd/link/internal/dwtest
compress/gzip
bootstrap/internal/profile
runtime/pprof
go/doc
go/printer
go/internal/typeparams
go/parser
bootstrap/cmd/internal/codesign
bootstrap/go/constant
bootstrap/internal/pkgbits
bootstrap/cmd/compile/internal/syntax
bootstrap/cmd/link/internal/benchmark
bootstrap/cmd/compile/internal/pgo/internal/graph
go/build
go/format
bootstrap/cmd/cgo
bootstrap/cmd/internal/obj/loong64
bootstrap/cmd/internal/obj/mips
bootstrap/cmd/internal/obj/wasm
bootstrap/cmd/internal/obj/arm
bootstrap/cmd/internal/obj/arm64
bootstrap/cmd/internal/obj/s390x
bootstrap/cmd/internal/obj/riscv
bootstrap/cmd/internal/obj/ppc64
bootstrap/cmd/internal/obj/x86
bootstrap/cmd/asm/internal/flags
bootstrap/cmd/compile/internal/base
bootstrap/cmd/compile/internal/logopt
bootstrap/cmd/asm/internal/lex
bootstrap/cmd/link/internal/sym
bootstrap/cmd/link/internal/loader
bootstrap/cmd/compile/internal/bitvec
bootstrap/cmd/compile/internal/types
bootstrap/cmd/compile/internal/types2
bootstrap/cmd/link/internal/loadelf
bootstrap/cmd/link/internal/loadmacho
bootstrap/cmd/link/internal/loadpe
bootstrap/cmd/link/internal/loadxcoff
bootstrap/cmd/compile/internal/typebits
bootstrap/cmd/compile/internal/ir
bootstrap/cmd/asm/internal/arch
bootstrap/cmd/link/internal/ld
bootstrap/cmd/asm/internal/asm
bootstrap/cmd/asm
bootstrap/cmd/compile/internal/abi
bootstrap/cmd/compile/internal/deadcode
bootstrap/cmd/compile/internal/typecheck
bootstrap/cmd/compile/internal/objw
bootstrap/cmd/compile/internal/staticdata
bootstrap/cmd/compile/internal/compare
bootstrap/cmd/compile/internal/pgo
bootstrap/cmd/compile/internal/coverage
bootstrap/cmd/compile/internal/loopvar
bootstrap/cmd/compile/internal/importer
bootstrap/cmd/compile/internal/escape
bootstrap/cmd/compile/internal/inline
bootstrap/cmd/compile/internal/reflectdata
bootstrap/cmd/compile/internal/devirtualize
bootstrap/cmd/compile/internal/staticinit
bootstrap/cmd/compile/internal/ssa
bootstrap/cmd/link/internal/amd64
bootstrap/cmd/link/internal/loong64
bootstrap/cmd/link/internal/arm
bootstrap/cmd/link/internal/mips
bootstrap/cmd/link/internal/mips64
bootstrap/cmd/link/internal/arm64
bootstrap/cmd/link/internal/ppc64
bootstrap/cmd/link/internal/riscv64
bootstrap/cmd/link/internal/s390x
bootstrap/cmd/link/internal/wasm
bootstrap/cmd/link/internal/x86
bootstrap/cmd/link
bootstrap/cmd/compile/internal/liveness
bootstrap/cmd/compile/internal/ssagen
bootstrap/cmd/compile/internal/amd64
bootstrap/cmd/compile/internal/arm
bootstrap/cmd/compile/internal/arm64
bootstrap/cmd/compile/internal/dwarfgen
bootstrap/cmd/compile/internal/loong64
bootstrap/cmd/compile/internal/mips
bootstrap/cmd/compile/internal/mips64
bootstrap/cmd/compile/internal/wasm
bootstrap/cmd/compile/internal/s390x
bootstrap/cmd/compile/internal/riscv64
bootstrap/cmd/compile/internal/ppc64
bootstrap/cmd/compile/internal/walk
bootstrap/cmd/compile/internal/x86
bootstrap/cmd/compile/internal/noder
bootstrap/cmd/compile/internal/pkginit
bootstrap/cmd/compile/internal/gc
bootstrap/cmd/compile

Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
runtime
go tool dist: /home/landerx/goroot/src/runtime/proc.go imports C

Tried the cgo_enabled=1 flag, doesn't seem to make any difference.

Tried just running make.bash, it didn't seem to make any difference.

I was wondering if it was a dependency issue, but I didn't see any messages related to the fake package cgo, nor did I see any errors with my vscode.

Solution

Okay... Finally, let me answer this question.

Why doesn’t it work

After quite some in-depth investigation, I found that it seems that Go (tools dist) does not allow source files in most go internals (Link)

Solution

There are still some workarounds to achieve this effect, namely using m5ops in go.

1. Pass function pointer through global variable

You can define global function pointers in proc.go and import cgo in your go application and assign these global function pointers to your functions that perform m5ops. Does not support calling C function pointers, so it needs to be wrapped with golang functions.

2. Go to assembly

Go uses a lot of Go Asm in its internal source files to handle stack switching etc.

On the other hand, m5ops will eventually be inlined as a single directive.

So following Go Asm's syntax and function bindings, which happens in asm_amd64.s and stubs.go a>, one can write an asm function that contains the m5ops directive, and then # Call it anywhere in the ##runtime. go should be good.

other information

    It seems that in
  • runtime.go when it switches to the system stack it can no longer execute functions outside of the file (or package?), so if you try to insert these function calls, method 1 Writing code that will run on the system stack does not work. So I finally discovered the second method.

The above is the detailed content of Modify go to use Gem5 m5ops: go tool dist displays import message and then exits. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:stackoverflow. If there is any infringement, please contact admin@php.cn delete
go语言有没有缩进go语言有没有缩进Dec 01, 2022 pm 06:54 PM

go语言有缩进。在go语言中,缩进直接使用gofmt工具格式化即可(gofmt使用tab进行缩进);gofmt工具会以标准样式的缩进和垂直对齐方式对源代码进行格式化,甚至必要情况下注释也会重新格式化。

go语言为什么叫gogo语言为什么叫goNov 28, 2022 pm 06:19 PM

go语言叫go的原因:想表达这门语言的运行速度、开发速度、学习速度(develop)都像gopher一样快。gopher是一种生活在加拿大的小动物,go的吉祥物就是这个小动物,它的中文名叫做囊地鼠,它们最大的特点就是挖洞速度特别快,当然可能不止是挖洞啦。

一文详解Go中的并发【20 张动图演示】一文详解Go中的并发【20 张动图演示】Sep 08, 2022 am 10:48 AM

Go语言中各种并发模式看起来是怎样的?下面本篇文章就通过20 张动图为你演示 Go 并发,希望对大家有所帮助!

tidb是go语言么tidb是go语言么Dec 02, 2022 pm 06:24 PM

是,TiDB采用go语言编写。TiDB是一个分布式NewSQL数据库;它支持水平弹性扩展、ACID事务、标准SQL、MySQL语法和MySQL协议,具有数据强一致的高可用特性。TiDB架构中的PD储存了集群的元信息,如key在哪个TiKV节点;PD还负责集群的负载均衡以及数据分片等。PD通过内嵌etcd来支持数据分布和容错;PD采用go语言编写。

go语言能不能编译go语言能不能编译Dec 09, 2022 pm 06:20 PM

go语言能编译。Go语言是编译型的静态语言,是一门需要编译才能运行的编程语言。对Go语言程序进行编译的命令有两种:1、“go build”命令,可以将Go语言程序代码编译成二进制的可执行文件,但该二进制文件需要手动运行;2、“go run”命令,会在编译后直接运行Go语言程序,编译过程中会产生一个临时文件,但不会生成可执行文件。

【整理分享】一些GO面试题(附答案解析)【整理分享】一些GO面试题(附答案解析)Oct 25, 2022 am 10:45 AM

本篇文章给大家整理分享一些GO面试题集锦快答,希望对大家有所帮助!

go语言是否需要编译go语言是否需要编译Dec 01, 2022 pm 07:06 PM

go语言需要编译。Go语言是编译型的静态语言,是一门需要编译才能运行的编程语言,也就说Go语言程序在运行之前需要通过编译器生成二进制机器码(二进制的可执行文件),随后二进制文件才能在目标机器上运行。

go语言怎么删除字符串字符go语言怎么删除字符串字符Dec 09, 2022 pm 07:19 PM

删除字符串的方法:1、用TrimSpace()来去除字符串空格;2、用Trim()、TrimLeft()、TrimRight()、TrimPrefix()或TrimSuffix()来去除字符串中全部、左边或右边指定字符串;3、用TrimFunc()、TrimLeftFunc()或TrimRightFunc()来去除全部、左边或右边指定规则字符串。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),