Microsoft MVP성태의 닷넷 이야기
닷넷: 2202. C# - PublishAot의 glibc에 대한 정적 링킹하는 방법 [링크 복사], [링크+제목 복사],
조회: 2193
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 6개 있습니다.)
개발 환경 구성: 386. .NET Framework Native compiler 프리뷰 버전 사용법
; https://www.sysnet.pe.kr/2/0/11563

.NET Framework: 2069. .NET 7 - AOT(ahead-of-time) 컴파일
; https://www.sysnet.pe.kr/2/0/13162

닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
; https://www.sysnet.pe.kr/2/0/13466

닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법
; https://www.sysnet.pe.kr/2/0/13483

개발 환경 구성: 696. C# - 리눅스용 AOT 빌드를 docker에서 수행
; https://www.sysnet.pe.kr/2/0/13487

닷넷: 2202. C# - PublishAot의 glibc에 대한 정적 링킹하는 방법
; https://www.sysnet.pe.kr/2/0/13529




C# - PublishAot의 glibc에 대한 정적 링킹하는 방법

지난 글에서,

C# - 리눅스용 AOT 빌드를 docker에서 수행
; https://www.sysnet.pe.kr/2/0/13487

PublishAot 빌드 시 해당 운영체제 환경의 glibc 의존성 문제가 있다고 했습니다. 일례로 Ubuntu 18.04 이미지에서 빌드하면,

# ls -l ConsoleApp1
-rwxr-xr-x 1 root root 2345024 Jan 14 14:50 ConsoleApp1

# ldd --version
ldd (Ubuntu GLIBC 2.31-0ubuntu9.14) 2.31

# objdump -p ConsoleApp1
...[생략]...
Version References:
  required from ld-linux-x86-64.so.2:
    0x0d696913 0x00 16 GLIBC_2.3
  required from libdl.so.2:
    0x09691a75 0x00 12 GLIBC_2.2.5
  required from libm.so.6:
    0x06969189 0x00 17 GLIBC_2.29
    0x09691a75 0x00 06 GLIBC_2.2.5
  required from libc.so.6:
    0x06969190 0x00 15 GLIBC_2.10
    0x09691974 0x00 14 GLIBC_2.3.4
    0x0d696914 0x00 13 GLIBC_2.4
    0x06969197 0x00 10 GLIBC_2.17
    0x06969194 0x00 09 GLIBC_2.14
    0x0d696919 0x00 08 GLIBC_2.9
    0x0d696916 0x00 05 GLIBC_2.6
    0x09691a75 0x00 04 GLIBC_2.2.5
  required from libpthread.so.0:
    0x09691973 0x00 11 GLIBC_2.3.3
    0x06969192 0x00 07 GLIBC_2.12
    0x09691a75 0x00 03 GLIBC_2.2.5
    0x09691972 0x00 02 GLIBC_2.3.2

이렇게 최소 GLIBC_2.29에 대한 의존성이 생깁니다. (그나저나, 지난번에 동일한 환경에서 빌드할 때는 "GLIBC_2.16"이 최고였고, 우분투 18.04의 ldd 버전이 2.27이었는데 그새 뭔가 바뀌었군요. ^^;)

어쨌든 이런 이유로 인해 제한된 컨테이너 환경, 가령 busybox에서는 실행할 수 없습니다. 결국 이 문제를 해결하려면 glibc에 대한 정적 링킹이 필요한데요, 문서에 의하면 AOT 빌드 시 링커 측으로 옵션을 전달하는 것이 가능하지만,

Native code interop with Native AOT - Linking
; https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/interop#linking

정적 링킹 옵션을 의도적으로 설정하는 경우,

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <PublishAot>true</PublishAot>
        <InvariantGlobalization>true</InvariantGlobalization>
    </PropertyGroup>

    <ItemGroup>
        <LinkerArg Include="-static" Condition="$(RuntimeIdentifier.StartsWith('linux'))" />
    </ItemGroup>

</Project>

이런 오류가 발생합니다.

