This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Change common diagnostics to report both object file location and source file location
ClosedPublic

Authored by MaskRay on Oct 26 2021, 12:19 AM.

Details

Summary

Many diagnostics use getErrorPlace or getErrorLocation to report a location.
In the presence of line table debug information, getErrorPlace uses a source
file location and ignores the object file location. However, the object file
location is sometimes more useful.

This patch changes "undefined symbol" and "out of range" diagnostics to report
both object/source file locations. Other diagnostics can use similar format if
needed.

The key idea is to let InputSectionBase::getLocation report the object file
location and use getSrcMsg for source file/line information. getSrcMsg
doesn't leverage STT_FILE information yet, but I think the temporary lack of
the functionality is ok.

For the ARM "branch and link relocation" diagnostic, I arbitrarily place the
source file location at the end of the line. The diagnostic is not very common
so its formatting doesn't need to be pretty.

Diff Detail

Event Timeline

MaskRay created this revision.Oct 26 2021, 12:19 AM
MaskRay requested review of this revision.Oct 26 2021, 12:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 26 2021, 12:19 AM
MaskRay edited the summary of this revision. (Show Details)Oct 26 2021, 12:20 AM
MaskRay edited the summary of this revision. (Show Details)

Overall I think the changes are going in the right direction. Just wanted to check that losing the function symbol information in the error messages was intentional?

lld/ELF/Arch/ARM.cpp
390–392

The first 4 lines of the if/else statement bodies look to be the same. Worth moving before the if/else?

lld/ELF/InputSection.cpp
287

I think the comment might be out of date. I think this is an object location now.

lld/test/ELF/ppc64-split-stack-adjust-overflow.s
23 ↗(On Diff #382208)

I note that we're missing the (function caller) before (.text+0x8). Same in next test. Is this intentional? Although this can be derived from looking at objdump/readelf it would be a shame to lose it.

lld/test/ELF/x86-64-reloc-error2.s
5

It looks like we are no longer reporting the function, only its section. I'm sure the references func is the target of the relocation. If we no longer output the information we should update the comment.

Thanks for working on this.
Maybe add a test for debug relocation overflow?

On side note. What do you think of expanding the error reporting to print out a section in to which relocation that overflowed "points to"?

MaskRay updated this revision to Diff 382535.Oct 26 2021, 11:56 PM
MaskRay marked 4 inline comments as done.
MaskRay edited the summary of this revision. (Show Details)

add a dedicated test

improve formatting

MaskRay added inline comments.Oct 26 2021, 11:57 PM
lld/test/ELF/ppc64-split-stack-adjust-overflow.s
23 ↗(On Diff #382208)

I restored the function func: part. The change is reverted.

lld/test/ELF/x86-64-reloc-error2.s
5

I restored the function func: part. The change is reverted.

Thanks for the update, I don't have any more comments. No objections to this landing assuming others are happy.

Thanks for the comments and the positive responses.
On the related D109400 we've waited for @evgeny777 for quite some time.

I'll push this tomorrow.

This revision was not accepted when it landed; it landed in state Needs Review.Oct 28 2021, 9:38 AM
This revision was automatically updated to reflect the committed changes.