Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-link] Improve missing file error message #82514

Merged

Conversation

mhalk
Copy link
Contributor

@mhalk mhalk commented Feb 21, 2024

Add error messages showing the missing filenames.

Currently, we only get 'No such file or directory' without any(!) further info. This patch will (only upon ENOENT error) iterate over all requested files and print which ones are actually missing.

@mhalk mhalk force-pushed the mhalk/feature/llvm_link_missing_file_err_improvement branch from 0314d0f to da7f21e Compare February 21, 2024 18:13
std::unique_ptr<MemoryBuffer> Buffer =
ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(File)));
ExitOnErr(errorOrToExpected(std::move(ErrOrExpected)));
Copy link
Contributor

@jhuber6 jhuber6 Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if it's necessary to error on all missing files at the same time. I would recommend just returning an error on this file if it's not found, and using something like createStringError("No such file or directory: %s", F.str()).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if it's necessary to error on all missing files at the same time.

I have no strong preference here, as long as I get the filename instead of nothing.
Q: So you'd prefer only one error message mentioning the first missing file?

I would recommend just returning an error on this file if it's not found [...]

Like this? (If not: what do you mean by 'returning'?)

  // When we encounter a missing file, print all missing files to stderr.
  if (auto EC = ErrOrExpected.getError())
    if (EC == std::errc::no_such_file_or_directory)
      ExitOnErr(createStringError(EC, "No such file or directory: %s", File.c_str()));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I had in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

@mhalk mhalk force-pushed the mhalk/feature/llvm_link_missing_file_err_improvement branch from da7f21e to ba85225 Compare February 21, 2024 21:32
@@ -393,8 +393,16 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
// Similar to some flags, internalization doesn't apply to the first file.
bool InternalizeLinkedSymbols = false;
for (const auto &File : Files) {
auto ErrOrExpected = MemoryBuffer::getFileOrSTDIN(File);
Copy link
Contributor

@jhuber6 jhuber6 Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, this variable name is a little weird, maybe BufferOrErr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check! I'll keep that in mind and address along with further potential feedback.
(Sorry, did not see this comment at the time of hitting the button.)

@mhalk mhalk requested a review from jhuber6 February 21, 2024 21:35
Add error message showing the missing filename.

Currently, we only get 'No such file or directory' without any(!) further info.
This patch will (upon ENOENT error) create an error which exposes the filename.
@mhalk mhalk force-pushed the mhalk/feature/llvm_link_missing_file_err_improvement branch from ba85225 to 73bbd41 Compare February 22, 2024 17:09
@mhalk
Copy link
Contributor Author

mhalk commented Feb 22, 2024

Should we add something that (lit-)checks the changed error message?

@jhuber6
Copy link
Contributor

jhuber6 commented Feb 22, 2024

Should we add something that (lit-)checks the changed error message?

If there's an existing check it may still pass since it checks the prefix. I don't think it's an issue personally.

mhalk added a commit to mhalk/aomp that referenced this pull request Feb 22, 2024
Add a simple test, which is trying to link a non-existent file, since the error
message will be expanded by the missing file's name.

Depends: llvm/llvm-project#82514
mhalk added a commit to mhalk/aomp that referenced this pull request Feb 22, 2024
Add a simple test, which is trying to link a non-existent file, since the error
message will be expanded by the missing file's name.

Depends: llvm/llvm-project#82514
@jhuber6 jhuber6 merged commit a64ff96 into llvm:main Feb 23, 2024
4 checks passed
@mhalk mhalk deleted the mhalk/feature/llvm_link_missing_file_err_improvement branch April 2, 2024 16:15
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Apr 3, 2024
Add error messages showing the missing filenames.

Currently, we only get 'No such file or directory' without any(!)
further info. This patch will (only upon ENOENT error) iterate over all
requested files and print which ones are actually missing.

Change-Id: I2a240e66576980e6878891e10ad3c5972b47ea1f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants