Messing with the Dynamic Linker to run Old Versions of Maple

Currently our funds are a little lacking for upgrading licenses at $WORK. Fortunately many of our users don't need the functionality in the newer versions of the math software we provide in the department. Unfortunately for me, that means I needed to figure out a way to keep really old versions of Maple running on newer equipment.

For practical purposes, here are the steps to sandbox such an app, with old versions of libc, the dynamic linker, and some other libraries it needs.

Illustrating the difference between the architectures and kernels

root@newmapleserver# uname -a
Linux byrd.math.ksu.edu 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

root@oldmapleserver# uname -a 
Linux newton 2.6.8-4-686-smp #1 SMP Mon Apr 30 08:15:22 UTC 2007 i686 GNU/Linux

Copy the installed maple distribution from the old server to the new server

root@newmapleserver# rsync -av root@oldmapleserver:/usr/local/maple/ /usr/local/maple/

Copy some of the necessary libraries

# Make a new place for the copied libraries from the old system 
root@newmapleserver# mkdir -p /usr/local/maple/syslib

# Copy the libs
root@newmapleserver# scp -r "root@oldmapleserver:/lib/ld-linux.so.2" /usr/local/maple/syslibs/
root@newmapleserver# scp -r "root@oldmapleserver:/lib/libc.so.6" /usr/local/maple/syslibs/
root@newmapleserver# scp -r "root@oldmapleserver:/lib/libdl.so.2" /usr/local/maple/syslibs/
root@newmapleserver# scp -r "root@oldmapleserver:/lib/libm.so.6" /usr/local/maple/syslibs/

Modify the runner scripts to include our freshly-downloaded old libraries

# in /usr/local/maple/bin/maple find the line exporting LD_LIBRARY_PATH 
# and add $MAPLE/syslib to the beginning

LD_LIBRARY_PATH=$MAPLE/syslib:$MAPLE/$MAPLE_SYS_BIN:$LD_LIBRARY_PATH

Now the fun part

The actual binaries are located in ${MAPLE}/bin.IBM_INTEL_LINUX and are hard-coded to use /lib/ld-linux.so.2 which is much newer than maple expects. It appears that there was some symbol shuffling somewhere along the way which gives the following error:

root@newmapleserver# /usr/local/maple/bin/maple
cmaple: relocation error: /usr/local/maple/syslib/libc.so.6: symbol _dl_out_of_memory, version GLIBC_PRIVATE not defined in file ld-linux.so.2 with link time reference

To fix this we need a way to use our own dynamic linker (ld-linux.so.2) to run the executable.

Let's create our own dynamic linker to use with maple:

# We have already downloaded ld-linux.so.2 from oldmapleserver and put it in
# syslibs so we just need to put it in /lib (We will find out why in a
# moment)
root@newmapleserver# ln -svf /usr/local/maple/syslibs/ld-linux.so.2 /lib/ld-MAPLE.so.2
`/lib/ld-MAPLE.so.2' -> `/usr/local/maple/syslibs/ld-linux.so.2'

Now find all the binaries that use ld-linux.so.2:

root@newmapleserver# cd /usr/local/maple/bin.IBM_INTEL_LINUX
root@newmapleserver# grep -l 'ld-linux.so.2' ./*
./cmaple
./maplew
./mint
./mplotbmp
./mplotchar
./mplotcps
./mplotdxf
./mplotgif
./mplothpgl
./mplothplj
./mplotjpeg
./mplotpcx
./mplotpov
./mplotps
./mplottek
./mplotwmf
./mplotx11
./mserver

All of these binaries contain a hard-coded reference to /lib/ld-linux.so.2 somewhere. To make them run properly we need a copy of the correct dynamic linker and we need the full path name (including the filename) to be the same number of characters as /lib/ld-linux.so.2 (i.e. we have 18 chars to work with). Otherwise, the executable would be off by a few bytes somewhere and would likely result in segfaults. Luckily the symlink we created above, /lib/ld-MAPLE.so.2, has 18 characters so we can use that.

# still in /usr/local/maple/bin.IBM_INTEL_LINUX
root@newmapleserver# sed 's#ld-linux.so.2#ld-MAPLE.so.2#' -i ./*

Just as a test, we can run the maple binary just as the script would by setting the correct env variables

root@newmapleserver# MAPLE=/usr/local/maple \
LD_LIBRARY_PATH=$MAPLE/syslibs:$MAPLE/bin.IBM_INTEL_LINUX:$LD_LIBRARY_PATH \
LD_ASSUME_KERNEL=2.4.1 \ 
/usr/local/maple/bin.IBM_INTEL_LINUX/cmaple

    |\^/|     Maple 7 (IBM INTEL LINUX)
._|\|   |/|_. Copyright (c) 2001 by Waterloo Maple Inc.
 \  MAPLE  /  All rights reserved. Maple is a registered trademark of
 <____ ____>  Waterloo Maple Inc.
      |       Type ? for help.
> 1+2;
                                             3

Et VoilĂ 

We now have a working Maple install on modern hardware

Copyright © 2012-2014 Brian Stinson. All Rights Reserved