]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: set correct alignment of ELF note section
authorIan Lance Taylor <iant@golang.org>
Thu, 24 Aug 2017 00:44:51 +0000 (17:44 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 24 Aug 2017 16:54:18 +0000 (16:54 +0000)
Otherwise the default computation in symalign kicked in, setting the
alignment to be too high. This didn't matter with GNU ld, which put
each loadable note into a separate PT_NOTE segment, but it did matter
with gold which accumulated them all into a single PT_NOTE segment,
respecting the requested alignment. In the single PT_NOTE segment
generated by gold, the incorrect section alignment made the notes
unreadable.

Fixes #21564

Change-Id: I15eb408bb04a2566c9fdfb6828e14188d9ef2280
Reviewed-on: https://go-review.googlesource.com/58290
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/note_test.go
src/cmd/link/internal/ld/elf.go

index 289af9908a486b48f0181cdea183c73a00c22627..1bbbd0d8a06e4c9468044c59d149f9e173ef45fb 100644 (file)
@@ -62,4 +62,23 @@ func testNoteReading(t *testing.T) {
        if id != buildID {
                t.Fatalf("buildID in hello binary = %q, want %q (linkmode=external)", id, buildID)
        }
+
+       switch runtime.GOOS {
+       case "dragonfly", "freebsd", "linux", "netbsd", "openbsd":
+               // Test while forcing use of the gold linker, since in the past
+               // we've had trouble reading the notes generated by gold.
+               err := tg.doRun([]string{"build", "-ldflags", "-buildid=" + buildID + " -linkmode=external -extldflags=-fuse-ld=gold", "-o", tg.path("hello.exe"), tg.path("hello.go")})
+               if err != nil && (tg.grepCountBoth("invalid linker") > 0 || tg.grepCountBoth("gold") > 0) {
+                       // It's not an error if gold isn't there.
+                       t.Log("skipping gold test")
+                       break
+               }
+               id, err = buildid.ReadBuildIDFromBinary(tg.path("hello.exe"))
+               if err != nil {
+                       t.Fatalf("reading build ID from hello binary (linkmode=external -extldflags=-fuse-ld=gold): %v", err)
+               }
+               if id != buildID {
+                       t.Fatalf("buildID in hello binary = %q, want %q (linkmode=external -extldflags=-fuse-ld=gold)", id, buildID)
+               }
+       }
 }
index 2c3f99b7568f1898f569b47f38e92a559fad19b7..d6b3cb0927ee6047b5c75d51ed160c248e1a0efa 100644 (file)
@@ -1874,6 +1874,7 @@ func addgonote(ctxt *Link, sectionName string, tag uint32, desc []byte) {
                s.P = append(s.P, 0)
        }
        s.Size = int64(len(s.P))
+       s.Align = 4
 }
 
 func (ctxt *Link) doelf() {