]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: support arbitrarily sized string data
authorMatthew Dempsky <mdempsky@google.com>
Sat, 12 Mar 2016 02:54:37 +0000 (18:54 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 14 Mar 2016 05:13:31 +0000 (05:13 +0000)
Updates #14786.

Change-Id: I5fe889886f772167386cd10390ac50abc1383937
Reviewed-on: https://go-review.googlesource.com/20607
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/gc/obj.go
src/cmd/internal/obj/data.go

index 021343868f438647583ceb64e3180849b6bc286e..a2c944ba9c39314e2901f6ace70a735e76e6747e 100644 (file)
@@ -223,16 +223,7 @@ func stringsym(s string) (hdr, data *Sym) {
        symdata.Flags |= SymUniq
        symdata.Def = newname(symdata)
 
-       off = 0
-       var m int
-       for n := 0; n < len(s); n += m {
-               m = 8
-               if m > len(s)-n {
-                       m = len(s) - n
-               }
-               off = dsname(symdata, off, s[n:n+m])
-       }
-
+       off = dsname(symdata, 0, s)
        ggloblsym(symdata, int32(off), obj.DUPOK|obj.RODATA|obj.LOCAL)
 
        return symhdr, symdata
@@ -241,22 +232,12 @@ func stringsym(s string) (hdr, data *Sym) {
 var slicebytes_gen int
 
 func slicebytes(nam *Node, s string, len int) {
-       var m int
-
        slicebytes_gen++
        symname := fmt.Sprintf(".gobytes.%d", slicebytes_gen)
        sym := Pkglookup(symname, localpkg)
        sym.Def = newname(sym)
 
-       off := 0
-       for n := 0; n < len; n += m {
-               m = 8
-               if m > len-n {
-                       m = len - n
-               }
-               off = dsname(sym, off, s[n:n+m])
-       }
-
+       off := dsname(sym, 0, s)
        ggloblsym(sym, int32(off), obj.NOPTR|obj.LOCAL)
 
        if nam.Op != ONAME {
index 1f09c9de124f2f64408f6a312853c421e247e00e..e6d116610cfa88e15e373f0275c4c807c50c81ab 100644 (file)
@@ -54,7 +54,7 @@ func Symgrow(ctxt *Link, s *LSym, lsiz int64) {
 
 // prepwrite prepares to write data of size siz into s at offset off.
 func (s *LSym) prepwrite(ctxt *Link, off, siz int64) {
-       if off < 0 || siz < 0 || off >= 1<<30 || siz >= 100 {
+       if off < 0 || siz < 0 || off >= 1<<30 {
                log.Fatalf("prepwrite: bad off=%d siz=%d", off, siz)
        }
        if s.Type == SBSS || s.Type == STLSBSS {
@@ -80,7 +80,7 @@ func (s *LSym) WriteInt(ctxt *Link, off, siz int64, i int64) {
        s.prepwrite(ctxt, off, siz)
        switch siz {
        default:
-               ctxt.Diag("WriteInt bad integer: %d", siz)
+               ctxt.Diag("WriteInt: bad integer size: %d", siz)
        case 1:
                s.P[off] = byte(i)
        case 2:
@@ -95,6 +95,9 @@ func (s *LSym) WriteInt(ctxt *Link, off, siz int64, i int64) {
 // WriteAddr writes an address of size siz into s at offset off.
 // rsym and roff specify the relocation for the address.
 func (s *LSym) WriteAddr(ctxt *Link, off, siz int64, rsym *LSym, roff int64) {
+       if siz != int64(ctxt.Arch.Ptrsize) {
+               ctxt.Diag("WriteAddr: bad address size: %d", siz)
+       }
        s.prepwrite(ctxt, off, siz)
        r := Addrel(s)
        r.Off = int32(off)
@@ -106,6 +109,9 @@ func (s *LSym) WriteAddr(ctxt *Link, off, siz int64, rsym *LSym, roff int64) {
 
 // WriteString writes a string of size siz into s at offset off.
 func (s *LSym) WriteString(ctxt *Link, off, siz int64, str string) {
+       if siz < int64(len(str)) {
+               ctxt.Diag("WriteString: bad string size: %d < %d", siz, len(str))
+       }
        s.prepwrite(ctxt, off, siz)
        copy(s.P[off:off+siz], str)
 }