2015-01-19 14:34:58 -05:00
|
|
|
// Derived from Inferno utils/6l/obj.c and utils/6l/span.c
|
|
|
|
|
// http://code.google.com/p/inferno-os/source/browse/utils/6l/obj.c
|
|
|
|
|
// http://code.google.com/p/inferno-os/source/browse/utils/6l/span.c
|
|
|
|
|
//
|
|
|
|
|
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
|
|
|
|
|
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
|
|
|
|
|
// Portions Copyright © 1997-1999 Vita Nuova Limited
|
|
|
|
|
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
|
|
|
|
|
// Portions Copyright © 2004,2006 Bruce Ellis
|
|
|
|
|
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
|
|
|
|
|
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
|
|
|
|
|
// Portions Copyright © 2009 The Go Authors. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
package obj
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"log"
|
|
|
|
|
"math"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Symgrow(ctxt *Link, s *LSym, lsiz int64) {
|
2015-02-23 16:07:24 -05:00
|
|
|
siz := int(lsiz)
|
2015-01-19 14:34:58 -05:00
|
|
|
if int64(siz) != lsiz {
|
2015-02-25 09:07:02 -08:00
|
|
|
log.Fatalf("Symgrow size %d too long", lsiz)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
if len(s.P) >= siz {
|
|
|
|
|
return
|
|
|
|
|
}
|
2015-09-07 16:21:25 +10:00
|
|
|
// TODO(dfc) append cap-len at once, rather than
|
|
|
|
|
// one byte at a time.
|
2015-01-19 14:34:58 -05:00
|
|
|
for cap(s.P) < siz {
|
|
|
|
|
s.P = append(s.P[:cap(s.P)], 0)
|
|
|
|
|
}
|
|
|
|
|
s.P = s.P[:siz]
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 16:21:25 +10:00
|
|
|
func savedata(ctxt *Link, s *LSym, p *Prog, file string) {
|
2015-01-19 14:34:58 -05:00
|
|
|
off := int32(p.From.Offset)
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
siz := int32(p.From3.Offset)
|
2015-01-19 14:34:58 -05:00
|
|
|
if off < 0 || siz < 0 || off >= 1<<30 || siz >= 100 {
|
2015-09-07 16:21:25 +10:00
|
|
|
log.Fatalf("%s: mangled input file", file)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
if ctxt.Enforce_data_order != 0 && off < int32(len(s.P)) {
|
2015-05-27 10:40:47 -04:00
|
|
|
ctxt.Diag("data out of order (already have %d)\n%v", len(s.P), p)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
2015-08-11 12:29:00 +12:00
|
|
|
if s.Type == SBSS || s.Type == STLSBSS {
|
|
|
|
|
ctxt.Diag("cannot supply data for BSS var")
|
|
|
|
|
}
|
2015-01-19 14:34:58 -05:00
|
|
|
Symgrow(ctxt, s, int64(off+siz))
|
|
|
|
|
|
2015-05-14 20:11:28 -07:00
|
|
|
switch p.To.Type {
|
2015-01-19 14:34:58 -05:00
|
|
|
default:
|
2015-05-27 10:40:47 -04:00
|
|
|
ctxt.Diag("bad data: %v", p)
|
2015-01-19 14:34:58 -05:00
|
|
|
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
case TYPE_FCONST:
|
2015-01-19 14:34:58 -05:00
|
|
|
switch siz {
|
|
|
|
|
default:
|
|
|
|
|
ctxt.Diag("unexpected %d-byte floating point constant", siz)
|
|
|
|
|
|
|
|
|
|
case 4:
|
2015-03-16 15:54:44 -04:00
|
|
|
flt := math.Float32bits(float32(p.To.Val.(float64)))
|
2015-01-19 14:34:58 -05:00
|
|
|
ctxt.Arch.ByteOrder.PutUint32(s.P[off:], flt)
|
|
|
|
|
|
|
|
|
|
case 8:
|
2015-03-16 15:54:44 -04:00
|
|
|
flt := math.Float64bits(p.To.Val.(float64))
|
2015-01-19 14:34:58 -05:00
|
|
|
ctxt.Arch.ByteOrder.PutUint64(s.P[off:], flt)
|
|
|
|
|
}
|
|
|
|
|
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
case TYPE_SCONST:
|
2015-03-16 15:54:44 -04:00
|
|
|
copy(s.P[off:off+siz], p.To.Val.(string))
|
2015-01-19 14:34:58 -05:00
|
|
|
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
case TYPE_CONST, TYPE_ADDR:
|
2015-05-14 20:11:28 -07:00
|
|
|
if p.To.Sym != nil || p.To.Type == TYPE_ADDR {
|
2015-01-19 14:34:58 -05:00
|
|
|
r := Addrel(s)
|
|
|
|
|
r.Off = off
|
|
|
|
|
r.Siz = uint8(siz)
|
|
|
|
|
r.Sym = p.To.Sym
|
2015-01-21 14:48:18 -05:00
|
|
|
r.Type = R_ADDR
|
2015-01-19 14:34:58 -05:00
|
|
|
r.Add = p.To.Offset
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
o := p.To.Offset
|
|
|
|
|
switch siz {
|
|
|
|
|
default:
|
|
|
|
|
ctxt.Diag("unexpected %d-byte integer constant", siz)
|
|
|
|
|
case 1:
|
|
|
|
|
s.P[off] = byte(o)
|
|
|
|
|
case 2:
|
|
|
|
|
ctxt.Arch.ByteOrder.PutUint16(s.P[off:], uint16(o))
|
|
|
|
|
case 4:
|
|
|
|
|
ctxt.Arch.ByteOrder.PutUint32(s.P[off:], uint32(o))
|
|
|
|
|
case 8:
|
|
|
|
|
ctxt.Arch.ByteOrder.PutUint64(s.P[off:], uint64(o))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Addrel(s *LSym) *Reloc {
|
|
|
|
|
s.R = append(s.R, Reloc{})
|
|
|
|
|
return &s.R[len(s.R)-1]
|
|
|
|
|
}
|
|
|
|
|
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
func Setuintxx(ctxt *Link, s *LSym, off int64, v uint64, wid int64) int64 {
|
2015-01-21 14:48:18 -05:00
|
|
|
if s.Type == 0 {
|
|
|
|
|
s.Type = SDATA
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
if s.Size < off+wid {
|
|
|
|
|
s.Size = off + wid
|
|
|
|
|
Symgrow(ctxt, s, s.Size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch wid {
|
|
|
|
|
case 1:
|
|
|
|
|
s.P[off] = uint8(v)
|
|
|
|
|
case 2:
|
|
|
|
|
ctxt.Arch.ByteOrder.PutUint16(s.P[off:], uint16(v))
|
|
|
|
|
case 4:
|
|
|
|
|
ctxt.Arch.ByteOrder.PutUint32(s.P[off:], uint32(v))
|
|
|
|
|
case 8:
|
|
|
|
|
ctxt.Arch.ByteOrder.PutUint64(s.P[off:], uint64(v))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return off + wid
|
|
|
|
|
}
|