Building PalmOS GLib Shared Libraries

Recently I was upgrading my Keyring installation to version 1.2.3. As usual, I was upgrading by re-compiling from the source.

It turned out that the developers have changed the code so that it no longer relies on PalmOS' built-in DES and MD5 functions but use the shared libraries DESLib.prc and MDLib.prc instead. Both are included as binaries in the distribution, so it is straight-forward to just use them. Out of curiosity I was interested to learn how these shared libraries were created. So I went into a slightly more difficult exercise than I had anticipated. Here's how it goes:

The libraries originate from the ISAAC project of the Computer Science Division at the University of California, Berkeley. This project has created a so-called GLib format for shared libraries that can be created with the prc-tools. Part of the ISAAC project are several PalmOS applications, among them a port of SSLeay (currently version 0.8.1) to PalmOS called pilotSSLeay that is currently available as release version 2.01.

But unfortunately, the state of pilotSSLeay is quite a bit out of sync with current prc-tools. A lot of features have been added to prc-tools, several tools have been removed or radically changed, but the most visible change is the removal of the "coff" distinguisher; for example m68k-palmos-coff-gcc became m68k-palmos-gcc. As it may change further in the future, this story holds for version 2.3. Here's my recipe:

Download SSLeay-0.8.1.tar.gz and pilotSSLeay-2.01.tar.gz. Unpack both tarballs to some directory, and (for the sake of completeness of the exercise) also download and unpack keyring-1.2.3.tar.gz into the same directory:

~/tmp # ls -laF
total 2844
drwxr-xr-x   2 hmo  staff     1024 Jul 27 20:28 ./
drwxr-xr-x  41 hmo  staff     3584 Jul 27 20:24 ../
-rw-r--r--   1 hmo  staff  1012844 Jul 23 23:22 SSLeay-0.8.1.tar.gz
-rw-r--r--   1 hmo  staff   118831 Jul 18 11:34 keyring-1.2.3.tar.gz
-rw-r--r--   1 hmo  staff  1728948 Jul 23 23:14 pilotSSLeay-2.01.tar.gz
~/tmp # tar xfz SSLeay-0.8.1.tar.gz
~/tmp # tar xfz keyring-1.2.3.tar.gz
~/tmp # tar xfz pilotSSLeay-2.01.tar.gz
~/tmp # ls -laF
total 2850
drwxr-xr-x   5 hmo  staff      512 Jul 27 20:29 ./
drwxr-xr-x  41 hmo  staff     3584 Jul 27 20:24 ../
drwxr-xr-x  20 hmo  staff     1024 Jul 27 20:29 SSLeay-0.8.1/
-rw-r--r--   1 hmo  staff  1012844 Jul 23 23:22 SSLeay-0.8.1.tar.gz
drwx--x--x   5 hmo  staff     1536 Oct 27  2003 keyring-1.2.3/
-rw-r--r--   1 hmo  staff   118831 Jul 18 11:34 keyring-1.2.3.tar.gz
drwxr-xr-x   6 hmo  staff      512 Jan  2  1998 pilotSSLeay-2.01/
-rw-r--r--   1 hmo  staff  1728948 Jul 23 23:14 pilotSSLeay-2.01.tar.gz
~/tmp # 

You may want to read pilotSSLeay-2.01/README which describes briefly the next steps in creating a GLib shared library. First, we go to the SSLeay-0.8.1 directory and apply the patch from pilotSSLeay-2.01.tar.gz:

~/tmp # cd SSLeay-0.8.1
~/tmp/SSLeay-0.8.1 # patch -p1 <../pilotSSLeay-2.01/pilotSSLeay-2.01.diff
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff -urN -x Makefile -x include SSLeay-0.8.1-orig/Configure SSLeay-0.8.1/Configure
|--- SSLeay-0.8.1-orig/Configure        Fri Jul 18 15:15:56 1997
|+++ SSLeay-0.8.1/Configure     Tue Dec 30 20:02:11 1997
--------------------------
Patching file Configure using Plan A...
Hunk #1 succeeded at 70.
Hmm...  The next patch looks like a unified diff to me...
········ lots of output here ········
The text leading up to this was:
--------------------------
|diff -urN -x Makefile -x include SSLeay-0.8.1-orig/e_os.h SSLeay-0.8.1/e_os.h
|--- SSLeay-0.8.1-orig/e_os.h   Fri Jul 18 15:15:56 1997
|+++ SSLeay-0.8.1/e_os.h        Tue Dec 30 20:02:12 1997
--------------------------
Patching file e_os.h using Plan A...
Hunk #1 succeeded at 76.
Hunk #2 succeeded at 146.
done
~/tmp/SSLeay-0.8.1 #

