Imported Upstream version 5.10.0.69

Former-commit-id: fc39669a0b707dd3c063977486506b6793da2890
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-29 19:03:06 +00:00
parent d8f8abd549
commit e2950ec768
6283 changed files with 453847 additions and 91879 deletions

View File

@@ -9,5 +9,9 @@ add_compile_options(-Wno-unused-private-field)
add_compile_options(-Wno-tautological-undefined-compare)
endif()
add_subdirectory(base)
if(NOT CLR_CMAKE_PLATFORM_WASM)
add_subdirectory(base)
endif(NOT CLR_CMAKE_PLATFORM_WASM)
add_subdirectory(cpp)
add_subdirectory(dll)

View File

@@ -41,4 +41,17 @@ inline double __uint64_to_double(uint64_t v)
return val.d;
}
#endif // __CPP_CODE_GEN_H
struct ReversePInvokeFrame
{
void* m_savedPInvokeTransitionFrame;
void* m_savedThread;
};
struct PInvokeTransitionFrame
{
void* m_RIP;
void* m_pThread; // unused by stack crawler, this is so GetThread is only called once per method
// can be an invalid pointer in universal transition cases (which never need to call GetThread)
uint32_t m_Flags; // PInvokeTransitionFrameFlags
};
#endif

View File

@@ -8,7 +8,7 @@ set(SOURCES
add_library(bootstrapper STATIC ${SOURCES})
# Install the static bootstrapper library
install (TARGETS bootstrapper DESTINATION lib)
install (TARGETS bootstrapper DESTINATION sdk)
if(WIN32)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bootstrapper.dir/$<CONFIG>/bootstrapper.pdb DESTINATION lib)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bootstrapper.dir/$<CONFIG>/bootstrapper.pdb DESTINATION sdk)
endif()

View File

@@ -73,15 +73,16 @@ struct RawEEType
void* m_pIndirectionModule;
};
struct ReversePInvokeFrame
{
void* m_savedPInvokeTransitionFrame;
void* m_savedThread;
};
struct ReversePInvokeFrame;
void __reverse_pinvoke(ReversePInvokeFrame* pRevFrame);
void __reverse_pinvoke_return(ReversePInvokeFrame* pRevFrame);
struct PInvokeTransitionFrame;
void __pinvoke(PInvokeTransitionFrame* pFrame);
void __pinvoke_return(PInvokeTransitionFrame* pFrame);
typedef size_t UIntNative;
inline bool IS_ALIGNED(UIntNative val, UIntNative alignment)

View File

@@ -10,7 +10,11 @@ set(SOURCES
add_library(bootstrappercpp STATIC ${SOURCES})
# Install the static bootstrappercpp library
install (TARGETS bootstrappercpp DESTINATION lib)
install (TARGETS bootstrappercpp DESTINATION sdk)
if(WIN32)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bootstrappercpp.dir/$<CONFIG>/bootstrappercpp.pdb DESTINATION lib)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bootstrappercpp.dir/$<CONFIG>/bootstrappercpp.pdb DESTINATION sdk)
endif()
# Install the CppCodeGen support headers
install (FILES ../common.h DESTINATION inc)
install (FILES ../CppCodeGen.h DESTINATION inc)

View File

@@ -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()

View File

