Commit 7bd0b610 authored by Cherry Zhang's avatar Cherry Zhang

cmd/internal/goobj: accept int64 in readInt

The counter part, writeInt in cmd/internal/obj, writes int64s.
So the reader side should also read int64s. This may cause a
larger range of values being accepted, some of which should
not be that large. This is probably ok: for example, for
size/index/length, the very large value (due to corruption)
may be well past the end and causes other errors. And we did
not do much bound check anyway.

One exmaple where this matters is ARM32's object file. For one
type of relocation it encodes the instruction into Reloc.Add
field (which itself may be problematic and worth fix) and the
instruction encoding overflows int32, causing ARM32 object
file being rejected by goobj (and so objdump and nm) before.

Unskip ARM32 object file tests in goobj, nm, and objdump.

Updates #19811.

Change-Id: Ia46c2b68df5f1c5204d6509ceab6416ad6372315
Reviewed-on: https://go-review.googlesource.com/69010
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 85c32c37
......@@ -32,14 +32,6 @@ func TestMain(m *testing.M) {
return
}
if runtime.GOARCH == "arm" {
switch runtime.GOOS {
case "darwin", "android", "nacl":
default:
return // skip tests due to #19811
}
}
if err := buildGoobj(); err != nil {
fmt.Println(err)
os.RemoveAll(buildDir)
......
......@@ -25,7 +25,7 @@ type Sym struct {
SymID // symbol identifier (name and version)
Kind objabi.SymKind // kind of symbol
DupOK bool // are duplicate definitions okay?
Size int // size of corresponding data
Size int64 // size of corresponding data
Type SymID // symbol for Go type information
Data Data // memory image of symbol
Reloc []Reloc // relocations to apply to Data
......@@ -43,7 +43,7 @@ type SymID struct {
// declarations in C) have a non-zero version distinguishing
// a symbol in one file from a symbol of the same name
// in another file
Version int
Version int64
}
func (s SymID) String() string {
......@@ -67,10 +67,10 @@ type Reloc struct {
// The bytes at [Offset, Offset+Size) within the containing Sym
// should be updated to refer to the address Add bytes after the start
// of the symbol Sym.
Offset int
Size int
Offset int64
Size int64
Sym SymID
Add int
Add int64
// The Type records the form of address expected in the bytes
// described by the previous fields: absolute, PC-relative, and so on.
......@@ -85,16 +85,16 @@ type Var struct {
// identifies a variable in a function stack frame.
// Using fewer of these - in particular, using only Name - does not.
Name string // Name of variable.
Kind int // TODO(rsc): Define meaning.
Offset int // Frame offset. TODO(rsc): Define meaning.
Kind int64 // TODO(rsc): Define meaning.
Offset int64 // Frame offset. TODO(rsc): Define meaning.
Type SymID // Go type for variable.
}
// Func contains additional per-symbol information specific to functions.
type Func struct {
Args int // size in bytes of argument frame: inputs and outputs
Frame int // size in bytes of local variable frame
Args int64 // size in bytes of argument frame: inputs and outputs
Frame int64 // size in bytes of local variable frame
Leaf bool // function omits save of link register (ARM)
NoSplit bool // function omits stack split prologue
Var []Var // detail about local variables
......@@ -119,9 +119,9 @@ type FuncData struct {
// An InlinedCall is a node in an InlTree.
// See cmd/internal/obj.InlTree for details.
type InlinedCall struct {
Parent int
Parent int64
File string
Line int
Line int64
Func SymID
}
......@@ -131,7 +131,7 @@ type Package struct {
Imports []string // packages imported by this package
SymRefs []SymID // list of symbol names and versions referred to by this pack
Syms []*Sym // symbols defined by this package
MaxVersion int // maximum Version in any SymID in Syms
MaxVersion int64 // maximum Version in any SymID in Syms
Arch string // architecture
Native []*NativeReader // native object data (e.g. ELF)
}
......@@ -255,7 +255,7 @@ func (r *objReader) readFull(b []byte) error {
}
// readInt reads a zigzag varint from the input file.
func (r *objReader) readInt() int {
func (r *objReader) readInt() int64 {
var u uint64
for shift := uint(0); ; shift += 7 {
......@@ -270,12 +270,7 @@ func (r *objReader) readInt() int {
}
}
v := int64(u>>1) ^ (int64(u) << 63 >> 63)
if int64(int(v)) != v {
r.error(errCorruptObject) // TODO
return 0
}
return int(v)
return int64(u>>1) ^ (int64(u) << 63 >> 63)
}
// readString reads a length-delimited string from the input file.
......@@ -313,8 +308,8 @@ func (r *objReader) readRef() {
// readData reads a data reference from the input file.
func (r *objReader) readData() Data {
n := r.readInt()
d := Data{Offset: r.dataOffset, Size: int64(n)}
r.dataOffset += int64(n)
d := Data{Offset: r.dataOffset, Size: n}
r.dataOffset += n
return d
}
......@@ -530,7 +525,7 @@ func (r *objReader) parseObject(prefix []byte) error {
r.readInt() // n files - ignore
r.dataOffset = r.offset
r.skip(int64(dataLength))
r.skip(dataLength)
// Symbols.
for {
......@@ -615,7 +610,7 @@ func (r *objReader) parseObject(prefix []byte) error {
}
func (r *Reloc) String(insnOffset uint64) string {
delta := r.Offset - int(insnOffset)
delta := r.Offset - int64(insnOffset)
s := fmt.Sprintf("[%d:%d]%s", delta, delta+r.Size, r.Type)
if r.Sym.Name != "" {
if r.Add != 0 {
......
......@@ -36,12 +36,5 @@ func TestExternalLinkerCgoExec(t *testing.T) {
}
func TestCgoLib(t *testing.T) {
if runtime.GOARCH == "arm" {
switch runtime.GOOS {
case "darwin", "android", "nacl":
default:
t.Skip("skip test due to #19811")
}
}
testGoLib(t, true)
}
......@@ -198,8 +198,6 @@ func TestDisasmExtld(t *testing.T) {
func TestDisasmGoobj(t *testing.T) {
switch runtime.GOARCH {
case "arm":
t.Skipf("skipping on %s, issue 19811", runtime.GOARCH)
case "mips", "mipsle", "mips64", "mips64le":
t.Skipf("skipping on %s, issue 12559", runtime.GOARCH)
case "s390x":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment