Improve -static-pie support (#81163)
authorAdeel Mujahid <3840695+am11@users.noreply.github.com>
Fri, 27 Jan 2023 00:48:15 +0000 (02:48 +0200)
committerGitHub <noreply@github.com>
Fri, 27 Jan 2023 00:48:15 +0000 (16:48 -0800)
src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
src/native/libs/System.Globalization.Native/CMakeLists.txt
src/native/libs/System.Security.Cryptography.Native/CMakeLists.txt

index 43ba381..7d113d3 100644 (file)
@@ -111,7 +111,7 @@ The .NET Foundation licenses this file to you under the MIT license.
       <LinkerArg Include="-arch $(CrossCompileArch)" Condition="'$(TargetOS)' == 'osx' and '$(CrossCompileArch)' != ''" />
       <LinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
       <LinkerArg Include="-Wl,--strip-debug" Condition="$(NativeDebugSymbols) != 'true' and '$(TargetOS)' != 'osx'" />
-      <LinkerArg Include="-Wl,-rpath,'$(IlcRPath)'" />
+      <LinkerArg Include="-Wl,-rpath,'$(IlcRPath)'" Condition="'$(StaticExecutable)' != 'true'" />
       <LinkerArg Include="-Wl,--build-id=sha1" Condition="'$(TargetOS)' != 'osx'" />
       <LinkerArg Include="-Wl,--as-needed" Condition="'$(TargetOS)' != 'osx'" />
       <LinkerArg Include="-Wl,-e0x0" Condition="'$(NativeLib)' == 'Shared' and '$(TargetOS)' != 'osx'" />
@@ -129,12 +129,12 @@ The .NET Foundation licenses this file to you under the MIT license.
       <LinkerArg Include="@(StaticICULibs)" Condition="'$(StaticICULinking)' == 'true'" />
       <LinkerArg Include="@(StaticSslLibs)" Condition="'$(StaticOpenSslLinking)' == 'true'" />
       <LinkerArg Include="-lm" />
-      <LinkerArg Include="-static" Condition="'$(StaticExecutable)' == 'true'" />
+      <LinkerArg Include="-static" Condition="'$(StaticExecutable)' == 'true' and '$(PositionIndependentExecutable)' == 'false'" />
+      <LinkerArg Include="-static-pie" Condition="'$(StaticExecutable)' == 'true' and '$(PositionIndependentExecutable)' != 'false'" />
       <LinkerArg Include="-dynamiclib" Condition="'$(TargetOS)' == 'osx' and '$(NativeLib)' == 'Shared'" />
       <LinkerArg Include="-shared" Condition="'$(TargetOS)' != 'osx' and '$(NativeLib)' == 'Shared'" />
       <!-- binskim warning BA3001 PIE disabled on executable -->
       <LinkerArg Include="-pie" Condition="'$(TargetOS)' != 'osx' and '$(NativeLib)' == '' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' != 'false'" />
-      <LinkerArg Include="-static-pie" Condition="'$(StaticExecutable)' == 'true' and '$(PositionIndependentExecutable)' != 'false'" />
       <!-- binskim warning BA3010 The GNU_RELRO segment is missing -->
       <LinkerArg Include="-Wl,-z,relro" Condition="'$(TargetOS)' != 'osx'" />
       <!-- binskim warning BA3011 The BIND_NOW flag is missing -->
index 0ee4e40..bbf9737 100644 (file)
@@ -60,6 +60,7 @@ set(NATIVEGLOBALIZATION_SOURCES
 )
 
 if (LOCAL_BUILD)
+    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
     set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c)
     add_definitions(-DLOCAL_BUILD)
     add_definitions(-DSTATIC_ICU)
index 3d55bb8..7278e31 100644 (file)
@@ -45,6 +45,7 @@ set(NATIVECRYPTO_SOURCES
 )
 
 if (LOCAL_BUILD)
+    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
     add_definitions(-DLOCAL_BUILD)
     add_definitions(-DPALEXPORT=EXTERN_C)
     add_definitions(-DTARGET_UNIX)