clang : warning : argument unused during compilation: '-pie' [-Wunused-command-line-argument] [/app/ConsoleApp1.csproj]
  /usr/bin/ld.bfd: /usr/bin/ld.bfd: DWARF error: invalid or unhandled FORM value: 0x25
  /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Native.a(pal_uid.c.o): in function `SystemNative_GetGroupList':
  pal_uid.c:(.text.SystemNative_GetGroupList+0x64): warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
  /usr/bin/ld.bfd: /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Native.a(pal_uid.c.o): in function `SystemNative_GetGroupName':
  pal_uid.c:(.text.SystemNative_GetGroupName+0x60): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
  /usr/bin/ld.bfd: /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Native.a(pal_uid.c.o): in function `SystemNative_GetPwNamR':
  pal_uid.c:(.text.SystemNative_GetPwNamR+0x50): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
  /usr/bin/ld.bfd: /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Native.a(pal_uid.c.o): in function `SystemNative_GetPwUidR':
  pal_uid.c:(.text.SystemNative_GetPwUidR+0x50): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
  /usr/bin/ld.bfd: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a PIE object
clang : error : linker command failed with exit code 1 (use -v to see invocation) [/app/ConsoleApp1.csproj]
/root/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.0/build/Microsoft.NETCore.Native.targets(364,5): error MSB3073: The command ""clang" "obj/Release/net8.0/linux-x64/native/ConsoleApp1.o" -o "bin/Release/net8.0/linux-x64/native/ConsoleApp1" -static -gz=zlib -fuse-ld=bfd /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libbootstrapper.o /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libRuntime.WorkstationGC.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libeventpipe-disabled.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libstdc++compat.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.IO.Compression.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Net.Security.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Security.Cryptography.Native.OpenSsl.a -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -ldl -lz -lrt -lm -pie -Wl,-pie -Wl,-z,relro -Wl,-z,now -Wl,--eh-frame-hdr -Wl,--discard-all -Wl,--gc-sections" exited with code 1. [/app/ConsoleApp1.csproj]

리눅스 환경에서의 빌드 경험이 거의 없어서, 도대체 저 에러가 왜 나는지 모르겠습니다. ^^; 그렇긴 한데, 분명히 clang 빌드에 대한 옵션에서 "-static" 옵션이 붙긴 했습니다.

"clang" "obj/Release/net8.0/linux-x64/native/ConsoleApp1.o" -o "bin/Release/net8.0/linux-x64/native/ConsoleApp1" -static -gz=zlib -fuse-ld=bfd /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libbootstrapper.o /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libRuntime.WorkstationGC.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libeventpipe-disabled.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libstdc++compat.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.IO.Compression.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Net.Security.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Security.Cryptography.Native.OpenSsl.a -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -ldl -lz -lrt -lm -pie -Wl,-pie -Wl,-z,relro -Wl,-z,now -Wl,--eh-frame-hdr -Wl,--discard-all -Wl,--gc-sections





방법이 없을까 싶어, 여기저기 살펴봤더니 또 다른 옵션들을 찾을 수 있었습니다. 일례로 다음의 경우,

Remove libstdc++ dependency from NativeAOT #76705
; https://github.com/dotnet/runtime/pull/76705/files#diff-a8c821001409a0c4d6589a59e663d4d07e53b0127b345f17640410828c580b37

LinkStandardCPlusPlusLibrary 옵션이 보입니다. PublishAot의 기본 빌드에서는 C++에 대한 (동적 모듈의) 의존성은 없지만, 다음과 같이 옵션을 추가하면,

<LinkStandardCPlusPlusLibrary>false</LinkStandardCPlusPlusLibrary>

이제는 바이너리에 libstdc++.so.6 모듈에 대한 동적 링킹이 됩니다.

# objdump -p ConsoleApp1
...[생략]...
Version References:
  required from ld-linux-x86-64.so.2:
    0x0d696913 0x00 15 GLIBC_2.3
  required from libdl.so.2:
    0x09691a75 0x00 14 GLIBC_2.2.5
  required from libstdc++.so.6:
    0x08922974 0x00 06 GLIBCXX_3.4
...[생략]...

혹시 그렇다면 LinkStandardCLibrary와 같은 옵션은 없을까요? 아쉽게도 테스트를 해보면 아무런 영향이 없습니다. 그런데, 위의 글에서 뜻밖의 수확을 얻었습니다. 바로 "Microsoft.NETCore.Native.Unix.targets" 파일에서 관련 빌드가 이뤄진다는 것인데요, 그리하여 ILCompiler 패키지에서 해당 파일을 찾아보면 더 많은 힌트를 얻을 수 있습니다.

