Seven Steps of Migrating a Program to a 64-bit System


Seven Steps of Migrating a Program to a 64-bit System

Author: Andrey Karpov

Date: 19.04.2009

Abstract

The article describes the main steps which should be performed to correctly port 32-bit Windows applications on 64-bit Windows systems. Although the article is meant for developers using C/C++ in Visual Studio 2005/2008 environment, it will be also useful for other developers who plan to port their applications on 64-bit systems.

Introduction

The article describes the main problems facing developers who plan to port 32-bit programs on 64-bit systems. Of course the list of the issues considered is not complete, but we hope that we’ll offer a more detailed version of this article in future. The author would be glad to receive responses, comments and questions which will help increase information value of this article.

1. The first step. 64-bit mode can be different. Let’s sort it out

Within the framework of a computer architecture by the term “64-bit” 64-bit integers and other 64-bit-sized data types are understood. By “64-bit” systems 64-bit microprocessor architectures (for example, EM64T, IA-64) or 64-bit operation system (for example, Windows XP Professional x64 Edition) can be understood [1].

AMD64 (or x86-64, Intel 64, EM64T, x64) is a 64-bit microprocessor architecture and a corresponding set of instructions developed by AMD company [2]. This set of instructions was licensed by Intel company under the name of EM64T (Intel64). AMD64 architecture is an extension of x86 architecture with full backward compatibility. The architecture became widespread as a basis of personal computers and workstations.

IA-64 is a 64-bit microprocessor architecture developed together by Intel and Hewlett Packard companies [3]. It is implemented in microprocessors Itanium and Itanium 2 [4]. The architecture is used mainly in multi-processor servers and cluster systems.

AMD64 and IA-64 are two different 64-bit architectures incompatible with each other. That’s why developers have to decide at once if they need support of the both architectures or only one of them. In most cases, if you don’t develop highly tailored software for cluster systems or don’t implement your own high-performance DBMS, most likely you will have to implement support only of AMD64 architecture which is much more popular than IA-64. It especially concerns software for PC market which is nearly 100% occupied by AMD64 architecture.

Further in the article we’ll speak only about AMD64 (EM64T, x64) architecture, as nowadays it is the most topical for application software developers.

Speaking about different architectures we should mention the notion “Data model“. By a data model we understand correlations between type sizes accepted within the framework of the development environment. There can be several development tools sticking to different data types for one operation system. But usually only one model dominates which corresponds to the hardware and software environment most. Such an example is 64-bit Windows whose original data model is LLP64. But for compatibility purposes 64-bit Windows supports execution of 32-bit programs which operate in ILP32LL data model mode. Table 1 gives information about the basic data models.









Table 1. Data models.

A data model being used influences the process of developing 64-bit applications as you need to keep in mind sizes of the data being used in programs’ code [5].

2. The second step. Find out if you need the 64-bit version of your product

You should begin mastering 64-bit systems with the question: “Do I really need to rebuild my project for a 64-bit system?” You give an answer to this question but only after you have thought it over, without hurry. On the one hand, you can lag behind your rivals if you don’t offer 64-bit solutions. On the other hand, you can just waste your time developing a 64-bit application which won’t provide any competitive advantages.

Let’s list the basic factors that will help you make up your mind.

2.1. Applications’ life-cycle duration

You shouldn’t create the 64-bit version of an application with a short life-cycle. Thanks to WOW64 subsystem old 32-bit applications operate rather well on 64-bit Windows systems and that’s why there is no sense in making a program 64-bit for it won’t be supported in 2 years [6]. Moreover, practice shows that porting on 64-bit Windows versions has been delayed and perhaps most of your users will use only the 32-bit version of your program solution in near-term outlook.

If you plan long-term development and support of a program product, you should begin to work over the 64-bit version of your solution. You can do this without hurry but keep in mind that the longer you don’t have a complete 64-bit version, the more difficulties you will face in supporting this application installed on 64-bit Windows versions.

2.2. Resource-intensiveness of an application

Recompilation of a program for a 64-bit system will allow it to use large sizes of main memory and will also speed up its operation by 5-15%. Increase in 5-10% will be gained due to using the 64-bit processor’s architectural abilities, for example a larger number of registers. The rest speed increase in 1-5% is explained by absence of WOW64 layer which translates API calls between 32-bit applications and a 64-bit operation system.

