Commit Graph

429 Commits

Author SHA1 Message Date
Fangrui Song
25a01d9e01 [llvm-objdump] Delete redundant check
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359102 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-24 15:09:23 +00:00
Fangrui Song
8b0afcf334 [CommandLine] Provide parser<unsigned long> instantiation to allow cl::opt<uint64_t> on LP64 platforms
Summary:
And migrate opt<unsigned long long> to opt<uint64_t>

Fixes PR19665

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359068 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-24 02:40:20 +00:00
Fangrui Song
8eaf2a6f00 [llvm-objdump] Fix End in disassemblyObject after rL358806
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358809 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 07:48:41 +00:00
Fangrui Song
b28f2143df [llvm-objdump] Don't disassemble symbols before SectionAddr
This was caught by UBSAN

tools/llvm-objdump/X86/macho-disassembly-g-dsym.test
tools/llvm-objdump/X86/hex-displacement.test

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358806 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 07:19:24 +00:00
Fangrui Song
10f82c578f [llvm-objdump] Simplify --{start,stop}-address
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358803 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 02:10:48 +00:00
Fangrui Song
27f152b9a7 Change some llvm::{lower,upper}_bound to llvm::bsearch. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358564 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-17 07:58:05 +00:00
Fangrui Song
078c887eb0 [llvm-objdump] Align instructions to a tab stop in disassembly output
This relands D60376/rL358405, with the difference: sed 'y/\t/ /' -> tr '\t' ' '
BSD sed doesn't support escape characters for the 'y' command.
I didn't use it in rL358405 because it was not listed at
https://llvm.org/docs/GettingStarted.html#software but it
should be available.

Original description:

In GNU objdump, -w/--wide aligns instructions in the disassembly output.
This patch does the same to llvm-objdump. However, we always use the
wide format (-w/--wide is ignored), because the narrow format
(instructions are misaligned) is probably not very useful.

In llvm-readobj, we made a similar decision: always use the wide format,
accept but ignore -W/--wide.

To save some columns, we change the tab before hex bytes (controlled by
--[no-]show-raw-insn) to a space.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358474 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-16 03:56:55 +00:00
Fangrui Song
1e6eb4cd50 [llvm-objdump] Simplify PrintHelpMessage() logic
This relands rL358418. It missed one test that should also use -macho
Note, all the other -private-header -exports-trie tests are used
together with -macho.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358472 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-16 02:37:29 +00:00
Alex Lorenz
a164cf508d Revert r358405: "[llvm-objdump] Align instructions to a tab stop in disassembly output"
The test fails on darwin due to a sed error:

sed: 1: "y/\t/ /": transform strings are not the same length


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358459 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 22:36:12 +00:00
Alex Lorenz
878c0a9d38 Revert r358418: "[llvm-objdump] Simplify PrintHelpMessage() logic"
This reverts commit r358418 as it broke `test/Object/objdump-export-list`
on Darwin.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358443 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 20:16:19 +00:00
Fangrui Song
0eccb9c93e [llvm-objdump] Simplify PrintHelpMessage() logic
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358418 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 15:52:32 +00:00
Fangrui Song
0ea2470160 [llvm-objdump] Wrap things in namespace llvm
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358417 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 15:31:42 +00:00
Fangrui Song
24f35eb0fc [llvm-objdump] Reorganize cl::opt variables and move Mach-O specifics to MachODump.cpp
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358415 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 15:00:10 +00:00
Fangrui Song
24e71e6865 [llvm-objdump] Align instructions to a tab stop in disassembly output
Summary:
In GNU objdump, -w/--wide aligns instructions in the disassembly output.
This patch does the same to llvm-objdump. However, we always use the
wide format (-w/--wide is ignored), because the narrow format
(instructions are misaligned) is probably not very useful.

In llvm-readobj, we made a similar decision: always use the wide format,
accept but ignore -W/--wide.

To save some columns, we change the tab before hex bytes (controlled by
--[no-]show-raw-insn) to a space.

Reviewers: rupprecht, jhenderson, grimar

Reviewed By: jhenderson

