NativeAot: Allow disabling -pie flag (#64580)
authorStephan Dollberg <s@stephandollberg.com>
Tue, 1 Feb 2022 02:18:14 +0000 (02:18 +0000)
committerGitHub <noreply@github.com>
Tue, 1 Feb 2022 02:18:14 +0000 (18:18 -0800)
Adds a msbuild property `PositionIndependentExecutable` to the -pie
flag.

While good by default for security reasons they might make binary
incompatible with certain tools.

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

index b49f24e..4e8bbec 100644 (file)
@@ -90,7 +90,7 @@ 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)' == ''" />
+      <LinkerArg Include="-pie" Condition="'$(TargetOS)' != 'OSX' and '$(NativeLib)' == '' 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 -->