]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: show native relocation type name in error messages
authorHiroshi Ioka <hirochachacha@gmail.com>
Thu, 17 Aug 2017 00:45:20 +0000 (09:45 +0900)
committerIan Lance Taylor <iant@golang.org>
Thu, 17 Aug 2017 23:41:25 +0000 (23:41 +0000)
Change-Id: I7f7b1e7ef832d53a93562b08ae914d023247c2c0
Reviewed-on: https://go-review.googlesource.com/56312
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/arm/asm.go
src/cmd/link/internal/arm64/asm.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/link.go
src/cmd/link/internal/ld/macho.go
src/cmd/link/internal/ld/pe.go
src/cmd/link/internal/ppc64/asm.go
src/cmd/link/internal/x86/asm.go

index c5909993fc9dfd602eb7dedfa313229f53a53680..2e1791fdb21654564572fc0f74e1cb62f11fe73c 100644 (file)
@@ -102,7 +102,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
        switch r.Type {
        default:
                if r.Type >= 256 {
-                       ld.Errorf(s, "unexpected relocation type %d", r.Type)
+                       ld.Errorf(s, "unexpected relocation type %d (%s)", r.Type, ld.RelocName(r.Type))
                        return false
                }
 
@@ -445,7 +445,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
 
        if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_PCREL || r.Type == objabi.R_GOTPCREL {
                if rs.Dynid < 0 {
-                       ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Type, rs.Type)
+                       ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
                        return -1
                }
 
@@ -454,7 +454,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
        } else {
                v = uint32(rs.Sect.Extnum)
                if v == 0 {
-                       ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Sect.Name, rs.Type, rs.Type)
+                       ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
                        return -1
                }
        }
@@ -507,7 +507,7 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
        rs := r.Xsym
 
        if rs.Dynid < 0 {
-               ld.Errorf(s, "reloc %d (%s) to non-coff symbol %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Type, rs.Type)
+               ld.Errorf(s, "reloc %d (%s) to non-coff symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
                return false
        }
 
index 2fc9329b61f04300c5fd78d5e041c256b9aeb0e3..20827817a7411289a42e4c55d168c1fd854ada20 100644 (file)
@@ -118,7 +118,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
        switch r.Type {
        default:
                if r.Type >= 256 {
-                       ld.Errorf(s, "unexpected relocation type %d", r.Type)
+                       ld.Errorf(s, "unexpected relocation type %d (%s)", r.Type, ld.RelocName(r.Type))
                        return false
                }
 
@@ -363,7 +363,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
 
        if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_CALLARM {
                if rs.Dynid < 0 {
-                       ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Type, rs.Type)
+                       ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
                        return -1
                }
 
@@ -372,7 +372,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
        } else {
                v = uint32(rs.Sect.Extnum)
                if v == 0 {
-                       ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Sect.Name, rs.Type, rs.Type)
+                       ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
                        return -1
                }
        }
@@ -481,7 +481,7 @@ func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) {
                        r.Done = 0
                }
        default:
-               ld.Errorf(s, "trampoline called with non-jump reloc: %v", r.Type)
+               ld.Errorf(s, "trampoline called with non-jump reloc: %d (%s)", r.Type, ld.RelocName(r.Type))
        }
 }
 
index 8d3c6fcb576a33fabcceab1f0c8209c2672184c7..1e77431ca4e35e9477ec6d9ff690c5576d981f4a 100644 (file)
@@ -158,7 +158,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
        // UNSIGNED relocation at all.
        if rs.Type == ld.SHOSTOBJ || r.Type == objabi.R_CALLARM64 || r.Type == objabi.R_ADDRARM64 || r.Type == objabi.R_ADDR {
                if rs.Dynid < 0 {
-                       ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Type, rs.Type)
+                       ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
                        return -1
                }
 
@@ -167,7 +167,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
        } else {
                v = uint32(rs.Sect.Extnum)
                if v == 0 {
-                       ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Sect.Name, rs.Type, rs.Type)
+                       ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
                        return -1
                }
        }
