首页 > 其他分享 >go tool compile 报错 could not import sync (file not found)

go tool compile 报错 could not import sync (file not found)

时间:2024-05-31 12:16:01浏览次数:11  
标签:src github zly tool sync race 报错 go com

前言

Go 版本 :

$ go version
go version go1.21.4 darwin/amd64

我想对 go 文件进行反汇编,然后就报错了:

$ go tool compile -S race.go
race.go:3:8: could not import sync (file not found)

我就惊讶了一下,标准库怎么还能找不到呢?难道是我 GOROOT 配置错了?

发现了问题原因

原来是因为 Go 团队认为 Go 安装包越来越大,就从 1.20 开始发行的安装包不再为 GOROOT 中的软件包提供预编译的.a 文件了。

Go 1.20版本中,GOROOT 下的源码将像其他用户包那样在构建后被缓存到本机 cache 中。此外,go install 也不会为 GOROOT 下的软件包安装 .a 文件。

https://github.com/golang/go/issues/47257

如何解决?

可以自行安装标准库的包

export GODEBUG=installgoroot=all 
go install -v std

执行上述命令后,可以在 $GOROOT/pkg 目录下查看到对应操作系统的目录中包含了标准库的.a 文件

$ ls $GOROOT/pkg
darwin_amd64 include      tool

$ ls darwin_amd64
archive    context.a  embed.a    flag.a     html       internal   math       net.a      plugin.a   runtime    sync       text       vendor
bufio.a    crypto     encoding   fmt.a      html.a     io         math.a     os         reflect    runtime.a  sync.a     time
bytes.a    crypto.a   encoding.a go         image      io.a       mime       os.a       reflect.a  sort.a     syscall.a  time.a
compress   database   errors.a   hash       image.a    log        mime.a     path       regexp     strconv.a  testing    unicode
container  debug      expvar.a   hash.a     index      log.a      net        path.a     regexp.a   strings.a  testing.a  unicode.a

参考内容

可以看下下面两个链接的内容。或者在命令行中看看 go help install 命令的内容


$ go help install
usage: go install [build flags] [packages]

Install compiles and installs the packages named by the import paths.

....

Before Go 1.20, the standard library was installed to
$GOROOT/pkg/$GOOS_$GOARCH.
Starting in Go 1.20, the standard library is built and cached but not installed.
Setting GODEBUG=installgoroot=all restores the use of
$GOROOT/pkg/$GOOS_$GOARCH.

https://stackoverflow.com/questions/77826479/how-do-i-precompile-the-golang-standard-library#:~:text=The standard library is not precompiled by default%2C,the default behavior. Check https%3A%2F%2Fgithub.com%2Fgolang%2Fgo%2Fissues%2F65204 for more details.

https://github.com/golang/go/issues/65204

验证结果

