summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-nm
Commit message (Collapse)AuthorAgeFilesLines
...
* [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
* Fix debug build by adding missing dependencies on libBinaryFormatSam Clegg2018-05-151-0/+1
| | | | | | | | Debug BUILD_SHARED_LIBS build was broken by rL332305 Differential Revision: https://reviews.llvm.org/D46859 llvm-svn: 332315
* 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
* [tools] Add option to install binutils symlinksShoaib Meenai2017-11-021-0/+4
| | | | | | | | | | | | The LLVM tools can be used as a replacement for binutils, in which case it's convenient to create symlinks with the binutils names. Add support for these symlinks in the build system. As with any other llvm tool symlinks, the user can limit the installed symlinks by only adding the desired ones to `LLVM_TOOLCHAIN_TOOLS`. Differential Revision: https://reviews.llvm.org/D39530 llvm-svn: 317272
* 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
* Rewrite demangle memory handling.Eric Christopher2017-06-301-3/+5
| | | | | | | | The return of itaniumDemangle is allocated with malloc rather than new[] and so using unique_ptr isn't called for here. As a note for the future we should rewrite it to do this. llvm-svn: 306788
* Change the type of Undecorated to unique_ptr<char[]> since we're looking at ↵Eric Christopher2017-06-301-1/+1
| | | | | | | | a null terminated string and not a single character. Fixes an error in tcmalloc sized delete checking. llvm-svn: 306780
* llvm-nm: Add support for symbol demangling (-C/--demangle)Sam Clegg2017-06-292-7/+35
| | | | | | Differential Revision: https://reviews.llvm.org/D34668 llvm-svn: 306718
* The change to llvm-nm in r305733 added fields to the struct NMSymbol Kevin Enderby2017-06-201-0/+7
| | | | | | | that are not set on the main path. This diff does a memset to 0 the structs so this change is to hopefully fix the sanitizer-x86_64-linux-fast bot. llvm-svn: 305762
* Change llvm-nm for Mach-O files to use dyld info in some cases when printing ↵Kevin Enderby2017-06-191-62/+528
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | symbols. In order to reduce swift binary sizes, Apple is now stripping swift symbols from the nlist symbol table. llvm-nm currently only looks at the nlist symbol table and misses symbols that are present in dyld info. This makes it hard to know the set of symbols for a binary using just llvm-nm. Unless you know to run llvm-objdump -exports-trie that can output the exported symbols in the dyld info from the export trie, which does so but in a different format. Also moving forward the time may come a when a fully linked Mach-O file that uses dyld will no longer have an nlist symbol table to avoid duplicating the symbol information. This change adds three flags to llvm-nm, -add-dyldinfo, -no-dyldinfo, and -dyldinfo-only. The first, -add-dyldinfo, has the same effect as when the new bit in the Mach-O header, MH_NLIST_OUTOFSYNC_WITH_DYLDINFO, appears in a binary. In that it looks through the dyld info from the export trie and adds symbols to be printed that are not already in its internal SymbolList variable. The -no-dyldinfo option turns this behavior off. The -dyldinfo-only option only looks at the dyld information and recreates the symbol table from the dyld info from the export trie and binding information. As if it the Mach-O file had no nlist symbol table. Also fixed a few bugs with Mach-O N_INDR symbols not correctly printing the indirect name, or in the same format as the old nm-classic program. rdar://32021551 llvm-svn: 305733
* Move Object format code to lib/BinaryFormat.Zachary Turner2017-06-071-1/+1
| | | | | | | | | | | | This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
* Print symbols from COFF import libraries.Rafael Espindola2017-05-241-1/+16
| | | | | | | | | This change allows llvm-nm to print symbols found in import libraries, in part by allowing COFFImportFiles to be casted to SymbolicFiles. Patch by Dave Lee! llvm-svn: 303821
* [WebAssembly] Improve readobj and nm support for wasmSam Clegg2017-04-141-0/+12
| | | | | | | | | Now that the libObect support for wasm is better we can have readobj and nm produce more useful output too. Differential Revision: https://reviews.llvm.org/D31514 llvm-svn: 300365
* Add a warning when the llvm-nm -print-size flag is used on a Mach-O file asKevin Enderby2017-01-251-3/+18
| | | | | | | | | | | | Mach-O files don’t have size information about the symbols in the object file format unlike ELF. Also add the part of the fix to llvm-nm that was missed with r290001 so -arch armv7m works. rdar://25681018 llvm-svn: 293099
* Fix a bugs with using some Mach-O command line flags like "-arch armv7m".Kevin Enderby2016-12-161-16/+16
| | | | | | | | | | | | | | | | | | The Mach-O command line flag like "-arch armv7m" does not match the arch name part of its llvm Triple which is "thumbv7m-apple-darwin”. I think the best way to fix this is to have llvm::object::MachOObjectFile::getArchTriple() optionally return the name of the Mach-O arch flag that would be used with -arch that matches the CPUType and CPUSubType. Then change llvm::object::MachOUniversalBinary::ObjectForArch::getArchTypeName() to use that and change it to getArchFlagName() as the type name is really part of the Triple and the -arch flag name is a Mach-O thing for a specific Triple with a specific Mcpu value. rdar://29663637 llvm-svn: 290001
* Object: Set SF_Indirect in ModuleSymbolTable.Peter Collingbourne2016-12-011-7/+2
| | | | | | | | This lets us remove the last use of IRObjectFile::getSymbolGV() in llvm-nm. Differential Revision: https://reviews.llvm.org/D27076 llvm-svn: 288321
* Object: Add SF_Executable symbol flag.Peter Collingbourne2016-12-011-16/+14
| | | | | | | | | | | | This allows us to remove a few uses of IRObjectFile::getSymbolGV() in llvm-nm. While here change host-dependent logic in llvm-nm to target-dependent logic. Differential Revision: https://reviews.llvm.org/D27075 llvm-svn: 288320
* Object: Add IRObjectFile::getTargetTriple().Peter Collingbourne2016-11-241-8/+2
| | | | | | | | This lets us remove a use of IRObjectFile::getModule() in llvm-nm. Differential Revision: https://reviews.llvm.org/D27074 llvm-svn: 287846
* llvm-nm: Print correct symbol types for init and fini sectionsMeador Inge2016-11-231-0/+3
| | | | | | | | | This patch fixes a small bug where symbols defined in the INIT and FINI sections were incorrectly getting a type of 'n'. Differential Revision: https://reviews.llvm.org/D26937 llvm-svn: 287803
* llvm-nm: Don't print value or size for undefined or weak symbolsMeador Inge2016-11-231-7/+15
| | | | | | | | | | | | | | | | | Undefined and weak symbols don't have a meaningful size or value. As such, nothing should be printed for those attributes (this is already done for the address with 'U') with the BSD format. This matches what GNU nm does. Note that for the POSIX.2 format [1] zero values are still printed for the size and value. This seems in spirit with the format strings in that specification, but is debatable. [1] http://pubs.opengroup.org/onlinepubs/9699919799/ Differential Revision: https://reviews.llvm.org/D26936 llvm-svn: 287802
* [CMake] llvm-nm depends on intrinsics_genChris Bieneman2016-11-191-0/+3
| | | | | | | | | | | | | llvm-nm.cpp has the following include chain: llvm/IR/Function.h llvm/IR/Argument.h llvm/IR/Attributes.h llvm/IR/Attributes.gen This means llvm-nm needs to depend on intrinsics_gen. llvm-svn: 287432
* Make the Error class constructor protectedMehdi Amini2016-11-111-4/+4
| | | | | | | | | This is forcing to use Error::success(), which is in a wide majority of cases a lot more readable. Differential Revision: https://reviews.llvm.org/D26481 llvm-svn: 286561
* Fix an unconditional break in checkMachOAndArchFlagsDavid Majnemer2016-10-311-2/+2
| | | | | | Found by PVS-Studio. llvm-svn: 285598
* Turn cl::values() (for enum) from a vararg function to using C++ variadic ↵Mehdi Amini2016-10-081-2/+2
| | | | | | | | | | | | | | | template The core of the change is supposed to be NFC, however it also fixes what I believe was an undefined behavior when calling: va_start(ValueArgs, Desc); with Desc being a StringRef. Differential Revision: https://reviews.llvm.org/D25342 llvm-svn: 283671
* Use the range variant of transform instead of unpacking begin/endDavid Majnemer2016-08-121-3/+3
| | | | | | No functionality change is intended. llvm-svn: 278477
* Add the first of what will be a long line of additional error checks for ↵Kevin Enderby2016-08-051-1/+1
| | | | | | | | | | | | | invalid Mach-O files. This is where an LC_SEGMENT load command has a fileoff field that extends past the end of the file. Also fix llvm-nm and llvm-size to remove the errorToErrorCode() call so error messages are printed. And needed to update a few test cases now that they do print the error messages just a bit differently. llvm-svn: 277845
* Clean up of libObject/Archive interfaces and change the last three uses of ↵Kevin Enderby2016-08-031-3/+3
| | | | | | | | | | | | ErrorOr<> changing them to Expected<> to allow them to pass through llvm Errors. No functional change. This commit by itself will break the next lld builds.  I’ll be committing the matching change for lld immediately next. llvm-svn: 277656
* The next step along the way to getting good error messages for bad archives.Kevin Enderby2016-07-291-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | As mentioned in commit log for r276686 this next step is adding a new method in the ArchiveMemberHeader class to get the full name that does proper error checking, and can be use for error messages. To do this the name of ArchiveMemberHeader::getName() is changed to ArchiveMemberHeader::getRawName() to be consistent with Archive::Child::getRawName(). Then the “new” method is the addition of a new implementation of ArchiveMemberHeader::getName() which gets the full name and provides proper error checking. Which is mostly a rewrite of what was Archive::Child::getName() and cleaning up incorrect uses of llvm_unreachable() in the code which were actually just cases of errors in the input Archives. Then Archive::Child::getName() is changed to return Expected<> and use the new implementation of ArchiveMemberHeader::getName() . Also needed to change Archive::getMemoryBufferRef() with these changes to return Expected<> as well to propagate Errors up. As well as changing Archive::isThinMember() to return Expected<> . llvm-svn: 277177
* [Object] Re-apply r275316 now that I have the corresponding LLD patch ready.Lang Hames2016-07-141-39/+35
| | | | llvm-svn: 275361
* [Object] Revert r275316, Archive::child_iterator changes, while I update lld.Lang Hames2016-07-141-35/+39
| | | | | | Should fix the bots broken by r275316. llvm-svn: 275353
* [Object] Change Archive::child_iterator for better interop with Error/Expected.Lang Hames2016-07-131-39/+35
| | | | | | | | | | | | | | | | | | | | | | | See http://reviews.llvm.org/D22079 Changes the Archive::child_begin and Archive::children to require a reference to an Error. If iterator increment fails (because the archive header is damaged) the iterator will be set to 'end()', and the error stored in the given Error&. The Error value should be checked by the user immediately after the loop. E.g.: Error Err; for (auto &C : A->children(Err)) { // Do something with archive child C. } // Check the error immediately after the loop. if (Err) return Err; Failure to check the Error will result in an abort() when the Error goes out of scope (as guaranteed by the Error class). llvm-svn: 275316
* Finish cleaning up most of the error handling in libObject’s ↵Kevin Enderby2016-06-281-3/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MachOUniversalBinary and its clients to use the new llvm::Error model for error handling. Changed getAsArchive() from ErrorOr<...> to Expected<...> so now all interfaces there use the new llvm::Error model for return values. In the two places it had if (!Parent) this is actually a program error so changed from returning errorCodeToError(object_error::parse_failed) to calling report_fatal_error() with a message. In getObjectForArch() added error messages to its two llvm::Error return values instead of returning errorCodeToError(object_error::arch_not_found) with no error message. For the llvm-obdump, llvm-nm and llvm-size clients since the only binary files in Mach-O Universal Binaries that are supported are Mach-O files or archives with Mach-O objects, updated their logic to generate an error when a slice contains something like an ELF binary instead of ignoring it. And added a test case for that. The last error stuff to be cleaned up for libObject’s MachOUniversalBinary is the use of errorOrToExpected(Archive::create(ObjBuffer)) which needs Archive::create() to be changed from ErrorOr<...> to Expected<...> first, which I’ll work on next. llvm-svn: 274079
OpenPOWER on IntegriCloud