1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
Commit Graph

322 Commits

Author SHA1 Message Date
Sunil Srivastava
10930d44a1 Compute the correct symbol size in llvm-nm even without --print-size
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
2019-02-03 22:40:01 +00:00
Matt Davis
16e0966379 [llvm-nm] Report '.comment' ELF sections as 'n' instead of '?'
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
2019-02-01 17:38:08 +00:00
Vedant Kumar
5881cafdd3 [llvm-nm] Print out N_COLD_FUNC as "cold func"
Per post-commit feedback from Mike, have llvm-nm print out this symbol
attribute as "[cold func]".

llvm-svn: 352258
2019-01-26 00:33:15 +00:00
Vedant Kumar
8057a16e18 [MC] Teach the MachO object writer about N_FUNC_COLD
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
2019-01-25 18:30:22 +00:00
Chandler Carruth
ae65e281f3 Update the file headers across all of the LLVM projects in the monorepo
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
2019-01-19 08:50:56 +00:00
Saurabh Badhwar
dff123d1a1 [llvm-nm] Allow --size-sort to print symbols with only Symbol size
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
2019-01-16 14:38:22 +00:00
James Henderson
81bc305168 [llvm-nm] Add --portability as alias for --format=posix
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
2019-01-07 14:12:51 +00:00
Jordan Rupprecht
dcc03de9b8 [binutils] NFC: fix clang-tidy warning: use empty() instead of size() == 0
llvm-svn: 349710
2018-12-20 00:57:06 +00:00
Francis Visoiu Mistrih
230dbd2b22 [llvm-nm] Fix use-after-free for MachOUniversalBinaries
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
2018-11-19 17:19:50 +00:00
Jonas Devlieghere
7972433688 [llvm-nm] Use WithColor for error reporting
Use helpers from Support/WithError.h to print errors.

llvm-svn: 346624
2018-11-11 22:12:21 +00:00
Jonas Devlieghere
681a56eed2 [Support] Make error banner optional in logAllUnhandledErrors
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
2018-11-11 01:46:03 +00:00
Fangrui Song
6c158e8d71 [llvm-nm] Simplify. NFC
Change a \t to spaces
Change some zero-filling memcpy to aggregate initialization
Delete redundant ArchiveName.clear() after declaration

llvm-svn: 345367
2018-10-26 06:56:51 +00:00
Jordan Rupprecht
31ccce8fd0 [llvm-nm] Fix crash when running with --print-armap on corrupt archives.
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
2018-10-11 17:55:11 +00:00
Martin Storsjo
1020912cfb [llvm-nm] Include the text "@FILE" in the output of --help
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
2018-10-11 06:53:38 +00:00
Petr Hosek
95955db0b5 [llvm-nm] Write "no symbol" output to stderr
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
2018-10-05 21:10:03 +00:00
Jordan Rupprecht
d5effeb47c [llvm-nm] Print an explicit "no symbols" message when an object file has no 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
2018-10-03 23:39:49 +00:00
Fangrui Song
c2791239be llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
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
2018-09-27 02:13:45 +00:00
Dave Lee
1320ae98e2 nm: Add -no-weak flag for hiding weak symbols
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
2018-07-02 17:24:37 +00:00
Sam Clegg
b0362616c3 Fix debug build by adding missing dependencies on libBinaryFormat
Debug BUILD_SHARED_LIBS build was broken by rL332305

Differential Revision: https://reviews.llvm.org/D46859

