]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/goobj: accept int64 in readInt
authorCherry Zhang <cherryyz@google.com>
Fri, 6 Oct 2017 19:00:02 +0000 (15:00 -0400)
committerCherry Zhang <cherryyz@google.com>
Wed, 1 Nov 2017 18:23:58 +0000 (18:23 +0000)
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: Russ Cox <rsc@golang.org>
src/cmd/internal/goobj/goobj_test.go
src/cmd/internal/goobj/read.go
src/cmd/nm/nm_cgo_test.go
src/cmd/objdump/objdump_test.go

index 92c2bf981927804359c108f48ef040211e4f7cbf..e5987e02ba44051f92539f536d6d6247ab4edc61 100644 (file)
@@ -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)
index ecc9719d2b1c83db85855428a430f634be8eac50..ebdc37575f21c94aa04dec397c3266dc1cc09c43 100644 (file)
@@ -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 {
index b32402069aa969a041e27376b20fef034e58e81a..1dfdf7f21acb4938748427c4f819fcc3eb706d2f 100644 (file)
@@ -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)
 }
index 100e9fcb5fcb5f483157e935fa2332de7484bf94..f0771cdde9d27945e66dcfb30b9f117dba757ec5 100644 (file)
@@ -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":