This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Print absolute file name in errors when possible.
ClosedPublic

Authored by grimar on Dec 7 2016, 1:03 AM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 80550.Dec 7 2016, 1:03 AM
grimar retitled this revision from to [ELF] - Print absolute file name in errors when possible..
grimar updated this object.
grimar added reviewers: ruiu, rafael, evgeny777.
grimar added subscribers: llvm-commits, grimar.
grimar updated this revision to Diff 80551.Dec 7 2016, 1:16 AM
  • Convert path separators to *nix style.
ruiu accepted this revision.Dec 7 2016, 8:46 AM
ruiu edited edge metadata.

LGTM

ELF/InputFiles.cpp
95 ↗(On Diff #80551)

Add a blank line before #ifdef.

test/ELF/Inputs/undef-debug.s
1 ↗(On Diff #80551)

nit: "folder" as a term is probably windows-ish too? probably "dir" or something.

This revision is now accepted and ready to land.Dec 7 2016, 8:46 AM
grimar added inline comments.Dec 7 2016, 8:49 AM
ELF/InputFiles.cpp
95 ↗(On Diff #80551)

I am going to export convertToUnixPathSeparator from \llvm\tools\lld\lib\Core\Reproduce.cpp as was requested by Rafael and use it here instead.

ruiu added inline comments.Dec 7 2016, 8:50 AM
ELF/InputFiles.cpp
95 ↗(On Diff #80551)

OK, but if it involves packing into SmallString and unpack it to std::string, it would be uglier than this, so please upload a patch after you make a change. Thanks.

grimar updated this revision to Diff 80612.Dec 7 2016, 9:12 AM
grimar edited edge metadata.
  • Exported and reused convertToUnixPathSeparator().
grimar added inline comments.Dec 7 2016, 9:14 AM
ELF/InputFiles.cpp
95 ↗(On Diff #80551)

It did not involve packing/unpacking..

ruiu added a comment.Dec 7 2016, 9:24 AM

LGTM

ELF/InputFiles.cpp
95 ↗(On Diff #80551)

Use Ret.data() instead of &Ret[0] because the latter is invalid if Ret is empty. (That shouldn't happen in this case, but always avoiding &Ret[0] is a good idea.)

grimar added inline comments.Dec 7 2016, 11:42 AM
ELF/InputFiles.cpp
95 ↗(On Diff #80551)

That is true, but data() returns const char*, that why I did not use it as it requires cast then.
It is not very clean to remove const, though in c++ 11 it is safe to modify pointer returned by data() afaik.

Do you really prefer:

convertToUnixPathSeparator({(char*)Ret.data(), Ret.size()});

?

This revision was automatically updated to reflect the committed changes.
ruiu added a comment.Dec 7 2016, 11:54 AM

I prefer a more functional approach. We don't need to modify a string in place. We can create a new string and return it.

ruiu added a comment.Dec 7 2016, 12:58 PM

By the way, the commit message was not accurate. It does not print out an absolute path. An absolute path is a path starts with '/' or a drive letter. This patch is to include path components in error messages instead of just base names.

In D27506#616268, @ruiu wrote:

By the way, the commit message was not accurate. It does not print out an absolute path. An absolute path is a path starts with '/' or a drive letter. This patch is to include path components in error messages instead of just base names.

Technically you probably correct. My naming was based on "DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath" I am using.