45
Visual C++ 6.0 응용 프로그램을 Visual Studio 2008로 이전하기 Visual C++ 6.0 응용 프로그램을 Visual Studio 2008로 이전하기 조현근(William Cho) 삼성전자 선임연구원 [email protected]

Visual Studio 2008로 가는 길 - Egloospds17.egloos.com/pds/201003/08/74/VisualStudio2008.pdf · 2010-03-08 · MFC, ATL, .NET, Web Services Introduced support for .NET Extended

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Visual C++ 6.0 응용 프로그램을Visual Studio 2008로 이전하기Visual C++ 6.0 응용 프로그램을Visual Studio 2008로 이전하기

조현근(William Cho)삼성전자 선임연구원[email protected]

Today’s PresentationToday’s Presentation

• Visual Studio 2008로 가는 길• 향상된 보안/향상된 성능• 64비트 프로그램을 준비하라

Today’s PresentationToday’s Presentation

•• Visual Studio 2008Visual Studio 2008로로 가는가는 길길• 향상된 보안/향상된 성능• 64비트 프로그램을 준비하라

Visual C++ Past and PresentVisual C++ Past and Present

Visual C++ 6 Visual C++ 2002

Visual C++ 2005

Visual C++ 2008

Release Date 1998 2002

Windows 98 to Windows XP

Win32, COM, MFC, ATL, .NET, Web Services

Introduced support for .NET

Extended support expires June 30, 2009

2005 2008

Target Platforms

Windows 95 to Windows NT 4.0

Windows 2000 to Windows Server 2003

Windows 2000 to Windows Server 2003

Libraries and Technologies

Win32, COM, MFC, ATL

Win32, COM, MFC, ATL, .NET, Web Services

Win32, COM, MFC, ATL, .NET, Web Services

Distinguishing Features

Introduced IntelliSense

Improved support for .NET, ISO C++ and Windows platforms

Improvoedsupport for MFCNext, TR1 and .NET 3.5

Support Extended support expires September 30, 2005

? Just shipped

Benefits of Visual Studio 2008Benefits of Visual Studio 2008

• 생산성 증가– 새로워진 IDE와 도구들– 스마트디바이스를 위한 개발 툴과 시뮬레이터

• 보안성 증대– 보안성 검사 옵션을 기본 적용

• 성능향상– 향상된 최적화 알고리즘– 최신 하드웨어의 새로운 기능을 적극 활용

• 새로운 환경에 대한 대비– 새로운 C++ 표준에 맞는 코드 작성으로 인한 이식성 확보– 최신 윈도우 및 앞으로 출시될 윈도우의 기능에 대한 지원– 64bit 환경 지원– .NET Framework 및 WinFX 지원

Be ready for servicing your applications!!

Be ready for servicing your applications!!

Visual C++ 2008로의 전환Visual C++ 2008로의 전환

Visual C++ 2008로의 전환Visual C++ 2008로의 전환

Visual C++ 2008로의 전환Visual C++ 2008로의 전환

Visual C++ 2008로의 전환Visual C++ 2008로의 전환

Visual C++ 2008로의 전환Visual C++ 2008로의 전환

프로젝트 파일의 변화프로젝트 파일의 변화

Visual C++ 6.0Visual C++ 6.0 Visual C++ 2008Visual C++ 2008

VC++ 2008 업그레이드시 주의사항VC++ 2008 업그레이드시 주의사항

• 새로운 ISO 지원으로 기존 C/C++코드와의 호환성 이슈– for 루프의 변수선언 범위 변화– 명시적인 ‘int’의 선언

– I/O stream 의 선언 변화– 함수 포인터 사용시 명시적 ‘&’사용– nested type에 대한 ‘using’키워드 사용불가

• Secure CRT– CRT deprecation warnings.

• Unicode 지원– CString → CStringT

• 컴파일러/링커 옵션– 몇몇 옵션 변경

VC++ 2008 업그레이드시 주의사항VC++ 2008 업그레이드시 주의사항

int main() {for(int i = 0; i < 10; ++i) ;for(i = 0; i < 10; ++i) ;

}

for for scoping change scoping change –– default is now: /default is now: /Zc:forScopeZc:forScopeCan change it to /Can change it to /Zc:forScopeZc:forScope-- for old default behaviorfor old default behavior

int main() {int i;for(i = 0; i < 10; ++i) ;for(i = 0; i < 10; ++i) ;

}

test.cpp(3) : error C2065: 'i' : undeclared identifiertest.cpp(3) : error C2065: 'i' : undeclared identifier

VC++ 2008 업그레이드시 주의사항VC++ 2008 업그레이드시 주의사항

const x = 0;

No more implicit No more implicit ‘‘intint’’

const int x = 0;

error C4430: missing type error C4430: missing type specifierspecifier -- intint assumed. assumed. Note: C++ does not support defaultNote: C++ does not support default--intint

