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 golang#10691

Change-Id: Ic51a571d60291f1ac2dad1b50dba4679643168ae
  • Loading branch information
mwhudson committed May 5, 2015
1 parent 71274e4 commit 202b601
Show file tree
Hide file tree
Showing 2 changed files with 15 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
10 changes: 7 additions & 3 deletions src/cmd/internal/ld/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1909,8 +1909,12 @@ func Asmbelf(symo int64) {
eh.machine = EM_PPC64
}

elfreserve := int64(ELFRESERVE)
if Buildmode == BuildmodeShared {
elfreserve *= 3
}
startva := INITTEXT - int64(HEADR)
resoff := int64(ELFRESERVE)
resoff := elfreserve

var pph *ElfPhdr
var pnote *ElfPhdr
Expand Down Expand Up @@ -2336,8 +2340,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 202b601

Please sign in to comment.