[lld] r288966 - [ELF] - Print absolute file name in errors when possible.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 7 11:42:25 PST 2016
Author: grimar
Date: Wed Dec 7 13:42:25 2016
New Revision: 288966
URL: http://llvm.org/viewvc/llvm-project?rev=288966&view=rev
Log:
[ELF] - Print absolute file name in errors when possible.
Currently LLD prints basename of source file name in error messages,
for example:
$ mkdir foo
$ echo 'void _start(void) { foobar(); }' > foo/bar.c
$ gcc -g -c foo/bar.c
$ bin/ld.lld -o out bar.o
bin/ld.lld: error: bar.c:1: undefined symbol 'foobar'
$
This should say:
bin/ld.lld: error: foo/bar.c:1: undefined symbol 'foobar'
This is PR31299
Differential revision: https://reviews.llvm.org/D27506
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/include/lld/Core/Reproduce.h
lld/trunk/lib/Core/Reproduce.cpp
lld/trunk/test/ELF/Inputs/undef-debug.s
lld/trunk/test/ELF/undef.s
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=288966&r1=288965&r2=288966&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Dec 7 13:42:25 2016
@@ -86,12 +86,14 @@ std::string elf::ObjectFile<ELFT>::getLi
// Use fake address calcuated by adding section file offset and offset in
// section. See comments for ObjectInfo class.
DILineInfo Info;
- DILineInfoSpecifier Spec;
- Tbl->getFileLineInfoForAddress(S->Offset + Offset, nullptr, Spec.FLIKind,
- Info);
+ Tbl->getFileLineInfoForAddress(
+ S->Offset + Offset, nullptr,
+ DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, Info);
if (Info.Line == 0)
return "";
- return Info.FileName + ":" + std::to_string(Info.Line);
+ std::string Ret = Info.FileName + ":" + std::to_string(Info.Line);
+ convertToUnixPathSeparator({(char*)Ret.data(), Ret.size()});
+ return Ret;
}
// Returns "(internal)", "foo.a(bar.o)" or "baz.o".
Modified: lld/trunk/include/lld/Core/Reproduce.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Reproduce.h?rev=288966&r1=288965&r2=288966&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Reproduce.h (original)
+++ lld/trunk/include/lld/Core/Reproduce.h Wed Dec 7 13:42:25 2016
@@ -11,6 +11,7 @@
#define LLD_CORE_REPRODUCE_H
#include "lld/Core/LLVM.h"
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Error.h"
@@ -65,6 +66,9 @@ std::string rewritePath(StringRef S);
// Returns the string form of the given argument.
std::string stringize(llvm::opt::Arg *Arg);
+// Converts path to use unix path separators.
+void convertToUnixPathSeparator(llvm::MutableArrayRef<char> Path);
+
}
#endif
Modified: lld/trunk/lib/Core/Reproduce.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Reproduce.cpp?rev=288966&r1=288965&r2=288966&view=diff
==============================================================================
--- lld/trunk/lib/Core/Reproduce.cpp (original)
+++ lld/trunk/lib/Core/Reproduce.cpp Wed Dec 7 13:42:25 2016
@@ -50,14 +50,6 @@ static void writeMember(raw_fd_ostream &
OS << Data; // c_filedata
}
-// Converts path to use unix path separators so the cpio can be extracted on
-// both unix and windows.
-static void convertToUnixPathSeparator(SmallString<128> &Path) {
-#ifdef LLVM_ON_WIN32
- std::replace(Path.begin(), Path.end(), '\\', '/');
-#endif
-}
-
void CpioFile::append(StringRef Path, StringRef Data) {
if (!Seen.insert(Path).second)
return;
@@ -127,3 +119,9 @@ std::string lld::stringize(opt::Arg *Arg
return K + V;
return K + " " + V;
}
+
+void lld::convertToUnixPathSeparator(MutableArrayRef<char> Path) {
+#ifdef LLVM_ON_WIN32
+ std::replace(Path.begin(), Path.end(), '\\', '/');
+#endif
+}
Modified: lld/trunk/test/ELF/Inputs/undef-debug.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/undef-debug.s?rev=288966&r1=288965&r2=288966&view=diff
==============================================================================
--- lld/trunk/test/ELF/Inputs/undef-debug.s (original)
+++ lld/trunk/test/ELF/Inputs/undef-debug.s Wed Dec 7 13:42:25 2016
@@ -1,4 +1,4 @@
-.file 1 "undef-debug.s"
+.file 1 "dir/undef-debug.s"
.loc 1 3
.quad zed3
Modified: lld/trunk/test/ELF/undef.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/undef.s?rev=288966&r1=288965&r2=288966&view=diff
==============================================================================
--- lld/trunk/test/ELF/undef.s (original)
+++ lld/trunk/test/ELF/undef.s Wed Dec 7 13:42:25 2016
@@ -9,9 +9,9 @@
# CHECK: error: undef.s:(.text+0x6): undefined symbol 'bar'
# CHECK: error: undef.s:(.text+0x10): undefined symbol 'foo(int)'
# CHECK: error: {{.*}}2.a({{.*}}.o):(.text+0x0): undefined symbol 'zed2'
-# CHECK: error: undef-debug.s:3: undefined symbol 'zed3'
-# CHECK: error: undef-debug.s:7: undefined symbol 'zed4'
-# CHECK: error: undef-debug.s:11: undefined symbol 'zed5'
+# CHECK: error: dir/undef-debug.s:3: undefined symbol 'zed3'
+# CHECK: error: dir/undef-debug.s:7: undefined symbol 'zed4'
+# CHECK: error: dir/undef-debug.s:11: undefined symbol 'zed5'
# RUN: not ld.lld %t.o %t2.a -o %t.exe -no-demangle 2>&1 | \
# RUN: FileCheck -check-prefix=NO-DEMANGLE %s
More information about the llvm-commits
mailing list