Commit Graph

455 Commits

Author SHA1 Message Date
Yuanfang Chen
1432e6009c [llvm-objdump] Match GNU objdump on symbol types shown in disassembly
output.

STT_OBJECT and STT_COMMON are dumped as data, not disassembled.

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

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364211 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-24 17:47:56 +00:00
Yuanfang Chen
71bf034cf8 [llvm-objdump] Allow --disassemble-functions to take demangled names
The --disassemble-functions switch takes demangled names when
--demangle is specified, otherwise the switch takes mangled names.

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

Reviewers: jhenderson, grimar, MaskRay, rupprecht

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364121 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-22 01:13:04 +00:00
Yuanfang Chen
d142165668 [llvm-objdump] Move --start-address >= --stop-address check out of the
-d code.

Summary:
Move it into `main` function so the checking is effective for all actions
user may do with llvm-objdump; notably, -r and -s in addition to existing -d.

Match GNU behavior.

Reviewers: jhenderson, grimar, MaskRay, rupprecht

Subscribers: llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364118 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-22 00:22:57 +00:00
James Henderson
b7bdff997f [binutils] Add response file option to help and docs
Many LLVM-based tools already support response files (i.e. files
containing a list of options, specified with '@'). This change simply
updates the documentation and help text for some of these tools to
include it. I haven't attempted to fix all tools, just a selection that
I am interested in.

I've taken the opportunity to add some tests for --help behaviour, where
they were missing. We could expand these tests, but I don't think that's
within scope of this patch.

This fixes https://bugs.llvm.org/show_bug.cgi?id=42233 and
https://bugs.llvm.org/show_bug.cgi?id=42236.

Reviewed by: grimar, MaskRay, jkorous

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364036 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-21 11:49:20 +00:00
Eli Friedman
cd0e53865d [llvm-objdump] Switch between ARM/Thumb based on mapping symbols.
The ARMDisassembler changes allow changing between ARM and Thumb mode
based on the MCSubtargetInfo, rather than the Target, which simplifies
the other changes a bit.

I'm not really happy with adding more target-specific logic to
tools/llvm-objdump/, but there isn't any easy way around it: the logic
in question specifically applies to disassembling an object file, and
that code simply isn't located in lib/Target, at least at the moment.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363903 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-20 00:29:40 +00:00
Yuanfang Chen
e3397d8664 [llvm-objdump] Remove unnecessary indentation when dumping ELF data.
Reviewers: MaskRay, jhenderson, rupprecht

Subscribers: llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363858 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-19 18:44:29 +00:00
Yuanfang Chen
c40299a741 Test commit access
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363763 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-19 05:40:24 +00:00
Fangrui Song
0ef6742182 [llvm-objdump] Tidy up AMDGCNPrettyPrinter
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363650 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-18 06:35:18 +00:00
Fangrui Song
400438c3c0 [llvm-objdump] Use %08 instead of %016 to print leading addresses for 32-bit binaries
Reviewed By: grimar

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363539 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-17 09:59:55 +00:00
Peter Collingbourne
254898f6b8 Symbolize: Replace the Options constructor with in-class initialization. NFCI.
This is not only less code but also clearer at the use site.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363024 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-11 02:31:54 +00:00
Jordan Rupprecht
699a2e567f [llvm-objdump] Fix Bugzilla ID 41862 to support checking addresses of disassembled object
Summary:
This fixes the bugzilla id,41862 to support dealing with checking
stop address against start address to support this not being a
proper object to check the disasembly against like gnu objdump
currently does.

Reviewers: jakehehrlich, rupprecht, echristo, jhenderson, grimar

Reviewed By: jhenderson

Subscribers: MaskRay, smeenai, rupprecht, llvm-commits

Tags: #llvm

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

Patch by Nicholas Krause!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362847 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-07 21:49:26 +00:00
Michael Pozulp
81d8e5d40b [llvm-objdump] Add warning if --disassemble-functions specifies an unknown symbol
Summary:
Fixes Bug 41904 https://bugs.llvm.org/show_bug.cgi?id=41904

Re-land r362768 after it was reverted in r362826.

Reviewers: jhenderson, rupprecht, grimar, MaskRay

Reviewed By: jhenderson, rupprecht, MaskRay

Subscribers: dexonsmith, rupprecht, kristina, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362838 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-07 20:34:31 +00:00
Vlad Tsyrklevich
7a94d4e4e4 Revert "[llvm-objdump] Add warning if --disassemble-functions specifies an unknown symbol"
This reverts commit 50f61af3f304a03f10d9ecb0828829f0a72d0099, it used
the function introduced in the previous revert of
0bddef79019a23ab14fcdb27028e55e484674c88.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362826 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-07 18:55:12 +00:00
Michael Pozulp
0ccb60f704 [llvm-objdump] Print source when subsequent lines in the translation unit come from the same line in two different headers.
Reviewers: grimar, rupprecht, jhenderson

