<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94685>94685</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc] Unify location of baremetal output hooks
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
michaelrj-google
</td>
</tr>
</table>
<pre>
In patch #94078 I added a new baremetal hook to allow for writing directly from printf to some equivalent of `stdout`. During review it was brought up that there exists a hook in https://github.com/llvm/llvm-project/blob/main/libc/src/__support/OSUtil/baremetal/io.cpp for writing to an equivalent of `stderr`. These are distinct enough I think they should both be included, but similar enough they should probably be in the same spot.
Since this is an external hook it doesn't technically matter where we put it, but there should be a unified list. To get that sort of unified list it would make sense to also create a `write_to_stdout` to match the existing `write_to_stderr`. Then the question arises of "how should `write_to_stdout` work on platforms other than baremetal?"
Option 1: Direct syscall to write to fd 0.
Pro: Simple
Cons: Completely ignores the file buffering mechanism, causing out of order output.
Option 2: Write to the `stdout` `FILE` object.
Pro: Proper buffering behavior, we could use this in `puts` and `putchar` as well, meaning those don't need specialized baremetal versions.
Con: Complexity around dependency ordering.
Regardless of if we go with one of these options or something else, it's out of scope for that original patch.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU-P27gP_TTOhWjgKP8mhxz66_wCDLBAi22LPQ5ki7bZkUVXpJJmP_1CctPJLHrZS2LLpPT4Hh9lRagPiMdq-79q-7iwSQeOx5HawaKP3971zL3HRcPuenwKMFltB6jM-rCp9w_wBNY5dGAh4AUaG3FEtR4G5hdQBus9X6DjCJdISqEHRxFb9VfoIo8wRQra5UjhEQG_Jzpbj0GBO6h2tajjpNWuXsJjijk_4pnwAqRwsQJN5NQPCmkCHayCDhgR8AeJCtgZBgUYVCep1u8rc6rMqScdUrNseazMyfvz7e_dFPkbtlqZU-O5qcxptBTyR2raypwk5t_nZ0nTxDG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