Subscribers: llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358405 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 13:32:41 +00:00
Fangrui Song
8d84ad6695 [llvm-objdump] Don't print trailing space in dumpBytes
In disassembly output, dumpBytes prints a space, followed by a tab
printed by printInstr. Remove the extra space.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358045 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-10 05:31:21 +00:00
Fangrui Song
90bb2f79b2 [llvm-objdump] Accept and ignore --wide/-w
This is similar to what we do for llvm-readobj (--wide/-W is for GNU
readelf compatibility).

The test will be added in D60376.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358043 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-10 04:46:01 +00:00
Fangrui Song
029dd82a55 [llvm-objdump] Migrate some functions from std::error_code to Error
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357965 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-09 05:41:24 +00:00
Fangrui Song
7ac74fb0ca [llvm-objdump] Migrate relocation handling functions from error_code to Error
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357920 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-08 16:24:08 +00:00
Fangrui Song
c0af88a98c [llvm-objdump] Fix MC/ARM/arm-macho-calls.s
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357880 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-08 01:22:38 +00:00
Fangrui Song
ddfe71d047 [llvm-objdump] Split disassembleObject and simplify --{start,stop}-address handling
The main disassembly loop is hard to read due to special handling of ARM
ELF data & ELF data. Split off the logic into two functions
dumpARMELFData and dumpELFData. Hoist some checks outside of the loop.

--start-address --stop-address have redundant checks and minor off-by-1
issues. Fix them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357869 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-07 16:33:24 +00:00
Fangrui Song
bcaec23c25 [llvm-objdump] Fix split of source lines; don't ltrim source lines
If the file does not end with a newline, it may be dropped. Fix the
splitting algorithm.

Also delete an unnecessary SourceCache lookup.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357858 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-07 10:16:46 +00:00
Fangrui Song
582aba066d [llvm-objdump] Simplify Expected<T> handling with unwrapOrError
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357855 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-07 08:19:55 +00:00
Fangrui Song
7a5b0c460c [llvm-objdump] Simplify disassembleObject
* Use std::binary_search to replace some std::lower_bound
* Use llvm::upper_bound to replace some std::upper_bound
* Use format_hex and support::endian::read{16,32}

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357853 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-07 05:32:16 +00:00
Fangrui Song
9cc714957f Change some StringRef::data() reinterpret_cast to bytes_begin() or arrayRefFromStringRef()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357852 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-07 03:58:42 +00:00
Eric Christopher
6d179d64d1 Fix typoed variable name.
NFCI.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357138 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-28 01:12:13 +00:00
Jordan Rupprecht
8cdeab01bc [llvm-objdump] Support arg grouping for -j and -M (e.g. llvm-objdump -sj.foo -dMreg-names-raw)
Summary:
r354375 added support for most objdump groupings, but didn't add support for -j|--sections, because that wasn't possible.
r354870 added --disassembler options, but grouping still wasn't available.
r355185 supported values for grouped options.

This just puts the three of them together. This supports -j in modes like `-s -j .foo`, `-sj .foo`, `-sj=.foo`, or `-sj.foo`, and similar for `-M`.

Reviewers: ormris, jhenderson, ikudrin

Reviewed By: jhenderson, ikudrin

Subscribers: javed.absar, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356697 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-21 18:45:44 +00:00
Alexey Lapshin
a15cff122c [DebugInfo] add SectionedAddress to DebugInfo interfaces.
That patch is the fix for https://bugs.llvm.org/show_bug.cgi?id=40703
   "wrong line number info for obj file compiled with -ffunction-sections"
   bug. The problem happened with only .o files. If object file contains
   several .text sections then line number information showed incorrectly.
   The reason for this is that DwarfLineTable could not detect section which
   corresponds to specified address(because address is the local to the
   section). And as the result it could not select proper sequence in the
   line table. The fix is to pass SectionIndex with the address. So that it
   would be possible to differentiate addresses from various sections. With
   this fix llvm-objdump shows correct line numbers for disassembled code.

   Differential review: https://reviews.llvm.org/D58194

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354972 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-27 13:17:36 +00:00
Igor Kudrin
b7fb794e26 [llvm-objdump] Implement -Mreg-names-raw/-std options.
The --disassembler-options, or -M, are used to customize
the disassembler and affect its output.

