llvm.org GIT mirror llvm / 94d01e5
[tools] [llvm-nm] Default to reading from stdin not a.out 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 [[ https://lists.llvm.org/pipermail/llvm-dev/2019-July/133642.html | here ]]. Reviewers: jhenderson, rupprecht, MaskRay, chrisjackson Reviewed By: jhenderson, MaskRay Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64290 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365889 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Brachet a month ago
3 changed file(s) with 43 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
1212
1313 The :program:`llvm-nm` utility lists the names of symbols from LLVM bitcode
1414 files, object files, and archives. Each symbol is listed along with some simple
15 information about its provenance. If no filename is specified, *a.out* is used
16 as the input. If *-* is used as a filename, :program:`llvm-nm` will read a file
17 from its standard input stream.
15 information about its provenance. If no filename is specified, or *-* is used as
16 a filename, :program:`llvm-nm` will read a file from its standard input stream.
1817
1918 :program:`llvm-nm`'s default output format is the traditional BSD :program:`nm`
2019 output format. Each such output record consists of an (optional) 8-digit
0 ## Test llvm-nm when using stdin both explicitly (using '-' as a filename)
1 ## and implicitly (not specifying any filename).
2
3 # RUN: yaml2obj %s -o %t.o
4
5 ## Pass an explicit filename to produce a baseline output. llvm-nm should
6 ## have the same behavior when opening a file itself and when reading that
7 ## file from its standard input stream.
8 # RUN: llvm-nm %t.o > %t.base 2> %t.err
9
10 ## Make sure there is no warning message about no file redirected to stdin.
11 # RUN: FileCheck %s --input-file=%t.err --allow-empty --implicit-check-not={{.}}
12
13 # RUN: llvm-nm - < %t.o > %t.explicit 2> %t.err
14 # RUN: FileCheck %s --input-file=%t.err --allow-empty --implicit-check-not={{.}}
15 # RUN: cmp %t.base %t.explicit
16
17 # RUN: llvm-nm < %t.o > %t.implicit 2> %t.err
18 # RUN: FileCheck %s --input-file=%t.err --allow-empty --implicit-check-not={{.}}
19 # RUN: cmp %t.base %t.implicit
20
21 !ELF
22 FileHeader:
23 Class: ELFCLASS64
24 Data: ELFDATA2LSB
25 Type: ET_REL
26 Machine: EM_X86_64
27 Sections:
28 - Name: .text
29 Type: SHT_PROGBITS
30 Symbols:
31 - Name: symbol_a
32 Section: .text
3333 #include "llvm/Support/Format.h"
3434 #include "llvm/Support/InitLLVM.h"
3535 #include "llvm/Support/MemoryBuffer.h"
36 #include "llvm/Support/Process.h"
3637 #include "llvm/Support/Program.h"
3738 #include "llvm/Support/Signals.h"
3839 #include "llvm/Support/TargetSelect.h"
17501751 }
17511752
17521753 static void dumpSymbolNamesFromFile(std::string &Filename) {
1754 if (Filename == "-" && sys::Process::StandardInIsUserInput()) {
1755 WithColor::warning(errs(), ToolName) << "can't read from terminal\n";
1756 cl::PrintHelpMessage();
1757 HadError = true;
1758 return;
1759 }
17531760 ErrorOr> BufferOrErr =
17541761 MemoryBuffer::getFileOrSTDIN(Filename);
17551762 if (error(BufferOrErr.getError(), Filename))
20812088 if (OutputFormat == sysv || SizeSort)
20822089 PrintSize = true;
20832090 if (InputFilenames.empty())
2084 InputFilenames.push_back("a.out");
2091 InputFilenames.push_back("-");
20852092 if (InputFilenames.size() > 1)
20862093 MultipleFiles = true;
20872094