]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: fix -buildmode=pie / -linkshared combination
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 13 Sep 2016 01:29:13 +0000 (13:29 +1200)
committerMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 13 Sep 2016 02:40:30 +0000 (02:40 +0000)
main.main and main.init were not being marked as reachable.

Fixes #17076

Change-Id: Ib3e29bd35ba6252962e6ba89173ca321ed6849b9
Reviewed-on: https://go-review.googlesource.com/28996
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/cgo/testshared/shared_test.go
src/cmd/link/internal/ld/deadcode.go

index bb84ef8cabe2aaa7febab74d2f1ea8fa3d95662d..af4f91550f2094beb4152d5fb59b7d7252585054 100644 (file)
@@ -394,6 +394,14 @@ func TestTrivialExecutable(t *testing.T) {
        AssertHasRPath(t, "./bin/trivial", gorootInstallDir)
 }
 
+// Build a trivial program in PIE mode that links against the shared runtime and check it runs.
+func TestTrivialExecutablePIE(t *testing.T) {
+       goCmd(t, "build", "-buildmode=pie", "-o", "trivial.pie", "-linkshared", "trivial")
+       run(t, "trivial executable", "./trivial.pie")
+       AssertIsLinkedTo(t, "./trivial.pie", soname)
+       AssertHasRPath(t, "./trivial.pie", gorootInstallDir)
+}
+
 // Build an executable that uses cgo linked against the shared runtime and check it
 // runs.
 func TestCgoExecutable(t *testing.T) {
index c8aa6ee0ce2bb5b03ac47bb2f5eb5e8555e4bb2f..9f49cf2dfc3460f0d851c47dbb19fea701c02b35 100644 (file)
@@ -241,7 +241,7 @@ func (d *deadcodepass) init() {
                // In a normal binary, start at main.main and the init
                // functions and mark what is reachable from there.
                names = append(names, *flagEntrySymbol)
-               if *FlagLinkshared && Buildmode == BuildmodeExe {
+               if *FlagLinkshared && (Buildmode == BuildmodeExe || Buildmode == BuildmodePIE) {
                        names = append(names, "main.main", "main.init")
                }
                for _, name := range markextra {