Microsoft MVP성태의 닷넷 이야기
.NET Framework: 524. .NET 4.0과 .NET 4.5의 컴파일 결과 차이점 [링크 복사], [링크+제목 복사],
조회: 30113
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 1개 있습니다.)

.NET 4.0과 .NET 4.5의 컴파일 결과 차이점

C# 프로젝트를 만들고, 프로젝트 속성 창의 "Target framework" 값을 ".NET Framework 4"로 하면 app.config에 다음과 같은 값이 추가되고,

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>

".NET Framework 4.5"로 설정하면 Version 속성 값만 살짝 4.5로 바뀝니다.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
    </startup>
</configuration>

그런데, .NET 수준에서 알려지지 않은 변화들이 있습니다. 이것은 dumpbin.exe를 이용해야 확인할 수 있는 것들인데요. 실제로 ^^ .NET 4.0과 .NET 4.5로 컴파일된 C# EXE 파일을 dumpbin.exe로 살펴보면 다음의 2가지 주요 차이점이 나옵니다.

=========== .NET 4.0

Subsystem version: 4.00
DLL Characteristics: 8540

=========== .NET 4.5

Subsystem version: 6.00
DLL Characteristics: 8560
    추가 - High Entropy Virtual Addresses

Subsystem은 다음의 문서에 적힌 바,

/subsystemversion (C# Compiler Options)
; https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/subsystemversion-compiler-option

Store App 또는 ARM 지원 응용 프로그램이 아닌 동시에 .NET 4.5로 지정하지 않은 모든 C# 응용 프로그램의 기본 Subsystem 버전이 4.0입니다. 그리고, .NET 4.5로 지정된 경우에는 Subsystem 버전이 6.0으로 바뀐다고 문서에 잘 적혀 있습니다.

Subsystem 6.0이 의미하는 운영체제는 Windows Vista인데, 따라서 .NET 4.5용 응용 프로그램들은 비스타 이전의 운영체제에서는 실행할 수 없습니다. 이 제한은 .NET Framework 4.5가 요구하는 시스템 사양과도 일치합니다.

Microsoft .NET Framework 4.5 
; http://www.microsoft.com/en-us/download/details.aspx?id=30653

Supported Operating System

Windows 7 Service Pack 1, Windows Server 2008 R2 SP1, Windows Server 2008 Service Pack 2, Windows Vista Service Pack 2 

그리고 또 한가지의 변화는 DLL 특징에 "High Entropy Virtual Addresses" 옵션이 추가된 점입니다.

/highentropyva (C# Compiler Options)
; https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/highentropyva-compiler-option

ASLR(Address Space Layout Randomization) 기능을 좀 더 강화해서 64비트 응용 프로그램일 때는 기본적으로 4GB 너머로 메모리 주소를 흩어버리는 것입니다. 이 기능을 확인하고 싶다면 unsafe 특성을 이용해 보면 됩니다. .NET 4.0 + x64로 콘솔 EXE를 다음의 코드로 만들어 (Allow unsafe code 옵션과 함께 컴파일해) 실행해 보면,

using System;

class Program
{
    static unsafe void Main(string[] args)
    {
        byte[] contents = new byte[1024];
        fixed (byte* ptr = &contents[0])
        {
            IntPtr pVoid = new IntPtr(ptr);
            Console.WriteLine("Addr of ptr: 0x" + pVoid.ToInt64().ToString("x"));
            // 출력 결과: Addr of ptr: 0x2d54560
        }
    }
}

출력된 주소 위치가 4GB 하위(< 0xffffffff)에 있는 것을 볼 수 있습니다. 반면, .NET 4.5로 대상 프레임워크를 맞추고 동일한 소스코드를 재컴파일만해도 출력 결과가 4GB 너머(> 0xffffffff)의 주소로 바뀌고 실행할 때마다 주소의 변화가 큽니다.

Addr of ptr: 0x5e09884560




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 8/16/2024]

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

비밀번호

댓글 작성자
 



2017-01-22 05시53분
정성태

... 121  122  123  124  125  126  127  128  129  [130]  131  132  133  134  135  ...
NoWriterDateCnt.TitleFile(s)
1806정성태11/10/201425134.NET Framework: 477. SeCreateGlobalPrivilege 특권과 WCF NamedPipe
1805정성태11/5/201421984.NET Framework: 476. Visual Studio에서 Mono용 Profiler 개발 [3]파일 다운로드1
1804정성태11/5/201428230.NET Framework: 475. ETW(Event Tracing for Windows)를 C#에서 사용하는 방법 [9]파일 다운로드1
1803정성태11/4/201420333오류 유형: 261. Windows Server Backup 오류 - Error in backup of E:\$Extend\$RmMetadata\$TxfLog
1802정성태11/4/201422253오류 유형: 260. 이벤트 로그 - Windows Error Reporting / AEAPPINVW8
1801정성태11/4/201427599오류 유형: 259. 이벤트 로그 - Windows Error Reporting / IPX Assertion / KorIME.exe [1]
1800정성태11/4/201418251오류 유형: 258. 이벤트 로그 - Starting a SMART disk polling operation in Automatic mode.
1799정성태11/4/201423069오류 유형: 257. 이벤트 로그 - The WMI Performance Adapter service entered the stopped state.
1798정성태11/4/201431859오류 유형: 256. 이벤트 로그 - The WinHTTP Web Proxy Auto-Discovery Service service entered the stopped state. [1]
1797정성태11/4/201417565오류 유형: 255. 이벤트 로그 - The Adobe Flash Player Update Service service entered the stopped state.
1796정성태10/30/201424535개발 환경 구성: 249. Visual Studio 2013에서 Mono 컴파일하는 방법
1795정성태10/29/201427062개발 환경 구성: 248. Lync 2013 서버 설치 방법
1794정성태10/29/201422500개발 환경 구성: 247. "Microsoft Office 365 Enterprise E3" 서비스에 대한 간략 소개
1793정성태10/27/201423148.NET Framework: 474. C# - chromiumembedded 사용 - 두 번째 이야기 [2]파일 다운로드1
1792정성태10/27/201423284.NET Framework: 473. WebClient 객체에 쿠키(Cookie)를 사용하는 방법
1791정성태10/22/201423005VC++: 83. G++ - 템플릿 클래스의 iterator 코드 사용에서 발생하는 컴파일 오류 [5]
1790정성태10/22/201418534오류 유형: 254. NETLOGON Service is paused on [... AD Server...]
1789정성태10/22/201421208오류 유형: 253. 이벤트 로그 - The client-side extension could not remove user policy settings for '...'
1788정성태10/22/201423235VC++: 82. COM 프로그래밍에서 HRESULT 타입의 S_FALSE는 실패일까요? 성공일까요? [2]
1787정성태10/22/201431404오류 유형: 252. COM 개체 등록시 0x8002801C 오류가 발생한다면?
1786정성태10/22/201432716디버깅 기술: 65. 프로세스 비정상 종료 시 "Debug Diagnostic Tool"를 이용해 덤프를 남기는 방법 [3]파일 다운로드1
1785정성태10/22/201421939오류 유형: 251. 이벤트 로그 - Load control template file /_controltemplates/TaxonomyPicker.ascx failed [1]
1784정성태10/22/201430027.NET Framework: 472. C/C++과 C# 사이의 메모리 할당/해제 방법파일 다운로드1
1783정성태10/21/201423484VC++: 81. 프로그래밍에서 borrowing의 개념
1782정성태10/21/201420212오류 유형: 250. 이벤트 로그 - Application Server job failed for service instance Microsoft.Office.Server.Search.Administration.SearchServiceInstance
1781정성태10/21/201420649디버깅 기술: 64. new/delete의 짝이 맞는 경우에도 메모리 누수가 발생한다면?
... 121  122  123  124  125  126  127  128  129  [130]  131  132  133  134  135  ...