1452 Commits

Author SHA1 Message Date
Fangrui Song
cd20a7ff9a
[llvm-readelf] Print ARM specific OSABI values in GNU mode (#82186)
Similar to #75661. Currently, there is only ELFOSABI_ARM, but I plan to
add ELFOSABI_ARM_FDPIC in a subsequent patch #82187
2024-02-19 11:45:54 -08:00
Pierre van Houtryve
43c7eb5d7b
[AMDGPU] Replace '.' with '-' in generic target names (#81718)
The dot is too confusing for tools. Output temporaries would have
'10.3-generic' so tools could parse it as an extension, device libs &
the associated clang driver logic are also confused by the dot.

After discussions, we decided it's better to just remove the '.' from
the target name than fix each issue one by one.
2024-02-14 15:19:04 +01:00
Pierre van Houtryve
f93aa5157a
[AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (#76955)
These generic targets include multiple GPUs and will, in the future,
provide a way to build once and run on multiple GPU, at the cost of less
optimization opportunities.

Note that this is just doing the compiler side of things, device libs an
runtimes/loader/etc. don't know about these targets yet, so none of them
actually work in practice right now. This is just the initial commit to
make LLVM aware of them.

This contains the documentation changes for both this change and #76954
as well.
2024-02-12 10:18:20 +01:00
Jacek Caban
8f23464a5d
[llvm-lib][llvm-dlltool][Object] Add support for EXPORTAS name types. (#78772)
EXPORTAS is a new name type in import libraries. It's used by default on ARM64EC,
but it's allowed on other platforms as well.
2024-02-10 01:00:14 +01:00
Jacek Caban
a2e5287d5a
[llvm-readobj][Object][COFF] Print COFF import library symbol export name. (#78769)
getExportName implementation is based on lld-link. In its current form,
it's mostly about convenience, but it will be more useful for EXPORTAS
support, for which export name is not possible to deduce from other
printed properties.
2024-02-06 13:47:58 +01:00
Pierre van Houtryve
500846d2f5
[AMDGPU] Introduce Code Object V6 (#76954)
Introduce Code Object V6 in Clang, LLD, Flang and LLVM. This is the same
as V5 except a new "generic version" flag can be present in EFLAGS. This
is related to new generic targets that'll be added in a follow-up patch.
It's also likely V6 will have new changes (possibly new metadata
entries) added later.

Docs change are part of the follow-up patch #76955
2024-02-05 08:19:53 +01: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
Micah Weston
aaaff74fd1
[SHT_LLVM_BB_ADDR_MAP][llvm-readobj] Implements llvm-readobj handling for PGOAnalysisMap. (#79520)
Adds raw printing of PGOAnalysisMap in llvm-readobj.

I'm leaving the fixme's for a later patch that will provide a 'pretty'
printing for BBFreq and BrProb (i.e. relative frequencies and
probabilities) that will apply to both llvm-readobj and llvm-objdump.
2024-02-01 16:02:14 -05:00
Jacek Caban
b26bfcc1ec
[llvm-readobj][Object][COFF] Include COFF import file machine type in format string. (#78366) 2024-01-17 22:47:18 +01: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
Joseph Huber
59567e711d [ELF][Obvious] Remove unused CUDA OS/ABI struct
Summary:
This did not need a separate struct because it is not past the
"architecture specific" ones in the identifier. This was accidentally
left when it was added somewhere else and caused unused variable
warnings.
2024-01-05 10:58:10 -06:00
Joseph Huber
3b337bbc81
[ELF] Attempt to set the OS when using 'makeTriple()' (#76992)
Summary:
This patch fixes up the `makeTriple()` interface to emit append the
operating system information when it is readily avaialble from the ELF.
The main motivation for this is so the GPU architectures can be easily
identified correctly when given and ELF. E.g. we want
`amdgpu-amd-amdhsa` as the output and not `amdgpu--`.

This required adding support for the CUDA OS/ABI, which is easily found
to be `0x33` when using `readelf`.
2024-01-05 10:24:30 -06:00
Joseph Huber
87b45f1ca6
[llvm-readobj] Print AMDGPU specific values in GNU mode (#75661)
Summary:
Currently, we don't emit any of the AMDGPU specific flags and options
when printing in GNU-mode (the default). This patch adds extra code to
handle outputting these values to match the output from GNU's `readelf`
when used on an AMDGPU image.
2023-12-18 09:22:22 -06:00
Joseph Huber
433498ce46
[llvm-readobj] Print the associated CUDA SM flags (#75664)
Summary:
The architecture that the CUDA application was compiled for is stored in
the ELF flags. This patch just adds some simple enum values to indicate
this to the user in a readable way.
2023-12-15 20:52:37 -06:00
Abhina Sree
ec41462d7a
[SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (#75339)
This patch adds strnlen to the zOSSupport.h file to fix build failures in multiple files.
2023-12-13 13:13:53 -05:00
john-brawn-arm
d293a354d0
[AArch64][ELF][llvm-readobj] Support the GCS .note.gnu.property bit (#75065)
This bit was added to the AArch64 ABI by
https://github.com/ARM-software/abi-aa/pull/231.
2023-12-13 10:54:06 +00:00
Kazu Hirata
586ecdf205
[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-11 21:01:36 -08:00
Fangrui Song
54b4a0d688
[llvm-readobj] --needed-libs: support --elf-output-style=JSON (#75028)
Close #74529
2023-12-11 08:59:19 -08:00
Daniil Kovalev
3c6efe5fdb
[llvm-readobj][AArch64][ELF][PAC] Support ELF AUTH constants (#74874)
Reapply llvm/llvm-project#72713 after fixing formatted printing of
`uint64_t` values as hex (see failing build here
https://lab.llvm.org/buildbot/#/builders/186/builds/13604).

This patch adds llvm-readobj support for:

- Dynamic `R_AARCH64_AUTH_*` relocations (including RELR compressed AUTH
relocations) as described here:
https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#auth-variant-dynamic-relocations

- `.note.AARCH64-PAUTH-ABI-tag` section as defined here
https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#elf-marking
2023-12-09 00:31:40 +03:00
Daniil Kovalev
24f8bc5506
Revert "[llvm-readobj][AArch64][ELF][PAC] Support ELF AUTH constants" (#74816)
Reverts llvm/llvm-project#72713

Buildbot tests fail on clang-armv7-global-isel builder
https://lab.llvm.org/buildbot/#/builders/186/builds/13604
2023-12-08 12:10:27 +03:00
Daniil Kovalev
c8616c724f
[llvm-readobj][AArch64][ELF][PAC] Support ELF AUTH constants (#72713)
This patch adds llvm-readobj support for:

- Dynamic R_AARCH64_AUTH_* relocations (including RELR compressed AUTH
relocations) as described here:
https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#auth-variant-dynamic-relocations

- .note.AARCH64-PAUTH-ABI-tag section as defined here
https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#elf-marking
2023-12-08 09:31:16 +03:00
Kazu Hirata
57eb4826e5 [llvm] Stop including string (NFC)
Identified with clangd.
2023-12-03 16:24:43 -08:00
Adrian Prantl
2c07181424 [LEB128] Don't initialize error on success
This change removes an unnecessary branch from a hot path. It's also
questionable API to override any previous error unconditonally.
2023-11-29 12:47:27 -08:00
Adrian Prantl
69b0cb9c56 Revert "[LEB128] Don't initialize error on success"
This reverts commit 545c8e009e2b649ef38f7e432ffbc06ba8a9b813.
2023-11-29 12:40:37 -08:00
Adrian Prantl
545c8e009e [LEB128] Don't initialize error on success
This change removes an unnecessary branch from a hot path. It's also
questionable API to override any previous error unconditonally.
2023-11-29 12:16:32 -08:00
Jason Liu
623cd75105
[llvm-objdump] Fix lma display issue for non-bss sections (#72141)
llvm-readobj and llvm-objdump have inconsistent handling of display
lma for sections.
This patch tries to common code up and adapt the same approach for
both tools.
2023-11-27 12:24:39 -05:00
Jay Foad
cf1e0c0b07
[AMDGPU] Define new targets gfx1200 and gfx1201 (#73133)
Define target names and ELF numbers for new GFX12 targets gfx1200 and
gfx1201. For now they behave identically to GFX11.
2023-11-23 16:44:05 +00:00
Jay Foad
e0d93d5aaa [AMDGPU] Reindent some tables
This keeps clang-format happy on future patches.
2023-11-23 09:49:03 +00:00
Billy Laws
5edf586146
[AArch64][Windows] Add llvm-readobj support for ec_context unwind opcode (#69515)
ARM64EC uses the same CONTEXT structure as x86_64 as opposed to the
regular ARM64 context, a new unwind opcode MSFT_OP_EC_CONTEXT is
added to handle this.
2023-11-16 12:19:34 +01:00
Pierre van Houtryve
d3876c58a8
[ELFDumper] Always read AMD Code Object notes as little-endian (#70775)
Should avoid issues on big-endian hosts.

Note that we use aligned types because primitive integers are also
aligned. If we don't use aligned types, `HSAILProperties` ends up being
11 bytes instead of 12 (1 byte padding at the end of the struct added by
the compiler).
Technically only the first type needs to be aligned, but I just used
aligned types everywhere to be consistent.

Fixes #65280
2023-11-14 07:26:09 +01:00
Kazu Hirata
197d6ac793 [llvm] Stop including llvm/ADT/PointerIntPair.h (NFC)
Identified with clangd.
2023-11-11 08:55:22 -08:00
David Spickett
c5d8bf7196
[llvm][llvm-readobj] Add AArch64 Tagged Address note type (#68568)
On Linux this contains a single register that determines memory tagging
and tagged address ABI settings.
2023-10-20 08:37:44 +01:00
Kazu Hirata
b2e487d1f9 [llvm] Use StringRef::contains (NFC) 2023-10-18 17:38:37 -07:00
Kazu Hirata
643b2ccd82 [tools] Stop including llvm/ADT/StringMap.h (NFC)
These source files do not use StringMap.h.
2023-10-13 20:50:59 -07:00
Kazu Hirata
18d199116f Stop including llvm/ADT/STLFunctionalExtras.h (NFC)
These source files do not use function_ref.
2023-10-13 20:50:58 -07:00
Kazu Hirata
4a0ccfa865 Use llvm::endianness::{big,little,native} (NFC)
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an
enum. This patch replaces support::{big,little,native} with
llvm::endianness::{big,little,native}.
2023-10-12 21:21:45 -07:00
Kazu Hirata
b8885926f8 Use llvm::endianness::{big,little,native} (NFC)
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an enum.
This patch replaces llvm::support::{big,little,native} with
llvm::endianness::{big,little,native}.
2023-10-10 22:54:51 -07:00
Kazu Hirata
a9d5056862 Use llvm::endianness (NFC)
Now that llvm::support::endianness has been renamed to
llvm::endianness, we can use the shorter form.  This patch replaces
support::endianness with llvm::endianness.
2023-10-10 21:54:15 -07:00
Kazu Hirata
b05dbc4d5f [llvm] Use llvm::endianness::{big,little,native} (NFC)
Now that llvm::support::endianness has been renamed to
llvm::endianness, we can use the shorter form.  This patch replaces
support::endianness::{big,little,native} with
llvm::endianness::{big,little,native}.
2023-10-10 20:14:20 -07:00
Frederic Cambus
e5038f0f34
[llvm-readobj] Add support for the PT_OPENBSD_NOBTCFI segment type. (#67239)
Reference: https://github.com/openbsd/src/blob/master/sys/sys/exec_elf.h
2023-09-25 09:22:19 +02:00
Fangrui Song
eb81493e95
[llvm-readelf] Add --extra-sym-info (#65580)
GNU readelf introduced --extra-sym-info/-X to display the section name
for --syms (https://sourceware.org/PR30684). Port the feature, which is
currently llvm-readelf only.

For STO_AARCH64_VARIANT_PCS/STO_RISCV_VARIANT_PCS, the Ndx and Name
columns may not be aligned.
2023-09-11 11:08:58 -07:00
Fangrui Song
111fcb0df0 [llvm] Fix duplicate word typos. NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 18:25:16 -07:00
Rahman Lavaee
32cabfcbc6 Define BBEntry::hasIndirectBranch. NFC
Differential Revision: https://reviews.llvm.org/D158429
2023-08-21 15:38:45 +00:00
Fangrui Song
07bb66784c [llvm-readobj] Fix std::abs overflow after D156821
Tested by llvm/test/tools/llvm-readobj/ELF/relocations.test
2023-08-18 13:21:37 -07:00
Jacek Caban
627512a96c [llvm-readobj] [Object] [NFC] Introduce inline helpers for chpe_range_entry.
Reviewed By: jhenderson, MaskRay
Differential Revision: https://reviews.llvm.org/D156797
2023-08-13 21:59:25 +02:00
duk
f11f90d5f4
Fix buildbot failure caused by D157623
GCC doesn't like the implicit conversion here.
2023-08-10 16:34:58 -04:00
namazso
e335c78ec2
[lld][COFF] Remove incorrect flag from EHcont table
Fixes EHCont implementation in LLD. Closes #64570

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D157623
2023-08-10 16:17:38 -04:00
Jan Svoboda
3f092f37b7 [llvm] Extract common OptTable bits into macros
All command-line tools using `llvm::opt` create an enum of option IDs and a table of `OptTable::Info` object. Most of the tools use the same ID (`OPT_##ID`), kind (`Option::KIND##Class`), group ID (`OPT_##GROUP`) and alias ID (`OPT_##ALIAS`). This patch extracts that common code into canonical macros. This results in fewer changes when tweaking the `OPTION` macros emitted by the TableGen backend.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D157028
2023-08-04 13:57:13 -07:00
esmeyi
776195865d [XCOFF] Write source language ID and CPU version ID into C_FILE symbol.
Summary: The source language ID and CPU version ID are required by debuggers on AIX. AIX's system assembler determines the source language ID based on the source file's name suffix, and the behavior in this patch is consistent with it.

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D155684
2023-07-24 00:35:24 -04:00
Fangrui Song
82b4368f7f [llvm-readobj] Print <null> for relocation target with an empty name
For a relocation, we don't differentiate the two cases:

* the symbol index is 0
* the symbol index is non zero, the type is not STT_SECTION, and the name is empty. Clang generates such local symbols for RISC-V linker relaxation.

So we may print
```
    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
000000000000001c  0000000100000039 R_RISCV_32_PCREL       0000000000000000 0

// llvm-readobj
0x1C R_RISCV_32_PCREL - 0x0
```

while GNU readelf prints "<null>", which is clearer. Let's match the GNU behavior.
Related to https://reviews.llvm.org/D81842

```
000000000000001c  0000000100000039 R_RISCV_32_PCREL       0000000000000000 <null> + 0

// llvm-readobj
0x1C R_RISCV_32_PCREL <null> 0x0
```

Reviewed By: jhenderson, kito-cheng

Differential Revision: https://reviews.llvm.org/D155353
2023-07-20 00:42:38 -07:00