1212 Commits

Author SHA1 Message Date
Kazu Hirata
0ae9c65d4a
[tools] Use *Set::insert_range (NFC) (#133384)
We can use *Set::insert_range to replace "for" loop-based insertions.
In some cases, we can further fold insert_range into the set
declaration.
2025-03-28 07:53:09 -07:00
Vladislav Dzhidzhoev
bcad050106
[llvm-objdump][ARM] Find ELF file PLT entries for arm, thumb (#130764)
This implements arm, armeb, thumb, thumbeb PLT entries parsing support
in ELF for llvm-objdump.

Implementation is similar to AArch64MCInstrAnalysis::findPltEntries. PLT
entry signatures are based on LLD code for PLT generation
(ARM::writePlt).

llvm-objdump tests are produced from lld/test/ELF/arm-plt-reloc.s,
lld/test/ELF/armv8-thumb-plt-reloc.s.
2025-03-26 20:18:23 +01:00
Kazu Hirata
599005686a
[llvm] Use *Set::insert_range (NFC) (#132325)
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently
gained C++23-style insert_range.  This patch replaces:

  Dest.insert(Src.begin(), Src.end());

with:

  Dest.insert_range(Src);

This patch does not touch custom begin like succ_begin for now.
2025-03-20 22:24:06 -07:00
Fangrui Song
b5ef33b3b9 [llvm-objdump] Delete unused variables after #128434 2025-03-18 23:48:55 -07:00
Vladislav Dzhidzhoev
84e44ae6b7
[llvm-objdump] Pass MCSubtargetInfo to findPltEntries (NFC) (#131773)
It allows access to subtarget features, collected in llvm-objdump.cpp,
from findPltEntries, which will be used in
https://github.com/llvm/llvm-project/pull/130764.
2025-03-18 14:00:34 +01:00
Zequan Wu
6dbe82f061
[NFC][DebugInfo] Wrap DILineInfo return type with std::optional to handle missing debug info. (#129792)
Currently, `DIContext::getLineInfoForAddress` and
`DIContext::getLineInfoForDataAddress` returns empty DILineInfo when the
debug info is missing for the given address. This is not differentiable
with the case when debug info is found for the given address but the
debug info is default value (filename:linenum is <invalid>:0).

This change wraps the return types of `DIContext::getLineInfoForAddress`
and `DIContext::getLineInfoForDataAddress` with `std::optional`.
2025-03-17 17:01:06 -04:00
Ruoyu Qiu
82f2b66110
[llvm-objdump][ELF]Fix crash when reading strings from .dynstr (#125679)
This change introduces a check for the strtab offset to prevent
llvm-objdump from crashing when processing malformed ELF files.
It provide a minimal reproduce test for
https://github.com/llvm/llvm-project/issues/86612#issuecomment-2035694455.
Additionally, it modifies how llvm-objdump handles and outputs malformed
ELF files with invalid string offsets.(More info:
https://discourse.llvm.org/t/should-llvm-objdump-objdump-display-actual-corrupted-values-in-malformed-elf-files/84391)

Fixes: #86612

Co-authored-by: James Henderson <James.Henderson@sony.com>
2025-03-09 19:39:58 -07:00
Fangrui Song
7c26356703
[llvm-objdump] Rework .gnu.version_d dumping
and fix crash when vd_aux is invalid (#86611).

vd_version, vd_flags, vd_ndx, and vd_cnt in Elf{32,64}_Verdef are
16-bit. Change VerDef to use uint16_t instead.

vda_name specifies a NUL-terminated string. Update getVersionDefinitions
to remove some `.c_str()`.

Pull Request: https://github.com/llvm/llvm-project/pull/128434
2025-02-28 09:38:48 -08:00
Ruoyu Qiu
5a2bee04d0
[llvm-objdump]Correct .dynstr finding of getDynamicStrTab() (#127975)
The dynamic string table used by the dynamic section is referenced by
the sh_link field of that section, so we should use that directly,
rather than going via the dynamic symbol table.
More info:
https://github.com/llvm/llvm-project/pull/125679#discussion_r1961333454

Signed-off-by: Ruoyu Qiu <cabbaken@outlook.com>
2025-02-24 10:39:40 +00:00
Chandler Carruth
cd5694ecea
[StrTable] Switch the option parser to llvm::StringTable (#123308)
Now that we have a dedicated abstraction for string tables, switch the
option parser library's string table over to it rather than using a raw
`const char*`. Also try to use the `StringTable::Offset` type rather
than a raw `unsigned` where we can to avoid accidental increments or
other issues.

This is based on review feedback for the initial switch of options to a
string table. Happy to tweak or adjust if desired here.
2025-01-22 23:19:47 -08:00
zhijian lin
b92cc78060
[llvm-objdump] Print out xcoff load section of xcoff object file with option private-headers (#121226)
[llvm-objdump] Print out xcoff load section of xcoff object file with
option private-headers
2025-01-20 09:35:01 -05:00
Daniel Paoliello
2201164477
[llvm] Win x64 Unwind V2 2/n: Support dumping UOP_Epilog (#110338)
Adds support to objdump and readobj for reading the `UOP_Epilog` entries
of Windows x64 unwind v2.

`UOP_Epilog` has a weird format:

The first `UOP_Epilog` in the unwind data is the "header":
* The least-significant bit of `OpInfo` is the "At End" flag, which
signifies that there is an epilog at the very end of the associated
function.
* `CodeOffset` is the length each epilog described by the current unwind
information (all epilogs have the same length).

Any subsequent `UOP_Epilog` represents another epilog for the current
function, where `OpInfo` and `CodeOffset` are combined to a 12-bit value
which is the offset of the beginning of the epilog from the end of the
current function. If the offset is 0, then this entry is actually
padding and can be ignored.
2025-01-13 16:53:42 -08:00
Ryan Mansfield
65566281ed
[llvm-objdump] Remove leading whitespace for PT_GNU_PROPERTY. (#121591)
This fixes the misaligned display of addresses for this p_type.

Previous:

```
   STACK off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**64
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
   PROPERTY off    0x0000000000000358 vaddr 0x0000000000000358 paddr 0x0000000000000358 align 2**3
         filesz 0x0000000000000020 memsz 0x0000000000000020 flags r--
    NOTE off    0x0000000000000334 vaddr 0x0000000000000334 paddr 0x0000000000000334 align 2**2
         filesz 0x0000000000000020 memsz 0x0000000000000020 flags r--
```

After:


```
   STACK off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**64
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
PROPERTY off    0x0000000000000358 vaddr 0x0000000000000358 paddr 0x0000000000000358 align 2**3
         filesz 0x0000000000000020 memsz 0x0000000000000020 flags r--
    NOTE off    0x0000000000000334 vaddr 0x0000000000000334 paddr 0x0000000000000334 align 2**2
         filesz 0x0000000000000020 memsz 0x0000000000000020 flags r--
```
2025-01-13 14:15:24 +00:00
Cabbaken
630b7f3673
[llvm-objdump] Remove some unneeded headers. (#120541)
Co-authored-by: qiuruoyu <qiuruoyu@xiaomi.com>
2024-12-23 10:16:06 +00:00
Chandler Carruth
dd647e3e60
Rework the Option library to reduce dynamic relocations (#119198)
Apologies for the large change, I looked for ways to break this up and
all of the ones I saw added real complexity. This change focuses on the
option's prefixed names and the array of prefixes. These are present in
every option and the dominant source of dynamic relocations for PIE or
PIC users of LLVM and Clang tooling. In some cases, 100s or 1000s of
them for the Clang driver which has a huge number of options.

This PR addresses this by building a string table and a prefixes table
that can be referenced with indices rather than pointers that require
dynamic relocations. This removes almost 7k dynmaic relocations from the
`clang` binary, roughly 8% of the remaining dynmaic relocations outside
of vtables. For busy-boxing use cases where many different option tables
are linked into the same binary, the savings add up a bit more.

The string table is a straightforward mechanism, but the prefixes
required some subtlety. They are encoded in a Pascal-string fashion with
a size followed by a sequence of offsets. This works relatively well for
the small realistic prefixes arrays in use.

Lots of code has to change in order to land this though: both all the
option library code has to be updated to use the string table and
prefixes table, and all the users of the options library have to be
updated to correctly instantiate the objects.

Some follow-up patches in the works to provide an abstraction for this
style of code, and to start using the same technique for some of the
other strings here now that the infrastructure is in place.
2024-12-11 15:44:44 -08:00
hstk30-hw
2f5bfb41e2
[llvm-objdump] Default to --mattr=+all for AArch64be and AArch64_32 (#118311)
GNU objdump disassembles all unknown instructions by default. 
Complement for [D128030](https://reviews.llvm.org/D128030)。
2024-12-03 11:18:17 +08:00
zhijian lin
e373ba46bb
[llvm-objdump] Implement decoding auxiliary header for xcoff with llvm-objdump --private-headers (#105682)
Implement decoding auxiliary header of XCOFF object file with
llvm-objdump --private-headers
2024-11-07 10:53:11 -05:00
Fangrui Song
92412c106f
[llvm-objdump] Handle -M for --macho
--macho -d uses the `parseInputMachO` code path, which does not handle
-M. Add -M handling for --macho as well.

Close #61019

Pull Request: https://github.com/llvm/llvm-project/pull/113795
2024-10-28 09:40:15 -07:00
Fangrui Song
abe0dd195a
[llvm-objdump] Print ... even if a data mapping symbol is active
Swap `!DisassembleZeroes` and `if (DumpARMELFData)` conditions so that
in the false DisassembleZeroes case (default), `...` will be printed for
long consecutive zeroes, even when a data mapping symbol is active.

This is especially useful for certain lld tests that insert a huge
padding within a code section. Without `...` the output will be huge.

Pull Request: https://github.com/llvm/llvm-project/pull/109553
2024-09-25 10:32:40 -07:00
Abhina Sree
74dcf0b595
[SystemZ][z/OS] Open text files in text mode (#109972)
This patch continues the work that was started here
https://reviews.llvm.org/D99426 to correctly open text files in text
mode.
2024-09-25 10:49:45 -04:00
Craig Topper
f78a48cfaf [MC] Use std::optional<MCRegisters> for values returned by MCRegisterInfo::getLLVMRegNum. NFC
I missed a few places when I changed the function return type in
f2b71491d11355c0df0c92ef7cce7d610c894660.
2024-09-13 22:47:19 -07:00
Ahmed Bougacha
fd4f9520a6
[AArch64][MachO] Add ptrauth ABI version to arm64e cpusubtype. (#104650)
In a mach_header, the cpusubtype is a 32-bit field, but it's split in 2
subfields:
- the low 24 bits containing the cpu subtype proper, (e.g.,
CPU_SUBTYPE_ARM64E 2)
- the high 8 bits containing a capability field used for additional
feature flags.

Notably, it's only the subtype subfield that participates in fat file
slice discrimination: the caps are ignored.

arm64e uses the caps subfield to encode a ptrauth ABI version:
- 0x80 (CPU_SUBTYPE_PTRAUTH_ABI) denotes a versioned binary
- 0x40 denotes a kernel-ABI binary
- 0x00-0x0F holds the ptrauth ABI version

This teaches the basic obj tools to decode that (or ignore it when
unneeded).

It also teaches the MachO writer to default to emitting versioned
binaries, but with a version of 0 (and without the kernel ABI flag).

Modern arm64e requires versioned binaries: a binary with 0x00 caps in
cpusubtype is now rejected by the linker and everything after. We can
live without the sophistication of specifying the version and kernel ABI
for now.

Co-authored-by: Francis Visoiu Mistrih <francisvm@apple.com>
2024-08-20 11:37:12 -07:00
Kazu Hirata
6bbbd30147 [llvm-objdump] Fix a warning
This patch fixes:

  llvm/tools/llvm-objdump/XCOFFDump.cpp:85:12: error: unused variable
  'BytesFormatted' [-Werror,-Wunused-variable]
2024-08-15 11:56:21 -07:00
Tim Northover
52337d5f9d
llvm-objdump: ensure a MachO symbol isn't STAB before looking up secion (#86667)
The section field has been repurposed for some STAB symbol types, and if
we blindly look it up we'll produce an error and terminate. Logic
already existed

Existing stabs test had a section that was in range. Unfortunately I
don't know of an easy way to produce stabs entries in LLVM (I thought
they died in the 90s until this came up) so I just binary-edited it to
cause a failure on existing llvm-objdump.
2024-08-15 11:19:30 -07:00
zhijian lin
29b0a251c1
[llvm-objdump] Print out xcoff file header for xcoff object file with option private-headers (#96350)
Print out the XCOFF file header and load section header for the XCOFF
object file using llvm-objdump with the --private-headers option.
2024-08-15 13:50:54 -04:00
eddyz87
ee1040b02a
[llvm-objdump][BPF] --symbolize-operands: infer local labels for BPF (#100550)
Enable local labels computation for BPF disassembly when
`--symbolize-operands` option is specified.
This relies on `MCInstrAnalysis::evaluateBranch()` method, which is
already defined in `BPFMCInstrAnalysis::evaluateBranch`.

After this change the assembly code below:

        if r1 > 42 goto +1
        r1 -= 10
        ...

Would be printed as:

        if r1 > 42 goto +1 <L0>
        r1 -= 10
      <L0>:
        ...

(when `--symbolize-operands` option is set).

See https://reviews.llvm.org/D84191 for the main part of the
`--symbolize-operands` implementation logic.
2024-07-31 08:52:34 +03:00
Fangrui Song
2f37a22f10
[llvm-objdump] -r: support CREL
Extract the llvm-readelf decoder to `decodeCrel` (#91280) and reuse it
for llvm-objdump.

Because the section representation of LLVMObject (`SectionRef`) is
64-bit, insufficient to hold all decoder states, `section_rel_begin` is
modified to decode CREL eagerly and hold the decoded relocations inside
ELFObjectFile<ELFT>.

The test is adapted from llvm/test/tools/llvm-readobj/ELF/crel.test.

Pull Request: https://github.com/llvm/llvm-project/pull/97382
2024-07-08 09:14:34 -07:00
Kazu Hirata
75bc20ff89
[llvm] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#97914) 2024-07-07 08:23:41 +09:00
zhijian lin
df86fb069e
[llvm-objdump] enable file-headers option of llvm-objdump for XCOFF object files (#96104)
the patch enable file-headers option of llvm-objdump for XCOFF object
files
2024-06-21 09:17:04 -04:00
Kazu Hirata
7c6d0d26b1
[llvm] Use llvm::unique (NFC) (#95628) 2024-06-14 22:49:36 -07:00
Kazu Hirata
bb6df0804b
[llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (#91441)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  70 under llvm/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-08 10:33:53 -07:00
Craig Topper
b27f86b40b
[RISCV] Add an instruction PrettyPrinter to llvm-objdump (#90093)
This prints the opcode bytes in the same order as GNU objdump without a
space between them.
2024-04-26 11:27:28 -07:00
Emma Pilkington
68e814d911
[AMDGPU] Add disassembler diagnostics for invalid kernel descriptors (#87400)
These mostly are checking for various reserved bits being set. The diagnostics
for gpu-dependent reserved bits have a bit more context since they seem like the
most likely ones to be observed in practice.

This commit also improves the error handling mechanism for
MCDisassembler::onSymbolStart(). Previously it had a comment stream parameter
that was just being ignored by llvm-objdump, now it returns errors using
Expected<T>.
2024-04-18 13:44:22 -04:00
Ramkumar Ramachandra
0e8b61f8e0
llvm-objdump/ELF: fix crash when reading dyn str table (#87519)
When reading the dynamic string table, llvm-objdump used to crash if the
ELF was malformed, due to an erroneous consumption of error status.
Instead, propogate the error status to the caller, fixing the crash, and
printing a warning.
2024-04-06 12:22:24 +01:00
Andrew Ng
c9db031c48
[Support] Fix color handling in formatted_raw_ostream (#86700)
The color methods in formatted_raw_ostream were forwarding directly to
the underlying stream without considering existing buffered output. This
would cause incorrect colored output for buffered uses of
formatted_raw_ostream.

Fix this issue by applying the color to the formatted_raw_ostream itself
and temporarily disabling scanning of any color related output so as not
to affect the position tracking.

This fix means that workarounds that forced formatted_raw_ostream
buffering to be disabled can be removed. In the case of llvm-objdump,
this can improve disassembly performance when redirecting to a file by
more than an order of magnitude on both Windows and Linux. This
improvement restores the disassembly performance when redirecting to a
file to a level similar to before color support was added.
2024-03-28 11:41:49 +00:00
alx32
b59c2a0eb4
[llvm-objdump][macho] Fix relative method list dumping for little endian hosts (#85778)
`macho-relative-method-lists.test` is failing on little endian
platforms, when matching 'name'.

```
CHK32-NEXT: name 0x144 (0x{{[0-9a-f]*}}) instance_method_00

next:10'0             X error: no match found
          18:  name 0x144 (0x7ac)      
```
This seems like the obvious fix.

Co-authored-by: Alex B <alexborcan@meta.com>
2024-03-19 07:43:09 -07:00
alx32
9d5edfde5c
[llvm-objdump][macho] Add support for ObjC relative method lists (#85477)
For Mach-O, ld64 supports the -fobjc-relative-method-lists flag which
changes the format in which method lists are generated. The format uses
delta encoding vs the original direct-pointer encoding.
This change adds support to llvm-objdump and llvm-otool for
decoding/dumping of method lists in the delta format. Previously, if a
binary with this information format was passed to the tooling, it would
output invalid information, trying to parse the delta lists as pointer
lists.
After this change, the tooling will output correct information if a
binary in this format is encountered.
The output format is closest feasible match to XCode 15.1's otool
output. Tests are included for both 32bit and 64bit binaries.

The code style was matched as close as possible to existing
implementation of parsing non-delta method lists.

Diff between llvm-objdump and XCode 15.1 otool:

![image](https://github.com/llvm/llvm-project/assets/103613512/2277e3ff-d59c-4fff-b93a-e0587ee740a6)

Note: This is a retry of this PR:
https://github.com/llvm/llvm-project/pull/84250
On the original PR, the armv7+armv8 builds were failing due to absolute
offsets being different.

Co-authored-by: Alex B <alexborcan@meta.com>
2024-03-16 07:51:45 -07:00
Kyungwoo Lee
36fd0e7979 Revert "[llvm-objdump][macho] Add support for ObjC relative method lists (#84250)"
This reverts llvm/llvm-project#84250, commit aa6100643c2c8f9a1b06ba557b68b0fba477e3c7.

See build failures:
https://lab.llvm.org/buildbot/#/builders/178/builds/7028
https://lab.llvm.org/buildbot/#/builders/182/builds/9282
https://lab.llvm.org/buildbot/#/builders/186/builds/15299
https://lab.llvm.org/buildbot/#/builders/187/builds/14564
2024-03-15 05:07:15 -07:00
alx32
aa6100643c
[llvm-objdump][macho] Add support for ObjC relative method lists (#84250)
For Mach-O, ld64 supports the `-fobjc-relative-method-lists` flag which
changes the format in which method lists are generated. The format uses
delta encoding vs the original direct-pointer encoding.
This change adds support to `llvm-objdump` and `llvm-otool` for
decoding/dumping of method lists in the delta format. Previously, if a
binary with this information format was passed to the tooling, it would
output invalid information, trying to parse the delta lists as pointer
lists.
After this change, the tooling will output correct information if a
binary in this format is encountered.
The output format is closest feasible match to XCode 15.1's otool
output. Tests are included for both 32bit and 64bit binaries.

The code style was matched as close as possible to existing
implementation of parsing non-delta method lists.

Diff between llvm-objdump and XCode 15.1 otool:


![objdump_vs_otool](https://github.com/llvm/llvm-project/assets/103613512/4fc04228-ed35-473d-b633-364402411b91)

---------

Co-authored-by: Alex B <alexborcan@meta.com>
2024-03-14 13:41:11 -07:00
Micah Weston
9ca8db352d
[SHT_LLVM_BB_ADDR_MAP] Adds pretty printing of BFI and BPI for PGO Analysis Map in tools. (#82292)
Primary change is to add a flag `--pretty-pgo-analysis-map` to
llvm-readobj and llvm-objdump that prints block frequencies and branch
probabilities in the same manner as BFI and BPI respectively. This can
be helpful if you are manually inspecting the outputs from the tools.

In order to print, I moved the `printBlockFreqImpl` function from
Analysis to Support and renamed it to `printRelativeBlockFreq`.
2024-02-27 14:13:00 -05:00
Frederic Cambus
1b89486486
[llvm-objdump] Add support for the PT_OPENBSD_SYSCALLS segment type. (#82121)
Reference: https://github.com/openbsd/src/blob/master/sys/sys/exec_elf.h
2024-02-20 09:11:54 +01:00
Derek Schuff
c344953ae7 Fix 01706e7 on 32-bit platforms
Make the type match the printf format.
2024-02-09 17:24:27 -08:00
Derek Schuff
01706e7677
[llvm-nm][WebAssembly] Print function symbol sizes (#81315)
nm already prints sizes for data symbols. Do that for function symbols 
too, and update objdump to also print size information.

Implements item 3 from https://github.com/llvm/llvm-project/issues/76107
2024-02-09 14:22:47 -08:00
Derek Schuff
8b0f47bfa4
[Object][Wasm] Use file offset for section addresses in linked wasm files (#80529)
Wasm has no unified virtual memory space as other object formats and
architectures do, so previously WasmObjectFile reported 0 for all
section addresses, and until 428cf71ff used section offsets for function
symbols. Now we use file offsets for function symbols, and this change
switches section addresses to do the same (in linked files). The main
result of this is that objdump now reports VMAs in section listings, and
also uses file offets rather than section offsets when disassembling
linked binaries (matching the behavior of other disassemblers and stack
traces produced by browwsers). To make this work, this PR also updates
objdump's generation of synthetics fallback symbols to match lib/Object
and also correctly plumbs symbol types for regular and dummy symbols
through to the backend to avoid needing special knowledge of address 0.

This also paves the way for generating symbols from name sections rather
than symbol tables or imports (see #76107) by allowing the
disassembler's synthetic fallback symbols match the name-section
generated symbols (in a followup PR).
2024-02-07 11:51:19 -08:00
Rahman Lavaee
acec6419e8
[SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (#74128)
Today `-split-machine-functions` and `-fbasic-block-sections={all,list}`
cannot be combined with `-basic-block-sections=labels` (the labels
option will be ignored).
The inconsistency comes from the way basic block address map -- the
underlying mechanism for basic block labels -- encodes basic block
addresses
(https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html).
Specifically, basic block offsets are computed relative to the function
begin symbol. This relies on functions being contiguous which is not the
case for MFS and basic block section binaries. This means Propeller
cannot use binary profiles collected from these binaries, which limits
the applicability of Propeller for iterative optimization.
    
To make the `SHT_LLVM_BB_ADDR_MAP` feature work with basic block section
binaries, we propose modifying the encoding of this section as follows.

First let us review the current encoding which emits the address of each
function and its number of basic blocks, followed by basic block entries
for each basic block.

| | |
|--|--|
| Address of the function | Function Address |
|  Number of basic blocks in this function | NumBlocks |
|  BB entry 1
|  BB entry 2
|   ...
|  BB entry #NumBlocks
    
To make this work for basic block sections, we treat each basic block
section similar to a function, except that basic block sections of the
same function must be encapsulated in the same structure so we can map
all of them to their single function.
    
We modify the encoding to first emit the number of basic block sections
(BB ranges) in the function. Then we emit the address map of each basic
block section section as before: the base address of the section, its
number of blocks, and BB entries for its basic block. The first section
in the BB address map is always the function entry section.
| | |
|--|--|
|  Number of sections for this function   | NumBBRanges |
| Section 1 begin address                     | BaseAddress[1]  |
| Number of basic blocks in section 1 | NumBlocks[1]    |
| BB entries for Section 1
|..................|
| Section #NumBBRanges begin address | BaseAddress[NumBBRanges] |
| Number of basic blocks in section #NumBBRanges |
NumBlocks[NumBBRanges] |
| BB entries for Section #NumBBRanges
    
The encoding of basic block entries remains as before with the minor
change that each basic block offset is now computed relative to the
begin symbol of its containing BB section.
    
This patch adds a new boolean codegen option `-basic-block-address-map`.
Correspondingly, the front-end flag `-fbasic-block-address-map` and LLD
flag `--lto-basic-block-address-map` are introduced.
Analogously, we add a new TargetOption field `BBAddrMap`. This means BB
address maps are either generated for all functions in the compiling
unit, or for none (depending on `TargetOptions::BBAddrMap`).
    
This patch keeps the functionality of the old
`-fbasic-block-sections=labels` option but does not remove it. A
subsequent patch will remove the obsolete option.

We refactor the `BasicBlockSections` pass by separating the BB address
map and BB sections handing to their own functions (named
`handleBBAddrMap` and `handleBBSections`). `handleBBSections` renumbers
basic blocks and places them in their assigned sections.
`handleBBAddrMap` is invoked after `handleBBSections` (if requested) and
only renumbers the blocks.
  - New tests added:
- Two tests basic-block-address-map-with-basic-block-sections.ll and
basic-block-address-map-with-mfs.ll to exercise the combination of
`-basic-block-address-map` with `-basic-block-sections=list` and
'-split-machine-functions`.
- A driver sanity test for the `-fbasic-block-address-map` option
(basic-block-address-map.c).
- An LLD test for testing the `--lto-basic-block-address-map` option.
This reuses the LLVM IR from `lld/test/ELF/lto/basic-block-sections.ll`.
- Renamed and modified the two existing codegen tests for basic block
address map (`basic-block-sections-labels-functions-sections.ll` and
`basic-block-sections-labels.ll`)
- Removed `SHT_LLVM_BB_ADDR_MAP_V0` tests. Full deprecation of
`SHT_LLVM_BB_ADDR_MAP_V0` and `SHT_LLVM_BB_ADDR_MAP` version less than 2
will happen in a separate PR in a few months.
2024-02-01 17:50:46 -08:00
Emma Pilkington
4eb0810922
[llvm-objdump][AMDGPU] Pass ELF ABIVersion through disassembler (#78907)
Admittedly, its a bit ugly to pass the ABIVersion through onSymbolStart
but I'm not sure what a better place for it would be.
2024-02-01 11:26:42 -05:00
Rahman Lavaee
313d33e33c
[llvm-objdump,SHT_LLVM_BB_ADDR_MAP,NFC] Use auto && instead of const auto & to allow moving from BBAddrMap objects. (#79456)
std::move on `const auto &` references is essentially a noop. Changing
to `auto &&` to actually allow moving.
2024-01-25 13:03:18 -08:00
Aiden Grossman
f9bc1ee3fc
[llvm-objdump] Add support for symbolizing PGOBBAddrMap Info (#76386)
This patch adds in support for symbolizing PGO information contained
within the SHT_LLVM_BB_ADDR_MAP section in llvm-objdump. The outputs are
simply the raw values contained within the section.
2024-01-19 14:28:31 -08:00
Alexandre Ganea
3c6f47d6b8
[llvm-driver] Fix usage of InitLLVM on Windows (#76306)
Previously, some tools such as `clang` or `lld` which require strict
order for certain command-line options, such as `clang -cc1` or `lld
-flavor`, would not longer work on Windows, when these tools were linked
as part of `llvm-driver`. This was caused by `InitLLVM` which was part
of the `*_main()` function of these tools, which in turn calls
`windows::GetCommandLineArguments`. That function completly replaces
argc/argv by new UTF-8 contents, so any ajustements to argc/argv made by
`llvm-driver` prior to calling these tools was reset.

`InitLLVM` is now called by the `llvm-driver`. Any tool that
participates in (or is part of) the `llvm-driver` doesn't call
`InitLLVM` anymore.
2024-01-11 19:08:28 -05:00
stephenpeckham
7026086073
[XCOFF] Use RLDs to print branches even without -r (#74342)
This presents misleading and confusing output. If you have a function
defined at the beginning of an XCOFF object file, and you have a
function call to an external function, the function call disassembles as
a branch to the local function. That is,

`void f() { f(); g();}`

disassembles as 
>00000000 <.f>:
       0: 7c 08 02 a6   mflr 0
4: 94 21 ff c0 stwu 1, -64(1)
       8: 90 01 00 48   stw 0, 72(1)
      c: 4b ff ff f5   bl 0x0 <.f>
      10: 4b ff ff f1   bl 0x0 <.f> 

With this PR, the second call will display:

`10: 4b ff ff f1   bl 0x0 <.g>  `

Using -r can help, but you still get the confusing output:

>10: 4b ff ff f1   bl 0x0 <.f>
      00000010:  R_RBR        .g
2023-12-21 08:17:32 -06:00