]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: nice error message on ABI mismatch
authorAustin Clements <austin@google.com>
Thu, 1 Nov 2018 00:42:38 +0000 (20:42 -0400)
committerAustin Clements <austin@google.com>
Mon, 12 Nov 2018 20:46:52 +0000 (20:46 +0000)
Currently, if a symbol is only defined under one ABI and referenced
under another ABI, you simply get a "relocation target X not defined".
This is confusing because it seems like the symbol is defined.

This CL enhances the error message in this case to be "relocation
target X not defined for <ABI> (but is defined for <ABI>)".

For #27539.

Change-Id: If857a1882c3fe9af5346797d5295ca1fe50ae565
Reviewed-on: https://go-review.googlesource.com/c/147159
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/link/internal/ld/link.go

index 48b92724b6fe075ede810f95b31f3049579d1f62..f3f1bba773a25d869740b8a40fa9b6e5dc41a3b3 100644 (file)
@@ -32,6 +32,7 @@ package ld
 
 import (
        "bufio"
+       "cmd/internal/obj"
        "cmd/internal/objabi"
        "cmd/internal/sys"
        "cmd/link/internal/sym"
@@ -108,9 +109,27 @@ func (ctxt *Link) ErrorUnresolved(s *sym.Symbol, r *sym.Reloc) {
        k := unresolvedSymKey{from: s, to: r.Sym}
        if !ctxt.unresolvedSymSet[k] {
                ctxt.unresolvedSymSet[k] = true
+
+               // Try to find symbol under another ABI.
+               var reqABI, haveABI obj.ABI
+               haveABI = ^obj.ABI(0)
+               for abi := obj.ABI(0); abi < obj.ABICount; abi++ {
+                       v := sym.ABIToVersion(abi)
+                       if v == -1 {
+                               continue
+                       }
+                       if v == int(r.Sym.Version) {
+                               reqABI = abi
+                       } else if ctxt.Syms.ROLookup(r.Sym.Name, v) != nil {
+                               haveABI = abi
+                       }
+               }
+
                // Give a special error message for main symbol (see #24809).
                if r.Sym.Name == "main.main" {
                        Errorf(s, "function main is undeclared in the main package")
+               } else if haveABI != ^obj.ABI(0) {
+                       Errorf(s, "relocation target %s not defined for %s (but is defined for %s)", r.Sym.Name, reqABI, haveABI)
                } else {
                        Errorf(s, "relocation target %s not defined", r.Sym.Name)
                }