Commit Graph

293 Commits

Author SHA1 Message Date
Sunho Kim 3d8061a3be [JITLink][ELF][AArch64] Implement R_AARCH64_MOVW_UABS_G*_NC.
Implements  R_AARCH64_MOVW_UABS_G*_NC fixup edges. These relocation entries can be generated when code is compiled without a PIC flag. With this patch, clang-repl can printf Hello World with ObjectLinkerLayer on aarch64 linux.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127585
2022-06-14 14:06:59 +09:00
Sunho Kim 398df667d6 [JITLink][AArch64] Implement MoveWide16 generic edge.
Implements MoveWide16 generic edge kind that can be used to patch MOVZ/MOVK (imm16) instructions.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127584
2022-06-14 13:51:47 +09:00
Sunho Kim 6cc3450a52 [JITLink][AArch64] Lift fixup functions from aarch64.cpp to aarch64.h. (NFC)
Lift fixup functions from aarch64.cpp to aarch64.h so that they have better chance of getting inlined. Also, adds some comments documenting the purpose of functions.

Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D127559
2022-06-14 13:34:00 +09:00
Sunho Kim db37225803 [JITLink][AArch64] Unify table managers of ELF and MachO.
Unifies GOT/PLT table managers of ELF and MachO on aarch64 architecture. Additionally, it migrates table managers from PerGraphGOTAndPLTStubsBuilder to generic crtp TableManager.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127558
2022-06-14 13:16:03 +09:00
Lang Hames 803c770ee0 [C-API][ORC] Add LLVMOrcExecutionSessionLookup -- generic async symbol lookup.
An API to wrap ExecutionSession::lookup, this allows C API clients to use async
lookup.

The immediate motivation for adding this is to simplify upcoming
definition-generator unit tests.

As we're adding more tests that need to convert between C and C++ flag values
this commit adds helper functions to support this. This patch also updates the
CAPIDefinitionGenerator to use these new utilities.
2022-06-13 16:37:35 -07:00
Sunho Kim f8a9536c55 [JITLink][ELF][AArch64] Implement eh frame handling.
Implements eh frame handling by using generic EHFrame passes. The c++ exception handling works correctly with this change.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127063
2022-06-11 04:06:14 +09:00
Sunho Kim 6d67f7a329 [JITLink][EHFrameSupport] Remove CodeAlignmentFactor and DataAlignmentFactor validation.
Removes CodeAlignmentFactor and DataAlignmentFactor validation in EHFrameEdgeFixer. I observed some of aarch64 elf files generated by clang contains CIE record with code_alignment_factor = 4 or data_alignment_factor = -8. code_alignment_factor and  data_alignment_factor are used by call fram instruction that should be correctled handled by libunwind.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127062
2022-06-10 15:29:20 +09:00
Sunho Kim 87c4268329 [JITLink][ELF][AArch64] Implement Procedure Linkage Table.
Implements Procedure Linkage Table (PLT) for ELF/AARCH64. The aarch64 linux calling convention also uses r16 as the intra-procedure-call scratch register same as MachO/ARM64. We can use the same stub sequence for this reason.

Also, BR regiseter doesn't touch X30 register. External function call by BL instruction (touched by CALL26 relocation) will set X30 to the original PC + 4, which is the intended behavior. External function call by B instruction (touched by JUMP26 relocation) doesn't requite to set X30, so the patch will be correct in this case too.

Reference: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#611general-purpose-registers

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127061
2022-06-10 14:44:33 +09:00
Sunho Kim 175f22d6c3 [JITLink][ELF][AArch64] Implement R_AARCH64_JUMP26
Implements R_AARCH64_JUMP26. We can use the same generic aarch64 Branch26 edge since B instruction and BL nstruction have the same sized&offseted immediate field, and the relocation address calculation is the same.

