<div dir="ltr"><div><span style="font-family:arial,sans-serif">I have been working towards this on
D63859. My current route was to add an optional callback to
MemoryBuffer::getFileOrSTDIN which will be executed if stdin has not
been redirected. James and I were talking over there and are maybe
deciding that this might not be the best solution. The alternative in my
mind is that the tools which want this behavior could do so by
explicitly testing if Process::StandardInIsUserInput rather than let
getFileOrSTDIN do it. This might be the better approach than passing a
callback to getFileOrSTDIN which perhaps not all tools will use anyway. <span style="font-family:arial,sans-serif"> I am leaning towards doing it outside of getFileOrSTDIN. </span>Does anyone have a preference either way, or a better solution than the above two?</span></div><div><br></div><div>Best,</div><div>Alex</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 26, 2019 at 3:09 PM Jake Ehrlich <<a href="mailto:jakehehrlich@google.com">jakehehrlich@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I think consistency is key and agree that people are likely not using this anywhere. It's better to go after the ideal at first but we need to be willing to offer some path forward on these tools if it turns out large code bases that can't be easily modified use this trick. So I suppose we should do it but be willing to switch back.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 26, 2019 at 10:15 AM via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="gmail-m_7890619524548307925gmail-m_451309304323115272WordSection1">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Like James, Michael suggested, I would prefer the default behavior be consistent across tools (either always read from stdin or no default at all /give error
messages)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<div style="border-color:currentcolor currentcolor currentcolor blue;border-style:none none none solid;border-width:medium medium medium 1.5pt;padding:0in 0in 0in 4pt">
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> James Henderson <<a href="mailto:jh7370.2008@my.bristol.ac.uk" target="_blank">jh7370.2008@my.bristol.ac.uk</a>>
<br>
<b>Sent:</b> Wednesday, June 26, 2019 2:31 AM<br>
<b>To:</b> Alex Brachet-Mialot <<a href="mailto:alexbrachetmialot@gmail.com" target="_blank">alexbrachetmialot@gmail.com</a>><br>
<b>Cc:</b> Fāng-ruì Sòng <<a href="mailto:maskray@google.com" target="_blank">maskray@google.com</a>>; LLVMDev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>; Jordan Rupprecht <<a href="mailto:rupprecht@google.com" target="_blank">rupprecht@google.com</a>>; Chen, Yuanfang <<a href="mailto:Yuanfang.Chen@sony.com" target="_blank">Yuanfang.Chen@sony.com</a>><br>
<b>Subject:</b> Re: [llvm-dev] [RFC] [tools] Changing Behavior of LLVM binutils When No File Is Specified<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">I agree with others that the a.out behaviour is weird (I've even thought this about the linker output being called a.out since I started programming, but perhaps that's a different story). The use-case I can imagine is something like:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">$ ld.lld test.o<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ llvm-objdump -d<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I.e. using a tool immediately after generating the linker output. However, I don't think this is likely actually done by anybody, and I think it's probably safe to change the behaviour here. I'd rather be universal across the tools (e.g.
always read from stdin) than do this frankly. An error message about a missing input file might be nice in some cases (llvm-readelf, llvm-objdump, llvm-nm), but I think we definitely want to support the option of stdin redirection if nothing else but for test
purposes. If it's complicated to achieve both the error under non-redirection cases, and no error in redirection cases then I'd prefer the latter.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Regards,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">James<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, 26 Jun 2019 at 08:28, Alex Brachet-Mialot via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Sounds good, I'll work on removing these in favor of defaulting to stdin then?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">> I think it would be much friendlier to just print "file or pipe expected" and then print the help.
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Do you have thoughts on this? I'm not sure there is a clean way to do this, the cleanest would be through getFileOrSTDIN(), but I'm not sure all of its users want this behavior. I don't think we need it personally, but if you think its
a good quality of life change to the tools and worth working on, I'd be happy to do so.<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Jun 26, 2019 at 1:41 AM Fāng-ruì Sòng <<a href="mailto:maskray@google.com" target="_blank">maskray@google.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">GNU addr2line, nm, objdump, and size default to a.out when no input file is specified.<br>
Among llvm binary utilities, llvm-nm llvm-objdump llvm-size llvm-dwarfdump default to a.out.<br>
<br>
I agree with Michael that a.out behavior may not be used by many people. If people don't care too much<br>
about these utilities' compatibility with GNU, deleting the default a.out LGTM.<br>
<br>
(I am opposed to make more utilities default to a.out)<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Jun 26, 2019 at 9:02 AM Alex Brachet-Mialot via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">> Does anyone actually use the default to a.out behavior?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">This is a good point. What bugs me is continuity across the tools, I agree with you that it isn't particularly useful to default to a.out. But we are kind of stuck with the weird way that GNU's binutils do things. I am not in favor of llvm-objdump
defaulting to a.out, but llvm-readelf giving this warning message. My guess is that moving away from using a.out by default for llvm-objdump, llvm-nm and others whose gnu counter parts do this would be more disruptive than my proposal.
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">As Jake pointed out we use "-" to describe stdin/stdout, GNU's tools do not do this, so I think there is some precedence for us slightly modifying behavior when we can reasonably say things will not happen, like the file "-" existing.
<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Tue, Jun 25, 2019 at 8:28 PM Michael Spencer <<a href="mailto:bigcheesegs@gmail.com" target="_blank">bigcheesegs@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<div>
<p class="MsoNormal">On Tue, Jun 25, 2019 at 4:58 PM Alex Brachet-Mialot via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
</div>
</div>
<div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Some binutils, nm comes to mind, when to input file is specified will default to a.out. Others do not do this and read from stdin by default. The rest of this email will be specifically referencing these which read from stdin, and not the
tools which for various reasons do things differently.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I propose that we change the behavior of these tools to use a.out when appropriate. By appropriate I mean firstly, no input file specified and also no stream redirection to stdin. These are the file types of stdin in these scenarios:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ writes-to-stdout | prog # named pipe (fifo)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ prog < file # regular file<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ prog # reading from tty, character device<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Perhaps if stdin is a named pipe or regular file, then the default behavior should be as it always was, to read from stdin, but if stdin is a tty then we should use a.out as a default file. This lets these tools act the same as their gnu
counterparts (when meaningful) but also adds what I think is convenient to not have to specify a.out.
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This proposal would look something like this:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ llvm-strings # not meanigful to read from stdin here, look for a.out<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ llvm-strings < file # use stdin<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I may have got the behavior of stream redirection wrong here, or missed a situation when reading from the terminal is useful. I would love some feedback.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Best,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Alex<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Does anyone actually use the default to a.out behavior? I think it would be much friendlier to just print "file or pipe expected" and then print the help. <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">- Michael Spencer <u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-family:DengXian" lang="ZH-CN">宋方睿</span><u></u><u></u></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div>