Commit Graph

24 Commits

Author SHA1 Message Date
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 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 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
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
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 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 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
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 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 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
Sunho Kim 0f00e58841 [JITLink][COFF][x86_64] Reimplement ADDR32NB/REL32.
Reimplements ADDR32NB/REL32 relocations properly, out-of-reach targets will be dealt in the separate patch that will generate the stub for dllimport symbols.

Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D129936
2022-07-25 23:41:53 +09:00
Sunho Kim aef75aec38 [JITLink][COFF] Implement IMAGE_SYM_CLASS_LABEL.
AcceptedPublic
Implements IMAGE_SYM_CLASS_LABEL. It's simply a section + offset. This is not used a lot by llvm mc but very commonly used by MSVC compiler.

Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D129754
2022-07-25 23:22:59 +09:00
Sunho Kim 07aa8fc8db [JITLink][COFF] Handle out-of-order COMDAT second symbol.
Handle out-of-order COMDAT second symbols. In llvm codegen, the second symbol of COMDAT sequence always follows the first symbol in the global symbol list. But, when the object file came from MSVC compiler, these can come in out of order.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D129721
2022-07-25 23:02:31 +09:00
Sunho Kim b4878493dc [JITLink][COFF] Don't dead strip COMDAT associative symbol.
This prevents the dead strip of associative comdat section when parent section is alive.

Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D129720
2022-07-25 22:59:19 +09:00
Kazu Hirata 8dfdb80f72 Ensure newlines at the end of files (NFC) 2022-07-17 15:37:45 -07:00
Sunho Kim 18a6ab5b8d [JITLink] Silence unused variable warning. (NFC) 2022-07-14 20:14:22 +09:00
sunho e5ff1a7f56 [JITLink][COFF] Fix compiler warnings. 2022-07-13 04:29:05 +09:00
Sunho Kim db995d72db [JITLink][COFF] Initial COFF support.
Adds initial COFF support in JITLink. This is able to run a hello world c program in x86 windows successfully.

Implemented
- COFF object loader
- Static local symbols
- Absolute symbols
- External symbols
- Weak external symbols
- Common symbols
- COFF jitlink-check support
- All COMDAT selection type execpt largest
- Implicit symobl size calculation
- Rel32 relocation with PLT stub.
- IMAGE_REL_AMD64_ADDR32NB relocation

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D128968
2022-07-13 03:52:43 +09:00