當(dāng)我嘗試運行帶有內(nèi)存完整性檢查的 go 單元測試系統(tǒng)時,我收到一條錯誤消息,我確信我可以通過將編譯器設(shè)置為 CLANG 來解決該錯誤消息。Go 命令文檔對此事做了一些簡短的介紹。-msan enable interoperation with memory sanitizer. Supported only on linux/amd64, linux/arm64 and only with Clang/LLVM as the host C compiler. On linux/arm64, pie build mode will be used.在過去,我使用我通過調(diào)用來實現(xiàn)它:CC=clang go test -msan ./..但是,當(dāng)我現(xiàn)在這樣做時,會出現(xiàn)以下錯誤:g++: error: unrecognized argument to -fsanitize= option: ‘memory’為了在 Ubuntu 18:04 下使用 memory sanitizer 運行我的 golang 測試,我需要做什么?我目前正在使用以下版本的工具:$ go versiongo version go1.14 linux/amd64$ clang --versionclang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)Target: x86_64-pc-linux-gnuThread model: posixInstalledDir: /usr/bin
1 回答

幕布斯7119047
TA貢獻(xiàn)1794條經(jīng)驗 獲得超8個贊
它需要一個支持-fsanitize=memory在程序運行的Ubuntu 18.04版本上的 LLVM 版本。請嘗試更新,然后重試。
另請注意,在Linux上,您至少需要LLVM 3.8才能獲得-fsanitize標(biāo)志。
Go工具會根據(jù)clang 的要求自動將 -fsanitize=memory 選項添加到CGO_CPPFLAGS標(biāo)志以進(jìn)行鏈接,這就是導(dǎo)致您出錯的地方。
此外,請確保添加CC和CXX(對于clang++)標(biāo)志,以便在您與C/C++互操作程序時使用Clang啟用編譯,即,
CC=clang CXX=clang++ go build -msan
也請參考此鏈接:
https://go.googlesource.com/go/+/go1.7/misc/cgo/testsanitizers/test.bash(bash腳本)
(或者)
https://github.com/golang/go/tree/master/misc/cgo/testsanitizers(*.go文件)
它將幫助您測試消毒劑是否適用于您的設(shè)置。
- 1 回答
- 0 關(guān)注
- 313 瀏覽
添加回答
舉報
0/150
提交
取消