The following is a choice extract from an article -- "Porting to 64 bit", which is written by Andreas Jaeger(SuSE Linux AG).
I put it here just as a summary. Some section just has a title because the constent is farmiliar to me or too complex.
Abstract:
This paper illustrates some problems on porting an application to 64-bit and also shows how use a 64-bit system as development platform for both 32-bit and 64-bit code. It will give hints especially to application and library developers on writing portable code using the GNU Compiler Collection.
1Introduction
The following differences can attribute to port software:
1) Compiler
2) ABI
3) CPU
4) C Library
5) Kernel
Application developers will mainly have portability problem due to different CPUs and different ABIs.
2 Advantages of 64-bit Programs
1) Larger address space
2) Improved performance, due to additional features introduced by 64-bit processors
As a example of point 2, AMD Opteron processor has some architectural improvements, like a memory controller integrated into the processor for faster memory access which eliminates high latency memory structure.
3 64-bit and 32-bit Programs on One System
In general, 64-bit CPUs can execute 32-bit code natively without any performance penalty, which can be commonly called “biarch support” or “multi-arch support”.
This offers some extra challenges for developers:
1) The kernel must support 32-bit and 64-bit programs;
2) The system has to be installed in such a way that 32-bit and 64-bit libraries of the same name can exist on one system;
3) The tool chain should handle development of both 32-bit and 64-bit programs
3.1 Kernel implications
Requirements:
1) Starting of programs for every architecture supported by the ABI, bot 32-bit and 64-bit;
2) System calls should be compatible to the corresponding 32-bit platform.
One problem here is the ioctl() system call.
3.2 Libraries: lib and lib64
Because libraries for 32-bit and 64-bit program have the same name, so we need consider where to install them. A example solution is that put 64-bit libraries into another directory like /usr/lib64. For 32-bit programs, no changes need; for 64-bit, the autoconf scripts should specify the library install path. And the ldconfig should handle all libraries too.
3.3 Development for Different ABIs
Compilers like GCC encapsulate almost all of the differences between ABIs.
Toolchains are also needed for development.
3.4 Development
Compiler option and library path.
4 64-bit Porting: Hints and Pitfalls
Using the same C library means: the same usage of functions and a different layout of structures.
Different program language has some specific problems.
The sizes of fundamental types on different platforms may be different.
4.1 “Portable” x86/AMD64 Inline Assembler
4.2 Sizes and Alignment of Fundamental Datatypes and Structure Layout
According to LP64 model, pointers and “long” have a size of 64bits while “int” uses 32 bits in 64-bit platform.
Besides this, different ABIs specify also different alignments. A double variable is aligned on x86 to 4 bytes but aligned to 8 bytes on AMD 64 despite having the same size of 8 bytes. Structures will therefore have a different layout on different platforms.
It is therefore not to hardcode any size and offsets.
4.2.1 int vs. long
1) pointer’s size
2) untyped integral constants are of type int
3) the type of identifiers of an enumeration is implementation defined but all constants get the same type, GCC by default gives them type int, unless any of the enumeration constants needs a larger type
4.3 Function Prototypes
When missing function prototypes, the return value is int and for arguments, integral promotions are performed and arguments of type float are promoted to double.
This may cause some fatal problems, like malloc and memcpy.
4.4 Variable argument Lists
Calling and called function do their job.
Va_lists and some function-like macro like va_copy to manipulate the variable parameters.
4.5 Function Pointers
4.6 Using Bitwidth-dependent types portably
4.7 Using printf and scanf
4.8 Unsigned and Signed Chars
4.9 Evaluation of Floating-point Arithmetic
4.10 Shared Libraries
-fPIC—compiler options forced by some archits
4.11 How to Check for 64-bit
4.12 Optimized Functions, Macros, and Builtins
4.13 Useful Compiler Flags