Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: unexpected files left in tmpdir: [dsymutil-f087bc] #59026

Closed
578559967 opened this issue Mar 14, 2023 · 24 comments
Closed

cmd/go: unexpected files left in tmpdir: [dsymutil-f087bc] #59026

578559967 opened this issue Mar 14, 2023 · 24 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@578559967
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.19.7 darwin/arm64

$ /opt/homebrew/opt/llvm/bin/clang --version
Homebrew clang version 15.0.7
Target: arm64-apple-darwin22.3.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/r/Library/Caches/go-build"
GOENV="/Users/r/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/r/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/r/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/Users/r/workspace/testgo/go1.19.7/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/r/workspace/testgo/go1.19.7/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.7"
GCCGO="gccgo"
AR="ar"
CC="/opt/homebrew/opt/llvm/bin/clang"
CXX="/opt/homebrew/opt/llvm/bin/clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/go-build4228174272=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.19.7 darwin/arm64
GOROOT/bin/go tool compile -V: compile version go1.19.7
uname -v: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000
ProductName:		macOS
ProductVersion:		13.2.1
BuildVersion:		22D68
lldb --version: lldb-1400.0.38.17
Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)

What did you do?

Install clang with brew install llvm.
Then build go with CC=/opt/homebrew/opt/llvm/bin/clang CXX=/opt/homebrew/opt/llvm/bin/clang++ ./all.bash under src.

What did you expect to see?

build pass

What did you see instead?

Building Go cmd/dist using /Users/robert/workspace/catdb-go. (go1.19.7.1 darwin/arm64)
Building Go toolchain1 using /Users/robert/workspace/catdb-go.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for darwin/arm64.

##### Test execution environment.
# GOARCH: arm64
# CPU:
# GOOS: darwin
# OS Version: Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64