그리고 바로 저 파일에, 바로 우리가 그토록 원했던 StaticExecutable 옵션이 나옵니다.

...[생략]...
<LinkerArg Include="-static" Condition="'$(StaticExecutable)' == 'true' and '$(PositionIndependentExecutable)' == 'false'" />
<LinkerArg Include="-static-pie" Condition="'$(StaticExecutable)' == 'true' and '$(PositionIndependentExecutable)' != 'false'" />
...[생략]...

저렇게 "-static"을 주고 있으니 위에서 우리가 LinkgerArg로 줬던 것과 같습니다. 단지, 저 옵션으로 인해 변경되는 다른 옵션들이 있는데 그런 것까지 맞춰준다면 LinkgerArg로도 빌드가 잘 되었을 것입니다. 어쨌든, 그런 수고를 할 필요 없이 우리는 다음과 같이 옵션을 주면 됩니다.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <PublishAot>true</PublishAot>
        <InvariantGlobalization>true</InvariantGlobalization>
        <StaticExecutable>true</StaticExecutable>
    </PropertyGroup>

</Project>

이렇게 빌드하면 (지난 글의 예제 코드로) 3,439,160 바이트의 실행 파일이 생성되는데요, glibc에 대한 동적 링킹이었을 때 2,345,024 바이트였던 것에 비하면 정적 링킹이 된 것 같습니다. 게다가 ldd의 명령어에서도,

# ldd ConsoleApp1
        statically linked

"statically linked"라고 나옵니다. 하지만, Go나 C++의 경우 위의 결과가 "not a dynamic executable"로 나왔었는데... 약간 이상하긴 합니다. 게다가 file로 살펴보면,

$ file ConsoleApp1
ConsoleApp1: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, for GNU/Linux 3.2.0, stripped

기대했던 "statically linked"가 아닌 "dynamically"라고 나옵니다. 그럼에도 불구하고 "objdump -p"로 살펴보면 각종 glibc에 대한 의존성이 없어지긴 했습니다. 저런 이상한 결과들을 모두 차치하고, 우리가 진짜 원하는 것은 실행 시 glibc 의존을 갖느냐 하는 것인데요, 따라서 busybox에서 실행해 보면 그 답을 알 수 있습니다. ^^

busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
; https://www.sysnet.pe.kr/2/0/13528

결과는 ^^ 잘 실행이 됩니다.




참고로, 아래는 Microsoft.NETCore.Native.Unix.targets 파일의 전문을 실었으니 원하는 옵션이 있는지 찾아보시면 됩니다. ^^

<!--
***********************************************************************************************
Microsoft.NETCore.Native.Unix.targets

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

This file defines the steps in the build process specific for native AOT compilation.

