Commit Graph

363 Commits

Author SHA1 Message Date
Kazu Hirata aadaaface2 [llvm] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02 21:11:44 -08:00
Kazu Hirata e80118eed6 [JITLink] Use std::optional in MachOLinkGraphBuilder.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-26 15:15:18 -08:00
luxufan f8979512ea [JITLink][RISCV] Add R_RISCV_LO12_S relocation support
Fixes: https://github.com/llvm/llvm-project/issues/58979

Reviewed By: Hahnfeld

Differential Revision: https://reviews.llvm.org/D138030
2022-11-16 19:50:18 +08:00
Stefan Gränitz f97d3ba269 [JITLink] Revert template typename change after 2a3b257a93 (NFC)
As pointed out in the review https://reviews.llvm.org/D135523#C3696894NL515
2022-11-01 10:20:29 +01:00
Lang Hames 5af9e648ae [JITLink][AArch46] Update aarch64 pointer jump stub sequence, add utilities.
Updates the aarch64 pointer jump stub sequence to:

ADRP x16, <ptr>@page21
LDR  x16, [x16, <ptr>@pageoff12]
BR   x16

from:

LDR  x16, <ptr>@ldrimm19
BR   x16

The old sequence can only reference pointers within +/-1Mb, which may not be
enough for large object files. The new sequence can reach pointers within
+/-4Gb. (A future pre-fixup-pass could apply range-based optimizations to
turn this into an ldr-br-nop sequence.)

Also adds createPointerJumpStubBlock and createAnonymousPointerJumpStub
utilities along the same lines as their x86-64 counterparts.

The PLTTableManager is updated to use the new utility functions.
2022-10-31 08:41:20 -07:00
Lang Hames cb33ef7ca7 [JITLink][AArch64] Update edge names to be more descriptive, add comments.
This brings the aarch64 edges into alignment with the naming scheme for the
x86-64 edges.

Edge behavior is mostly unchanged, but some irrelevant assertions and errors
have been removed.
2022-10-30 19:03:22 -07:00
Kshitij Jain 2a3b257a93 [JITLink][i386] Adds absolute and pc relative relocation support for ELF/i386.
This commit adds support for 32 bit absolute and pc relative relocations in
ELF/i386 objects, along with simple regression tests.

Reviewed By: sgraenitz, lhames

Differential Revision: https://reviews.llvm.org/D135523
2022-10-30 17:35:41 -07:00
Lang Hames 1f16107219 [JITLink][aarch64] Remove the unused PairedAddend aarch64 edge kind.
This is a vestige of the original MachO-specific edge set and was never used
as a generic aarch64 edge kind.
2022-10-30 16:07:27 -07:00
Lang Hames b4db2da420 [JITLink][AArch64] Remove unused Pointer64Anon edge kind.
Pointer64Anon was lifted out of the MachO backend and into aarch64.h when that
header was created, but Pointer64Anon is really a MachO-specific "normalized"
relocation value, rather than a generic Edge::Kind. Any uses can be safely
replaced with Pointer64.

(Side note: the role of MachOPointer64Anon is to aid MachO relocation parsing:
For MachOPointer64, the target symbol is specified by the r_symbolnum field in
the relocation. For MachOPointer64Anon the address of the anonymous target is
read from the fixup location.)
2022-10-30 11:21:08 -07:00
Jonas Hahnfeld c4dd260f92 [JITLink][RISCV] Add names for GOT/PLT relocations
It is confusing to see "Unrecognized edge kind" in debugging output
for supported relocations; this was probably an oversight in commit
89f546f6ba which added the support.

Differential Revision: https://reviews.llvm.org/D136985
2022-10-29 12:04:16 +02:00
Lang Hames b5d5813762 [JITLink][AArch64] Add a generic 'createAnonymousPointer' utility.
Adds a generic utility for creating anonymous aarch64 pointer blocks
(automatically adding an edge to initialize the pointer if given an
initial target).

Updates the aarch64 GOTTableManager to use the utility when building
GOT entries.
2022-10-25 11:46:06 -07:00
Lang Hames d3d9f7caf9 [ORC][JITLink] Move MemoryFlags.h (MemProt, AllocGroup,...) from JITLink to ORC.
Moving these types to OrcShared eliminates the need for the separate
WireProtectionFlags type.
2022-10-03 19:35:34 -07:00
Lang Hames 565f4eb8e6 [JITLink] Update external symbol scopes to reflect scopes of resolved defs.
This is a counterpart to ffe2dda29f, and does for scope what that commit did
for linkage.

