The high-level answer is that library code shouldn’t hardcode output paths, including “-” and including using llvm::outs(). Library code should (in general) instead accept an ostream in its API and write to wherever it is being asked to write. If this is followed, the only place in any program using llvm::outs() is code which is not part of a “library” – i.e. it is the “main” code, and it should only do so if it is a program which doesn’t open file names which could be “-”.
Do you have a use-case where this restriction is too restrictive?
As a random aside, a more aggressive answer could be that “-” is a kind of hack, and that it would be a better approach to use /dev/stdout and /dev/stdin instead of “-”, because they wouldn’t require special-case logic. Unfortunately, this may not be sufficiently portable.
lld takes a -emit-yaml option, which emits the intermediate representation(atoms) in YAML form.
By default output goes to stdout, the user can control it by using the -o option too.
The way its handled is, similiar to this piece of pseudo-code
if (dash_o_option)
outputFile = dash_o_option->value()
else
outputFile = "-"
When lld tries to mix things that go to stdout using llvm::outs() and -emit-yaml, it starts to get this error.
If there is a restriction like this, possibly it has to be mentioned somewhere for usecases (or) raw_fd_ostream should not be accepting a '-' in the argument.
What is the other output going to stdout? Seems like it could get mixed into the yaml output, causing problems.
If -o is not supplied, the linker normally writes to a file called “a.out”. If this is for the core linker when running test suites, may would should have the core linker create a temp file or string buffer to write to (if -o not supplied) and then at the end read from that file and write to stdout.
Standard error is what many tools, including clang for example, use for their --verbose output. This is appropriate because it leaves standard output available for regular output data, which the user may wish to capture in a file or a pipe.
Standard error is what many tools, including clang for example, use for their --verbose output. This is appropriate because it leaves standard output available for regular output data, which the user may wish to capture in a file or a pipe.
Well, at least with the darwin linker, the linker main output goes to a file (specified by -o or “a.out”). So, since there is normally nothing going to stdout, -v and -t output goes to stdout.
Shankar, although not quite as convenient, we could change the core linker test cases from:
lld … | FileCheck
to:
lld … -o %t && FileCheck < %t
Then change the core linker to not use “-“, but error if -o is not supplied.
It's a very common lit test pattern to do 'clang/llc %s ... -o - |
FileCheck %s ', and lld should probably support that. It should be just a
matter of avoiding outs().