2130 Commits

Author SHA1 Message Date
Cyndy Ishida
cc945e41a7
[MachO] Loosen boundary check for reading export trie nodes (#96705)
The design of the export trie in macho's is that each node has a
variable length payload. When reading nodes, it should be an error if
reading the uleb128 puts you beyond the stated node size but not when
the stated size goes beyond the known part that was read.

resolves: rdar://130310832

This was primarily authored by Nick Kledzik, I added/cleaned up the test
cases.
2024-07-09 10:18:05 -07: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
Fangrui Song
1b704e889f
[MC,llvm-readobj,yaml2obj] Support CREL relocation format
CREL is a compact relocation format for the ELF object file format.

This patch adds integrated assembler support (using the RELA form)
available with `llvm-mc -filetype=obj -crel a.s -o a.o`.
A dependent patch will add `clang -c -Wa,--crel,--allow-experimental-crel`.

Also add llvm-readobj support (for both REL and RELA forms) to
facilitate testing the assembler. Additionally, yaml2obj gains support
for the RELA form to aid testing with llvm-readobj.

We temporarily assign the section type code 0x40000020 from the generic
range to `SHT_CREL`. We avoided using `SHT_LLVM_` or `SHT_GNU_` to
avoid code churn and maintain broader applicability for interested psABIs.
Similarly, `DT_CREL` is temporarily 0x40000026.

LLVM will change the code and break compatibility. This is not an issue
if all relocatable files using CREL are regenerated (aka no prebuilt
relocatable files).

Link: https://discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600

Pull Request: https://github.com/llvm/llvm-project/pull/91280
2024-07-01 10:32:02 -07:00
Kazu Hirata
ddaa93b095
[llvm] Use std::make_unique (NFC) (#97165)
This patch is based on clang-tidy's modernize-make-unique but limited
to those cases where type names are mentioned twice like
std::unique_ptr<Type>(new Type()), which is a bit mouthful.
2024-06-29 11:50:41 -07:00
Nikita Popov
9df71d7673
[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds
`getDataLayout()` helpers to Function and GlobalValue, replacing the
current `getParent()->getDataLayout()` pattern.
2024-06-28 08:36:49 +02: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
Shilei Tian
1ca0055f45
[AMDGPU] Add a new target gfx1152 (#94534) 2024-06-06 12:16:11 -04:00
Konstantin Zhuravlyov
775f1cd34d
AMDGPU: Add gfx12-generic target (#93875) 2024-05-31 12:46:44 -04:00
Zixu Wang
1fa073ab89
[MachO] Stop parsing past end of rebase/bind table (#93897)
`MachORebaseEntry::moveNext()` and `MachOBindEntry::moveNext()` assume
that the rebase/bind table ends with `{REBASE|BIND}_OPCODE_DONE` or an
actual rebase/bind. However a valid rebase/bind table might also end
with other effectively no-op opcodes, which caused the parser to move
past the end and go into the next table, resulting in corrupted entries
or infinite loops.
2024-05-30 23:08:01 -07:00
Heejin Ahn
c179d50fd3
[WebAssembly] Add exnref type (#93586)
This adds (back) the exnref type restored in the new EH proposal adopted
in Oct 2023 CG meeting:

https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md:x
2024-05-28 16:10:11 -07:00
Kazu Hirata
14030d7169 [llvm] Drop explicit conversions of string literals to StringRef (NFC)
We routinely rely on implicit conversions of string literals to
StringRef so that we can use operator==(StringRef, StringRef).
2024-05-16 22:18:45 -07:00
Mircea Trofin
217668f641
[nfc] Allow forwarding Error returns from Expected callers (#92208)
On a few compilers (clang 11/12 for example [1]), the following does not
result in a copy elision, and since `Error`'s copy dtor is elided,
results in a compile error:

```
  Expect<Something> foobar() {
    ...
    if (Error E = aCallReturningError())
      return E;
    ...
  }
```

Moving `E` would, conversely, result in the pessimizing-move warning on
more recent clangs ("moving a local object in a return statement
prevents copy elision")

We just need to make the `Expected` ctor taking an `Error` take it as a
r-value reference.

[1] https://lab.llvm.org/buildbot/#/builders/54/builds/10505
2024-05-15 10:34:47 -07:00
Zixu Wang
b910bebc30
[llvm][MachO] Fix integer truncation in rebase/bind parsing (#89337)
`Count` and `Skip` should use `uint64_t` as they are encoded/decoded
using 64-bit ULEB128.

In `*_OPCODE_DO_*_ULEB_TIMES_SKIPPING_ULEB`, `Skip` could be encoded as
a two's complement for moving `SegmentOffset` backwards. Having a 32-bit
`Skip` truncates the encoded value and leads to a malformed
`AdvanceAmount`
and invalid `SegmentOffset` that extends past valid sections.
2024-05-08 18:53:15 -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
Fangrui Song
99e7350235
IRSymTab: Record _GLOBAL_OFFSET_TABLE_ for ELF x86
In ELF, relocatable files generated for x86-32 and some code models of
x86-64 (medium, large) may reference the special symbol
`_GLOBAL_OFFSET_TABLE_` that is not used in the IR. In an LTO link, if
there is no regular relocatable file referencing the special symbol, the
linker may not define the symbol and lead to a spurious "undefined
symbol" error.

Fix #61101: record that `_GLOBAL_OFFSET_TABLE_` is used in the IR symbol
table.

Note: The `PreservedSymbols` mechanism
(https://reviews.llvm.org/D112595) that just sets `FB_used` is not
applicable.
The `getRuntimeLibcallSymbols` for extracting lazy runtime library
symbols is for symbols that are "always" potentially used, but linkers
don't have the code model information to make a precise decision.

Pull Request: https://github.com/llvm/llvm-project/pull/89463
2024-04-23 17:02:21 -07:00
Craig Topper
733a87783c
[RISCV] Split code that tablegen needs out of RISCVISAInfo. (#89684)
This introduces a new file, RISCVISAUtils.cpp and moves the rest of
RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using tablegen.
2024-04-23 15:12:36 -07:00
Martin Storsjö
750de326ef
[COFF] Rename the COFFShortExport::AliasTarget field. NFC. (#89039)
It turns out that the previous name is vaguely misleading.

When operating on a def file like "symbolname == dllname", that is
supposed to make an import library entry, that when the symbol
"symbolname" links against this, it imports the DLL symbol "dllname"
from the referenced DLL. This doesn't need to involve any alias, and it
doesn't need to imply that "dllname" is available on its own as a
separate symbol in the import library at all.

GNU dlltool implements import libraries in the form of "long import
library", where each member is a regular object file with section chunks
that compose the relevant .idata section pieces. There, this kind of
import renaming does not involve any form of aliases, but the right
.idata section just gets a different string than the symbol name.
2024-04-18 13:29:38 +03:00
Simon Pilgrim
db08060512 Fix MSVC "result of 32-bit shift implicitly converted to 64 bits" warning. NFC. 2024-04-09 09:59:57 +01:00
Yusra Syeda
4c718fdbea
[SystemZ][z/OS] TXT records in the GOFF reader (#87648)
This PR adds handling for TXT records in the GOFF reader.

---------

Co-authored-by: Yusra Syeda <yusra.syeda@ibm.com>
2024-04-08 11:05:42 -04:00
Jacek Caban
5c1544c953
[Object][COFF][NFC] Introduce getMachineArchType helper. (#87370)
It's a common pattern that we have a machine type, but we don't care
which ARM64* platform we're dealing with. We already have
isAnyArm64 for that, but it does not fit cases where we use a switch
statement. With this helper, it's easy to simplify such cases by using
Triple::ArchType instead of machine type.
2024-04-03 13:28:23 +02:00
Kai Nacke
6634c3e937
[GOFF] Wrap debug output with LLVM_DEBUG (#87252)
The content of a GOFF record is always dumped if NDEBUG is not defined,
which produces rather confusing output. This changes wrap the dumping
code in LLVM_DEBUG, so the dump is only done when debug output of this
module is requested.
2024-04-01 14:20:41 -04:00
Jacek Caban
8d8fff09d7
[Object][COFF][NFC] Don't use inline function for COFFImportFile::printSymbolName. (#87195)
Fixes BUILD_SHARED_LIBS builds after #87191 made helpers non-inline.
2024-03-31 18:30:04 +02:00
Aiden Grossman
abc270ae00 Finish revert "[SystemZ][z/OS] TXT records in the GOFF reader (#74526)"
This finishes the revert started in
aeb8628c218f8224e08dddcdd3199a445d8607a8 which didn't completely back
out the original patch.
2024-03-27 12:47:52 -07:00
Neumann Hon
aeb8628c21 Revert "[SystemZ][z/OS] TXT records in the GOFF reader (#74526)"
This reverts commit 009f88fc0e3a036be97ef7b222b90af342bae0b7.

Reverting PR due to test failure.
2024-03-27 15:15:32 -04:00
Simon Pilgrim
468c6bea22 Fix "result of 32-bit shift implicitly converted to 64 bits" MSVC warning. NFCI. 2024-03-27 16:26:10 +00:00
Yusra Syeda
009f88fc0e
[SystemZ][z/OS] TXT records in the GOFF reader (#74526)
This PR adds handling for TXT records in the GOFF reader.

---------

Authored-by: Yusra Syeda <yusra.syeda@ibm.com>
2024-03-27 11:31:21 -04:00
Jacek Caban
c9d12664f2
[llvm-dlltool][llvm-lib][COFF] Don't override NONAME exports with demangled ARM64EC symbols. (#86722) 2024-03-27 11:41:02 +01:00
Cooper Partin
c62c74639a
Add support for PSV EntryFunctionName (#86296)
This change introduces a version 3 of the PSV data that includes support
for the name of the entry function as an offset into StringTable data to
a null-terminated utf-8 string.

Additional tests were added to ensure that the new value was properly
serialized/deserialized from object data.

Fixes #80175

---------

Co-authored-by: Cooper Partin <coopp@ntdev.microsoft.com>
2024-03-25 10:18:53 -07:00
Antonio Frighetto
6e28ecd799 [Object][ELF] Ensure offset to locate dyn section does not go past size
Validate `p_offset` in `dynamicEntries` before computing the entry offset.

Fixes: https://github.com/llvm/llvm-project/issues/85568.
2024-03-22 16:29:09 +01:00
Antonio Frighetto
6f44bb7717 [Object] Ensure header size not to underflow in OffloadBinary::create
Prevent potential integer underflows when header size is not valid.

Fixes: https://github.com/llvm/llvm-project/issues/86280.
2024-03-22 15:45:23 +01:00
Cooper Partin
1538b82fd3
Revert "Add support for PSV EntryFunctionName (#84409)" (#86211)
This reverts commit cde54df39cab3a1d60a3e1862ab341609bee3cc3.

Co-authored-by: Cooper Partin <coopp@ntdev.microsoft.com>
2024-03-21 15:40:29 -07:00
Cooper Partin
cde54df39c
Add support for PSV EntryFunctionName (#84409)
This change introduces a version 3 of the PSV data that includes support
for the name of the entry function as an offset into StringTable data to
a null-terminated utf-8 string.

Additional tests were added to ensure that the new value was properly
serialized/deserialized from object data.

Fixes #80175

---------

Co-authored-by: Cooper Partin <coopp@ntdev.microsoft.com>
2024-03-21 14:43:15 -07:00
Jacek Caban
8ecc377c88
[llvm-lib] Use ARM64EC machine type for import libraries when -machine:arm64x is used. (#85972)
This is compatible with MSVC, `-machine:arm64x` is essentially an alias
to `-machine:arm64ec`. To make a type library that exposes both native
and EC symbols, an additional `-defArm64Native` argument is needed in
both cases.
2024-03-21 11:40:46 +01:00
Jacek Caban
254bfe955a
[llvm-ar][Object][COFF] Add support for EC symbols to llvm-ar. (#85230)
Make writeArchive IsEC argument optional and use EC symbol map when indicated by input object files.
2024-03-20 13:39:23 +01:00
quic-areg
31f4b329c8
[Hexagon] ELF attributes for Hexagon (#85359)
Defines a subset of attributes and emits them to a section called
.hexagon.attributes.

The current attributes recorded are the attributes needed by
llvm-objdump to automatically determine target features and eliminate
the need to manually pass features.
2024-03-19 16:22:30 -05:00
Jacek Caban
c7fc95baae
[Object][Archive][NFC] Create all symbolic files objects before calculating offsets. (#85229)
This is refactoring preparing to move UseECMap computation to the
archive writer. We currently require writeArchive caller to pass that.
This is not practical for llvm-ar, which currently interprets at most
one passed object. For a reliable UseECMap, we need to interpret all
symbolic objects: we may have, for example, a list of x86_64 files
followed by aarch64 file, which indicates that we should use EC map for
x86_64 objects.

This commit interprets symbolic files in a separated pass, which will be
a convenient place to implement UseECMap computation in the follow up.
It also makes accessing the next member for AIX big archive offset
computation a bit easier.
2024-03-15 12:38:41 +01:00
Jacek Caban
2037577768
[llvm-ar] Use COFF archive format for COFF targets. (#82898)
Detect COFF files by default and allow specifying it with --format
argument.

This is important for ARM64EC, which uses a separated symbol map for EC
symbols. Since K_COFF is mostly compatible with K_GNU, this shouldn't
really make a difference for other targets.

This originally landed as #82642, but was reverted due to test failures
in tests using no symbol table. Since COFF symbol can't express it,
fallback to GNU format in that case.
2024-03-13 13:27:20 +01:00
Daniel Paoliello
1a6ec906fb
[Arm64EC] Copy import descriptors to the EC Map (#84834)
As noted in <https://github.com/llvm/llvm-project/pull/78537>, MSVC
places import descriptors in both the EC and regular map - that PR moved
the descriptors to ONLY the regular map, however this causes linking
errors when linking as Arm64EC:

```
bcryptprimitives.lib(bcryptprimitives.dll) : error LNK2001: unresolved external symbol __IMPORT_DESCRIPTOR_bcryptprimitives (EC Symbol)
```

This change copies import descriptors from the regular map to the EC
map, which fixes this linking error.
2024-03-12 14:10:49 -07:00
Michael Spencer
ba13fa2a5d
[llvm][Support] Add and use errnoAsErrorCode (#84423)
LLVM is inconsistent about how it converts `errno` to `std::error_code`.
This can cause problems because values outside of `std::errc` compare
differently if one is system and one is generic on POSIX systems.

This is even more of a problem on Windows where use of the system
category is just wrong, as that is for Windows errors, which have a
completely different mapping than POSIX/generic errors. This patch fixes
one instance of this mistake in `JSONTransport.cpp`.

This patch adds `errnoAsErrorCode()` which makes it so people do not
need to think about this issue in the future. It also cleans up a lot of
usage of `errno` in LLVM and Clang.
2024-03-08 23:30:33 -08:00
Xiang Li
50136ca11f
[DirectX][NFC] Rename ShaderFlag to SHADER_FEATURE_FLAG. (#82700)
This is preparation for add ShaderFlag in DXIL.

For #57925
2024-02-27 21:01:37 -05:00
Jacek Caban
13fd4bf4e5
[llvm-ar][Archive] Use getDefaultTargetTriple instead of host triple for the fallback archive format. (#82888) 2024-02-27 19:56:00 +01:00
Jacek Caban
8a5aa103c5
Revert "[llvm-ar] Use COFF archive format for COFF targets." (#82889)
Reverts llvm/llvm-project#82642 for
lld/test/ELF/invalid/Output/data-encoding.test.tmp.a failures on
Windows.
2024-02-24 17:43:59 +01:00
Jacek Caban
cf9201cfdb
[llvm-ar] Use COFF archive format for COFF targets. (#82642)
Detect COFF files by default and allow specifying it with --format
argument.

This is important for ARM64EC, which uses a separated symbol map for EC
symbols. Since K_COFF is mostly compatible with K_GNU, this shouldn't
really make a difference for other targets.
2024-02-24 17:01:54 +01:00
Derek Schuff
ca09e08239
[Symbolizer][WebAssembly] Use wasm-specific getSymbolSize (#82083)
getSymbolSize was recently added to WasmObjectFile and has correct sizes 
for most symbol types. This makes llvm-symbolizer correctly symbolize
addresses in the middle of the symbol.

When reworking the test I also noticed that the DWARF info seems to be
wrong for the first instruction in each function. I noted that in the test
comments but didn't attempt to fix here.
2024-02-22 19:41:15 -08:00
stephenpeckham
26db845536
[XCOFF] Support the subtype flag in DWARF section headers (#81667)
The section headers for XCOFF files have a subtype flag for Dwarf
sections. This PR updates obj2yaml, yaml2obj, and llvm-readobj so that
they recognize the subtype.
2024-02-20 08:42:12 -06:00
Derek Schuff
2eaeae7e9a
[Object][Wasm] Use offset instead of index for Global address and store size (#81781)
Currently the address reported by binutils for a global is its index;
but its offset (in the file or section) is more useful for binary size
attribution.
This PR treats globals similarly to functions, and tracks their offset
and size. It also centralizes the logic differentiating linked from object
and dylib files (where section addresses are 0).
2024-02-15 09:36:44 -08:00
Jacek Caban
fd191378dc
[llvm-dlltool] Add ARM64EC target support. (#81624)
Add new target and a new -n option allowing to specify native module
definition file, similar to how -defArm64Native works in llvm-lib. This
also changes archive format to use K_COFF like non-mingw targets. It's
required on ARM64EC, but it should be fine for other targets too.
2024-02-15 12:17:45 +01: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
Jacek Caban
46122082a6
[Object][COFF][NFC] Make writeImportLibrary NativeExports argument optional. (#81600)
It's not interesting for majority of downstream users.
2024-02-13 15:17:28 +01:00
Jacek Caban
a38152e215
[llvm-lib] Add support for -defArm64Native argument. (#81426)
This can be used to create import libraries that contain both ARM64EC
and native exports. The implementation follows observed MSVC lib.exe
behaviour. It's ignored on targets other than ARM64EC.
2024-02-13 01:49:45 +01:00