Reference: ELF for the ARM ® 64-bit Architecture Tabel 4-10, ARM Architecture Reference Manual ® ARMv8, for ARMv8-A architecture profile C6.2.24, C6.2.31

Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D127059
2022-06-10 11:35:42 +09:00
Sunho Kim 51a41f23b6 [JITLink][AArch64] Fix overflow range of Page21 fixup edge.
Allowed range for Page21 relocation is -2^32 <= X < 2^32 in both ELF and MachO.

09c2b7c35a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h (L210) (MachO)

ELF for the ARM ® 64-bit Architecture (AArch64) Table 4-9 (ELF)

Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D126387
2022-06-10 10:30:19 +09:00
Sunho Kim 5d5183b198 [JITLink][ELF][AArch64] Implement R_AARCH64_PREL32 and R_AARCH64_PREL64.
This patch implements R_AARCH64_PREL64 and R_AARCH64_PREL32 relocations that is
used in eh frame pointers. The test case utlizes obj2yaml tool to create an
artifical eh frame that generates related relocation types.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127058
2022-06-08 12:14:05 -07:00
Sunho Kim 2094fad009 [JITLink][ELF][AArch64] Implement ADR_GOT_PAGE, LD64_GOT_LO12_NC.
This patch implements two most commonly used Global Offset Table relocations in
ELF/AARCH64: R_AARCH64_ADR_GOT_PAGE and R_AARCH64_LD64_GOT_LO12_NC. It
implements the GOT table manager by extending the existing
PerGraphGOTAndPLTStubsBuilder. A future patch will unify this with the MachO
implementation to produce a generic aarch64 got table manager.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127057
2022-06-07 18:20:37 -07:00
Lang Hames 1deaa9b8bd [JITLink][ELF][AArch64] Implement R_AARCH64_ABS64 relocation type.
Implement R_AARCH64_ABS64 relocation entry. This relocation type is generated
when creating a static function pointer to symbol.

Reviewed By: lhames, sgraenitz

Differential Revision: https://reviews.llvm.org/D126658
2022-06-07 17:56:10 -07:00
Sunho Kim ab472c9615 [JITLink][ELF][AArch64] Implement R_AARCH64_LDST*_ABS_LO12_NC relocation types.
Implement R_AARCH64_LDST*_ABS_LO12_NC relocaiton entries by reusing PageOffset21
generic relocation edge. The difference between MachO backend is that in ELF,
the shift value is explicitly given by relocation type. lld generates the
relocation type that matches with instruction bitwidth, so getting the shift
value implicitly from instruction bytes should be fine in typical use cases.
2022-06-07 17:32:09 -07:00
Sunho Kim 25a9fb12e0 [JITLink][ELF][AArch64] Implement ADR_PREL_PG_HI21, ADD_ABS_LO12_NC.
Implements R_AARCH64_ADR_PREL_PG_HI21 and R_AARCH64_ADD_ABS_LO12_NC fixup edges
using the generic aarch64 patch edges.

Reviewed By: lhames, sgraenitz

Differential Revision: https://reviews.llvm.org/D126287
2022-06-07 16:42:37 -07:00
Sunho Kim 9f29916169 [JITLink][AArch64] Refactor isLoadStoreImm12 check out of getPageOffset12Shift.
The separate isLoadStoreImm12 predicate will be used for validating ELF/aarch64
ldst relocation types.

Reviewed By: lhames, sgraenitz

Differential Revision: https://reviews.llvm.org/D126628
2022-06-07 13:18:12 -07:00
Sunho Kim b6553f592a [JITLink][ELF][AArch64] Lift MachO/arm64 edges into aarch64.h, reuse for ELF.
This patch moves the aarch64 fixup logic from the MachO/arm64 backend to
aarch64.h header so that it can be re-used in the ELF/aarch64 backend. This
significantly expands relocation support in the ELF/aarch64 backend.

Reviewed By: lhames, sgraenitz

