目錄
問題內容
解決方法
為什麼不起作用
解決辦法
1。透過全域變數傳遞函數指標
2。去彙編
其他資訊
首頁 後端開發 Golang 修改go以使用Gem5 m5ops:go tool dist顯示導入訊息然後退出

修改go以使用Gem5 m5ops:go tool dist顯示導入訊息然後退出

Feb 13, 2024 pm 07:50 PM
go語言 模擬器

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

php小編蘋果在這裡為大家介紹一個關於修改Go語言以使用Gem5 m5ops的方法。 Gem5是一個廣泛使用的模擬器,而m5ops是Gem5中的一組作業系統介面。透過修改Go語言,我們可以使用Gem5的m5ops介面來進行效能分析和除錯。具體的步驟是,在Go的工具鏈中加入對m5ops的支持,然後使用m5ops提供的函數進行效能監測和除錯操作。透過這種方式,我們可以更了解Go語言在模擬環境中的運作情況,並進行相應的最佳化和偵錯工作。

問題內容

我對 golang 還很陌生。

我正在嘗試將一些 c 函數呼叫(特別是 m5ops)插入到 golang 的執行時間(特別是 src/proc.go)。

我嘗試使用 cgo,這導致將此導入添加到 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"
登入後複製

但是當我嘗試使用 ./all.bash 重建時,腳本輸出然後退出:

./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
登入後複製

上述輸出的更詳細版本:

./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
登入後複製

嘗試了 cgo_enabled=1 標誌,似乎沒有任何區別。

嘗試只運行 make.bash,似乎沒有任何區別。

我想知道是否是依賴問題,但沒有看到任何與偽包 cgo 相關的訊息,也沒有看到我的 vscode 出現任何錯誤。

解決方法

好吧...最後,讓我來回答這個問題。

為什麼不起作用

經過相當深入的調查,我發現似乎Go(工具dist)不允許在大多數go內部原始檔(連結)

解決辦法

仍然有一些解決方法可以實現該效果,即在 go 中使用 m5ops

1。透過全域變數傳遞函數指標

你可以在proc.go中定義全域函數指針,並在你的go應用程式中導入cgo,並將這些全域函數指針指派給你執行m5ops的函數。 不支援呼叫C函數指標,所以需要用golang函數包裝它。

2。去彙編

Go 在其內部原始檔案中使用了大量 Go Asm,以處理堆疊切換等。

另一方面,m5ops 最終將作為單一偽指令內聯。

因此遵循Go Asm 的語法和函數綁定,這發生在asm_amd64.sstubs.go a>,可以寫一個包含m5ops指令的asm函數,然後在runtime的任何地方都呼叫它。 go應該不錯。

其他資訊

  • 似乎在runtime.go中,當它切換到系統堆疊時,它無法再執行檔案(或套件?)之外的函數,因此如果您嘗試插入這些函數調用,方法1將不起作用寫入將在系統堆疊上運行的程式碼。所以我終於發現了第二種方法。

以上是修改go以使用Gem5 m5ops:go tool dist顯示導入訊息然後退出的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Go語言中用於浮點數運算的庫有哪些? Go語言中用於浮點數運算的庫有哪些? Apr 02, 2025 pm 02:06 PM

Go語言中用於浮點數運算的庫介紹在Go語言(也稱為Golang)中,進行浮點數的加減乘除運算時,如何確保精度是�...

Go的爬蟲Colly中Queue線程的問題是什麼? Go的爬蟲Colly中Queue線程的問題是什麼? Apr 02, 2025 pm 02:09 PM

Go爬蟲Colly中的Queue線程問題探討在使用Go語言的Colly爬蟲庫時,開發者常常會遇到關於線程和請求隊列的問題。 �...

在 Go 語言中,為什麼使用 Println 和 string() 函數打印字符串會出現不同的效果? 在 Go 語言中,為什麼使用 Println 和 string() 函數打印字符串會出現不同的效果? Apr 02, 2025 pm 02:03 PM

Go語言中字符串打印的區別:使用Println與string()函數的效果差異在Go...

在Go語言中使用Redis Stream實現消息隊列時,如何解決user_id類型轉換問題? 在Go語言中使用Redis Stream實現消息隊列時,如何解決user_id類型轉換問題? Apr 02, 2025 pm 04:54 PM

Go語言中使用RedisStream實現消息隊列時類型轉換問題在使用Go語言與Redis...

GoLand中自定義結構體標籤不顯示怎麼辦? GoLand中自定義結構體標籤不顯示怎麼辦? Apr 02, 2025 pm 05:09 PM

GoLand中自定義結構體標籤不顯示怎麼辦?在使用GoLand進行Go語言開發時,很多開發者會遇到自定義結構體標籤在�...

Go語言中`var`和`type`關鍵字定義結構體的區別是什麼? Go語言中`var`和`type`關鍵字定義結構體的區別是什麼? Apr 02, 2025 pm 12:57 PM

Go語言中結構體定義的兩種方式:var與type關鍵字的差異Go語言在定義結構體時,經常會看到兩種不同的寫法:一�...

Go語言中哪些庫是由大公司開發或知名的開源項目提供的? Go語言中哪些庫是由大公司開發或知名的開源項目提供的? Apr 02, 2025 pm 04:12 PM

Go語言中哪些庫是大公司開發或知名開源項目?在使用Go語言進行編程時,開發者常常會遇到一些常見的需求,�...

在Go編程中,如何正確管理Mysql和Redis的連接與釋放資源? 在Go編程中,如何正確管理Mysql和Redis的連接與釋放資源? Apr 02, 2025 pm 05:03 PM

Go編程中的資源管理:Mysql和Redis的連接與釋放在學習Go編程過程中,如何正確管理資源,特別是與數據庫和緩存�...

See all articles