Skip to content

Commit 2c2d6df

Browse files
[mono] Fix libcoreclr.so build incompatibilities on Linux (#60077)
Backport of #59988 * Link with -z relro -z now to enable full RELRO mode Fixes #59904 * Generate and link in version.c to provide version string Fixes dotnet/source-build#2484 Co-authored-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
1 parent aeb84f6 commit 2c2d6df

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/mono/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
205205
set(HOST_LINUX 1)
206206
add_definitions(-D_GNU_SOURCE -D_REENTRANT)
207207
add_definitions(-D_THREAD_SAFE)
208+
# Enable the "full RELRO" options (RELRO & BIND_NOW) at link time
209+
add_link_options(-Wl,-z,relro)
210+
add_link_options(-Wl,-z,now)
208211
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
209212
set(HOST_LINUX 1)
210213
add_definitions(-D_GNU_SOURCE -D_REENTRANT)
@@ -724,11 +727,13 @@ endif()
724727
######################################
725728
# EXTRACT VERSION
726729
######################################
727-
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/_version.h")
728-
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
730+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
731+
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/_version.h")
729732
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/_version.h" "#undef VER_PRODUCTVERSION_STR\n#define VER_PRODUCTVERSION_STR \"42.42.42.42424\"\n")
730-
else()
731-
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/_version.h" "static char sccsid[] __attribute__((used)) = \"@(#)Version 42.42.42.42424 @Commit: AAA\";\n")
733+
endif()
734+
else()
735+
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/version.c")
736+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/version.c" "static char sccsid[] __attribute__((used)) = \"@(#)Version 42.42.42.42424 @Commit: AAA\";\n")
732737
endif()
733738
endif()
734739
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/NativeVersion.rc")
@@ -750,7 +755,7 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
750755
file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/_version.h" product_version_string_line REGEX "VER_PRODUCTVERSION_STR ")
751756
string(REGEX REPLACE ".*VER_PRODUCTVERSION_STR *(.*)" "\\1" product_version_string ${product_version_string_line})
752757
else()
753-
file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/_version.h" product_version_string_line REGEX "sccsid")
758+
file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/version.c" product_version_string_line REGEX "sccsid")
754759
string(REGEX REPLACE ".*Version *(.*)\";" "\"\\1\"" product_version_string ${product_version_string_line})
755760
endif()
756761

src/mono/mono.proj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,18 @@
724724
</Target>
725725

726726
<Target Name="GenerateMonoVersionFile" DependsOnTargets="InitializeGenerateRuntimeVersionFile">
727+
<PropertyGroup>
728+
<NativeVersionFile Condition="'$(OS)' == 'Windows_NT'">_version.h</NativeVersionFile>
729+
<NativeVersionFile Condition="'$(OS)' != 'Windows_NT'">version.c</NativeVersionFile>
730+
</PropertyGroup>
731+
727732
<MSBuild Projects="$(RepoRoot)eng\empty.csproj"
728733
Targets="GenerateRuntimeVersionFile"
729-
Properties="NativeVersionFile=$(MonoObjDir)_version.h;RuntimeVersionFile=$(MonoObjDir)runtime_version.h" />
734+
Properties="NativeVersionFile=$(MonoObjDir)$(NativeVersionFile);RuntimeVersionFile=$(MonoObjDir)runtime_version.h" />
730735
<MSBuild Condition="'$(BuildMonoAOTCrossCompiler)' == 'true'"
731736
Projects="$(RepoRoot)eng\empty.csproj"
732737
Targets="GenerateRuntimeVersionFile"
733-
Properties="NativeVersionFile=$(MonoObjCrossDir)_version.h;RuntimeVersionFile=$(MonoObjCrossDir)runtime_version.h" />
738+
Properties="NativeVersionFile=$(MonoObjCrossDir)$(NativeVersionFile);RuntimeVersionFile=$(MonoObjCrossDir)runtime_version.h" />
734739
</Target>
735740

736741
<!-- The standard set of targets that need to run before the BuildMono target runs -->

src/mono/mono/mini/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ endif()
315315

316316
if(HOST_WIN32)
317317
set(mini_sources "${mini_sources};${PROJECT_BINARY_DIR}/../../NativeVersion.rc") # this is generated by GenerateMonoVersionFile in mono.proj
318+
elseif(NOT HOST_BROWSER)
319+
set(mini_sources "${mini_sources};${PROJECT_BINARY_DIR}/../../version.c") # this is generated by GenerateMonoVersionFile in mono.proj
318320
endif()
319321

320322
set(monosgen-sources "${metadata_sources};${utils_sources};${sgen_sources};${icu_shim_sources};${mini_sources};${zlib_sources}")

0 commit comments

Comments
 (0)