Skip to content

Commit

Permalink
cmd/internal/ld: reserve space for package list note when -buildmode=…
Browse files Browse the repository at this point in the history
…shared

This makes the intermediate object file a little bigger but it doesn't waste
any space in the final shared library.

Fixes #10691

Change-Id: Ic51a571d60291f1ac2dad1b50dba4679643168ae
Reviewed-on: https://go-review.googlesource.com/9710
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
mwhudson authored and ianlancetaylor committed May 5, 2015
1 parent a1858e9 commit de6d5b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/cmd/6l/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ func archinit() {
ld.Elfinit()

ld.HEADR = ld.ELFRESERVE
if ld.Buildmode == ld.BuildmodeShared {
// When building a shared library we write a package list
// note that can get quite large. The external linker will
// re-layout all the sections anyway, so making this larger
// just wastes a little space in the intermediate object
// file, not the final shared library.
ld.HEADR *= 3
}
if ld.INITTEXT == -1 {
ld.INITTEXT = (1 << 22) + int64(ld.HEADR)
}
Expand Down
13 changes: 10 additions & 3 deletions src/cmd/internal/ld/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1909,8 +1909,9 @@ func Asmbelf(symo int64) {
eh.machine = EM_PPC64
}

elfreserve := int64(ELFRESERVE)
startva := INITTEXT - int64(HEADR)
resoff := int64(ELFRESERVE)
resoff := elfreserve

var pph *ElfPhdr
var pnote *ElfPhdr
Expand All @@ -1921,6 +1922,12 @@ func Asmbelf(symo int64) {
eh.phentsize = 0

if Buildmode == BuildmodeShared {
// The package list note we make space for here can get quite
// large. The external linker will re-layout all the sections
// anyway, so making this larger just wastes a little space
// in the intermediate object file, not the final shared
// library.
elfreserve *= 3
sh := elfshname(".note.go.pkg-list")
resoff -= int64(elfgopkgnote(sh, uint64(startva), uint64(resoff)))
}
Expand Down Expand Up @@ -2336,8 +2343,8 @@ elfobj:
a += int64(elfwritegopkgnote())
}

if a > ELFRESERVE {
Diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE)
if a > elfreserve {
Diag("ELFRESERVE too small: %d > %d", a, elfreserve)
}
}

Expand Down

0 comments on commit de6d5b0

Please sign in to comment.