set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
+# All code we build should be compiled as position independent
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
set(CLR_DEFINES_DEBUG_INIT DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1)
set(CLR_DEFINES_CHECKED_INIT DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1)
set(CLR_DEFINES_RELEASE_INIT NDEBUG URTBLDENV_FRIENDLY=Retail)
endif ()
# -fdata-sections -ffunction-sections: each function has own section instead of one per .o file (needed for --gc-sections)
- # -fPIC: enable Position Independent Code normally just for shared libraries but required when linking with address sanitizer
# -O1: optimization level used instead of -O0 to avoid compile error "invalid operand for inline asm constraint"
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -fPIC -O1")
- set(CMAKE_CXX_FLAGS_CHECKED "${CMAKE_CXX_FLAGS_CHECKED} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -fPIC -O1")
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -O1")
+ set(CMAKE_CXX_FLAGS_CHECKED "${CMAKE_CXX_FLAGS_CHECKED} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -O1")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${CLR_SANITIZE_LINK_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_CHECKED "${CMAKE_EXE_LINKER_FLAGS_CHECKED} ${CLR_SANITIZE_LINK_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_CHECKED "${CMAKE_SHARED_LINKER_FLAGS_CHECKED} ${CLR_SANITIZE_LINK_FLAGS} -Wl,--gc-sections")
endif ()
endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
+
+ # This linker option causes executables we build to be marked as containing position independent code.
+ # It is necessary to make ASLR work for executables.
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie" )
+
endif(WIN32)
# CLR_ADDITIONAL_LINKER_FLAGS - used for passing additional arguments to linker
convert_to_absolute_path(BINDER_SOURCES ${BINDER_SOURCES})
convert_to_absolute_path(BINDER_CROSSGEN_SOURCES ${BINDER_CROSSGEN_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(v3binder)
add_subdirectory(v3binder_crossgen)
variant.cpp
)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_library_clr(bcltype
STATIC
${BCLTYPE_SOURCES}
floatsingle.cpp
)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_library_clr(comfloat_wks
STATIC
${FLOAT_SOURCES}
include_directories(../unixcoreruncommon)
-add_compile_options(-fPIE)
-
set(CORERUN_SOURCES
osxbundlerun.cpp
)
include_directories(../unixcoreruncommon)
-add_compile_options(-fPIE)
-
set(CORECONSOLE_SOURCES
coreconsole.cpp
)
include_directories(../unixcoreruncommon)
-add_compile_options(-fPIE)
-
set(CORERUN_SOURCES
corerun.cpp
)
project(unixcoreruncommon)
-add_compile_options(-fPIC)
-
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(configure.cmake)
include(configure.cmake)
-add_compile_options(-fPIC)
-
set(NATIVEGLOBALIZATION_SOURCES
pal_calendarData.c
pal_casing.c
add_definitions(-DPAL_STDCPP_COMPAT)
-add_compile_options(-fPIE)
-
set(CREATEDUMP_SOURCES
createdump.cpp
crashinfo.cpp
if(CLR_CMAKE_PLATFORM_UNIX)
include_directories(${GENERATED_INCLUDE_DIR})
- add_compile_options(-fPIC)
endif(CLR_CMAKE_PLATFORM_UNIX)
set(DACCESS_SOURCES
dbgutil.cpp
)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_library_clr(dbgutil STATIC ${DBGUTIL_SOURCES})
endif(WIN32)
if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
add_definitions(-DFEATURE_PAL)
add_definitions(-DPAL_IMPLEMENTATION)
set(CORDBDI_SOURCES_ASM_FILE ${CMAKE_CURRENT_BINARY_DIR}/${name}.obj)
endif()
elseif(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_ARM)
set(CORDBDI_SOURCES_ASM_FILE
include_directories(BEFORE ${VM_DIR}/${ARCH_SOURCES_DIR})
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
set(CORDBEE_SOURCES_DAC_AND_WKS
controller.cpp
debugger.cpp
else ()
- add_compile_options(-fPIC)
-
if(CLR_CMAKE_PLATFORM_ARCH_AMD64 OR CLR_CMAKE_PLATFORM_ARCH_ARM OR CLR_CMAKE_PLATFORM_ARCH_ARM64 OR CLR_CMAKE_PLATFORM_ARCH_I386)
add_library_clr(cordbee_wks ${CORDBEE_SOURCES_WKS} ../${ARCH_SOURCES_DIR}/dbghelpers.S)
else()
symwrite.cpp
)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_library_clr(ildbsymlib ${ILDBSYMLIB_SOURCES})
add_definitions(-DHOST_IS_WINDOWS_OS)
endif(WIN32)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
set(DEBUGSHIM_SOURCES
debugshim.cpp
)
add_library_clr(dbgshim SHARED ${DBGSHIM_SOURCES})
if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-
add_custom_target(dbgshim_exports DEPENDS ${EXPORTS_FILE})
add_dependencies(dbgshim dbgshim_exports)
include(${CLR_DIR}/dac.cmake)
add_definitions(-DFEATURE_NO_HOST)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
set(CLR_DAC_SOURCES
)
string(REPLACE "/guard:cf" "" CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
endif(WIN32)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(full)
# Only add the small version of the resources if the platform is Windows.
install_clr(clrgc)
if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
# dprintf causes many warnings (https://github.com/dotnet/coreclr/issues/13367)
add_compile_options(-Wno-format)
endif(CLR_CMAKE_PLATFORM_UNIX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
-add_compile_options(-fPIC)
include_directories("../env")
include(configure.cmake)
convert_to_absolute_path(GCINFO_SOURCES ${GCINFO_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(lib)
add_subdirectory(crossgen)
include_directories(.)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIE)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
set(ILASM_SOURCES
assem.cpp
writer.cpp
include_directories(..)
if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIE)
build_resources(${CMAKE_CURRENT_SOURCE_DIR}/../dasm.rc dasm_rc TARGET_CPP_FILE)
set(ILDASM_RESOURCES
list(APPEND CORGUIDS_SOURCES ${C_SOURCE})
endforeach(IDL_SOURCE)
-add_compile_options(-fPIC)
endif(WIN32)
if(FEATURE_JIT_PITCHING)
set_source_files_properties(${JIT_EXPORTS_FILE} PROPERTIES GENERATED TRUE)
if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-
add_library_clr(clrjit_static
STATIC
${SHARED_LIB_SOURCES}
../../inc/utilcode.h
)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_precompiled_header(stdafx.h stdafx.cpp CEEFILEGEN_SOURCES)
if (WIN32)
convert_to_absolute_path(MDCOMPILER_SOURCES ${MDCOMPILER_SOURCES})
convert_to_absolute_path(MDCOMPILER_HEADERS ${MDCOMPILER_HEADERS})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(dac)
add_subdirectory(wks)
add_subdirectory(dbi)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
set(MDDATASOURCE_SOURCES
api.cpp
datatargetreader.cpp
convert_to_absolute_path(MDRUNTIMERW_HEADERS ${MDRUNTIMERW_HEADERS})
convert_to_absolute_path(MDRUNTIMERW_SOURCES ${MDRUNTIMERW_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(dac)
add_subdirectory(wks)
add_subdirectory(dbi)
convert_to_absolute_path(MDHOTDATA_HEADERS ${MDHOTDATA_HEADERS})
convert_to_absolute_path(MDHOTDATA_SOURCES ${MDHOTDATA_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(dac)
add_subdirectory(full)
add_subdirectory(crossgen)
convert_to_absolute_path(MDRUNTIME_HEADERS ${MDRUNTIME_HEADERS})
convert_to_absolute_path(MDRUNTIME_SOURCES ${MDRUNTIME_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(dac)
add_subdirectory(wks)
add_subdirectory(dbi)
convert_to_absolute_path(STATICMD_SOURCES ${STATICMD_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
-
add_definitions(-DFEATURE_METADATA_EMIT_ALL)
add_definitions(-DFEATURE_METADATA_EMIT)
add_definitions(-DFEATURE_METADATA_INTERNAL_APIS)
convert_to_absolute_path(MDWINMD_HEADERS ${MDWINMD_HEADERS})
convert_to_absolute_path(MDWINMD_SOURCES ${MDWINMD_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(dac)
add_subdirectory(wks)
if(WIN32)
project(nativeresourcestring)
-add_compile_options(-fPIC)
-
add_library_clr(nativeresourcestring
STATIC
resourcestring.cpp
include_directories(SYSTEM /usr/local/include)
endif()
-add_compile_options(-fPIC)
-
if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
include_directories(libunwind/include)
include_directories(libunwind/include/tdep)
eventproviderhelpers.cpp
)
-add_compile_options(-fPIC)
-
add_library(coreclrtraceptprovider
SHARED
${TRACEPOINT_PROVIDER_SOURCES}
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
add_definitions(-DFEATURE_ENABLE_HARDWARE_EXCEPTIONS)
endif(CLR_CMAKE_PLATFORM_UNIX)
variant.cpp
)
-add_compile_options(-fPIC)
-
add_library_clr(palrt
STATIC
${PALRT_SOURCES}
convert_to_absolute_path(STRONGNAME_SOURCES ${STRONGNAME_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(dac)
add_subdirectory(wks)
add_subdirectory(crossgen)
endif()
if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIE)
add_definitions(-DNO_NGENPDB)
endif(CLR_CMAKE_PLATFORM_UNIX)
convert_to_absolute_path(UNWINDER_SOURCES ${UNWINDER_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
if(CLR_CMAKE_PLATFORM_UNIX)
add_subdirectory(wks)
endif(CLR_CMAKE_PLATFORM_UNIX)
convert_to_absolute_path(UTILCODE_CROSSGEN_SOURCES ${UTILCODE_CROSSGEN_SOURCES})
convert_to_absolute_path(UTILCODE_STATICNOHOST_SOURCES ${UTILCODE_STATICNOHOST_SOURCES})
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
add_subdirectory(dac)
add_subdirectory(dyncrt)
add_subdirectory(staticnohost)
endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
endif(CMAKE_CONFIGURATION_TYPES)
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
if(FEATURE_GDBJIT)
set(VM_SOURCES_GDBJIT
gdbjit.cpp
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()
-if(CLR_CMAKE_PLATFORM_UNIX)
- add_compile_options(-fPIC)
-endif(CLR_CMAKE_PLATFORM_UNIX)
-
MACRO(SUBDIRLIST result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")