Issues after Porting applications to 64 bit architecture

Application Binary Interface(ABI) specifies sizes of fundamental types. ABI is hidden from the developer by the compiler. The main limitation of 32-bit programs that push developers to 64-bit programs is the limited address space. A 32-bit program can only address 4 GB of memory. Nowadays applications need larger and larger address spaces and performance can be greatly improved with large caches which is a benefit especially for databases.

Besides larger address space, most recent 64-bit processors introduce additional features over the previous processor generation for improved
performance.

64-bit architecture has the following distinct advantages:
can directly access 4 exabytes of virtual memory
allows for file sizes up to 4 exabytes

Issues after porting to 64 bit architecture:
One of most common issue after porting application to 64 bit is, reading structure values from file which was written by 32 bit application may not work properly in 64 bit application.

For example, consider the following structure variable.
typedef struct porting{
long lx;
long ly;
long lz;
} port;

Assume this structure was wrriten to a file after assigning values to structure members by 32 bit application. Reading these values by same structure in 64 bit application will result in incorrect values being filled in structure members. Why ?.
This is becaue, long is 32 bit in 32 bit application. So the size of structure will be 12 bytes(only in case of above structure), which is written to file. Size of long is 8 bytes in case of 64 bit application. When this strucutre is read by 64 bit application, first 8 bytes are read to lx member, 8-15 and 16-23 bytes are read to ly and lz structure members which is totally incorrect.

So after the application is ported to 64 bit, in case older data which was written by 32 bit application has to be read again, migration has to done to move all the files on disk to 64 bit. Below is one of the methods which can be used to do this.

A seprate migration application has to be written to migrate the files which were created from 32 bit application.

In migration application which itself a 64 bit application, declare two structure variables. One which reads the 32 bit structure values from files (with the use of variables of specified width type like int16_t, int32_t…..etc ) and another 64 bit structure which writes the values to a new.

typedef struct porting32{
int32_t lx;
int32_t ly;
int32_t lz;
} port32;

typedef struct porting{
long lx;
long ly;
long lz;
} port;

Migration application reads values from files using port32 structure variable, assign’s values to 64 bit structure port i.e

port.lx = prt32.lx;
port.ly = prt32.ly;
port.lz = prt32.lz;

after this, write the structure port to new file. After reading/writting all the values, delete old file and move new file to old file name.

This way, all files which were written with 32bit application are converted, so that values read with 64 bit application are proper.

Another common way to resolve the issue is to read 4 bytes at once three times to complete reading one structure member in 64 bit application itself and continue with futher processing in application. But this makes 32 bit and 64 bit application.

Based on what is written in files by 32 bit application, various other approaches would be used for these kind of issues. But most of the times, it’s difficult to have a common solution for these kind of issues in all applications.

References:
ftp://gcc.gnu.org/pub/gcc/summit/2003/Porting%20to%2064%20bit.pdf
http://www.ibm.com/developerworks/library/l-port64/index.html

Advertisements
This entry was posted in C Section. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s