From 3a62f4ee40212c363ae7ebf5e28954efb7ff7ee6 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Wed, 6 Mar 2019 17:57:35 -0500 Subject: [PATCH] cmd/link: fix suspicious code in emitPcln In cmd/link/internal/ld/pcln.go:emitPcln, the code and the comment don't match. I think the comment is right. Fix the code. As a consequence, on Linux/AMD64, internal linking with PIE buildmode with cgo (at least the cgo packages in the standard library) now works. Add a test. Change-Id: I091cf81ba89571052bc0ec1fa0a6a688dec07b04 Reviewed-on: https://go-review.googlesource.com/c/go/+/166017 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/dist/test.go | 11 +++++++++++ src/cmd/link/internal/ld/pcln.go | 5 +---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 8084e474a8..a58cee7518 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -579,6 +579,17 @@ func (t *tester) registerTests() { return nil }, }) + // Also test a cgo package. + if t.cgoEnabled { + t.tests = append(t.tests, distTest{ + name: "pie_internal_cgo", + heading: "internal linking of -buildmode=pie", + fn: func(dt *distTest) error { + t.addCmd(dt, "src", t.goTest(), "os/user", "-buildmode=pie", "-ldflags=-linkmode=internal", t.timeout(60)) + return nil + }, + }) + } } // sync tests diff --git a/src/cmd/link/internal/ld/pcln.go b/src/cmd/link/internal/ld/pcln.go index e4db834622..e32f9e7110 100644 --- a/src/cmd/link/internal/ld/pcln.go +++ b/src/cmd/link/internal/ld/pcln.go @@ -182,10 +182,7 @@ func emitPcln(ctxt *Link, s *sym.Symbol) bool { } // We want to generate func table entries only for the "lowest level" symbols, // not containers of subsymbols. - if s.Attr.Container() { - return true - } - return true + return !s.Attr.Container() } // pclntab initializes the pclntab symbol with -- 2.50.0