If your program doesn’t operate with large data sizes (more than 2GB) and the speed of its operation is not crucial, porting on a 64-bit system is not so urgent in the near future.

By the way, even simple 32-bit applications can get advantage being launched in 64-bit environment. Perhaps you know that a program built with /LARGEADDRESSAWARE:YES key can allocate up to 3 GB of memory if the 32-bit Windows is launched with /3gb key. This very 32-bit program launched on a 64-bit system can allocate nearly 4 GB of memory (in practice about 3.5 GB).

2.3. Development of libraries

If you develop libraries, components or other elements with the help of which third-party developers create their software you should act quickly while creating the 64-bit version of your product. Otherwise, your clients interested in release of 64-bit versions will have to search for alternative solutions. For example, some developers of software-hardware security responded with a large delay to appearance of 64-bit programs and that made some clients search for other tools to protect their programs.

An additional advantage of releasing the 64-bit version of a library is that you can sell it as a separate product. Thus, your clients wishing to create both 32-bit and 64-bit applications will have to buy 2 different licenses. For example, this policy is used by Spatial Corporation when selling Spatial ACIS library.

2.4. Dependence of your product on third-party libraries

Before you plan your work on creation of the 64-bit version of your product, find out if there are 64-bit versions of libraries and components used in it. Besides, learn about the pricing policy concerning the 64-bit version of a library. If there is no support provided, search for alternative solutions supporting 64-bit systems beforehand.

2.5. Using 16-bit applications

If your solutions still use 16-bit units it is high time you got rid of them. 16-bit applications in 64-bit Windows versions are not supported.

We should explain one thing here concerning using 16-bit installers. They are still used to install some 32-bit applications. There is a special mechanism which replaces some of the most popular 16-bit installers with their newer versions. It can cause a false opinion that 16-bit programs still operate in 64-bit environment. Remember: it is not so.

2.6. Assembler code

Don’t forget that using a large size of Assembler code can significantly increase the cost of creating the 64-bit version of an application.

Having thought all the listed factors over and weighed all pros and cons, decide if you need to port your project on 64-bit systems. If yes, we go further.

3. The third step. Toolkit

If you have decided to develop the 64-bit version of your product and are ready to spend time on it, it is still not enough to guarantee success. The point is that you must possess the entire necessary toolkit and here you can face some difficulties.

Absence of a 64-bit compiler can be the simplest but the most insuperable problem. The article is being written in 2009 but there is still no 64-bit C++ Builder compiler by Codegear [7]. Its release is expected by the end of this year. It is impossible to avoid this problem, if only to rewrite the whole project using, for example, Visual Studio. But if everything is clear about absence of a 64-bit compiler, other similar problems can appear to be less transparent and occur only at the stage of porting the project on a new architecture. That’s why we would like to advise you to find out beforehand if there are all the necessary components you will need to implement the 64-bit version of your product. You may face unpleasant surprises.

Of course it is impossible to list everything you may need for a project here, but I will continue the list which will help you to orient yourself and perhaps to remember about other things necessary to implement your 64-bit project:

3.1. A 64-bit compiler

There is hardly more to say about the importance of having a 64-bit compiler. It simply must be.

If you are planning to develop 64-bit applications using the latest (by the moment the article is written) Visual Studio 2008 version, the following Table 2 will help you understand which of the Visual Studio editions you need.


 

 

 

 

 

 

 

Table 2. Abilities of different editions of Visual Studio 2008.

3.2. 64-bit computers under control of 64-bit operation system

Of course you can use virtual machines for launching 64-bit applications on 32-bit computers but it is too inconvenient and won’t provide the necessary level of tests. It is desirable that the machines have not less than 4-8 GB of main memory.

3.3. 64-bit versions of all the used libraries

If libraries are presented in source codes, there must be a 64-bit configuration of the project. It can be a thankless and difficult task to update the library for a 64-bit system on your own, and the result can be unreliable and contain errors. Besides, you can violate license agreements by these actions. If you use libraries in the form of binary units you should also find out if there are 64-bit units. You cannot use 32-bit DLL inside a 64-bit application. You can create a special tie through COM but it will be a separate large and difficult task [8]. Also keep in mind that you may need to spend some extra money to purchase the 64-bit version of the library.

3.4. Absence of embedded Assembler code

