786 Commits

Author SHA1 Message Date
Martin Storsjö
4c642b62b9 [llvm-jitlink] [test] Add an XFAIL for a JITLink test on MinGW
This testcase fails on MinGW targets, because when compiling the
main() function, it gets an implicit call to __main(), which is
missing in this context.
2024-03-01 12:16:47 +02:00
David Spickett
e4d4ebe041 [llvm][llvm-jitlink] Disable test on Windows on Arm
This fails on one of our bots:
https://lab.llvm.org/buildbot/#/builders/120/builds/6309

llvm-jitlink error: Unsupported target machine architecture in COFF object

The other bot doesn't run the test at all it seems but I can't explain
why. It's also possible that I'm mistaken and the mostly native but still
"cross compiling" setup we have on WoA means an x86 object is produced sometimes
(perhaps because a default triple is still x86).
2024-02-22 10:23:02 +00:00
Lang Hames
54b014b3f7 [llvm-jitlink] Use '@' rather than ':' for separator in -sectcreate.
This should avoid the issue with Windows paths that have caused failures on
some builders.
2024-02-20 15:05:42 -08:00
Lang Hames
c625b99652 [ORC] Add SectCreateMaterializationUnit, llvm-jitlink -sectcreate option.
The SectCreateMaterializationUnit creates a LinkGraph with a single named
section containing a single named block whose content is given by a
MemoryBuffer. It is intended to support emulation of ld64's -sectcreate option.
2024-02-20 10:23:54 -08:00
Craig Topper
8c37e3e64b
[RISCV] Only set Zca flag for EF_RISCV_RVC in ELFObjectFileBase::getRISCVFeatures(). (#80928)
This code appears to be a hack to set the features to include compressed
instructions if the ELF EFLAGS flags bit is present, but the ELF
attribute for the ISA string is no present or not accurate.

We can't remove the hack because llvm-mc doesn't create ELF attributes
by default so a lot of tests fail to disassembler properly. Using clang
as the assembler does set the attributes.

This patch changes the hack to only set Zca since that is the minimum
implied by the flag. Setting anything else potentially conflicts with
the ISA string containing Zcmp or Zcmt.

JITLink also needs to be updated to recognize Zca in addition to C.
2024-02-07 08:23:57 -08:00
lhames
ebe8733a11
[ORC] Merge MaterializationResponsibility notifyEmitted and addDependencies
Removes the MaterializationResponsibility::addDependencies and
addDependenciesForAll methods, and transfers dependency registration to
the notifyEmitted operation. The new dependency registration allows
dependencies to be specified for arbitrary subsets of the
MaterializationResponsibility's symbols (rather than just single symbols
or all symbols) via an array of SymbolDependenceGroups (pairs of symbol
sets and corresponding dependencies for that set).

This patch aims to both improve emission performance and simplify
dependence tracking. By eliminating some states (e.g. symbols having
registered dependencies but not yet being resolved or emitted) we make
some errors impossible by construction, and reduce the number of error
cases that we need to check. NonOwningSymbolStringPtrs are used for
dependence tracking under the session lock, which should reduce
ref-counting operations, and intra-emit dependencies are resolved
outside the session lock, which should provide better performance when
JITing concurrently (since some dependence tracking can happen in
parallel).

