aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-06-14 09:49:13 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-06-14 11:48:08 +0200
commitf5ba04758374afae0c1edcf28425758a50ce78be (patch)
treee4ff575399b10d256dad42361f6272d52f3eb861 /pkg
parent2e9b5f5949dcd74bf08de7af33d59307ca475307 (diff)
pkg/build: extract "multiple definition" linker errors
Diffstat (limited to 'pkg')
-rw-r--r--pkg/build/build.go22
-rw-r--r--pkg/build/build_test.go51
2 files changed, 68 insertions, 5 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go
index b51f1f78b..ffc5b0703 100644
--- a/pkg/build/build.go
+++ b/pkg/build/build.go
@@ -219,10 +219,13 @@ func extractCauseInner(s []byte, kernelSrc string) ([]byte, string) {
lines[i] = bytes.Replace(lines[i], stripPrefix, nil, -1)
}
if file == "" {
- match := fileRe.FindSubmatch(lines[i])
- if match != nil {
- file = string(match[1])
- if file[0] == '/' {
+ for _, fileRe := range fileRes {
+ match := fileRe.FindSubmatch(lines[i])
+ if match != nil {
+ file = string(match[1])
+ if file[0] != '/' {
+ break
+ }
// We already removed kernel source prefix,
// if we still have an absolute path, it's probably pointing
// to compiler/system libraries (not going to work).
@@ -232,6 +235,10 @@ func extractCauseInner(s []byte, kernelSrc string) ([]byte, string) {
}
}
file = strings.TrimPrefix(file, "./")
+ if strings.HasSuffix(file, ".o") {
+ // Linker may point to object files instead.
+ file = strings.TrimSuffix(file, ".o") + ".c"
+ }
res := bytes.Join(lines, []byte{'\n'})
// gcc uses these weird quotes around identifiers, which may be
// mis-rendered by systems that don't understand utf-8.
@@ -277,10 +284,15 @@ var buildFailureCauses = [...]buildFailureCause{
{pattern: []byte("ERROR: ")},
{pattern: []byte(": fatal error: ")},
{pattern: []byte(": undefined reference to")},
+ {pattern: []byte(": multiple definition of")},
{pattern: []byte(": Permission denied")},
{weak: true, pattern: []byte(": final link failed: ")},
{weak: true, pattern: []byte("collect2: error: ")},
{weak: true, pattern: []byte("FAILED: Build did NOT complete")},
}
-var fileRe = regexp.MustCompile(`^([a-zA-Z0-9_\-/.]+):[0-9]+:([0-9]+:)? `)
+var fileRes = []*regexp.Regexp{
+ regexp.MustCompile(`^([a-zA-Z0-9_\-/.]+):[0-9]+:([0-9]+:)? `),
+ regexp.MustCompile(`^(?:ld: )?(([a-zA-Z0-9_\-/.]+?)\.o):`),
+ regexp.MustCompile(`; (([a-zA-Z0-9_\-/.]+?)\.o):`),
+}
diff --git a/pkg/build/build_test.go b/pkg/build/build_test.go
index 16636737c..54b2efb49 100644
--- a/pkg/build/build_test.go
+++ b/pkg/build/build_test.go
@@ -415,4 +415,55 @@ make[1]: *** Waiting for unfinished jobs....
"",
"include/linux/netfilter_ipv6.h",
},
+ {`
+ld: mm/slub.o: in function '__kmem_cache_create':
+slub.c:(.text+0x6260): multiple definition of '__kmem_cache_create'; mm/page_alloc.o:page_alloc.c:(.text+0x1970): first defined here
+make: *** [Makefile:1139: vmlinux] Error 1
+`,
+ "slub.c:(.text+0x6260): multiple definition of '__kmem_cache_create'; mm/page_alloc.o:page_alloc.c:(.text+0x1970): first defined here",
+ "",
+ "mm/page_alloc.c",
+ },
+ {`
+ld: mm/slub.o:(.bss+0x0): multiple definition of 'foobar'; mm/page_alloc.o:(.bss+0x34): first defined here
+make: *** [Makefile:1139: vmlinux] Error 1
+`,
+ "ld: mm/slub.o:(.bss+0x0): multiple definition of 'foobar'; mm/page_alloc.o:(.bss+0x34): first defined here",
+ "",
+ "mm/slub.c",
+ },
+ {`
+ld.lld: error: duplicate symbol: __kmem_cache_create
+>>> defined at page_alloc.c
+>>> page_alloc.o:(__kmem_cache_create) in archive mm/built-in.a
+>>> defined at slub.c
+>>> slub.o:(.text+0x6260) in archive mm/built-in.a
+make: *** [Makefile:1139: vmlinux] Error 1
+`,
+ "ld.lld: error: duplicate symbol: __kmem_cache_create",
+ "",
+ "", // ld.lld makes it very hard to extract the file name
+ },
+ {`
+ld.lld: error: duplicate symbol: foobar
+>>> defined at page_alloc.c
+>>> page_alloc.o:(foobar) in archive mm/built-in.a
+>>> defined at slub.c
+>>> slub.o:(.bss+0x0) in archive mm/built-in.a
+make: *** [Makefile:1139: vmlinux] Error 1
+`,
+ "ld.lld: error: duplicate symbol: foobar",
+ "",
+ "", // ld.lld makes it very hard to extract the file name
+ },
+ {`
+mm/page_alloc.o:(.data+0x1a40): multiple definition of '__kmem_cache_create'
+mm/slub.o:(.data+0x7a0): first defined here
+Makefile:1160: recipe for target 'vmlinux' failed
+make: *** [vmlinux] Error 1
+`,
+ "mm/page_alloc.o:(.data+0x1a40): multiple definition of '__kmem_cache_create'",
+ "",
+ "mm/page_alloc.c",
+ },
}