Differential Revision: https://reviews.llvm.org/D126286
2022-06-07 12:01:43 -07:00
Lang Hames 42614062e2 [JITLink] Error instead of asserting on unrecognized edge kinds.
It's idiomatic to require that plugins (especially platform plugins) be
installed to handle special edge kinds. If the plugins are not installed and an
object is loaded that uses one of the special edge kinds then we want to error
out rather than asserting.
2022-04-16 18:52:27 -07:00
Lang Hames 0d11351bd7 [JITLink] Add missing moves from 43acef48d3. 2022-04-15 12:58:22 -07:00
Lang Hames 43acef48d3 [JITLink] Refactor and expand DWARF pointer encoding support.
Adds support for pointer encodings commonly used in large/static models,
including non-pcrel, sdata/udata8, indirect, and omit.

Also refactors pointer-encoding handling to consolidate error generation inside
common functions, rather than callees of those functions.
2022-04-15 12:51:46 -07:00
Lang Hames 9a62d9db2e [JITLink][MachO] Fix alignment bug in the c-string literal section graphifier.
This function had been assuming a 1-byte alignment, which isn't always correct.
This commit updates it to take the alignment from the __cstring section.

The key change is to the createContentBlock call, but the surrounding code is
updated with clearer debugging output to support the testcase (and any future
debugging work).
2022-04-05 17:38:54 -07:00
Lang Hames 01bc5b7034 [JITLink] Fix sorting bug for PC-begin candidate symbols during EH-frame fixup.
The sort should have been lexicographic, but wasn't. This resulted in us
choosing a common symbol at address zero over the intended target function,
leading to a crash.

This patch also moves sorting up to the start of the pass, which means that we
only need to hold on to the canonical symbol at each address rather than a list
of candidates.
2022-04-05 13:02:28 -07:00
Shubham Sandeep Rastogi d46409fc8e Move DWARFRecordSectionSplitter code to its own file
With 229d576b31 the class EHFrameSplitter was renamed to DWARFRecordSectionSplitter. This change merely moves it to it's own .cpp/.h file

Differential Revision: https://reviews.llvm.org/D121721
2022-03-15 11:38:25 -07:00
Simon Pilgrim 1df20fa8f5 [JITLink] Fix -Wparentheses warning in R_RISCV_SUB6 case.
Perform the mask inside parentheses before applying the offset
2022-03-15 14:13:28 +00:00
Shubham Sandeep Rastogi 229d576b31 Rename EHFrameSplitter to DWARFRecordSectionSplitter
EHFrameSplitter does the exact same work to split up the eh_frame as it would need for any section that follows the DWARF record, therefore this patch just changes the name of it to DWARFRecordSectionSplitter to be more general.

Differential Revision: https://reviews.llvm.org/D121486
2022-03-11 16:02:31 -08:00
fourdim 16dc90cbe7 [JITLink][RISCV] Refactor range checking and alignment checking
This patch refactors the range checking function to make it compatible with all relocation types and supports range checking for R_RISCV_BRANCH. Moreover, it refactors the alignment check functions.

Reviewed By: StephenFan

Differential Revision: https://reviews.llvm.org/D117946
2022-03-09 22:13:57 +08:00
Lang Hames 36f0dfd07a [ORC][JITLink] Fix MachO absolute symbol handling, add test case.
This patch removes the unintended resolution of locally scoped absolute symbols
(which was causing unexpected definition errors).

It stops using the JITSymbolFlags::Absolute flag (it isn't set or used elsewhere,
and causes mismatch-flags asserts), and adds JITSymbolFlags::Exported to default
scoped absolute symbols.

Finally, we now set the scope of absolute symbols correctly in
MachOLinkGraphBuilder.
2022-03-07 20:54:55 -08:00
luxufan 3362f54d08 [JITLink] Add R_RISCV_SUB6 relocation
Add R_RISCV_SUB6 relocation

Differential Revision: https://reviews.llvm.org/D120001
2022-03-01 01:45:03 +08:00
fourdim 1ece3eeeb7 [JITLink][RISCV] fix the extractBits behavior and add R_RISCV_JAL relocation.
This patch supports the R_RISCV_JAL relocation.
Moreover, it will fix the extractBits function's behavior as it extracts Size + 1 bits.
In the test ELF_jal.s:
Before:
```
Hi: 4294836480
extractBits(Hi, 12, 8): 480
```
After:
```
Hi: 4294836480
extractBits(Hi, 12, 8): 224
```