index 691e74cc974eb69ff881f5b98e4ffaa5ef71022c..c09633823244c5726f7f39c06405c0457adc5320 100644 (file)
@@ -432,7 +432,7 @@ func relocsym(ctxt *Link, s *Symbol) {
                // shared libraries, and Solaris needs it always
                if Headtype != objabi.Hsolaris && r.Sym != nil && r.Sym.Type == SDYNIMPORT && !ctxt.DynlinkingGo() {
                        if !(SysArch.Family == sys.PPC64 && Linkmode == LinkExternal && r.Sym.Name == ".TOC.") {
-                               Errorf(s, "unhandled relocation for %s (type %d (%s) rtype %d (%s))", r.Sym.Name, r.Sym.Type, r.Sym.Type, r.Type, r.Type)
+                               Errorf(s, "unhandled relocation for %s (type %d (%s) rtype %d (%s))", r.Sym.Name, r.Sym.Type, r.Sym.Type, r.Type, RelocName(r.Type))
                        }
                }
                if r.Sym != nil && r.Sym.Type != STLSBSS && r.Type != objabi.R_WEAKADDROFF && !r.Sym.Attr.Reachable() {
@@ -465,7 +465,7 @@ func relocsym(ctxt *Link, s *Symbol) {
                                o = int64(ctxt.Arch.ByteOrder.Uint64(s.P[off:]))
                        }
                        if Thearch.Archreloc(ctxt, r, s, &o) < 0 {
-                               Errorf(s, "unknown reloc to %v: %v", r.Sym.Name, r.Type)
+                               Errorf(s, "unknown reloc to %v: %d (%s)", r.Sym.Name, r.Type, RelocName(r.Type))
                        }
 
                case objabi.R_TLS_LE:
@@ -714,7 +714,7 @@ func relocsym(ctxt *Link, s *Symbol) {
                        if r.Sym != nil {
                                nam = r.Sym.Name
                        }
-                       fmt.Printf("relocate %s %#x (%#x+%#x, size %d) => %s %#x +%#x [type %d/%d, %x]\n", s.Name, s.Value+int64(off), s.Value, r.Off, r.Siz, nam, Symaddr(r.Sym), r.Add, r.Type, r.Variant, o)
+                       fmt.Printf("relocate %s %#x (%#x+%#x, size %d) => %s %#x +%#x [type %d (%s)/%d, %x]\n", s.Name, s.Value+int64(off), s.Value, r.Off, r.Siz, nam, Symaddr(r.Sym), r.Add, r.Type, RelocName(r.Type), r.Variant, o)
                }
                switch siz {
                default:
@@ -828,7 +828,7 @@ func dynrelocsym(ctxt *Link, s *Symbol) {
                                Errorf(s, "dynamic relocation to unreachable symbol %s", r.Sym.Name)
                        }
                        if !Thearch.Adddynrel(ctxt, s, r) {
-                               Errorf(s, "unsupported dynamic relocation for symbol %s (type=%d (%s) stype=%d (%s))", r.Sym.Name, r.Type, r.Type, r.Sym.Type, r.Sym.Type)
+                               Errorf(s, "unsupported dynamic relocation for symbol %s (type=%d (%s) stype=%d (%s))", r.Sym.Name, r.Type, RelocName(r.Type), r.Sym.Type, r.Sym.Type)
                        }
                }
        }
index 9ac55ada1dfd59455646a743fbe00df0edf5c88b..2c3f99b7568f1898f569b47f38e92a559fad19b7 100644 (file)
@@ -1812,13 +1812,13 @@ func elfrelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
                                continue
                        }
                        if r.Xsym.ElfsymForReloc() == 0 {
-                               Errorf(sym, "reloc %d (%s) to non-elf symbol %s (outer=%s) %d (%s)", r.Type, r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type, r.Sym.Type)
+                               Errorf(sym, "reloc %d (%s) to non-elf symbol %s (outer=%s) %d (%s)", r.Type, RelocName(r.Type), r.Sym.Name, r.Xsym.Name, r.Sym.Type, r.Sym.Type)
                        }
                        if !r.Xsym.Attr.Reachable() {
-                               Errorf(sym, "unreachable reloc %v target %v", r.Type, r.Xsym.Name)
+                               Errorf(sym, "unreachable reloc %d (%s) target %v", r.Type, RelocName(r.Type), r.Xsym.Name)
                        }
                        if Thearch.Elfreloc1(ctxt, r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) < 0 {
-                               Errorf(sym, "unsupported obj reloc %d (%s)/%d to %s", r.Type, r.Type, r.Siz, r.Sym.Name)
+                               Errorf(sym, "unsupported obj reloc %d (%s)/%d to %s", r.Type, RelocName(r.Type), r.Siz, r.Sym.Name)
                        }
                }
        }
index 302364c299366125085c1517eb1a2f5c25d83a7d..857957afb0df01e69f4bef38fdb147ba92c66044 100644 (file)
@@ -330,3 +330,47 @@ const (
        RV_CHECK_OVERFLOW RelocVariant = 1 << 7
        RV_TYPE_MASK      RelocVariant = RV_CHECK_OVERFLOW - 1
 )
