1
0
mirror of https://github.com/golang/go synced 2024-10-02 08:18:32 -06:00

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/58290
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Ian Lance Taylor 2017-08-23 17:44:51 -07:00
parent 744ebfde04
commit cd5c10f040
2 changed files with 20 additions and 0 deletions

View 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)
}
}
}

View 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() {