Reviewed By: StephenFan

Differential Revision: https://reviews.llvm.org/D117975
2022-02-18 14:07:28 +08:00
fourdim 051f7cdcd2 Revert "[JITLink][RISCV] fix the extractBits behavior and add R_RISCV_JAL relocation."
This reverts commit 3af7bbca4a.
2022-02-17 23:40:32 +08:00
fourdim 3af7bbca4a [JITLink][RISCV] fix the extractBits behavior and add R_RISCV_JAL relocation.
This patch supports the R_RISCV_JAL relocation.
Moreover, it will fix the extractBits function's behavior as it extracts Size + 1 bits.
In the test ELF_jal.s:
Before:
```
Hi: 4294836480
extractBits(Hi, 12, 8): 480
```
After:
```
Hi: 4294836480
extractBits(Hi, 12, 8): 224
```

Reviewed By: StephenFan

Differential Revision: https://reviews.llvm.org/D117975
2022-02-17 23:03:36 +08:00
luxufan 9920943ea2 [JITLink] Fix the incorrect relocation behavior for R_RISCV_BRANCH
In D116573, the relocation behavior of R_RISCV_BRANCH didn't consider that branch instruction like 'bge' has a branch target address which is given as a PC-relative offset, sign-extend and multiplied by 2.
Although the target address is a 12-bits number, acctually its range is [-4096, 4094].

This patch fix it.

Differential Revision: https://reviews.llvm.org/D118151
2022-02-07 14:34:19 +08:00
Kazu Hirata 3a3cb929ab [llvm] Use = default (NFC) 2022-02-06 22:18:35 -08:00
dongAxis df597bf000 [NFC][ORC][AArch64] use isInt<N> to replace fitsRangeSignedInt on aarch64
Summary:
This is the first path to support more relocation types on aarch64.
 The patch just uses the isInt<N> to replace fitsRangeSignedInt.

Test Plan:
check-all

Differential Revision: https://reviews.llvm.org/D118231
2022-01-26 23:26:31 +08:00
luxufan 0283b07746 reapply de87238295 "[JITLink] Add anonymous symbols in LinkGraph..."
with fixes

This reapply `de872382951572b70dfaefe8d77eb98d15586115`, which was
reverted in `fdb6578514dd3799ad23c8bbb7699577c0fb414d`

Add `# REQUIRES: asserts` in test file `anonymous_symbol.s` to disable
this test for non-debug build
2022-01-22 20:50:36 +08:00
fourdim f7d4cafe5a [JITLink][RISCV] Support R_RISCV_SET* and R_RISCV_32_PCREL relocations
This patch supports R_RISCV_SET* and R_RISCV_32_PCREL relocations in JITLink.

Reviewed By: StephenFan

Differential Revision: https://reviews.llvm.org/D117082
2022-01-22 03:34:51 +08:00
luxufan fdb6578514 Revert "[JITLink] Add anonymous symbols in LinkGraph for unnamed temporary symbols"
This reverts commit de87238295.

Buildbot check error
2022-01-22 17:26:54 +08:00
luxufan de87238295 [JITLink] Add anonymous symbols in LinkGraph for unnamed temporary symbols
In RISCV, temporary symbols will be used to generate dwarf, eh_frame sections..., and will be placed in object code's symbol table. However, LLVM does not use names on these temporary symbols. This patch add anonymous symbols in LinkGraph for these temporary symbols.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D116475
2022-01-22 16:47:39 +08:00
luxufan dc18c5fa97 [JITLink] Add RISCV label subtraction and addition relocations
This patch add RISCV label subtraction and addition relocations in JITLink

