299 Commits

Author SHA1 Message Date
Connie
9ddfe62f5c
[LLVM][test][nfc] Updating test to work with internal shell (#98370)
The RUN line attempts to set the JITDUMPDIR environment variable, which
fails in llvm-lit's internal shell. This patch prefixes JITDUMPDIR with
env so that the behavior of setting the variable is as expected in the
internal shell.
2024-07-11 09:34:24 -07:00
Eymen Ünay
9efa63359e [JITLink][AArch32] Fix buildbot failure by restricting test to assert build
The expressive test added in PR #97030 requires debug option in cli.
2024-06-29 18:59:47 +03:00
Eymen Ünay
cd0f89109b
[JITLink][AArch32] Fix Unaligned Data Symbol Address Resolution (#97030)
The ARM architecture uses the LSB bit for ARM/Thumb mode switch
flagging. This is true for alignments of 2 and 4 but in data
relocations the alignment is 1 allowing the LSB bit to be set.
Now only `ELF::STT_FUNC` typed symbols are used in the 
TargetFlag mechanism.

The test is a minimal example of the issue mentioned below.

Fixes #95911 "Orc global constructor order test fails on 32
bit ARM".
2024-06-29 18:27:06 +03:00
Maksim Panchenko
ae6f730b2f
[JITLink] Add x86_64::Delta8 edge kind, ELF::R_X86_64_PC8 support (#95869)
Add support for ELF::R_X86_64_PC8 relocation via new x86_64::Delta8 edge
kind.
2024-06-18 09:31:52 -07:00
Eymen Ünay
f29352b63b
[RuntimeDyldChecker][AArch32] Add a PC offset to next_PC for ARM targets (#91746)
In ARM mode, the Program Counter (PC) points to the current instruction's
address + 8 instead of + 4. An offset is added to RuntimeDyldChecker to
use `next_pc` expression in JITLink tests with both Thumb and Arm.
2024-05-28 14:53:37 +03:00
Pavel Samolysov
d395b56a52
[JITLink][AArch64] Implement R_AARCH64_LDR_PREL_LO19 (#82172)
This relocation is used for the 32-bit aligned 21-bit immediate in LDR
Literal instructions.
2024-05-17 07:46:43 +03:00
Fangrui Song
bf67610a8a [MC] Rename temporary symbols of empty name to ".L0 " (#89693)
Temporary symbols generated for .eh_frame and .debug_line have an empty
name, which appear in .symtab in the presence of RISC-V style linker
relaxation and will not be discarded by ld/objcopy --discard-locals
(-X).

In contrast, GNU assembler's riscv port assigns a fake name ".L0 " (with
a trailing space) to these symbols so that will be discarded by
ld/objcopy --discard-locals.

This patch matches the GNU behavior. Since Clang's RISC-V targets pass
-X to ld, and GNU ld defaults to -X for RISC-V targets, these ".L0 "
symbols will be discarded after linking by default, as expected by
users.

The llvm-symbolizer special case for RISC-V `SF_FormatSpecific` symbols
https://reviews.llvm.org/D98669 needs to be adjusted.

Note: `"":` in assembly currently crashes.

Note: bolt tests used /usr/bin/clang before
llvmorg-19-init-9532-g59bfc3106874.
The revert llvmorg-19-init-9531-g28b55342e1a8 actually broke
bolt/test/RISCV/fake-label-no-entry.c
2024-04-26 08:30:27 -07:00
Amir Ayupov
28b55342e1 Revert "[MC] Rename temporary symbols of empty name to ".L0 " (#89693)"
This reverts commit 96c45a7fa12619c3abd6b81effe4c80f0916b78b.

Broke BOLT builders and all pre-merge testing:
https://lab.llvm.org/buildbot/#/builders/244/builds/28097
2024-04-25 20:05:29 -07:00
Fangrui Song
b9f2c16b50 [MC] Rename temporary symbols of empty name to ".L0 " (#89693)
Temporary symbols generated for .eh_frame and .debug_line have an empty
name, which appear in .symtab in the presence of RISC-V style linker
relaxation and will not be discarded by ld/objcopy --discard-locals
(-X).

In contrast, GNU assembler's riscv port assigns a fake name ".L0 " (with
a trailing space) to these symbols so that will be discarded by
ld/objcopy --discard-locals.

This patch matches the GNU behavior. Since Clang's RISC-V targets pass
-X to ld, and GNU ld defaults to -X for RISC-V targets, these ".L0 "
symbols will be discarded after linking by default, as expected by
users.

The llvm-symbolizer special case for RISC-V `SF_FormatSpecific` symbols
https://reviews.llvm.org/D98669 needs to be adjusted.

Note: `"":` in assembly currently crashes.
2024-04-24 16:25:45 -07:00
Mehdi Amini
9961311216
Revert "[MC] Rename temporary symbols of empty name to ".L0 "" (#90002)
Reverts llvm/llvm-project#89693

This broke the premerge bot (bolt tests failing)
2024-04-25 01:00:31 +02:00
Fangrui Song
96c45a7fa1
[MC] Rename temporary symbols of empty name to ".L0 " (#89693)
Temporary symbols generated for .eh_frame and .debug_line have an empty
name, which appear in .symtab in the presence of RISC-V style linker
relaxation and will not be discarded by ld/objcopy --discard-locals
(-X).

In contrast, GNU assembler's riscv port assigns a fake name ".L0 " (with
a trailing space) to these symbols so that will be discarded by
ld/objcopy --discard-locals.

This patch matches the GNU behavior. Since Clang's RISC-V targets pass
-X to ld, and GNU ld defaults to -X for RISC-V targets, these ".L0 "
symbols will be discarded after linking by default, as expected by
users.

The llvm-symbolizer special case for RISC-V `SF_FormatSpecific` symbols
https://reviews.llvm.org/D98669 needs to be adjusted.

Note: `"":` in assembly currently crashes.
2024-04-24 13:16:02 -07:00
Wu Yingcong
9cb755cf5b
[Test][JITLink] Save rbx in ExecutionEngine/JITLink/x86-64/ELF_vtune.s (#86472)
The callee should preserve rbx according to the calling convention, but
it is not in the test case `ExecutionEngine/JITLink/x86-64/ELF_vtune.s`.
Not preserving the rbx register may result in some random error to the
caller function. This patch adds the missing command to preserve the
rbx.
2024-04-15 17:37:35 -06:00
Lang Hames
c4d5881550 [JITLink][MachO] Handle MachO section start/end symbols.
Transform section$start$<section-name> and section$end$<section-name> external
symbols into defined symbols when a section named <section-name> is present.

rdar://125357048

Coding my way home: 8.98112N, 79.52094W
2024-03-25 11:40:52 -05:00
Lang Hames
488a18738f [JITLink][ELF] Improve ELF section start/end symbol handling.
This commit adds section start and stop symbol handling to ELF/aarch64, and
fixes the section symbol prefixes (using `__start_` and `__stop_`, rather than
`__start` and `__end`). It also adds a testcase for handling of these symbols.
2024-03-24 14:54:15 -05:00
Hongyu Chen
00f412168c
[ORC][JITLink] Add Intel VTune support to JITLink (#83957)
[ORC] Re-land https://github.com/llvm/llvm-project/pull/81826

This patch adds two plugins: VTuneSupportPlugin.cpp and
JITLoaderVTune.cpp. The testing is done in a manner similar to
llvm-jitlistener. Currently, we only support the old version of Intel
VTune API.
2024-03-07 11:15:16 -08:00
Fangrui Song
a331937197 [MC] Move CompressDebugSections/RelaxELFRelocations from TargetOptions/MCAsmInfo to MCTargetOptions
The convention is for such MC-specific options to reside in
MCTargetOptions. However, CompressDebugSections/RelaxELFRelocations do
not follow the convention: `CompressDebugSections` is defined in both
TargetOptions and MCAsmInfo and there is forwarding complexity.

Move the option to MCTargetOptions and hereby simplify the code. Rename
the misleading RelaxELFRelocations to X86RelaxRelocations. llvm-mc
-relax-relocations and llc -x86-relax-relocations can now be unified.
2024-03-06 23:19:59 -08:00
Jordan Rupprecht
1a67dee089 Revert "[ORC][JITLink] Add Intel VTune support to JITLink (#81826)"
This reverts commit 17efdad2296a2757813e4f11d0575ee6fb826e39. It introduces a layering violation: https://github.com/llvm/llvm-project/pull/81826#issuecomment-1977455140
2024-03-04 17:50:44 -08:00
Hongyu Chen
17efdad229
[ORC][JITLink] Add Intel VTune support to JITLink (#81826)
This patch adds two plugins: VTuneSupportPlugin.cpp and
JITLoaderVTune.cpp. The testing is done in a manner similar to
llvm-jitlistener. Currently, we only support the old version of Intel
VTune API.

This pull request is stacked on top of
https://github.com/llvm/llvm-project/pull/81825
2024-03-04 08:52:45 -08:00
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
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
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
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
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
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