Commit Graph

3188 Commits

Author SHA1 Message Date
Sunho Kim 9fc0aa45e3 [JITLink][ELF] Log enum name of unsupported relocation type.
Logs enum name of unsupported relocation type. This also changes elf/x86 to use common util function (getELFRelocationTypeName) inside llvm object module.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127715
2022-06-15 23:26:29 +09:00
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 14b7c108a2 [C-API][ORC] Add C API to suspend lookups during definition generation.
Slow definition generators may suspend lookups to temporarily release the
session lock, allowing unrelated lookups to proceed.

Using this functionality is discouraged: it is best to make definition
generation fast, rather than suspending the lookup. As a last resort where
this is not possible, suspension may be used.
2022-06-13 17:20:07 -07: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
Jez Ng d4bcb45db7 [MC][re-land] Omit DWARF unwind info if compact unwind is present where eligible
This reverts commit d941d59783.

Differential Revision: https://reviews.llvm.org/D122258
2022-06-12 17:24:19 -04:00
Jez Ng d941d59783 Revert "[MC] Omit DWARF unwind info if compact unwind is present where eligible"
This reverts commit ef501bf85d.
2022-06-12 10:47:08 -04:00
Jez Ng ef501bf85d [MC] Omit DWARF unwind info if compact unwind is present where eligible
Previously, omitting unnecessary DWARF unwinds was only done in two
cases:
* For Darwin + aarch64, if no DWARF unwind info is needed for all the
  functions in a TU, then the `__eh_frame` section would be omitted
  entirely. If any one function needed DWARF unwind, then MC would emit
  DWARF unwind entries for all the functions in the TU.
* For watchOS, MC would omit DWARF unwind on a per-function basis, as
  long as compact unwind was available for that function.

This diff makes it so that we omit DWARF unwind on a per-function basis
for Darwin + aarch64 as well. In addition, we introduce the flag
`--emit-dwarf-unwind=` which can toggle between `always`,
`no-compact-unwind` (only emit DWARF when CU cannot be emitted for a
given function), and the target platform `default`.  `no-compact-unwind`
is particularly useful for newer x86_64 platforms: we don't want to omit
DWARF unwind for x86_64 in general due to possible backwards compat
issues, but we should make it possible for people to opt into this
behavior if they are only targeting newer platforms.

**Motivation:** I'm working on adding support for `__eh_frame` to LLD,
but I'm concerned that we would suffer a perf hit. Processing compact
unwind is already expensive, and that's a simpler format than EH frames.
Given that MC currently produces one EH frame entry for every compact
unwind entry, I don't think processing them will be cheap. I tried to do
something clever on LLD's end to drop the unnecessary EH frames at parse
time, but this made the code significantly more complex. So I'm looking
at fixing this at the MC level instead.

**Addendum:** It turns out that there was a latent bug in the X86
backend when `OmitDwarfIfHaveCompactUnwind` is naively enabled, which is
not too surprising given that this combination has not been heretofore
used.

For functions that have unwind info that cannot be encoded with CU, MC
would end up dropping both the compact unwind entry (OK; existing
behavior) as well as the DWARF entries (not OK).  This diff fixes things
so that we emit the DWARF entry, as well as a CU entry with encoding
`UNWIND_X86_MODE_DWARF` -- this basically tells the unwinder to look for
the DWARF entry. I'm not 100% sure the `UNWIND_X86_MODE_DWARF` CU entry
is necessary, this was the simplest fix. ld64 seems to be able to handle
both the absence and presence of this CU entry. Ultimately ld64 (and
LLD) will synthesize `UNWIND_X86_MODE_DWARF` if it is absent, so there
is no impact to the final binary size.

Reviewed By: davide, lhames

Differential Revision: https://reviews.llvm.org/D122258
2022-06-12 10:03:56 -04: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
Peter S. Housel 2be5abb7e9 [ORC][ORC_RT] Handle ELF .init_array with non-default priority
ELF-based platforms currently support defining multiple static
initializer table sections with differing priorities, for example
.init_array.0 or .init_array.100; the default .init_array corresponds
to a priority of 65535. When building a shared library or executable,
the system linker normally sorts these sections and combines them into
a single .init_array section. This change adds the capability to
recognize ELF static initializers with priorities other than the
default, and to properly sort them by priority, to Orc and the Orc
runtime.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127056
2022-06-09 22:47:58 -07:00
Peter S. Housel 1aa71f8679 [ORC][ORC_RT] Integrate ORC platforms with LLJIT and lli
This change enables integrating orc::LLJIT with the ORCv2
platforms (MachOPlatform and ELFNixPlatform) and the compiler-rt orc
runtime. Changes include:

- Adding SPS wrapper functions for the orc runtime's dlfcn emulation
  functions, allowing initialization and deinitialization to be invoked
  by LLJIT.

- Changing the LLJIT code generation default to add UseInitArray so
  that .init_array constructors are generated for ELF platforms.

- Integrating the ORCv2 Platforms into lli, and adding a
  PlatformSupport implementation to the LLJIT instance used by lli which
  implements initialization and deinitialization by calling the new
  wrapper functions in the runtime.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D126492
