Commit cd5c10f0 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/link: set correct alignment of ELF note section

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/58290Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 744ebfde
...@@ -62,4 +62,23 @@ func testNoteReading(t *testing.T) { ...@@ -62,4 +62,23 @@ func testNoteReading(t *testing.T) {
if id != buildID { if id != buildID {
t.Fatalf("buildID in hello binary = %q, want %q (linkmode=external)", 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)
}
}
} }
...@@ -1874,6 +1874,7 @@ func addgonote(ctxt *Link, sectionName string, tag uint32, desc []byte) { ...@@ -1874,6 +1874,7 @@ func addgonote(ctxt *Link, sectionName string, tag uint32, desc []byte) {
s.P = append(s.P, 0) s.P = append(s.P, 0)
} }
s.Size = int64(len(s.P)) s.Size = int64(len(s.P))
s.Align = 4
} }
func (ctxt *Link) doelf() { func (ctxt *Link) doelf() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment