This is an archive of the discontinued LLVM Phabricator instance.

[tools] [llvm-objdump] Default to reading from stdin not a.out
AbandonedPublic

Authored by abrachet on Jul 14 2019, 6:40 AM.

Details

Summary

This moves away from defaulting to a.out and uses stdin only if stdin has a file redirected to it. This has been discussed on the llvm-dev mailing list here.

Diff Detail

Event Timeline

abrachet created this revision.Jul 14 2019, 6:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2019, 6:40 AM
MaskRay added inline comments.Jul 14 2019, 6:42 PM
llvm/test/tools/llvm-objdump/stdin.test
9

You can writes this as:

not llvm-objdump -h < /dev/null 2>&1 | FileCheck %s

to test that llvm-objdump doesn't read from a.out

compnerd requested changes to this revision.Jul 14 2019, 6:44 PM
compnerd added a subscriber: compnerd.

This breaks compatibility with objdump. Please ensure that the original behavior is preserved when invoked as objdump rather than llvm-objdump.

This revision now requires changes to proceed.Jul 14 2019, 6:44 PM

This breaks compatibility with objdump. Please ensure that the original behavior is preserved when invoked as objdump rather than llvm-objdump.

This was discussed on the mailing list, it was decided that defaulting to a.out was not something that was worth maintaining compatibility with GNU and favored standardizing the llvm tools, ie reading from stdin on default.

FWIW, I favored defaulting to a.out when stdin is a tty and stdin when a file has been redirected in.

This breaks compatibility with objdump. Please ensure that the original behavior is preserved when invoked as objdump rather than llvm-objdump.

Hi @compnerd,

Do you have a concrete use-case for reading from a.out? The mailing list discussion was of the opinion that this was not an area we need GNU compatibility with. However, we could probably be persuaded otherwise with appropriate evidence.

objcopy is often used in autotools to run tests of what the compiler is doing. I'm afraid that changing that behaviour will break the autoconf tests which rely on the behaviour (a.out is what the compiler generates by default, and that is why the tool defaults to that filename). So, if you have something like the following:

cc test.c
objcopy --extract-dwo

to test whether you can do split-debug with dwarf packages, it will break.

We could do:

if (InputFilenames.empty())
  InputFilenames.push_back(StandardInIsUserInput() ? "a.out" : "-");

This behavior would be very confusing though. Not to mention wouldn't even work always (doesn't for lit which seemingly redirects something to stdin).

FWIW, @MaskRay pointed out that addr2line defaults to a.out but llvm-addr2line doesn't. Since that thread llvm-nm also defaults to reading from standard input while nm uses a.out, see rL365889. I have no preference I don't mind going back on this or rL365889.

objcopy is often used in autotools to run tests of what the compiler is doing. I'm afraid that changing that behaviour will break the autoconf tests which rely on the behaviour (a.out is what the compiler generates by default, and that is why the tool defaults to that filename). So, if you have something like the following:

cc test.c
objcopy --extract-dwo

to test whether you can do split-debug with dwarf packages, it will break.

It's worth noting that this is not about llvm-objcopy. It's about llvm-objdump. I don't believe our llvm-objcopy has the behaviour you've described implemented anyway. That being said, I think it's a valid point and you should bring it up on the thread on the mailing list to discuss it, so that this discussion gets more visibility: https://lists.llvm.org/pipermail/llvm-dev/2019-July/133642.html

Thats what I get for not having coffee before responding. objdump is used quite a bit in tests as well (objdump -t | grep ..., objdump -h | grep ..., etc).

abrachet abandoned this revision.Jul 28 2019, 3:52 PM