Now we need to fix the Configure script to cater for the newer prc-tools release. There is a new m68k-palmos-gcc option -mown-gp which makes prc-tools address global data through the A4 register instead of A5. This is what we need for a shared GLib library. Look here for a more detailed description of the options. This is also the right place to add the correct PalmOS SDK pointer. For visibility we perform the modification in a ed script here and start Configure:

~/tmp/SSLeay-0.8.1 # ed Configure
17496
,s/m68k-palmos-coff-gcc:-O2/m68k-palmos-gcc:-mown-gp -palmos3.1 -O2/
17487
w
17502
q
~/tmp/SSLeay-0.8.1 # perl Configure palmos
CC     =m68k-palmos-gcc
CFLAG  =-mown-gp -palmos3.1 -O2 -g -fno-builtin
EX_LIBS=
BN_MULW=asm/m68k-palmos.o
DES_ENC=des_enc.o fcrypt_b.o
BF_ENC =bf_enc.o
SIXTEEN_BIT mode
BN_LLONG mode
~/tmp/SSLeay-0.8.1 # 

Now it's time to build SSLeay-0.8.1. Note that GNU make is required for this step and all others in this description. I am using the gmake command to clarify this.

~/tmp/SSLeay-0.8.1 # gmake
making crypto...
making all in md...
m68k-palmos-gcc -I.. -I../../include -mown-gp -palmos3.1 -O2 -g -fno-builtin -c md2_dgst.c
········ lots of output here ········
m68k-palmos-gcc -I.. -I../../include -mown-gp -palmos3.1 -O2 -g -fno-builtin -c dh_err.c
ar r ../../libdh.a dh_gen.o dh_key.o dh_lib.o dh_check.o dh_err.o
sh ../../util/ranlib.sh ../../libdh.a
~/tmp/SSLeay-0.8.1 # ls -laF *.a
-rw-r--r--  1 hmo  staff   117348 Jul 27 21:02 libbf.a
-rw-r--r--  1 hmo  staff  1677410 Jul 27 21:02 libbn.a
-rw-r--r--  1 hmo  staff  2376894 Jul 27 21:02 libdes.a
-rw-r--r--  1 hmo  staff   411910 Jul 27 21:03 libdh.a
-rw-r--r--  1 hmo  staff    11264 Jul 27 21:02 libidea.a
-rw-r--r--  1 hmo  staff   351540 Jul 27 21:01 libmd.a
-rw-r--r--  1 hmo  staff   208060 Jul 27 21:01 librand.a
-rw-r--r--  1 hmo  staff     9912 Jul 27 21:02 librc2.a
-rw-r--r--  1 hmo  staff     3172 Jul 27 21:02 librc4.a
-rw-r--r--  1 hmo  staff   321318 Jul 27 21:02 librsa.a
-rw-r--r--  1 hmo  staff   297976 Jul 27 21:01 libsha.a
~/tmp/SSLeay-0.8.1 # 

We now have a bunch of crypto libraries that we will use in the next steps. We now move to the pilotSSLeay-2.01/lib directory, store away the existing library files and replace them with symbolic links to out freshly created ones. Then we re-create the libraries' symbol tables. Note that it is important to use the prc-tools' m68k-palmos-ar instead of your system's ar during this step!