@@ -8,7 +8,7 @@
#include "gcenv.structs.h"
#include "gcenv.base.h"
#include <stdlib.h>
#include <stdlib.h>
#ifndef CPPCODEGEN
@@ -39,9 +39,18 @@ __declspec(allocate(".modules$Z")) void * __modules_z[] = { nullptr };
//
#pragma comment(linker, "/merge:.modules=.rdata")
//
// Unboxing stubs need to be merged, folded and sorted. They are delimited by two special sections (.unbox$A
// and .unbox$Z). All unboxing stubs are in .unbox$M sections.
//
#pragma comment(linker, "/merge:.unbox=.text")
extern "C" void __managedcode_a();
extern "C" void __managedcode_z();
extern "C" void __unbox_a();
extern "C" void __unbox_z();
#else // _MSC_VER
#if defined(__APPLE__)
@@ -50,6 +59,8 @@ extern void * __modules_a[] __asm("section$start$__DATA$__modules");
extern void * __modules_z[] __asm("section$end$__DATA$__modules");
extern char __managedcode_a __asm("section$start$__TEXT$__managedcode");
extern char __managedcode_z __asm("section$end$__TEXT$__managedcode");
extern char __unbox_a __asm("section$start$__TEXT$__unbox");
extern char __unbox_z __asm("section$end$__TEXT$__unbox");
#else // __APPLE__
@@ -63,17 +74,23 @@ extern "C" char __stop___managedcode;
static char& __managedcode_a = __start___managedcode;
static char& __managedcode_z = __stop___managedcode;
extern "C" char __start___unbox;
extern "C" char __stop___unbox;
static char& __unbox_a = __start___unbox;
static char& __unbox_z = __stop___unbox;
#endif // __APPLE__
#endif // _MSC_VER
#endif // !CPPCODEGEN
// Do not warn that extern C methods throw exceptions. This is temporary
// as long as we have unimplemented/throwing APIs in this file.
#pragma warning(disable:4297)
#ifdef CPPCODEGEN
#pragma warning(disable:4297)
extern "C" Object * RhNewObject(MethodTable * pMT);
extern "C" Object * RhNewArray(MethodTable * pMT, int32_t elements);
extern "C" void * RhTypeCast_IsInstanceOf(void * pObject, MethodTable * pMT);
@@ -135,6 +152,19 @@ void __reverse_pinvoke_return(ReversePInvokeFrame* pRevFrame)
RhpReversePInvokeReturn2(pRevFrame);
}
extern "C" void RhpPInvoke2(PInvokeTransitionFrame* pFrame);
extern "C" void RhpPInvokeReturn2(PInvokeTransitionFrame* pFrame);
void __pinvoke(PInvokeTransitionFrame* pFrame)
{
RhpPInvoke2(pFrame);
}
void __pinvoke_return(PInvokeTransitionFrame* pFrame)
{
RhpPInvokeReturn2(pFrame);
}
namespace System_Private_CoreLib { namespace System {
class Object {
@@ -209,15 +239,18 @@ extern "C" void RhpUniversalTransition_DebugStepTailCall()
{
throw "RhpUniversalTransition_DebugStepTailCall";
}
extern "C" void CCWAddRef()
{
throw "CCWAddRef";
}
void* RtRHeaderWrapper();
#endif // CPPCODEGEN
// This works around System.Private.Interop's references to Interop.Native.
// This won't be needed once we stop dragging in S.P.Interop for basic p/invoke support.
extern "C" void CCWAddRef()
{
throw "CCWAddRef";
}
extern "C" void __fail_fast()
{
// TODO: FailFast
@@ -226,35 +259,25 @@ extern "C" void __fail_fast()
exit(-1);
}
extern "C" bool REDHAWK_PALAPI PalInit();
#define DLL_PROCESS_ATTACH 1
extern "C" BOOL WINAPI RtuDllMain(HANDLE hPalInstance, DWORD dwReason, void* pvReserved);
extern "C" bool RhInitialize();
extern "C" void RhpEnableConservativeStackReporting();
extern "C" void RhpShutdown();
extern "C" int32_t RhpEnableConservativeStackReporting();
extern "C" void RhSetRuntimeInitializationCallback(int (*fPtr)());
#ifndef CPPCODEGEN
extern "C" bool RhpRegisterCoffModule(void * pModule,
void * pvStartRange, uint32_t cbRange,
extern "C" bool RhRegisterOSModule(void * pModule,
void * pvManagedCodeStartRange, uint32_t cbManagedCodeRange,
void * pvUnboxingStubsStartRange, uint32_t cbUnboxingStubsRange,
void ** pClasslibFunctions, uint32_t nClasslibFunctions);
extern "C" bool RhpRegisterUnixModule(void * pModule,
void * pvStartRange, uint32_t cbRange,
void ** pClasslibFunctions, uint32_t nClasslibFunctions);
#ifdef _WIN32
extern "C" void* WINAPI GetModuleHandleW(const wchar_t *);
#else
extern "C" void* WINAPI PalGetModuleHandleFromPointer(void* pointer);
#endif
extern "C" void* PalGetModuleHandleFromPointer(void* pointer);
extern "C" void GetRuntimeException();
extern "C" void FailFast();
extern "C" void AppendExceptionStackFrame();
extern "C" void GetSystemArrayEEType();
extern "C" void OnFirstChanceException();
typedef void(*pfn)();
@@ -265,59 +288,76 @@ static const pfn c_classlibFunctions[] = {
&AppendExceptionStackFrame,
nullptr, // &CheckStaticClassConstruction,
&GetSystemArrayEEType,
&OnFirstChanceException
};
#endif // !CPPCODEGEN
extern "C" void InitializeModules(void* osModule, void ** modules, int count, void ** pClasslibFunctions, int nClasslibFunctions);
#ifndef CORERT_DLL
#define CORERT_ENTRYPOINT __managed__Main
#if defined(_WIN32)
extern "C" int __managed__Main(int argc, wchar_t* argv[]);
int wmain(int argc, wchar_t* argv[])
#else
extern "C" int __managed__Main(int argc, char* argv[]);
int main(int argc, char* argv[])
#endif
{
if (!PalInit())
return -1;
#else
#define CORERT_ENTRYPOINT __managed__Startup
extern "C" void __managed__Startup();
#endif // !CORERT_DLL
if (!RtuDllMain(NULL, DLL_PROCESS_ATTACH, NULL))
static int InitializeRuntime()
{
if (!RhInitialize())
return -1;
#if defined(CPPCODEGEN)
if (!RhpEnableConservativeStackReporting())
return -1;
RhpEnableConservativeStackReporting();
#endif // CPPCODEGEN
#ifndef CPPCODEGEN
void *osModule;
void * osModule = PalGetModuleHandleFromPointer((void*)&CORERT_ENTRYPOINT);
#if defined(_WIN32)
osModule = GetModuleHandleW(NULL);
if (!RhpRegisterCoffModule(osModule,
#else // _WIN32
osModule = PalGetModuleHandleFromPointer((void*)&main);
if (!RhpRegisterUnixModule(osModule,
#endif // _WIN32
// TODO: pass struct with parameters instead of the large signature of RhRegisterOSModule
if (!RhRegisterOSModule(
osModule,
(void*)&__managedcode_a, (uint32_t)((char *)&__managedcode_z - (char*)&__managedcode_a),
(void*)&__unbox_a, (uint32_t)((char *)&__unbox_z - (char*)&__unbox_a),
(void **)&c_classlibFunctions, _countof(c_classlibFunctions)))
{
return -1;
}
#endif // !CPPCODEGEN
#ifdef CPPCODEGEN
ReversePInvokeFrame frame;
__reverse_pinvoke(&frame);
#endif
#ifndef CPPCODEGEN
InitializeModules(osModule, __modules_a, (int)((__modules_z - __modules_a)), (void **)&c_classlibFunctions, _countof(c_classlibFunctions));
#elif defined _WASM_
// WASMTODO: Figure out what to do here. This is a NativeCallable method in the runtime
// and we also would have to figure out what to pass for pModuleHeaders
#else // !CPPCODEGEN
InitializeModules(nullptr, (void**)RtRHeaderWrapper(), 2, nullptr, 0);
#endif // !CPPCODEGEN
#ifdef CORERT_DLL
// Run startup method immediately for a native library
__managed__Startup();
#endif // CORERT_DLL
return 0;
}
#ifndef CORERT_DLL
#if defined(_WIN32)
int __cdecl wmain(int argc, wchar_t* argv[])
#else
int main(int argc, char* argv[])
#endif
{
int initval = InitializeRuntime();
if (initval != 0)
return initval;
int retval;
#ifdef CPPCODEGEN
try
@@ -333,12 +373,18 @@ int main(int argc, char* argv[])
retval = -1;
}
#endif
#ifdef CPPCODEGEN
__reverse_pinvoke_return(&frame);
#endif
RhpShutdown();
return retval;
}
#endif // !CORERT_DLL
#ifdef CORERT_DLL
static struct InitializeRuntimePointerHelper
{
InitializeRuntimePointerHelper()
{
RhSetRuntimeInitializationCallback(&InitializeRuntime);
}
} initializeRuntimePointerHelper;
#endif // CORERT_DLL

View File

@@ -4,9 +4,14 @@ project(CoreRT)
# Include cmake functions
include(functions.cmake)
string(FIND ${CMAKE_GENERATOR} "Visual Studio 15 2017" VS2017_POS)
if(VS2017_POS EQUAL 0 AND (CMAKE_VERSION VERSION_LESS 3.6.0))
message(FATAL_ERROR "CMake version 3.6.0 or higher is required to compile targeting VS 2017")
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
# CMake version 3.8.0 or higher is required to compile targeting VS 2017
cmake_minimum_required(VERSION 3.8.0)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
# CMake version 3.4.0 or higher has bug fixes required to compile targeting Darwin
cmake_minimum_required(VERSION 3.4.0)
endif()
set(CMAKE_MACOSX_RPATH ON)
@@ -19,73 +24,64 @@ endif()
set(CMAKE_SHARED_LIBRARY_PREFIX "")
function(clr_unknown_arch)
if (WIN32)
message(FATAL_ERROR "Only AMD64 and I386 are supported")
else()
message(FATAL_ERROR "Only AMD64, ARM64, ARM and ARMEL are supported")
endif()
message(FATAL_ERROR "Only AMD64, ARM64, ARM, ARMEL, I386 and WASM are supported")
endfunction()
if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64)
set(IS_64BIT_BUILD 1)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
if(CLR_CMAKE_TARGET_ARCH STREQUAL x64)
set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1)
add_definitions(-D_TARGET_AMD64_=1)
add_definitions(-D_AMD64_)
add_definitions(-DBIT64=1)
elseif(CLR_CMAKE_TARGET_ARCH MATCHES "^(arm|armel)$")
set(CLR_CMAKE_PLATFORM_ARCH_ARM 1)
add_definitions(-D_TARGET_ARM_=1)
add_definitions(-D_ARM_)
add_definitions(-DBIT32=1)
# Because we don't use CMAKE_C_COMPILER/CMAKE_CXX_COMPILER to use clang
# we have to set the triple by adding a compiler argument
if(TOOLCHAIN STREQUAL arm-linux-gnueabi)
add_compile_options(-target armv7-linux-gnueabi)
add_compile_options(-mfloat-abi=softfp)
else ()
add_compile_options(-target armv7-linux-gnueabihf)
endif ()
add_compile_options(-mthumb)
add_compile_options(-mfpu=vfpv3)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
set(IS_64BIT_BUILD 1)
# Because we don't use CMAKE_C_COMPILER/CMAKE_CXX_COMPILER to use clang
# we have to set the triple by adding a compiler argument
add_compile_options(-target aarch64-linux-gnu)
endif ()
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64)
set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1)
add_definitions(-D_TARGET_ARM64_=1)
add_definitions(-D_ARM64_)
add_definitions(-DBIT64=1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86)
set(CLR_CMAKE_PLATFORM_ARCH_I386 1)
add_definitions(-D_TARGET_X86_=1)
add_definitions(-D_X86_)
add_definitions(-DBIT32=1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL wasm)
set(CLR_CMAKE_PLATFORM_ARCH_WASM 1)
add_definitions(-D_TARGET_WASM_=1)
add_definitions(-D_WASM_)
add_definitions(-DBIT32=1)
else()
clr_unknown_arch()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)
set(CLR_CMAKE_PLATFORM_DARWIN 1)
if(CMAKE_VERSION VERSION_LESS "3.4.0")
set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> -o <OBJECT> -c <SOURCE>")
else()
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_DARWIN 1)
set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> <INCLUDES> -o <OBJECT> -c <SOURCE>")
endif(CMAKE_VERSION VERSION_LESS "3.4.0")
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CLR_CMAKE_PLATFORM_UNIX 1)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM64 1)
else()
clr_unknown_arch()
endif()
set(CLR_CMAKE_PLATFORM_LINUX 1)
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_FREEBSD 1)
endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
if(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
set(CLR_CMAKE_PLATFORM_UNIX 1)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM64 1)
else()
clr_unknown_arch()
endif()
set(CLR_CMAKE_PLATFORM_NETBSD 1)
endif(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_WASM 1)
endif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
if (CLR_CMAKE_PLATFORM_UNIX)
include_directories(inc/unix)
@@ -99,10 +95,34 @@ if (CLR_CMAKE_PLATFORM_UNIX)
add_compile_options(-Wno-null-arithmetic)
add_compile_options(-Wno-null-conversion)
if (CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)
if (CLR_CMAKE_PLATFORM_ARCH_AMD64 OR CLR_CMAKE_PLATFORM_ARCH_I386)
# Allow 16 byte compare-exchange
add_compile_options(-mcx16)
endif()
if (CLR_CMAKE_PLATFORM_ARCH_ARM)
# Because we don't use CMAKE_C_COMPILER/CMAKE_CXX_COMPILER to use clang
# we have to set the triple by adding a compiler argument
if(TOOLCHAIN STREQUAL arm-linux-gnueabi)
add_compile_options(-target armv7-linux-gnueabi)
add_compile_options(-mfloat-abi=softfp)
else ()
add_compile_options(-target armv7-linux-gnueabihf)
endif ()
add_compile_options(-mthumb)
add_compile_options(-mfpu=vfpv3)
endif()
if (CLR_CMAKE_PLATFORM_ARCH_ARM64)
# Because we don't use CMAKE_C_COMPILER/CMAKE_CXX_COMPILER to use clang
# we have to set the triple by adding a compiler argument
add_compile_options(-target aarch64-linux-gnu)
endif ()
if (CLR_CMAKE_PLATFORM_ARCH_AMD64)
add_definitions(-DUNIX_AMD64_ABI)
elseif (CLR_CMAKE_PLATFORM_ARCH_I386)
add_definitions(-DUNIX_X86_ABI)
endif()
# Disable strict warning on unused functions.
@@ -122,32 +142,10 @@ if (CLR_CMAKE_PLATFORM_UNIX)
endif(CLR_CMAKE_PLATFORM_DARWIN)
if(CLR_CMAKE_PLATFORM_LINUX)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
endif(CLR_CMAKE_PLATFORM_LINUX)
endif(CLR_CMAKE_PLATFORM_UNIX)
if(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM)
set(CLR_CMAKE_PLATFORM_ARCH_ARM 1)
elseif(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM64)
set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1)
elseif(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)
set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1)
elseif(WIN32)
if (CLR_CMAKE_TARGET_ARCH STREQUAL x64)
set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1)
set(IS_64BIT_BUILD 1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86)
set(CLR_CMAKE_PLATFORM_ARCH_I386 1)
set(IS_64BIT_BUILD 0)
else()
clr_unknown_arch()
endif()
endif()
if(IS_64BIT_BUILD)
add_definitions(-DBIT64=1)
endif(IS_64BIT_BUILD)
if(WIN32)
enable_language(ASM_MASM)
else()
@@ -161,7 +159,7 @@ function(get_compile_definitions DefinitionName)
foreach(DEFINITION IN LISTS COMPILE_DEFINITIONS_LIST)
if (${DEFINITION} MATCHES "^\\$<\\$<CONFIG:([^>]+)>:([^>]+)>$")
# The entries that contain generator expressions must have the -D inside of the
# The entries that contain generator expressions must have the -D inside of the
# expression. So we transform e.g. $<$<CONFIG:Debug>:_DEBUG> to $<$<CONFIG:Debug>:-D_DEBUG>
set(DEFINITION "$<$<CONFIG:${CMAKE_MATCH_1}>:-D${CMAKE_MATCH_2}>")
else()
@@ -172,25 +170,9 @@ function(get_compile_definitions DefinitionName)
set(${DefinitionName} ${DEFINITIONS} PARENT_SCOPE)
endfunction(get_compile_definitions)
if(CLR_CMAKE_PLATFORM_ARCH_AMD64)
add_definitions(-D_TARGET_AMD64_=1)
add_definitions(-D_AMD64_)
elseif(CLR_CMAKE_PLATFORM_ARCH_I386)
add_definitions(-D_TARGET_X86_=1)
add_definitions(-D_X86_)
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM)
add_definitions(-D_TARGET_ARM_=1)
add_definitions(-D_ARM_)
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
add_definitions(-D_TARGET_ARM64_=1)
add_definitions(-D_ARM64_)
else()
clr_unknown_arch()
endif()
# Set the passed in RetSources variable to the list of sources with added current source directory
# to form absolute paths.
# The parameters after the RetSources are the input files.
# to form absolute paths.
# The parameters after the RetSources are the input files.
function(convert_to_absolute_path RetSources)
set(Sources ${ARGN})
foreach(Source IN LISTS Sources)
@@ -204,8 +186,13 @@ if(WIN32)
add_compile_options($<$<CONFIG:Debug>:-DDEBUG>)
add_compile_options($<$<CONFIG:Debug>:/MTd>)
add_compile_options($<$<CONFIG:Release>:/MT>)
add_compile_options(/source-charset:utf-8) # Force MSVC to compile source as UTF-8.
add_compile_options(/Zi) # enable debugging information
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG")
if (CLR_CMAKE_PLATFORM_ARCH_I386)
add_compile_options(/Gz)
endif (CLR_CMAKE_PLATFORM_ARCH_I386)
else(WIN32)
string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_CMAKE_BUILD_TYPE)
if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG)
@@ -213,23 +200,35 @@ if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG)
add_definitions(-DDEBUG)
add_definitions(-D_DEBUG)
elseif (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
add_compile_options (-O3)
add_compile_options (-g -O3)
add_definitions(-DNDEBUG)
else ()
message(FATAL_ERROR "Unknown build type. Set CMAKE_BUILD_TYPE to DEBUG or RELEASE.")
endif ()
if (CLR_CMAKE_PLATFORM_ARCH_I386)
add_compile_options(-m32)
link_libraries(-m32)
endif()
endif (WIN32)
include(configure.cmake)
if(WIN32)
add_subdirectory(gc)
add_subdirectory(gc)
endif()
add_subdirectory(Runtime)
add_subdirectory(Bootstrap)
add_subdirectory(jitinterface)
if(NOT CLR_CMAKE_PLATFORM_WASM)
add_subdirectory(jitinterface)
endif(NOT CLR_CMAKE_PLATFORM_WASM)
# We don't need the PAL on Windows.
if(CLR_CMAKE_PLATFORM_UNIX)
add_subdirectory(System.Private.CoreLib.Native)
if(NOT WIN32)
add_subdirectory(System.Private.CoreLib.Native)
endif(NOT WIN32)
# Build ObjWriter on Linux only
if(CMAKE_SYSTEM_NAME STREQUAL Linux AND OBJWRITER_BUILD)
add_subdirectory(ObjWriter/llvmCap)
endif()

View File

@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>Microsoft.DotNet.ObjectWriter</id>
<version>1.0.19-prerelease-00001</version>
<title>Microsoft .NET Object File Generator</title>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<licenseUrl>http://go.microsoft.com/fwlink/?LinkId=329770</licenseUrl>
<projectUrl>https://github.com/dotnet/corert</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Provides object writer to the managed to native code-generator.</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright &#169; Microsoft Corporation</copyright>
</metadata>
<files>
<file src="runtime.json" />
</files>
</package>

View File

@@ -0,0 +1,19 @@
{
"runtimes": {
"win7-x64": {
"Microsoft.DotNet.ObjectWriter": {
"toolchain.win7-x64.Microsoft.DotNet.ObjectWriter": "1.0.19-prerelease-00001"
}
},
"ubuntu.14.04-x64": {
"Microsoft.DotNet.ObjectWriter": {
"toolchain.ubuntu.14.04-x64.Microsoft.DotNet.ObjectWriter": "1.0.19-prerelease-00001"
}
},
"osx.10.10-x64": {
"Microsoft.DotNet.ObjectWriter": {
"toolchain.osx.10.10-x64.Microsoft.DotNet.ObjectWriter": "1.0.19-prerelease-00001"
}
}
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>toolchain.osx.10.10-x64.Microsoft.DotNet.ObjectWriter</id>
<version>1.0.19-prerelease-00001</version>
<title>Microsoft .NET Object File Generator</title>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<licenseUrl>http://go.microsoft.com/fwlink/?LinkId=329770</licenseUrl>
<projectUrl>https://github.com/dotnet/corert</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Provides object writer to the managed to native code-generator.</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright &#169; Microsoft Corporation</copyright>
</metadata>
<files>
<file src="../libobjwriter.dylib" target="runtimes/osx.10.10-x64/native/libobjwriter.dylib" />
</files>
</package>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>toolchain.ubuntu.14.04-x64.Microsoft.DotNet.ObjectWriter</id>
<version>1.0.19-prerelease-00001</version>
<title>Microsoft .NET Object File Generator</title>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<licenseUrl>http://go.microsoft.com/fwlink/?LinkId=329770</licenseUrl>
<projectUrl>https://github.com/dotnet/corert</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Provides object writer to the managed to native code-generator.</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright &#169; Microsoft Corporation</copyright>
</metadata>
<files>
<file src="../libobjwriter.so" target="runtimes/ubuntu.14.04-x64/native/libobjwriter.so" />
</files>
</package>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>toolchain.win7-x64.Microsoft.DotNet.ObjectWriter</id>
<version>1.0.19-prerelease-00001</version>
<title>Microsoft .NET Object File Generator</title>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<licenseUrl>http://go.microsoft.com/fwlink/?LinkId=329770</licenseUrl>
<projectUrl>https://github.com/dotnet/corert</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Provides object writer to the managed to native code-generator.</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright &#169; Microsoft Corporation</copyright>
</metadata>
<files>
<file src="..\objwriter.dll" target="runtimes\win7-x64\native\objwriter.dll" />
</files>
</package>

View File

@@ -0,0 +1,46 @@
project(objwriter)
set(CMAKE_BUILD_TYPE "${OBJWRITER_BUILD_TYPE}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OBJWRITER_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OBJWRITER_CXX_FLAGS} -std=c++11 -fno-rtti")
message(STATUS "ObjWriter configuring with (${CMAKE_BUILD_TYPE}) build type and (${LLVM_DEFAULT_TARGET_TRIPLE}) default target triple")
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(.)
add_definitions(${LLVM_DEFINITIONS})
if (WIN32)
# Create .def file containing a list of exports preceeded by
# 'EXPORTS'. The file "objwriter.exports" already contains the list, so we
# massage it into the correct format here to create "objwriter.exports.def".
set(OBJWRITER_EXPORTS_DEF ${CMAKE_CURRENT_BINARY_DIR}/objwriter.exports.def)
set(OBJWRITER_EXPORTS_DEF_TEMP ${OBJWRITER_EXPORTS_DEF}.txt)
file(READ "objwriter.exports" exports_list)
file(WRITE ${OBJWRITER_EXPORTS_DEF_TEMP} "LIBRARY OBJWRITER\n")
file(APPEND ${OBJWRITER_EXPORTS_DEF_TEMP} "EXPORTS\n")
file(APPEND ${OBJWRITER_EXPORTS_DEF_TEMP} ${exports_list})
# Copy the file only if it has changed.
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${OBJWRITER_EXPORTS_DEF_TEMP} ${OBJWRITER_EXPORTS_DEF})
endif()
# Now build our tools
add_library(objwriter
SHARED
objwriter.cpp
typeBuilder.cpp
objwriter.h # Visual Studio generator doesn't include necessary header files into the project automatically
typeBuilder.h
${OBJWRITER_EXPORTS_DEF}
)
# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs
${LLVM_TARGETS_TO_BUILD}
)
# Link against LLVM libraries
target_link_libraries(objwriter
${llvm_libs})

View File

@@ -0,0 +1,37 @@
// 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.
//
// Keep in sync with https://github.com/dotnet/coreclr/blob/master/src/inc/cfi.h
//
#ifndef CFI_H_
#define CFI_H_
#define DWARF_REG_ILLEGAL -1
enum CFI_OPCODE
{
CFI_ADJUST_CFA_OFFSET, // Offset is adjusted relative to the current one.
CFI_DEF_CFA_REGISTER, // New register is used to compute CFA
CFI_REL_OFFSET // Register is saved at offset from the current CFA
};
struct CFI_CODE
{
unsigned char CodeOffset;// Offset from the start of code the frame covers.
unsigned char CfiOpCode;
short DwarfReg; // Dwarf register number. 0~32 for x64.
int Offset;
CFI_CODE(unsigned char codeOffset, unsigned char cfiOpcode,
short dwarfReg, int offset)
: CodeOffset(codeOffset)
, CfiOpCode(cfiOpcode)
, DwarfReg(dwarfReg)
, Offset(offset)
{}
};
typedef CFI_CODE* PCFI_CODE;
#endif // CFI_H

View File

@@ -0,0 +1,327 @@
// 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.
//
// Keep in sync with https://github.com/dotnet/coreclr/blob/master/src/inc/cordebuginfo.h
//
/**********************************************************************************/
// DebugInfo types shared by JIT-EE interface and EE-Debugger interface
class ICorDebugInfo
{
public:
/*----------------------------- Boundary-info ---------------------------*/
enum MappingTypes
{
NO_MAPPING = -1,
PROLOG = -2,
EPILOG = -3,
MAX_MAPPING_VALUE = -3 // Sentinal value. This should be set to the largest magnitude value in the enum
// so that the compression routines know the enum's range.
};
enum BoundaryTypes
{
NO_BOUNDARIES = 0x00, // No implicit boundaries
STACK_EMPTY_BOUNDARIES = 0x01, // Boundary whenever the IL evaluation stack is empty
NOP_BOUNDARIES = 0x02, // Before every CEE_NOP instruction
CALL_SITE_BOUNDARIES = 0x04, // Before every CEE_CALL, CEE_CALLVIRT, etc instruction
// Set of boundaries that debugger should always reasonably ask the JIT for.
DEFAULT_BOUNDARIES = STACK_EMPTY_BOUNDARIES | NOP_BOUNDARIES | CALL_SITE_BOUNDARIES
};
// Note that SourceTypes can be OR'd together - it's possible that
// a sequence point will also be a stack_empty point, and/or a call site.
// The debugger will check to see if a boundary offset's source field &
// SEQUENCE_POINT is true to determine if the boundary is a sequence point.
enum SourceTypes
{
SOURCE_TYPE_INVALID = 0x00, // To indicate that nothing else applies
SEQUENCE_POINT = 0x01, // The debugger asked for it.
STACK_EMPTY = 0x02, // The stack is empty here
CALL_SITE = 0x04, // This is a call site.
NATIVE_END_OFFSET_UNKNOWN = 0x08, // Indicates a epilog endpoint
CALL_INSTRUCTION = 0x10 // The actual instruction of a call.
};
struct OffsetMapping
{
DWORD nativeOffset;
DWORD ilOffset;
SourceTypes source; // The debugger needs this so that
// we don't put Edit and Continue breakpoints where
// the stack isn't empty. We can put regular breakpoints
// there, though, so we need a way to discriminate
// between offsets.
};
/*------------------------------ Var-info -------------------------------*/
// Note: The debugger needs to target register numbers on platforms other than which the debugger itself
// is running. To this end it maintains its own values for REGNUM_SP and REGNUM_AMBIENT_SP across multiple
// platforms. So any change here that may effect these values should be reflected in the definitions
// contained in debug/inc/DbgIPCEvents.h.
enum RegNum
{
#ifdef _TARGET_X86_
REGNUM_EAX,
REGNUM_ECX,
REGNUM_EDX,
REGNUM_EBX,
REGNUM_ESP,
REGNUM_EBP,
REGNUM_ESI,
REGNUM_EDI,
#elif _TARGET_ARM_
REGNUM_R0,
REGNUM_R1,
REGNUM_R2,
REGNUM_R3,
REGNUM_R4,
REGNUM_R5,
REGNUM_R6,
REGNUM_R7,
REGNUM_R8,
REGNUM_R9,
REGNUM_R10,
REGNUM_R11,
REGNUM_R12,
REGNUM_SP,
REGNUM_LR,
REGNUM_PC,
#elif _TARGET_ARM64_
REGNUM_X0,
REGNUM_X1,
REGNUM_X2,
REGNUM_X3,
REGNUM_X4,
REGNUM_X5,
REGNUM_X6,
REGNUM_X7,
REGNUM_X8,
REGNUM_X9,
REGNUM_X10,
REGNUM_X11,
REGNUM_X12,
REGNUM_X13,
REGNUM_X14,
REGNUM_X15,
REGNUM_X16,
REGNUM_X17,
REGNUM_X18,
REGNUM_X19,
REGNUM_X20,
REGNUM_X21,
REGNUM_X22,
REGNUM_X23,
REGNUM_X24,
REGNUM_X25,
REGNUM_X26,
REGNUM_X27,
REGNUM_X28,
REGNUM_FP,
REGNUM_LR,
REGNUM_SP,
REGNUM_PC,
#elif _TARGET_AMD64_
REGNUM_RAX,
REGNUM_RCX,
REGNUM_RDX,
REGNUM_RBX,
REGNUM_RSP,
REGNUM_RBP,
REGNUM_RSI,
REGNUM_RDI,
REGNUM_R8,
REGNUM_R9,
REGNUM_R10,
REGNUM_R11,
REGNUM_R12,
REGNUM_R13,
REGNUM_R14,
REGNUM_R15,
#else
PORTABILITY_WARNING("Register numbers not defined on this platform")
#endif
REGNUM_COUNT,
REGNUM_AMBIENT_SP, // ambient SP support. Ambient SP is the original SP in the non-BP based frame.
// Ambient SP should not change even if there are push/pop operations in the method.
#ifdef _TARGET_X86_
REGNUM_FP = REGNUM_EBP,
REGNUM_SP = REGNUM_ESP,
#elif _TARGET_AMD64_
REGNUM_SP = REGNUM_RSP,
#elif _TARGET_ARM_
#ifdef REDHAWK
REGNUM_FP = REGNUM_R7,
#else
REGNUM_FP = REGNUM_R11,
#endif //REDHAWK
#elif _TARGET_ARM64_
//Nothing to do here. FP is already alloted.
#else
// RegNum values should be properly defined for this platform
REGNUM_FP = 0,
REGNUM_SP = 1,
#endif
};
// VarLoc describes the location of a native variable. Note that currently, VLT_REG_BYREF and VLT_STK_BYREF
// are only used for value types on X64.
enum VarLocType
{
VLT_REG, // variable is in a register
VLT_REG_BYREF, // address of the variable is in a register
VLT_REG_FP, // variable is in an fp register
VLT_STK, // variable is on the stack (memory addressed relative to the frame-pointer)
VLT_STK_BYREF, // address of the variable is on the stack (memory addressed relative to the frame-pointer)
VLT_REG_REG, // variable lives in two registers
VLT_REG_STK, // variable lives partly in a register and partly on the stack
VLT_STK_REG, // reverse of VLT_REG_STK
VLT_STK2, // variable lives in two slots on the stack
VLT_FPSTK, // variable lives on the floating-point stack
VLT_FIXED_VA, // variable is a fixed argument in a varargs function (relative to VARARGS_HANDLE)
VLT_COUNT,
VLT_INVALID,
};
struct VarLoc
{
VarLocType vlType;
union
{
// VLT_REG/VLT_REG_FP -- Any pointer-sized enregistered value (TYP_INT, TYP_REF, etc)
// eg. EAX
// VLT_REG_BYREF -- the specified register contains the address of the variable
// eg. [EAX]
struct
{
RegNum vlrReg;
} vlReg;
// VLT_STK -- Any 32 bit value which is on the stack
// eg. [ESP+0x20], or [EBP-0x28]
// VLT_STK_BYREF -- the specified stack location contains the address of the variable
// eg. mov EAX, [ESP+0x20]; [EAX]
struct
{
RegNum vlsBaseReg;
signed vlsOffset;
} vlStk;
// VLT_REG_REG -- TYP_LONG with both DWords enregistred
// eg. RBM_EAXEDX
struct
{
RegNum vlrrReg1;
RegNum vlrrReg2;
} vlRegReg;
// VLT_REG_STK -- Partly enregistered TYP_LONG
// eg { LowerDWord=EAX UpperDWord=[ESP+0x8] }
struct
{
RegNum vlrsReg;
struct
{
RegNum vlrssBaseReg;
signed vlrssOffset;
} vlrsStk;
} vlRegStk;
// VLT_STK_REG -- Partly enregistered TYP_LONG
// eg { LowerDWord=[ESP+0x8] UpperDWord=EAX }
struct
{
struct
{
RegNum vlsrsBaseReg;
signed vlsrsOffset;
} vlsrStk;
RegNum vlsrReg;
} vlStkReg;
// VLT_STK2 -- Any 64 bit value which is on the stack,
// in 2 successsive DWords.
// eg 2 DWords at [ESP+0x10]
struct
{
RegNum vls2BaseReg;
signed vls2Offset;
} vlStk2;
// VLT_FPSTK -- enregisterd TYP_DOUBLE (on the FP stack)
// eg. ST(3). Actually it is ST("FPstkHeigth - vpFpStk")
struct
{
unsigned vlfReg;
} vlFPstk;
// VLT_FIXED_VA -- fixed argument of a varargs function.
// The argument location depends on the size of the variable
// arguments (...). Inspecting the VARARGS_HANDLE indicates the
// location of the first arg. This argument can then be accessed
// relative to the position of the first arg
struct
{
unsigned vlfvOffset;
} vlFixedVarArg;
// VLT_MEMORY
struct
{
void *rpValue; // pointer to the in-process
// location of the value.
} vlMemory;
};
};
// This is used to report implicit/hidden arguments
enum
{
VARARGS_HND_ILNUM = -1, // Value for the CORINFO_VARARGS_HANDLE varNumber
RETBUF_ILNUM = -2, // Pointer to the return-buffer
TYPECTXT_ILNUM = -3, // ParamTypeArg for CORINFO_GENERICS_CTXT_FROM_PARAMTYPEARG
UNKNOWN_ILNUM = -4, // Unknown variable
MAX_ILNUM = -4 // Sentinal value. This should be set to the largest magnitude value in th enum
// so that the compression routines know the enum's range.
};
struct ILVarInfo
{
DWORD startOffset;
DWORD endOffset;
DWORD varNumber;
};
struct NativeVarInfo
{
DWORD startOffset;
DWORD endOffset;
DWORD varNumber;
VarLoc loc;
};
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
#ifndef JIT_DEBUG_INFO_H
#define JIT_DEBUG_INFO_H
typedef unsigned int DWORD;
#define _TARGET_AMD64_ 1
#include "cordebuginfo.h"
#include "cvconst.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
struct DebugLocInfo {
int NativeOffset;
int FileId;
int LineNumber;
int ColNumber;
};
struct DebugVarInfo {
std::string Name;
int TypeIndex;
bool IsParam;
std::vector<ICorDebugInfo::NativeVarInfo> Ranges;
DebugVarInfo() {}
DebugVarInfo(char *ArgName, int ArgTypeIndex, bool ArgIsParam)
: Name(ArgName), TypeIndex(ArgTypeIndex), IsParam(ArgIsParam) {}
};
typedef unsigned short CVRegMapping;
#define CVREGDAT(p2, cv) cv
const CVRegMapping cvRegMapAmd64[] = {
CVREGDAT(REGNUM_RAX, CV_AMD64_RAX), CVREGDAT(REGNUM_RCX, CV_AMD64_RCX),
CVREGDAT(REGNUM_RDX, CV_AMD64_RDX), CVREGDAT(REGNUM_RBX, CV_AMD64_RBX),
CVREGDAT(REGNUM_RSP, CV_AMD64_RSP), CVREGDAT(REGNUM_RBP, CV_AMD64_RBP),
CVREGDAT(REGNUM_RSI, CV_AMD64_RSI), CVREGDAT(REGNUM_RDI, CV_AMD64_RDI),
CVREGDAT(REGNUM_R8, CV_AMD64_R8), CVREGDAT(REGNUM_R9, CV_AMD64_R9),
CVREGDAT(REGNUM_R10, CV_AMD64_R10), CVREGDAT(REGNUM_R11, CV_AMD64_R11),
CVREGDAT(REGNUM_R12, CV_AMD64_R12), CVREGDAT(REGNUM_R13, CV_AMD64_R13),
CVREGDAT(REGNUM_R14, CV_AMD64_R14), CVREGDAT(REGNUM_R15, CV_AMD64_R15)};
#endif // JIT_DEBUG_INFO_H

View File

@@ -0,0 +1,123 @@
diff --git a/include/llvm/MC/MCObjectStreamer.h b/include/llvm/MC/MCObjectStreamer.h
index 7c1189e46ab..d1d77c97311 100644
--- a/include/llvm/MC/MCObjectStreamer.h
+++ b/include/llvm/MC/MCObjectStreamer.h
@@ -101,6 +101,11 @@ public:
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
bool = false) override;
+ /// \brief EmitValueImpl with additional param, that allows to emit PCRelative
+ /// MCFixup.
+ void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc,
+ bool isPCRelative);
+
/// \brief Emit an instruction to a special fragment, because this instruction
/// can change its size during relaxation.
virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &);
diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp
index 174397e2739..ef7161fb56c 100644
--- a/lib/MC/MCObjectStreamer.cpp
+++ b/lib/MC/MCObjectStreamer.cpp
@@ -122,7 +122,7 @@ void MCObjectStreamer::EmitCFISections(bool EH, bool Debug) {
}
void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
- SMLoc Loc) {
+ SMLoc Loc, bool isPCRelative) {
MCStreamer::EmitValueImpl(Value, Size, Loc);
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
@@ -143,10 +143,16 @@ void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
}
DF->getFixups().push_back(
MCFixup::create(DF->getContents().size(), Value,
- MCFixup::getKindForSize(Size, false), Loc));
+ MCFixup::getKindForSize(Size, isPCRelative), Loc));
DF->getContents().resize(DF->getContents().size() + Size, 0);
}
+
+void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
+ SMLoc Loc) {
+ EmitValueImpl(Value, Size, Loc, false);
+}
+
void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
// We need to create a local symbol to avoid relocations.
Frame.Begin = getContext().createTempSymbol();
diff --git a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index a77df7a2598..e1aa7526f9b 100644
--- a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
+++ b/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
@@ -48,6 +48,14 @@ public:
};
} // end anonymous namespace
+Optional<MCFixupKind> ARMAsmBackend::getFixupKind(StringRef Name) const {
+ return StringSwitch<Optional<MCFixupKind>>(Name)
+ .Case("R_ARM_THM_MOVW_ABS_NC", (MCFixupKind)ARM::fixup_t2_movw_lo16)
+ .Case("R_ARM_THM_MOVT_ABS", (MCFixupKind)ARM::fixup_t2_movt_hi16)
+ .Case("R_ARM_THM_JUMP24", (MCFixupKind)ARM::fixup_arm_thumb_blx)
+ .Default(MCAsmBackend::getFixupKind(Name));
+}
+
const MCFixupKindInfo &ARMAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
const static MCFixupKindInfo InfosLE[ARM::NumTargetFixupKinds] = {
// This table *must* be in the order that the fixup_* kinds are defined in
@@ -386,6 +394,8 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
case FK_Data_2:
case FK_Data_4:
return Value;
+ case FK_PCRel_4:
+ return Value;
case FK_SecRel_2:
return Value;
case FK_SecRel_4:
@@ -825,6 +835,9 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
case ARM::fixup_t2_so_imm:
return 4;
+ case FK_PCRel_4:
+ return 4;
+
case FK_SecRel_2:
return 2;
case FK_SecRel_4:
diff --git a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h b/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h
index 02374966daf..01676a01683 100644
--- a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h
+++ b/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h
@@ -36,6 +36,7 @@ public:
bool hasNOP() const { return STI->getFeatureBits()[ARM::HasV6T2Ops]; }
+ Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
diff --git a/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index 59f31be69d5..9b95598f99f 100644
--- a/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -103,6 +103,9 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
break;
}
break;
+ case FK_PCRel_4:
+ Type = ELF::R_ARM_REL32;
+ break;
case ARM::fixup_arm_blx:
case ARM::fixup_arm_uncondbl:
switch (Modifier) {
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index b654b8c5cb8..58d25159af8 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -46,6 +46,7 @@ add_llvm_external_project(clang)
add_llvm_external_project(llgo)
add_llvm_external_project(lld)
add_llvm_external_project(lldb)
+add_llvm_external_project(ObjWriter)
# Automatically add remaining sub-directories containing a 'CMakeLists.txt'
# file as external projects.

View File

@@ -0,0 +1,116 @@
cmake_minimum_required(VERSION 3.6)
project(ObjWriter)
include(ExternalProject)
set(OBJWRITER_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../)
set(OBJWRITER_LLVM_POINT tools/ObjWriter)
if(NOT OBJWRITER_TARGET_ARCH)
if(CLR_CMAKE_TARGET_ARCH MATCHES "^(x64|x86)$")
if(NOT CROSS_BUILD)
set(OBJWRITER_TARGET_ARCH "X86")
else()
# If we really want a cross version for x86/x64 -> arm32/arm64
# I think in the opposite direction it's not necessary for anyone ;-)
set(OBJWRITER_TARGET_ARCH "X86::ARM")
set(USE_ARM_TARGET_TRIPLE 1)
endif()
elseif(CLR_CMAKE_TARGET_ARCH MATCHES "^(arm|armel)$")
set(OBJWRITER_TARGET_ARCH "ARM")
set(USE_ARM_TARGET_TRIPLE 1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL "arm64")
set(OBJWRITER_TARGET_ARCH "AArch64")
else()
clr_unknown_arch()
endif()
endif()
get_target_property(CORERT_NATIVE_COMPILE_OPTIONS Runtime COMPILE_OPTIONS)
# For armel RootFS compatibility
if(CLR_CMAKE_TARGET_ARCH STREQUAL "armel")
list(APPEND CORERT_NATIVE_COMPILE_OPTIONS "-Wno-gnu-include-next")
endif()
if(USE_ARM_TARGET_TRIPLE)
list(APPEND LLVM_CMAKE_EXTRA_ARGS "-DLLVM_DEFAULT_TARGET_TRIPLE=thumbv7-linux-gnueabi")
endif()
list(REMOVE_DUPLICATES CORERT_NATIVE_COMPILE_OPTIONS)
# Make sure to remove debug flags from general build flags for LLVM
set(LLVM_COMPILE_OPTIONS "${CORERT_NATIVE_COMPILE_OPTIONS}")
list(REMOVE_ITEM LLVM_COMPILE_OPTIONS "-g")
list(REMOVE_ITEM LLVM_COMPILE_OPTIONS "-O0")
string(REPLACE ";" "\ " CORERT_NATIVE_COMPILE_OPTIONS "${CORERT_NATIVE_COMPILE_OPTIONS}")
string(REPLACE ";" "\ " LLVM_COMPILE_OPTIONS "${LLVM_COMPILE_OPTIONS}")
# If host and target are the same, we could use llvm-tblgen from LLVM itself.
# Otherwise we use host llvm-tblgen. It's universal way for cross-building.
if(NOT ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_SYSTEM_PROCESSOR})
execute_process (
COMMAND bash -c "echo -n `which llvm-tblgen`"
OUTPUT_VARIABLE LLVM_TBLGEN_TOOL
)
if(NOT LLVM_TBLGEN_TOOL)
message(FATAL_ERROR "Can't find llvm-tblgen. You need to make sure that you have installed LLVM")
endif()
list(APPEND LLVM_CMAKE_EXTRA_ARGS "-DLLVM_TABLEGEN=${LLVM_TBLGEN_TOOL}")
endif()
ExternalProject_Add(LLVM
GIT_REPOSITORY https://github.com/llvm-mirror/llvm
GIT_TAG release_50
GIT_SHALLOW 1
GIT_PROGRESS 1
PATCH_COMMAND ""
UPDATE_COMMAND ""
INSTALL_COMMAND ""
USES_TERMINAL_DOWNLOAD 1
USES_TERMINAL_CONFIGURE 1
USES_TERMINAL_BUILD 1
USES_TERMINAL_INSTALL 1
UPDATE_DISCONNECTED 1
DEPENDS Runtime PortableRuntime
LIST_SEPARATOR ::
CMAKE_ARGS -DHAVE_POSIX_SPAWN=0
-DLLVM_BUILD_DOCS=0
-DLLVM_BUILD_TESTS=0
-DLLVM_ENABLE_DOXYGEN=0
-DLLVM_ENABLE_PEDANTIC=0
-DLLVM_ENABLE_PIC=1
-DLLVM_ENABLE_WERROR=0
-DLLVM_INCLUDE_DOCS=0
-DLLVM_INCLUDE_EXAMPLES=0
-DLLVM_INCLUDE_TESTS=0
-DLLVM_OPTIMIZED_TABLEGEN=1
-DCMAKE_BUILD_TYPE=Release
-DLLVM_TARGET_ARCH=${OBJWRITER_TARGET_ARCH}
-DLLVM_TARGETS_TO_BUILD=${OBJWRITER_TARGET_ARCH}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_FLAGS=${LLVM_COMPILE_OPTIONS}
-DCMAKE_CXX_FLAGS=${LLVM_COMPILE_OPTIONS}
-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}
-DCMAKE_MODULE_LINKER_FLAGS=${CMAKE_MODULE_LINKER_FLAGS}
-DCMAKE_SHARED_LINKER_FLAGS=${CMAKE_SHARED_LINKER_FLAGS}
-DOBJWRITER_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DOBJWRITER_C_FLAGS=${CORERT_NATIVE_COMPILE_OPTIONS}
-DOBJWRITER_CXX_FLAGS=${CORERT_NATIVE_COMPILE_OPTIONS}
${LLVM_CMAKE_EXTRA_ARGS}
)
ExternalProject_Get_Property(LLVM source_dir)
set(LLVM_SOURCE_DIR ${source_dir})
ExternalProject_Add_Step(LLVM PatchingLLVM
COMMAND git apply --3way ${OBJWRITER_ROOT}/llvm.patch COMMENT "Applying LLVM patch with ObjWriter fixes"
WORKING_DIRECTORY ${LLVM_SOURCE_DIR}
DEPENDEES patch
USES_TERMINAL 1
)
ExternalProject_Add_Step(LLVM ObjWriterInjection
COMMAND ${CMAKE_COMMAND} -E create_symlink ${OBJWRITER_ROOT} ${OBJWRITER_LLVM_POINT} COMMENT "mklink ${OBJWRITER_ROOT} -> ${OBJWRITER_LLVM_POINT}"
WORKING_DIRECTORY ${LLVM_SOURCE_DIR}
DEPENDEES patch
USES_TERMINAL 1
)

Some files were not shown because too many files have changed in this diff Show More