##### Testing packages.
ok      archive/tar     4.193s
ok      archive/zip     2.958s
ok      bufio   0.591s
ok      bytes   2.737s
ok      compress/bzip2  0.354s
ok      compress/flate  2.546s
ok      compress/gzip   6.626s
ok      compress/lzw    1.091s
ok      compress/zlib   3.201s
ok      container/heap  1.373s
ok      container/list  1.626s
ok      container/ring  2.140s
ok      context 4.763s
ok      crypto  0.842s
ok      crypto/aes      1.897s
ok      crypto/cipher   3.654s
ok      crypto/des      3.887s
ok      crypto/dsa      3.414s
ok      crypto/ecdsa    4.340s
ok      crypto/ed25519  4.006s
ok      crypto/elliptic 4.576s
ok      crypto/hmac     4.969s
ok      crypto/internal/boring  5.081s
ok      crypto/internal/boring/bcache   5.341s
ok      crypto/internal/edwards25519    7.070s
ok      crypto/internal/edwards25519/field      7.190s
ok      crypto/internal/nistec  5.448s
ok      crypto/internal/nistec/fiat     5.300s [no tests to run]
ok      crypto/internal/subtle  5.161s
ok      crypto/md5      5.181s
ok      crypto/rand     5.244s
ok      crypto/rc4      5.307s
ok      crypto/rsa      5.070s
ok      crypto/sha1     5.183s
ok      crypto/sha256   5.144s
ok      crypto/sha512   5.247s
ok      crypto/subtle   5.009s
ok      crypto/tls      5.109s
ok      crypto/x509     4.531s
ok      database/sql    4.718s
ok      database/sql/driver     4.657s
ok      debug/buildinfo 4.839s
ok      debug/dwarf     4.564s
ok      debug/elf       4.350s
ok      debug/gosym     4.112s
ok      debug/macho     4.517s
ok      debug/pe        4.581s
ok      debug/plan9obj  4.678s
ok      embed   4.627s [no tests to run]
ok      embed/internal/embedtest        4.840s
ok      encoding/ascii85        5.014s
ok      encoding/asn1   4.925s
ok      encoding/base32 5.154s
ok      encoding/base64 5.058s
ok      encoding/binary 4.916s
ok      encoding/csv    5.095s
ok      encoding/gob    4.955s
ok      encoding/hex    5.152s
ok      encoding/json   5.001s
ok      encoding/pem    4.954s
ok      encoding/xml    5.215s
ok      errors  5.093s
ok      expvar  5.257s
ok      flag    5.140s
ok      fmt     4.702s
ok      go/ast  4.670s
ok      go/build        5.516s
ok      go/build/constraint     5.079s
ok      go/constant     5.276s
ok      go/doc  5.088s
ok      go/doc/comment  5.506s
ok      go/format       5.325s
ok      go/importer     5.184s
ok      go/internal/gccgoimporter       5.257s
ok      go/internal/gcimporter  9.432s
ok      go/internal/srcimporter 7.480s
ok      go/parser       5.204s
ok      go/printer      5.234s
ok      go/scanner      4.747s
ok      go/token        4.868s
ok      go/types        6.433s
ok      hash    5.027s
ok      hash/adler32    4.891s
ok      hash/crc32      5.179s
ok      hash/crc64      5.340s
ok      hash/fnv        5.575s
ok      hash/maphash    5.336s
ok      html    5.290s
ok      html/template   5.233s
ok      image   5.093s
ok      image/color     5.249s
ok      image/draw      5.383s
ok      image/gif       12.434s
ok      image/jpeg      6.648s
ok      image/png       4.817s
ok      index/suffixarray       4.860s
ok      internal/abi    3.839s
ok      internal/buildcfg       3.834s
ok      internal/cpu    3.326s
ok      internal/diff   3.624s
ok      internal/fmtsort        4.462s
ok      internal/fuzz   3.988s
ok      internal/godebug        4.219s
ok      internal/intern 3.526s
ok      internal/itoa   3.764s
ok      internal/poll   4.768s
ok      internal/profile        4.032s
ok      internal/reflectlite    4.278s
ok      internal/safefilepath   3.693s
ok      internal/singleflight   3.938s
ok      internal/trace  4.529s
ok      internal/unsafeheader   4.040s
ok      internal/xcoff  4.638s
ok      io      4.090s
ok      io/fs   4.027s
ok      io/ioutil       4.328s
ok      log     4.567s
ok      log/syslog      5.955s
ok      math    4.071s
ok      math/big        4.177s
ok      math/bits       4.190s
ok      math/cmplx      3.873s
ok      math/rand       4.484s
ok      mime    4.069s
ok      mime/multipart  5.091s
ok      mime/quotedprintable    4.963s
ok      net     6.306s
ok      net/http        9.438s
ok      net/http/cgi    4.585s
ok      net/http/cookiejar      4.255s
ok      net/http/fcgi   4.305s
ok      net/http/httptest       4.422s
ok      net/http/httptrace      4.820s
ok      net/http/httputil       4.949s
ok      net/http/internal       4.616s
ok      net/http/internal/ascii 5.040s
ok      net/http/pprof  8.722s
ok      net/internal/socktest   4.956s
ok      net/mail        4.777s
ok      net/netip       5.013s
ok      net/rpc 4.654s
ok      net/rpc/jsonrpc 4.795s
ok      net/smtp        4.922s
ok      net/textproto   4.972s
ok      net/url 4.884s
ok      os      8.531s
ok      os/exec 9.822s
ok      os/exec/internal/fdtest 4.519s
ok      os/signal       5.950s
ok      os/user 4.312s
ok      path    4.684s
ok      path/filepath   4.170s
ok      plugin  4.298s
ok      reflect 4.334s
ok      regexp  4.018s
ok      regexp/syntax   4.415s
ok      runtime 55.950s
ok      runtime/cgo     3.884s
ok      runtime/debug   3.592s
ok      runtime/internal/atomic 3.584s
ok      runtime/internal/math   4.103s
ok      runtime/internal/sys    4.346s
ok      runtime/metrics 4.596s
ok      runtime/pprof   17.286s
ok      runtime/trace   5.363s
ok      sort    3.936s
ok      strconv 3.872s
ok      strings 3.592s
ok      sync    4.254s
ok      sync/atomic     4.405s
ok      syscall 4.762s
ok      testing 4.345s
ok      testing/fstest  3.743s
ok      testing/iotest  3.759s
ok      testing/quick   4.106s
ok      text/scanner    4.300s
ok      text/tabwriter  4.457s
ok      text/template   4.775s
ok      text/template/parse     4.513s
ok      time    6.690s
ok      unicode 3.998s
ok      unicode/utf16   4.261s
ok      unicode/utf8    4.554s
ok      cmd/addr2line   9.236s
ok      cmd/api 9.043s
ok      cmd/asm/internal/asm    4.435s
ok      cmd/asm/internal/lex    4.527s
ok      cmd/compile/internal/abt        4.640s
ok      cmd/compile/internal/amd64      4.597s
ok      cmd/compile/internal/dwarfgen   4.924s
ok      cmd/compile/internal/importer   4.062s
ok      cmd/compile/internal/ir 4.401s
ok      cmd/compile/internal/logopt     4.237s
ok      cmd/compile/internal/noder      4.831s
ok      cmd/compile/internal/reflectdata        4.601s [no tests to run]
ok      cmd/compile/internal/ssa        9.325s
ok      cmd/compile/internal/syntax     4.863s
ok      cmd/compile/internal/test       21.495s
ok      cmd/compile/internal/typecheck  9.284s
ok      cmd/compile/internal/types      4.107s
ok      cmd/compile/internal/types2     4.377s
ok      cmd/cover       20.418s
ok      cmd/dist        3.914s
ok      cmd/doc 4.002s
ok      cmd/fix 4.857s
go test proxy running at GOPROXY=http://127.0.0.1:53820/mod
PASS
2023/03/14 17:57:18 unexpected files left in tmpdir: [dsymutil-579a25]
FAIL    cmd/go  55.017s
ok      cmd/go/internal/auth    3.753s
ok      cmd/go/internal/cache   5.255s
ok      cmd/go/internal/fsys    4.843s
ok      cmd/go/internal/generate        4.666s
ok      cmd/go/internal/get     4.737s
ok      cmd/go/internal/imports 4.809s
ok      cmd/go/internal/load    4.401s
ok      cmd/go/internal/lockedfile      4.661s
ok      cmd/go/internal/lockedfile/internal/filelock    4.846s
ok      cmd/go/internal/modconv 5.273s
ok      cmd/go/internal/modfetch        4.910s
ok      cmd/go/internal/modfetch/codehost       4.706s
ok      cmd/go/internal/modfetch/zip_sum_test   4.803s
ok      cmd/go/internal/modindex        5.085s
ok      cmd/go/internal/modload 4.966s
ok      cmd/go/internal/mvs     5.460s
ok      cmd/go/internal/par     5.225s
ok      cmd/go/internal/search  7.524s
ok      cmd/go/internal/str     8.214s
ok      cmd/go/internal/test    8.955s
ok      cmd/go/internal/vcs     9.391s
ok      cmd/go/internal/web     9.434s
ok      cmd/go/internal/work    9.780s
ok      cmd/gofmt       9.542s
ok      cmd/internal/archive    22.327s
ok      cmd/internal/buildid    10.866s
ok      cmd/internal/dwarf      10.819s
ok      cmd/internal/edit       10.874s
ok      cmd/internal/goobj      10.738s
ok      cmd/internal/moddeps    11.653s
ok      cmd/internal/notsha256  10.947s
ok      cmd/internal/obj        10.902s
ok      cmd/internal/obj/arm64  10.283s
ok      cmd/internal/obj/ppc64  9.832s
ok      cmd/internal/obj/riscv  9.595s
ok      cmd/internal/obj/s390x  9.188s
ok      cmd/internal/obj/x86    19.340s
ok      cmd/internal/objabi     8.707s
ok      cmd/internal/pkgpath    8.770s
ok      cmd/internal/quoted     9.015s
ok      cmd/internal/src        9.091s
ok      cmd/internal/sys        8.924s
ok      cmd/internal/test2json  9.258s
ok      cmd/link        26.602s
ok      cmd/link/internal/benchmark     9.016s
ok      cmd/link/internal/ld    22.978s
ok      cmd/link/internal/loader        8.907s
ok      cmd/nm  19.877s
ok      cmd/objdump     18.330s
ok      cmd/pack        27.134s
ok      cmd/pprof       10.160s
ok      cmd/trace       9.561s
ok      cmd/vet 21.569s
FAIL
go tool dist: Failed: exit status 1
@cherrymui
Copy link
Member

cherrymui commented Mar 14, 2023

Is this error reproducible or it happens only once? Also, does it reproduce if you use the system C compiler (/usr/bin/cc or the one from Xcode)? Thanks.

Maybe the dsymutil command (that we run on macOS to combine DWARF) creates temporary files but not (always) clean up?

cc @bcmills @thanm

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 14, 2023
@cherrymui cherrymui added this to the Backlog milestone Mar 14, 2023
@578559967
Copy link
Author

578559967 commented Mar 15, 2023

Is this error reproducible or it happens only once?

It is reproducible.

Also, does it reproduce if you use the system C compiler (/usr/bin/cc or the one from Xcode)? Thanks.

It reproduces with the system C compiler if the compiler version is clang-14.0.3.

% which clang
clang --version
/usr/bin/clang
Apple clang version 14.0.3 (clang-1403.0.22.12)
Target: x86_64-apple-darwin22.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

But if the system C compiler version is clang-14.0.0, it does not reproduce.

@thanm
Copy link
Contributor

thanm commented Mar 15, 2023

I looked over the LLVM source code for dsymutil. Looks to me as though it only creates temp files when it is generating a "universal" binary (which I don't think would apply here). It also uses a template of the form "dsym.tmp%%%%%.dwarf", which doesn't look like what you are we're encountering here.

Is there any chance we could narrow down the test a bit? Perhaps figure out which testpoint within the cmd/go tests is causing the bad behavior?

@bcmills
Copy link
Contributor

bcmills commented Mar 15, 2023

if the system C compiler version is clang-14.0.0, it does not reproduce

Can you bisect the clang changes between 14.0.0 and 14.0.3 to pin it down? At the moment I'm inclined to suspect a Clang bug, but it would be helpful to know exactly what introduced this behavior.

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. GoCommand cmd/go labels Mar 15, 2023
@cherrymui
Copy link
Member

Do you know if the leftover temporary file is from a compiling action or a linking action? If it is for linking, the Go linker probably could invoke clang (and dsymutil) in the linker's temporary directory, then the Go linker will delete the directory, including whatever leftover file by the C linker, at exit.

@578559967
Copy link
Author

Is there any chance we could narrow down the test a bit? Perhaps figure out which testpoint within the cmd/go tests is causing the bad behavior?

I found the temp files under these cases' temp directory:

$ find /var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689/ -name 'dsymutil*'        [130](0s)[9:02:27]
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-cgo_syso_issue29253/tmp/dsymutil-648873
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-version_build_settings/tmp/dsymutil-40d5da
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-version_build_settings/tmp/dsymutil-cc1a4c
find: /var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-list_perm/gopath/src/noread: Permission denied
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-ldflag/tmp/dsymutil-bc39d8
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-toolexec/tmp/dsymutil-e55e4b
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-cgo_undef/tmp/dsymutil-e858d0
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-link_syso_issue33139/tmp/dsymutil-9fc3e9
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_trimpath_cgo/tmp/dsymutil-7f7c66
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_trimpath_cgo/tmp/dsymutil-18c773
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_trimpath_cgo/tmp/dsymutil-260210
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_trimpath_cgo/tmp/dsymutil-d6a027
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_overlay/tmp/dsymutil-c67e6f
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_overlay/tmp/dsymutil-5f2ea1
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_overlay/tmp/dsymutil-16864e
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_issue48319/tmp/dsymutil-166899
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_issue48319/tmp/dsymutil-904fbc
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_issue48319/tmp/dsymutil-558069
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_dash_x/tmp/dsymutil-1cb039
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-build_dash_x/tmp/dsymutil-f881f0
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-version/tmp/dsymutil-9f048c
find: /var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//tmpdir1964347547/script-mod_perm/gopath/src/_data: Permission denied
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//dsymutil-41a965
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//dsymutil-6fec50
/var/folders/j_/rq9ph2cd3h50w468sgv34lwh0000gn/T/cmd-go-test-4207447689//dsymutil-96fab2

@578559967
Copy link
Author

Do you know if the leftover temporary file is from a compiling action or a linking action? If it is for linking, the Go linker probably could invoke clang (and dsymutil) in the linker's temporary directory, then the Go linker will delete the directory, including whatever leftover file by the C linker, at exit.

It is from a linking action. Clang (or dsymutil) creates the temp file under $TMPDIR env variable, instead of the go linker's temporary directory.

@578559967
Copy link
Author

if the system C compiler version is clang-14.0.0, it does not reproduce

Can you bisect the clang changes between 14.0.0 and 14.0.3 to pin it down? At the moment I'm inclined to suspect a Clang bug, but it would be helpful to know exactly what introduced this behavior.

It's hard for me. The system C compiler of my mac is clang-14.0.0. And my friend's system C compiler is clang-14.0.3. I don't know how to install clang between these two versions.

@cherrymui
Copy link
Member

Would it be possible to reproduce with building a C program with clang 14.0.3? If so, we could conclude it is a bug in clang.

It is from a linking action. Clang (or dsymutil) creates the temp file under $TMPDIR env variable, instead of the go linker's temporary directory.

I'm curious what makes you conclude that it is from the linking?

The Go linker could potentially change the environment variable when invoking clang. Not sure if this is preferable.

@578559967
Copy link
Author

I'm curious what makes you conclude that it is from the linking?

The Go linker could potentially change the environment variable when invoking clang. Not sure if this is preferable.

I use the '-x' flag to get all build commands and execute one by one to see which command generate the temp file:

export TMPDIR=$PWD/tmp
export CC=/opt/homebrew/opt/llvm/bin/clang
go1.20.2 build -x ./test7.go > build.sh 2>&1

Now execute the command in build.sh one by one and check the $PWD/tmp dir.

@578559967
Copy link
Author

Would it be possible to reproduce with building a C program with clang 14.0.3? If so, we could conclude it is a bug in clang.

$ cat test.c
#include <stdio.h>

int main() {
  printf("hello\n");
}

$ mkdir tmp

$ TMPDIR=$PWD/tmp "/opt/homebrew/opt/llvm/bin/clang" test.c -o test.o -ggdb -c

$ ls tmp

$ TMPDIR=$PWD/tmp "/opt/homebrew/opt/llvm/bin/clang" test.o -o test -ggdb

$ ls tmp

$ TMPDIR=$PWD/tmp /opt/homebrew/opt/llvm/bin/dsymutil -f test -o test.k

$ ls tmp
dsymutil-5f58bc

@mojotx
Copy link

mojotx commented Apr 3, 2023

I am having the same problem. I am compiling Go 1.20.2 from source, but also using clang 14.0.3 on macOS Ventura 13.3.

I clone the Go repo, check out the branch, "release-branch-1.20," and then run this command:

CGO_ENABLED=1 GOROOT_FINAL=/usr/local/go GOROOT_BOOTSTRAP=/usr/local/opt/go/libexec /usr/local/go/src/all.bash -v

Here's the output of go env:

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mjarvis/Library/Caches/go-build"
GOENV="/Users/mjarvis/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mjarvis/go/pkg/mod"
GONOPROXY="github.com/mojotx"
GONOSUMDB="github.com/mojotx"
GOOS="darwin"
GOPATH="/Users/mjarvis/go"
GOPRIVATE="github.com/mojotx"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/usr/local/go/src/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/73/7zd4ytyd7s5cygnlbz8m63qh0000gn/T/go-build1275907450=/tmp/go-build -gno-record-gcc-switches -fno-common"
+./jarvis-build.sh:8> CGO_ENABLED=1 GOROOT_FINAL=/usr/local/go GOROOT_BOOTSTRAP=/usr/local/opt/go/libexec /usr/local/go/src/all.bash -v

The relevant part of the output is:

ok  	cmd/doc	2.757s
ok  	cmd/fix	8.684s
vcs-test.golang.org rerouted to http://127.0.0.1:62408
https://vcs-test.golang.org rerouted to https://127.0.0.1:62409
go test proxy running at GOPROXY=http://127.0.0.1:62410/mod
PASS
2023/04/03 11:32:28 unexpected files left in tmpdir: [dsymutil-8c2fce]
FAIL	cmd/go	88.908s
ok  	cmd/go/internal/auth	5.404s
ok  	cmd/go/internal/cache	1.994s
ok  	cmd/go/internal/fsys	5.189s

@cherrymui
Copy link
Member

@578559967 Thanks. So this is a bug in LLVM dsymutil. Maybe you want to report there?

@bcmills
Copy link
Contributor

bcmills commented Apr 3, 2023

If we can get more information on the nature of the dsymutil bug I'd be open to consider workarounds on the Go side, but since this looks like an LLVM bug I'd like someone to at least bisect (and ideally diagnose) the LLVM bug so that we can know exactly what it is we're working around.

@578559967
Copy link
Author

@578559967 Thanks. So this is a bug in LLVM dsymutil. Maybe you want to report there?

I report there and they fix it quickly. But it may take a long time for apple to upgrade clang. It's better to workaround on the Go side as @bcmills said.

@578559967
Copy link
Author

@keith gives a option of dsymutil to workaround: --reproducer Off. I have tried and it worked.
He says:

The default is that if dsymutil crashes it will produce a reproducer for filing a bug report. So with this option you will not get that.

@cherrymui
Copy link
Member

cherrymui commented Apr 4, 2023

Thanks. We could consider the --reproducer Off workaround. On the other hand, older version of dsymutil doesn't seem to understand this flag, which makes things more complex. Does --reproducer=Off work? My version of dsymutil emits a warning warning: ignoring unknown option: --reproducer=Off but doesn't fail. (It does fail with --reproducer Off as it only ignores --reproducer, not Off.)

@bcmills
Copy link
Contributor

bcmills commented Apr 4, 2023

IIUC, dsymutil creates the file in $TMPDIR. Maybe our invocation of dsymutil could explicitly set TMPDIR to match *flagTmpdir?

@keith
Copy link

keith commented Apr 4, 2023

Instead of passing the flag you can set DSYMUTIL_REPRODUCER_PATH to some other path that is ignored, that should work for new and old versions https://github.com/llvm/llvm-project/blob/1e2f87868f6fb64179b02c1076c6b3cd26576907/llvm/tools/dsymutil/Reproducer.cpp#L17

@cherrymui
Copy link
Member

Maybe our invocation of dsymutil could explicitly set TMPDIR to match *flagTmpdir

This is the workaround I initially thought about. DSYMUTIL_REPRODUCER_PATH is probably better? (Assuming we want to do a workaround.)

@bcmills
Copy link
Contributor

bcmills commented Apr 4, 2023

Either approach seems ok to me. Since the workaround seems tiny and low-risk, I think it's probably worth working around on the master branch so that contributors can successfully run all.bash with less need to manually upgrade or downgrade their clang.

@krader1961
Copy link

FWIW, I ran into this today while working on issue #59446. I exported DSYMUTIL_REPRODUCER_PATH=$HOME/tmp and building Go succeeded. So I'm happy with that as a workaround.

@fazalmajid
Copy link

DSYMUTIL_REPRODUCER_PATH=/dev/null also works, and does not depend on the existence of $HOME/tmp.

@gopherbot
Copy link

Change https://go.dev/cl/490818 mentions this issue: cmd/link: work around dsymutils not cleaning temp file

newacorn pushed a commit to newacorn/go that referenced this issue Aug 16, 2023
Some versions of dsymutils, notably the one in clang 14.0.3, which
is shipped in some versions of Xcode, have a bug that it creates a
temporary directory but doesn't clean it up at exit. The temporary
directory is created in DSYMUTIL_REPRODUCER_PATH (if set,
otherwise TMPDIR). Work around the issue by setting
DSYMUTIL_REPRODUCER_PATH to the linker's temporary directory, so
the linker will clean it up at exit anyway.

Fixes golang#59026.

Change-Id: Ie3e90a2d6a01f90040dc2eac91e8e536ccdda5a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/490818
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
daemon-p pushed a commit to daemon-p/go that referenced this issue Sep 14, 2023
Some versions of dsymutils, notably the one in clang 14.0.3, which
is shipped in some versions of Xcode, have a bug that it creates a
temporary directory but doesn't clean it up at exit. The temporary
directory is created in DSYMUTIL_REPRODUCER_PATH (if set,
otherwise TMPDIR). Work around the issue by setting
DSYMUTIL_REPRODUCER_PATH to the linker's temporary directory, so
the linker will clean it up at exit anyway.

Fixes golang#59026.

Change-Id: Ie3e90a2d6a01f90040dc2eac91e8e536ccdda5a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/490818
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

9 participants