Skip to content

Commit 96e8366

Browse files
cherrymuiaclements
authored andcommitted
Revert "cmd/link: fix GC data reading from shared library"
This reverts CL 240462. Reason for revert: test fails on PPC64LE. Updates #39927. Change-Id: I4f14fd0c36e604a80ae9f2f86d1e643e28945e93 Reviewed-on: https://go-review.googlesource.com/c/go/+/240616 Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 5779bb4 commit 96e8366

File tree

5 files changed

+9
-82
lines changed

5 files changed

+9
-82
lines changed

misc/cgo/testshared/shared_test.go

-16
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,7 @@ var testWork = flag.Bool("testwork", false, "if true, log and do not delete the
3838

3939
// run runs a command and calls t.Errorf if it fails.
4040
func run(t *testing.T, msg string, args ...string) {
41-
runWithEnv(t, msg, nil, args...)
42-
}
43-
44-
// runWithEnv runs a command under the given environment and calls t.Errorf if it fails.
45-
func runWithEnv(t *testing.T, msg string, env []string, args ...string) {
4641
c := exec.Command(args[0], args[1:]...)
47-
if len(env) != 0 {
48-
c.Env = append(os.Environ(), env...)
49-
}
5042
if output, err := c.CombinedOutput(); err != nil {
5143
t.Errorf("executing %s (%s) failed %s:\n%s", strings.Join(args, " "), msg, err, output)
5244
}
@@ -1042,11 +1034,3 @@ func TestGeneratedHash(t *testing.T) {
10421034
func TestPackageOrder(t *testing.T) {
10431035
goCmd(t, "install", "-buildmode=shared", "-linkshared", "./issue39777/a", "./issue39777/b")
10441036
}
1045-
1046-
// Test that GC data are generated correctly by the linker when it needs a type defined in
1047-
// a shared library. See issue 39927.
1048-
func TestGCData(t *testing.T) {
1049-
goCmd(t, "install", "-buildmode=shared", "-linkshared", "./gcdata/p")
1050-
goCmd(t, "build", "-linkshared", "./gcdata/main")
1051-
runWithEnv(t, "running gcdata/main", []string{"GODEBUG=clobberfree=1"}, "./main")
1052-
}

misc/cgo/testshared/testdata/gcdata/main/main.go

-37
This file was deleted.

misc/cgo/testshared/testdata/gcdata/p/p.go

-7
This file was deleted.

src/cmd/link/internal/ld/decodesym.go

+8-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"cmd/link/internal/loader"
1111
"cmd/link/internal/sym"
1212
"debug/elf"
13-
"log"
1413
)
1514

1615
// Decoding the type.* symbols. This has to be in sync with
@@ -230,15 +229,8 @@ func decodetypeGcmask(ctxt *Link, s loader.Sym) []byte {
230229
ptrdata := decodetypePtrdata(ctxt.Arch, symData)
231230
sect := findShlibSection(ctxt, ctxt.loader.SymPkg(s), addr)
232231
if sect != nil {
233-
bits := ptrdata / int64(ctxt.Arch.PtrSize)
234-
r := make([]byte, (bits+7)/8)
235-
// ldshlibsyms avoids closing the ELF file so sect.ReadAt works.
236-
// If we remove this read (and the ones in decodetypeGcprog), we
237-
// can close the file.
238-
_, err := sect.ReadAt(r, int64(addr-sect.Addr))
239-
if err != nil {
240-
log.Fatal(err)
241-
}
232+
r := make([]byte, ptrdata/int64(ctxt.Arch.PtrSize))
233+
sect.ReadAt(r, int64(addr-sect.Addr))
242234
return r
243235
}
244236
Exitf("cannot find gcmask for %s", ctxt.loader.SymName(s))
@@ -259,15 +251,9 @@ func decodetypeGcprog(ctxt *Link, s loader.Sym) []byte {
259251
// A gcprog is a 4-byte uint32 indicating length, followed by
260252
// the actual program.
261253
progsize := make([]byte, 4)
262-
_, err := sect.ReadAt(progsize, int64(addr-sect.Addr))
263-
if err != nil {
264-
log.Fatal(err)
265-
}
254+
sect.ReadAt(progsize, int64(addr-sect.Addr))
266255
progbytes := make([]byte, ctxt.Arch.ByteOrder.Uint32(progsize))
267-
_, err = sect.ReadAt(progbytes, int64(addr-sect.Addr+4))
268-
if err != nil {
269-
log.Fatal(err)
270-
}
256+
sect.ReadAt(progbytes, int64(addr-sect.Addr+4))
271257
return append(progsize, progbytes...)
272258
}
273259
Exitf("cannot find gcmask for %s", ctxt.loader.SymName(s))
@@ -282,7 +268,7 @@ func decodetypeGcprog(ctxt *Link, s loader.Sym) []byte {
282268
func findShlibSection(ctxt *Link, path string, addr uint64) *elf.Section {
283269
for _, shlib := range ctxt.Shlibs {
284270
if shlib.Path == path {
285-
for _, sect := range shlib.File.Sections[1:] { // skip the NULL section
271+
for _, sect := range shlib.File.Sections {
286272
if sect.Addr <= addr && addr <= sect.Addr+sect.Size {
287273
return sect
288274
}
@@ -293,5 +279,8 @@ func findShlibSection(ctxt *Link, path string, addr uint64) *elf.Section {
293279
}
294280

295281
func decodetypeGcprogShlib(ctxt *Link, data []byte) uint64 {
282+
if ctxt.Arch.Family == sys.ARM64 {
283+
return 0
284+
}
296285
return decodeInuxi(ctxt.Arch, data[2*int32(ctxt.Arch.PtrSize)+8+1*int32(ctxt.Arch.PtrSize):], ctxt.Arch.PtrSize)
297286
}

src/cmd/link/internal/ld/lib.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -2124,9 +2124,7 @@ func ldshlibsyms(ctxt *Link, shlib string) {
21242124
Errorf(nil, "cannot open shared library: %s", libpath)
21252125
return
21262126
}
2127-
// Keep the file open as decodetypeGcprog needs to read from it.
2128-
// TODO: fix. Maybe mmap the file.
2129-
//defer f.Close()
2127+
defer f.Close()
21302128

21312129
hash, err := readnote(f, ELF_NOTE_GO_NAME, ELF_NOTE_GOABIHASH_TAG)
21322130
if err != nil {

0 commit comments

Comments
 (0)