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/link: the "section .debug_gdb_scripts" is not always "$GOROOT/src/runtime/runtime-gdb.py" as expected. #47881

Closed
zhouguangyuan0718 opened this issue Aug 22, 2021 · 3 comments

Comments

@zhouguangyuan0718
Copy link
Contributor

@zhouguangyuan0718 zhouguangyuan0718 commented Aug 22, 2021

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

$ go version
go version devel go1.18-6e50991d2a Sat Aug 21 18:23:58 2021 +0000 linux/amd64

Does this issue reproduce with the latest release?

YES. This issue reproduced with 1.17 and earlier.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/mnt/h/1.code/7.godev/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/mnt/h/1.code/7.godev/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-6e50991d2a Sat Aug 21 18:23:58 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/mnt/h/1.code/02.Project/godev/demo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build280056047=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. create a new file named "proc.go" located in a package named with "XXXruntime" (such as: "fakeruntime/proc.go");
  2. the "fakeruntime" package above imported in the project named "demo";
 ├── demo.go
 ├── env.sh
 ├── fakeruntime
 │   └── proc.go
 └── go.mod
  1. go build the "demo";
  2. execute "objdump -sj .debug_gdb_scripts demo" ;
  3. repeat step 3,4 several times (do not forget execute "go clean" first,or use go build -a).

demo/demo.go:

package main

import (
	"demo/fakeruntime"
	"fmt"
)

func main() {
	s := fakeruntime.FakeRuntimeStruct{A: 1}
	fmt.Println(s)
}

demo/fakeruntime/proc.go

package fakeruntime

type FakeRuntimeStruct struct {
	A int
}

What did you expect to see?

When executed "objdump -sj .debug_gdb_scripts demo". the contents of section .debug_gdb_scripts should be "$GOROOT/src/runtime/runtime-gdb.py".
like this:
image

What did you see instead?

Sometimes, the contents of section .debug_gdb_scripts is as follows:
image

Reason

in the linking procedure:
the final value of the variable “gdbscript” will not be unique any more, if the project contains another file named like "XXXruntime/proc.go".
The whole process is executed by different go-routines as follows:
the variable “gdbscript” was assigned in the function "writeDirFileTables" which is executed by different goroutines in parallel .
if another file whose name ended with "runtime/proc.go" (not "$GOROOT/src/runtime/proc.go") was found firstly, the final value of the variable “gdbscript” will not be "$GOROOT/src/runtime/runtime-gdb.py".

the code is as follows:

if i := strings.Index(name, "runtime/proc.go"); i >= 0 {

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 22, 2021

Change https://golang.org/cl/344229 mentions this issue: cmd/link: guarantee "section .debug_gdb_scripts" is always "$GOROOT/src/runtime/runtime-gdb.py".

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 22, 2021

Please don't send plain text as images. Please just use plain test. Images are much harder to read. Thanks.

Loading

@zhouguangyuan0718
Copy link
Contributor Author

@zhouguangyuan0718 zhouguangyuan0718 commented Aug 23, 2021

Please don't send plain text as images. Please just use plain test. Images are much harder to read. Thanks.

Sorry. I rewrote it in text format.

What did you expect to see?

When executed "objdump -sj .debug_gdb_scripts demo". the contents of section .debug_gdb_scripts should be "$GOROOT/src/runtime/runtime-gdb.py".
like this:

$ objdump -sj .debug_gdb_scripts demo

demo:     file format elf64-x86-64

Contents of section .debug_gdb_scripts:
 578e62 012f6d6e 742f682f 312e636f 64652f37  ./mnt/h/1.code/7
 578e72 2e676f64 65762f67 6f2f7372 632f7275  .godev/go/src/ru
 578e82 6e74696d 652f7275 6e74696d 652d6764  ntime/runtime-gd
 578e92 622e7079 00                          b.py.

What did you see instead?

Sometimes, the contents of section .debug_gdb_scripts is as follows:

$ objdump -sj .debug_gdb_scripts demo

demo:     file format elf64-x86-64

Contents of section .debug_gdb_scripts:
 57b4a6 012f6d6e 742f682f 312e636f 64652f30  ./mnt/h/1.code/0
 57b4b6 322e5072 6f6a6563 742f676f 6465762f  2.Project/godev/
 57b4c6 64656d6f 2f66616b 6572756e 74696d65  demo/fakeruntime
 57b4d6 2f72756e 74696d65 2d676462 2e707900  /runtime-gdb.py.

Loading

@gopherbot gopherbot closed this in daa55b2 Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants