]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: fix suspicious code in emitPcln
authorCherry Zhang <cherryyz@google.com>
Wed, 6 Mar 2019 22:57:35 +0000 (17:57 -0500)
committerCherry Zhang <cherryyz@google.com>
Thu, 7 Mar 2019 23:09:46 +0000 (23:09 +0000)
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 <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/dist/test.go
src/cmd/link/internal/ld/pcln.go

index 8084e474a8538794d5e705f9765b62d947f93744..a58cee75181b5104448b54d957853b25ec5c823c 100644 (file)
@@ -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
index e4db834622dd47dd6308b5ee60d48f21a96002c5..e32f9e7110acff9eee6fee198d1be189a7e14a8f 100644 (file)
@@ -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