diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
commit | 3e45412327a2654a77944249962b3652e6142299 (patch) | |
tree | bc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/pkg/debug | |
parent | c533680039762cacbc37db8dc7eed074c3e497be (diff) | |
download | golang-3e45412327a2654a77944249962b3652e6142299.tar.gz |
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/pkg/debug')
27 files changed, 1382 insertions, 707 deletions
diff --git a/src/pkg/debug/dwarf/Makefile b/src/pkg/debug/dwarf/Makefile index a626513c7..c4203188e 100644 --- a/src/pkg/debug/dwarf/Makefile +++ b/src/pkg/debug/dwarf/Makefile @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -include ../../../Make.$(GOARCH) +include ../../../Make.inc TARG=debug/dwarf GOFILES=\ diff --git a/src/pkg/debug/dwarf/type.go b/src/pkg/debug/dwarf/type.go index 5d4a51653..902a545f8 100644 --- a/src/pkg/debug/dwarf/type.go +++ b/src/pkg/debug/dwarf/type.go @@ -451,16 +451,7 @@ func (d *Data) Type(off Offset) (Type, os.Error) { f.ByteSize, _ = kid.Val(AttrByteSize).(int64) f.BitOffset, _ = kid.Val(AttrBitOffset).(int64) f.BitSize, _ = kid.Val(AttrBitSize).(int64) - n := len(t.Field) - if n >= cap(t.Field) { - fld := make([]*StructField, n, n*2) - for i, f := range t.Field { - fld[i] = f - } - t.Field = fld - } - t.Field = t.Field[0 : n+1] - t.Field[n] = f + t.Field = append(t.Field, f) } } @@ -505,9 +496,7 @@ func (d *Data) Type(off Offset) (Type, os.Error) { n := len(t.Val) if n >= cap(t.Val) { val := make([]*EnumValue, n, n*2) - for i, f := range t.Val { - val[i] = f - } + copy(val, t.Val) t.Val = val } t.Val = t.Val[0 : n+1] @@ -558,16 +547,7 @@ func (d *Data) Type(off Offset) (Type, os.Error) { case TagUnspecifiedParameters: tkid = &DotDotDotType{} } - n := len(t.ParamType) - if n >= cap(t.ParamType) { - param := make([]Type, n, n*2) - for i, t := range t.ParamType { - param[i] = t - } - t.ParamType = param - } - t.ParamType = t.ParamType[0 : n+1] - t.ParamType[n] = tkid + t.ParamType = append(t.ParamType, tkid) } case TagTypedef: diff --git a/src/pkg/debug/elf/Makefile b/src/pkg/debug/elf/Makefile index 931f9d24d..dd431f653 100644 --- a/src/pkg/debug/elf/Makefile +++ b/src/pkg/debug/elf/Makefile @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -include ../../../Make.$(GOARCH) +include ../../../Make.inc TARG=debug/elf GOFILES=\ diff --git a/src/pkg/debug/elf/elf.go b/src/pkg/debug/elf/elf.go index 394a7cc87..74e979986 100644 --- a/src/pkg/debug/elf/elf.go +++ b/src/pkg/debug/elf/elf.go @@ -69,8 +69,8 @@ const ( ) var versionStrings = []intName{ - intName{0, "EV_NONE"}, - intName{1, "EV_CURRENT"}, + {0, "EV_NONE"}, + {1, "EV_CURRENT"}, } func (i Version) String() string { return stringName(uint32(i), versionStrings, false) } @@ -86,9 +86,9 @@ const ( ) var classStrings = []intName{ - intName{0, "ELFCLASSNONE"}, - intName{1, "ELFCLASS32"}, - intName{2, "ELFCLASS64"}, + {0, "ELFCLASSNONE"}, + {1, "ELFCLASS32"}, + {2, "ELFCLASS64"}, } func (i Class) String() string { return stringName(uint32(i), classStrings, false) } @@ -104,9 +104,9 @@ const ( ) var dataStrings = []intName{ - intName{0, "ELFDATANONE"}, - intName{1, "ELFDATA2LSB"}, - intName{2, "ELFDATA2MSB"}, + {0, "ELFDATANONE"}, + {1, "ELFDATA2LSB"}, + {2, "ELFDATA2MSB"}, } func (i Data) String() string { return stringName(uint32(i), dataStrings, false) } @@ -136,23 +136,23 @@ const ( ) var osabiStrings = []intName{ - intName{0, "ELFOSABI_NONE"}, - intName{1, "ELFOSABI_HPUX"}, - intName{2, "ELFOSABI_NETBSD"}, - intName{3, "ELFOSABI_LINUX"}, - intName{4, "ELFOSABI_HURD"}, - intName{5, "ELFOSABI_86OPEN"}, - intName{6, "ELFOSABI_SOLARIS"}, - intName{7, "ELFOSABI_AIX"}, - intName{8, "ELFOSABI_IRIX"}, - intName{9, "ELFOSABI_FREEBSD"}, - intName{10, "ELFOSABI_TRU64"}, - intName{11, "ELFOSABI_MODESTO"}, - intName{12, "ELFOSABI_OPENBSD"}, - intName{13, "ELFOSABI_OPENVMS"}, - intName{14, "ELFOSABI_NSK"}, - intName{97, "ELFOSABI_ARM"}, - intName{255, "ELFOSABI_STANDALONE"}, + {0, "ELFOSABI_NONE"}, + {1, "ELFOSABI_HPUX"}, + {2, "ELFOSABI_NETBSD"}, + {3, "ELFOSABI_LINUX"}, + {4, "ELFOSABI_HURD"}, + {5, "ELFOSABI_86OPEN"}, + {6, "ELFOSABI_SOLARIS"}, + {7, "ELFOSABI_AIX"}, + {8, "ELFOSABI_IRIX"}, + {9, "ELFOSABI_FREEBSD"}, + {10, "ELFOSABI_TRU64"}, + {11, "ELFOSABI_MODESTO"}, + {12, "ELFOSABI_OPENBSD"}, + {13, "ELFOSABI_OPENVMS"}, + {14, "ELFOSABI_NSK"}, + {97, "ELFOSABI_ARM"}, + {255, "ELFOSABI_STANDALONE"}, } func (i OSABI) String() string { return stringName(uint32(i), osabiStrings, false) } @@ -174,15 +174,15 @@ const ( ) var typeStrings = []intName{ - intName{0, "ET_NONE"}, - intName{1, "ET_REL"}, - intName{2, "ET_EXEC"}, - intName{3, "ET_DYN"}, - intName{4, "ET_CORE"}, - intName{0xfe00, "ET_LOOS"}, - intName{0xfeff, "ET_HIOS"}, - intName{0xff00, "ET_LOPROC"}, - intName{0xffff, "ET_HIPROC"}, + {0, "ET_NONE"}, + {1, "ET_REL"}, + {2, "ET_EXEC"}, + {3, "ET_DYN"}, + {4, "ET_CORE"}, + {0xfe00, "ET_LOOS"}, + {0xfeff, "ET_HIOS"}, + {0xff00, "ET_LOPROC"}, + {0xffff, "ET_HIPROC"}, } func (i Type) String() string { return stringName(uint32(i), typeStrings, false) } @@ -244,55 +244,55 @@ const ( ) var machineStrings = []intName{ - intName{0, "EM_NONE"}, - intName{1, "EM_M32"}, - intName{2, "EM_SPARC"}, - intName{3, "EM_386"}, - intName{4, "EM_68K"}, - intName{5, "EM_88K"}, - intName{7, "EM_860"}, - intName{8, "EM_MIPS"}, - intName{9, "EM_S370"}, - intName{10, "EM_MIPS_RS3_LE"}, - intName{15, "EM_PARISC"}, - intName{17, "EM_VPP500"}, - intName{18, "EM_SPARC32PLUS"}, - intName{19, "EM_960"}, - intName{20, "EM_PPC"}, - intName{21, "EM_PPC64"}, - intName{22, "EM_S390"}, - intName{36, "EM_V800"}, - intName{37, "EM_FR20"}, - intName{38, "EM_RH32"}, - intName{39, "EM_RCE"}, - intName{40, "EM_ARM"}, - intName{42, "EM_SH"}, - intName{43, "EM_SPARCV9"}, - intName{44, "EM_TRICORE"}, - intName{45, "EM_ARC"}, - intName{46, "EM_H8_300"}, - intName{47, "EM_H8_300H"}, - intName{48, "EM_H8S"}, - intName{49, "EM_H8_500"}, - intName{50, "EM_IA_64"}, - intName{51, "EM_MIPS_X"}, - intName{52, "EM_COLDFIRE"}, - intName{53, "EM_68HC12"}, - intName{54, "EM_MMA"}, - intName{55, "EM_PCP"}, - intName{56, "EM_NCPU"}, - intName{57, "EM_NDR1"}, - intName{58, "EM_STARCORE"}, - intName{59, "EM_ME16"}, - intName{60, "EM_ST100"}, - intName{61, "EM_TINYJ"}, - intName{62, "EM_X86_64"}, + {0, "EM_NONE"}, + {1, "EM_M32"}, + {2, "EM_SPARC"}, + {3, "EM_386"}, + {4, "EM_68K"}, + {5, "EM_88K"}, + {7, "EM_860"}, + {8, "EM_MIPS"}, + {9, "EM_S370"}, + {10, "EM_MIPS_RS3_LE"}, + {15, "EM_PARISC"}, + {17, "EM_VPP500"}, + {18, "EM_SPARC32PLUS"}, + {19, "EM_960"}, + {20, "EM_PPC"}, + {21, "EM_PPC64"}, + {22, "EM_S390"}, + {36, "EM_V800"}, + {37, "EM_FR20"}, + {38, "EM_RH32"}, + {39, "EM_RCE"}, + {40, "EM_ARM"}, + {42, "EM_SH"}, + {43, "EM_SPARCV9"}, + {44, "EM_TRICORE"}, + {45, "EM_ARC"}, + {46, "EM_H8_300"}, + {47, "EM_H8_300H"}, + {48, "EM_H8S"}, + {49, "EM_H8_500"}, + {50, "EM_IA_64"}, + {51, "EM_MIPS_X"}, + {52, "EM_COLDFIRE"}, + {53, "EM_68HC12"}, + {54, "EM_MMA"}, + {55, "EM_PCP"}, + {56, "EM_NCPU"}, + {57, "EM_NDR1"}, + {58, "EM_STARCORE"}, + {59, "EM_ME16"}, + {60, "EM_ST100"}, + {61, "EM_TINYJ"}, + {62, "EM_X86_64"}, /* Non-standard or deprecated. */ - intName{6, "EM_486"}, - intName{10, "EM_MIPS_RS4_BE"}, - intName{41, "EM_ALPHA_STD"}, - intName{0x9026, "EM_ALPHA"}, + {6, "EM_486"}, + {10, "EM_MIPS_RS4_BE"}, + {41, "EM_ALPHA_STD"}, + {0x9026, "EM_ALPHA"}, } func (i Machine) String() string { return stringName(uint32(i), machineStrings, false) } @@ -315,12 +315,12 @@ const ( ) var shnStrings = []intName{ - intName{0, "SHN_UNDEF"}, - intName{0xff00, "SHN_LOPROC"}, - intName{0xff20, "SHN_LOOS"}, - intName{0xfff1, "SHN_ABS"}, - intName{0xfff2, "SHN_COMMON"}, - intName{0xffff, "SHN_XINDEX"}, + {0, "SHN_UNDEF"}, + {0xff00, "SHN_LOPROC"}, + {0xff20, "SHN_LOOS"}, + {0xfff1, "SHN_ABS"}, + {0xfff2, "SHN_COMMON"}, + {0xffff, "SHN_XINDEX"}, } func (i SectionIndex) String() string { return stringName(uint32(i), shnStrings, false) } @@ -356,29 +356,29 @@ const ( ) var shtStrings = []intName{ - intName{0, "SHT_NULL"}, - intName{1, "SHT_PROGBITS"}, - intName{2, "SHT_SYMTAB"}, - intName{3, "SHT_STRTAB"}, - intName{4, "SHT_RELA"}, - intName{5, "SHT_HASH"}, - intName{6, "SHT_DYNAMIC"}, - intName{7, "SHT_NOTE"}, - intName{8, "SHT_NOBITS"}, - intName{9, "SHT_REL"}, - intName{10, "SHT_SHLIB"}, - intName{11, "SHT_DYNSYM"}, - intName{14, "SHT_INIT_ARRAY"}, - intName{15, "SHT_FINI_ARRAY"}, - intName{16, "SHT_PREINIT_ARRAY"}, - intName{17, "SHT_GROUP"}, - intName{18, "SHT_SYMTAB_SHNDX"}, - intName{0x60000000, "SHT_LOOS"}, - intName{0x6fffffff, "SHT_HIOS"}, - intName{0x70000000, "SHT_LOPROC"}, - intName{0x7fffffff, "SHT_HIPROC"}, - intName{0x80000000, "SHT_LOUSER"}, - intName{0xffffffff, "SHT_HIUSER"}, + {0, "SHT_NULL"}, + {1, "SHT_PROGBITS"}, + {2, "SHT_SYMTAB"}, + {3, "SHT_STRTAB"}, + {4, "SHT_RELA"}, + {5, "SHT_HASH"}, + {6, "SHT_DYNAMIC"}, + {7, "SHT_NOTE"}, + {8, "SHT_NOBITS"}, + {9, "SHT_REL"}, + {10, "SHT_SHLIB"}, + {11, "SHT_DYNSYM"}, + {14, "SHT_INIT_ARRAY"}, + {15, "SHT_FINI_ARRAY"}, + {16, "SHT_PREINIT_ARRAY"}, + {17, "SHT_GROUP"}, + {18, "SHT_SYMTAB_SHNDX"}, + {0x60000000, "SHT_LOOS"}, + {0x6fffffff, "SHT_HIOS"}, + {0x70000000, "SHT_LOPROC"}, + {0x7fffffff, "SHT_HIPROC"}, + {0x80000000, "SHT_LOUSER"}, + {0xffffffff, "SHT_HIUSER"}, } func (i SectionType) String() string { return stringName(uint32(i), shtStrings, false) } @@ -403,16 +403,16 @@ const ( ) var shfStrings = []intName{ - intName{0x1, "SHF_WRITE"}, - intName{0x2, "SHF_ALLOC"}, - intName{0x4, "SHF_EXECINSTR"}, - intName{0x10, "SHF_MERGE"}, - intName{0x20, "SHF_STRINGS"}, - intName{0x40, "SHF_INFO_LINK"}, - intName{0x80, "SHF_LINK_ORDER"}, - intName{0x100, "SHF_OS_NONCONFORMING"}, - intName{0x200, "SHF_GROUP"}, - intName{0x400, "SHF_TLS"}, + {0x1, "SHF_WRITE"}, + {0x2, "SHF_ALLOC"}, + {0x4, "SHF_EXECINSTR"}, + {0x10, "SHF_MERGE"}, + {0x20, "SHF_STRINGS"}, + {0x40, "SHF_INFO_LINK"}, + {0x80, "SHF_LINK_ORDER"}, + {0x100, "SHF_OS_NONCONFORMING"}, + {0x200, "SHF_GROUP"}, + {0x400, "SHF_TLS"}, } func (i SectionFlag) String() string { return flagName(uint32(i), shfStrings, false) } @@ -437,18 +437,18 @@ const ( ) var ptStrings = []intName{ - intName{0, "PT_NULL"}, - intName{1, "PT_LOAD"}, - intName{2, "PT_DYNAMIC"}, - intName{3, "PT_INTERP"}, - intName{4, "PT_NOTE"}, - intName{5, "PT_SHLIB"}, - intName{6, "PT_PHDR"}, - intName{7, "PT_TLS"}, - intName{0x60000000, "PT_LOOS"}, - intName{0x6fffffff, "PT_HIOS"}, - intName{0x70000000, "PT_LOPROC"}, - intName{0x7fffffff, "PT_HIPROC"}, + {0, "PT_NULL"}, + {1, "PT_LOAD"}, + {2, "PT_DYNAMIC"}, + {3, "PT_INTERP"}, + {4, "PT_NOTE"}, + {5, "PT_SHLIB"}, + {6, "PT_PHDR"}, + {7, "PT_TLS"}, + {0x60000000, "PT_LOOS"}, + {0x6fffffff, "PT_HIOS"}, + {0x70000000, "PT_LOPROC"}, + {0x7fffffff, "PT_HIPROC"}, } func (i ProgType) String() string { return stringName(uint32(i), ptStrings, false) } @@ -466,9 +466,9 @@ const ( ) var pfStrings = []intName{ - intName{0x1, "PF_X"}, - intName{0x2, "PF_W"}, - intName{0x4, "PF_R"}, + {0x1, "PF_X"}, + {0x2, "PF_W"}, + {0x4, "PF_R"}, } func (i ProgFlag) String() string { return flagName(uint32(i), pfStrings, false) } @@ -523,44 +523,44 @@ const ( ) var dtStrings = []intName{ - intName{0, "DT_NULL"}, - intName{1, "DT_NEEDED"}, - intName{2, "DT_PLTRELSZ"}, - intName{3, "DT_PLTGOT"}, - intName{4, "DT_HASH"}, - intName{5, "DT_STRTAB"}, - intName{6, "DT_SYMTAB"}, - intName{7, "DT_RELA"}, - intName{8, "DT_RELASZ"}, - intName{9, "DT_RELAENT"}, - intName{10, "DT_STRSZ"}, - intName{11, "DT_SYMENT"}, - intName{12, "DT_INIT"}, - intName{13, "DT_FINI"}, - intName{14, "DT_SONAME"}, - intName{15, "DT_RPATH"}, - intName{16, "DT_SYMBOLIC"}, - intName{17, "DT_REL"}, - intName{18, "DT_RELSZ"}, - intName{19, "DT_RELENT"}, - intName{20, "DT_PLTREL"}, - intName{21, "DT_DEBUG"}, - intName{22, "DT_TEXTREL"}, - intName{23, "DT_JMPREL"}, - intName{24, "DT_BIND_NOW"}, - intName{25, "DT_INIT_ARRAY"}, - intName{26, "DT_FINI_ARRAY"}, - intName{27, "DT_INIT_ARRAYSZ"}, - intName{28, "DT_FINI_ARRAYSZ"}, - intName{29, "DT_RUNPATH"}, - intName{30, "DT_FLAGS"}, - intName{32, "DT_ENCODING"}, - intName{32, "DT_PREINIT_ARRAY"}, - intName{33, "DT_PREINIT_ARRAYSZ"}, - intName{0x6000000d, "DT_LOOS"}, - intName{0x6ffff000, "DT_HIOS"}, - intName{0x70000000, "DT_LOPROC"}, - intName{0x7fffffff, "DT_HIPROC"}, + {0, "DT_NULL"}, + {1, "DT_NEEDED"}, + {2, "DT_PLTRELSZ"}, + {3, "DT_PLTGOT"}, + {4, "DT_HASH"}, + {5, "DT_STRTAB"}, + {6, "DT_SYMTAB"}, + {7, "DT_RELA"}, + {8, "DT_RELASZ"}, + {9, "DT_RELAENT"}, + {10, "DT_STRSZ"}, + {11, "DT_SYMENT"}, + {12, "DT_INIT"}, + {13, "DT_FINI"}, + {14, "DT_SONAME"}, + {15, "DT_RPATH"}, + {16, "DT_SYMBOLIC"}, + {17, "DT_REL"}, + {18, "DT_RELSZ"}, + {19, "DT_RELENT"}, + {20, "DT_PLTREL"}, + {21, "DT_DEBUG"}, + {22, "DT_TEXTREL"}, + {23, "DT_JMPREL"}, + {24, "DT_BIND_NOW"}, + {25, "DT_INIT_ARRAY"}, + {26, "DT_FINI_ARRAY"}, + {27, "DT_INIT_ARRAYSZ"}, + {28, "DT_FINI_ARRAYSZ"}, + {29, "DT_RUNPATH"}, + {30, "DT_FLAGS"}, + {32, "DT_ENCODING"}, + {32, "DT_PREINIT_ARRAY"}, + {33, "DT_PREINIT_ARRAYSZ"}, + {0x6000000d, "DT_LOOS"}, + {0x6ffff000, "DT_HIOS"}, + {0x70000000, "DT_LOPROC"}, + {0x7fffffff, "DT_HIPROC"}, } func (i DynTag) String() string { return stringName(uint32(i), dtStrings, false) } @@ -585,11 +585,11 @@ const ( ) var dflagStrings = []intName{ - intName{0x0001, "DF_ORIGIN"}, - intName{0x0002, "DF_SYMBOLIC"}, - intName{0x0004, "DF_TEXTREL"}, - intName{0x0008, "DF_BIND_NOW"}, - intName{0x0010, "DF_STATIC_TLS"}, + {0x0001, "DF_ORIGIN"}, + {0x0002, "DF_SYMBOLIC"}, + {0x0004, "DF_TEXTREL"}, + {0x0008, "DF_BIND_NOW"}, + {0x0010, "DF_STATIC_TLS"}, } func (i DynFlag) String() string { return flagName(uint32(i), dflagStrings, false) } @@ -605,9 +605,9 @@ const ( ) var ntypeStrings = []intName{ - intName{1, "NT_PRSTATUS"}, - intName{2, "NT_FPREGSET"}, - intName{3, "NT_PRPSINFO"}, + {1, "NT_PRSTATUS"}, + {2, "NT_FPREGSET"}, + {3, "NT_PRPSINFO"}, } func (i NType) String() string { return stringName(uint32(i), ntypeStrings, false) } @@ -627,13 +627,13 @@ const ( ) var stbStrings = []intName{ - intName{0, "STB_LOCAL"}, - intName{1, "STB_GLOBAL"}, - intName{2, "STB_WEAK"}, - intName{10, "STB_LOOS"}, - intName{12, "STB_HIOS"}, - intName{13, "STB_LOPROC"}, - intName{15, "STB_HIPROC"}, + {0, "STB_LOCAL"}, + {1, "STB_GLOBAL"}, + {2, "STB_WEAK"}, + {10, "STB_LOOS"}, + {12, "STB_HIOS"}, + {13, "STB_LOPROC"}, + {15, "STB_HIPROC"}, } func (i SymBind) String() string { return stringName(uint32(i), stbStrings, false) } @@ -657,17 +657,17 @@ const ( ) var sttStrings = []intName{ - intName{0, "STT_NOTYPE"}, - intName{1, "STT_OBJECT"}, - intName{2, "STT_FUNC"}, - intName{3, "STT_SECTION"}, - intName{4, "STT_FILE"}, - intName{5, "STT_COMMON"}, - intName{6, "STT_TLS"}, - intName{10, "STT_LOOS"}, - intName{12, "STT_HIOS"}, - intName{13, "STT_LOPROC"}, - intName{15, "STT_HIPROC"}, + {0, "STT_NOTYPE"}, + {1, "STT_OBJECT"}, + {2, "STT_FUNC"}, + {3, "STT_SECTION"}, + {4, "STT_FILE"}, + {5, "STT_COMMON"}, + {6, "STT_TLS"}, + {10, "STT_LOOS"}, + {12, "STT_HIOS"}, + {13, "STT_LOPROC"}, + {15, "STT_HIPROC"}, } func (i SymType) String() string { return stringName(uint32(i), sttStrings, false) } @@ -684,10 +684,10 @@ const ( ) var stvStrings = []intName{ - intName{0x0, "STV_DEFAULT"}, - intName{0x1, "STV_INTERNAL"}, - intName{0x2, "STV_HIDDEN"}, - intName{0x3, "STV_PROTECTED"}, + {0x0, "STV_DEFAULT"}, + {0x1, "STV_INTERNAL"}, + {0x2, "STV_HIDDEN"}, + {0x3, "STV_PROTECTED"}, } func (i SymVis) String() string { return stringName(uint32(i), stvStrings, false) } @@ -728,30 +728,30 @@ const ( ) var rx86_64Strings = []intName{ - intName{0, "R_X86_64_NONE"}, - intName{1, "R_X86_64_64"}, - intName{2, "R_X86_64_PC32"}, - intName{3, "R_X86_64_GOT32"}, - intName{4, "R_X86_64_PLT32"}, - intName{5, "R_X86_64_COPY"}, - intName{6, "R_X86_64_GLOB_DAT"}, - intName{7, "R_X86_64_JMP_SLOT"}, - intName{8, "R_X86_64_RELATIVE"}, - intName{9, "R_X86_64_GOTPCREL"}, - intName{10, "R_X86_64_32"}, - intName{11, "R_X86_64_32S"}, - intName{12, "R_X86_64_16"}, - intName{13, "R_X86_64_PC16"}, - intName{14, "R_X86_64_8"}, - intName{15, "R_X86_64_PC8"}, - intName{16, "R_X86_64_DTPMOD64"}, - intName{17, "R_X86_64_DTPOFF64"}, - intName{18, "R_X86_64_TPOFF64"}, - intName{19, "R_X86_64_TLSGD"}, - intName{20, "R_X86_64_TLSLD"}, - intName{21, "R_X86_64_DTPOFF32"}, - intName{22, "R_X86_64_GOTTPOFF"}, - intName{23, "R_X86_64_TPOFF32"}, + {0, "R_X86_64_NONE"}, + {1, "R_X86_64_64"}, + {2, "R_X86_64_PC32"}, + {3, "R_X86_64_GOT32"}, + {4, "R_X86_64_PLT32"}, + {5, "R_X86_64_COPY"}, + {6, "R_X86_64_GLOB_DAT"}, + {7, "R_X86_64_JMP_SLOT"}, + {8, "R_X86_64_RELATIVE"}, + {9, "R_X86_64_GOTPCREL"}, + {10, "R_X86_64_32"}, + {11, "R_X86_64_32S"}, + {12, "R_X86_64_16"}, + {13, "R_X86_64_PC16"}, + {14, "R_X86_64_8"}, + {15, "R_X86_64_PC8"}, + {16, "R_X86_64_DTPMOD64"}, + {17, "R_X86_64_DTPOFF64"}, + {18, "R_X86_64_TPOFF64"}, + {19, "R_X86_64_TLSGD"}, + {20, "R_X86_64_TLSLD"}, + {21, "R_X86_64_DTPOFF32"}, + {22, "R_X86_64_GOTTPOFF"}, + {23, "R_X86_64_TPOFF32"}, } func (i R_X86_64) String() string { return stringName(uint32(i), rx86_64Strings, false) } @@ -792,34 +792,34 @@ const ( ) var ralphaStrings = []intName{ - intName{0, "R_ALPHA_NONE"}, - intName{1, "R_ALPHA_REFLONG"}, - intName{2, "R_ALPHA_REFQUAD"}, - intName{3, "R_ALPHA_GPREL32"}, - intName{4, "R_ALPHA_LITERAL"}, - intName{5, "R_ALPHA_LITUSE"}, - intName{6, "R_ALPHA_GPDISP"}, - intName{7, "R_ALPHA_BRADDR"}, - intName{8, "R_ALPHA_HINT"}, - intName{9, "R_ALPHA_SREL16"}, - intName{10, "R_ALPHA_SREL32"}, - intName{11, "R_ALPHA_SREL64"}, - intName{12, "R_ALPHA_OP_PUSH"}, - intName{13, "R_ALPHA_OP_STORE"}, - intName{14, "R_ALPHA_OP_PSUB"}, - intName{15, "R_ALPHA_OP_PRSHIFT"}, - intName{16, "R_ALPHA_GPVALUE"}, - intName{17, "R_ALPHA_GPRELHIGH"}, - intName{18, "R_ALPHA_GPRELLOW"}, - intName{19, "R_ALPHA_IMMED_GP_16"}, - intName{20, "R_ALPHA_IMMED_GP_HI32"}, - intName{21, "R_ALPHA_IMMED_SCN_HI32"}, - intName{22, "R_ALPHA_IMMED_BR_HI32"}, - intName{23, "R_ALPHA_IMMED_LO32"}, - intName{24, "R_ALPHA_COPY"}, - intName{25, "R_ALPHA_GLOB_DAT"}, - intName{26, "R_ALPHA_JMP_SLOT"}, - intName{27, "R_ALPHA_RELATIVE"}, + {0, "R_ALPHA_NONE"}, + {1, "R_ALPHA_REFLONG"}, + {2, "R_ALPHA_REFQUAD"}, + {3, "R_ALPHA_GPREL32"}, + {4, "R_ALPHA_LITERAL"}, + {5, "R_ALPHA_LITUSE"}, + {6, "R_ALPHA_GPDISP"}, + {7, "R_ALPHA_BRADDR"}, + {8, "R_ALPHA_HINT"}, + {9, "R_ALPHA_SREL16"}, + {10, "R_ALPHA_SREL32"}, + {11, "R_ALPHA_SREL64"}, + {12, "R_ALPHA_OP_PUSH"}, + {13, "R_ALPHA_OP_STORE"}, + {14, "R_ALPHA_OP_PSUB"}, + {15, "R_ALPHA_OP_PRSHIFT"}, + {16, "R_ALPHA_GPVALUE"}, + {17, "R_ALPHA_GPRELHIGH"}, + {18, "R_ALPHA_GPRELLOW"}, + {19, "R_ALPHA_IMMED_GP_16"}, + {20, "R_ALPHA_IMMED_GP_HI32"}, + {21, "R_ALPHA_IMMED_SCN_HI32"}, + {22, "R_ALPHA_IMMED_BR_HI32"}, + {23, "R_ALPHA_IMMED_LO32"}, + {24, "R_ALPHA_COPY"}, + {25, "R_ALPHA_GLOB_DAT"}, + {26, "R_ALPHA_JMP_SLOT"}, + {27, "R_ALPHA_RELATIVE"}, } func (i R_ALPHA) String() string { return stringName(uint32(i), ralphaStrings, false) } @@ -865,39 +865,39 @@ const ( ) var rarmStrings = []intName{ - intName{0, "R_ARM_NONE"}, - intName{1, "R_ARM_PC24"}, - intName{2, "R_ARM_ABS32"}, - intName{3, "R_ARM_REL32"}, - intName{4, "R_ARM_PC13"}, - intName{5, "R_ARM_ABS16"}, - intName{6, "R_ARM_ABS12"}, - intName{7, "R_ARM_THM_ABS5"}, - intName{8, "R_ARM_ABS8"}, - intName{9, "R_ARM_SBREL32"}, - intName{10, "R_ARM_THM_PC22"}, - intName{11, "R_ARM_THM_PC8"}, - intName{12, "R_ARM_AMP_VCALL9"}, - intName{13, "R_ARM_SWI24"}, - intName{14, "R_ARM_THM_SWI8"}, - intName{15, "R_ARM_XPC25"}, - intName{16, "R_ARM_THM_XPC22"}, - intName{20, "R_ARM_COPY"}, - intName{21, "R_ARM_GLOB_DAT"}, - intName{22, "R_ARM_JUMP_SLOT"}, - intName{23, "R_ARM_RELATIVE"}, - intName{24, "R_ARM_GOTOFF"}, - intName{25, "R_ARM_GOTPC"}, - intName{26, "R_ARM_GOT32"}, - intName{27, "R_ARM_PLT32"}, - intName{100, "R_ARM_GNU_VTENTRY"}, - intName{101, "R_ARM_GNU_VTINHERIT"}, - intName{250, "R_ARM_RSBREL32"}, - intName{251, "R_ARM_THM_RPC22"}, - intName{252, "R_ARM_RREL32"}, - intName{253, "R_ARM_RABS32"}, - intName{254, "R_ARM_RPC24"}, - intName{255, "R_ARM_RBASE"}, + {0, "R_ARM_NONE"}, + {1, "R_ARM_PC24"}, + {2, "R_ARM_ABS32"}, + {3, "R_ARM_REL32"}, + {4, "R_ARM_PC13"}, + {5, "R_ARM_ABS16"}, + {6, "R_ARM_ABS12"}, + {7, "R_ARM_THM_ABS5"}, + {8, "R_ARM_ABS8"}, + {9, "R_ARM_SBREL32"}, + {10, "R_ARM_THM_PC22"}, + {11, "R_ARM_THM_PC8"}, + {12, "R_ARM_AMP_VCALL9"}, + {13, "R_ARM_SWI24"}, + {14, "R_ARM_THM_SWI8"}, + {15, "R_ARM_XPC25"}, + {16, "R_ARM_THM_XPC22"}, + {20, "R_ARM_COPY"}, + {21, "R_ARM_GLOB_DAT"}, + {22, "R_ARM_JUMP_SLOT"}, + {23, "R_ARM_RELATIVE"}, + {24, "R_ARM_GOTOFF"}, + {25, "R_ARM_GOTPC"}, + {26, "R_ARM_GOT32"}, + {27, "R_ARM_PLT32"}, + {100, "R_ARM_GNU_VTENTRY"}, + {101, "R_ARM_GNU_VTINHERIT"}, + {250, "R_ARM_RSBREL32"}, + {251, "R_ARM_THM_RPC22"}, + {252, "R_ARM_RREL32"}, + {253, "R_ARM_RABS32"}, + {254, "R_ARM_RPC24"}, + {255, "R_ARM_RBASE"}, } func (i R_ARM) String() string { return stringName(uint32(i), rarmStrings, false) } @@ -941,37 +941,37 @@ const ( ) var r386Strings = []intName{ - intName{0, "R_386_NONE"}, - intName{1, "R_386_32"}, - intName{2, "R_386_PC32"}, - intName{3, "R_386_GOT32"}, - intName{4, "R_386_PLT32"}, - intName{5, "R_386_COPY"}, - intName{6, "R_386_GLOB_DAT"}, - intName{7, "R_386_JMP_SLOT"}, - intName{8, "R_386_RELATIVE"}, - intName{9, "R_386_GOTOFF"}, - intName{10, "R_386_GOTPC"}, - intName{14, "R_386_TLS_TPOFF"}, - intName{15, "R_386_TLS_IE"}, - intName{16, "R_386_TLS_GOTIE"}, - intName{17, "R_386_TLS_LE"}, - intName{18, "R_386_TLS_GD"}, - intName{19, "R_386_TLS_LDM"}, - intName{24, "R_386_TLS_GD_32"}, - intName{25, "R_386_TLS_GD_PUSH"}, - intName{26, "R_386_TLS_GD_CALL"}, - intName{27, "R_386_TLS_GD_POP"}, - intName{28, "R_386_TLS_LDM_32"}, - intName{29, "R_386_TLS_LDM_PUSH"}, - intName{30, "R_386_TLS_LDM_CALL"}, - intName{31, "R_386_TLS_LDM_POP"}, - intName{32, "R_386_TLS_LDO_32"}, - intName{33, "R_386_TLS_IE_32"}, - intName{34, "R_386_TLS_LE_32"}, - intName{35, "R_386_TLS_DTPMOD32"}, - intName{36, "R_386_TLS_DTPOFF32"}, - intName{37, "R_386_TLS_TPOFF32"}, + {0, "R_386_NONE"}, + {1, "R_386_32"}, + {2, "R_386_PC32"}, + {3, "R_386_GOT32"}, + {4, "R_386_PLT32"}, + {5, "R_386_COPY"}, + {6, "R_386_GLOB_DAT"}, + {7, "R_386_JMP_SLOT"}, + {8, "R_386_RELATIVE"}, + {9, "R_386_GOTOFF"}, + {10, "R_386_GOTPC"}, + {14, "R_386_TLS_TPOFF"}, + {15, "R_386_TLS_IE"}, + {16, "R_386_TLS_GOTIE"}, + {17, "R_386_TLS_LE"}, + {18, "R_386_TLS_GD"}, + {19, "R_386_TLS_LDM"}, + {24, "R_386_TLS_GD_32"}, + {25, "R_386_TLS_GD_PUSH"}, + {26, "R_386_TLS_GD_CALL"}, + {27, "R_386_TLS_GD_POP"}, + {28, "R_386_TLS_LDM_32"}, + {29, "R_386_TLS_LDM_PUSH"}, + {30, "R_386_TLS_LDM_CALL"}, + {31, "R_386_TLS_LDM_POP"}, + {32, "R_386_TLS_LDO_32"}, + {33, "R_386_TLS_IE_32"}, + {34, "R_386_TLS_LE_32"}, + {35, "R_386_TLS_DTPMOD32"}, + {36, "R_386_TLS_DTPOFF32"}, + {37, "R_386_TLS_TPOFF32"}, } func (i R_386) String() string { return stringName(uint32(i), r386Strings, false) } @@ -1061,85 +1061,85 @@ const ( ) var rppcStrings = []intName{ - intName{0, "R_PPC_NONE"}, - intName{1, "R_PPC_ADDR32"}, - intName{2, "R_PPC_ADDR24"}, - intName{3, "R_PPC_ADDR16"}, - intName{4, "R_PPC_ADDR16_LO"}, - intName{5, "R_PPC_ADDR16_HI"}, - intName{6, "R_PPC_ADDR16_HA"}, - intName{7, "R_PPC_ADDR14"}, - intName{8, "R_PPC_ADDR14_BRTAKEN"}, - intName{9, "R_PPC_ADDR14_BRNTAKEN"}, - intName{10, "R_PPC_REL24"}, - intName{11, "R_PPC_REL14"}, - intName{12, "R_PPC_REL14_BRTAKEN"}, - intName{13, "R_PPC_REL14_BRNTAKEN"}, - intName{14, "R_PPC_GOT16"}, - intName{15, "R_PPC_GOT16_LO"}, - intName{16, "R_PPC_GOT16_HI"}, - intName{17, "R_PPC_GOT16_HA"}, - intName{18, "R_PPC_PLTREL24"}, - intName{19, "R_PPC_COPY"}, - intName{20, "R_PPC_GLOB_DAT"}, - intName{21, "R_PPC_JMP_SLOT"}, - intName{22, "R_PPC_RELATIVE"}, - intName{23, "R_PPC_LOCAL24PC"}, - intName{24, "R_PPC_UADDR32"}, - intName{25, "R_PPC_UADDR16"}, - intName{26, "R_PPC_REL32"}, - intName{27, "R_PPC_PLT32"}, - intName{28, "R_PPC_PLTREL32"}, - intName{29, "R_PPC_PLT16_LO"}, - intName{30, "R_PPC_PLT16_HI"}, - intName{31, "R_PPC_PLT16_HA"}, - intName{32, "R_PPC_SDAREL16"}, - intName{33, "R_PPC_SECTOFF"}, - intName{34, "R_PPC_SECTOFF_LO"}, - intName{35, "R_PPC_SECTOFF_HI"}, - intName{36, "R_PPC_SECTOFF_HA"}, - - intName{67, "R_PPC_TLS"}, - intName{68, "R_PPC_DTPMOD32"}, - intName{69, "R_PPC_TPREL16"}, - intName{70, "R_PPC_TPREL16_LO"}, - intName{71, "R_PPC_TPREL16_HI"}, - intName{72, "R_PPC_TPREL16_HA"}, - intName{73, "R_PPC_TPREL32"}, - intName{74, "R_PPC_DTPREL16"}, - intName{75, "R_PPC_DTPREL16_LO"}, - intName{76, "R_PPC_DTPREL16_HI"}, - intName{77, "R_PPC_DTPREL16_HA"}, - intName{78, "R_PPC_DTPREL32"}, - intName{79, "R_PPC_GOT_TLSGD16"}, - intName{80, "R_PPC_GOT_TLSGD16_LO"}, - intName{81, "R_PPC_GOT_TLSGD16_HI"}, - intName{82, "R_PPC_GOT_TLSGD16_HA"}, - intName{83, "R_PPC_GOT_TLSLD16"}, - intName{84, "R_PPC_GOT_TLSLD16_LO"}, - intName{85, "R_PPC_GOT_TLSLD16_HI"}, - intName{86, "R_PPC_GOT_TLSLD16_HA"}, - intName{87, "R_PPC_GOT_TPREL16"}, - intName{88, "R_PPC_GOT_TPREL16_LO"}, - intName{89, "R_PPC_GOT_TPREL16_HI"}, - intName{90, "R_PPC_GOT_TPREL16_HA"}, - - intName{101, "R_PPC_EMB_NADDR32"}, - intName{102, "R_PPC_EMB_NADDR16"}, - intName{103, "R_PPC_EMB_NADDR16_LO"}, - intName{104, "R_PPC_EMB_NADDR16_HI"}, - intName{105, "R_PPC_EMB_NADDR16_HA"}, - intName{106, "R_PPC_EMB_SDAI16"}, - intName{107, "R_PPC_EMB_SDA2I16"}, - intName{108, "R_PPC_EMB_SDA2REL"}, - intName{109, "R_PPC_EMB_SDA21"}, - intName{110, "R_PPC_EMB_MRKREF"}, - intName{111, "R_PPC_EMB_RELSEC16"}, - intName{112, "R_PPC_EMB_RELST_LO"}, - intName{113, "R_PPC_EMB_RELST_HI"}, - intName{114, "R_PPC_EMB_RELST_HA"}, - intName{115, "R_PPC_EMB_BIT_FLD"}, - intName{116, "R_PPC_EMB_RELSDA"}, + {0, "R_PPC_NONE"}, + {1, "R_PPC_ADDR32"}, + {2, "R_PPC_ADDR24"}, + {3, "R_PPC_ADDR16"}, + {4, "R_PPC_ADDR16_LO"}, + {5, "R_PPC_ADDR16_HI"}, + {6, "R_PPC_ADDR16_HA"}, + {7, "R_PPC_ADDR14"}, + {8, "R_PPC_ADDR14_BRTAKEN"}, + {9, "R_PPC_ADDR14_BRNTAKEN"}, + {10, "R_PPC_REL24"}, + {11, "R_PPC_REL14"}, + {12, "R_PPC_REL14_BRTAKEN"}, + {13, "R_PPC_REL14_BRNTAKEN"}, + {14, "R_PPC_GOT16"}, + {15, "R_PPC_GOT16_LO"}, + {16, "R_PPC_GOT16_HI"}, + {17, "R_PPC_GOT16_HA"}, + {18, "R_PPC_PLTREL24"}, + {19, "R_PPC_COPY"}, + {20, "R_PPC_GLOB_DAT"}, + {21, "R_PPC_JMP_SLOT"}, + {22, "R_PPC_RELATIVE"}, + {23, "R_PPC_LOCAL24PC"}, + {24, "R_PPC_UADDR32"}, + {25, "R_PPC_UADDR16"}, + {26, "R_PPC_REL32"}, + {27, "R_PPC_PLT32"}, + {28, "R_PPC_PLTREL32"}, + {29, "R_PPC_PLT16_LO"}, + {30, "R_PPC_PLT16_HI"}, + {31, "R_PPC_PLT16_HA"}, + {32, "R_PPC_SDAREL16"}, + {33, "R_PPC_SECTOFF"}, + {34, "R_PPC_SECTOFF_LO"}, + {35, "R_PPC_SECTOFF_HI"}, + {36, "R_PPC_SECTOFF_HA"}, + + {67, "R_PPC_TLS"}, + {68, "R_PPC_DTPMOD32"}, + {69, "R_PPC_TPREL16"}, + {70, "R_PPC_TPREL16_LO"}, + {71, "R_PPC_TPREL16_HI"}, + {72, "R_PPC_TPREL16_HA"}, + {73, "R_PPC_TPREL32"}, + {74, "R_PPC_DTPREL16"}, + {75, "R_PPC_DTPREL16_LO"}, + {76, "R_PPC_DTPREL16_HI"}, + {77, "R_PPC_DTPREL16_HA"}, + {78, "R_PPC_DTPREL32"}, + {79, "R_PPC_GOT_TLSGD16"}, + {80, "R_PPC_GOT_TLSGD16_LO"}, + {81, "R_PPC_GOT_TLSGD16_HI"}, + {82, "R_PPC_GOT_TLSGD16_HA"}, + {83, "R_PPC_GOT_TLSLD16"}, + {84, "R_PPC_GOT_TLSLD16_LO"}, + {85, "R_PPC_GOT_TLSLD16_HI"}, + {86, "R_PPC_GOT_TLSLD16_HA"}, + {87, "R_PPC_GOT_TPREL16"}, + {88, "R_PPC_GOT_TPREL16_LO"}, + {89, "R_PPC_GOT_TPREL16_HI"}, + {90, "R_PPC_GOT_TPREL16_HA"}, + + {101, "R_PPC_EMB_NADDR32"}, + {102, "R_PPC_EMB_NADDR16"}, + {103, "R_PPC_EMB_NADDR16_LO"}, + {104, "R_PPC_EMB_NADDR16_HI"}, + {105, "R_PPC_EMB_NADDR16_HA"}, + {106, "R_PPC_EMB_SDAI16"}, + {107, "R_PPC_EMB_SDA2I16"}, + {108, "R_PPC_EMB_SDA2REL"}, + {109, "R_PPC_EMB_SDA21"}, + {110, "R_PPC_EMB_MRKREF"}, + {111, "R_PPC_EMB_RELSEC16"}, + {112, "R_PPC_EMB_RELST_LO"}, + {113, "R_PPC_EMB_RELST_HI"}, + {114, "R_PPC_EMB_RELST_HA"}, + {115, "R_PPC_EMB_BIT_FLD"}, + {116, "R_PPC_EMB_RELSDA"}, } func (i R_PPC) String() string { return stringName(uint32(i), rppcStrings, false) } @@ -1208,62 +1208,62 @@ const ( ) var rsparcStrings = []intName{ - intName{0, "R_SPARC_NONE"}, - intName{1, "R_SPARC_8"}, - intName{2, "R_SPARC_16"}, - intName{3, "R_SPARC_32"}, - intName{4, "R_SPARC_DISP8"}, - intName{5, "R_SPARC_DISP16"}, - intName{6, "R_SPARC_DISP32"}, - intName{7, "R_SPARC_WDISP30"}, - intName{8, "R_SPARC_WDISP22"}, - intName{9, "R_SPARC_HI22"}, - intName{10, "R_SPARC_22"}, - intName{11, "R_SPARC_13"}, - intName{12, "R_SPARC_LO10"}, - intName{13, "R_SPARC_GOT10"}, - intName{14, "R_SPARC_GOT13"}, - intName{15, "R_SPARC_GOT22"}, - intName{16, "R_SPARC_PC10"}, - intName{17, "R_SPARC_PC22"}, - intName{18, "R_SPARC_WPLT30"}, - intName{19, "R_SPARC_COPY"}, - intName{20, "R_SPARC_GLOB_DAT"}, - intName{21, "R_SPARC_JMP_SLOT"}, - intName{22, "R_SPARC_RELATIVE"}, - intName{23, "R_SPARC_UA32"}, - intName{24, "R_SPARC_PLT32"}, - intName{25, "R_SPARC_HIPLT22"}, - intName{26, "R_SPARC_LOPLT10"}, - intName{27, "R_SPARC_PCPLT32"}, - intName{28, "R_SPARC_PCPLT22"}, - intName{29, "R_SPARC_PCPLT10"}, - intName{30, "R_SPARC_10"}, - intName{31, "R_SPARC_11"}, - intName{32, "R_SPARC_64"}, - intName{33, "R_SPARC_OLO10"}, - intName{34, "R_SPARC_HH22"}, - intName{35, "R_SPARC_HM10"}, - intName{36, "R_SPARC_LM22"}, - intName{37, "R_SPARC_PC_HH22"}, - intName{38, "R_SPARC_PC_HM10"}, - intName{39, "R_SPARC_PC_LM22"}, - intName{40, "R_SPARC_WDISP16"}, - intName{41, "R_SPARC_WDISP19"}, - intName{42, "R_SPARC_GLOB_JMP"}, - intName{43, "R_SPARC_7"}, - intName{44, "R_SPARC_5"}, - intName{45, "R_SPARC_6"}, - intName{46, "R_SPARC_DISP64"}, - intName{47, "R_SPARC_PLT64"}, - intName{48, "R_SPARC_HIX22"}, - intName{49, "R_SPARC_LOX10"}, - intName{50, "R_SPARC_H44"}, - intName{51, "R_SPARC_M44"}, - intName{52, "R_SPARC_L44"}, - intName{53, "R_SPARC_REGISTER"}, - intName{54, "R_SPARC_UA64"}, - intName{55, "R_SPARC_UA16"}, + {0, "R_SPARC_NONE"}, + {1, "R_SPARC_8"}, + {2, "R_SPARC_16"}, + {3, "R_SPARC_32"}, + {4, "R_SPARC_DISP8"}, + {5, "R_SPARC_DISP16"}, + {6, "R_SPARC_DISP32"}, + {7, "R_SPARC_WDISP30"}, + {8, "R_SPARC_WDISP22"}, + {9, "R_SPARC_HI22"}, + {10, "R_SPARC_22"}, + {11, "R_SPARC_13"}, + {12, "R_SPARC_LO10"}, + {13, "R_SPARC_GOT10"}, + {14, "R_SPARC_GOT13"}, + {15, "R_SPARC_GOT22"}, + {16, "R_SPARC_PC10"}, + {17, "R_SPARC_PC22"}, + {18, "R_SPARC_WPLT30"}, + {19, "R_SPARC_COPY"}, + {20, "R_SPARC_GLOB_DAT"}, + {21, "R_SPARC_JMP_SLOT"}, + {22, "R_SPARC_RELATIVE"}, + {23, "R_SPARC_UA32"}, + {24, "R_SPARC_PLT32"}, + {25, "R_SPARC_HIPLT22"}, + {26, "R_SPARC_LOPLT10"}, + {27, "R_SPARC_PCPLT32"}, + {28, "R_SPARC_PCPLT22"}, + {29, "R_SPARC_PCPLT10"}, + {30, "R_SPARC_10"}, + {31, "R_SPARC_11"}, + {32, "R_SPARC_64"}, + {33, "R_SPARC_OLO10"}, + {34, "R_SPARC_HH22"}, + {35, "R_SPARC_HM10"}, + {36, "R_SPARC_LM22"}, + {37, "R_SPARC_PC_HH22"}, + {38, "R_SPARC_PC_HM10"}, + {39, "R_SPARC_PC_LM22"}, + {40, "R_SPARC_WDISP16"}, + {41, "R_SPARC_WDISP19"}, + {42, "R_SPARC_GLOB_JMP"}, + {43, "R_SPARC_7"}, + {44, "R_SPARC_5"}, + {45, "R_SPARC_6"}, + {46, "R_SPARC_DISP64"}, + {47, "R_SPARC_PLT64"}, + {48, "R_SPARC_HIX22"}, + {49, "R_SPARC_LOX10"}, + {50, "R_SPARC_H44"}, + {51, "R_SPARC_M44"}, + {52, "R_SPARC_L44"}, + {53, "R_SPARC_REGISTER"}, + {54, "R_SPARC_UA64"}, + {55, "R_SPARC_UA16"}, } func (i R_SPARC) String() string { return stringName(uint32(i), rsparcStrings, false) } @@ -1356,9 +1356,12 @@ type Sym32 struct { const Sym32Size = 16 -func ST_BIND(info uint8) SymBind { return SymBind(info >> 4) } -func ST_TYPE(bind SymBind, typ SymType) uint8 { return uint8(bind)<<4 | uint8(typ)&0xf } -func ST_VISIBILITY(other uint8) SymVis { return SymVis(other & 3) } +func ST_BIND(info uint8) SymBind { return SymBind(info >> 4) } +func ST_TYPE(info uint8) SymType { return SymType(info & 0xF) } +func ST_INFO(bind SymBind, typ SymType) uint8 { + return uint8(bind)<<4 | uint8(typ)&0xf +} +func ST_VISIBILITY(other uint8) SymVis { return SymVis(other & 3) } /* * ELF64 diff --git a/src/pkg/debug/elf/elf_test.go b/src/pkg/debug/elf/elf_test.go index 6f827faf0..67b961b5c 100644 --- a/src/pkg/debug/elf/elf_test.go +++ b/src/pkg/debug/elf/elf_test.go @@ -15,28 +15,28 @@ type nameTest struct { } var nameTests = []nameTest{ - nameTest{ELFOSABI_LINUX, "ELFOSABI_LINUX"}, - nameTest{ET_EXEC, "ET_EXEC"}, - nameTest{EM_860, "EM_860"}, - nameTest{SHN_LOPROC, "SHN_LOPROC"}, - nameTest{SHT_PROGBITS, "SHT_PROGBITS"}, - nameTest{SHF_MERGE + SHF_TLS, "SHF_MERGE+SHF_TLS"}, - nameTest{PT_LOAD, "PT_LOAD"}, - nameTest{PF_W + PF_R + 0x50, "PF_W+PF_R+0x50"}, - nameTest{DT_SYMBOLIC, "DT_SYMBOLIC"}, - nameTest{DF_BIND_NOW, "DF_BIND_NOW"}, - nameTest{NT_FPREGSET, "NT_FPREGSET"}, - nameTest{STB_GLOBAL, "STB_GLOBAL"}, - nameTest{STT_COMMON, "STT_COMMON"}, - nameTest{STV_HIDDEN, "STV_HIDDEN"}, - nameTest{R_X86_64_PC32, "R_X86_64_PC32"}, - nameTest{R_ALPHA_OP_PUSH, "R_ALPHA_OP_PUSH"}, - nameTest{R_ARM_THM_ABS5, "R_ARM_THM_ABS5"}, - nameTest{R_386_GOT32, "R_386_GOT32"}, - nameTest{R_PPC_GOT16_HI, "R_PPC_GOT16_HI"}, - nameTest{R_SPARC_GOT22, "R_SPARC_GOT22"}, - nameTest{ET_LOOS + 5, "ET_LOOS+5"}, - nameTest{ProgFlag(0x50), "0x50"}, + {ELFOSABI_LINUX, "ELFOSABI_LINUX"}, + {ET_EXEC, "ET_EXEC"}, + {EM_860, "EM_860"}, + {SHN_LOPROC, "SHN_LOPROC"}, + {SHT_PROGBITS, "SHT_PROGBITS"}, + {SHF_MERGE + SHF_TLS, "SHF_MERGE+SHF_TLS"}, + {PT_LOAD, "PT_LOAD"}, + {PF_W + PF_R + 0x50, "PF_W+PF_R+0x50"}, + {DT_SYMBOLIC, "DT_SYMBOLIC"}, + {DF_BIND_NOW, "DF_BIND_NOW"}, + {NT_FPREGSET, "NT_FPREGSET"}, + {STB_GLOBAL, "STB_GLOBAL"}, + {STT_COMMON, "STT_COMMON"}, + {STV_HIDDEN, "STV_HIDDEN"}, + {R_X86_64_PC32, "R_X86_64_PC32"}, + {R_ALPHA_OP_PUSH, "R_ALPHA_OP_PUSH"}, + {R_ARM_THM_ABS5, "R_ARM_THM_ABS5"}, + {R_386_GOT32, "R_386_GOT32"}, + {R_PPC_GOT16_HI, "R_PPC_GOT16_HI"}, + {R_SPARC_GOT22, "R_SPARC_GOT22"}, + {ET_LOOS + 5, "ET_LOOS+5"}, + {ProgFlag(0x50), "0x50"}, } func TestNames(t *testing.T) { diff --git a/src/pkg/debug/elf/file.go b/src/pkg/debug/elf/file.go index 568370b85..e69317a75 100644 --- a/src/pkg/debug/elf/file.go +++ b/src/pkg/debug/elf/file.go @@ -75,6 +75,15 @@ func (s *Section) Data() ([]byte, os.Error) { return dat[0:n], err } +// stringTable reads and returns the string table given by the +// specified link value. +func (f *File) stringTable(link uint32) ([]byte, os.Error) { + if link <= 0 || link >= uint32(len(f.Sections)) { + return nil, os.ErrorString("section has invalid string table link") + } + return f.Sections[link].Data() +} + // Open returns a new ReadSeeker reading the ELF section. func (s *Section) Open() io.ReadSeeker { return io.NewSectionReader(s.sr, 0, 1<<63-1) } @@ -108,9 +117,9 @@ func (p *Prog) Open() io.ReadSeeker { return io.NewSectionReader(p.sr, 0, 1<<63- // A Symbol represents an entry in an ELF symbol table section. type Symbol struct { - Name uint32 + Name string Info, Other byte - Section uint32 + Section SectionIndex Value, Size uint64 } @@ -160,6 +169,17 @@ func (f *File) Close() os.Error { return err } +// SectionByType returns the first section in f with the +// given type, or nil if there is no such section. +func (f *File) SectionByType(typ SectionType) *Section { + for _, s := range f.Sections { + if s.Type == typ { + return s + } + } + return nil +} + // NewFile creates a new File for accessing an ELF binary in an underlying reader. // The ELF binary is expected to start at position 0 in the ReaderAt. func NewFile(r io.ReaderAt) (*File, os.Error) { @@ -293,9 +313,8 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { } // Load section header string table. - s := f.Sections[shstrndx] - shstrtab := make([]byte, s.Size) - if _, err := r.ReadAt(shstrtab, int64(s.Offset)); err != nil { + shstrtab, err := f.Sections[shstrndx].Data() + if err != nil { return nil, err } for i, s := range f.Sections { @@ -309,25 +328,65 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { return f, nil } -func (f *File) getSymbols() ([]Symbol, os.Error) { +// getSymbols returns a slice of Symbols from parsing the symbol table +// with the given type. +func (f *File) getSymbols(typ SectionType) ([]Symbol, os.Error) { switch f.Class { case ELFCLASS64: - return f.getSymbols64() + return f.getSymbols64(typ) + + case ELFCLASS32: + return f.getSymbols32(typ) } return nil, os.ErrorString("not implemented") } -// GetSymbols returns a slice of Symbols from parsing the symbol table. -func (f *File) getSymbols64() ([]Symbol, os.Error) { - var symtabSection *Section - for _, section := range f.Sections { - if section.Type == SHT_SYMTAB { - symtabSection = section - break - } +func (f *File) getSymbols32(typ SectionType) ([]Symbol, os.Error) { + symtabSection := f.SectionByType(typ) + if symtabSection == nil { + return nil, os.ErrorString("no symbol section") + } + + data, err := symtabSection.Data() + if err != nil { + return nil, os.ErrorString("cannot load symbol section") + } + symtab := bytes.NewBuffer(data) + if symtab.Len()%Sym32Size != 0 { + return nil, os.ErrorString("length of symbol section is not a multiple of SymSize") + } + + strdata, err := f.stringTable(symtabSection.Link) + if err != nil { + return nil, os.ErrorString("cannot load string table section") + } + + // The first entry is all zeros. + var skip [Sym32Size]byte + symtab.Read(skip[0:]) + + symbols := make([]Symbol, symtab.Len()/Sym32Size) + + i := 0 + var sym Sym32 + for symtab.Len() > 0 { + binary.Read(symtab, f.ByteOrder, &sym) + str, _ := getString(strdata, int(sym.Name)) + symbols[i].Name = str + symbols[i].Info = sym.Info + symbols[i].Other = sym.Other + symbols[i].Section = SectionIndex(sym.Shndx) + symbols[i].Value = uint64(sym.Value) + symbols[i].Size = uint64(sym.Size) + i++ } + return symbols, nil +} + +func (f *File) getSymbols64(typ SectionType) ([]Symbol, os.Error) { + symtabSection := f.SectionByType(typ) if symtabSection == nil { return nil, os.ErrorString("no symbol section") } @@ -341,6 +400,11 @@ func (f *File) getSymbols64() ([]Symbol, os.Error) { return nil, os.ErrorString("length of symbol section is not a multiple of Sym64Size") } + strdata, err := f.stringTable(symtabSection.Link) + if err != nil { + return nil, os.ErrorString("cannot load string table section") + } + // The first entry is all zeros. var skip [Sym64Size]byte symtab.Read(skip[0:]) @@ -351,10 +415,11 @@ func (f *File) getSymbols64() ([]Symbol, os.Error) { var sym Sym64 for symtab.Len() > 0 { binary.Read(symtab, f.ByteOrder, &sym) - symbols[i].Name = sym.Name + str, _ := getString(strdata, int(sym.Name)) + symbols[i].Name = str symbols[i].Info = sym.Info symbols[i].Other = sym.Other - symbols[i].Section = uint32(sym.Shndx) + symbols[i].Section = SectionIndex(sym.Shndx) symbols[i].Value = sym.Value symbols[i].Size = sym.Size i++ @@ -403,7 +468,7 @@ func (f *File) applyRelocationsAMD64(dst []byte, rels []byte) os.Error { return os.ErrorString("length of relocation section is not a multiple of Sym64Size") } - symbols, err := f.getSymbols() + symbols, err := f.getSymbols(SHT_SYMTAB) if err != nil { return err } @@ -478,3 +543,63 @@ func (f *File) DWARF() (*dwarf.Data, os.Error) { abbrev, info, str := dat[0], dat[1], dat[2] return dwarf.New(abbrev, nil, nil, info, nil, nil, nil, str) } + +// ImportedSymbols returns the names of all symbols +// referred to by the binary f that are expected to be +// satisfied by other libraries at dynamic load time. +// It does not return weak symbols. +func (f *File) ImportedSymbols() ([]string, os.Error) { + sym, err := f.getSymbols(SHT_DYNSYM) + if err != nil { + return nil, err + } + var all []string + for _, s := range sym { + if ST_BIND(s.Info) == STB_GLOBAL && s.Section == SHN_UNDEF { + all = append(all, s.Name) + } + } + return all, nil +} + +// ImportedLibraries returns the names of all libraries +// referred to by the binary f that are expected to be +// linked with the binary at dynamic link time. +func (f *File) ImportedLibraries() ([]string, os.Error) { + ds := f.SectionByType(SHT_DYNAMIC) + if ds == nil { + // not dynamic, so no libraries + return nil, nil + } + d, err := ds.Data() + if err != nil { + return nil, err + } + str, err := f.stringTable(ds.Link) + if err != nil { + return nil, err + } + var all []string + for len(d) > 0 { + var tag DynTag + var value uint64 + switch f.Class { + case ELFCLASS32: + tag = DynTag(f.ByteOrder.Uint32(d[0:4])) + value = uint64(f.ByteOrder.Uint32(d[4:8])) + d = d[8:] + case ELFCLASS64: + tag = DynTag(f.ByteOrder.Uint64(d[0:8])) + value = f.ByteOrder.Uint64(d[8:16]) + d = d[16:] + } + if tag == DT_NEEDED { + s, ok := getString(str, int(value)) + if ok { + all = append(all, s) + } + } + } + + return all, nil +} diff --git a/src/pkg/debug/elf/file_test.go b/src/pkg/debug/elf/file_test.go index 49adc4dc7..84068ea12 100644 --- a/src/pkg/debug/elf/file_test.go +++ b/src/pkg/debug/elf/file_test.go @@ -18,83 +18,83 @@ type fileTest struct { } var fileTests = []fileTest{ - fileTest{ + { "testdata/gcc-386-freebsd-exec", FileHeader{ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ELFOSABI_FREEBSD, 0, binary.LittleEndian, ET_EXEC, EM_386}, []SectionHeader{ - SectionHeader{"", SHT_NULL, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, - SectionHeader{".interp", SHT_PROGBITS, SHF_ALLOC, 0x80480d4, 0xd4, 0x15, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".hash", SHT_HASH, SHF_ALLOC, 0x80480ec, 0xec, 0x90, 0x3, 0x0, 0x4, 0x4}, - SectionHeader{".dynsym", SHT_DYNSYM, SHF_ALLOC, 0x804817c, 0x17c, 0x110, 0x4, 0x1, 0x4, 0x10}, - SectionHeader{".dynstr", SHT_STRTAB, SHF_ALLOC, 0x804828c, 0x28c, 0xbb, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".rel.plt", SHT_REL, SHF_ALLOC, 0x8048348, 0x348, 0x20, 0x3, 0x7, 0x4, 0x8}, - SectionHeader{".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x8048368, 0x368, 0x11, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".plt", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x804837c, 0x37c, 0x50, 0x0, 0x0, 0x4, 0x4}, - SectionHeader{".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x80483cc, 0x3cc, 0x180, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x804854c, 0x54c, 0xc, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".rodata", SHT_PROGBITS, SHF_ALLOC, 0x8048558, 0x558, 0xa3, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".data", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80495fc, 0x5fc, 0xc, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".eh_frame", SHT_PROGBITS, SHF_ALLOC, 0x8049608, 0x608, 0x4, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".dynamic", SHT_DYNAMIC, SHF_WRITE + SHF_ALLOC, 0x804960c, 0x60c, 0x98, 0x4, 0x0, 0x4, 0x8}, - SectionHeader{".ctors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496a4, 0x6a4, 0x8, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".dtors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496ac, 0x6ac, 0x8, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".jcr", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496b4, 0x6b4, 0x4, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".got", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496b8, 0x6b8, 0x1c, 0x0, 0x0, 0x4, 0x4}, - SectionHeader{".bss", SHT_NOBITS, SHF_WRITE + SHF_ALLOC, 0x80496d4, 0x6d4, 0x20, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".comment", SHT_PROGBITS, 0x0, 0x0, 0x6d4, 0x12d, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_aranges", SHT_PROGBITS, 0x0, 0x0, 0x801, 0x20, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_pubnames", SHT_PROGBITS, 0x0, 0x0, 0x821, 0x1b, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_info", SHT_PROGBITS, 0x0, 0x0, 0x83c, 0x11d, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_abbrev", SHT_PROGBITS, 0x0, 0x0, 0x959, 0x41, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_line", SHT_PROGBITS, 0x0, 0x0, 0x99a, 0x35, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_frame", SHT_PROGBITS, 0x0, 0x0, 0x9d0, 0x30, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".debug_str", SHT_PROGBITS, 0x0, 0x0, 0xa00, 0xd, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".shstrtab", SHT_STRTAB, 0x0, 0x0, 0xa0d, 0xf8, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".symtab", SHT_SYMTAB, 0x0, 0x0, 0xfb8, 0x4b0, 0x1d, 0x38, 0x4, 0x10}, - SectionHeader{".strtab", SHT_STRTAB, 0x0, 0x0, 0x1468, 0x206, 0x0, 0x0, 0x1, 0x0}, + {"", SHT_NULL, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, + {".interp", SHT_PROGBITS, SHF_ALLOC, 0x80480d4, 0xd4, 0x15, 0x0, 0x0, 0x1, 0x0}, + {".hash", SHT_HASH, SHF_ALLOC, 0x80480ec, 0xec, 0x90, 0x3, 0x0, 0x4, 0x4}, + {".dynsym", SHT_DYNSYM, SHF_ALLOC, 0x804817c, 0x17c, 0x110, 0x4, 0x1, 0x4, 0x10}, + {".dynstr", SHT_STRTAB, SHF_ALLOC, 0x804828c, 0x28c, 0xbb, 0x0, 0x0, 0x1, 0x0}, + {".rel.plt", SHT_REL, SHF_ALLOC, 0x8048348, 0x348, 0x20, 0x3, 0x7, 0x4, 0x8}, + {".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x8048368, 0x368, 0x11, 0x0, 0x0, 0x4, 0x0}, + {".plt", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x804837c, 0x37c, 0x50, 0x0, 0x0, 0x4, 0x4}, + {".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x80483cc, 0x3cc, 0x180, 0x0, 0x0, 0x4, 0x0}, + {".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x804854c, 0x54c, 0xc, 0x0, 0x0, 0x4, 0x0}, + {".rodata", SHT_PROGBITS, SHF_ALLOC, 0x8048558, 0x558, 0xa3, 0x0, 0x0, 0x1, 0x0}, + {".data", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80495fc, 0x5fc, 0xc, 0x0, 0x0, 0x4, 0x0}, + {".eh_frame", SHT_PROGBITS, SHF_ALLOC, 0x8049608, 0x608, 0x4, 0x0, 0x0, 0x4, 0x0}, + {".dynamic", SHT_DYNAMIC, SHF_WRITE + SHF_ALLOC, 0x804960c, 0x60c, 0x98, 0x4, 0x0, 0x4, 0x8}, + {".ctors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496a4, 0x6a4, 0x8, 0x0, 0x0, 0x4, 0x0}, + {".dtors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496ac, 0x6ac, 0x8, 0x0, 0x0, 0x4, 0x0}, + {".jcr", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496b4, 0x6b4, 0x4, 0x0, 0x0, 0x4, 0x0}, + {".got", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496b8, 0x6b8, 0x1c, 0x0, 0x0, 0x4, 0x4}, + {".bss", SHT_NOBITS, SHF_WRITE + SHF_ALLOC, 0x80496d4, 0x6d4, 0x20, 0x0, 0x0, 0x4, 0x0}, + {".comment", SHT_PROGBITS, 0x0, 0x0, 0x6d4, 0x12d, 0x0, 0x0, 0x1, 0x0}, + {".debug_aranges", SHT_PROGBITS, 0x0, 0x0, 0x801, 0x20, 0x0, 0x0, 0x1, 0x0}, + {".debug_pubnames", SHT_PROGBITS, 0x0, 0x0, 0x821, 0x1b, 0x0, 0x0, 0x1, 0x0}, + {".debug_info", SHT_PROGBITS, 0x0, 0x0, 0x83c, 0x11d, 0x0, 0x0, 0x1, 0x0}, + {".debug_abbrev", SHT_PROGBITS, 0x0, 0x0, 0x959, 0x41, 0x0, 0x0, 0x1, 0x0}, + {".debug_line", SHT_PROGBITS, 0x0, 0x0, 0x99a, 0x35, 0x0, 0x0, 0x1, 0x0}, + {".debug_frame", SHT_PROGBITS, 0x0, 0x0, 0x9d0, 0x30, 0x0, 0x0, 0x4, 0x0}, + {".debug_str", SHT_PROGBITS, 0x0, 0x0, 0xa00, 0xd, 0x0, 0x0, 0x1, 0x0}, + {".shstrtab", SHT_STRTAB, 0x0, 0x0, 0xa0d, 0xf8, 0x0, 0x0, 0x1, 0x0}, + {".symtab", SHT_SYMTAB, 0x0, 0x0, 0xfb8, 0x4b0, 0x1d, 0x38, 0x4, 0x10}, + {".strtab", SHT_STRTAB, 0x0, 0x0, 0x1468, 0x206, 0x0, 0x0, 0x1, 0x0}, }, }, - fileTest{ + { "testdata/gcc-amd64-linux-exec", FileHeader{ELFCLASS64, ELFDATA2LSB, EV_CURRENT, ELFOSABI_NONE, 0, binary.LittleEndian, ET_EXEC, EM_X86_64}, []SectionHeader{ - SectionHeader{"", SHT_NULL, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, - SectionHeader{".interp", SHT_PROGBITS, SHF_ALLOC, 0x400200, 0x200, 0x1c, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".note.ABI-tag", SHT_NOTE, SHF_ALLOC, 0x40021c, 0x21c, 0x20, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".hash", SHT_HASH, SHF_ALLOC, 0x400240, 0x240, 0x24, 0x5, 0x0, 0x8, 0x4}, - SectionHeader{".gnu.hash", SHT_LOOS + 268435446, SHF_ALLOC, 0x400268, 0x268, 0x1c, 0x5, 0x0, 0x8, 0x0}, - SectionHeader{".dynsym", SHT_DYNSYM, SHF_ALLOC, 0x400288, 0x288, 0x60, 0x6, 0x1, 0x8, 0x18}, - SectionHeader{".dynstr", SHT_STRTAB, SHF_ALLOC, 0x4002e8, 0x2e8, 0x3d, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".gnu.version", SHT_HIOS, SHF_ALLOC, 0x400326, 0x326, 0x8, 0x5, 0x0, 0x2, 0x2}, - SectionHeader{".gnu.version_r", SHT_LOOS + 268435454, SHF_ALLOC, 0x400330, 0x330, 0x20, 0x6, 0x1, 0x8, 0x0}, - SectionHeader{".rela.dyn", SHT_RELA, SHF_ALLOC, 0x400350, 0x350, 0x18, 0x5, 0x0, 0x8, 0x18}, - SectionHeader{".rela.plt", SHT_RELA, SHF_ALLOC, 0x400368, 0x368, 0x30, 0x5, 0xc, 0x8, 0x18}, - SectionHeader{".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x400398, 0x398, 0x18, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".plt", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x4003b0, 0x3b0, 0x30, 0x0, 0x0, 0x4, 0x10}, - SectionHeader{".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x4003e0, 0x3e0, 0x1b4, 0x0, 0x0, 0x10, 0x0}, - SectionHeader{".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x400594, 0x594, 0xe, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".rodata", SHT_PROGBITS, SHF_ALLOC, 0x4005a4, 0x5a4, 0x11, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".eh_frame_hdr", SHT_PROGBITS, SHF_ALLOC, 0x4005b8, 0x5b8, 0x24, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".eh_frame", SHT_PROGBITS, SHF_ALLOC, 0x4005e0, 0x5e0, 0xa4, 0x0, 0x0, 0x8, 0x0}, - SectionHeader{".ctors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600688, 0x688, 0x10, 0x0, 0x0, 0x8, 0x0}, - SectionHeader{".dtors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600698, 0x698, 0x10, 0x0, 0x0, 0x8, 0x0}, - SectionHeader{".jcr", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x6006a8, 0x6a8, 0x8, 0x0, 0x0, 0x8, 0x0}, - SectionHeader{".dynamic", SHT_DYNAMIC, SHF_WRITE + SHF_ALLOC, 0x6006b0, 0x6b0, 0x1a0, 0x6, 0x0, 0x8, 0x10}, - SectionHeader{".got", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600850, 0x850, 0x8, 0x0, 0x0, 0x8, 0x8}, - SectionHeader{".got.plt", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600858, 0x858, 0x28, 0x0, 0x0, 0x8, 0x8}, - SectionHeader{".data", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600880, 0x880, 0x18, 0x0, 0x0, 0x8, 0x0}, - SectionHeader{".bss", SHT_NOBITS, SHF_WRITE + SHF_ALLOC, 0x600898, 0x898, 0x8, 0x0, 0x0, 0x4, 0x0}, - SectionHeader{".comment", SHT_PROGBITS, 0x0, 0x0, 0x898, 0x126, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_aranges", SHT_PROGBITS, 0x0, 0x0, 0x9c0, 0x90, 0x0, 0x0, 0x10, 0x0}, - SectionHeader{".debug_pubnames", SHT_PROGBITS, 0x0, 0x0, 0xa50, 0x25, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_info", SHT_PROGBITS, 0x0, 0x0, 0xa75, 0x1a7, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_abbrev", SHT_PROGBITS, 0x0, 0x0, 0xc1c, 0x6f, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_line", SHT_PROGBITS, 0x0, 0x0, 0xc8b, 0x13f, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".debug_str", SHT_PROGBITS, SHF_MERGE + SHF_STRINGS, 0x0, 0xdca, 0xb1, 0x0, 0x0, 0x1, 0x1}, - SectionHeader{".debug_ranges", SHT_PROGBITS, 0x0, 0x0, 0xe80, 0x90, 0x0, 0x0, 0x10, 0x0}, - SectionHeader{".shstrtab", SHT_STRTAB, 0x0, 0x0, 0xf10, 0x149, 0x0, 0x0, 0x1, 0x0}, - SectionHeader{".symtab", SHT_SYMTAB, 0x0, 0x0, 0x19a0, 0x6f0, 0x24, 0x39, 0x8, 0x18}, - SectionHeader{".strtab", SHT_STRTAB, 0x0, 0x0, 0x2090, 0x1fc, 0x0, 0x0, 0x1, 0x0}, + {"", SHT_NULL, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, + {".interp", SHT_PROGBITS, SHF_ALLOC, 0x400200, 0x200, 0x1c, 0x0, 0x0, 0x1, 0x0}, + {".note.ABI-tag", SHT_NOTE, SHF_ALLOC, 0x40021c, 0x21c, 0x20, 0x0, 0x0, 0x4, 0x0}, + {".hash", SHT_HASH, SHF_ALLOC, 0x400240, 0x240, 0x24, 0x5, 0x0, 0x8, 0x4}, + {".gnu.hash", SHT_LOOS + 268435446, SHF_ALLOC, 0x400268, 0x268, 0x1c, 0x5, 0x0, 0x8, 0x0}, + {".dynsym", SHT_DYNSYM, SHF_ALLOC, 0x400288, 0x288, 0x60, 0x6, 0x1, 0x8, 0x18}, + {".dynstr", SHT_STRTAB, SHF_ALLOC, 0x4002e8, 0x2e8, 0x3d, 0x0, 0x0, 0x1, 0x0}, + {".gnu.version", SHT_HIOS, SHF_ALLOC, 0x400326, 0x326, 0x8, 0x5, 0x0, 0x2, 0x2}, + {".gnu.version_r", SHT_LOOS + 268435454, SHF_ALLOC, 0x400330, 0x330, 0x20, 0x6, 0x1, 0x8, 0x0}, + {".rela.dyn", SHT_RELA, SHF_ALLOC, 0x400350, 0x350, 0x18, 0x5, 0x0, 0x8, 0x18}, + {".rela.plt", SHT_RELA, SHF_ALLOC, 0x400368, 0x368, 0x30, 0x5, 0xc, 0x8, 0x18}, + {".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x400398, 0x398, 0x18, 0x0, 0x0, 0x4, 0x0}, + {".plt", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x4003b0, 0x3b0, 0x30, 0x0, 0x0, 0x4, 0x10}, + {".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x4003e0, 0x3e0, 0x1b4, 0x0, 0x0, 0x10, 0x0}, + {".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x400594, 0x594, 0xe, 0x0, 0x0, 0x4, 0x0}, + {".rodata", SHT_PROGBITS, SHF_ALLOC, 0x4005a4, 0x5a4, 0x11, 0x0, 0x0, 0x4, 0x0}, + {".eh_frame_hdr", SHT_PROGBITS, SHF_ALLOC, 0x4005b8, 0x5b8, 0x24, 0x0, 0x0, 0x4, 0x0}, + {".eh_frame", SHT_PROGBITS, SHF_ALLOC, 0x4005e0, 0x5e0, 0xa4, 0x0, 0x0, 0x8, 0x0}, + {".ctors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600688, 0x688, 0x10, 0x0, 0x0, 0x8, 0x0}, + {".dtors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600698, 0x698, 0x10, 0x0, 0x0, 0x8, 0x0}, + {".jcr", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x6006a8, 0x6a8, 0x8, 0x0, 0x0, 0x8, 0x0}, + {".dynamic", SHT_DYNAMIC, SHF_WRITE + SHF_ALLOC, 0x6006b0, 0x6b0, 0x1a0, 0x6, 0x0, 0x8, 0x10}, + {".got", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600850, 0x850, 0x8, 0x0, 0x0, 0x8, 0x8}, + {".got.plt", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600858, 0x858, 0x28, 0x0, 0x0, 0x8, 0x8}, + {".data", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600880, 0x880, 0x18, 0x0, 0x0, 0x8, 0x0}, + {".bss", SHT_NOBITS, SHF_WRITE + SHF_ALLOC, 0x600898, 0x898, 0x8, 0x0, 0x0, 0x4, 0x0}, + {".comment", SHT_PROGBITS, 0x0, 0x0, 0x898, 0x126, 0x0, 0x0, 0x1, 0x0}, + {".debug_aranges", SHT_PROGBITS, 0x0, 0x0, 0x9c0, 0x90, 0x0, 0x0, 0x10, 0x0}, + {".debug_pubnames", SHT_PROGBITS, 0x0, 0x0, 0xa50, 0x25, 0x0, 0x0, 0x1, 0x0}, + {".debug_info", SHT_PROGBITS, 0x0, 0x0, 0xa75, 0x1a7, 0x0, 0x0, 0x1, 0x0}, + {".debug_abbrev", SHT_PROGBITS, 0x0, 0x0, 0xc1c, 0x6f, 0x0, 0x0, 0x1, 0x0}, + {".debug_line", SHT_PROGBITS, 0x0, 0x0, 0xc8b, 0x13f, 0x0, 0x0, 0x1, 0x0}, + {".debug_str", SHT_PROGBITS, SHF_MERGE + SHF_STRINGS, 0x0, 0xdca, 0xb1, 0x0, 0x0, 0x1, 0x1}, + {".debug_ranges", SHT_PROGBITS, 0x0, 0x0, 0xe80, 0x90, 0x0, 0x0, 0x10, 0x0}, + {".shstrtab", SHT_STRTAB, 0x0, 0x0, 0xf10, 0x149, 0x0, 0x0, 0x1, 0x0}, + {".symtab", SHT_SYMTAB, 0x0, 0x0, 0x19a0, 0x6f0, 0x24, 0x39, 0x8, 0x18}, + {".strtab", SHT_STRTAB, 0x0, 0x0, 0x2090, 0x1fc, 0x0, 0x0, 0x1, 0x0}, }, }, } @@ -135,17 +135,17 @@ type relocationTest struct { } var relocationTests = []relocationTest{ - relocationTest{ + { "testdata/go-relocation-test-gcc441-x86-64.o", - &dwarf.Entry{Offset: 0xb, Tag: dwarf.TagCompileUnit, Children: true, Field: []dwarf.Field{dwarf.Field{Attr: dwarf.AttrProducer, Val: "GNU C 4.4.1"}, dwarf.Field{Attr: dwarf.AttrLanguage, Val: int64(1)}, dwarf.Field{Attr: dwarf.AttrName, Val: "go-relocation-test.c"}, dwarf.Field{Attr: dwarf.AttrCompDir, Val: "/tmp"}, dwarf.Field{Attr: dwarf.AttrLowpc, Val: uint64(0x0)}, dwarf.Field{Attr: dwarf.AttrHighpc, Val: uint64(0x6)}, dwarf.Field{Attr: dwarf.AttrStmtList, Val: int64(0)}}}, + &dwarf.Entry{Offset: 0xb, Tag: dwarf.TagCompileUnit, Children: true, Field: []dwarf.Field{{Attr: dwarf.AttrProducer, Val: "GNU C 4.4.1"}, {Attr: dwarf.AttrLanguage, Val: int64(1)}, {Attr: dwarf.AttrName, Val: "go-relocation-test.c"}, {Attr: dwarf.AttrCompDir, Val: "/tmp"}, {Attr: dwarf.AttrLowpc, Val: uint64(0x0)}, {Attr: dwarf.AttrHighpc, Val: uint64(0x6)}, {Attr: dwarf.AttrStmtList, Val: int64(0)}}}, }, - relocationTest{ + { "testdata/go-relocation-test-gcc441-x86.o", - &dwarf.Entry{Offset: 0xb, Tag: dwarf.TagCompileUnit, Children: true, Field: []dwarf.Field{dwarf.Field{Attr: dwarf.AttrProducer, Val: "GNU C 4.4.1"}, dwarf.Field{Attr: dwarf.AttrLanguage, Val: int64(1)}, dwarf.Field{Attr: dwarf.AttrName, Val: "t.c"}, dwarf.Field{Attr: dwarf.AttrCompDir, Val: "/tmp"}, dwarf.Field{Attr: dwarf.AttrLowpc, Val: uint64(0x0)}, dwarf.Field{Attr: dwarf.AttrHighpc, Val: uint64(0x5)}, dwarf.Field{Attr: dwarf.AttrStmtList, Val: int64(0)}}}, + &dwarf.Entry{Offset: 0xb, Tag: dwarf.TagCompileUnit, Children: true, Field: []dwarf.Field{{Attr: dwarf.AttrProducer, Val: "GNU C 4.4.1"}, {Attr: dwarf.AttrLanguage, Val: int64(1)}, {Attr: dwarf.AttrName, Val: "t.c"}, {Attr: dwarf.AttrCompDir, Val: "/tmp"}, {Attr: dwarf.AttrLowpc, Val: uint64(0x0)}, {Attr: dwarf.AttrHighpc, Val: uint64(0x5)}, {Attr: dwarf.AttrStmtList, Val: int64(0)}}}, }, - relocationTest{ + { "testdata/go-relocation-test-gcc424-x86-64.o", - &dwarf.Entry{Offset: 0xb, Tag: dwarf.TagCompileUnit, Children: true, Field: []dwarf.Field{dwarf.Field{Attr: dwarf.AttrProducer, Val: "GNU C 4.2.4 (Ubuntu 4.2.4-1ubuntu4)"}, dwarf.Field{Attr: dwarf.AttrLanguage, Val: int64(1)}, dwarf.Field{Attr: dwarf.AttrName, Val: "go-relocation-test-gcc424.c"}, dwarf.Field{Attr: dwarf.AttrCompDir, Val: "/tmp"}, dwarf.Field{Attr: dwarf.AttrLowpc, Val: uint64(0x0)}, dwarf.Field{Attr: dwarf.AttrHighpc, Val: uint64(0x6)}, dwarf.Field{Attr: dwarf.AttrStmtList, Val: int64(0)}}}, + &dwarf.Entry{Offset: 0xb, Tag: dwarf.TagCompileUnit, Children: true, Field: []dwarf.Field{{Attr: dwarf.AttrProducer, Val: "GNU C 4.2.4 (Ubuntu 4.2.4-1ubuntu4)"}, {Attr: dwarf.AttrLanguage, Val: int64(1)}, {Attr: dwarf.AttrName, Val: "go-relocation-test-gcc424.c"}, {Attr: dwarf.AttrCompDir, Val: "/tmp"}, {Attr: dwarf.AttrLowpc, Val: uint64(0x0)}, {Attr: dwarf.AttrHighpc, Val: uint64(0x6)}, {Attr: dwarf.AttrStmtList, Val: int64(0)}}}, }, } diff --git a/src/pkg/debug/gosym/Makefile b/src/pkg/debug/gosym/Makefile index ac16b4cee..3c0d8c440 100644 --- a/src/pkg/debug/gosym/Makefile +++ b/src/pkg/debug/gosym/Makefile @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -include ../../../Make.$(GOARCH) +include ../../../Make.inc TARG=debug/gosym GOFILES=\ diff --git a/src/pkg/debug/gosym/pclinetest.s b/src/pkg/debug/gosym/pclinetest.s index 519656b63..6305435b0 100644 --- a/src/pkg/debug/gosym/pclinetest.s +++ b/src/pkg/debug/gosym/pclinetest.s @@ -51,39 +51,8 @@ TEXT main(SB),7,$0 CALL pcfromline(SB) // Keep the linker happy -TEXT runtime·morestack(SB),7,$0 +TEXT main·main(SB),7,$0 RET -TEXT runtime·morestack00(SB),7,$0 +TEXT main·init(SB),7,$0 RET - -TEXT runtime·morestack10(SB),7,$0 - RET - -TEXT runtime·morestack01(SB),7,$0 - RET - -TEXT runtime·morestack11(SB),7,$0 - RET - -TEXT runtime·morestack8(SB),7,$0 - RET - -TEXT runtime·morestack16(SB),7,$0 - RET - -TEXT runtime·morestack24(SB),7,$0 - RET - -TEXT runtime·morestack32(SB),7,$0 - RET - -TEXT runtime·morestack40(SB),7,$0 - RET - -TEXT runtime·morestack48(SB),7,$0 - RET - -TEXT runtime·morestack8(SB),7,$0 - RET - diff --git a/src/pkg/debug/gosym/pclntab_test.go b/src/pkg/debug/gosym/pclntab_test.go index 8752e3c9f..908702173 100644 --- a/src/pkg/debug/gosym/pclntab_test.go +++ b/src/pkg/debug/gosym/pclntab_test.go @@ -143,7 +143,7 @@ func TestLineAline(t *testing.T) { } } -// gotest: if [ "$(uname)-$(uname -m)" = Linux-x86_64 ]; then +// gotest: if [ "$(uname)-$(uname -m)" = Linux-x86_64 -a "$GOARCH" = amd64 ]; then // gotest: mkdir -p _test && $AS pclinetest.s && $LD -E main -o _test/pclinetest pclinetest.$O // gotest: fi func TestPCLine(t *testing.T) { diff --git a/src/pkg/debug/macho/Makefile b/src/pkg/debug/macho/Makefile index d34aacf54..5fbbf1efe 100644 --- a/src/pkg/debug/macho/Makefile +++ b/src/pkg/debug/macho/Makefile @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -include ../../../Make.$(GOARCH) +include ../../../Make.inc TARG=debug/macho GOFILES=\ diff --git a/src/pkg/debug/macho/file.go b/src/pkg/debug/macho/file.go index 246dad8e7..fd8da9449 100644 --- a/src/pkg/debug/macho/file.go +++ b/src/pkg/debug/macho/file.go @@ -24,6 +24,9 @@ type File struct { Loads []Load Sections []*Section + Symtab *Symtab + Dysymtab *Dysymtab + closer io.Closer } @@ -112,6 +115,28 @@ func (s *Section) Data() ([]byte, os.Error) { // Open returns a new ReadSeeker reading the Mach-O section. func (s *Section) Open() io.ReadSeeker { return io.NewSectionReader(s.sr, 0, 1<<63-1) } +// A Dylib represents a Mach-O load dynamic library command. +type Dylib struct { + LoadBytes + Name string + Time uint32 + CurrentVersion uint32 + CompatVersion uint32 +} + +// A Symtab represents a Mach-O symbol table command. +type Symtab struct { + LoadBytes + SymtabCmd + Syms []Symbol +} + +// A Dysymtab represents a Mach-O dynamic symbol table command. +type Dysymtab struct { + LoadBytes + DysymtabCmd + IndirectSyms []uint32 // indices into Symtab.Syms +} /* * Mach-O reader @@ -217,6 +242,71 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { default: f.Loads[i] = LoadBytes(cmddat) + case LoadCmdDylib: + var hdr DylibCmd + b := bytes.NewBuffer(cmddat) + if err := binary.Read(b, bo, &hdr); err != nil { + return nil, err + } + l := new(Dylib) + if hdr.Name >= uint32(len(cmddat)) { + return nil, &FormatError{offset, "invalid name in dynamic library command", hdr.Name} + } + l.Name = cstring(cmddat[hdr.Name:]) + l.Time = hdr.Time + l.CurrentVersion = hdr.CurrentVersion + l.CompatVersion = hdr.CompatVersion + l.LoadBytes = LoadBytes(cmddat) + f.Loads[i] = l + + case LoadCmdSymtab: + var hdr SymtabCmd + b := bytes.NewBuffer(cmddat) + if err := binary.Read(b, bo, &hdr); err != nil { + return nil, err + } + strtab := make([]byte, hdr.Strsize) + if _, err := r.ReadAt(strtab, int64(hdr.Stroff)); err != nil { + return nil, err + } + var symsz int + if f.Magic == Magic64 { + symsz = 16 + } else { + symsz = 12 + } + symdat := make([]byte, int(hdr.Nsyms)*symsz) + if _, err := r.ReadAt(symdat, int64(hdr.Symoff)); err != nil { + return nil, err + } + st, err := f.parseSymtab(symdat, strtab, cmddat, &hdr, offset) + if err != nil { + return nil, err + } + f.Loads[i] = st + f.Symtab = st + + case LoadCmdDysymtab: + var hdr DysymtabCmd + b := bytes.NewBuffer(cmddat) + if err := binary.Read(b, bo, &hdr); err != nil { + return nil, err + } + dat := make([]byte, hdr.Nindirectsyms*4) + if _, err := r.ReadAt(dat, int64(hdr.Indirectsymoff)); err != nil { + return nil, err + } + x := make([]uint32, hdr.Nindirectsyms) + if err := binary.Read(bytes.NewBuffer(dat), bo, x); err != nil { + return nil, err + } + st := new(Dysymtab) + st.LoadBytes = LoadBytes(cmddat) + st.DysymtabCmd = hdr + st.IndirectSyms = x + f.Loads[i] = st + f.Dysymtab = st + case LoadCmdSegment: var seg32 Segment32 b := bytes.NewBuffer(cmddat) @@ -301,18 +391,45 @@ func NewFile(r io.ReaderAt) (*File, os.Error) { return f, nil } -func (f *File) pushSection(sh *Section, r io.ReaderAt) { - n := len(f.Sections) - if n >= cap(f.Sections) { - m := (n + 1) * 2 - new := make([]*Section, n, m) - for i, sh := range f.Sections { - new[i] = sh +func (f *File) parseSymtab(symdat, strtab, cmddat []byte, hdr *SymtabCmd, offset int64) (*Symtab, os.Error) { + bo := f.ByteOrder + symtab := make([]Symbol, hdr.Nsyms) + b := bytes.NewBuffer(symdat) + for i := range symtab { + var n Nlist64 + if f.Magic == Magic64 { + if err := binary.Read(b, bo, &n); err != nil { + return nil, err + } + } else { + var n32 Nlist32 + if err := binary.Read(b, bo, &n32); err != nil { + return nil, err + } + n.Name = n32.Name + n.Type = n32.Type + n.Sect = n32.Sect + n.Desc = n32.Desc + n.Value = uint64(n32.Value) + } + sym := &symtab[i] + if n.Name >= uint32(len(strtab)) { + return nil, &FormatError{offset, "invalid name in symbol table", n.Name} } - f.Sections = new + sym.Name = cstring(strtab[n.Name:]) + sym.Type = n.Type + sym.Sect = n.Sect + sym.Desc = n.Desc + sym.Value = n.Value } - f.Sections = f.Sections[0 : n+1] - f.Sections[n] = sh + st := new(Symtab) + st.LoadBytes = LoadBytes(cmddat) + st.Syms = symtab + return st, nil +} + +func (f *File) pushSection(sh *Section, r io.ReaderAt) { + f.Sections = append(f.Sections, sh) sh.sr = io.NewSectionReader(r, int64(sh.Offset), int64(sh.Size)) sh.ReaderAt = sh.sr } @@ -368,3 +485,33 @@ func (f *File) DWARF() (*dwarf.Data, os.Error) { abbrev, info, str := dat[0], dat[1], dat[2] return dwarf.New(abbrev, nil, nil, info, nil, nil, nil, str) } + +// ImportedSymbols returns the names of all symbols +// referred to by the binary f that are expected to be +// satisfied by other libraries at dynamic load time. +func (f *File) ImportedSymbols() ([]string, os.Error) { + if f.Dysymtab == nil || f.Symtab == nil { + return nil, &FormatError{0, "missing symbol table", nil} + } + + st := f.Symtab + dt := f.Dysymtab + var all []string + for _, s := range st.Syms[dt.Iundefsym : dt.Iundefsym+dt.Nundefsym] { + all = append(all, s.Name) + } + return all, nil +} + +// ImportedLibraries returns the paths of all libraries +// referred to by the binary f that are expected to be +// linked with the binary at dynamic link time. +func (f *File) ImportedLibraries() ([]string, os.Error) { + var all []string + for _, l := range f.Loads { + if lib, ok := l.(*Dylib); ok { + all = append(all, lib.Name) + } + } + return all, nil +} diff --git a/src/pkg/debug/macho/file_test.go b/src/pkg/debug/macho/file_test.go index d4f3fc19c..56d8a20be 100644 --- a/src/pkg/debug/macho/file_test.go +++ b/src/pkg/debug/macho/file_test.go @@ -17,7 +17,7 @@ type fileTest struct { } var fileTests = []fileTest{ - fileTest{ + { "testdata/gcc-386-darwin-exec", FileHeader{0xfeedface, Cpu386, 0x3, 0x2, 0xc, 0x3c0, 0x85}, []*SegmentHeader{ @@ -42,7 +42,7 @@ var fileTests = []fileTest{ &SectionHeader{"__jump_table", "__IMPORT", 0x3000, 0xa, 0x2000, 0x6, 0x0, 0x0, 0x4000008}, }, }, - fileTest{ + { "testdata/gcc-amd64-darwin-exec", FileHeader{0xfeedfacf, CpuAmd64, 0x80000003, 0x2, 0xb, 0x568, 0x85}, []*SegmentHeader{ @@ -69,7 +69,7 @@ var fileTests = []fileTest{ &SectionHeader{"__la_symbol_ptr", "__DATA", 0x100001058, 0x10, 0x1058, 0x2, 0x0, 0x0, 0x7}, }, }, - fileTest{ + { "testdata/gcc-amd64-darwin-exec-debug", FileHeader{0xfeedfacf, CpuAmd64, 0x80000003, 0xa, 0x4, 0x5a0, 0}, []*SegmentHeader{ diff --git a/src/pkg/debug/macho/macho.go b/src/pkg/debug/macho/macho.go index 41962d562..1386f5acf 100644 --- a/src/pkg/debug/macho/macho.go +++ b/src/pkg/debug/macho/macho.go @@ -47,8 +47,8 @@ const ( ) var cpuStrings = []intName{ - intName{uint32(Cpu386), "Cpu386"}, - intName{uint32(CpuAmd64), "CpuAmd64"}, + {uint32(Cpu386), "Cpu386"}, + {uint32(CpuAmd64), "CpuAmd64"}, } func (i Cpu) String() string { return stringName(uint32(i), cpuStrings, false) } @@ -59,16 +59,21 @@ type LoadCmd uint32 const ( LoadCmdSegment LoadCmd = 1 - LoadCmdSegment64 LoadCmd = 25 + LoadCmdSymtab LoadCmd = 2 LoadCmdThread LoadCmd = 4 LoadCmdUnixThread LoadCmd = 5 // thread+stack + LoadCmdDysymtab LoadCmd = 11 + LoadCmdDylib LoadCmd = 12 + LoadCmdDylinker LoadCmd = 15 + LoadCmdSegment64 LoadCmd = 25 ) var cmdStrings = []intName{ - intName{uint32(LoadCmdSegment), "LoadCmdSegment"}, - intName{uint32(LoadCmdSegment64), "LoadCmdSegment64"}, - intName{uint32(LoadCmdThread), "LoadCmdThread"}, - intName{uint32(LoadCmdUnixThread), "LoadCmdUnixThread"}, + {uint32(LoadCmdSegment), "LoadCmdSegment"}, + {uint32(LoadCmdThread), "LoadCmdThread"}, + {uint32(LoadCmdUnixThread), "LoadCmdUnixThread"}, + {uint32(LoadCmdDylib), "LoadCmdDylib"}, + {uint32(LoadCmdSegment64), "LoadCmdSegment64"}, } func (i LoadCmd) String() string { return stringName(uint32(i), cmdStrings, false) } @@ -104,6 +109,16 @@ type Segment32 struct { Flag uint32 } +// A DylibCmd is a Mach-O load dynamic library command. +type DylibCmd struct { + Cmd LoadCmd + Len uint32 + Name uint32 + Time uint32 + CurrentVersion uint32 + CompatVersion uint32 +} + // A Section32 is a 32-bit Mach-O section header. type Section32 struct { Name [16]byte @@ -135,6 +150,67 @@ type Section64 struct { Reserve3 uint32 } +// A SymtabCmd is a Mach-O symbol table command. +type SymtabCmd struct { + Cmd LoadCmd + Len uint32 + Symoff uint32 + Nsyms uint32 + Stroff uint32 + Strsize uint32 +} + +// A DysymtabCmd is a Mach-O dynamic symbol table command. +type DysymtabCmd struct { + Cmd LoadCmd + Len uint32 + Ilocalsym uint32 + Nlocalsym uint32 + Iextdefsym uint32 + Nextdefsym uint32 + Iundefsym uint32 + Nundefsym uint32 + Tocoffset uint32 + Ntoc uint32 + Modtaboff uint32 + Nmodtab uint32 + Extrefsymoff uint32 + Nextrefsyms uint32 + Indirectsymoff uint32 + Nindirectsyms uint32 + Extreloff uint32 + Nextrel uint32 + Locreloff uint32 + Nlocrel uint32 +} + +// An Nlist32 is a Mach-O 32-bit symbol table entry. +type Nlist32 struct { + Name uint32 + Type uint8 + Sect uint8 + Desc uint16 + Value uint32 +} + +// An Nlist64 is a Mach-O 64-bit symbol table entry. +type Nlist64 struct { + Name uint32 + Type uint8 + Sect uint8 + Desc uint16 + Value uint64 +} + +// A Symbol is a Mach-O 32-bit or 64-bit symbol table entry. +type Symbol struct { + Name string + Type uint8 + Sect uint8 + Desc uint16 + Value uint64 +} + // A Thread is a Mach-O thread state command. type Thread struct { Cmd LoadCmd diff --git a/src/pkg/debug/pe/Makefile b/src/pkg/debug/pe/Makefile new file mode 100644 index 000000000..998e6a418 --- /dev/null +++ b/src/pkg/debug/pe/Makefile @@ -0,0 +1,12 @@ +# Copyright 2009 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. + +include ../../../Make.inc + +TARG=debug/pe +GOFILES=\ + pe.go\ + file.go\ + +include ../../../Make.pkg diff --git a/src/pkg/debug/pe/file.go b/src/pkg/debug/pe/file.go new file mode 100644 index 000000000..904d2f863 --- /dev/null +++ b/src/pkg/debug/pe/file.go @@ -0,0 +1,231 @@ +// Copyright 2009 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. + +// Package pe implements access to PE (Microsoft Windows Portable Executable) files. +package pe + +import ( + "debug/dwarf" + "encoding/binary" + "fmt" + "io" + "os" + "strconv" +) + +// A File represents an open PE file. +type File struct { + FileHeader + Sections []*Section + + closer io.Closer +} + +type SectionHeader struct { + Name string + VirtualSize uint32 + VirtualAddress uint32 + Size uint32 + Offset uint32 + PointerToRelocations uint32 + PointerToLineNumbers uint32 + NumberOfRelocations uint16 + NumberOfLineNumbers uint16 + Characteristics uint32 +} + + +type Section struct { + SectionHeader + + // Embed ReaderAt for ReadAt method. + // Do not embed SectionReader directly + // to avoid having Read and Seek. + // If a client wants Read and Seek it must use + // Open() to avoid fighting over the seek offset + // with other clients. + io.ReaderAt + sr *io.SectionReader +} + +// Data reads and returns the contents of the PE section. +func (s *Section) Data() ([]byte, os.Error) { + dat := make([]byte, s.sr.Size()) + n, err := s.sr.ReadAt(dat, 0) + return dat[0:n], err +} + +// Open returns a new ReadSeeker reading the PE section. +func (s *Section) Open() io.ReadSeeker { return io.NewSectionReader(s.sr, 0, 1<<63-1) } + + +type FormatError struct { + off int64 + msg string + val interface{} +} + +func (e *FormatError) String() string { + msg := e.msg + if e.val != nil { + msg += fmt.Sprintf(" '%v'", e.val) + } + msg += fmt.Sprintf(" in record at byte %#x", e.off) + return msg +} + +// Open opens the named file using os.Open and prepares it for use as a PE binary. +func Open(name string) (*File, os.Error) { + f, err := os.Open(name, os.O_RDONLY, 0) + if err != nil { + return nil, err + } + ff, err := NewFile(f) + if err != nil { + f.Close() + return nil, err + } + ff.closer = f + return ff, nil +} + +// Close closes the File. +// If the File was created using NewFile directly instead of Open, +// Close has no effect. +func (f *File) Close() os.Error { + var err os.Error + if f.closer != nil { + err = f.closer.Close() + f.closer = nil + } + return err +} + +// NewFile creates a new File for acecssing a PE binary in an underlying reader. +func NewFile(r io.ReaderAt) (*File, os.Error) { + f := new(File) + sr := io.NewSectionReader(r, 0, 1<<63-1) + + var dosheader [96]byte + if _, err := r.ReadAt(dosheader[0:], 0); err != nil { + return nil, err + } + var base int64 + if dosheader[0] == 'M' && dosheader[1] == 'Z' { + var sign [4]byte + r.ReadAt(sign[0:], int64(dosheader[0x3c])) + if !(sign[0] == 'P' && sign[1] == 'E' && sign[2] == 0 && sign[3] == 0) { + return nil, os.NewError("Invalid PE File Format.") + } + base = int64(dosheader[0x3c]) + 4 + } else { + base = int64(0) + } + sr.Seek(base, 0) + if err := binary.Read(sr, binary.LittleEndian, &f.FileHeader); err != nil { + return nil, err + } + if f.FileHeader.Machine != IMAGE_FILE_MACHINE_UNKNOWN && f.FileHeader.Machine != IMAGE_FILE_MACHINE_AMD64 && f.FileHeader.Machine != IMAGE_FILE_MACHINE_I386 { + return nil, os.NewError("Invalid PE File Format.") + } + // get symbol string table + sr.Seek(int64(f.FileHeader.PointerToSymbolTable+18*f.FileHeader.NumberOfSymbols), 0) + var l uint32 + if err := binary.Read(sr, binary.LittleEndian, &l); err != nil { + return nil, err + } + ss := make([]byte, l) + if _, err := r.ReadAt(ss, int64(f.FileHeader.PointerToSymbolTable+18*f.FileHeader.NumberOfSymbols)); err != nil { + return nil, err + } + sr.Seek(base, 0) + binary.Read(sr, binary.LittleEndian, &f.FileHeader) + sr.Seek(int64(f.FileHeader.SizeOfOptionalHeader), 1) //Skip OptionalHeader + f.Sections = make([]*Section, f.FileHeader.NumberOfSections) + for i := 0; i < int(f.FileHeader.NumberOfSections); i++ { + sh := new(SectionHeader32) + if err := binary.Read(sr, binary.LittleEndian, sh); err != nil { + return nil, err + } + var name string + if sh.Name[0] == '\x2F' { + si, _ := strconv.Atoi(cstring(sh.Name[1:])) + name, _ = getString(ss, si) + } else { + name = cstring(sh.Name[0:]) + } + s := new(Section) + s.SectionHeader = SectionHeader{ + Name: name, + VirtualSize: uint32(sh.VirtualSize), + VirtualAddress: uint32(sh.VirtualAddress), + Size: uint32(sh.SizeOfRawData), + Offset: uint32(sh.PointerToRawData), + PointerToRelocations: uint32(sh.PointerToRelocations), + PointerToLineNumbers: uint32(sh.PointerToLineNumbers), + NumberOfRelocations: uint16(sh.NumberOfRelocations), + NumberOfLineNumbers: uint16(sh.NumberOfLineNumbers), + Characteristics: uint32(sh.Characteristics), + } + s.sr = io.NewSectionReader(r, int64(s.SectionHeader.Offset), int64(s.SectionHeader.Size)) + s.ReaderAt = s.sr + f.Sections[i] = s + } + return f, nil +} + +func cstring(b []byte) string { + var i int + for i = 0; i < len(b) && b[i] != 0; i++ { + } + return string(b[0:i]) +} + +// getString extracts a string from symbol string table. +func getString(section []byte, start int) (string, bool) { + if start < 0 || start >= len(section) { + return "", false + } + + for end := start; end < len(section); end++ { + if section[end] == 0 { + return string(section[start:end]), true + } + } + return "", false +} + +// Section returns the first section with the given name, or nil if no such +// section exists. +func (f *File) Section(name string) *Section { + for _, s := range f.Sections { + if s.Name == name { + return s + } + } + return nil +} + +func (f *File) DWARF() (*dwarf.Data, os.Error) { + // There are many other DWARF sections, but these + // are the required ones, and the debug/dwarf package + // does not use the others, so don't bother loading them. + var names = [...]string{"abbrev", "info", "str"} + var dat [len(names)][]byte + for i, name := range names { + name = ".debug_" + name + s := f.Section(name) + if s == nil { + continue + } + b, err := s.Data() + if err != nil && uint32(len(b)) < s.Size { + return nil, err + } + dat[i] = b + } + + abbrev, info, str := dat[0], dat[1], dat[2] + return dwarf.New(abbrev, nil, nil, info, nil, nil, nil, str) +} diff --git a/src/pkg/debug/pe/file_test.go b/src/pkg/debug/pe/file_test.go new file mode 100644 index 000000000..2c5c25b8c --- /dev/null +++ b/src/pkg/debug/pe/file_test.go @@ -0,0 +1,99 @@ +// Copyright 2009 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. + +package pe + +import ( + "reflect" + "testing" +) + +type fileTest struct { + file string + hdr FileHeader + sections []*SectionHeader +} + +var fileTests = []fileTest{ + { + "testdata/gcc-386-mingw-obj", + FileHeader{0x014c, 0x000c, 0x0, 0x64a, 0x1e, 0x0, 0x104}, + []*SectionHeader{ + &SectionHeader{".text", 0, 0, 36, 500, 1440, 0, 3, 0, 0x60300020}, + &SectionHeader{".data", 0, 0, 0, 0, 0, 0, 0, 0, 3224371264}, + &SectionHeader{".bss", 0, 0, 0, 0, 0, 0, 0, 0, 3224371328}, + &SectionHeader{".debug_abbrev", 0, 0, 137, 536, 0, 0, 0, 0, 0x42100000}, + &SectionHeader{".debug_info", 0, 0, 418, 673, 1470, 0, 7, 0, 1108344832}, + &SectionHeader{".debug_line", 0, 0, 128, 1091, 1540, 0, 1, 0, 1108344832}, + &SectionHeader{".rdata", 0, 0, 16, 1219, 0, 0, 0, 0, 1076887616}, + &SectionHeader{".debug_frame", 0, 0, 52, 1235, 1550, 0, 2, 0, 1110441984}, + &SectionHeader{".debug_loc", 0, 0, 56, 1287, 0, 0, 0, 0, 1108344832}, + &SectionHeader{".debug_pubnames", 0, 0, 27, 1343, 1570, 0, 1, 0, 1108344832}, + &SectionHeader{".debug_pubtypes", 0, 0, 38, 1370, 1580, 0, 1, 0, 1108344832}, + &SectionHeader{".debug_aranges", 0, 0, 32, 1408, 1590, 0, 2, 0, 1108344832}, + }, + }, + { + "testdata/gcc-386-mingw-exec", + FileHeader{0x014c, 0x000f, 0x4c6a1b60, 0x3c00, 0x282, 0xe0, 0x107}, + []*SectionHeader{ + &SectionHeader{Name: ".text", VirtualSize: 0xcd8, VirtualAddress: 0x1000, Size: 0xe00, Offset: 0x400, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x60500060}, + &SectionHeader{Name: ".data", VirtualSize: 0x10, VirtualAddress: 0x2000, Size: 0x200, Offset: 0x1200, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0xc0300040}, + &SectionHeader{Name: ".rdata", VirtualSize: 0x120, VirtualAddress: 0x3000, Size: 0x200, Offset: 0x1400, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x40300040}, + &SectionHeader{Name: ".bss", VirtualSize: 0xdc, VirtualAddress: 0x4000, Size: 0x0, Offset: 0x0, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0xc0400080}, + &SectionHeader{Name: ".idata", VirtualSize: 0x3c8, VirtualAddress: 0x5000, Size: 0x400, Offset: 0x1600, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0xc0300040}, + &SectionHeader{Name: ".CRT", VirtualSize: 0x18, VirtualAddress: 0x6000, Size: 0x200, Offset: 0x1a00, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0xc0300040}, + &SectionHeader{Name: ".tls", VirtualSize: 0x20, VirtualAddress: 0x7000, Size: 0x200, Offset: 0x1c00, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0xc0300040}, + &SectionHeader{Name: ".debug_aranges", VirtualSize: 0x20, VirtualAddress: 0x8000, Size: 0x200, Offset: 0x1e00, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x42100000}, + &SectionHeader{Name: ".debug_pubnames", VirtualSize: 0x51, VirtualAddress: 0x9000, Size: 0x200, Offset: 0x2000, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x42100000}, + &SectionHeader{Name: ".debug_pubtypes", VirtualSize: 0x91, VirtualAddress: 0xa000, Size: 0x200, Offset: 0x2200, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x42100000}, + &SectionHeader{Name: ".debug_info", VirtualSize: 0xe22, VirtualAddress: 0xb000, Size: 0x1000, Offset: 0x2400, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x42100000}, + &SectionHeader{Name: ".debug_abbrev", VirtualSize: 0x157, VirtualAddress: 0xc000, Size: 0x200, Offset: 0x3400, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x42100000}, + &SectionHeader{Name: ".debug_line", VirtualSize: 0x144, VirtualAddress: 0xd000, Size: 0x200, Offset: 0x3600, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x42100000}, + &SectionHeader{Name: ".debug_frame", VirtualSize: 0x34, VirtualAddress: 0xe000, Size: 0x200, Offset: 0x3800, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x42300000}, + &SectionHeader{Name: ".debug_loc", VirtualSize: 0x38, VirtualAddress: 0xf000, Size: 0x200, Offset: 0x3a00, PointerToRelocations: 0x0, PointerToLineNumbers: 0x0, NumberOfRelocations: 0x0, NumberOfLineNumbers: 0x0, Characteristics: 0x42100000}, + }, + }, +} + +func TestOpen(t *testing.T) { + for i := range fileTests { + tt := &fileTests[i] + + f, err := Open(tt.file) + if err != nil { + t.Error(err) + continue + } + if !reflect.DeepEqual(f.FileHeader, tt.hdr) { + t.Errorf("open %s:\n\thave %#v\n\twant %#v\n", tt.file, f.FileHeader, tt.hdr) + continue + } + + for i, sh := range f.Sections { + if i >= len(tt.sections) { + break + } + have := &sh.SectionHeader + want := tt.sections[i] + if !reflect.DeepEqual(have, want) { + t.Errorf("open %s, section %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want) + } + } + tn := len(tt.sections) + fn := len(f.Sections) + if tn != fn { + t.Errorf("open %s: len(Sections) = %d, want %d", tt.file, fn, tn) + } + + } +} + +func TestOpenFailure(t *testing.T) { + filename := "file.go" // not a PE file + _, err := Open(filename) // don't crash + if err == nil { + t.Errorf("open %s: succeeded unexpectedly", filename) + } +} diff --git a/src/pkg/debug/pe/pe.go b/src/pkg/debug/pe/pe.go new file mode 100644 index 000000000..b3dab739a --- /dev/null +++ b/src/pkg/debug/pe/pe.go @@ -0,0 +1,51 @@ +// Copyright 2009 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. + +package pe + +type FileHeader struct { + Machine uint16 + NumberOfSections uint16 + TimeDateStamp uint32 + PointerToSymbolTable uint32 + NumberOfSymbols uint32 + SizeOfOptionalHeader uint16 + Characteristics uint16 +} + +type SectionHeader32 struct { + Name [8]uint8 + VirtualSize uint32 + VirtualAddress uint32 + SizeOfRawData uint32 + PointerToRawData uint32 + PointerToRelocations uint32 + PointerToLineNumbers uint32 + NumberOfRelocations uint16 + NumberOfLineNumbers uint16 + Characteristics uint32 +} + +const ( + IMAGE_FILE_MACHINE_UNKNOWN = 0x0 + IMAGE_FILE_MACHINE_AM33 = 0x1d3 + IMAGE_FILE_MACHINE_AMD64 = 0x8664 + IMAGE_FILE_MACHINE_ARM = 0x1c0 + IMAGE_FILE_MACHINE_EBC = 0xebc + IMAGE_FILE_MACHINE_I386 = 0x14c + IMAGE_FILE_MACHINE_IA64 = 0x200 + IMAGE_FILE_MACHINE_M32R = 0x9041 + IMAGE_FILE_MACHINE_MIPS16 = 0x266 + IMAGE_FILE_MACHINE_MIPSFPU = 0x366 + IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466 + IMAGE_FILE_MACHINE_POWERPC = 0x1f0 + IMAGE_FILE_MACHINE_POWERPCFP = 0x1f1 + IMAGE_FILE_MACHINE_R4000 = 0x166 + IMAGE_FILE_MACHINE_SH3 = 0x1a2 + IMAGE_FILE_MACHINE_SH3DSP = 0x1a3 + IMAGE_FILE_MACHINE_SH4 = 0x1a6 + IMAGE_FILE_MACHINE_SH5 = 0x1a8 + IMAGE_FILE_MACHINE_THUMB = 0x1c2 + IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169 +) diff --git a/src/pkg/debug/pe/testdata/gcc-386-mingw-exec b/src/pkg/debug/pe/testdata/gcc-386-mingw-exec Binary files differnew file mode 100644 index 000000000..4b808d043 --- /dev/null +++ b/src/pkg/debug/pe/testdata/gcc-386-mingw-exec diff --git a/src/pkg/debug/pe/testdata/gcc-386-mingw-obj b/src/pkg/debug/pe/testdata/gcc-386-mingw-obj Binary files differnew file mode 100644 index 000000000..0c84d898d --- /dev/null +++ b/src/pkg/debug/pe/testdata/gcc-386-mingw-obj diff --git a/src/pkg/debug/pe/testdata/hello.c b/src/pkg/debug/pe/testdata/hello.c new file mode 100644 index 000000000..a689d3644 --- /dev/null +++ b/src/pkg/debug/pe/testdata/hello.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int +main(void) +{ + printf("hello, world\n"); + return 0; +} diff --git a/src/pkg/debug/proc/Makefile b/src/pkg/debug/proc/Makefile index 5444ec0db..c6d879836 100644 --- a/src/pkg/debug/proc/Makefile +++ b/src/pkg/debug/proc/Makefile @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -include ../../../Make.$(GOARCH) +include ../../../Make.inc TARG=debug/proc GOFILES=\ diff --git a/src/pkg/debug/proc/proc_linux.go b/src/pkg/debug/proc/proc_linux.go index 5253ea846..f0cc43a10 100644 --- a/src/pkg/debug/proc/proc_linux.go +++ b/src/pkg/debug/proc/proc_linux.go @@ -153,7 +153,7 @@ type process struct { debugEvents chan *debugEvent debugReqs chan *debugReq stopReq chan os.Error - transitionHandlers *vector.Vector + transitionHandlers vector.Vector err os.Error } @@ -297,7 +297,7 @@ func (t *thread) logTrace(format string, args ...interface{}) { } } fmt.Fprint(os.Stderr, ": ") - fmt.Fprintf(os.Stderr, format, args) + fmt.Fprintf(os.Stderr, format, args...) fmt.Fprint(os.Stderr, "\n") } @@ -305,7 +305,7 @@ func (t *thread) warn(format string, args ...interface{}) { logLock.Lock() defer logLock.Unlock() fmt.Fprintf(os.Stderr, "Thread %d: WARNING ", t.tid) - fmt.Fprintf(os.Stderr, format, args) + fmt.Fprintf(os.Stderr, format, args...) fmt.Fprint(os.Stderr, "\n") } @@ -316,7 +316,7 @@ func (p *process) logTrace(format string, args ...interface{}) { logLock.Lock() defer logLock.Unlock() fmt.Fprintf(os.Stderr, "Process %d: ", p.pid) - fmt.Fprintf(os.Stderr, format, args) + fmt.Fprintf(os.Stderr, format, args...) fmt.Fprint(os.Stderr, "\n") } @@ -472,8 +472,8 @@ func (t *thread) setState(newState threadState) { return } - t.proc.transitionHandlers = new(vector.Vector) - for _, h := range handlers.Data() { + t.proc.transitionHandlers = nil + for _, h := range handlers { h := h.(*transitionHandler) h.handle(t, oldState, newState) } @@ -738,7 +738,7 @@ func (p *process) monitor() { // Abort waiting handlers // TODO(austin) How do I stop the wait threads? - for _, h := range p.transitionHandlers.Data() { + for _, h := range p.transitionHandlers { h := h.(*transitionHandler) h.onErr(err) } @@ -1249,14 +1249,13 @@ func (p *process) attachAllThreads() os.Error { // newProcess creates a new process object and starts its monitor thread. func newProcess(pid int) *process { p := &process{ - pid: pid, - threads: make(map[int]*thread), - breakpoints: make(map[uintptr]*breakpoint), - ready: make(chan bool, 1), - debugEvents: make(chan *debugEvent), - debugReqs: make(chan *debugReq), - stopReq: make(chan os.Error), - transitionHandlers: new(vector.Vector), + pid: pid, + threads: make(map[int]*thread), + breakpoints: make(map[uintptr]*breakpoint), + ready: make(chan bool, 1), + debugEvents: make(chan *debugEvent), + debugReqs: make(chan *debugReq), + stopReq: make(chan os.Error), } go p.monitor() diff --git a/src/pkg/debug/proc/proc_nacl.go b/src/pkg/debug/proc/proc_nacl.go deleted file mode 100644 index be26bbf18..000000000 --- a/src/pkg/debug/proc/proc_nacl.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2009 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. - -package proc - -import ( - "os" - "syscall" -) - -// Process tracing is not supported on Native Client. - -func Attach(pid int) (Process, os.Error) { - return nil, os.NewSyscallError("ptrace", syscall.ENACL) -} - -func ForkExec(argv0 string, argv []string, envv []string, dir string, fd []*os.File) (Process, os.Error) { - return nil, os.NewSyscallError("fork/exec", syscall.ENACL) -} diff --git a/src/pkg/debug/proc/regs_linux_386.go b/src/pkg/debug/proc/regs_linux_386.go index 7cebfa64a..b4a9769db 100644 --- a/src/pkg/debug/proc/regs_linux_386.go +++ b/src/pkg/debug/proc/regs_linux_386.go @@ -80,17 +80,17 @@ func (r *_386Regs) Get(i int) Word { case 9: return Word(uint32(r.Eflags)) case 10: - return Word(r.Cs) + return Word(r.Xcs) case 11: - return Word(r.Ss) + return Word(r.Xss) case 12: - return Word(r.Ds) + return Word(r.Xds) case 13: - return Word(r.Es) + return Word(r.Xes) case 14: - return Word(r.Fs) + return Word(r.Xfs) case 15: - return Word(r.Gs) + return Word(r.Xgs) } panic("invalid register index " + strconv.Itoa(i)) } @@ -118,17 +118,17 @@ func (r *_386Regs) Set(i int, val Word) os.Error { case 9: r.Eflags = int32(val) case 10: - r.Cs = uint16(val) + r.Xcs = int32(val) case 11: - r.Ss = uint16(val) + r.Xss = int32(val) case 12: - r.Ds = uint16(val) + r.Xds = int32(val) case 13: - r.Es = uint16(val) + r.Xes = int32(val) case 14: - r.Fs = uint16(val) + r.Xfs = int32(val) case 15: - r.Gs = uint16(val) + r.Xgs = int32(val) default: panic("invalid register index " + strconv.Itoa(i)) } diff --git a/src/pkg/debug/proc/regs_linux_amd64.go b/src/pkg/debug/proc/regs_linux_amd64.go index a9f3569d3..381be29b1 100644 --- a/src/pkg/debug/proc/regs_linux_amd64.go +++ b/src/pkg/debug/proc/regs_linux_amd64.go @@ -71,7 +71,7 @@ func (r *amd64Regs) SetSP(val Word) os.Error { return r.setter(&r.PtraceRegs) } -func (r *amd64Regs) Names() []string { return &names } +func (r *amd64Regs) Names() []string { return names[0:] } func (r *amd64Regs) Get(i int) Word { switch i { diff --git a/src/pkg/debug/proc/regs_nacl_386.go b/src/pkg/debug/proc/regs_nacl_386.go deleted file mode 100644 index 60c9ac719..000000000 --- a/src/pkg/debug/proc/regs_nacl_386.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2009 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. - -package proc |