Skip to content

Commit e463920

Browse files
am11jkotas
andauthored
Fix a few static linking issues (#81086)
* Fix a few static linking issues * Dedup paths * Update src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets Co-authored-by: Adeel Mujahid <[email protected]> Co-authored-by: Jan Kotas <[email protected]>
1 parent 828edfb commit e463920

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The .NET Foundation licenses this file to you under the MIT license.
2020
<CppLinker>$(CppCompilerAndLinker)</CppLinker>
2121
<CppLibCreator>ar</CppLibCreator>
2222
<DsymUtilOptions Condition="'$(TargetOS)' == 'osx'">--flat</DsymUtilOptions>
23+
<_SymbolPrefix Condition="'$(TargetOS)' == 'osx'">_</_SymbolPrefix>
2324
</PropertyGroup>
2425

2526
<Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)">
@@ -79,15 +80,15 @@ The .NET Foundation licenses this file to you under the MIT license.
7980
</ItemGroup>
8081

8182
<ItemGroup Condition="'$(StaticICULinking)' == 'true' and '$(NativeLib)' != 'Static'">
82-
<NativeLibrary Include="$(IntermediateOutputPath)/libs/System.Globalization.Native/build/libSystem.Globalization.Native.a"/>
83+
<NativeLibrary Include="$(IntermediateOutputPath)libs/System.Globalization.Native/build/libSystem.Globalization.Native.a" />
8384
<DirectPInvoke Include="libSystem.Globalization.Native" />
8485
<StaticICULibs Include="-Wl,-Bstatic" Condition="'$(StaticExecutable)' != 'true'" />
8586
<StaticICULibs Include="-licuio -licutu -licui18n -licuuc -licudata -lstdc++" />
8687
<StaticICULibs Include="-Wl,-Bdynamic" Condition="'$(StaticExecutable)' != 'true'" />
8788
</ItemGroup>
8889

8990
<ItemGroup Condition="'$(StaticOpenSslLinking)' == 'true' and '$(NativeLib)' != 'Static'">
90-
<NativeLibrary Include="$(IntermediateOutputPath)/libs/System.Security.Cryptography.Native/build/libSystem.Security.Cryptography.Native.OpenSsl.a"/>
91+
<NativeLibrary Include="$(IntermediateOutputPath)libs/System.Security.Cryptography.Native/build/libSystem.Security.Cryptography.Native.OpenSsl.a" />
9192
<DirectPInvoke Include="libSystem.Security.Cryptography.Native.OpenSsl" />
9293
<StaticSslLibs Include="-Wl,-Bstatic" Condition="'$(StaticExecutable)' != 'true'" />
9394
<StaticSslLibs Include="-lssl -lcrypto" />
@@ -102,13 +103,8 @@ The .NET Foundation licenses this file to you under the MIT license.
102103
<NativeFramework Include="GSS" />
103104
</ItemGroup>
104105

105-
<Exec Command="&quot;$(IlcHostPackagePath)/native/src/libs/build-local.sh&quot; &quot;$(IlcHostPackagePath)/&quot; &quot;$(IntermediateOutputPath)&quot; System.Globalization.Native" Condition="'$(StaticICULinking)' == 'true'"/>
106-
107-
<Exec Command="&quot;$(IlcHostPackagePath)/native/src/libs/build-local.sh&quot; &quot;$(IlcHostPackagePath)/&quot; &quot;$(IntermediateOutputPath)&quot; System.Security.Cryptography.Native" Condition="'$(StaticOpenSslLinking)' == 'true'"/>
108-
109106
<ItemGroup>
110107
<LinkerArg Include="-fuse-ld=lld" Condition="'$(UseLLVMLinker)' == 'true'" />
111-
<LinkerArg Include="-static" Condition="'$(StaticExecutable)' == 'true'" />
112108
<LinkerArg Include="@(NativeLibrary)" />
113109
<LinkerArg Include="--sysroot=$(SysRoot)" Condition="'$(SysRoot)' != ''" />
114110
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetOS)' != 'osx' and '$(TargetTriple)' != ''" />
@@ -122,7 +118,6 @@ The .NET Foundation licenses this file to you under the MIT license.
122118
<LinkerArg Include="-pthread" Condition="'$(TargetOS)' != 'osx'" />
123119
<LinkerArg Include="-lstdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
124120
<LinkerArg Include="-ldl" />
125-
<LinkerArg Include="-lm" />
126121
<LinkerArg Include="-lobjc" Condition="'$(TargetOS)' == 'osx'" />
127122
<LinkerArg Include="-lswiftCore" Condition="'$(TargetOS)' == 'osx'" />
128123
<LinkerArg Include="-lswiftFoundation" Condition="'$(TargetOS)' == 'osx'" />
@@ -133,6 +128,8 @@ The .NET Foundation licenses this file to you under the MIT license.
133128
<LinkerArg Include="@(StaticNumaLibs)" Condition="'$(StaticNumaLinking)' == 'true'" />
134129
<LinkerArg Include="@(StaticICULibs)" Condition="'$(StaticICULinking)' == 'true'" />
135130
<LinkerArg Include="@(StaticSslLibs)" Condition="'$(StaticOpenSslLinking)' == 'true'" />
131+
<LinkerArg Include="-lm" />
132+
<LinkerArg Include="-static" Condition="'$(StaticExecutable)' == 'true'" />
136133
<LinkerArg Include="-dynamiclib" Condition="'$(TargetOS)' == 'osx' and '$(NativeLib)' == 'Shared'" />
137134
<LinkerArg Include="-shared" Condition="'$(TargetOS)' != 'osx' and '$(NativeLib)' == 'Shared'" />
138135
<!-- binskim warning BA3001 PIE disabled on executable -->
@@ -142,8 +139,12 @@ The .NET Foundation licenses this file to you under the MIT license.
142139
<LinkerArg Include="-Wl,-z,relro" Condition="'$(TargetOS)' != 'osx'" />
143140
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
144141
<LinkerArg Include="-Wl,-z,now" Condition="'$(TargetOS)' != 'osx'" />
145-
<LinkerArg Include="-Wl,-u,_NativeAOT_StaticInitialization" Condition="('$(UseLLVMLinker)' == 'true' or '$(TargetOS)' == 'osx' or '$(TargetOS)' == 'freebsd') and '$(NativeLib)' == 'Shared'" />
142+
<LinkerArg Include="-Wl,-u,$(_SymbolPrefix)NativeAOT_StaticInitialization" Condition="('$(UseLLVMLinker)' == 'true' or '$(TargetOS)' == 'osx' or '$(TargetOS)' == 'freebsd') and '$(NativeLib)' == 'Shared'" />
146143
<LinkerArg Include="-Wl,--require-defined,NativeAOT_StaticInitialization" Condition="'$(UseLLVMLinker)' != 'true' and '$(TargetOS)' == 'linux' and '$(NativeLib)' == 'Shared'" />
144+
<!-- this workaround can be deleted once the minimum supported glibc version
145+
(runtime's official build machine's glibc version) is at least 2.33
146+
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
147+
<LinkerArg Include="-Wl,--defsym,__xmknod=mknod" Condition="'$(StaticExecutable)' == 'true'" />
147148
<!-- FreeBSD has two versions of the GSSAPI it can use, but we only use the ports version (MIT version) here -->
148149
<LinkerArg Include="-L/usr/local/lib -lgssapi_krb5" Condition="'$(TargetOS)' == 'freebsd'" />
149150
<!-- FreeBSD's inotify is an installed package and not found in default libraries -->
@@ -207,6 +208,12 @@ The .NET Foundation licenses this file to you under the MIT license.
207208
<Output TaskParameter="ExitCode" PropertyName="_DsymUtilOutput" />
208209
</Exec>
209210