Making the scope of external definitions visible to JITLink plugins will
allow us to distinguish hidden weak defs (which do not need to be tracked by
default) from default-scoped weak defs (which need to be updated to point at
a single chosen definition at runtime).
2022-09-29 20:32:46 -07:00
Lang Hames ffe2dda29f [ORC][JITLink] Retain Weak flags in JITDylib interfaces, propagate to LinkGraph.
Previously we stripped Weak flags from JITDylib symbol table entries once they
were resolved (there was no particularly good reason for this). Now we want to
retain them and query them when setting the Linkage on external symbols in
LinkGraphs during symbol resolution (this was the motivation for 75404e9ef8).
Making weak linkage of external definitions discoverable in the LinkGraph will
in turn allow future plugins to implement correct handling for them (by
recording locations that depend on exported weak definitions and pointing all
of these at one chosen definition at runtime).
2022-09-27 10:04:59 -07:00
Lang Hames 4ba1f04465 [JITLink] Remove overly-restrictive visibility check introduced in 75404e9ef8.
ELF undefined symbols can have non-default visibility.
2022-09-26 11:19:40 -07:00
Lang Hames 75404e9ef8 [JITLink] Introduce new weakly-referenced concept separate from linkage.
Introduces two new methods on Symbol: isWeaklyReferenced and
setWeaklyReferenced. These are now used to track/set whether an external symbol
is weakly referenced, rather than having the Symbol's linkage set to weak.

This change is a first step towards proper handling of weak defs used across
JITDylib boundaries: It frees up the Linkage field on external symbols so that
it can be used to represent the linkage of the definition that the symbol resolves
to. It is expected that Platform plugins will use this information to track
locations that need to be updated if the selected weak definition changes (e.g.
because JITDylibs were dlclosed and then dlopened again in a different order).
2022-09-25 20:34:45 -07:00
Kazu Hirata 9606608474 [llvm] Use x.empty() instead of llvm::empty(x) (NFC)
I'm planning to deprecate and eventually remove llvm::empty.

I thought about replacing llvm::empty(x) with std::empty(x), but it
turns out that all uses can be converted to x.empty().  That is, no
use requires the ability of std::empty to accept C arrays and
std::initializer_list.

Differential Revision: https://reviews.llvm.org/D133677
2022-09-12 13:34:35 -07:00
sunho bc24e6ab7c [JITLink][COFF] Use DLLImportDefinitionGenerator for creating PLT stubs.
Uses DLLImportDefinitionGenerator for creating PLT stubs. It removes previous approach for dllimport stub creation which can't deal with jump thunks.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D132524
2022-09-10 15:25:44 +09:00
Lang Hames 06c4634483 [JITLink] Sink ELFX86RelocationKind into implementation file (ELF_x86_64.cpp).
The ELF/x86-64 backend uses the generic x86_64 edges now, so the
ELFX86RelocationKind is just an implementation detail.
2022-09-01 13:36:49 -07:00
Kazu Hirata ce377df57e Ensure newlines at the end of files (NFC) 2022-08-20 21:18:23 -07:00
Lang Hames c2786683ca [JITLink][MachO] Add support for non-subsections-via-symbols objects.
This patch updates MachOLinkGraphBuilder to honor the MH_SUBSECTIONS_VIA_SYMBOLS
flag. Prior to this patch we assumed MH_SUBSECTIONS_VIA_SYMBOLS, but never
checked the flag.

If MH_SUBSECTIONS_VIA_SYMBOLS is set (the default for MachO output on modern
compilers) then MachOLinkGraphBuilder will break MachO section content into
jitlink::Blocks on symbol boundaries. (This is how JITLink has always handled
MachO sections previously).

If MH_SUBSECTIONS_VIA_SYMBOLS is not set then MachOLinkGraphBuilder will create
a single jitlink::Block for each MachO section.

Existing hand-written testcases that were _not_ using the
.subsections_via_symbols directive are updated to use it. A new testcase for
non-subsections-via-symbols behavior is included.
2022-08-17 15:55:42 -07:00
Kazu Hirata eca990702d [ExecutionEngine] Fix a warning
This patch fixes the warning:

  llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp:66:11: error: unused
  type alias 'Base' [-Werror,-Wunused-local-typedef]
2022-08-15 20:33:10 -07:00
Kshitij Jain 29fe204b4e Re-apply "[JITLink] Introduce ELF/i386 backend " with correct authorship.
I (lhames) accidentally pushed 5f300397c6 on
Kshitij Jain's behalf without updating the patch author first (my apologies
Kshitij!).

Re-applying with correct authorship.

https://reviews.llvm.org/D131347
2022-08-15 18:44:43 -07:00
Lang Hames 73600b7c8a Revert "[JITLink] Introduce ELF/i386 backend support for JITLink."
This reverts commit 5f300397c6.

No functional issues, I just failed to correctly set authorship on the patch.
2022-08-15 18:44:43 -07:00
Lang Hames 5f300397c6 [JITLink] Introduce ELF/i386 backend support for JITLink.
This initial ELF/i386 JITLink backend enables JIT-linking of minimal ELF i386
object files. No relocations are supported yet.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D131347
2022-08-15 18:35:51 -07:00
Lang Hames 8b9b45ce54 [JITLink] Fix some missing std::moves.
This should fix failures on some bots due to 1cf81274f4
(e.g. https://lab.llvm.org/buildbot#builders/196/builds/16684)
2022-08-14 11:42:26 -07:00
Lang Hames 1cf81274f4 [JITLink] Add eh-frame CFI inspector, fix crash on malformed FDEs.
Add a fix to check that FDE pc-begin targets are defined before calling
getBlock (which will crash if the target is not defined). FDE pc-begins
pointing at undefined symbols are expected to arise only in obscure
circumstances (malformed objects, or removal of targets by JITLink
passes), but we want to handle them gracefully. With this patch the
FDE will be retained, but without any keepalive edge to it. Unless
some pass takes action to mark it as live it will be dead-stripped.

To make it easier for passes to connect FDEs to their targets a new
EHFrameCFIBlockInspector utility is added. This allows clients to
quickly determine whether a CFI record is a CIE or an FDE (assuming
that it's valid), and retrieve any personality, pc-begin, cie, or
LSDA edges associated with it.
2022-08-14 10:49:26 -07:00
Sunho Kim 9381de0952 [JITLink][COFF][x86_64] Stub SECREL relocation to external symbol.
Stubs SECREL relocation to external symbol. In order to correctly deal with this, we want to requrest memory manager to keep track of address of first block of sepecific section and keep address to be only increased from that point. We also should give jitlink to get information about global section. The relocation is only used for debug and tls info which we don't support yet anyways, so just stubbing it for now.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D130451
2022-08-11 15:12:25 +09:00
Sunho Kim 5cf0082ae3 [JITLink][COFF][x86_64] Implement SECTION/SECREL relocation.
Implements SECTION/SECREL relocation. These are used by debug info (pdb) data.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D130275
2022-08-11 15:12:24 +09:00
Kazu Hirata e20d210eef [llvm] Qualify auto (NFC)
Identified with readability-qualified-auto.
2022-08-07 23:55:27 -07:00
Lang Hames 41c41fcbc0 Revert "[JITLink] Fix some C++17 related fixmes."
This reverts commit 6ea5bf436a.

6ea5bf436a made use of new c++17 rules regarding
order of evaluation (specifically: in function calls the expression naming the
function should be sequenced before the evalution of any operands) to simplify
some continuation-passing calls. Unfortunately this appears to break at least
one MSVC bot: https://lab.llvm.org/buildbot/#/builders/123/builds/12149 .

Includes an update to the comments to note that the workaround is now based on
MSVC limitations, not on LLVM adopting c++17.
2022-08-07 12:15:59 -07:00
Lang Hames 6ea5bf436a [JITLink] Fix some C++17 related fixmes. 2022-08-07 09:37:14 -07:00
Kazu Hirata 71638b8be7 [ExecutionEngine] Ensure newlines at the end of files (NFC) 2022-07-31 15:16:58 -07:00
Sunho Kim c559072e46 [JITLink][COFF] Remove unused variable. 2022-07-31 09:19:17 +09:00
Sunho Kim b501770aef [JITLink][COFF] Handle COMDAT symbol with offset.
Handles COMDAT symbol with an offset and refactor the code to only generated symbol if the second symbol was encountered. This happens very infrequently but happens in recursive_mutex implementation of MSVC STL library.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D130454
2022-07-31 09:09:48 +09:00
Sunho Kim d86f903b1d [JITLink][COFF][x86_64] Implement remaining IMAGE_REL_AMD64_REL32_*.
Implements remaining IMAGE_REL_AMD64_REL32_*. We only need IMAGE_REL_AMD64_REL32_4 for now but doing all remaining ones for completeness. (clang only uses IMAGE_REL_AMD64_REL32_1 and IMAGE_REL_AMD64_REL32)

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D130452
2022-07-31 09:03:28 +09:00
Sunho Kim e781451140 [JITLink] Relax zero-fill edge assertions.
Relax zero-fill edge assertions to only consider relocation edges. Keep-alive edges to zero-fill blocks can cause this assertion which is too strict.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D130450
2022-07-31 08:34:10 +09:00
Sunho Kim ee9cf336d6 [JITLink][COFF] Remove obsolete FIXMEs. (NFC) 2022-07-31 08:10:14 +09:00
Sunho Kim ea75c25833 [JITLInk][COFF] Remove unnecessary unique_ptr. (NFC) 2022-07-31 08:08:19 +09:00
Sunho Kim 067faddb55 [JITLink][COFF] Add explicit std::move.
Since ArgList is not copyable we need to make sure it's moved explicitly.
2022-07-31 08:01:00 +09:00
Sunho Kim 88181375a3 [JITLink][COFF] Implement include/alternatename linker directive.
Implements include/alternatename linker directive. Alternatename is used by static msvc runtime library. Alias symbol is technically incorrect (we have to search for external definition) but we don't have a way to represent this in jitlink/orc yet, this is solved in the following up patch.

Inlcude linker directive is used in ucrt to forcelly lookup the static initializer symbols so that they will be emitted. It's implemented as extenral symbols with live flag on that cause the lookup of these symbols.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D130276
2022-07-31 07:49:59 +09:00
Kazu Hirata 66b6cc3acd [ExecutionEngine] Ensure a newline at the end of a file (NFC) 2022-07-30 10:35:43 -07:00
Sunho Kim e590f945c6 Revert "[JITLink][COFF] Implement include/alternatename linker directive."
This reverts commit f1fcd06a2a.

Faliures reported in
https://lab.llvm.org/buildbot/#/builders/193/builds/16143 and http://lab.llvm.org/buildbot/#/builders/91/builds/13010
2022-07-29 17:03:19 +09:00
Sunho Kim f1fcd06a2a [JITLink][COFF] Implement include/alternatename linker directive.
Implements include/alternatename linker directive. Alternatename is used by static msvc runtime library. Alias symbol is technically incorrect (we have to search for external definition) but we don't have a way to represent this in jitlink/orc yet, this is solved in the following up patch.

Inlcude linker directive is used in ucrt to forcelly lookup the static initializer symbols so that they will be emitted. It's implemented as extenral symbols with live flag on that cause the lookup of these symbols.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D130276
2022-07-29 16:48:29 +09:00
Sunho Kim 049fd21b42 [JITLink][COFF][x86_64] Implement ADDR64 relocation.
Implements ADDR64 relocation using x86_64 edge kind.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D130178
2022-07-29 16:32:07 +09:00
Sunho Kim 410e0aa759 [JITLink][COFF] Implement dllimport stubs.
Implements dllimport stubs using GOT table manager. Benefit of using GOT table manager is that we can just reuse jitlink-check architecture.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D130175
2022-07-29 16:29:53 +09:00
Sunho Kim cd953e4ffc [JITLink][COFF] Don't dead strip seh frame of exported function.
Adds keep-alive edges to pdata section to prevent dead strip of block when its parent function is alive.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D129945
2022-07-26 13:04:12 +09:00
Sunho Kim df344e1f44 [JITLink][COFF] Implement IMAGE_COMDAT_SELECT_LARGEST partially.
Implement IMAGE_COMDAT_SELECT_LARGEST partially. It's going to fail if larger symbol appears but this hasn't happened at least in vcruntime library.

We probably would not implement this properly as it requires complicated runtime patching which is not of nature of JIT. However, we'd like to validate if larger section appears and report to the user in the near future.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D129941
2022-07-26 12:51:33 +09:00
Sunho Kim 736b6311e1 [JITLink][COFF] Implement IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY/LIBRARY.
Implement IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY/LIBRARY characteristics flag.

Since COFFObjectFile class will set undefined flag for symbols with no alias flag, ORC ObjectFileInterface will not pull in this symbol. So, we only need to make sure the scope is local. NOLIBRARY and LIBRARY are handled in the same way for now. (which is what lld does right now)

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D129939
2022-07-26 12:46:34 +09:00
Sunho Kim 71eff61be6 [JITLink][COFF] Handle duplicate external symbols.
Handles duplicate external symbols. This happens in few static libraries generaed from msvc toolchain.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D129937
2022-07-26 12:44:04 +09:00