HPCx homepage
Services User support Projects Research About us Sitemap Search  
  line          
Helpdesk User Guide Notices Bulletin Documentation
Training Porting Filestore Batch Interactive FAQ
               
home > support > FAQ > lib_32_64
spacer
hr
spacer

Creating Mixed 32/64 bit libraries

spacer

Under AIX on IBMs it is possible to create library files that contain both 32-bit and 64-bit versions of the same (compiled) routines. This is an extremely useful feature, as it means that only one version of a library needs to be maintained, even though the apllication that uses it may be compiled in either mode.

This is a brief summary of how to create such libraries.

The important point to remember when doing this is that the linker searches for appropriate entry points in the library, not the name of the file. Thus it is possible to have both a 32-bit and a 64-bit entry point for the same routine in a library, provided that the name of the object file that originally contained the compiled routine differs.

The procedure to achieve this will depend somewhat on how the compilation is performed. We will use LAPACK as an example, and hopefully the relevant points can be adapted as required.

The makefile for LAPACK compiles up the Fortran routines and places them in a library called lapack.a. The basic procedure is as follows:

  1. Create lapack.a in 32 bit mode
  2. Split up lapack.a into its component object files
  3. Rename all those object files to indicate that they are in 32 bit mode. For example rename foo.o to foo_32.o
  4. Create a new library, e.g. liblapack.a, containing the renamed object files. This library must be created using the -X32_64 flag to ar that indicates the library may contain both types of object file.
  5. make clean
  6. Create a new lapack.a in 64 bit mode
  7. Split up the new lapack.a into its component object files
  8. Rename all those object files to indicate that they are in 64 bit mode. For example rename foo.o to foo_64.o
  9. Add these files to the mixed mode library, and then you are done.

Here is how it is done, step by step

Creating the 32 bit lapack.a

LAPACK comes with an include file which is where you set the compilation and archiving (library creation) flags. For 32 bit mode, these compilation options may be used:

FORTRAN = xlf90_r
OPTS = -qfixed -O3 -q32 -qarch=pwr4 -qtune=pwr4
DRVOPTS = $(OPTS)
NOOPT = -qfixed -q32

and for archiving:

ARCH = ar
ARCHFLAGS= -X32_64 cr

Note the -X32_64 flag for the ar command. As mentioned above, this tells the archiver that the library will contain both 32 and 64 bit object files. While not necessary for this stage, it makes life easier and more consistent if you use this flag the whole time. An alternative is to set the environment variable OBJECT_MODE to 32_64 (the default is 32)

Once that is done simply

make lapacklib

creates the library

Splitting the library and renaming the 32 bit files

This is most easily done with a script. For example:

prompt> cat ~/bin/rename32
#!/usr/bin/bash
lib=$1
mkdir tmp
cd tmp
ar -X32_64 -x ../$lib
for i in *
do
base=`echo $i | awk -F\. '{ print $1 }'`
base="$base"_32
mv $i "$base".o
done

This is invoked by

rename32 library_to_split_and_rename

The script makes a directory tmp in the working directory, splits up the library into tmp and renames the files by adding a _32 to the name.

So

prompt> ~/bin/rename32 lapack.a
prompt> ls -l tmp | head
total 80576
-rw------- 1 ijb z001 11497 Mar 04 12:40 cbdsqr_32.o
-rw------- 1 ijb z001 8823 Mar 04 12:40 cgbbrd_32.o
-rw------- 1 ijb z001 3915 Mar 04 12:40 cgbcon_32.o
-rw------- 1 ijb z001 4717 Mar 04 12:40 cgbequ_32.o
-rw------- 1 ijb z001 7685 Mar 04 12:40 cgbrfs_32.o
-rw------- 1 ijb z001 1525 Mar 04 12:40 cgbsv_32.o
-rw------- 1 ijb z001 8807 Mar 04 12:40 cgbsvx_32.o
-rw------- 1 ijb z001 2815 Mar 04 12:40 cgbtf2_32.o
-rw------- 1 ijb z001 8487 Mar 04 12:40 cgbtrf_32.o

Creating the new library

This is done by

prompt> ar -X32_64 -cr liblapack.a tmp/*
prompt> ar -X32_64 -t liblapack.a | head
cbdsqr_32.o
cgbbrd_32.o
cgbcon_32.o
cgbequ_32.o
cgbrfs_32.o
cgbsv_32.o
cgbsvx_32.o
cgbtf2_32.o
cgbtrf_32.o
cgbtrs_32.o

Note: you will now probably want to clean up the tmp directory that the script above created

prompt> rm -rf tmp

Tidy up for next compilation

For lapack the command

prompt> make clean

will tidy up the object files. You will also want to remove the lapack.a file.

prompt> rm lapack.a

Creating the 64 bit lapack.a

This is very similar to the procedure for the 32 bit case, simply change all the occurences of -q32 to -q64. So the flags become

FORTRAN = xlf90_r
OPTS = -qfixed -O3 -q64 -qarch=pwr4 -qtune=pwr4
DRVOPTS = $(OPTS)
NOOPT = -qfixed -q64

ARCH = ar
ARCHFLAGS= -X32_64 cr

As before make lapacklib now makes the library

Splitting the library and renaming the 64 bit files

Again this is most easily done using a script:

prompt> cat ~/bin/rename64
#!/usr/bin/bash
lib=$1
mkdir tmp
cd tmp
ar -X32_64 -x ../$lib
for i in *
do
base=`echo $i | awk -F\. '{ print $1 }'`
base="$base"_64
mv $i "$base".o
done

And the procedure is, apart from the name of the script, the same as for 32 bit files:

prompt> ~/bin/rename64 lapack.a
prompt> ls -l tmp | head
total 83264
-rw------- 1 ijb z001 12685 Mar 04 13:00 cbdsqr_64.o
-rw------- 1 ijb z001 9290 Mar 04 13:00 cgbbrd_64.o
-rw------- 1 ijb z001 4843 Mar 04 13:00 cgbcon_64.o
-rw------- 1 ijb z001 4792 Mar 04 13:00 cgbequ_64.o
-rw------- 1 ijb z001 8414 Mar 04 13:00 cgbrfs_64.o
-rw------- 1 ijb z001 1841 Mar 04 13:00 cgbsv_64.o
-rw------- 1 ijb z001 9474 Mar 04 13:00 cgbsvx_64.o
-rw------- 1 ijb z001 3141 Mar 04 13:00 cgbtf2_64.o
-rw------- 1 ijb z001 9132 Mar 04 13:00 cgbtrf_64.o

Adding the 64 bit object files to the library

This is the same as for the 32 bit case:

prompt> ar -X32_64 -cr liblapack.a tmp/*
prompt> ar -X32_64 -t liblapack.a | grep cbdsqr
cbdsqr_32.o
cbdsqr_64.o

You should now have a library that links to both 32 and 64 bit compilations.

spacer
hr
spacer
http://www.hpcx.ac.uk/support/FAQ/lib_32_64.html contact email - www@hpcx.ac.uk © UoE HPCX Ltd