The two implemented options allow selecting register names on ARM:
* With -Mreg-names-raw, the disassembler uses rNN for all registers.
* With -Mreg-names-std it prints sp, lr and pc for r13, r14 and r15,
  which is the default behavior of llvm-objdump.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354870 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-26 12:15:14 +00:00
Xing GUO
472d362ffc [llvm-objdump] Add Version References dumper
Summary: Add symbol version dumper for [#30241](https://bugs.llvm.org/show_bug.cgi?id=30241)

Reviewers: jhenderson, MaskRay, kristina, emaste, grimar

Reviewed By: jhenderson, grimar

Subscribers: grimar, rupprecht, jakehehrlich, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354782 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-25 13:13:19 +00:00
Matthew Voss
26dfbddae1 Revert "Revert "[llvm-objdump] Allow short options without arguments to be grouped""
- Tests that use multiple short switches now test them grouped and ungrouped.

  - Ensure the output of ungrouped and grouped variants is identical

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354375 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-19 19:46:08 +00:00
George Rimar
1cb4de41ab [yaml2obj] - Do not skip zeroes blocks if there are relocations against them.
This is for -D -reloc combination.

With this patch, we do not skip the zero bytes that have a relocation against
them when -reloc is used. If -reloc is not used, then the behavior will be the same.

Differential revision: https://reviews.llvm.org/D58174

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354319 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-19 12:38:36 +00:00
Matthew Voss
1854768f0f Revert "[llvm-objdump] Allow short options without arguments to be grouped"
Reverted due to failures on the llvm-hexagon-elf.

This reverts commit 77e1f27476c89f65eeb496d131065177e6417f23.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354002 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-14 01:39:43 +00:00
Matthew Voss
dce0292ccb [llvm-objdump] Allow short options without arguments to be grouped
Summary:

https://bugs.llvm.org/show_bug.cgi?id=31679

Reviewers: kristina, jhenderson, grimar, jakehehrlich, rupprecht

Subscribers: llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353998 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-14 00:39:40 +00:00
Sid Manning
45db4e8ea9 [llvm-objdump] - llvm-objdump can skip bytes at the end of a section.
Differential Revision: https://reviews.llvm.org/D57549

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352900 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-01 19:11:47 +00:00
Matt Davis
7fac036c20 [ELF] Return the section name when calling getSymbolName on a section symbol.
Summary:
Previously, llvm-nm would report symbols for .debug and .note sections as: '?' with an empty  section name:

```
00000000 ?
00000000 ?
...
```

With this patch the output more closely resembles GNU nm:
```
00000000 N .debug_abbrev
00000000 n .note.GNU-stack
...
```

This patch calls `getSectionName` for sections that belong to symbols of type `ELF::STT_SECTION`, which returns the name of the section from the section string table.

Reviewers: Bigcheese, davide, jhenderson

Reviewed By: davide, jhenderson

Subscribers: rupprecht, jhenderson, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352785 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-31 19:42:21 +00:00
George Rimar
24fe26b1a5 [llvm-objdump] - Restore a piece of code removed by mistake in r352366.
Seems when committed the r352366
("[llvm-objdump] - Print LMAs when dumping section headers.")
I resolved merge conflict incorrectly and removed this piece by mistake.

Bots did not catch this yet, seems they are slow today,
but the `X86/adjust-vma.test` test case fails locally for me without that.





git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352383 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-28 16:36:12 +00:00
George Rimar
4771873908 [llvm-objdump] - Print LMAs when dumping section headers.
When --section-headers is used, GNU objdump prints both LMA and VMA for sections.
llvm-objdump does not do that what makes it's output be slightly inconsistent.

Patch teaches llvm-objdump to print LMA/VMA for ELF file formats.
The behavior for other formats remains unchanged.

Differential revision: https://reviews.llvm.org/D57146

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352366 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-28 14:11:35 +00:00
George Rimar
aa66d2b539 [llvm-objdump] - Fix comment. NFC.
This was mentioned by James Henderson
in review for https://reviews.llvm.org/D57051.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352348 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-28 10:48:54 +00:00
George Rimar
747cd64953 [llvm-objdump] - Implement the --adjust-vma option.
GNU objdump's help says: "--adjust-vma: Add OFFSET to all displayed section addresses"
In real life what it does is a bit more complicated
(and IMO not always reasonable. For example, GNU objdump prints not only VMA, but also LMA
for sections. And with --adjust-vma it adjusts LMA, but only when a section has relocations.
llvm-objsump does not seem to support printing LMAs yet, but GNU's logic anyways does not
make sense for me here).

This patch tries to adjust VMA. I tried to implement a reasonable approach.
I am not adjusting sections that are not allocatable. As, for example, adjusting debug sections
VA's and rel[a] sections VA's should not make sense. This behavior seems to be GNU compatible.

Differential revision: https://reviews.llvm.org/D57051

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352347 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-28 10:44:01 +00:00
George Rimar
c01927928c [llvm-objdump] - Move common code to a new printRelocation() helper. NFC.
This extracts the common code for printing relocations into a new helper function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351951 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-23 13:39:12 +00:00
George Rimar
482634dcda [llvm-objdump] - Move variable. NFC.
It was too far from the place where it is used.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351942 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-23 10:52:38 +00:00
George Rimar
7ace113659 [llvm-objdump] - Split disassembleObject() into two methods. NFCI.
Currently, disassembleObject() is a ~550 lines length function.

This patch splits it into two, where first do all helper objects initializations
and calls the second which does all the rest job.
This is a straightforward split.

Differential revision: https://reviews.llvm.org/D57020

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351940 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-23 10:33:26 +00:00
George Rimar
5d73c0daaf [llvm-objdump] - Introduce getRelocsMap() helper. NFCI.
Currently disassembleObject() is a ~550 lines length function.
This patch extracts the code that creates a section->their relocation
mapping into a new helper function to simplify/reduce it a bit.

Differential revision: https://reviews.llvm.org/D57019

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351824 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-22 14:09:37 +00:00
Chandler Carruth
6b547686c5 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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 08:50:56 +00:00
Clement Courbet
1498f1dfed Revert r351529 "[llvm-objdump][NFC] Improve readability."
msan errors in ELF/strip-all.s.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351556 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-18 15:26:14 +00:00
Clement Courbet
e69eed4580 Reland r351529 "[llvm-objdump][NFC] Improve readability."
`SectionSymbol*` is cast from `void*` to
`std::tuple<uint64_t, StringRef, uint8_t>` in AMDGPUSymbolizer, so it has to
*be* one, not *act like* one.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351553 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-18 14:20:13 +00:00
George Rimar
a99a3c6de1 [llvm-objdump] - Dump the archive headers when -all-headers is specified.
When -all-headers is given it is supposed to dump all headers,
but now it skips the archive headers for no reason.

The patch fixes that.

Differential revision: https://reviews.llvm.org/D56780

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351547 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-18 12:01:59 +00:00
George Rimar
605942eacd [llvm-objdump] - Move getRelocationValueString and dependenices out of the llvm-objdump.cpp
getRelocationValueString is a dispatcher function that calls the
corresponding ELF/COFF/Wasm/MachO implementations
that currently live in the llvm-objdump.cpp file.

These implementations better be moved to ELFDump.cpp,
COFFDump.cpp and other corresponding files, to move platform specific
implementation out from the common logic.

The patch does that. Also, I had to move ToolSectionFilter helper
and SectionFilterIterator, SectionFilter to a header to make them
available across the objdump code.

Differential revision: https://reviews.llvm.org/D56842

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351545 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-18 11:33:26 +00:00
George Rimar
4d0c775881 [llvm-objdump] - Show aliases in -help.
Currently llvm-objdump is inconsistent.

When -help is specified it shows no aliases except two.
Aliases are shown with -help-hidden though.
GNU objdump also prints them by default.

This patch does a change to always show all aliases
when -help is given.

Differential revision: https://reviews.llvm.org/D56853

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351542 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-18 10:41:26 +00:00
Clement Courbet
70872139d5 Revert r351529 "[llvm-objdump][NFC] Improve readability."
Breaks labels-branch.s

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351534 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-18 09:40:19 +00:00