+
+func RelocName(r objabi.RelocType) string {
+       // We didn't have some relocation types at Go1.4.
+       // Uncomment code when we include those in bootstrap code.
+
+       switch {
+       case r >= 512: // Mach-O
+               // nr := (r - 512)>>1
+               // switch SysArch.Family {
+               // case sys.AMD64:
+               //      return macho.RelocTypeX86_64(nr).String()
+               // case sys.ARM:
+               //      return macho.RelocTypeARM(nr).String()
+               // case sys.ARM64:
+               //      return macho.RelocTypeARM64(nr).String()
+               // case sys.I386:
+               //      return macho.RelocTypeGeneric(nr).String()
+               // default:
+               //      panic("unreachable")
+               // }
+       case r >= 256: // ELF
+               nr := r - 256
+               switch SysArch.Family {
+               case sys.AMD64:
+                       return elf.R_X86_64(nr).String()
+               case sys.ARM:
+                       return elf.R_ARM(nr).String()
+               case sys.ARM64:
+                       return elf.R_AARCH64(nr).String()
+               case sys.I386:
+                       return elf.R_386(nr).String()
+               case sys.MIPS, sys.MIPS64:
+                       // return elf.R_MIPS(nr).String()
+               case sys.PPC64:
+                       // return elf.R_PPC64(nr).String()
+               case sys.S390X:
+                       // return elf.R_390(nr).String()
+               default:
+                       panic("unreachable")
+               }
+       }
+
+       return r.String()
+}
index ccdbc54f66d1dfdb67d16320d6c4bef6d505ec8f..3997cfb844d0f9fdf2edd1a201d54494d37d8c89 100644 (file)
@@ -930,10 +930,10 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
                                continue
                        }
                        if !r.Xsym.Attr.Reachable() {
-                               Errorf(sym, "unreachable reloc %v target %v", r.Type, r.Xsym.Name)
+                               Errorf(sym, "unreachable reloc %d (%s) target %v", r.Type, RelocName(r.Type), r.Xsym.Name)
                        }
                        if Thearch.Machoreloc1(sym, r, int64(uint64(sym.Value+int64(r.Off))-sect.Vaddr)) < 0 {
-                               Errorf(sym, "unsupported obj reloc %v/%d to %s", r.Type, r.Siz, r.Sym.Name)
+                               Errorf(sym, "unsupported obj reloc %d (%s)/%d to %s", r.Type, RelocName(r.Type), r.Siz, r.Sym.Name)
                        }
                }
        }
index 171fa6da6eb36ee9ab3953e97e0a11bafe77e16c..7d17a6471d643e900faa8372ac0e4d53f3dd775d 100644 (file)
@@ -882,10 +882,10 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol, base uint64) int {
                        }
 
                        if r.Xsym.Dynid < 0 {
-                               Errorf(sym, "reloc %d (%s) to non-coff symbol %s (outer=%s) %d (%s)", r.Type, r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type, r.Sym.Type)
+                               Errorf(sym, "reloc %d (%s) to non-coff symbol %s (outer=%s) %d (%s)", r.Type, RelocName(r.Type), r.Sym.Name, r.Xsym.Name, r.Sym.Type, r.Sym.Type)
                        }
                        if !Thearch.PEreloc1(sym, r, int64(uint64(sym.Value+int64(r.Off))-base)) {
-                               Errorf(sym, "unsupported obj reloc %d (%s)/%d to %s", r.Type, r.Type, r.Siz, r.Sym.Name)
+                               Errorf(sym, "unsupported obj reloc %d (%s)/%d to %s", r.Type, RelocName(r.Type), r.Siz, r.Sym.Name)
                        }
 
                        relocs++
index ee4e218125a26f575b96333bec3d473d0fd13389..b2f040b5ba06ea0e63c6127ccf4fff2d00f18f36 100644 (file)
@@ -252,7 +252,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
        switch r.Type {
        default:
                if r.Type >= 256 {
-                       ld.Errorf(s, "unexpected relocation type %d", r.Type)
+                       ld.Errorf(s, "unexpected relocation type %d (%s)", r.Type, ld.RelocName(r.Type))
                        return false
                }
 
@@ -581,7 +581,7 @@ func trampoline(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol) {
                        r.Done = 0
                }
        default:
-               ld.Errorf(s, "trampoline called with non-jump reloc: %v", r.Type)
+               ld.Errorf(s, "trampoline called with non-jump reloc: %d (%s)", r.Type, ld.RelocName(r.Type))
        }
 }
 
index 157b42697113ead9570b74d36f71cf2122baaa67..dc60381d14d9fd570e13ef6c9c720d2d0fe59b3a 100644 (file)
@@ -170,7 +170,7 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
        switch r.Type {
        default:
                if r.Type >= 256 {
-                       ld.Errorf(s, "unexpected relocation type %d", r.Type)
+                       ld.Errorf(s, "unexpected relocation type %d (%s)", r.Type, ld.RelocName(r.Type))
                        return false
                }
 
@@ -416,7 +416,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
 
        if rs.Type == ld.SHOSTOBJ {
                if rs.Dynid < 0 {
-                       ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Type, rs.Type)
+                       ld.Errorf(s, "reloc %d (%s) to non-macho symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
                        return -1
                }
 
@@ -425,7 +425,7 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
        } else {
                v = uint32(rs.Sect.Extnum)
                if v == 0 {
-                       ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Sect.Name, rs.Type, rs.Type)
+                       ld.Errorf(s, "reloc %d (%s) to symbol %s in non-macho section %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Sect.Name, rs.Type, rs.Type)
                        return -1
                }
        }
@@ -471,7 +471,7 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
        rs := r.Xsym
 
        if rs.Dynid < 0 {
-               ld.Errorf(s, "reloc %d (%s) to non-coff symbol %s type=%d (%s)", r.Type, r.Type, rs.Name, rs.Type, rs.Type)
+               ld.Errorf(s, "reloc %d (%s) to non-coff symbol %s type=%d (%s)", r.Type, ld.RelocName(r.Type), rs.Name, rs.Type, rs.Type)
                return false
        }