Can also use /wd4430 to silence Can also use /wd4430 to silence ““warningwarning””

VC++ 2008 업그레이드시 주의사항VC++ 2008 업그레이드시 주의사항

I/O stream changesI/O stream changes

#include <iostream.h>#include <fstream.h>

int main(int argc, char *argv[]) {ifstream ifStream(argv[1], ios::nocreate);}

#include <iostream>#include <fstream>using namespace std;

int main(int argc, char *argv[]) {ifstream ifStream(argv[1], ios_base::in);}

test.cpp(1) : fatal error C1083: Cannot open include file: 'test.cpp(1) : fatal error C1083: Cannot open include file: 'iostream.hiostream.h': No such file ': No such file test.cpp(2) : fatal error C1083: Cannot open include file: test.cpp(2) : fatal error C1083: Cannot open include file: ‘‘fstream.hfstream.h': No such file ': No such file

test.cpp(5) : error C2653: 'test.cpp(5) : error C2653: 'iosios' : is not a class or namespace name' : is not a class or namespace nametest.cpp(5) : error C2065: 'test.cpp(5) : error C2065: 'nocreatenocreate' : undeclared identifier' : undeclared identifier

VC++ 2008 업그레이드시 주의사항VC++ 2008 업그레이드시 주의사항

class Foo {int Func(int x) {return x*x;}};…bar(objectFoo, Foo::Func, x);

Pointer to Member requires an Pointer to Member requires an ‘‘&&’’

class Foo {int Func(int x) {return x*x;}};…bar(objectFoo, &Foo::Func, x);

test.cpp(5) : error C3867: 'test.cpp(5) : error C3867: 'Foo::FuncFoo::Func': function call missing argument list; use': function call missing argument list; use'&'&Foo::FuncFoo::Func' to create a pointer to member' to create a pointer to member

VC++ 2008 업그레이드시 주의사항VC++ 2008 업그레이드시 주의사항

class Foo {class SubFoo {

…};…

};…using Foo::SubFoo;SubFoo object;

‘‘usingusing’’ on nested type, not allowedon nested type, not allowed

class Foo {class SubFoo {

…};…

};…Foo::SubFoo object;

error C2885: 'error C2885: 'Foo::SubFooFoo::SubFoo': not a valid using': not a valid using--declaration at nondeclaration at non--class scopeclass scope

VC++ 2008 업그레이드시 주의사항VC++ 2008 업그레이드시 주의사항

/MAPINFO:LINES is no longer supported/MAPINFO:LINES is no longer supported

Today’s PresentationToday’s Presentation

• Visual Studio 2008로 가는 길•• 향상된향상된 보안보안//향상된향상된 성능성능• 64비트 프로그램을 준비하라

Buffer OverrunBuffer Overrun

• Stack Overrun• Heap Overrun• Array Indexing Error• Format String Bugs• Unicode and ANSI buffer

Stack OverrunStack Overrun

• Local buffer의 Writing overflow에 의해서 발생• Return 주소의 값이 변경 됨

void foo(const char* input){

char buf[10];strcpy(buf, input);

}

Stack OverrunStack Overrun

• Stack의 구조

로컬변수

이전 EBP

foo() 복귀주소

파라미터

로컬변수

이전 EBP

main() 복귀주소

0x444342410x484746450x7FFD0049

0x0012FF80

0x004010A2

main()

foo()

StackOverrun.exe ABCDEFGHIStackOverrun.exe ABCDEFGHI

0x00370E6D

Heap OverrunHeap Overrun

• Overflow는 BadStringBuf의 값을 변경할 수 있다

void BadFund(const char* input1){

char* buf = NULL;

buf = (char*)malloc(16);g_pInput = new BadStringBuf;

strcpy(buf, input1);}

향상된 보안향상된 보안

• Secure CRT• 버퍼오버런 방지 (/GS) 옵션 기본 적용

– 스택에 선언되는 local변수, EBP, return address 그리고 예외처리 핸들러간의 관계를 검증

• Static Code Analysis 지원

Secure CRTSecure CRT

TCHAR szHello[MAX_LOADSTRING];_tcscpy(szHello, _T("Hello World!"));

CRT deprecation warningsCRT deprecation warnings

TCHAR szHello[MAX_LOADSTRING];_tcscpy_s(szHello, _T("Hello World!"));

warning C4996: 'strcpy': This function or variable may be unsafewarning C4996: 'strcpy': This function or variable may be unsafe..

향상된 성능향상된 성능

• 향상된 최적화 알고리즘 및 최신 하드웨어의 새로운 기능적극 활용– 새로운 프로세서에 최적화된 코드 생성– 향상된 floating point 연산 속도 및 정밀도 개선– 새로운 최적화 테크닉