go tool compile -S race.go
<unlinkable>.Race STEXT size=202 args=0x0 locals=0x30 funcid=0x0 align=0x0
	0x0000 00000 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	TEXT	<unlinkable>.Race(SB), ABIInternal, $48-0
	0x0000 00000 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	CMPQ	SP, 16(R14)
	0x0004 00004 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	PCDATA	$0, $-2
	0x0004 00004 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	JLS	189
	0x000a 00010 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	PCDATA	$0, $-1
	0x000a 00010 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	PUSHQ	BP
	0x000b 00011 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	MOVQ	SP, BP
	0x000e 00014 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	SUBQ	$40, SP
	0x0012 00018 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	FUNCDATA	$0, gclocals·ykHN0vawYuq1dUW4zEe2gA==(SB)
	0x0012 00018 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/race.go:5)	FUNCDATA	$1, gclocals·sQxO+jiYy+d9ldxoWSePwQ==(SB)
	0x0012 00018 (/Users/zly/workspace/go/src/github.com/xiaowuzai/go-example/mrace/rac

可以了

标签:src,github,zly,tool,sync,race,报错,go,com
From: https://www.cnblogs.com/LanceZh/p/18224221

相关文章

  • Rsync数据同步
    目标端配置:一、安装yum-yinstallrsync二、配置文件vi/etc/rsyncd.conf用户iduid=rsync组idgid=rsync程序安全设置usechroot=no客户端连接数maxconnections=200进程号文件位置pidfile=/var/run/rsyncd.pid进程锁文件位置lockfile=/var/run/rsy......
  • 安装并运行pytorch报错“核心已转储”
    1问题和解决概要主机环境:Ubuntu20.04,RTX3090,GPUDriverVersion525.89.02问题:用anaconda创建虚拟环境python3.10,安装pytorch2.2.2-cu118和对应torchvision后,训练模型出现报错:“核心已转储”。定位和解决:查阅资料,确认driver支持cuda-11.8,主机安装cuda-11.8后编译一个sample......
  • SwiftUI中AsyncImage的使用(一个高效的异步下载图片组件)
    iOS开发者经常会遇到需要在应用中显示网络图像的场景,无论是获取和显示用户头像,展示产品图像,等等。在原来的UIKit中,如果我们要用系统的API还是稍微有点麻烦,很多开发的朋友都选择了第三方的框架去处理网络图片的请求缓存等等。AsyncImage是SwiftUI中一个强大的功能,它简化了在......
  • com.omarea.vtools/files/up.sh
    scene="com.omarea.vtools"daemon="scene-daemon"current_dir=$(dirname$0)origin_path="$current_dir/$daemon"if[[!-e"$origin_path"]];then echo$origin_path echo"Scene'sdaemonnotfound!" exit......
  • 新版Python安装,新手入门必看,报错分析
    第一次接触Python的朋友,可能会在安装的过程中遇到很多问题,下面会详细的指出可能出现的各种状况、以及应对方法,让新入行的朋友也可上手安装,并且完成第一个Helloworld代码。【Python安装】一、打开python官网点击下载搜索并打开官网进入页面后点击导航中的Downloads进入下载......
  • SQL Server报错:数据库"YourDatabaseName"的事务日志已满,原因为"LOG_BACKUP"
      通过以下代码可以收缩日志,执行完后就不报错了。--设置简单模式USE[master]GOALTERDATABASEYourDatabaseNameSETRECOVERYSIMPLEWITHNO_WAITGOALTERDATABASEYourDatabaseNameSETRECOVERYSIMPLEGO--设置压缩后的日志大小为2M,可自定义USEY......
  • RSAUtils 非对称加密hutool
    1、使用hutool的rsa加解密工具,自定义公钥私钥字符串2、importcn.hutool.core.codec.Base64Decoder;importcn.hutool.crypto.asymmetric.KeyType;importcn.hutool.crypto.asymmetric.RSA;importlombok.extern.slf4j.Slf4j;importorg.jeecg.common.util.CN;importjav......
  • async/await处理异步操作
    在JavaScript中,async/await是用于处理异步操作的一种语法糖,它允许我们以同步的方式编写异步代码,从而使代码更加清晰和易于理解。当使用await关键字等待一个Promise对象时,有时候我们需要捕获可能出现的异常并进行处理。以下是关于await异常捕获的介绍:asyncfunctionfetchData()......
  • 【Spring Security】Error:A granted authority textual representation is required
     Security出错了! 分析:Debug跑后 排查是Security中的UserDetails.getAuthorities()在创建SimpleGrantedAuthorityauthority时,所传递的授权信息是空的,导致SimpleGrantedAuthorityauthority出现异常;报出Agrantedauthoritytextualrepresentationisreq......
  • 关于Interrupted system call 报错
    Socket编程或者其他的一些慢速系统调用中,我们经常会碰到“interruptedsystemcall”的问题。这些系统调用包括:长时间读取磁盘,等待网络连接i.e.Accept,阻塞的系统调用,i.e.Read/Writeepoll_wait/kevent这是因为系统调用在执行过程中有可能收到来自外部的信号中断,那么该系......