Reviewed By: grimar, jhenderson

Subscribers: llvm-commits, jhenderson

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362771 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-07 06:23:54 +00:00
Michael Pozulp
702cdcb85d [llvm-objdump] Add warning if --disassemble-functions specifies an unknown symbol
Summary: Fixes Bug 41904 https://bugs.llvm.org/show_bug.cgi?id=41904

Reviewers: jhenderson, rupprecht, grimar, MaskRay

Reviewed By: jhenderson, rupprecht, MaskRay

Subscribers: dexonsmith, rupprecht, kristina, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362768 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-07 05:11:13 +00:00
George Rimar
3fa8760f89 [llvm-objdump] - Disassemble non-executable sections if specifically requested.
This is https://bugs.llvm.org/show_bug.cgi?id=41897.

Previously -d + -j .data had no effect, that wasn't consistent with GNU,
which proccesses .data in that case. With this patch we follow this behavior.

Diffeential revision: https://reviews.llvm.org/D62848

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362596 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-05 11:37:53 +00:00
Fangrui Song
e48c7bddae [Object] object::ELFObjectFile::symbol_begin(): skip symbol index 0
For clients iterating the symbol table, none expects to handle index 0
(STN_UNDEF). Skip it to improve consistency with other binary formats.
Clients that need STN_UNDEF (e.g. lld) can use
getSectionContentsAsArray(). A test will be added in D62148.

Reviewed By: mtrent

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361506 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-23 16:01:59 +00:00
Fangrui Song
93cf9afa9e [llvm-objdump] Dump inline relocations if the relocated section is specified with --section
This fixes PR41886: llvm-objdump -d -r -j .text doesn't show inline relocations of .text

While here, switch to stable_sort() because we don't want to change the order of relocations applied to the same location. gABI says consecutive relocation records are composed together and their order matters. In practise it is difficult to see relocations applied to the same location not consecutive, we just have to keep the relative order of relocations with the same offset.

Reviewed By: grimar

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361395 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-22 15:12:51 +00:00
Serge Guelton
5701a34dbf Properly categorize llvm-objdump options
Filters out noise, and distinguish Mach-O related options from others.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361351 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-22 06:30:46 +00:00
George Rimar
efe98de75a [llvm-objdump] Make --disassemble-functions imply -d
Fixes https://bugs.llvm.org/show_bug.cgi?id=41903

Patch by Mike Pozulp!

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361240 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-21 11:05:46 +00:00
Fangrui Song
7287acf23f Recommit [Object] Change object::SectionRef::getContents() to return Expected<StringRef>
r360876 didn't fix 2 call sites in clang.

Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now.

Follow-up of D61781.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360892 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-16 13:24:04 +00:00
Hans Wennborg
71eaa4f97d Revert r360876 "[Object] Change object::SectionRef::getContents() to return Expected<StringRef>"
It broke the Clang build, see llvm-commits thread.

> Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now.
>
> Follow-up of D61781.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360878 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-16 12:08:34 +00:00
Fangrui Song
a4d6bb66d0 [Object] Change object::SectionRef::getContents() to return Expected<StringRef>
Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now.

Follow-up of D61781.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360876 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-16 11:33:48 +00:00
Fangrui Song
699a92151e [llvm-objdump] Print st_other
Add support for ".hidden" ".internal" ".protected" and " 0x%02x" for
other st_other bits used by some architectures.

Reviewed By: sfertile

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360439 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-10 16:24:57 +00:00
George Rimar
f4cd658f2d [llvm-objdump] - Print relocation record in a GNU format.
This fixes the https://bugs.llvm.org/show_bug.cgi?id=41355.

Previously with -r we printed relocation section name instead of the target section name.
It was like this: "RELOCATION RECORDS FOR [.rel.text]"
Now it is: "RELOCATION RECORDS FOR [.text]"

Also when relocation target section has more than one relocation section,
we did not combine the output. Now we do.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360143 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-07 13:14:18 +00:00
Fangrui Song
2a774bf95f [llvm-objdump] Print newlines before and after "Disassembly of section ...:"
This improves readability and the behavior is consistent with GNU objdump.

The new test test/tools/llvm-objdump/X86/disassemble-section-name.s
checks we print newlines before and after "Disassembly of section ...:"

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359668 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-01 10:40:48 +00:00
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