• Whole program optimization– 기존에는 각각의 OBJ 파일별 최적화– Visual C++ 2002에서 도입 후 지속적인 개선

• 일반적 성능개선 기대치– VC++6에서 VC++2005로 변경할 때 20 ~ 30%의 성능개선

향상된 성능향상된 성능

• VC++ 6: 367.484 (msec)• VC++ 2005: 223.332 (msec)

for(long idx=0; idx<50000; idx++){_stprintf(buf, _T("%8.6f\n"), idx);}

39%faster

향상된 성능향상된 성능

SpecINT (V isual C++ 6 Baseline)

0%

2%

4%

6%

8%

10%

12%

14%

16%

18%

20%

VC7 /O2 VC7 /O2 /GL VC7.1 /O2 /G7 VC7.1 /O2 /G7 /arch:SSE2

VC7.1 /O2 /GL /G7 VC7.1 /O2 /GL /G7 /arch:SSE2

향상된 성능향상된 성능

SpecFP (V isual C++ 6 Baseline)

0%

5%

10%

15%

20%

25%

30%

35%

40%

VC7 /O2 VC7 /O2 /GL VC7.1 /O2 /G7 VC7.1 /O2 /G7 /arch:SSE2

VC7.1 /O2 /GL /G7 VC7.1 /O2 /GL /G7 /arch:SSE2

Today’s PresentationToday’s Presentation

• Visual Studio 2008로 가는 길• 향상된 보안/향상된 성능•• 6464비트비트 프로그램을프로그램을 준비하라준비하라

Then and NowThen and Now

• Windows 3.0• “640K 메모리 장벽을 제거…”• “1 MB 시스템 시대가 도래…”

• 64-bit Windows• “4 GB 메모리 장벽 극복”• “16 TERABYTES의 가상 메모리 지원”

64비트 프로그램의 준비64비트 프로그램의 준비

• 프로젝트에 64비트 플랫폼 지원 추가• Unaligned access로 인한 비효율성 제거• IA64에서의 crash 방지• Polymorphic data 지원• 하나의 프로젝트로 32/64비트 지원

프로젝트에 64비트 플랫폼 추가프로젝트에 64비트 플랫폼 추가

프로젝트에 64비트 플랫폼 추가프로젝트에 64비트 플랫폼 추가

Unaligned access로 인한 비효율성 제거Unaligned access로 인한 비효율성 제거

• Misalignment can be fatal on Itanium• x64 handles alignment faults in hardware

// Cause unalignment on 64-bit#pragma pack(push,4)struct CRecalcThreadInfo{

char m_dummy;HWND m_hwndNotify;

double m_nRecalcSpeed1;double m_nRecalcSpeed2;

};#pragma pack(pop)

IA64에서의 crash 방지IA64에서의 crash 방지

UINT uOldMode = SetErrorMode(0);SetErrorMode(uOldMode | SEM_NOALIGNMENTFAULTEXCEPT);

• For Itanium processor memory access should be aligned on “natural” boundaries.– Handle the fault silently (slow!) or– Raise an exception in user code

• Following natural alignment benefits both Win32 and Win64 apps

Polymorphic data 지원Polymorphic data 지원

• LLP64 data model

// wrong!!long dwNewLong = GetWindowLong();

// correct!!LONG_PTR dwNewLong = GetWindowLongPtr();

하나의 프로젝트로 32/64비트 지원하나의 프로젝트로 32/64비트 지원

• _WIN64• IsWow64Process

#ifdef _WIN64#define ENDPART QuadPart#else#define ENDPART LowPart#endif

pRecalcInfo->m_nRecalcSpeed1 = (double)(endCount.ENDPART-startCount.ENDPART) /

freq.ENDPART;

SummarySummary

• Visual C++ 6.0에서 Visual C++ 2008로 이전하는 것은 생각보다어렵지 않다.

• Visual C++ 2008로의 이전은 단순한 개발툴의 전환이 아니다.– C++는 20년간 이어져 왔으며 계속 발전하고 있다.– 하드웨어는 지속적으로 새로운 기술을 채용하고 있다.– 윈도우는 어플리케이션을 위해 새로운 최적화된 기능을 제공한다.

• Visual C++ 2008에서 단순히 rebuild하는 것 만으로도 성능이 향상될 수 있다.

• 프로젝트의 이전 과정에서 발생하는 모든 warning을 잡으려 하지마라!!

• 64비트 환경에 대한 대비가 필요하다.

ReferenceReference

• Porting Applications to VC2005: Part I / Microsoft• Moving Your Application Forward with Visual C++ 2005 /

Microsoft• Channel 9: New Updates to MFC in Visual Studio 2008

– http://channel9.msdn.com/

• VC++ Team blog– http://blogs.msdn.com/vcblog/

• Writing Secure Code 2nd• 64비트 윈도우 프로그래밍 / 마이크로소프트웨어, 2005, 유병인