llvm-svn: 332315
2018-05-15 00:46:43 +00:00
Rui Ueyama
04fb9911c5 Define InitLLVM to do common initialization all at once.
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
2018-04-13 18:26:06 +00:00
Mandeep Singh Grang
3cf1a994cb [tools] Change std::sort to llvm::sort in response to r327219
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
2018-04-01 21:24:53 +00:00
Kevin Enderby
f1015c1f29 Try to fix sanitizer-x86_64-linux-fast bot due to change in r328820.
llvm-svn: 328824
2018-03-29 20:49:24 +00:00
Kevin Enderby
c8edddc947 For llvm-nm and Mach-O files that are fully stripped, special case a 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
2018-03-29 20:04:29 +00:00
Kevin Enderby
bd5b90f5da For llvm-nm and Mach-O files also use function starts info in some
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
2018-03-22 23:59:35 +00:00
Kevin Enderby
d55cebfaec llvm-nm should show a symbol type of T for symbols in the (__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
2018-01-31 00:00:41 +00:00
Michael Zolotukhin
66a95d7c09 Remove redundant includes from tools.
llvm-svn: 320631
2017-12-13 21:31:10 +00:00
Aaron Ballman
b071b10879 Add llvm::for_each as a range-based extensions to <algorithm> and make use of it in some cases where it is a more clear alternative to std::for_each.
llvm-svn: 317356
2017-11-03 20:01:25 +00:00
Martin Storsjo
30bb4fe8f8 [llvm-nm] Don't error out on multiple occurrances of the -g/--external-only flag
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
2017-11-03 07:18:21 +00:00
Martin Storsjo
cb4d10b029 [llvm-nm] Print 'I' for import table data in COFF
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
2017-11-03 07:18:14 +00:00
Shoaib Meenai
8e98660f03 [tools] Add option to install binutils symlinks
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
2017-11-02 21:43:32 +00:00
Zachary Turner
0cc2a53e00 Revert "[ADT] Make Twine's copy constructor private."
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
2017-10-11 23:54:34 +00:00
Zachary Turner
ab809dc2fa [ADT] Make Twine's copy constructor private.
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
2017-10-11 23:33:06 +00:00
Kevin Enderby
a0fc9b0eaa Fix a crash in llvm-nm for a bad Mach-O file that has an N_SECT type symbol 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
2017-09-13 21:01:49 +00:00
Sam Clegg
2b0d3a4740 [llvm-nm] Fix output formatting of -f sysv for 64bit targets
Differential Revision: https://reviews.llvm.org/D37347

llvm-svn: 312284
2017-08-31 21:23:44 +00:00
Alexander Shaposhnikov
5614ad605c [llvm] Update MachOObjectFile::exports interface
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
2017-07-29 00:30:45 +00:00
Kevin Enderby
fe3ae3d76e Add error handling to the dyld compact export entries in libObject.
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
2017-07-20 23:08:41 +00:00
Eric Christopher
3f00a9d981 Rewrite demangle memory handling.
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
2017-06-30 05:38:56 +00:00
Eric Christopher
5545022a09 Change the type of Undecorated to unique_ptr<char[]> since we're looking at a null terminated string and not a single character.
Fixes an error in tcmalloc sized delete checking.

llvm-svn: 306780
2017-06-30 01:45:56 +00:00
Sam Clegg
8c3cc297fe llvm-nm: Add support for symbol demangling (-C/--demangle)
Differential Revision: https://reviews.llvm.org/D34668

llvm-svn: 306718
2017-06-29 18:29:05 +00:00
Kevin Enderby
3a465194e0 The change to llvm-nm in r305733 added fields to the struct NMSymbol
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
2017-06-20 00:41:04 +00:00
Kevin Enderby
1a26f183b2 Change llvm-nm for Mach-O files to use dyld info in some cases when printing 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
2017-06-19 19:38:22 +00:00
Zachary Turner
c5632126fc Move Object format code to lib/BinaryFormat.
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
2017-06-07 03:48:56 +00:00
Rafael Espindola
bbfcd24e3e Print symbols from COFF import libraries.
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
2017-05-24 23:40:36 +00:00
Sam Clegg
c688dd181f [WebAssembly] Improve readobj and nm support for wasm
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
2017-04-14 19:50:44 +00:00
Kevin Enderby
791a549fbd Add a warning when the llvm-nm -print-size flag is used on a Mach-O file as
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
2017-01-25 21:33:38 +00:00
Kevin Enderby
5bbb04ae53 Fix a bugs with using some Mach-O command line flags like "-arch armv7m".
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
2016-12-16 22:54:02 +00:00
Peter Collingbourne
9d56ed9660 Object: Set SF_Indirect in ModuleSymbolTable.
This lets us remove the last use of IRObjectFile::getSymbolGV() in llvm-nm.

Differential Revision: https://reviews.llvm.org/D27076

llvm-svn: 288321
2016-12-01 07:00:35 +00:00
Peter Collingbourne
7f3cfca4ed Object: Add SF_Executable symbol flag.
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
2016-12-01 06:53:47 +00:00
Peter Collingbourne
780535ef14 Object: Add IRObjectFile::getTargetTriple().
This lets us remove a use of IRObjectFile::getModule() in llvm-nm.

Differential Revision: https://reviews.llvm.org/D27074

llvm-svn: 287846
2016-11-24 01:13:09 +00:00
Meador Inge
6746ba845f llvm-nm: Print correct symbol types for init and fini sections
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
2016-11-23 20:17:20 +00:00