2022-06-09 22:47:58 -07: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 e093e42107 [ORC][AArch64] Add initial support for aarch64 in ELFNixPlatform.
Adds the aarch64 support in ELFNixPlatform. These are few simple changes, but it allows us to use the orc runtime in ELF/AARCH64 backend. It succesfully run the static initializers of stdlibc++ iostream so that "cout << Hello world" testcase starts to work.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127060
2022-06-10 13:37:36 +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
Lang Hames 3fcd3669e3 [ORC] Add an output stream operator for SymbolStringPool.
Handy for checking string pool state, e.g. when debugging dangling-pool-entry
errors.
2022-06-08 16:49:51 -07: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
Kazu Hirata e0039b8d6a Use llvm::less_second (NFC) 2022-06-04 22:48:32 -07:00
Lang Hames 7be783ab9d [ORC] Check for errors when materializing absolute symbols.
This code previously used cantFail, but both steps (resolution and emission)
can fail if the resource tracker associated with the
AbsoluteSymbolsMaterializationUnit is removed. Checking these errors is
necessary for correct error propagation.
2022-05-21 14:11:53 -07:00
Lang Hames 55e8f721d4 [ORC] Allow FailedToMaterialize errors to outlive ExecutionSessions.
Idiomatic llvm::Error usage can result in a FailedToMaterialize error tearing
down an ExecutionSession instance. Since the FailedToMaterialize error holds
SymbolStringPtrs and JITDylib references this leads to crashes when accessing
or logging the error.

This patch modifies FailedToMaterialize to retain the SymbolStringPool and
JITDylibs involved in the failure so that we can safely report an error message
to the client, even if the error tears down the session.

The contract for JITDylibs allows the getName method to be used even after the
session has been torn down, but no other JITDylib fields should be accessed via
the FailedToMaterialize error if the ssesion has been torn down. Logging the
error is guaranteed to be safe in all cases.
2022-05-21 13:51:02 -07:00
Lang Hames f3428dafdc [ORC] Add a ~ExectionSession destructor to verify that endSession was called.
Clients are required to call ExecutionSession::endSession before destroying the
ExecutionSession. Failure to do so can lead to memory leaks and other difficult
to debug issues. Enforcing this requirement by assertion makes it easy to spot
or debug situations where the contract was not followed.
2022-05-21 09:02:01 -07:00
Lang Hames 441f691b37 [ORC] Remove usused Error variable.
This was left in by accident, and caused unchecked-error assertions
during program termination in BuildingAJIT-Ch4.
2022-05-20 19:33:07 -07:00
Lang Hames 2ca81cd914 [ORC] Avoid more SymbolStringPtr copies. 2022-05-19 10:51:20 -07:00
Lang Hames d27e4bcebd [ORC] Add a FIXME. 2022-05-19 10:51:20 -07:00
Lang Hames 4bb18a89c4 [ORC] Add missing std::moves, pass SymbolLookupSet by value.
Avoids some unnecessary SymbolStringPtr copies.
2022-05-19 10:51:20 -07:00
Jonas Hahnfeld e451d55234 [ORC] Fix sorting of contructors by priority
The code was incorrectly sorting by the function address.

Differential Revision: https://reviews.llvm.org/D123311
2022-05-11 09:06:41 +02:00
Peter S. Housel 981523b2e4 [ORC-RT][ORC] Handle dynamic unwind registration for libunwind
This changes the ELFNix platform Orc runtime to use, when available,
the __unw_add_dynamic_eh_frame_section interface provided by libunwind
for registering .eh_frame sections loaded by JITLink. When libunwind
is not being used for unwinding, the ELFNix platform detects this and
defaults to the __register_frame interface provided by libgcc_s.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D114961
2022-05-06 14:00:29 -07:00
Lang Hames 16dcbb53dc [ORC] Return ExecutorAddrs rather than JITEvaluatedSymbols from LLJIT::lookup.
Clients don't care about linkage, and ExecutorAddr is much more ergonomic.
2022-05-05 13:56:00 -07:00
Alexey Moksyakov 48e894a536 [BOLT] Add R_AARCH64_PREL16/32/64 relocations support
Reviewed By: yota9, rafauler

Differential Revision: https://reviews.llvm.org/D122294
2022-04-21 13:52:47 +03:00
Lang Hames 45e390cfee [ORC] Report paths in errors when creating StaticLibrarySearchGenerators. 2022-04-17 12:01:06 -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
Alex Fan acb408fbbc [ORC] add lazy jit support for riscv64
This adds resolver, indirection and trampoline stubs for riscv64,
allowing lazy compilation to work.

It assumes hard float extension exists. I don't know the proper way to detect it as Triple doesn't provide the interface to check riscv +f +d abi.

I am also not sure if orclazy tests should be enabled because lli needs an additional -codemodel=melany for tests to pass.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D122543
2022-04-10 18:44:50 +08:00
Lang Hames a76209c265 [ORC] Fix handling of casts in llvm.global_ctors.
Removes a bogus dyn_cast_or_null that was breaking cast-expression handling when
parsing llvm.global_ctors.

The intent of this code was to identify Functions nested within cast
expressions, but the offending dyn_cast_or_null was actually blocking that:
Since a function is not a cast expression, we would set FuncC to null and break
the loop without finding the Function. The cast was not necessary either:
Functions are already Constants, and we didn't need to do anything
ConstantExpr-specific with FuncC, so we could just drop the cast.

Thanks to Jonas Hahnfeld for tracking this down.

http://llvm.org/PR54797
2022-04-07 17:06:38 -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
Pavel Labath ec6d621050 Remove a top-level using-directive from EPCDebugObjectRegistrar.h
The directive pollutes the namespace of all files which include the
header.

Use alternate ways to reference the namespace constituents instead.
2022-03-28 15:14:20 +02: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