Pass -pie and -no-pie to the linker (#81533)
authorAdeel Mujahid <3840695+am11@users.noreply.github.com>
Thu, 2 Feb 2023 16:02:34 +0000 (18:02 +0200)
committerGitHub <noreply@github.com>
Thu, 2 Feb 2023 16:02:34 +0000 (08:02 -0800)
* Pass -pie and -no-pie to the linker

When `PositionIndependentExecutable` is `false`, we need to pass
`-no-pie` to the linker. Otherwise, we need to pass `-pie` to the
linker with `-Wl` because we are not compiling the code at this stage
(only linking the objects).

* Add -pie for non-pie .o (in CentOS 7)

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets

index eb9f333..aac111f 100644 (file)
@@ -134,7 +134,8 @@ The .NET Foundation licenses this file to you under the MIT license.
       <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="-pie -Wl,-pie" Condition="'$(TargetOS)' != 'osx' and '$(NativeLib)' == '' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' != 'false'" />
+      <LinkerArg Include="-Wl,-no-pie" Condition="'$(TargetOS)' != 'osx' and '$(NativeLib)' == '' and '$(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 -->