211+
<Exec Command="CC=&quot;$(CppLinker)&quot; &quot;$(IlcHostPackagePath)/native/src/libs/build-local.sh&quot; &quot;$(IlcHostPackagePath)/&quot; &quot;$(IntermediateOutputPath)&quot; System.Globalization.Native"
212+
Condition="'$(StaticICULinking)' == 'true'" />
213+
214+
<Exec Command="CC=&quot;$(CppLinker)&quot; &quot;$(IlcHostPackagePath)/native/src/libs/build-local.sh&quot; &quot;$(IlcHostPackagePath)/&quot; &quot;$(IntermediateOutputPath)&quot; System.Security.Cryptography.Native"
215+
Condition="'$(StaticOpenSslLinking)' == 'true'" />
216+
210217
<PropertyGroup Condition="'$(TargetOS)' == 'osx' and '$(StripSymbols)' == 'true' and $(_DsymUtilOutput.Contains('--minimize'))">
211218
<DsymUtilOptions>$(DsymUtilOptions) --minimize</DsymUtilOptions>
212219
</PropertyGroup>

src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<File Include="$(MibcOptimizationDataDir)/$(TargetOS)/$(TargetArchitecture)/**/*.mibc" TargetPath="mibc" />
1818
</ItemGroup>
1919
<ItemGroup Condition="'$(PackageTargetRuntime)' != '' and '$(TargetOS)' == 'linux'">
20-
<File Include="$(MSBuildThisFileDirectory)\..\..\..\..\native\libs\System.Globalization.Native\*" TargetPath="native/src/libs/System.Globalization.Native"/>
21-
<File Include="$(MSBuildThisFileDirectory)\..\..\..\..\native\libs\System.Security.Cryptography.Native\*" TargetPath="native/src/libs/System.Security.Cryptography.Native"/>
22-
<File Include="$(MSBuildThisFileDirectory)\..\..\..\..\native\libs\build-local.sh" TargetPath="native/src/libs/build-local.sh"/>
23-
<File Include="$(MSBuildThisFileDirectory)\..\..\..\..\native\minipal\*" TargetPath="native/src/minipal"/>
24-
<File Include="$(MSBuildThisFileDirectory)\..\..\..\..\native\libs\Common\*" TargetPath="native/src/libs/Common"/>
20+
<File Include="$(SharedNativeRoot)libs\System.Globalization.Native\*" TargetPath="native/src/libs/System.Globalization.Native"/>
21+
<File Include="$(SharedNativeRoot)libs\System.Security.Cryptography.Native\*" TargetPath="native/src/libs/System.Security.Cryptography.Native"/>
22+
<File Include="$(SharedNativeRoot)libs\build-local.sh" TargetPath="native/src/libs/build-local.sh"/>
23+
<File Include="$(SharedNativeRoot)minipal\*" TargetPath="native/src/minipal"/>
24+
<File Include="$(SharedNativeRoot)libs\Common\*" TargetPath="native/src/libs/Common"/>
2525
</ItemGroup>
2626

2727
<ItemGroup>

0 commit comments

Comments
 (0)