]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: mark rel.ro segment as PT_GNU_RELRO
authorDavid Crawshaw <crawshaw@golang.org>
Tue, 6 Sep 2016 12:02:30 +0000 (08:02 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Sun, 11 Sep 2016 21:29:51 +0000 (21:29 +0000)
Details: http://www.airs.com/blog/archives/189

Part of adding PIE internal linking on linux/amd64.

Change-Id: I8843a97f22f6f120346cccd694c7fff32f09f60b
Reviewed-on: https://go-review.googlesource.com/28541
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/link/internal/ld/elf.go

index 6d09d173b8785f230d1598cfbfc770f21c55fe23..3e027c6a08af1f2d86fc1d3d7d06f4c7cbc328f7 100644 (file)
@@ -236,6 +236,7 @@ const (
        PT_LOPROC            = 0x70000000
        PT_HIPROC            = 0x7fffffff
        PT_GNU_STACK         = 0x6474e551
+       PT_GNU_RELRO         = 0x6474e552
        PT_PAX_FLAGS         = 0x65041580
        PF_X                 = 0x1
        PF_W                 = 0x2
@@ -1599,6 +1600,17 @@ func elfphload(ctxt *Link, seg *Segment) *ElfPhdr {
        return ph
 }
 
+func elfphrelro(ctxt *Link, seg *Segment) {
+       ph := newElfPhdr(ctxt)
+       ph.type_ = PT_GNU_RELRO
+       ph.vaddr = seg.Vaddr
+       ph.paddr = seg.Vaddr
+       ph.memsz = seg.Length
+       ph.off = seg.Fileoff
+       ph.filesz = seg.Filelen
+       ph.align = uint64(*FlagRound)
+}
+
 func elfshname(ctxt *Link, name string) *ElfShdr {
        var off int
        var sh *ElfShdr
@@ -2291,6 +2303,7 @@ func Asmbelf(ctxt *Link, symo int64) {
        }
        if Segrelrodata.Sect != nil {
                elfphload(ctxt, &Segrelrodata)
+               elfphrelro(ctxt, &Segrelrodata)
        }
        elfphload(ctxt, &Segdata)