Skip to content

Commit b65016d

Browse files
committed
[ELF] For VS-style diagnostics, prefer printing full paths in the header.
The filename part in the message header is used by Visual Studio to fill Error List so that a user can click on an item and jump to the mentioned location. If we use only the name of a source file and not the full path, Visual Studio might be unable to find the right file or, even worse, show a wrong one. Differential Revision: https://reviews.llvm.org/D65875 llvm-svn: 368409
1 parent e1a5f66 commit b65016d

File tree

7 files changed

+54
-8
lines changed

7 files changed

+54
-8
lines changed

lld/Common/ErrorHandler.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,18 @@ std::string ErrorHandler::getLocation(const Twine &msg) {
114114

115115
static std::regex regexes[] = {
116116
std::regex(
117-
R"(^undefined (?:\S+ )?symbol:.*\n>>> referenced by (\S+):(\d+)\n.*)"),
117+
R"(^undefined (?:\S+ )?symbol:.*\n)"
118+
R"(>>> referenced by .+\((\S+):(\d+)\))"),
119+
std::regex(
120+
R"(^undefined (?:\S+ )?symbol:.*\n>>> referenced by (\S+):(\d+))"),
118121
std::regex(R"(^undefined symbol:.*\n>>> referenced by (.*):)"),
119122
std::regex(
120123
R"(^duplicate symbol: .*\n>>> defined in (\S+)\n>>> defined in.*)"),
121-
std::regex(R"(^duplicate symbol: .*\n>>> defined at (\S+):(\d+).*)"),
124+
std::regex(
125+
R"(^duplicate symbol: .*\n>>> defined at .+\((\S+):(\d+)\))"),
126+
std::regex(R"(^duplicate symbol: .*\n>>> defined at (\S+):(\d+))"),
127+
std::regex(
128+
R"(.*\n>>> defined in .*\n>>> referenced by .+\((\S+):(\d+)\))"),
122129
std::regex(R"(.*\n>>> defined in .*\n>>> referenced by (\S+):(\d+))"),
123130
std::regex(R"((\S+):(\d+): unclosed quote)"),
124131
};
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.file "duplicate3.s"
22

3-
.global baz
3+
.global baz, qux
44
.text
55
baz:
66
nop
7+
qux:
8+
nop

lld/test/ELF/vs-diagnostics-duplicate-split.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
33
// RUN: not ld.lld --vs-diagnostics --shared %t.o %t.o -o /dev/null 2>&1 | FileCheck %s
44

5-
// CHECK: duplicate.s(15): error: duplicate symbol: foo
5+
// CHECK: /tmp{{/|\\}}duplicate.s(15): error: duplicate symbol: foo
66
// CHECK-NEXT: >>> defined at duplicate.s:15 (/tmp{{/|\\}}duplicate.s:15)
77
// CHECK-NEXT: >>>{{.*}}.o:(.text+0x{{.+}})
8-
// CHECK: duplicate.s(15): error: duplicate symbol: foo
8+
// CHECK: /tmp{{/|\\}}duplicate.s(15): error: duplicate symbol: foo
99
// CHECK-NEXT: >>> defined at duplicate.s:15 (/tmp{{/|\\}}duplicate.s:15)
1010
// CHECK-NEXT: >>>{{.*}}.o:(.text+0x{{.+}})
1111

lld/test/ELF/vs-diagnostics-duplicate.s

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@
2424
// CHECK-NEXT: >>> defined at duplicate3.s
2525
// CHECK-NEXT: >>> {{.*}}3.o:(.text+0x{{.+}})
2626

