This is an archive of the discontinued LLVM Phabricator instance.

[llvm-nm] Don't report "no symbols" error for files that contain symbols
ClosedPublic

Authored by sbc100 on Jan 13 2020, 3:15 PM.

Details

Summary

Previously we were reporting this error if we were list no symbols
which is not the same thing as the file containing no symbols.

Also, always report the filename when printing errors.

This matches the GNU nm behaviour.

This a followup to https://reviews.llvm.org/D52810

Diff Detail

Event Timeline

sbc100 created this revision.Jan 13 2020, 3:15 PM
sbc100 edited the summary of this revision. (Show Details)Jan 13 2020, 3:17 PM

A few comments/suggestions from me.

llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml
14

nit: we often remove the excessive identation. It
makes the output to be a bit more readable.

16

nit: Some of the llvm-nm tests are using ## for comments, just like
many other our tools already do. I'd follow this style as it is really common nowadays.

llvm/test/tools/llvm-nm/X86/nm-no-symbols.test
11

I see that this way of name checking existed before this patch, but FTR my concern
is that the output name depends on the lit naming rules.

I.e. I'd suggest to be a bit more explicit here:

# RUN: yaml2obj %s > %t.o
# RUN: llvm-nm %t.o 2>&1 | FileCheck %s -DFILE=%t.o
...
# CHECK: [[FILE]]: no symbols{{$}}
llvm/tools/llvm-nm/llvm-nm.cpp
710

I think this either could accept Twines:

writeFileName(raw_ostream &S, const Twine ArchiveName, ...

or I am thinking it could probably be:

std::string getFileName(const Twine ArchiveName, ...)

I think in the latter case the callers code can be a bit nicer/simpler probably.

1739

You probably can use the existent error() method from line 224 for reporting:

static void error(Twine Message, Twine Path = Twine()) {
  HadError = true;
  WithColor::error(errs(), ToolName) << Path << ": " << Message << ".\n";
}
grimar added inline comments.Jan 14 2020, 12:31 AM
llvm/tools/llvm-nm/llvm-nm.cpp
710

const Twine -> const Twine &

As mentioned in D52810, GNU nm's behaviour is the same for both a symbol table with only a null symbol and a completely missing symbol table (both print "no symbols"). I think both need testing.

llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml
2

It migth make more sense to merge this and the existing test into a single test, with multiple YAML documents, since it's only a minor variation.

3

I know this existed in the pre-existing test, but I feel like that test should be fixed too. This won't prove that "no symbols" is printed on stderr, because it's merged with stdout. I think it would be best to pipe stderr to a separate file completely and check that file.

llvm/tools/llvm-nm/llvm-nm.cpp
1739

No, I don't think so. That would cause it to print "error:" and colour the output, which isn't right.

sbc100 updated this revision to Diff 238001.Jan 14 2020, 9:15 AM
  • use count
sbc100 updated this revision to Diff 238005.Jan 14 2020, 9:34 AM
sbc100 marked 6 inline comments as done.
  • double comments
  • use [[FILE]]
llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml
2

I'd rather leave it separate if thats ok with you. They seems different enough to me and it makes it easier to run them individually.

3

I'm just trying to show the output is empty. I've updated it to use "count 0" which clearer.

If you want to fix the existing test thats a separate issue.

14

The prevailing style in this directory seems to be to preserve the yaml with indentation and alignment. I'm not sure I agree that its more readable either. So if its OK with you I'll leave this as is for this change and you and propose an widespread change if you feel strongly.

llvm/tools/llvm-nm/llvm-nm.cpp
710

I was initially going to do that are part of this change but I'm inclined to follow the style of writeFileName below and leave that refactor to a follow up change.

sbc100 updated this revision to Diff 238015.Jan 14 2020, 9:47 AM
  • static

Followup change to convert params to StringRef: https://reviews.llvm.org/D72718

sbc100 updated this revision to Diff 238312.Jan 15 2020, 10:12 AM
  • remove old check
jhenderson added inline comments.Jan 16 2020, 2:50 AM
llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml
14

I'm also of the opinion that new tests are better without the extra whitespace for readability. However, I don't think it's worth the noise to fix up the existing tests - I prefer a more organic migration from one style to the other, i.e. as you change the YAML in an area, update it.

sbc100 updated this revision to Diff 238617.Jan 16 2020, 2:07 PM
  • rebase
sbc100 updated this revision to Diff 238618.Jan 16 2020, 2:08 PM
  • remove indentation

D72718 landed first so switched to StringRef for args. Also remove extra indentation in yaml.

Unit tests: fail. 61930 tests passed, 5 failed and 783 were skipped.

failed: Clang.CodeGen/thinlto_backend.ll
failed: Clang.InterfaceStubs/externstatic.c
failed: Clang.InterfaceStubs/function-template-specialization.cpp
failed: Clang.InterfaceStubs/inline.c
failed: lld.ELF/lto/thinlto-obj-path.ll

clang-tidy: unknown.

clang-format: pass.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Unit tests: fail. 61930 tests passed, 5 failed and 783 were skipped.

failed: Clang.CodeGen/thinlto_backend.ll
failed: Clang.InterfaceStubs/externstatic.c
failed: Clang.InterfaceStubs/function-template-specialization.cpp
failed: Clang.InterfaceStubs/inline.c
failed: lld.ELF/lto/thinlto-obj-path.ll

clang-tidy: unknown.

clang-format: pass.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

This revision is now accepted and ready to land.Jan 17 2020, 5:25 AM
This revision was automatically updated to reflect the committed changes.

Oops, looks like this broke some tests. Investigating.