Differential Revision: https://reviews.llvm.org/D116794
2022-01-19 22:12:56 +08:00
Steven Wu 091e364866 [JITLink][ELF] Support duplicated section names from object file
ELF object files can contain duplicated sections (thus section symbols
as well), espeically when comdats/section groups are present. This patch
adds support for generating LinkGraph from object files that have
duplicated section names. This is the first step to properly model
comdats/section groups.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D114753
2022-01-18 08:38:28 -08:00
fourdim 0c6f762622 [jitlink] add R_RISCV_BRANCH to jitlink
This patch supported the R_RISCV_BRANCH relocation.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D116573
2022-01-15 03:36:58 +08:00
Lang Hames bfd0cbd4eb Reapply 253ce92844 "[JITLink][AArch64] Add support for splitting.." with fixes.
This reapplies 253ce92844, which was reverted in
66b2ed477f due to bot failures.

I have added the `-phony-externals` option added, which should fix the
unresolved symbol errors.
2022-01-14 10:00:20 +11:00
luxufan 0ef5aa69e7 [JITLink] Add fixup value range check
This patch makes jitlink to report an out of range error when the fixup value out of range

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D107328
2022-01-13 16:32:49 +08:00
Nico Weber 66b2ed477f Revert "[JITLink][AArch64] Add support for splitting eh-frames on AArch64."
This reverts commit 253ce92844.
Breaks tests on Windows, see
https://github.com/llvm/llvm-project/issues/52921#issuecomment-1011118896
2022-01-12 14:40:09 -05:00
Lang Hames 253ce92844 [JITLink][AArch64] Add support for splitting eh-frames on AArch64.
This is needed for DWARF eh-frame exception handling on AArch64.

https://github.com/llvm/llvm-project/issues/52921.

Original patch by David Nadlinger <code@klickverbot.at> (thanks David!),
testcase and comments added by me.
2022-01-12 20:42:36 +11:00
Lang Hames 1f3d4525d8 [JITLink][AArch64] Use R-X permissions for the GOT.
This consistent with ld64's treatment of the GOT, but the main aim here is a
short-term workaround for a bad interaction between stub code sequences and
memory layout: Stubs use LDRLiteral19 relocations to reference the GOT, but
BasicLayout currently puts RW- segments between R-- and R-X segments -- a large
RW- segment (or a large R-- for that matter) can cause the relocation to fail
with an out-of-range error.

Putting the GOT in R-X fixes this efficiently in practice. A more robust fix
will be to use a longer code sequence to materialize the GOT pointer and then
rewrite the stub to use a shorter sequence where possible.
2022-01-12 18:03:58 +11:00
Lang Hames 3fabda51a6 [JITLink] Use Section + Offset format for anon symbols in out-of-range errors.
The previous error message only provided the address of the anonymous symbol.
Knowing the containing section makes the error easier to diagnose at a glance.
2022-01-12 18:03:57 +11:00
Lang Hames 5ff916ab72 [ORC][JITLink] Add dependence on OrcShared to JITLink.
JITLink depends on OrcShared as of c0fdc74887. This should fix the build
failure at https://lab.llvm.org/buildbot#builders/61/builds/19796.
2022-01-10 19:25:46 +11:00
Lang Hames c0fdc74887 [ORC] Add helper functions for running finalize / dealloc actions.
runFinalizeActions takes an AllocActions vector and attempts to run its finalize
actions. If any finalize action fails then all paired dealloc actions up to the
failing pair are run, and the error(s) returned. If all finalize actions succeed
then a vector containing the dealloc actions is returned.

runDeallocActions takes a vector<WrapperFunctionCall> containing dealloc action
calls and runs them all, returning any error(s).

These helpers are intended to simplify the implementation of
JITLinkMemoryManager::InFlightAlloc::finalize and
JITLinkMemoryManager::deallocate overrides by taking care of execution (and
potential roll-back) of allocation actions.
2022-01-10 19:13:58 +11:00
Lang Hames 089acf2522 [ORC][JITLink] Merge JITLink AllocActionCall and ORC WrapperFunctionCall.
These types performed identical roles. Merging them simplifies interoperability
between JITLink and ORC APIs (allowing us to address a few FIXMEs).
2022-01-08 16:46:15 +11:00