This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Make subsequent opens to auxiliary files append
ClosedPublic

Authored by abrachet on Jun 27 2023, 7:02 AM.

Details

Summary

Previously, the same file could be used across diagnostic options but
the file would be silently overwritten by the whichever option gets
handled last.

Diff Detail

Event Timeline

abrachet created this revision.Jun 27 2023, 7:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2023, 7:02 AM
abrachet requested review of this revision.Jun 27 2023, 7:02 AM

I wonder whether this behavior is conventional? CC some folks to get some opinions.

@arichardson @ikudrin @smeenai @peter.smith

Note, if we use - as the output (stdout), they actually get appended --print-archive-stats=- --why-extract=-. In this case, supporting this seems fine.

lld/ELF/Config.h
468

I wonder whether openAuxiliaryFile is more appropriate. The file type has a wide ranges including non-diagnostic use cases.

lld/test/ELF/diagnostic-options.test
2

This creates a file in the current directory which is not allowed in some cases, e.g. Google's internal lit runner.

3

You can just use /dev/null as the only input file.

We don't use this ourselves, but in general, appending seems like a much friendlier behavior than overwriting in this case. Do we need to be concerned about any simultaneous attempted writes to the same file though?

FWIW Arm's proprietary linker armlink puts out all diagnostics on one stream under append which includes the map file. It works well although we didn't have to contend with multiple threads interleaving the output.

It looks like the current cases are all in the single threaded path so this shouldn't be a problem.

One possibility that could be worth doing if we can detect that files share the same file is to put some extra line breaks or a header to distinguish between diagnostics. That may not be worth the complexity though.

abrachet updated this revision to Diff 535460.Jun 28 2023, 10:30 AM
MaskRay added inline comments.Jun 28 2023, 2:53 PM
lld/ELF/Config.h
458

This variable and the subject haven't been updated.

lld/test/ELF/diagnostic-options.test
5

## From --print-archive-stats

abrachet updated this revision to Diff 535760.Jun 29 2023, 6:07 AM
abrachet marked 3 inline comments as done.
abrachet retitled this revision from [ELF] Allow multiple diagnostic options to the same file to [ELF] Make subsequent opens to auxiliary files append.
abrachet marked 2 inline comments as done.Jun 29 2023, 6:30 AM

One possibility that could be worth doing if we can detect that files share the same file is to put some extra line breaks or a header to distinguish between diagnostics. That may not be worth the complexity though.

The --cref output adds a newline, but does it so unconditionally, so --cref without -Map will print a newline followed by the rest of the output to stdout. Regarding the complexity, because raw_fd_ostream is not copyable/movable I think openAuxiliaryFile would need to first create the raw_fd_ostream, write the newline, then create it again to for return elision. I do think that I don't feel strongly either way, so I'll defer to what others think

MaskRay accepted this revision.Jun 29 2023, 9:44 AM
This revision is now accepted and ready to land.Jun 29 2023, 9:44 AM
abrachet updated this revision to Diff 538636.Jul 10 2023, 7:21 AM

Use %t instead of /dev/null which lit emulates on windows by renaming the file

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 4:09 AM