This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 509
Allow creating static or shared native library #4718
Merged
Merged
Changes from 28 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
b7a5b0f
add bootstrapper for native libraries (#1285)
tonerdo e0752ec
overwrite main method when building library (#1285)
tonerdo a915ad9
update buildscripts to build shared library for non-windows (#1285)
tonerdo 155a9ca
add stub for native library startup method (#1285)
tonerdo 65b2b25
initialize runtime at start of reverse PInvoke, unix dlopen successfu…
tonerdo 80d721b
don't run library initializers for Multi module build (#1285)
tonerdo 79d3322
update Windows buildscripts, LoadLibrary successful (#1285)
tonerdo 27ef3aa
tidy up native binary extension conditions (#1285)
tonerdo f5f71f4
update buildscript to build unix static library (#1285)
tonerdo 0435d64
update buildscript to build Windows static library (#1285)
tonerdo c13edf6
fix rebase related error (#1285)
tonerdo c82a602
create and use NativeLibraryInitializerRootProvider (#1285)
tonerdo 3ba221b
use "shared" linker arg on unix to build shared library (#1285)
tonerdo 9ae9eb7
use system module to initialize NativeLibraryInitializerRootProvider …
tonerdo 55495ee
move NativeLibraryStartupMethod ClassCode and CompareToImpl to separa…
tonerdo 8b3f216
revert redundant changes to LibraryRootProvider (#1285)
tonerdo a915c73
revert redundant changes to Windows build script (#1285)
tonerdo bd42322
move call to InitializeRuntime to RhpReversePInvokeAttachOrTrapThread…
tonerdo 6738e30
initialize runtime just before initializing the thread (#1285)
tonerdo 6575a65
move InitializeRuntime call to within TSF_Attached state check (#1285)
tonerdo 9d7df3d
use pointer to reference InitializeRuntime method (#1285)
tonerdo 641ebd8
use Dllmain to set InitializeRuntime function pointer on Windows (#1285)
tonerdo 079a369
use static struct constructor to set InitializeRuntime pointer (#1285)
tonerdo fd7b073
update method signature of native library startup method (#1285)
tonerdo 0558e82
do not include main function in native library build (#1285)
tonerdo 32da10e
move runtime initialization check to thread init (#1285)
tonerdo 4a91edf
use Thread* to determine whether to initialize runtime (#1285)
tonerdo 0c3b863
update code to match overall style of the CoreRT runtime (#1285)
tonerdo 474dd62
update code style (#1285)
tonerdo 426693e
handle race conditions when initializing runtime (#1285)
tonerdo 928f04d
fix Windows build (#1285)
tonerdo 727bcd1
some code improvements (#1285)
tonerdo 7a2d8a0
explicitly use spaces (#1285)
tonerdo 2c3b68c
remove unneeded usings (#1285)
tonerdo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/ILCompiler.Compiler/src/Compiler/NativeLibraryInitializerRootProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
|
||
using Internal.TypeSystem.Ecma; | ||
using Internal.TypeSystem; | ||
using Internal.IL.Stubs.StartupCode; | ||
|
||
namespace ILCompiler | ||
{ | ||
/// <summary> | ||
/// Provides compilation group for a native library that compiles the initialize method. | ||
/// </summary> | ||
public class NativeLibraryInitializerRootProvider : ICompilationRootProvider | ||
{ | ||
/// <summary> | ||
/// Symbolic name under which the managed initializer is exported. | ||
/// </summary> | ||
public const string ManagedEntryPointMethodName = "__managed__Startup"; | ||
|
||
private EcmaModule _module; | ||
private IList<MethodDesc> _libraryInitializers; | ||
|
||
public NativeLibraryInitializerRootProvider(EcmaModule module, IList<MethodDesc> libraryInitializers) | ||
{ | ||
_module = module; | ||
_libraryInitializers = libraryInitializers; | ||
} | ||
|
||
public void AddCompilationRoots(IRootingServiceProvider rootProvider) | ||
{ | ||
TypeDesc owningType = _module.GetGlobalModuleType(); | ||
NativeLibraryStartupMethod nativeLibStartupCode = new NativeLibraryStartupMethod(owningType, _libraryInitializers); | ||
rootProvider.AddCompilationRoot(nativeLibStartupCode, "Startup Code Main Method", ManagedEntryPointMethodName); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/ILCompiler.Compiler/src/IL/Stubs/StartupCode/NativeLibraryStartupMethod.Sorting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Internal.TypeSystem; | ||
|
||
using AssemblyName = System.Reflection.AssemblyName; | ||
using Debug = System.Diagnostics.Debug; | ||
|
||
namespace Internal.IL.Stubs.StartupCode | ||
{ | ||
partial class NativeLibraryStartupMethod | ||
{ | ||
protected override int ClassCode => -304225482; | ||
|
||
protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer) | ||
{ | ||
// Should be a singleton | ||
Debug.Assert(this == other); | ||
return 0; | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/ILCompiler.Compiler/src/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Internal.TypeSystem; | ||
|
||
using AssemblyName = System.Reflection.AssemblyName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: unneeded using |
||
using Debug = System.Diagnostics.Debug; | ||
|
||
namespace Internal.IL.Stubs.StartupCode | ||
{ | ||
/// <summary> | ||
/// Startup code that does initialization, Main invocation | ||
/// and shutdown of the runtime. | ||
/// </summary> | ||
public sealed partial class NativeLibraryStartupMethod : ILStubMethod | ||
{ | ||
private TypeDesc _owningType; | ||
private MethodSignature _signature; | ||
private IList<MethodDesc> _libraryInitializers; | ||
|
||
public NativeLibraryStartupMethod(TypeDesc owningType, IList<MethodDesc> libraryInitializers) | ||
{ | ||
_owningType = owningType; | ||
_libraryInitializers = libraryInitializers; | ||
} | ||
|
||
public override TypeSystemContext Context | ||
{ | ||
get | ||
{ | ||
return _owningType.Context; | ||
} | ||
} | ||
|
||
public override TypeDesc OwningType | ||
{ | ||
get | ||
{ | ||
return _owningType; | ||
} | ||
} | ||
|
||
public override string Name | ||
{ | ||
get | ||
{ | ||
return "NativeLibraryStartup"; | ||
} | ||
} | ||
|
||
public override MethodIL EmitIL() | ||
{ | ||
ILEmitter emitter = new ILEmitter(); | ||
ILCodeStream codeStream = emitter.NewCodeStream(); | ||
|
||
// Allow the class library to run explicitly ordered class constructors first thing in start-up. | ||
if (_libraryInitializers != null) | ||
{ | ||
foreach (MethodDesc method in _libraryInitializers) | ||
{ | ||
codeStream.Emit(ILOpcode.call, emitter.NewToken(method)); | ||
} | ||
} | ||
|
||
codeStream.Emit(ILOpcode.ret); | ||
return emitter.Link(this); | ||
} | ||
|
||
public override MethodSignature Signature | ||
{ | ||
get | ||
{ | ||
if (_signature == null) | ||
{ | ||
_signature = new MethodSignature(MethodSignatureFlags.Static, 0, | ||
Context.GetWellKnownType(WellKnownType.Void), | ||
new TypeDesc[0]); | ||
} | ||
|
||
return _signature; | ||
} | ||
} | ||
|
||
public override bool IsNativeCallable | ||
{ | ||
get | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ if(NOT CLR_CMAKE_PLATFORM_WASM) | |
endif(NOT CLR_CMAKE_PLATFORM_WASM) | ||
|
||
add_subdirectory(cpp) | ||
add_subdirectory(dll) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
project(bootstrapperdll) | ||
|
||
add_definitions(-DCORERT_DLL) | ||
|
||
set(SOURCES | ||
../main.cpp | ||
../common.cpp | ||
) | ||
|
||
add_library(bootstrapperdll STATIC ${SOURCES}) | ||
|
||
# Install the static bootstrapperdll library | ||
install (TARGETS bootstrapperdll DESTINATION sdk) | ||
if(WIN32) | ||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bootstrapperdll.dir/$<CONFIG>/bootstrapperdll.pdb DESTINATION sdk) | ||
endif() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: unneeded using