]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/ld: reserve space for package list note when -buildmode=shared
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 5 May 2015 02:17:07 +0000 (14:17 +1200)
committerIan Lance Taylor <iant@golang.org>
Tue, 5 May 2015 22:32:23 +0000 (22:32 +0000)
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 <iant@golang.org>
src/cmd/6l/obj.go
src/cmd/internal/ld/elf.go

index ba3580ef5f92c12d6d7ada3314f5814777c9634d..9e6dc60e2d3b26e0fc4e1793167784e3c89fd557 100644 (file)
@@ -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)
                }
index 01be55e16d5fe10c0f4355729a9b44bb56240984..ab87be60ed3710f8c13c4ab0ce7e0ea53118a143 100644 (file)
@@ -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
@@ -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)))
                }
@@ -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)
        }
 }