~/tmp/SSLeay-0.8.1 # cd ../pilotSSLeay-2.01/lib
~/tmp/pilotSSLeay-2.01/lib # ls -laF
total 4934
drwxr-xr-x  2 hmo  staff      512 May 30  1997 ./
drwxr-xr-x  6 hmo  staff      512 Jan  2  1998 ../
-rw-r--r--  1 hmo  staff   103598 Dec 31  1997 libbf.a
-rw-r--r--  1 hmo  staff  1455328 Dec 31  1997 libbn.a
-rw-r--r--  1 hmo  staff  2058396 Dec 31  1997 libdes.a
-rw-r--r--  1 hmo  staff   356356 Dec 31  1997 libdh.a
-rw-r--r--  1 hmo  staff    11538 Dec 31  1997 libidea.a
-rw-r--r--  1 hmo  staff   271810 Dec 31  1997 libmd.a
-rw-r--r--  1 hmo  staff   180308 Dec 31  1997 librand.a
-rw-r--r--  1 hmo  staff    10466 Dec 31  1997 librc2.a
-rw-r--r--  1 hmo  staff     3574 Dec 31  1997 librc4.a
-rw-r--r--  1 hmo  staff   279982 Dec 31  1997 librsa.a
-rw-r--r--  1 hmo  staff   193970 Dec 31  1997 libsha.a
~/tmp/pilotSSLeay-2.01/lib # for f in *.a; do mv $f $f.ORIG; ln -s ../../SSLeay-0.8.1/$f $f; done
~/tmp/pilotSSLeay-2.01/lib # ls -laF
total 4934
drwxr-xr-x  2 hmo  staff      512 Jul 27 21:31 ./
drwxr-xr-x  6 hmo  staff      512 Jan  2  1998 ../
lrwxr-xr-x  1 hmo  staff       26 Jul 27 21:31 libbf.a@ -> ../../SSLeay-0.8.1/libbf.a
-rw-r--r--  1 hmo  staff   103598 Dec 31  1997 libbf.a.ORIG
lrwxr-xr-x  1 hmo  staff       26 Jul 27 21:31 libbn.a@ -> ../../SSLeay-0.8.1/libbn.a
-rw-r--r--  1 hmo  staff  1455328 Dec 31  1997 libbn.a.ORIG
lrwxr-xr-x  1 hmo  staff       27 Jul 27 21:31 libdes.a@ -> ../../SSLeay-0.8.1/libdes.a
-rw-r--r--  1 hmo  staff  2058396 Dec 31  1997 libdes.a.ORIG
lrwxr-xr-x  1 hmo  staff       26 Jul 27 21:31 libdh.a@ -> ../../SSLeay-0.8.1/libdh.a
-rw-r--r--  1 hmo  staff   356356 Dec 31  1997 libdh.a.ORIG
lrwxr-xr-x  1 hmo  staff       28 Jul 27 21:31 libidea.a@ -> ../../SSLeay-0.8.1/libidea.a
-rw-r--r--  1 hmo  staff    11538 Dec 31  1997 libidea.a.ORIG
lrwxr-xr-x  1 hmo  staff       26 Jul 27 21:31 libmd.a@ -> ../../SSLeay-0.8.1/libmd.a
-rw-r--r--  1 hmo  staff   271810 Dec 31  1997 libmd.a.ORIG
lrwxr-xr-x  1 hmo  staff       28 Jul 27 21:31 librand.a@ -> ../../SSLeay-0.8.1/librand.a
-rw-r--r--  1 hmo  staff   180308 Dec 31  1997 librand.a.ORIG
lrwxr-xr-x  1 hmo  staff       27 Jul 27 21:31 librc2.a@ -> ../../SSLeay-0.8.1/librc2.a
-rw-r--r--  1 hmo  staff    10466 Dec 31  1997 librc2.a.ORIG
lrwxr-xr-x  1 hmo  staff       27 Jul 27 21:31 librc4.a@ -> ../../SSLeay-0.8.1/librc4.a
-rw-r--r--  1 hmo  staff     3574 Dec 31  1997 librc4.a.ORIG
lrwxr-xr-x  1 hmo  staff       27 Jul 27 21:31 librsa.a@ -> ../../SSLeay-0.8.1/librsa.a
-rw-r--r--  1 hmo  staff   279982 Dec 31  1997 librsa.a.ORIG
lrwxr-xr-x  1 hmo  staff       27 Jul 27 21:31 libsha.a@ -> ../../SSLeay-0.8.1/libsha.a
-rw-r--r--  1 hmo  staff   193970 Dec 31  1997 libsha.a.ORIG
~/tmp/pilotSSLeay-2.01/lib # for f in *.a; do m68k-palmos-ar s $f; done
~/tmp/pilotSSLeay-2.01/lib # 

