summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-nm/llvm-nm.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Revert [llvm-nm] Fix handling of symbol types + [llvm-nm] Generalize symbol ↵Jordan Rupprecht2019-05-021-11/+28
| | | | | | | | types This reverts r359311 and r359312 (git commit 0bf06a8f59b0074a60871865e828d92db8930c59 and 5f184f17800ea2ac27be5e4ab540cb94a46e80c7) llvm-svn: 359830
* [Object] Change getSectionName() to return Expected<StringRef>Fangrui Song2019-05-021-7/+9
| | | | | | | | | | Summary: It currently receives an output parameter and returns std::error_code. Expected<StringRef> fits for this purpose perfectly. Differential Revision: https://reviews.llvm.org/D61421 llvm-svn: 359774
* [llvm-nm] Add --special-syms no-op flagEugene Leviant2019-04-301-0/+3
| | | | | | Differential revision: https://reviews.llvm.org/D60502 llvm-svn: 359563
* [llvm-nm] Simplify and fix a buffer overflowFangrui Song2019-04-291-149/+107
| | | | | | | | | | | | | * char SymbolAddrStr[18] can't hold "%" PRIo64 which may need 22 characters. * Use range-based for * Delete unnecessary typedef * format(...).print(Str, sizeof(Str)) + outs() << Str => outs() << format(...) * Use cascading outs() << .. << .. * Use iterator_range(Container &&c) * (A & B) == B => A & B if B is a power of 2 * replace null sentinel in constants with makeArrayRef llvm-svn: 359416
* [llvm-nm][llvm-readelf] Avoid single-dash -long-option in testsFangrui Song2019-04-271-4/+0
| | | | llvm-svn: 359383
* [llvm-nm] Support section type 'u': STB_GNU_UNIQUEFangrui Song2019-04-271-0/+4
| | | | llvm-svn: 359380
* [llvm-nm] Revert inadvertently committed 'i' change in r359314Fangrui Song2019-04-261-3/+0
| | | | llvm-svn: 359315
* [ThinLTO] Fix X86/strong_non_prevailing.ll after llvm-nm 'r' changeFangrui Song2019-04-261-0/+3
| | | | llvm-svn: 359314
* [llvm-nm] Generalize symbol types 'N', 'n' and '?'Fangrui Song2019-04-261-9/+5
| | | | llvm-svn: 359312
* [llvm-nm] Fix handling of symbol types 't' 'd' 'r'Fangrui Song2019-04-261-19/+6
| | | | | | | | | | | | | | | In addition, fix and convert the two tests to yaml2obj based. This allows us to delete two executables. X86/weak.test: 'v' was not tested X86/init-fini.test: symbol types of __bss_start _edata _end were wrong GNU nm reports __init_array_start as 't', and __preinit_array_start as 'd'. __init_array_start is 't' just because its section ".init_array" starts with ".init" 'd' makes more sense and allows us to drop the weird SHT_INIT_ARRAY rule. So, change __init_array_start to 'd' instead. llvm-svn: 359311
* Make llvm-nm -help great againSerge Guelton2019-04-111-33/+58
| | | | | | | | | Only display help from the llvm-nm category instead of all llvm options, which make it much more usable. There's still an issue with -s, which is probably a bug in llvm::cl and worth another commit. Differential Revision: https://reviews.llvm.org/D60411 llvm-svn: 358185
* [llvm-nm]Add support for --no-demangleJames Henderson2019-04-031-3/+10
| | | | | | | | | | | | | GNU nm has --no-demangle, so llvm-nm should too. It disables the --demangle switch. The patch also allows --demangle to be specified multiple times (the last of all --no-demangle/--demangle switches takes precedence). Reviewed by: grimar, rupprecht, mattd Differential Revision: https://reviews.llvm.org/D60134 llvm-svn: 357575
* Improve "llvm-nm -f sysv" output for Elf filesSunil Srivastava2019-03-081-3/+42
| | | | | | | | | | Specifically, compute and Print Type and Section columns. This is a re-commit of rL354833, after fixing the Asan problem found a a buildbot. Differential Revision: https://reviews.llvm.org/D59060 llvm-svn: 355742
* Revert "Improve "llvm-nm -f sysv" output for Elf files"Vlad Tsyrklevich2019-02-261-44/+4
| | | | | | | This reverts commit r354833, it was causing ASan test failures on sanitizer-x86_64-linux-fast. llvm-svn: 354849
* Improve "llvm-nm -f sysv" output for Elf filesSunil Srivastava2019-02-261-4/+44
| | | | | | | | Specifically, compute and Print Type and Section columns. Differential Revision: https://reviews.llvm.org/D58263 llvm-svn: 354833
* llvm-nm: Observe -no-llvm-bc for archive membersDave Lee2019-02-161-6/+8
| | | | | | | | | | | | | | | | | | | | | Summary: This change fixes the `-no-llvm-bc` flag to work with object files within archives. Currently the `-no-llvm-bc` flag works for regular object files, but not static libraries, where it continues to show bitcode symbol info. Original support was added in D4371. Reviewers: compnerd, smeenai, pcc Reviewed By: compnerd Subscribers: rupprecht, keith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D48798 llvm-svn: 354196
* Compute the correct symbol size in llvm-nm even without --print-sizeSunil Srivastava2019-02-031-4/+2
| | | | | | | | | | | | | | In llvm-nm, the symbol size was being computed only with --print-size option, even though it was being printed in other cases, such as with --format=posix. This patch simply removes the guard, so that the size is computed independently of the later decision to print it or not. Fixes PR39997. Differential Revision: https://reviews.llvm.org/D57599 llvm-svn: 353011
* [llvm-nm] Report '.comment' ELF sections as 'n' instead of '?'Matt Davis2019-02-011-0/+1
| | | | | | | | | | | | | | | | | | | Summary: The previous implementation reported `.comment` sections as '?' GNU uses 'n' which means "The symbol is a debugging symbol." `.note` sections are represented as 'n' too. The test related to this change was updated to CHECK-NEXT to ensure order and that we did not miss any symbols in the dump. Reviewers: jhenderson Reviewed By: jhenderson Subscribers: rupprecht, llvm-commits Differential Revision: https://reviews.llvm.org/D57544 llvm-svn: 352891
* [llvm-nm] Print out N_COLD_FUNC as "cold func"Vedant Kumar2019-01-261-1/+1
| | | | | | | Per post-commit feedback from Mike, have llvm-nm print out this symbol attribute as "[cold func]". llvm-svn: 352258
* [MC] Teach the MachO object writer about N_FUNC_COLDVedant Kumar2019-01-251-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | N_FUNC_COLD is a new MachO symbol attribute. It's a hint to the linker to order a symbol towards the end of its section, to improve locality. Example: ``` void a1() {} __attribute__((cold)) void a2() {} void a3() {} int main() { a1(); a2(); a3(); return 0; } ``` A linker that supports N_FUNC_COLD will order _a2 to the end of the text section. From `nm -njU` output, we see: ``` _a1 _a3 _main _a2 ``` Differential Revision: https://reviews.llvm.org/D57190 llvm-svn: 352227
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [llvm-nm] Allow --size-sort to print symbols with only Symbol sizeSaurabh Badhwar2019-01-161-2/+1
| | | | | | | | | | | | | | | | | | | Summary: When llvm-nm is passed only the --size-sort option for an object file, there is no output generated. The commit modifies the behavior to print the symbols sorted and their size which is also inline with the output of the GNU nm tool. Signed-off-by: Saurabh Badhwar <sbsaurabhbadhwar9@gmail.com> Reviewers: enderby, rupprecht Reviewed By: rupprecht Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D56063 llvm-svn: 351347
* [llvm-nm] Add --portability as alias for --format=posixJames Henderson2019-01-071-0/+2
| | | | | | | | | | | | | GNU nm supports this alias, so supporting it in llvm-nm makes it easier to transition between the two. Fixes https://bugs.llvm.org/show_bug.cgi?id=40002 Reviewed by: mstorsjo, rupprecht Differential Revision: https://reviews.llvm.org/D56312 llvm-svn: 350522
* [binutils] NFC: fix clang-tidy warning: use empty() instead of size() == 0Jordan Rupprecht2018-12-201-4/+4
| | | | llvm-svn: 349710
* [llvm-nm] Fix use-after-free for MachOUniversalBinariesFrancis Visoiu Mistrih2018-11-191-1/+2
| | | | | | | | | MachOObjectFile::getHostArch() returns a temporary, and getArchName returns a StringRef pointing to a temporary std::string. No tests since it doesn't trigger any errors except with the sanitizers. llvm-svn: 347230
* [llvm-nm] Use WithColor for error reportingJonas Devlieghere2018-11-111-7/+8
| | | | | | Use helpers from Support/WithError.h to print errors. llvm-svn: 346624
* [Support] Make error banner optional in logAllUnhandledErrorsJonas Devlieghere2018-11-111-7/+6
| | | | | | | | In a lot of places an empty string was passed as the ErrorBanner to logAllUnhandledErrors. This patch makes that argument optional to simplify the call sites. llvm-svn: 346604
* [llvm-nm] Simplify. NFCFangrui Song2018-10-261-14/+7
| | | | | | | | Change a \t to spaces Change some zero-filling memcpy to aggregate initialization Delete redundant ArchiveName.clear() after declaration llvm-svn: 345367
* [llvm-nm] Fix crash when running with --print-armap on corrupt archives.Jordan Rupprecht2018-10-111-2/+4
| | | | | | | | error() in llvm-nm intentionally does not return so that the callee can move on to future files/slices. When printing the archive map, this is not currently handled (the caller assumes that error() returns), so processing continues despite there being an error. Also, change one return to a break, so that symbols can be printed even if the archive map is corrupt. llvm-svn: 344268
* [llvm-nm] Include the text "@FILE" in the output of --helpMartin Storsjo2018-10-111-0/+2
| | | | | | | | | | libtool requires this text to be present, in order to conclude that the tool supports response files. Also add an explicit test of using response files with llvm-nm. Differential Revision: https://reviews.llvm.org/D53064 llvm-svn: 344222
* [llvm-nm] Write "no symbol" output to stderrPetr Hosek2018-10-051-8/+8
| | | | | | | | | | This matches the output of binutils' nm and ensures that any scripts or tools that use nm and expect empty output in case there no symbols don't break. Differential Revision: https://reviews.llvm.org/D52943 llvm-svn: 343887
* [llvm-nm] Print an explicit "no symbols" message when an object file has no ↵Jordan Rupprecht2018-10-031-11/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | symbols Summary: GNU nm (and other nm implementations, such as "go tool nm") prints an explicit "no symbols" message when an object file has no symbols. Currently llvm-nm just doesn't print anything. Adding an explicit "no symbols" message will allow llvm-nm to be used in place of nm: some scripts and build processes use `nm <file> | grep "no symbols"` as a test to see if a file has no symbols. It will also be more familiar to anyone used to nm. That said, the format implemented here is slightly different, in that it doesn't print the tool name in the message (which IMHO is not useful to include). Demo: ``` $ for nm in nm bin/llvm-nm ; do echo "nm implementation: $nm"; $nm /tmp/foo{1,2}.o; echo; done nm implementation: nm /tmp/foo1.o: nm: /tmp/foo1.o: no symbols /tmp/foo2.o: 0000000000000000 T foo2 nm implementation: bin/llvm-nm /tmp/foo1.o: no symbols /tmp/foo2.o: 0000000000000000 T foo2 ``` Reviewers: MaskRay Reviewed By: MaskRay Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D52810 llvm-svn: 343742
* llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song2018-09-271-1/+1
| | | | | | | | | | | | Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits Differential Revision: https://reviews.llvm.org/D52573 llvm-svn: 343163
* nm: Add -no-weak flag for hiding weak symbolsDave Lee2018-07-021-1/+8
| | | | | | | | | | | | | | | | | | Summary: This adds a new -no-weak flag to nm to hide weak symbols in its output. This also adds a -W alias for this which is analogous to -U. Patch by Keith Smiley Reviewers: kastiglione, enderby, compnerd Reviewed By: kastiglione Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D48751 llvm-svn: 336126
* Define InitLLVM to do common initialization all at once.Rui Ueyama2018-04-131-7/+2
| | | | | | | | | | | We have a few functions that virtually all command wants to run on process startup/shutdown. This patch adds InitLLVM class to do that all at once, so that we don't need to copy-n-paste boilerplate code to each llvm command's main() function. Differential Revision: https://reviews.llvm.org/D45602 llvm-svn: 330046
* [tools] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang2018-04-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | Summary: r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort. Refer the comments section in D44363 for a list of all the required patches. Reviewers: JDevlieghere, zturner, echristo, dberris, friss Reviewed By: echristo Subscribers: gbedwell, llvm-commits Differential Revision: https://reviews.llvm.org/D45141 llvm-svn: 328943
* Try to fix sanitizer-x86_64-linux-fast bot due to change in r328820.Kevin Enderby2018-03-291-2/+2
| | | | llvm-svn: 328824
* For llvm-nm and Mach-O files that are fully stripped, special case a ↵Kevin Enderby2018-03-291-2/+11
| | | | | | | | | | | | | | redacted LC_MAIN As a further refinement on: r328274 - For llvm-nm and Mach-O files also use function starts info in some cases when printing symbols we want to special case a redacted LC_MAIN so it is easier to find. rdar://38978929 llvm-svn: 328820
* For llvm-nm and Mach-O files also use function starts info in someKevin Enderby2018-03-221-2/+90
| | | | | | | | | | | | | | cases when printing symbols. As an improvement to: r305733 - Change llvm-nm for Mach-O files to use dyld info in some cases when printing symbols it could be made a bit better if it also read the function starts and faked up nlist entries to those address not already faked up by the other dyld info. This would help with stripped static functions. rdar://38761029 llvm-svn: 328274
* llvm-nm should show a symbol type of T for symbols in the ↵Kevin Enderby2018-01-311-0/+4
| | | | | | | | | | | | | | | (__TEXT_EXEC,__text) section. When a the Apple link editor builds a kext bundle file type and the value of the -miphoneos-version-min argument is significantly current (like 11.0) then the (__TEXT,__text) section is changed to the (__TEXT_EXEC,__text) section. So it would be nice for llvm-nm to show symbols in that section with a type of T instead of the generic type of S for some section other than text, data, etc. rdar://36262205 llvm-svn: 323836
* Remove redundant includes from tools.Michael Zolotukhin2017-12-131-9/+0
| | | | llvm-svn: 320631
* Add llvm::for_each as a range-based extensions to <algorithm> and make use ↵Aaron Ballman2017-11-031-2/+1
| | | | | | of it in some cases where it is a more clear alternative to std::for_each. llvm-svn: 317356
* [llvm-nm] Don't error out on multiple occurrances of the -g/--external-only flagMartin Storsjo2017-11-031-2/+4
| | | | | | | | | | | GNU binutils nm doesn't error out on this, and some projects' build systems can end up doing that in some cases. Allowing that seems like a better target than trying to avoid user projects passing multiple -g parameters to $NM. Differential Revision: https://reviews.llvm.org/D39539 llvm-svn: 317301
* [llvm-nm] Print 'I' for import table data in COFFMartin Storsjo2017-11-031-0/+4
| | | | | | | | | | | | | | | | | | | | | | The character gets uppercased into 'I' when it's a global symbol. In GNU binutils, nm prints 'I' for symbols classified by bfd_is_ind_section - which probably isn't exactly/only import tables. When building for win32, (some incarnations of?) libtool has got rules that try to inspect linked libraries, and in order to be sure that it is linking to a DLL import library as opposed to a static library, it expects to find the string " I " in the output of $NM when run on such an import library. GNU binutils nm also flags all of the .idata$X chunks as 'i' (while this patch only makes it set on .idata$2 and .idata$6) and also flags __imp__function as 'I'. Differential Revision: https://reviews.llvm.org/D39540 llvm-svn: 317300
* Revert "[ADT] Make Twine's copy constructor private."Zachary Turner2017-10-111-2/+2
| | | | | | | | | | This reverts commit 4e4ee1c507e2707bb3c208e1e1b6551c3015cbf5. This is failing due to some code that isn't built on MSVC so I didn't catch. Not immediately obvious how to fix this at first glance, so I'm reverting for now. llvm-svn: 315536
* [ADT] Make Twine's copy constructor private.Zachary Turner2017-10-111-2/+2
| | | | | | | | | | | | | | | | | There's a lot of misuse of Twine scattered around LLVM. This ranges in severity from benign (returning a Twine from a function by value that is just a string literal) to pretty sketchy (storing a Twine by value in a class). While there are some uses for copying Twines, most of the very compelling ones are confined to the Twine class implementation itself, and other uses are either dubious or easily worked around. This patch makes Twine's copy constructor private, and fixes up all callsites. Differential Revision: https://reviews.llvm.org/D38767 llvm-svn: 315530
* Fix a crash in llvm-nm for a bad Mach-O file that has an N_SECT type symbol ↵Kevin Enderby2017-09-131-0/+6
| | | | | | | | | | | | | | and a zero n_sect value. The code in llvm-nm for Mach-O files to determine the section type for an N_SECT type symbol it will call getSymbolSection() and check for the error, but in the case the n_sect value is zero it will return section_end() (aka nullptr). And the code was using that and crashing instead of just returning a ’s’ for a section or printing (?,?) as it would if getSymbolSection() returned an error. rdar://33136604 llvm-svn: 313193
* [llvm-nm] Fix output formatting of -f sysv for 64bit targetsSam Clegg2017-08-311-3/+7
| | | | | | Differential Revision: https://reviews.llvm.org/D37347 llvm-svn: 312284
* [llvm] Update MachOObjectFile::exports interfaceAlexander Shaposhnikov2017-07-291-2/+1
| | | | | | | | | | This diff removes the second argument of the method MachOObjectFile::exports. In all in-tree uses this argument is equal to "this" and without this argument the interface seems to be cleaner. Test plan: make check-all llvm-svn: 309462
* Add error handling to the dyld compact export entries in libObject.Kevin Enderby2017-07-201-1/+5
| | | | | | | | | | | | | | | | | | | | | lld needs a matching change for this will be my next commit. Expect it to fail build until that matching commit is picked up by the bots. Like the changes in r296527 for dyld bind entires and the changes in r298883 for lazy bind, weak bind and rebase entries the export entries are the last of the dyld compact info to have error handling added. This follows the model of iterators that can fail that Lang Hanes designed when fixing the problem for bad archives r275316 (or r275361). So that iterating through the exports now terminates if there is an error and returns an llvm::Error with an error message in all cases for malformed input. This change provides the plumbing for the error handling, all the needed testing of error conditions and test cases for all of the unique error messages. llvm-svn: 308690
OpenPOWER on IntegriCloud