Licensed to the .NET Foundation under one or more agreements.
The .NET Foundation licenses this file to you under the MIT license.
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <CppCompilerAndLinkerAlternative />
    <CppCompilerAndLinkerAlternative Condition="'$(CppCompilerAndLinker)' == '' and '$(_IsApplePlatform)' != 'true'">gcc</CppCompilerAndLinkerAlternative>
    <CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
    <CppLinker>$(CppCompilerAndLinker)</CppLinker>
    <CppLibCreator>ar</CppLibCreator>
    <_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
    <LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
    <LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
    <LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
  </PropertyGroup>

  <Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)">

    <PropertyGroup>
      <FullRuntimeName>libRuntime.WorkstationGC</FullRuntimeName>
      <FullRuntimeName Condition="'$(ServerGarbageCollection)' == 'true'">libRuntime.ServerGC</FullRuntimeName>

      <CrossCompileRid />
      <CrossCompileRid Condition="!$(RuntimeIdentifier.EndsWith('-$(_hostArchitecture)'))">$(RuntimeIdentifier)</CrossCompileRid>

      <CrossCompileArch />
      <CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-x64'))">x86_64</CrossCompileArch>
      <CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-arm64')) and '$(_IsApplePlatform)' != 'true'">aarch64</CrossCompileArch>
      <CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-arm64')) and '$(_IsApplePlatform)' == 'true'">arm64</CrossCompileArch>

      <TargetTriple />
      <TargetTriple Condition="'$(CrossCompileArch)' != ''">$(CrossCompileArch)-linux-gnu</TargetTriple>
      <TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('linux-musl')) or $(CrossCompileRid.StartsWith('alpine')))">$(CrossCompileArch)-alpine-linux-musl</TargetTriple>
      <TargetTriple Condition="'$(CrossCompileArch)' != '' and $(CrossCompileRid.StartsWith('linux-bionic'))">$(CrossCompileArch)-linux-android21</TargetTriple>
      <TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>

      <IlcRPath Condition="'$(IlcRPath)' == '' and '$(_IsApplePlatform)' != 'true'">$ORIGIN</IlcRPath>
      <IlcRPath Condition="'$(IlcRPath)' == '' and '$(_IsApplePlatform)' == 'true'">@executable_path</IlcRPath>

      <EventPipeName>libeventpipe-disabled</EventPipeName>
      <EventPipeName Condition="'$(EventSourceSupport)' == 'true'">libeventpipe-enabled</EventPipeName>

      <LinkStandardCPlusPlusLibrary Condition="'$(LinkStandardCPlusPlusLibrary)' == '' and '$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'">true</LinkStandardCPlusPlusLibrary>
    </PropertyGroup>

    <ItemGroup>
      <NativeLibrary Condition="'$(IlcMultiModule)' == 'true'" Include="$(SharedLibrary)" />
      <NativeLibrary Condition="'$(NativeLib)' == '' and '$(CustomNativeMain)' != 'true'" Include="$(IlcSdkPath)libbootstrapper.o" />
      <NativeLibrary Condition="'$(NativeLib)' != '' or '$(CustomNativeMain)' == 'true'" Include="$(IlcSdkPath)libbootstrapperdll.o" />
      <NativeLibrary Include="$(IlcSdkPath)$(FullRuntimeName).a" />
      <NativeLibrary Include="$(IlcSdkPath)$(EventPipeName)$(LibFileExt)" />
      <NativeLibrary Condition="'$(LinkStandardCPlusPlusLibrary)' != 'true' and '$(StaticICULinking)' != 'true'" Include="$(IlcSdkPath)libstdc++compat.a" />
    </ItemGroup>

    <ItemGroup>
      <NetCoreAppNativeLibrary Include="System.Native" />
      <NetCoreAppNativeLibrary Include="System.Globalization.Native" Condition="'$(StaticICULinking)' != 'true' and '$(InvariantGlobalization)' != 'true'" />
      <NetCoreAppNativeLibrary Include="System.IO.Compression.Native" />
      <NetCoreAppNativeLibrary Include="System.Net.Security.Native" Condition="!$(_targetOS.StartsWith('tvos')) and '$(_linuxLibcFlavor)' != 'bionic'" />
      <NetCoreAppNativeLibrary Include="System.Security.Cryptography.Native.Apple" Condition="'$(_IsApplePlatform)' == 'true'" />
      <!-- Not compliant for iOS-like platforms -->
      <NetCoreAppNativeLibrary Include="System.Security.Cryptography.Native.OpenSsl" Condition="'$(StaticOpenSslLinking)' != 'true' and '$(_IsiOSLikePlatform)' != 'true'" />
      <NetCoreAppNativeLibrary Include="icudata" Condition="'$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'" />
      <NetCoreAppNativeLibrary Include="icui18n" Condition="'$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'" />
      <NetCoreAppNativeLibrary Include="icuuc" Condition="'$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'" />
    </ItemGroup>

    <ItemGroup>
      <DirectPInvoke Include="@(NetCoreAppNativeLibrary->'lib%(Identity)')" />
      <NetCoreAppNativeLibrary Include="@(NetCoreAppNativeLibrary->'%(Identity)')">
        <EscapedPath>$(IlcFrameworkNativePath)lib%(Identity).a</EscapedPath>
      </NetCoreAppNativeLibrary>
      <NativeLibrary Include="@(NetCoreAppNativeLibrary->'%(EscapedPath)')" />
    </ItemGroup>

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

    <ItemGroup Condition="'$(StaticOpenSslLinking)' == 'true' and '$(NativeLib)' != 'Static'">
      <NativeLibrary Include="$(IntermediateOutputPath)libs/System.Security.Cryptography.Native/build/libSystem.Security.Cryptography.Native.OpenSsl.a" />
      <DirectPInvoke Include="libSystem.Security.Cryptography.Native.OpenSsl" />
      <StaticSslLibs Include="-Wl,-Bstatic" Condition="'$(StaticExecutable)' != 'true'" />
      <StaticSslLibs Include="-lssl -lcrypto" />
      <StaticSslLibs Include="-Wl,-Bdynamic" Condition="'$(StaticExecutable)' != 'true'" />
    </ItemGroup>

    <ItemGroup Condition="'$(_IsApplePlatform)' == 'true'">
      <NativeFramework Include="CoreFoundation" />
      <NativeFramework Condition="'$(_targetOS)' == 'osx'" Include="CryptoKit" />
      <NativeFramework Include="Foundation" />
      <NativeFramework Include="Security" />
      <!-- The library builds don't reference the GSS API on tvOS builds. -->
      <NativeFramework Condition="!$(_targetOS.StartsWith('tvos'))" Include="GSS" />
    </ItemGroup>

    <ItemGroup>
      <NativeSystemLibrary Include="stdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
      <NativeSystemLibrary Include="dl" />
      <NativeSystemLibrary Include="objc" Condition="'$(_IsApplePlatform)' == 'true'" />
      <NativeSystemLibrary Include="swiftCore" Condition="'$(_targetOS)' == 'osx'" />
      <NativeSystemLibrary Include="swiftFoundation" Condition="'$(_targetOS)' == 'osx'" />
      <NativeSystemLibrary Include="z" />
      <NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
      <NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
      <NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
      <NativeSystemLibrary Include="m" />
    </ItemGroup>

    <ItemGroup>
      <ExtraLinkerArg Include="-segprot,__THUNKS,rx,rx" Condition="'$(_IsApplePlatform)' == 'true'" />
    </ItemGroup>

    <ItemGroup>
      <LinkerArg Include="-gz=zlib" Condition="'$(CompressSymbols)' != 'false'" />
      <LinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''" />
      <LinkerArg Include="@(NativeLibrary)" />
      <LinkerArg Include="--sysroot=$(SysRoot)" Condition="'$(SysRoot)' != ''" />
      <LinkerArg Include="--target=$(TargetTriple)" Condition="'$(_IsApplePlatform)' != 'true' and '$(TargetTriple)' != ''" />
      <LinkerArg Include="-arch $(CrossCompileArch)" Condition="'$(_IsApplePlatform)' == 'true' and '$(CrossCompileArch)' != ''" />
      <LinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
      <LinkerArg Include="-Wl,--strip-debug" Condition="$(NativeDebugSymbols) != 'true' and '$(_IsApplePlatform)' != 'true'" />
      <LinkerArg Include="-Wl,-rpath,'$(IlcRPath)'" Condition="'$(StaticExecutable)' != 'true' and !$([MSBuild]::IsOSPlatform('Windows'))" />
      <LinkerArg Include="-Wl,-rpath,&quot;$(IlcRPath)&quot;" Condition="'$(StaticExecutable)' != 'true' and $([MSBuild]::IsOSPlatform('Windows'))" />
      <LinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" />
      <LinkerArg Include="-Wl,--as-needed" Condition="'$(_IsApplePlatform)' != 'true'" />
      <LinkerArg Include="-Wl,-e0x0" Condition="'$(NativeLib)' == 'Shared' and '$(_IsApplePlatform)' != 'true'" />
      <LinkerArg Include="-pthread" Condition="'$(_IsApplePlatform)' != 'true'" />
      <LinkerArg Include="@(NativeSystemLibrary->'-l%(Identity)')" />
      <LinkerArg Include="-L/usr/lib/swift" Condition="'$(_targetOS)' == 'osx'" />
      <LinkerArg Include="@(StaticICULibs)" Condition="'$(StaticICULinking)' == 'true'" />
      <LinkerArg Include="@(StaticSslLibs)" Condition="'$(StaticOpenSslLinking)' == 'true'" />
      <LinkerArg Include="-static" Condition="'$(StaticExecutable)' == 'true' and '$(PositionIndependentExecutable)' == 'false'" />
      <LinkerArg Include="-static-pie" Condition="'$(StaticExecutable)' == 'true' and '$(PositionIndependentExecutable)' != 'false'" />
      <LinkerArg Include="-dynamiclib" Condition="'$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'" />
      <LinkerArg Include="-shared" Condition="'$(_IsApplePlatform)' != 'true' and '$(NativeLib)' == 'Shared'" />
      <!-- binskim warning BA3001 PIE disabled on executable -->
      <LinkerArg Include="-pie -Wl,-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(NativeLib)' == '' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' != 'false'" />
      <LinkerArg Include="-Wl,-no-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(NativeLib)' == '' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' == 'false'" />
      <!-- binskim warning BA3010 The GNU_RELRO segment is missing -->
      <LinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
      <!-- binskim warning BA3011 The BIND_NOW flag is missing -->
      <LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
      <!-- this workaround can be deleted once the minimum supported glibc version
           (runtime's official build machine's glibc version) is at least 2.33
           see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
      <LinkerArg Include="-Wl,--defsym,__xmknod=mknod" Condition="'$(StaticExecutable)' == 'true'" />
      <!-- FreeBSD has two versions of the GSSAPI it can use, but we only use the ports version (MIT version) here -->
      <LinkerArg Include="-L/usr/local/lib -lgssapi_krb5" Condition="'$(_targetOS)' == 'freebsd'" />
      <!-- FreeBSD's inotify is an installed package and not found in default libraries  -->
      <LinkerArg Include="-L/usr/local/lib -linotify" Condition="'$(_targetOS)' == 'freebsd'" />
      <LinkerArg Include="@(ExtraLinkerArg->'-Wl,%(Identity)')" />
      <LinkerArg Include="@(NativeFramework->'-framework %(Identity)')" Condition="'$(_IsApplePlatform)' == 'true'" />
      <LinkerArg Include="-Wl,--eh-frame-hdr" Condition="'$(_IsApplePlatform)' != 'true'" />
    </ItemGroup>

    <PropertyGroup>
      <_CommandProbe>command -v</_CommandProbe>
      <_CommandProbe Condition="$([MSBuild]::IsOSPlatform('Windows'))">where /Q</_CommandProbe>
    </PropertyGroup>

    <Exec Command="$(_CommandProbe) &quot;$(CppLinker)&quot;" IgnoreExitCode="true" StandardOutputImportance="Low">
      <Output TaskParameter="ExitCode" PropertyName="_WhereLinker" />
    </Exec>

    <Exec Command="$(_CommandProbe) &quot;$(CppCompilerAndLinkerAlternative)&quot;" Condition="'$(CppCompilerAndLinkerAlternative)' != '' and '$(_WhereLinker)' != '0'" IgnoreExitCode="true" StandardOutputImportance="Low">
      <Output TaskParameter="ExitCode" PropertyName="_WhereLinkerAlt" />
    </Exec>

    <PropertyGroup Condition="'$(CppCompilerAndLinkerAlternative)' != '' and '$(_WhereLinker)' != '0' and '$(_WhereLinkerAlt)' == '0'">
      <CppCompilerAndLinker>$(CppCompilerAndLinkerAlternative)</CppCompilerAndLinker>
      <CppLinker>$(CppCompilerAndLinker)</CppLinker>
      <_WhereLinker>0</_WhereLinker>
    </PropertyGroup>

    <PropertyGroup Condition="'$(ObjCopyName)' == '' and '$(_IsApplePlatform)' != 'true'">
      <ObjCopyName Condition="!$(CppCompilerAndLinker.Contains('clang'))">objcopy</ObjCopyName>
      <ObjCopyName Condition="$(CppCompilerAndLinker.Contains('clang'))">llvm-objcopy</ObjCopyName>
      <ObjCopyNameAlternative />
      <ObjCopyNameAlternative Condition="$(CppCompilerAndLinker.Contains('clang'))">objcopy</ObjCopyNameAlternative>
    </PropertyGroup>

    <Error Condition="'$(_WhereLinker)' != '0' and '$(_IsApplePlatform)' == 'true'" Text="Platform linker ('$(CppLinker)') not found in PATH. Ensure you have all the required prerequisites documented at https://aka.ms/nativeaot-prerequisites." />
    <Error Condition="'$(_WhereLinker)' != '0' and '$(CppCompilerAndLinkerAlternative)' != ''"
      Text="Platform linker ('$(CppLinker)' or '$(CppCompilerAndLinkerAlternative)') not found in PATH. Ensure you have all the required prerequisites documented at https://aka.ms/nativeaot-prerequisites." />
    <Error Condition="'$(_WhereLinker)' != '0' and '$(CppCompilerAndLinkerAlternative)' == '' and '$(_IsApplePlatform)' != 'true'"
      Text="Requested linker ('$(CppLinker)') not found in PATH." />

    <Exec Command="&quot;$(CppLinker)&quot; -fuse-ld=lld -Wl,--version" Condition="'$(LinkerFlavor)' == 'lld'" IgnoreExitCode="true" StandardOutputImportance="Low" ConsoleToMSBuild="true">
      <Output TaskParameter="ExitCode" PropertyName="_LinkerVersionStringExitCode" />
      <Output TaskParameter="ConsoleOutput" PropertyName="_LinkerVersionString" />
    </Exec>

    <PropertyGroup Condition="'$(_LinkerVersionStringExitCode)' == '0' and '$(_LinkerVersionString)' != ''">
      <_LinkerVersion>$([System.Text.RegularExpressions.Regex]::Match($(_LinkerVersionString), '[1-9]\d*'))</_LinkerVersion>
    </PropertyGroup>

    <Exec Command="$(_CommandProbe) &quot;$(ObjCopyName)&quot;" IgnoreExitCode="true" StandardOutputImportance="Low" Condition="'$(_IsApplePlatform)' != 'true' and '$(StripSymbols)' == 'true'">
      <Output TaskParameter="ExitCode" PropertyName="_WhereSymbolStripper" />
    </Exec>

    <Exec Command="$(_CommandProbe) &quot;$(ObjCopyNameAlternative)&quot;" IgnoreExitCode="true" StandardOutputImportance="Low" Condition="'$(_IsApplePlatform)' != 'true' and '$(ObjCopyNameAlternative)' != '' and '$(StripSymbols)' == 'true'">
      <Output TaskParameter="ExitCode" PropertyName="_WhereSymbolStripperAlt" />
    </Exec>

    <PropertyGroup Condition="'$(ObjCopyNameAlternative)' != '' and '$(_WhereSymbolStripper)' != '0' and '$(_WhereSymbolStripperAlt)' == '0'">
      <ObjCopyName>$(ObjCopyNameAlternative)</ObjCopyName>
      <_WhereSymbolStripper>0</_WhereSymbolStripper>
    </PropertyGroup>

    <Error Condition="'$(_WhereSymbolStripper)' != '0' and '$(StripSymbols)' == 'true' and '$(ObjCopyNameAlternative)' != ''"
      Text="Symbol stripping tool ('$(ObjCopyName)' or '$(ObjCopyNameAlternative)') not found in PATH. Try installing appropriate package for $(ObjCopyName) or $(ObjCopyNameAlternative) to resolve the problem or set the StripSymbols property to false to disable symbol stripping." />
    <Error Condition="'$(_WhereSymbolStripper)' != '0' and '$(StripSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
      Text="Symbol stripping tool ('$(ObjCopyName)') not found in PATH. Make sure '$(ObjCopyName)' is available in PATH or set the StripSymbols property to false to disable symbol stripping." />

    <Exec Command="command -v dsymutil &amp;&amp; command -v strip" IgnoreExitCode="true" StandardOutputImportance="Low" Condition="'$(_IsApplePlatform)' == 'true' and '$(StripSymbols)' == 'true'">
      <Output TaskParameter="ExitCode" PropertyName="_WhereSymbolStripper" />
    </Exec>
    <Error Condition="'$(_WhereSymbolStripper)' != '0' and '$(StripSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
      Text="Symbol stripping tools ('dsymutil' and 'strip') not found in PATH. Make sure 'dsymutil' and 'strip' are available in PATH or set the StripSymbols property to false to disable symbol stripping." />

    <Exec Command="dsymutil --help" IgnoreExitCode="true" StandardOutputImportance="Low" Condition="'$(_IsApplePlatform)' == 'true' and '$(StripSymbols)' == 'true'">
      <Output TaskParameter="ExitCode" PropertyName="_DsymUtilOutput" />
    </Exec>

    <Exec Command="CC=&quot;$(CppLinker)&quot; &quot;$(IlcHostPackagePath)/native/src/libs/build-local.sh&quot; &quot;$(IlcHostPackagePath)/&quot; &quot;$(IntermediateOutputPath)&quot; System.Globalization.Native"
        Condition="'$(StaticICULinking)' == 'true' and '$(InvariantGlobalization)' != 'true'" />

    <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"
        Condition="'$(StaticOpenSslLinking)' == 'true'" />

    <PropertyGroup Condition="'$(_IsApplePlatform)' == 'true' and '$(StripSymbols)' == 'true' and $(_DsymUtilOutput.Contains('--minimize'))">
      <DsymUtilOptions>$(DsymUtilOptions) --minimize</DsymUtilOptions>
    </PropertyGroup>
  </Target>