We move on to the pilotSSLeay-2.01/shlib directory and again we move the existing stuff out of our way.

~/tmp/pilotSSLeay-2.01/lib # cd ../shlib
~/tmp/pilotSSLeay-2.01/shlib # for f in *.sa *.prc; do mv $f $f.ORIG; done
~/tmp/pilotSSLeay-2.01/shlib # mv Makefile Makefile.ORIG
~/tmp/pilotSSLeay-2.01/shlib # 

Note that we have also moved the Makefile away. The reason is that this Makefile is desparately out of date with respect to the recent prc-tools. Please use this Makefile instead to build the GLib .prc files. The most notable differences are:

And here it goes:

~/tmp/pilotSSLeay-2.01/shlib # gmake
(echo glib { \"Bignum Library\" CrBN }; \
echo export {; \
(m68k-palmos-nm ../lib/libbn.a | grep ' T ' | cut -c12- | sort -u) ; \
echo }) > bn.def
m68k-palmos-stubgen --base BN bn.def
m68k-palmos-as   -o BN-jumps.o BN-jumps.s
(echo glib { \"RAND Library\" CrRN }; \
echo export {; \
(m68k-palmos-nm ../lib/librand.a | grep ' T ' | cut -c12- | sort -u) ; \
echo }) > rand.def
m68k-palmos-stubgen --base RAND rand.def
m68k-palmos-gcc -O2 -g   -c -o RAND-stubs.o RAND-stubs.c
········ lots of output here ········
m68k-palmos-ar rcs librc2.sa RC2-stubs.o
m68k-palmos-gcc -O2 -g   -c -o RC4-stubs.o RC4-stubs.c
m68k-palmos-ar rcs librc4.sa RC4-stubs.o
m68k-palmos-gcc -O2 -g   -c -o RSA-stubs.o RSA-stubs.c
m68k-palmos-ar rcs librsa.sa RSA-stubs.o
~/tmp/pilotSSLeay-2.01/shlib # ls -laF *.prc
-rw-r--r--  1 hmo  staff  20684 Jul 27 21:39 BNLib.prc
-rw-r--r--  1 hmo  staff  10926 Jul 27 21:39 BlowfishLib.prc
-rw-r--r--  1 hmo  staff  26771 Jul 27 21:39 DESLib.prc
-rw-r--r--  1 hmo  staff   4042 Jul 27 21:39 DHLib.prc
-rw-r--r--  1 hmo  staff   5326 Jul 27 21:39 IDEALib.prc
-rw-r--r--  1 hmo  staff   6270 Jul 27 21:39 MDLib.prc
-rw-r--r--  1 hmo  staff   4450 Jul 27 21:39 RANDLib.prc
-rw-r--r--  1 hmo  staff   4654 Jul 27 21:39 RC2Lib.prc
-rw-r--r--  1 hmo  staff   2962 Jul 27 21:39 RC4Lib.prc
-rw-r--r--  1 hmo  staff   7070 Jul 27 21:39 RSALib.prc
-rw-r--r--  1 hmo  staff  13606 Jul 27 21:39 SHALib.prc
~/tmp/pilotSSLeay-2.01/shlib # ls -laF *.def
-rw-r--r--  1 hmo  staff  141 Jul 27 21:39 bf.def
-rw-r--r--  1 hmo  staff  760 Jul 27 21:39 bn.def
-rw-r--r--  1 hmo  staff  590 Jul 27 21:39 des.def
-rw-r--r--  1 hmo  staff  125 Jul 27 21:39 dh.def
-rw-r--r--  1 hmo  staff  180 Jul 27 21:39 idea.def
-rw-r--r--  1 hmo  staff  118 Jul 27 21:39 md.def
-rw-r--r--  1 hmo  staff  133 Jul 27 21:39 rand.def
-rw-r--r--  1 hmo  staff  131 Jul 27 21:39 rc2.def
-rw-r--r--  1 hmo  staff   67 Jul 27 21:39 rc4.def
-rw-r--r--  1 hmo  staff  215 Jul 27 21:39 rsa.def
-rw-r--r--  1 hmo  staff  111 Jul 27 21:39 sha.def
~/tmp/pilotSSLeay-2.01/shlib # ls -laF *-stubs.c
-rw-r--r--  1 hmo  staff  5523 Jul 27 21:39 BN-stubs.c
-rw-r--r--  1 hmo  staff  2017 Jul 27 21:39 Blowfish-stubs.c
-rw-r--r--  1 hmo  staff  4095 Jul 27 21:39 DES-stubs.c
-rw-r--r--  1 hmo  staff  1990 Jul 27 21:39 DH-stubs.c
-rw-r--r--  1 hmo  staff  2142 Jul 27 21:39 IDEA-stubs.c
-rw-r--r--  1 hmo  staff  2059 Jul 27 21:39 MD-stubs.c
-rw-r--r--  1 hmo  staff  2007 Jul 27 21:39 RAND-stubs.c
-rw-r--r--  1 hmo  staff  1962 Jul 27 21:39 RC2-stubs.c
-rw-r--r--  1 hmo  staff  1711 Jul 27 21:39 RC4-stubs.c
-rw-r--r--  1 hmo  staff  2337 Jul 27 21:39 RSA-stubs.c
-rw-r--r--  1 hmo  staff  2004 Jul 27 21:39 SHA-stubs.c
~/tmp/pilotSSLeay-2.01/shlib # 

Done! Now we have created the .prc GLib libraries for upload to the palm, and the .def and base-stubs.c files for creating applications that make use of the GLib shared libraries.

Finally, an exercise for building keyring-1.2.3 to make use of the freshly created files. Again, we store away the existing files in that build directory and create symbolic links for our new files instead. Actually, it doesn't make much difference, as the new files essentially identical to the old ones, but it's a good habit.

~/tmp/pilotSSLeay-2.01/shlib # cd ../../keyring-1.2.3
~/tmp/keyring-1.2.3 # ls -laF ssl*
-rw-------  1 hmo  staff  4123 Oct 27  2003 ssl-des-stubs.c
-rw-------  1 hmo  staff   590 Oct 27  2003 ssl-des.def
-rw-------  1 hmo  staff  2087 Oct 27  2003 ssl-md-stubs.c
-rw-------  1 hmo  staff   118 Oct 27  2003 ssl-md.def
~/tmp/keyring-1.2.3 # for f in ssl*; do mv $f $f.ORIG; done
~/tmp/keyring-1.2.3 # ln -s ../pilotSSLeay-2.01/shlib/md.def ssl-md.def
~/tmp/keyring-1.2.3 # ln -s ../pilotSSLeay-2.01/shlib/des.def ssl-des.def
~/tmp/keyring-1.2.3 # ln -s ../pilotSSLeay-2.01/shlib/md-stubs.c ssl-md-stubs.c
~/tmp/keyring-1.2.3 # ln -s ../pilotSSLeay-2.01/shlib/des-stubs.c ssl-des-stubs.c
~/tmp/keyring-1.2.3 # ls -laF ssl*
lrwxr-xr-x  1 hmo  staff    37 Jul 27 21:47 ssl-des-stubs.c@ -> ../pilotSSLeay-2.01/shlib/des-stubs.c
-rw-------  1 hmo  staff  4123 Oct 27  2003 ssl-des-stubs.c.ORIG
lrwxr-xr-x  1 hmo  staff    33 Jul 27 21:46 ssl-des.def@ -> ../pilotSSLeay-2.01/shlib/des.def
-rw-------  1 hmo  staff   590 Oct 27  2003 ssl-des.def.ORIG
lrwxr-xr-x  1 hmo  staff    36 Jul 27 21:46 ssl-md-stubs.c@ -> ../pilotSSLeay-2.01/shlib/md-stubs.c
-rw-------  1 hmo  staff  2087 Oct 27  2003 ssl-md-stubs.c.ORIG
lrwxr-xr-x  1 hmo  staff    32 Jul 27 21:46 ssl-md.def@ -> ../pilotSSLeay-2.01/shlib/md.def
-rw-------  1 hmo  staff   118 Oct 27  2003 ssl-md.def.ORIG
~/tmp/keyring-1.2.3 # mv pilotSSLeay pilotSSLeay.ORIG
~/tmp/keyring-1.2.3 # ln -s ../pilotSSLeay-2.01 pilotSSLeay
~/tmp/keyring-1.2.3 # ls -laFd pilotSSLeay*
lrwxr-xr-x  1 hmo  staff   19 Jul 27 22:27 pilotSSLeay@ -> ../pilotSSLeay-2.01
drwxr-xr-x  4 hmo  staff  512 Oct 27  2003 pilotSSLeay.ORIG/
~/tmp/keyring-1.2.3 # gmake
(echo '// ******DYNAMICALLY GENERATED DO NOT EDIT********'; \
 sed -e "s/__VERSION__/1.2.3/g" -e "s/__DATE__/2004-07-27/g" keyring.rcp.ja keyring.rcp.iso2 keyring.rcp.in) > keyring.rcp
pilrc -allowEditID -H auto.h.tmp -q  -L en keyring.rcp res/en/ >/dev/null
perl script/mkproto.pl keyring.c keyedit.c keydb.c memutil.c listform.c crypto.c passwd.c uiutil.c generate.c prefs.c export.c dbutil.c upgrade.c record.c category.c setpasswd.c pwhash.c snib.c reencrypt.c pack.c unpack.c sort.c secrand.c search.c pronounce.c > prototype.h.new
Installing new prototype.h
m68k-palmos-gcc -O2  -Wall -Winline -Wunused -W -Wstrict-prototypes -Wmissing-prototypes -Wlarger-than-260 -Wshadow -Wcast-align -DkAppVersion=0x1023 -IpilotSSLeay/include -c keyring.c -o keyring.o
········ lots of output here ········
m68k-palmos-stubgen ssl-md.def
m68k-palmos-gcc -O2  -Wall -Winline -Wunused -W -Wstrict-prototypes -Wmissing-prototypes -Wlarger-than-260 -Wshadow -Wcast-align -DkAppVersion=0x1023 -IpilotSSLeay/include -c ssl-md-stubs.c -o ssl-md-stubs.o
ssl-md-stubs.c:23: warning: no previous prototype for `GLib_CrMD'
ssl-md-stubs.c:111: warning: function declaration isn't a prototype
m68k-palmos-stubgen ssl-des.def
m68k-palmos-gcc -O2  -Wall -Winline -Wunused -W -Wstrict-prototypes -Wmissing-prototypes -Wlarger-than-260 -Wshadow -Wcast-align -DkAppVersion=0x1023 -IpilotSSLeay/include -c ssl-des-stubs.c -o ssl-des-stubs.o
ssl-des-stubs.c:23: warning: no previous prototype for `GLib_CrDS'
ssl-des-stubs.c:215: warning: function declaration isn't a prototype
m68k-palmos-gcc -O2  -Wall -Winline -Wunused -W -Wstrict-prototypes -Wmissing-prototypes -Wlarger-than-260 -Wshadow -Wcast-align -DkAppVersion=0x1023 -IpilotSSLeay/include keyring.o keyedit.o keydb.o memutil.o listform.o crypto.o passwd.o uiutil.o generate.o prefs.o export.o dbutil.o upgrade.o record.o category.o setpasswd.o pwhash.o snib.o reencrypt.o pack.o unpack.o sort.o secrand.o search.o pronounce.o ssl-md-stubs.o ssl-des-stubs.o -lPalmOSGlue -o keyring
cd res/en; build-prc ../../keyring-1.2.3-en.prc 'Keyring' Gtkr ../../keyring *.bin
~/tmp/keyring-1.2.3 # ls -laF *.prc
-rw-r--r--  1 hmo  staff  42957 Jul 27 21:48 keyring-1.2.3-en.prc
~/tmp/keyring-1.2.3 # 

Done. Tested this application and the DESLib.prc and MDLib.prc libraries with pose and on a real Palm, and it indeed works as expected.


automagically generated for 38.103.63.18 at 22 May 2008 21:58:47 CEST
last modified by myself at 23 Feb 2006 07:57:02 CET
accessed 1631 times since 13 May 2005 16:37:24 CEST
validated HTML 4.01