| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | package obj |
| |
|
| | import ( |
| | "cmd/internal/objabi" |
| | "log" |
| | "math" |
| | ) |
| |
|
| | |
| | func (s *LSym) Grow(lsiz int64) { |
| | siz := int(lsiz) |
| | if int64(siz) != lsiz { |
| | log.Fatalf("LSym.Grow size %d too long", lsiz) |
| | } |
| | if len(s.P) >= siz { |
| | return |
| | } |
| | s.P = append(s.P, make([]byte, siz-len(s.P))...) |
| | } |
| |
|
| | |
| | func (s *LSym) GrowCap(c int64) { |
| | if int64(cap(s.P)) >= c { |
| | return |
| | } |
| | if s.P == nil { |
| | s.P = make([]byte, 0, c) |
| | return |
| | } |
| | b := make([]byte, len(s.P), c) |
| | copy(b, s.P) |
| | s.P = b |
| | } |
| |
|
| | |
| | func (s *LSym) prepwrite(ctxt *Link, off int64, siz int) { |
| | if off < 0 || siz < 0 || off >= 1<<30 { |
| | ctxt.Diag("prepwrite: bad off=%d siz=%d s=%v", off, siz, s) |
| | } |
| | switch s.Type { |
| | case objabi.Sxxx, objabi.SBSS: |
| | s.Type = objabi.SDATA |
| | s.setFIPSType(ctxt) |
| | case objabi.SNOPTRBSS: |
| | s.Type = objabi.SNOPTRDATA |
| | s.setFIPSType(ctxt) |
| | case objabi.STLSBSS: |
| | ctxt.Diag("cannot supply data for %v var %v", s.Type, s.Name) |
| | } |
| | l := off + int64(siz) |
| | s.Grow(l) |
| | if l > s.Size { |
| | s.Size = l |
| | } |
| | } |
| |
|
| | |
| | func (s *LSym) WriteFloat32(ctxt *Link, off int64, f float32) { |
| | s.prepwrite(ctxt, off, 4) |
| | ctxt.Arch.ByteOrder.PutUint32(s.P[off:], math.Float32bits(f)) |
| | } |
| |
|
| | |
| | func (s *LSym) WriteFloat64(ctxt *Link, off int64, f float64) { |
| | s.prepwrite(ctxt, off, 8) |
| | ctxt.Arch.ByteOrder.PutUint64(s.P[off:], math.Float64bits(f)) |
| | } |
| |
|
| | |
| | func (s *LSym) WriteInt(ctxt *Link, off int64, siz int, i int64) { |
| | s.prepwrite(ctxt, off, siz) |
| | switch siz { |
| | default: |
| | ctxt.Diag("WriteInt: bad integer size: %d", siz) |
| | case 1: |
| | s.P[off] = byte(i) |
| | case 2: |
| | ctxt.Arch.ByteOrder.PutUint16(s.P[off:], uint16(i)) |
| | case 4: |
| | ctxt.Arch.ByteOrder.PutUint32(s.P[off:], uint32(i)) |
| | case 8: |
| | ctxt.Arch.ByteOrder.PutUint64(s.P[off:], uint64(i)) |
| | } |
| | } |
| |
|
| | func (s *LSym) writeAddr(ctxt *Link, off int64, siz int, rsym *LSym, roff int64, rtype objabi.RelocType) { |
| | |
| | if siz != ctxt.Arch.PtrSize && siz != 4 { |
| | ctxt.Diag("WriteAddr: bad address size %d in %s", siz, s.Name) |
| | } |
| | s.prepwrite(ctxt, off, siz) |
| | if int64(int32(off)) != off { |
| | ctxt.Diag("WriteAddr: off overflow %d in %s", off, s.Name) |
| | } |
| | s.AddRel(ctxt, Reloc{ |
| | Type: rtype, |
| | Off: int32(off), |
| | Siz: uint8(siz), |
| | Sym: rsym, |
| | Add: roff, |
| | }) |
| | } |
| |
|
| | |
| | |
| | func (s *LSym) WriteAddr(ctxt *Link, off int64, siz int, rsym *LSym, roff int64) { |
| | s.writeAddr(ctxt, off, siz, rsym, roff, objabi.R_ADDR) |
| | } |
| |
|
| | |
| | |
| | |
| | func (s *LSym) WriteWeakAddr(ctxt *Link, off int64, siz int, rsym *LSym, roff int64) { |
| | s.writeAddr(ctxt, off, siz, rsym, roff, objabi.R_WEAKADDR) |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func (s *LSym) WriteCURelativeAddr(ctxt *Link, off int64, rsym *LSym, roff int64) { |
| | s.writeAddr(ctxt, off, ctxt.Arch.PtrSize, rsym, roff, objabi.R_ADDRCUOFF) |
| | } |
| |
|
| | |
| | |
| | |
| | func (s *LSym) WriteOff(ctxt *Link, off int64, rsym *LSym, roff int64) { |
| | s.prepwrite(ctxt, off, 4) |
| | if int64(int32(off)) != off { |
| | ctxt.Diag("WriteOff: off overflow %d in %s", off, s.Name) |
| | } |
| | s.AddRel(ctxt, Reloc{ |
| | Type: objabi.R_ADDROFF, |
| | Off: int32(off), |
| | Siz: 4, |
| | Sym: rsym, |
| | Add: roff, |
| | }) |
| | } |
| |
|
| | |
| | |
| | |
| | func (s *LSym) WriteWeakOff(ctxt *Link, off int64, rsym *LSym, roff int64) { |
| | s.prepwrite(ctxt, off, 4) |
| | if int64(int32(off)) != off { |
| | ctxt.Diag("WriteWeakOff: off overflow %d in %s", off, s.Name) |
| | } |
| | s.AddRel(ctxt, Reloc{ |
| | Type: objabi.R_WEAKADDROFF, |
| | Off: int32(off), |
| | Siz: 4, |
| | Sym: rsym, |
| | Add: roff, |
| | }) |
| | } |
| |
|
| | |
| | func (s *LSym) WriteString(ctxt *Link, off int64, siz int, str string) { |
| | if siz < len(str) { |
| | ctxt.Diag("WriteString: bad string size: %d < %d", siz, len(str)) |
| | } |
| | s.prepwrite(ctxt, off, siz) |
| | copy(s.P[off:off+int64(siz)], str) |
| | } |
| |
|
| | |
| | func (s *LSym) WriteBytes(ctxt *Link, off int64, b []byte) int64 { |
| | s.prepwrite(ctxt, off, len(b)) |
| | copy(s.P[off:], b) |
| | return off + int64(len(b)) |
| | } |
| |
|
| | |
| | func (s *LSym) AddRel(ctxt *Link, rel Reloc) { |
| | if s.Type.IsFIPS() { |
| | s.checkFIPSReloc(ctxt, rel) |
| | } |
| | s.R = append(s.R, rel) |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | func (s *LSym) WriteDwTxtAddrx(ctxt *Link, off int64, rsym *LSym, maxFuncs int) { |
| | rtype, sz := objabi.FuncCountToDwTxtAddrFlavor(maxFuncs) |
| | s.prepwrite(ctxt, off, sz) |
| | if int64(int32(off)) != off { |
| | ctxt.Diag("WriteDwTxtAddrx: off overflow %d in %s", off, s.Name) |
| | } |
| | s.AddRel(ctxt, Reloc{ |
| | Type: rtype, |
| | Off: int32(off), |
| | Siz: uint8(sz), |
| | Sym: rsym, |
| | }) |
| | } |
| |
|