The Orc C API is updated to account for this change, with the
LLVMOrcMaterializationResponsibilityNotifyEmitted API being modified and
the LLVMOrcMaterializationResponsibilityAddDependencies and
LLVMOrcMaterializationResponsibilityAddDependenciesForAll operations
being removed.
2024-01-31 13:06:09 -08:00
Stefan Gränitz
55929cd679
[JITLink][AArch32] Implement Armv5 ldr-pc stubs and use them for all pre-v7 targets (#79082)
This stub type loads an absolute address directly into the PC register.
It's the simplest and most compatible way to implement a branch
indirection across the entire address space (and probably the slowest as
well). It's the ideal fallback for all targets for which we did not
(yet) implement a more performant solution.
2024-01-23 18:02:17 +01:00
Stefan Gränitz
9577806b1e
[JITLink][AArch32] Implement R_ARM_PREL31 and process .ARM.exidx sections (#79044)
`R_ARM_PREL31` is a 31-bits relative data relocation where the
most-significant bit is preserved. It's used primarily in `.ARM.exidx`
sections, which we skipped processing until now, because we didn't
support the relocation type. This was implemented in RuntimeDyld with
https://reviews.llvm.org/D25069 and I implemented it in a similar way in
JITLink in order to reach feature parity.
2024-01-23 03:37:32 +01:00
Stefan Gränitz
e5ca202ef8
[JITLink][AArch32] Multi-stub support for armv7/thumbv7 (#78371)
We want to emit stubs that match the instruction set state of the
relocation site. This is important for branches that have no built-in
switch for the instruction set state. It's the case for Jump24
relocations. Relocations on instructions that support switching on
the fly will be rewritten in a relaxation step in the future. This
affects Call relocations on `BL`/`BLX` instructions.

In this patch, the StubManager gains a second stub symbol slot for each
target and selects which one to use based on the relocation type. For
testing, we select the appropriate slot with a stub-kind filter, i.e.
`arm` or `thumb`. With that we can implement Armv7 stubs and test
that we can have both kinds of stubs for a single external symbol.
2024-01-23 02:59:30 +01:00
Stefan Gränitz
cd6ed95e48 Reland "[lli] Revisit Orc debug output tests (#79055)"
Integrate in-memory debug-info dumps into the `--orc-lazy-debug`
command-line option instead of exposing built-in functions to be called
from JITed code. This reduces overall amount of code (removing
`ExecutionUtils.cpp`) and seems cleaner anyway.

All existing items of `OrcDumpKind` work on IR level and run in the
IR-transform step of the JIT. The newly added `DumpDebugDescriptor` and
`DumpDebugObjects` must run after debug-registration and thus are
deferred to the Object-transform step of the JIT. This separation is the
major side-effect of the patch.

The original commit 263efb044add93b9 was reverted in #79055, because
the gcc 7.5 bot had found a missing std::move().
2024-01-22 22:46:27 +01:00
Mehdi Amini
3f3a3e873a
Revert "[lli] Revisit Orc debug output tests" (#79055)
Reverts llvm/llvm-project#76822

This fails to build with gcc 7.5:
```
llvm/tools/lli/lli.cpp:1087:16: error: could not convert ‘Obj’ from ‘std::unique_ptr<llvm::MemoryBuffer>’ to ‘llvm::Expected<std::unique_ptr<llvm::MemoryBuffer> >’
         return Obj;
                ^~~
```
2024-01-22 12:54:30 -08:00
Stefan Gränitz
263efb044a
[lli] Revisit Orc debug output tests (#76822)
Integrate in-memory debug-info dumps into the `--orc-lazy-debug`
command-line option instead of exposing built-in functions to be called
from JITed code. This reduces overall amount of code (removing
`ExecutionUtils.cpp`) and seems cleaner anyway.

All existing items of `OrcDumpKind` work on IR level and run in the
IR-transform step of the JIT. The newly added `DumpDebugDescriptor` and
`DumpDebugObjects` must run after debug-registration and thus are
deferred to the Object-transform step of the JIT. This separation is the
major side-effect of the patch.
2024-01-22 21:24:57 +01:00
Stefan Gränitz
565470ed27 [JITLink][AArch32] Implement ELF relocation R_ARM_NONE 2024-01-22 16:47:17 +01:00
Stefan Gränitz
bfb09326be [JITLink][AArch32] Implement ELF relocation R_ARM_TARGET1
Prepare a configuration switch and default to R_ARM_ABS32
2024-01-22 16:47:17 +01:00
Stefan Gränitz
c4fc563b8d
[JITLink][AArch32] Add GOT builder and implement R_ARM_GOT_PREL relocations for ELF (#78753)
LLJIT needs this relocation for running deinitializers. Implementation and
test are adapted from test arm-fpic-got.s in LLD.
2024-01-22 12:00:24 +01:00
Stefan Gränitz
079706df02 [JITLink][AArch32] Fix typos in Thumb stubs test (NFC) 2024-01-17 00:36:29 +01:00
Stefan Gränitz
539c557a7f [JITLink][AArch32] Streamline file-names of tests (NFC)
All other backends use the full term "relocations". Also, sorting by type (relocations/stubs/etc.) before CPU states (arm/thumb/other) makes it easier to filter in LIT.
2024-01-17 00:36:29 +01:00
Fangrui Song
f972e4d343 [MC,ELF] .section: unconditionally print section flag 'G' after 'o'
* Placing 'G' before 'M' (SHF_MERGE) can be misleading as the sh_entsize
  argument goes before the section group name, if a reader doesn't know
  that the order of extra arguments is not affected by the order of flags.
* 'a', 'w', and 'x' indicate basic permission-related flags. Separating
  them with 'G' is kinda ugly.

Simplify code and move 'G' after 'o'. The new output is more similar to
GCC.
2024-01-09 10:48:23 -08:00
Stefan Gränitz
27091dacdd [Orc] Temporarily disable OrcLazy debug tests on macOS
Test failures were reported after https://github.com/llvm/llvm-project/pull/76244 landed. Let's revisit these tests now that we have native Mach-O debug support as well.
2024-01-02 18:56:12 +01:00
Kai Luo
4128edeaad [JITLink] Tell yaml2obj the MachO file is little-endian. NFC.
Big-endian is not supported on aarch64 and x86 yet. Try to fix
buildbot failure on ppc64be, https://lab.llvm.org/buildbot/#/builders/93/builds/18057.
2023-12-27 07:31:42 +00:00
Lang Hames
95bdbc8a28 [JITLink] Add -phony-externals to silence test errors on some buildbots.
The recently added MachO_subtractor_single_block tests reference C++ itanium
ABI symbols, but these break on some Windows systems (see e.g.
https://lab.llvm.org/buildbot/#/builders/117/builds/17021). Adding
-phony-externals should suppress the errors.
2023-12-25 09:54:14 -08:00
Lang Hames
4c1bc8e753 [JITLink][MachO] Handle intra-block subtractor relocations.
Previously the JITLink MachO backends (aarch64 and x86-64) only looked at the
fixup block to determine which symbol was being fixed up. This assumption breaks
if both symbols used in the subtractor are in the same block. The fix is to
check for such cases and use the offsets of each symbol to decide which is being
fixed up.

The issue only resulted in incorrect behavior for negative-delta relocations,
so the testcases use eh-frames with explicit edges for the CIE-pointer field in
FDEs (since these are negative-deltas).

rdar://119351329
2023-12-24 14:06:11 -08:00
Lang Hames
3b2f879509 [ORC] Use dyn_cast to check input type in StaticLibraryDefinitionGenerator.
Replaces an llvm::cast that assumed that all Binary instances were either
Archive or MachOUniversalBinary instances with a dyn_cast. The cast was
triggering an assert in StaticLibraryDefinitionGenerator::Load if that method
was given a path or MemoryBuffer containing a relocatable object file.
Switching to dyn_cast causes the operation to error out with a bad-format
error as expected.

Fixes rdar://119262300
2023-12-06 14:01:55 -08:00
Lang Hames
b4e1915517 Re-apply "[llvm-jitlink] Add Process and Platform JITDylibs, ..." with fixes.
This reapplies 3d0dd1a7d6, which was reverted in df2485b215a due to bot
failures. This patch addresses the issues seen on the bots by disabling two
Linux atexit tests in the ORC runtime whose behavior could not be maintained
now that the ORC runtime is being loaded into a separate Platform JITDylib.
https://github.com/llvm/llvm-project/issues/74641 has been filed to fix the
issue with atexit.
2023-12-06 12:35:56 -08:00
Lang Hames
df2485b215 Revert "[llvm-jitlink] Add Process and Platform JITDylibs, generalize alias..."
This reverts commit 3d0dd1a7d62 while I investigate bot failures (e.g.
https://lab.llvm.org/buildbot/#/builders/272/builds/2573)
2023-12-05 10:23:31 -08:00
Lang Hames
3d0dd1a7d6 [llvm-jitlink] Add Process and Platform JITDylibs, generalize alias option.
The Process JITDylib holds reflected process symbols. The Platform JITDylib
holds ORC runtime symbols if the ORC runtime is loaded. The Platform and
Process JITDylibs are appended to the link order of all other JITDylibs,
including the main JITDylib, after any explicitly specified libraries. This
scheme is similar to the one introduced in LLJIT in 371cb1af61d, and makes
it easier to introduce aliases for process and platform symbols in a way that
affects all JITDylibs uniformly.

Since the Process and Platform JITDylibs are created implicitly the -alias
option is generalized to allow source and destination JITDylibs to be explicitly
specified, i.e. the -alias option now supports general re-exports.

Testcases are updated to account for the change.
2023-12-05 09:48:58 -08:00
Arthur Eubanks
d8a04398f9 Reland [X86] With large code model, put functions into .ltext with large section flag (#73037)
So that when mixing small and large text, large text stays out of the
way of the rest of the binary.

This is useful for mixing precompiled small code model object files and
built-from-source large code model binaries so that the the text
sections don't get merged.

The reland fixes an issue where a function in the large code model would reference small data without GOTOFF.

This was incorrectly reverted in 76f78ecc789d58baa3a88b2fe2a57428f07e5362.
2023-12-01 14:23:44 -08:00
Dmitri Gribenko
76f78ecc78 Revert "Reland [X86] With large code model, put functions into .ltext with large section flag (#73037)"
This reverts commit 4bf8a688956a759b7b6b8d94f42d25c13c7af130.

This commit seems to be breaking the semantics of the
ObjectFile::isSectionText method, which breaks numba/llvmlite bindings.
2023-12-01 17:18:14 +01:00
Arthur Eubanks
4bf8a68895 Reland [X86] With large code model, put functions into .ltext with large section flag (#73037)
So that when mixing small and large text, large text stays out of the
way of the rest of the binary.

This is useful for mixing precompiled small code model object files and
built-from-source large code model binaries so that the the text
sections don't get merged.

The reland fixes an issue where a function in the large code model would reference small data without GOTOFF.
2023-11-30 15:17:17 -08:00
Arthur Eubanks
d8d9394cb0 Revert "[X86] With large code model, put functions into .ltext with large section flag (#73037)"
This reverts commit 38e435895779c6f0e6c47a171f3b300ad99828b3.

May be culprit for https://lab.llvm.org/buildbot/#/builders/37/builds/28079/steps/9/logs/stdio.
2023-11-28 14:14:40 -08:00
Arthur Eubanks
38e4358957
[X86] With large code model, put functions into .ltext with large section flag (#73037)
So that when mixing small and large text, large text stays out of the
way of the rest of the binary.

This is useful for mixing precompiled small code model object files and
built-from-source large code model binaries so that the the text
sections don't get merged.
2023-11-28 12:55:17 -08:00
Stefan Gränitz
95dcb8b49d
[llvm-jitlink] Support plain AArch32 stubs in jitlink-check's stub_addr() expressions (#73268)
We want to use regular `stub_addr()` expressions in `jitlink-check` lines to test the generation of stubs in AArch32, but we don't want this to require a standardized GOT-based PLT implementation. In terms of performance and binary size it doesn't seem beneficial. And in terms of patching branch targets, we should be able to handle range-extension- and interworking-stubs without a lot of extra logic.

In order to allow such AArch32 stubs we add a separate path for `stub_addr()` expressions in `llvm-jitlink-elf`. The relocations in our stubs are not pointing to the GOT, but to the external symbol directly. Thus, we have to avoid access to the block of the edge target. Instead we only return the symbol name, which is enough to use `stub_addr()` expressions in tests.

The name of the AArch32 stubs section differs from the conventional `$__STUBS` on purpose. It allows to add a regular PLT/GOT implementation as an orthogonal feature in the future. In order to also allow decoding of stub target addresses in the future, we mention the stub flavor in the section name as well.
2023-11-24 21:41:00 +01:00
Stefan Gränitz
3bf6cbd51a [JITLink][AArch32] Add tests for BLX interworking calls
Exercise transformation of BL into BLX instructions, if
instruction set mode differs between origin and target.
2023-11-23 22:01:41 +01:00
Eymen Ünay
87081f1c18
[JITLink][AArch32] Add support for ELF::R_ARM_THM_MOV{W_PREL_NC,T_PREL} (#70364)
Support for ELF::R_ARM_THM_MOVW_PREL_NC and ELF::R_ARM_THM_MOVT_PREL
is added. Move instructions with PC-relative immediates can be handled
in Thumb mode with this addition.
2023-11-09 11:51:02 +03:00
Eymen Ünay
6a451ea5b4
[JITLink][AArch32] Add test for ELF::R_ARM_THM_MOV{W_ABS_NC,T_ABS} (#70346)
Support for ELF::R_ARM_THM_MOVW_ABS_NC and ELF::R_ARM_THM_MOVT_ABS
was present but lacked tests. Test cases are similar to the ARM
versions of the relocations in ELF_static_arm_reloc.s.
2023-11-07 21:00:45 +03:00
Eymen Ünay
1e46bc73a4 [JITLink][AArch32] Tests for ELF::R_ARM_ABS32 and ELF::R_ARM_REL32
Testing for Static Data relocations for both ARM and Thumb targets.

Reviewed By: lhames, Eymay

Differential Revision: https://reviews.llvm.org/D157519
2023-11-07 12:31:37 +01:00
Jonas Hahnfeld
4f6757ce4b
[JITLink][RISCV] Implement eh_frame handling (#68253)
This requires adding a `NegDelta32` edge kind that cannot be mapped to
existing relocations.

Co-authored-by: Job Noorman <jnoorman@igalia.com>
2023-10-28 11:30:43 +02:00
Dudeldu
75d6f508f8
[Interpreter] Add initialization of array members (#66172)
Currently, the interpreter does not initialize `undef` constants of
aggregate types correctly (with respect to arrays).
The initialization of the array elements is skipped although it is valid
to directly write to them. Instructions like
`insertvalue {i32, [4 x i32]} undef, i32 1, 1, 2` therefore lead to a
crash.
This is fixed by initializing array values just as fixed-size vectors or
structs.
2023-10-20 15:27:11 +02:00
Kai Luo
18dc8dcd76
[PowerPC][JITLink] Support R_PPC64_GOT_TLSGD_PCREL34 (#68660)
`R_PPC64_GOT_TLSGD_PCREL34` is generated for pwr10+.
2023-10-14 10:57:03 +08:00
Kai Luo
a712244f3b
[PowerPC][JITLink] Support R_PPC64_GOT_PCREL34 (#68658)
`R_PPC64_GOT_PCREL34` is generated for pwr10+.
2023-10-13 08:51:11 +08:00
Leonard Chan
2ae3a71230 Fix minimal-throw-catch.ll on x86 mac
It looks like this broke after https://reviews.llvm.org/D86310 and the
data layout just needs to be updated for this test.
2023-10-12 20:34:31 +00:00
Jonas Hahnfeld
b9383a86b8
[JITLink] Some cleanups to EHFrameSupport (#66707)
* Remove unused variable.
 * Error on existing edge at CIE pointer field.
 * Simplify CFI processing in `EHFrameEdgeFixer`: The code expects
`DWARFRecordSectionSplitter` to split each CFI record into its own
block, so remove loop over possibly multiple entries in one block.
2023-10-05 18:16:48 +02:00
kda
c7294486f3
Disable MSAN test: ELF_perf.s
This should be repaired.  Fixes build bots quickly.

Introduced:
https://reviews.llvm.org/D146169
2023-09-18 13:17:33 -07:00
Prem Chintalapudi
88e3358f33 [ORC][JITLink] Non-debuginfo JITLink perf jitdump support.
This patch ports PerfJITEventListener to a JITLink plugin, but adds unwind
record support and drops debuginfo support temporarily. Debuginfo can be
enabled in the future by providing a way to obtain a DWARFContext from a
LinkGraph.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D146169
2023-09-18 04:10:29 +00:00
Eymen Ünay
e575b7cb7a
[JITlink][AArch32] Implement ELF::R_ARM_MOVT_ABS and R_ARM_MOVW_ABS_NC (#66219)
Add support for static Arm relocations of R_ARM_MOVT_ABS and R_ARM_MOVW_ABS_NC
which are emitted by movt and movw instructions. The implementation contains
relocation fixup and its testing as well as its encode/decode functions for
reading and writing immediate values together with its unittests.
2023-09-14 17:50:53 -07:00
Kai Luo
1dae4dd0d8 [JITLink][PowerPC] Fix incorrect assertion of addend for R_PPC64_REL24
There is case that R_PPC64_REL24 with non-zero addend. The assertion is incorrectly triggered in such situation.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D158708
2023-09-14 02:40:45 +00:00
Eymen Ünay
62f793ec9c [JITLink][AArch32] Implement ELF::R_ARM_JUMP24 relocation
Added support and test for ELF::R_ARM_JUMP24

Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D157541
2023-09-13 17:16:29 +02:00
Eymen Ünay
142c89c381 [JITLink][AArch32] Implement ELF::R_ARM_CALL relocation
- Added WritableArmRelocation and ArmRelocation Structs
- Encode/Decode funcs for B/BL A1 and BLX A2 encodings
- Add ARM helper functions, consistent with the existing Thumb helper functions
- Add Test for ELF::R_ARM_CALL

Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D157533
2023-09-13 17:16:29 +02:00
Eymen Ünay
9c017a99d5 [jitlink][rtdyld][checker] Re-apply 4b17c81d5a5 with fixes.
This re-applies 4b17c81d5a5, "[jitlink/rtdydl][checker] Add TargetFlag
dependent disassembler switching support", which was reverted in
4871a9ca546 due to bot failures.

The patch has been updated to add missing plumbing for Subtarget Features and
a CPU string, which should fix the failing tests.

https://reviews.llvm.org/D158280
2023-09-09 13:10:38 -07:00
bzEq
0eeca5739a
[JITLink][PowerPC] Port rtdyld's tests to jitlink. NFC. (#65739) 2023-09-09 05:52:58 +08:00