Visual C++ doesn’t support a 64-bit inline assembler. You must either use an external 64-bit assembler (for example, MASM) or possess an implementation with the same functionality in C/C++ [9].

3.5. Testing methodology update

It means considerable remaking of the testing methodology, update of unit-tests and using new tools. We will speak about it in more detail further, but don’t forget to take it into account at the stage of evaluating time costs on migration of an application on a new system [10].

3.6. New data for testing

If you are developing resource-intensive applications using a large size of main memory, you need to provide replenishment of the testing input data base. At load testing of 64-bit applications it is desirable to excess the limits of 4 GB of the used memory. Many errors can occur only in these conditions.

3.7. 64-bit security systems

The security system being used must provide full support of 64-bit systems. For example, Aladdin company has released 64-bit drivers for support of hardware Hasp keys rather quickly. But for a long time there has been no system of automatic protection of 64-bit binary files (Hasp Envelop program). Thus, the security mechanism had to be implemented manually inside the program code and that was one more difficult task demanding professionalism and time. Don’t forget about such things relating to security, update system etc.

3.8. Installer

You need a new installer able to fully install 64-bit applications. We would like to warn you about one very typical mistake. It is creation of 64-bit installers for installing 32/64-bit program products. Preparing the 64-bit version of an application developers often want to make “64-bit mode” in it absolute and create a 64-bit installer forgetting that those who use a 32-bit operation system won’t simply be able to launch such an installation package. Pay attention that it is not the 32-bit application included into the distribution kit together with the 64-bit one, but the installer itself. For if the distribution kit is a 64-bit application, of course it won’t operate on a 32-bit operation system. What is the most unpleasant is that a user won’t be able to guess why it happens. He will simply see the installation package which cannot be launched.

4. The fourth step. Setting of a project in Visual Studio 2005/2008

Creation of the 64-bit configuration of a project in Visual Studio 2005/2008 looks rather simple. Difficulties will begin at the stage of building a new configuration and searching errors in it. To create the 64-bit configuration itself you just need to perform the following 4 steps:

Launch the configuration manager as shown in Figure 1:

 

 

 

 

 

 

Figure 1. Launch of the configuration manager.

In the configuration manager choose support of the new platform (Figure 2):






Figure 2. Creation of a new configuration.

Choose the 64-bit platform (x64) and as a basis – settings from the 32-bit version (Figure 3). Those settings which influence the building mode will be corrected by Visual Studio automatically.

 

 

 

 

 

 

 

 

Figure 3. Choose x64 as a platform and use Win32 configuration as a basis.

Addition of a new configuration is complete and now you can choose the 64-bit configuration version and begin compiling a 64-bit application. Choosing the 64-bit configuration for building is shown in Figure 4.







Figure 4. Now both 32-bit and 64-bit configurations are available.

If you are lucky you won’t need to additionally set a 64-bit project. But it greatly depends on the project, its complexity and the number of libraries used. The only thing you should change at once is the stack’s size. In case if the stack’s size in your project is set by default, that is 1 MB, you should define it as 2 MB for the 64-bit version. It is not necessary but it is better to insure yourself beforehand. If you use the size different from that by default, there is sense in increasing it twice for the 64-bit version. To do this find and change Stack Reserve Size and Stack Commit Size parameters in the project’s settings.

5. The fifth step. Compilation of an application

Here we should tell you about typical problems occurring at the stage of compiling the 64-bit configuration, discuss what problems occur in third-party libraries, tell you that in the code relating to WinAPI functions the compiler won’t permit placing of a pointer into LONG type and you will have to update your code and use LONG_PTG type. And there is a lot else to say. Unfortunately, there are so many problems and errors are so various that we cannot describe them all in one article and even book. You will have to look through all the errors the compiler will show you and all the new warnings which haven’t been there before by yourself and in each particular case to find out how to update the code.

The following list of links to resources devoted to developing 64-bit applications can partly help you: http://www.viva64.com/links/64-bit-development/. The list is constantly enlarged and the author will be glad if readers send him links to resources which are, in their opinion, worthy attention.

Let’s describe here only types which can be of interest for developers when porting applications. These types are shown in Table 3. Most recompilation errors will relate to using these very types.

The simplest but none the easiest for detection error class relates to explicit type conversions when significant bits are cut. A popular example is conversion of pointers to 32-bit types when transferring them into functions such as SendMessage:

Leave a Reply