Skip to content

Commit

Permalink
Pass linker flags to Mono build on Android correctly (#51403)
Browse files Browse the repository at this point in the history
We were setting `_MonoLDFLAGS` in mono.proj but never passed the values down into CMake.
  • Loading branch information
akoeplinger authored Apr 17, 2021
1 parent fbd3b98 commit af1ed05
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ endif()
# Older CMake versions (3.8) do not assign the result of their tests, causing unused-value errors
# which are not distinguished from the test failing. So no error for that one.
# For clang-5.0 avoid errors like "unused variable 'err' [-Werror,-Wunused-variable]".
set(CMAKE_REQUIRED_FLAGS "-Werror -Wno-error=unused-value -Wno-error=unused-variable")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror -Wno-error=unused-value -Wno-error=unused-variable")

# Apple platforms like macOS/iOS allow targeting older operating system versions with a single SDK,
# the mere presence of a symbol in the SDK doesn't tell us whether the deployment target really supports it.
Expand Down
3 changes: 3 additions & 0 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(HOST_LINUX 1)
add_definitions(-D_GNU_SOURCE -D_REENTRANT)
add_definitions(-D_THREAD_SAFE)
add_compile_options(-Wl,-z,now)
add_compile_options(-Wl,-z,relro)
add_compile_options(-Wl,-z,noexecstack)
# The normal check fails because it uses --isystem <ndk root>/sysroot/usr/include
set(HAVE_USR_INCLUDE_MALLOC_H 1)
set(HOST_ANDROID 1)
Expand Down
11 changes: 0 additions & 11 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@
<_MonoCMakeArgs Include="-DCMAKE_OSX_DEPLOYMENT_TARGET=$(macOSVersionMin)" />
<_MonoCFLAGS Condition="'$(TargetArchitecture)' == 'arm64'" Include="-arch arm64" />
<_MonoCXXFLAGS Condition="'$(TargetArchitecture)' == 'arm64'" Include="-arch arm64" />
<_MonoLDFLAGS Condition="'$(TargetArchitecture)' == 'arm64'" Include="-arch arm64" />
<!-- Force running as arm64 even when invoked from an x86 msbuild process -->
<_MonoBuildEnv Condition="'$(BuildArchitecture)' == 'arm64'" Include="arch -arch arm64" />
</ItemGroup>
Expand All @@ -264,7 +263,6 @@
<_MonoCXXFlags Condition="'$(TargetArchitecture)' == 'arm64'" Include="-target arm64-apple-ios14.2-macabi" />
<_MonoCXXFlags Condition="'$(TargetArchitecture)' == 'x64'" Include="-target x86_64-apple-ios13.5-macabi" />
<_MonoCXXFLAGS Condition="'$(TargetArchitecture)' == 'arm64'" Include="-arch arm64" />
<_MonoLDFLAGS Condition="'$(TargetArchitecture)' == 'arm64'" Include="-arch arm64" />
<!-- Force running as arm64 even when invoked from an x86 msbuild process -->
<_MonoBuildEnv Condition="'$(BuildArchitecture)' == 'arm64'" Include="arch -arch arm64" />
</ItemGroup>
Expand Down Expand Up @@ -378,15 +376,6 @@
<_MonoCXXFLAGS Condition="'$(Platform)' == 'arm64' or '$(Platform)' == 'arm'" Include="-DSK_RELEASE" />
<_MonoCXXFLAGS Condition="'$(Platform)' == 'arm64' or '$(Platform)' == 'arm'" Include="-DNDEBUG" />
<_MonoCXXFLAGS Condition="'$(Platform)' == 'arm64' or '$(Platform)' == 'arm'" Include="-UDEBUG" />

<_MonoLDFLAGS Include="-z now" />
<_MonoLDFLAGS Include="-z relro" />
<_MonoLDFLAGS Include="-z noexecstack" />
<_MonoLDFLAGS Include="-ldl" />
<_MonoLDFLAGS Include="-lm" />
<_MonoLDFLAGS Include="-llog" />
<_MonoLDFLAGS Include="-lc" />
<_MonoLDFLAGS Include="-lgcc" />
</ItemGroup>
<!-- Linux options -->
<ItemGroup Condition="'$(TargetsLinux)' == true">
Expand Down

0 comments on commit af1ed05

Please sign in to comment.