27-
.global _start, foo, bar, baz
27+
// Check that we prefer using the full path of a source file.
28+
// CHECK: /tmp{{/|\\}}duplicate.s(33): error: duplicate symbol: qux
29+
// CHECK-NEXT: >>> defined at duplicate.s:33 (/tmp{{/|\\}}duplicate.s:33)
30+
// CHECK-NEXT: >>> {{.*}}1.o:(.text+0x{{.+}})
31+
// CHECK-NEXT: >>> defined at duplicate3.s
32+
// CHECK-NEXT: >>> {{.*}}3.o:(.text+0x{{.+}})
33+
34+
.global _start, foo, bar, baz, qux
2835
.text
2936
_start:
3037
nop
@@ -42,6 +49,11 @@ bar:
4249
baz:
4350
nop
4451

52+
.file 2 "/tmp" "duplicate.s"
53+
.loc 2 33
54+
qux:
55+
nop
56+
4557
.section .debug_abbrev,"",@progbits
4658
.byte 1 # Abbreviation Code
4759
.byte 17 # DW_TAG_compile_unit

lld/test/ELF/vs-diagnostics-dynamic-relocation.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,23 @@
77
// CHECK-NEXT: >>> referenced by dyn.s:15
88
// CHECK-NEXT: >>>{{.*}}.o:(.text+0x{{.+}})
99

10+
// CHECK: /tmp{{/|\\}}dyn.s(20): error: can't create dynamic relocation {{.*}}
11+
// CHECK-NEXT: >>> defined in {{.*}}.o
12+
// CHECK-NEXT: >>> referenced by dyn.s:20 (/tmp{{/|\\}}dyn.s:20)
13+
// CHECK-NEXT: >>>{{.*}}.o:(.text+0x{{.+}})
14+
1015
.file 1 "dyn.s"
1116
.loc 1 15
1217

1318
foo:
1419
.quad foo
1520

21+
.file 2 "/tmp" "dyn.s"
22+
.loc 2 20
23+
24+
bar:
25+
.quad bar
26+
1627
.section .debug_abbrev,"",@progbits
1728
.byte 1 # Abbreviation Code
1829
.byte 17 # DW_TAG_compile_unit

lld/test/ELF/vs-diagnostics-undefined-hidden.s

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@
99
// CHECK: undef.s(27): error: undefined protected symbol: bar
1010
// CHECK-NEXT: >>> referenced by undef.s:27
1111

12+
// CHECK: /tmp{{/|\\}}undef.s(13): error: undefined protected symbol: baz
13+
// CHECK-NEXT: >>> referenced by undef.s:13 (/tmp{{/|\\}}undef.s:13)
14+
1215
.file 1 "undef.s"
16+
.file 2 "/tmp" "undef.s"
1317

1418
.hidden foo
15-
.protected bar
19+
.protected bar, baz
1620
.text
1721
_start:
1822
.loc 1 15
1923
jmp foo
2024
.loc 1 27
2125
jmp bar
26+
.loc 2 13
27+
jmp baz
2228

2329
.section .debug_abbrev,"",@progbits
2430
.byte 1 # Abbreviation Code

lld/test/ELF/vs-diagnostics-undefined-symbol-3.s

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@
1010
// CHECK: >>> referenced by undef3.s:15
1111
// CHECK-NEXT: >>> {{.*}}1.o:(.text+0x{{.+}})
1212

13+
// ERR: /tmp{{/|\\}}undef3.s(20): error: undefined symbol: bar
14+
// WARN: /tmp{{/|\\}}undef3.s(20): warning: undefined symbol: bar
15+
// CHECK: >>> referenced by undef3.s:20 (/tmp{{/|\\}}undef3.s:20)
16+
// CHECK-NEXT: >>> {{.*}}1.o:(.text+0x{{.+}})
17+
1318
.file 1 "undef3.s"
19+
.file 2 "/tmp" "undef3.s"
1420

15-
.global _start, foo
21+
.global _start, foo, bar
1622
.text
1723
_start:
1824
.loc 1 15
1925
jmp foo
26+
.loc 2 20
27+
jmp bar
2028

2129
.section .debug_abbrev,"",@progbits
2230
.byte 1 # Abbreviation Code

0 commit comments

Comments
 (0)