summaryrefslogtreecommitdiff
path: root/libgo/go/debug
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2017-01-14 00:05:42 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2017-01-14 00:05:42 +0000
commitccea2b367771831e9877ec31e0656d153818bf3f (patch)
treee183ae81a1f48a02945cb6de463a70c5be1b06f6 /libgo/go/debug
parentfd961cec64a5807cd6375d5c4042bca4256c5fda (diff)
downloadgcc-ccea2b367771831e9877ec31e0656d153818bf3f.tar.gz
libgo: update to Go 1.8 release candidate 1
Compiler changes: * Change map assignment to use mapassign and assign value directly. * Change string iteration to use decoderune, faster for ASCII strings. * Change makeslice to take int, and use makeslice64 for larger values. * Add new noverflow field to hmap struct used for maps. Unresolved problems, to be fixed later: * Commented out test in go/types/sizes_test.go that doesn't compile. * Commented out reflect.TestStructOf test for padding after zero-sized field. Reviewed-on: https://go-review.googlesource.com/35231 gotools/: Updates for Go 1.8rc1. * Makefile.am (go_cmd_go_files): Add bug.go. (s-zdefaultcc): Write defaultPkgConfig. * Makefile.in: Rebuild. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@244456 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/debug')
-rw-r--r--libgo/go/debug/elf/file.go44
-rw-r--r--libgo/go/debug/elf/file_test.go38
-rw-r--r--libgo/go/debug/elf/testdata/go-relocation-test-gcc492-mipsle.objbin0 -> 2864 bytes
-rw-r--r--libgo/go/debug/elf/testdata/go-relocation-test-gcc540-mips.objbin0 -> 3064 bytes
-rw-r--r--libgo/go/debug/gosym/pclntab.go3
-rw-r--r--libgo/go/debug/gosym/pclntab_test.go4
-rw-r--r--libgo/go/debug/macho/macho.go2
-rw-r--r--libgo/go/debug/pe/file.go21
-rw-r--r--libgo/go/debug/pe/file_test.go2
-rw-r--r--libgo/go/debug/pe/section.go14
-rw-r--r--libgo/go/debug/pe/string.go14
-rw-r--r--libgo/go/debug/pe/symbol.go13
12 files changed, 118 insertions, 37 deletions
diff --git a/libgo/go/debug/elf/file.go b/libgo/go/debug/elf/file.go
index c1cbfa62254..8eeab65df89 100644
--- a/libgo/go/debug/elf/file.go
+++ b/libgo/go/debug/elf/file.go
@@ -579,7 +579,7 @@ func (f *File) Section(name string) *Section {
}
// applyRelocations applies relocations to dst. rels is a relocations section
-// in RELA format.
+// in REL or RELA format.
func (f *File) applyRelocations(dst []byte, rels []byte) error {
switch {
case f.Class == ELFCLASS64 && f.Machine == EM_X86_64:
@@ -594,6 +594,8 @@ func (f *File) applyRelocations(dst []byte, rels []byte) error {
return f.applyRelocationsPPC(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_PPC64:
return f.applyRelocationsPPC64(dst, rels)
+ case f.Class == ELFCLASS32 && f.Machine == EM_MIPS:
+ return f.applyRelocationsMIPS(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_MIPS:
return f.applyRelocationsMIPS64(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_S390:
@@ -863,6 +865,44 @@ func (f *File) applyRelocationsPPC64(dst []byte, rels []byte) error {
return nil
}
+func (f *File) applyRelocationsMIPS(dst []byte, rels []byte) error {
+ // 8 is the size of Rel32.
+ if len(rels)%8 != 0 {
+ return errors.New("length of relocation section is not a multiple of 8")
+ }
+
+ symbols, _, err := f.getSymbols(SHT_SYMTAB)
+ if err != nil {
+ return err
+ }
+
+ b := bytes.NewReader(rels)
+ var rel Rel32
+
+ for b.Len() > 0 {
+ binary.Read(b, f.ByteOrder, &rel)
+ symNo := rel.Info >> 8
+ t := R_MIPS(rel.Info & 0xff)
+
+ if symNo == 0 || symNo > uint32(len(symbols)) {
+ continue
+ }
+ sym := &symbols[symNo-1]
+
+ switch t {
+ case R_MIPS_32:
+ if rel.Off+4 >= uint32(len(dst)) {
+ continue
+ }
+ val := f.ByteOrder.Uint32(dst[rel.Off : rel.Off+4])
+ val += uint32(sym.Value)
+ f.ByteOrder.PutUint32(dst[rel.Off:rel.Off+4], val)
+ }
+ }
+
+ return nil
+}
+
func (f *File) applyRelocationsMIPS64(dst []byte, rels []byte) error {
// 24 is the size of Rela64.
if len(rels)%24 != 0 {
@@ -981,7 +1021,7 @@ func (f *File) applyRelocationsSPARC64(dst []byte, rels []byte) error {
for b.Len() > 0 {
binary.Read(b, f.ByteOrder, &rela)
symNo := rela.Info >> 32
- t := R_SPARC(rela.Info & 0xffff)
+ t := R_SPARC(rela.Info & 0xff)
if symNo == 0 || symNo > uint64(len(symbols)) {
continue
diff --git a/libgo/go/debug/elf/file_test.go b/libgo/go/debug/elf/file_test.go
index f1e28a06715..58bdf277d36 100644
--- a/libgo/go/debug/elf/file_test.go
+++ b/libgo/go/debug/elf/file_test.go
@@ -511,6 +511,44 @@ var relocationTests = []relocationTest{
},
},
{
+ "testdata/go-relocation-test-gcc492-mipsle.obj",
+ []relocationTestEntry{
+ {0, &dwarf.Entry{
+ Offset: 0xb,
+ Tag: dwarf.TagCompileUnit,
+ Children: true,
+ Field: []dwarf.Field{
+ {Attr: dwarf.AttrProducer, Val: "GNU C 4.9.2 -mel -march=mips2 -mtune=mips32 -mllsc -mno-shared -mabi=32 -g", Class: dwarf.ClassString},
+ {Attr: dwarf.AttrLanguage, Val: int64(1), Class: dwarf.ClassConstant},
+ {Attr: dwarf.AttrName, Val: "hello.c", Class: dwarf.ClassString},
+ {Attr: dwarf.AttrCompDir, Val: "/tmp", Class: dwarf.ClassString},
+ {Attr: dwarf.AttrLowpc, Val: uint64(0x0), Class: dwarf.ClassAddress},
+ {Attr: dwarf.AttrHighpc, Val: int64(0x58), Class: dwarf.ClassConstant},
+ {Attr: dwarf.AttrStmtList, Val: int64(0), Class: dwarf.ClassLinePtr},
+ },
+ }},
+ },
+ },
+ {
+ "testdata/go-relocation-test-gcc540-mips.obj",
+ []relocationTestEntry{
+ {0, &dwarf.Entry{
+ Offset: 0xb,
+ Tag: dwarf.TagCompileUnit,
+ Children: true,
+ Field: []dwarf.Field{
+ {Attr: dwarf.AttrProducer, Val: "GNU C11 5.4.0 20160609 -meb -mips32 -mtune=mips32r2 -mfpxx -mllsc -mno-shared -mabi=32 -g -gdwarf-2", Class: dwarf.ClassString},
+ {Attr: dwarf.AttrLanguage, Val: int64(12), Class: dwarf.ClassConstant},
+ {Attr: dwarf.AttrName, Val: "hello.c", Class: dwarf.ClassString},
+ {Attr: dwarf.AttrCompDir, Val: "/tmp", Class: dwarf.ClassString},
+ {Attr: dwarf.AttrLowpc, Val: uint64(0x0), Class: dwarf.ClassAddress},
+ {Attr: dwarf.AttrHighpc, Val: uint64(0x5c), Class: dwarf.ClassAddress},
+ {Attr: dwarf.AttrStmtList, Val: int64(0), Class: dwarf.ClassLinePtr},
+ },
+ }},
+ },
+ },
+ {
"testdata/go-relocation-test-gcc493-mips64le.obj",
[]relocationTestEntry{
{0, &dwarf.Entry{
diff --git a/libgo/go/debug/elf/testdata/go-relocation-test-gcc492-mipsle.obj b/libgo/go/debug/elf/testdata/go-relocation-test-gcc492-mipsle.obj
new file mode 100644
index 00000000000..a5fbcfbbdd2
--- /dev/null
+++ b/libgo/go/debug/elf/testdata/go-relocation-test-gcc492-mipsle.obj
Binary files differ
diff --git a/libgo/go/debug/elf/testdata/go-relocation-test-gcc540-mips.obj b/libgo/go/debug/elf/testdata/go-relocation-test-gcc540-mips.obj
new file mode 100644
index 00000000000..270c7775968
--- /dev/null
+++ b/libgo/go/debug/elf/testdata/go-relocation-test-gcc540-mips.obj
Binary files differ
diff --git a/libgo/go/debug/gosym/pclntab.go b/libgo/go/debug/gosym/pclntab.go
index e859d5aed50..ba1cf8b699a 100644
--- a/libgo/go/debug/gosym/pclntab.go
+++ b/libgo/go/debug/gosym/pclntab.go
@@ -295,9 +295,6 @@ func (t *LineTable) step(p *[]byte, pc *uint64, val *int32, first bool) bool {
// off is the offset to the beginning of the pc-value table,
// and entry is the start PC for the corresponding function.
func (t *LineTable) pcvalue(off uint32, entry, targetpc uint64) int32 {
- if off == 0 {
- return -1
- }
p := t.Data[off:]
val := int32(-1)
diff --git a/libgo/go/debug/gosym/pclntab_test.go b/libgo/go/debug/gosym/pclntab_test.go
index 9f82e31ae41..7e7cee67934 100644
--- a/libgo/go/debug/gosym/pclntab_test.go
+++ b/libgo/go/debug/gosym/pclntab_test.go
@@ -37,7 +37,7 @@ func dotest(t *testing.T) {
// the resulting binary looks like it was built from pclinetest.s,
// but we have renamed it to keep it away from the go tool.
pclinetestBinary = filepath.Join(pclineTempDir, "pclinetest")
- cmd := exec.Command("go", "tool", "asm", "-o", pclinetestBinary+".o", "pclinetest.asm")
+ cmd := exec.Command(testenv.GoToolPath(t), "tool", "asm", "-o", pclinetestBinary+".o", "pclinetest.asm")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
@@ -58,7 +58,7 @@ func dotest(t *testing.T) {
t.Fatal(err)
}
- cmd = exec.Command("go", "tool", "link", "-H", "linux",
+ cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "-H", "linux",
"-o", pclinetestBinary, pclinetestBinary+".o")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
diff --git a/libgo/go/debug/macho/macho.go b/libgo/go/debug/macho/macho.go
index 31647536ac5..40ac74e9a14 100644
--- a/libgo/go/debug/macho/macho.go
+++ b/libgo/go/debug/macho/macho.go
@@ -145,7 +145,7 @@ type Section32 struct {
Reserve2 uint32
}
-// A Section32 is a 64-bit Mach-O section header.
+// A Section64 is a 64-bit Mach-O section header.
type Section64 struct {
Name [16]byte
Seg [16]byte
diff --git a/libgo/go/debug/pe/file.go b/libgo/go/debug/pe/file.go
index 3074ba0f506..87f225cb398 100644
--- a/libgo/go/debug/pe/file.go
+++ b/libgo/go/debug/pe/file.go
@@ -13,14 +13,17 @@ import (
"os"
)
+// Avoid use of post-Go 1.4 io features, to make safe for toolchain bootstrap.
+const seekStart = 0
+
// A File represents an open PE file.
type File struct {
FileHeader
OptionalHeader interface{} // of type *OptionalHeader32 or *OptionalHeader64
Sections []*Section
Symbols []*Symbol // COFF symbols with auxiliary symbol records removed
- _COFFSymbols []COFFSymbol // all COFF symbols (including auxiliary symbol records)
- _StringTable _StringTable
+ COFFSymbols []COFFSymbol // all COFF symbols (including auxiliary symbol records)
+ StringTable StringTable
closer io.Closer
}
@@ -80,7 +83,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
} else {
base = int64(0)
}
- sr.Seek(base, io.SeekStart)
+ sr.Seek(base, seekStart)
if err := binary.Read(sr, binary.LittleEndian, &f.FileHeader); err != nil {
return nil, err
}
@@ -93,23 +96,23 @@ func NewFile(r io.ReaderAt) (*File, error) {
var err error
// Read string table.
- f._StringTable, err = readStringTable(&f.FileHeader, sr)
+ f.StringTable, err = readStringTable(&f.FileHeader, sr)
if err != nil {
return nil, err
}
// Read symbol table.
- f._COFFSymbols, err = readCOFFSymbols(&f.FileHeader, sr)
+ f.COFFSymbols, err = readCOFFSymbols(&f.FileHeader, sr)
if err != nil {
return nil, err
}
- f.Symbols, err = removeAuxSymbols(f._COFFSymbols, f._StringTable)
+ f.Symbols, err = removeAuxSymbols(f.COFFSymbols, f.StringTable)
if err != nil {
return nil, err
}
// Read optional header.
- sr.Seek(base, io.SeekStart)
+ sr.Seek(base, seekStart)
if err := binary.Read(sr, binary.LittleEndian, &f.FileHeader); err != nil {
return nil, err
}
@@ -141,7 +144,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
if err := binary.Read(sr, binary.LittleEndian, sh); err != nil {
return nil, err
}
- name, err := sh.fullName(f._StringTable)
+ name, err := sh.fullName(f.StringTable)
if err != nil {
return nil, err
}
@@ -168,7 +171,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
}
for i := range f.Sections {
var err error
- f.Sections[i]._Relocs, err = readRelocs(&f.Sections[i].SectionHeader, sr)
+ f.Sections[i].Relocs, err = readRelocs(&f.Sections[i].SectionHeader, sr)
if err != nil {
return nil, err
}
diff --git a/libgo/go/debug/pe/file_test.go b/libgo/go/debug/pe/file_test.go
index 964caf56ec7..5a740c87050 100644
--- a/libgo/go/debug/pe/file_test.go
+++ b/libgo/go/debug/pe/file_test.go
@@ -307,7 +307,7 @@ func main() {
src := filepath.Join(tmpdir, "a.go")
exe := filepath.Join(tmpdir, "a.exe")
err = ioutil.WriteFile(src, []byte(prog), 0644)
- output, err := exec.Command("go", "build", "-o", exe, src).CombinedOutput()
+ output, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, src).CombinedOutput()
if err != nil {
t.Fatalf("building test executable failed: %s %s", err, output)
}
diff --git a/libgo/go/debug/pe/section.go b/libgo/go/debug/pe/section.go
index 8e6690f0820..b641158eccb 100644
--- a/libgo/go/debug/pe/section.go
+++ b/libgo/go/debug/pe/section.go
@@ -28,7 +28,7 @@ type SectionHeader32 struct {
// fullName finds real name of section sh. Normally name is stored
// in sh.Name, but if it is longer then 8 characters, it is stored
// in COFF string table st instead.
-func (sh *SectionHeader32) fullName(st _StringTable) (string, error) {
+func (sh *SectionHeader32) fullName(st StringTable) (string, error) {
if sh.Name[0] != '/' {
return cstring(sh.Name[:]), nil
}
@@ -41,23 +41,23 @@ func (sh *SectionHeader32) fullName(st _StringTable) (string, error) {
// TODO(brainman): copy all IMAGE_REL_* consts from ldpe.go here
-// _Reloc represents a PE COFF relocation.
+// Reloc represents a PE COFF relocation.
// Each section contains its own relocation list.
-type _Reloc struct {
+type Reloc struct {
VirtualAddress uint32
SymbolTableIndex uint32
Type uint16
}
-func readRelocs(sh *SectionHeader, r io.ReadSeeker) ([]_Reloc, error) {
+func readRelocs(sh *SectionHeader, r io.ReadSeeker) ([]Reloc, error) {
if sh.NumberOfRelocations <= 0 {
return nil, nil
}
- _, err := r.Seek(int64(sh.PointerToRelocations), io.SeekStart)
+ _, err := r.Seek(int64(sh.PointerToRelocations), seekStart)
if err != nil {
return nil, fmt.Errorf("fail to seek to %q section relocations: %v", sh.Name, err)
}
- relocs := make([]_Reloc, sh.NumberOfRelocations)
+ relocs := make([]Reloc, sh.NumberOfRelocations)
err = binary.Read(r, binary.LittleEndian, relocs)
if err != nil {
return nil, fmt.Errorf("fail to read section relocations: %v", err)
@@ -83,7 +83,7 @@ type SectionHeader struct {
// Section provides access to PE COFF section.
type Section struct {
SectionHeader
- _Relocs []_Reloc
+ Relocs []Reloc
// Embed ReaderAt for ReadAt method.
// Do not embed SectionReader directly
diff --git a/libgo/go/debug/pe/string.go b/libgo/go/debug/pe/string.go
index 69837f6d019..c30255f341a 100644
--- a/libgo/go/debug/pe/string.go
+++ b/libgo/go/debug/pe/string.go
@@ -1,4 +1,4 @@
-// Copyright 2016 The Go Authors. All rights reserved.
+// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -19,16 +19,16 @@ func cstring(b []byte) string {
return string(b[:i])
}
-// _StringTable is a COFF string table.
-type _StringTable []byte
+// StringTable is a COFF string table.
+type StringTable []byte
-func readStringTable(fh *FileHeader, r io.ReadSeeker) (_StringTable, error) {
+func readStringTable(fh *FileHeader, r io.ReadSeeker) (StringTable, error) {
// COFF string table is located right after COFF symbol table.
if fh.PointerToSymbolTable <= 0 {
return nil, nil
}
offset := fh.PointerToSymbolTable + COFFSymbolSize*fh.NumberOfSymbols
- _, err := r.Seek(int64(offset), io.SeekStart)
+ _, err := r.Seek(int64(offset), seekStart)
if err != nil {
return nil, fmt.Errorf("fail to seek to string table: %v", err)
}
@@ -47,13 +47,13 @@ func readStringTable(fh *FileHeader, r io.ReadSeeker) (_StringTable, error) {
if err != nil {
return nil, fmt.Errorf("fail to read string table: %v", err)
}
- return _StringTable(buf), nil
+ return StringTable(buf), nil
}
// TODO(brainman): decide if start parameter should be int instead of uint32
// String extracts string from COFF string table st at offset start.
-func (st _StringTable) String(start uint32) (string, error) {
+func (st StringTable) String(start uint32) (string, error) {
// start includes 4 bytes of string table length
if start < 4 {
return "", fmt.Errorf("offset %d is before the start of string table", start)
diff --git a/libgo/go/debug/pe/symbol.go b/libgo/go/debug/pe/symbol.go
index 7b8cbf236be..7fa5948641f 100644
--- a/libgo/go/debug/pe/symbol.go
+++ b/libgo/go/debug/pe/symbol.go
@@ -23,10 +23,13 @@ type COFFSymbol struct {
}
func readCOFFSymbols(fh *FileHeader, r io.ReadSeeker) ([]COFFSymbol, error) {
+ if fh.PointerToSymbolTable == 0 {
+ return nil, nil
+ }
if fh.NumberOfSymbols <= 0 {
return nil, nil
}
- _, err := r.Seek(int64(fh.PointerToSymbolTable), io.SeekStart)
+ _, err := r.Seek(int64(fh.PointerToSymbolTable), seekStart)
if err != nil {
return nil, fmt.Errorf("fail to seek to symbol table: %v", err)
}
@@ -46,17 +49,17 @@ func isSymNameOffset(name [8]byte) (bool, uint32) {
return false, 0
}
-// _FullName finds real name of symbol sym. Normally name is stored
+// FullName finds real name of symbol sym. Normally name is stored
// in sym.Name, but if it is longer then 8 characters, it is stored
// in COFF string table st instead.
-func (sym *COFFSymbol) _FullName(st _StringTable) (string, error) {
+func (sym *COFFSymbol) FullName(st StringTable) (string, error) {
if ok, offset := isSymNameOffset(sym.Name); ok {
return st.String(offset)
}
return cstring(sym.Name[:]), nil
}
-func removeAuxSymbols(allsyms []COFFSymbol, st _StringTable) ([]*Symbol, error) {
+func removeAuxSymbols(allsyms []COFFSymbol, st StringTable) ([]*Symbol, error) {
if len(allsyms) == 0 {
return nil, nil
}
@@ -67,7 +70,7 @@ func removeAuxSymbols(allsyms []COFFSymbol, st _StringTable) ([]*Symbol, error)
aux--
continue
}
- name, err := sym._FullName(st)
+ name, err := sym.FullName(st)
if err != nil {
return nil, err
}