This patch adds -vs-diagnostics flag to lld so that the linker prints
out error messages in the format that is friendly to Microsoft Visual Studio.
Since the existing error message format of lld and MSVC are significantly
different, and in most cases we print out more information than MSVC,
it is not practical nor beneficial to make lld to print out the same error
messages as MSVC does.
It looks like the most annoying issue if you are using lld on MSVC is that
the IDE automatically makes the first word of the first line of a linker
error message a hypertext, expecting that the word is an error location.
We print out "ld.lld" there by default, so when you click that string on
the IDE, it opens the linker binary file -- which is not useful at all.
In this patch, I'm focusing on fixing that issue.
This patch adds a function to find an error location in an error message.
If -vs-diagnostics is given, lld calls that function and prints out its
return value instead of "ld.lld". That operation is purely textual; I
used regexps to recognize some error message patterns to extract an error
location.
An alternative approach would have been abstracting error message
construction so that we can construct both the existing and MSVC-style
error messages.
Doing everything over a text might seems too primitive compared to adding
an abstraction layer, but I think the former is overall a better approach
than the latter. It is much less intrusive and very easy to understand.
And if you think of it, this is similar to what IDEs do to recognize and
highlight compiler and linker error messages. They do recognize some
patterns because linkers print out somewhat structured error messages.
If IDEs can recognize it, so do we. If our error message is machine-
unfriendly, we should change the error message.
This is a counter-proposal to https://reviews.llvm.org/D58300. This is
a proof-of-concept to share the idea. I think I need to add a few more
regexes to make it usable.