[PATCH] D112518: [ELF] Change common diagnostics to report both object file location and source file location

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 26 00:19:32 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: ayermolo, bd1976llvm, evgeny777, jhenderson, peter.smith.
Herald added subscribers: kbarton, kristof.beyls, arichardson, nemanjai, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Many diagnostics use `getErrorPlace` or `getErrorLocation` to report a location.
In the presence of line table debug information, the result of `getErrorPlace`
uses a source file location and ignores the object file location. However, the
object file location is sometimes more useful (a source file may be compiled
into multiple object files and an object file may be an archive member).

"undefined symbol" and "out of range" are two most common diagnostics. This
patch adds `srcLoc` to `ErrorPlace` and changes the common diagnostics to report
object file location first, then report `\n>>> referenced by ${srcLoc}` if debug
info is available.

The key idea is that `InputSectionBase::getLocation` duplicates a bit of the
functionality of `getSrcMsg`, but `getSrcMsg` does not use `STT_FILE`
information. We can add `STT_FILE` fallback to `getSrcMsg` later. I think the
temporarly lack of `STT_FILE` is ok.

For the ARM "branch and link relocation" diagnostic, I randomly 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112518

Files:
  lld/ELF/Arch/ARM.cpp
  lld/ELF/InputSection.cpp
  lld/ELF/Relocations.cpp
  lld/ELF/Target.cpp
  lld/ELF/Target.h
  lld/test/ELF/arm-thumb-interwork-notfunc.s
  lld/test/ELF/ppc64-error-toc-local-call.s
  lld/test/ELF/ppc64-split-stack-adjust-overflow.s
  lld/test/ELF/x86-64-reloc-error2.s
  lld/test/ELF/x86-64-reloc-range-debug-loc.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112518.382208.patch
Type: text/x-patch
Size: 15601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211026/52b80fe6/attachment.bin>


More information about the llvm-commits mailing list