</Project>




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 1/15/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13241정성태2/3/20234034디버깅 기술: 188. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.IO.FileNotFoundException
13240정성태2/1/20234182디버깅 기술: 187. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.Web.HttpException
13239정성태2/1/20233866디버깅 기술: 186. C# - CacheDependency의 숨겨진 예외 - System.Web.HttpException
13238정성태1/31/20235998.NET Framework: 2092. IIS 웹 사이트를 TLS 1.2 또는 TLS 1.3 프로토콜로만 운영하는 방법
13237정성태1/30/20235689.NET Framework: 2091. C# - 웹 사이트가 어떤 버전의 TLS/SSL을 지원하는지 확인하는 방법
13236정성태1/29/20235188개발 환경 구성: 663. openssl을 이용해 인트라넷 IIS 사이트의 SSL 인증서 생성
13235정성태1/29/20234821개발 환경 구성: 662. openssl - 윈도우 환경의 명령행에서 SAN 적용하는 방법
13234정성태1/28/20235905개발 환경 구성: 661. dnSpy를 이용해 소스 코드가 없는 .NET 어셈블리의 코드를 변경하는 방법 [1]
13233정성태1/28/20237281오류 유형: 840. C# - WebClient로 https 호출 시 "The request was aborted: Could not create SSL/TLS secure channel" 예외 발생
13232정성태1/27/20234950스크립트: 43. uwsgi의 --processes와 --threads 옵션
13231정성태1/27/20233961오류 유형: 839. python - TypeError: '...' object is not callable
13230정성태1/26/20234337개발 환경 구성: 660. WSL 2 내부로부터 호스트 측의 네트워크로 UDP 데이터가 1개의 패킷으로만 제한되는 문제
13229정성태1/25/20235369.NET Framework: 2090. C# - UDP Datagram의 최대 크기
13228정성태1/24/20235480.NET Framework: 2089. C# - WMI 논리 디스크가 속한 물리 디스크의 정보를 얻는 방법 [2]파일 다운로드1
13227정성태1/23/20235143개발 환경 구성: 659. Windows - IP MTU 값을 바꿀 수 있을까요? [1]
13226정성태1/23/20234820.NET Framework: 2088. .NET 5부터 지원하는 GetRawSocketOption 사용 시 주의할 점
13225정성태1/21/20234019개발 환경 구성: 658. Windows에서 실행 중인 소켓 서버를 다른 PC 또는 WSL에서 접속할 수 없는 경우
13224정성태1/21/20234451Windows: 221. Windows - Private/Public/Domain이 아닌 네트워크 어댑터 단위로 방화벽을 on/off하는 방법
13223정성태1/20/20234611오류 유형: 838. RDP 연결 오류 - The two computers couldn't connect in the amount of time allotted
13222정성태1/20/20234309개발 환경 구성: 657. WSL - DockerDesktop.vhdx 파일 위치를 옮기는 방법
13221정성태1/19/20234473Linux: 57. C# - 리눅스 프로세스 메모리 정보파일 다운로드1
13220정성태1/19/20234591오류 유형: 837. NETSDK1045 The current .NET SDK does not support targeting .NET ...
13219정성태1/18/20234197Windows: 220. 네트워크의 인터넷 접속 가능 여부에 대한 판단 기준
13218정성태1/17/20234093VS.NET IDE: 178. Visual Studio 17.5 (Preview 2) - 포트 터널링을 이용한 웹 응용 프로그램의 외부 접근 허용
13217정성태1/13/20234710디버깅 기술: 185. windbg - 64비트 운영체제에서 작업 관리자로 뜬 32비트 프로세스의 덤프를 sos로 디버깅하는 방법
13216정성태1/12/20234961디버깅 기술: 184. windbg - 32비트 프로세스의 메모리 덤프인 경우 !peb 명령어로 나타나지 않는 환경 변수
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...