home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / docs / elf-howt < prev    next >
Encoding:
Text File  |  1996-07-11  |  38.4 KB  |  862 lines

  1.   The Linux ELF HOWTO
  2.   Daniel Barlow <daniel.barlow@sjc.ox.ac.uk>
  3.   v1.11, 13 September 1995
  4.  
  5.   This document describes how to migrate your Linux system to compile
  6.   and run programs in the ELF binary format.  It falls into three con¡
  7.   ceptual parts: (1) What ELF is, and why/whether you should upgrade,
  8.   (2) How to upgrade to ELF-capability, and (3) what you can do then.
  9.  
  10.   1.  What is ELF?  An introduction
  11.  
  12.   ELF (Executable and Linking Format) is a binary format originally
  13.   developed by USL (UNIX System Laboratories) and currently used in
  14.   Solaris and System V Release 4.  Because of its increased flexibility
  15.   over the older a.out format that Linux currently uses, the GCC and C
  16.   library developers decided last year to move to using ELF as the Linux
  17.   standard binary format also.
  18.  
  19.   This `increased flexibility' manifests as essentially two benefits to
  20.   the average applications progammer:
  21.  
  22.   ╖  It is much simpler to make shared libraries with ELF.  Typically,
  23.      just compile all the object files with -fPIC, then link with a
  24.      command like
  25.  
  26.         gcc -shared -Wl,-soname,libfoo.so.y -o libfoo.so.y.x *.o
  27.  
  28.   If that looks complex, you obviously haven't ever read up on the
  29.   equivalent procedure for a.out shared libraries, which involves com¡
  30.   piling the library twice, reserving space for all the data you think
  31.   that the library is likely to require in future, and registering that
  32.   address space with a third party (it's described in a document over 20
  33.   pages long --- look at
  34.   <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/src/tools-2.16.tar.gz>
  35.   for details).
  36.  
  37.   ╖  It makes dynamic loading (ie programs which can load modules at
  38.      runtime) much simpler.  This is used by Perl 5, Python, and the
  39.      ongoing port of Java to Linux, among other things.  Other
  40.      suggestions for dynamic loading have included super-fast MUDs,
  41.      where extra code could be compiled and linked into the running
  42.      executable without having to stop and restart the program.
  43.  
  44.   Against this it must be weighed that ELF is possibly a bit slower.
  45.   The figures that get bandied around are between 1% and 5%, though all
  46.   the actual tests that have been conducted so far indicate that the
  47.   difference is small enough to get lost in the noise of other events
  48.   happening at the same time.  If you have TeX or a Postscript
  49.   viewer/printer, you can read speed.comp-1.0.tar.gz, which is available
  50.   from SunSite somewhere.
  51.  
  52.   The slowdown comes from the fact that ELF library code must be
  53.   position independent (this is what the -fPIC above stands for) and so
  54.   a register must be devoted to holding offsets.  That's one less for
  55.   holding variables in, and the 80x86 has a paucity of general-purpose
  56.   registers anyway.
  57.   1.1.  What ELF isn't
  58.  
  59.   There are a number of common misconceptions about what ELF will do for
  60.   your system:
  61.  
  62.      It's not a way to run SVR4 or Solaris programs
  63.         Although it's the same binary `container' as SVR4 systems use,
  64.         that doesn't mean that SVR4 programs suddenly become runnable on
  65.         Linux.  It's analogous to a disk format --- you can keep Linux
  66.         programs on MSDOS or Minix-format disks, and vice versa, but
  67.         that doesn't mean that these systems become able to run each
  68.         others' programs.
  69.  
  70.         It is theoretically possible to run applications for other x86
  71.         Unices under Linux, but following the instructions in this HOWTO
  72.         will not have that effect.  Start by looking at the iBCS kernel
  73.         module (somewhere on tsx-11.mit.edu) and see if it fits your
  74.         needs.
  75.  
  76.      It's not intrinsically smaller or faster
  77.         You may well end up with smaller binaries anyway, though, as you
  78.         can more easily create shared libraries of common code between
  79.         many programs.  In general, if you use the same compiler options
  80.         and your binaries come out smaller than they did with a.out,
  81.         it's more likely to be fluke or a different compiler version.
  82.         As for `faster', I'd be surprised.  Speed increases could turn
  83.         up if your binaries are smaller, due to less swapping or larger
  84.         functional areas fitting in cache.
  85.  
  86.      It doesn't require that you replace every binary on your system
  87.         At the end of this procedure you have a system capable of
  88.         compiling and running both ELF and a.out programs.  New programs
  89.         will by default be compiled in ELF, though this can be
  90.         overridden with a command-line switch.  There is admittedly a
  91.         memory penalty for running a mixed ELF/a.out system --- if you
  92.         have both breeds of program running at once you also have two
  93.         copies of the C library in core, and so on.  I've had reports
  94.         that the speed difference from this is undetectable in normal
  95.         use on a 6Mb system though (I certainly haven't noticed much in
  96.         8Mb), so it's hardly pressing.  You lose far more memory every
  97.         day by running bloated programs like Emacs and static
  98.         Mosaic/Netscape binaries :-)
  99.  
  100.      It's nothing to do with Tolkien.
  101.         Or at least, not in this context.
  102.  
  103.   1.2.  Why you should(n't) convert to ELF
  104.  
  105.   There are essentially two reasons to upgrade your system to compile
  106.   and run ELF programs: the first is the increased flexibility in
  107.   programming referred to above, and the second is that, due to the
  108.   first, everyone else will be too.  Future releases of the C library
  109.   and GCC will only be compiled for ELF, and other developers are
  110.   expected to move ELFwards too.
  111.  
  112.   Pleasingly for the purposes of symmetry, there are also two reasons
  113.   not to convert at this time.  The first is that things are still
  114.   changing, some packages (including the `stable' 1.2 kernel series)
  115.   require patches to be made before they will compile in ELF, and there
  116.   may be residual bugs; one could make a strong case for waiting until
  117.   Linus himself has converted, for example.
  118.  
  119.   The second is that although the installation described here is a
  120.   fairly small job in itself (it can be completed in well under an hour,
  121.   excepting the time taken to download the new software), an error at
  122.   almost any stage of it will probably leave you with an unbootable
  123.   system.  If you are not comfortable with upgrading shared libraries
  124.   and the commands ldconfig and ldd mean nothing to you, you may want to
  125.   obtain or wait for a new Linux distribution in ELF, and backup,
  126.   reinstall and selectively restore your system using it.  Then again
  127.   (and especially if the system is not mission-critical) you may want to
  128.   go through it anyway and look on it as a learning experience.
  129.  
  130.   Still with us?
  131.  
  132.   2.  Installation
  133.  
  134.   2.1.  Background
  135.  
  136.   The aim of this conversion is to leave you with a system which can
  137.   build and run both a.out and ELF programs, with each type of program
  138.   being able to find its appropriate breed of shared libraries.  This
  139.   obviously requires a bit more intelligence in the library search
  140.   routines than the simple `look in /lib, /usr/lib and anywhere else
  141.   that the program was compiled to search' strategy that some other
  142.   systems can get away with.
  143.  
  144.   The beastie responsible for searching out libraries in linux is
  145.   /lib/ld.so.  The compiler and linker do not encode absolute library
  146.   pathnames into the programs they output; instead they put the library
  147.   name and the absolute path to ld.so in, and leave ld.so to match the
  148.   library name to the appropriate place at runtime.  This has one very
  149.   important effect --- it means that the libraries that a program uses
  150.   can be moved to other directories without recompiling the program,
  151.   provided that ld.so is told to search the new directory.  This is
  152.   essential functionality for the directory swapping operation that
  153.   follows.
  154.  
  155.   The corollary of the above, of course, is that any attempt to delete
  156.   or move ld.so will cause every dynamically linked program on the
  157.   system to stop working.  This is generally regarded as a Bad Thing.
  158.  
  159.   For ELF binaries, an alternate dynamic loader is provided.  This is
  160.    /lib/ld-linux.so.1, and does exactly the same thing as ld.so, but for
  161.   ELF programs.  ld-linux.so.1 uses the same support files and programs
  162.   (ldd, ldconfig, and /etc/ld.so.conf) as the a.out loader ld.so does.
  163.  
  164.   The basic plan, then, is that ELF development things (compilers,
  165.   include files and libraries) go into /usr/{bin,lib,include} where your
  166.   a.out ones currently are, and the a.out things will be moved into
  167.   /usr/i486-linuxaout/{bin, lib, include}.  /etc/ld.so.conf lists all
  168.   the places on the system where libraries are expected to be found, and
  169.   ldconfig is intelligent enough to distinguish between ELF and a.out
  170.   variants.
  171.  
  172.   There are a couple of exceptions to the library placement, though.
  173.  
  174.   ╖  Some old programs were built without the use of ld.so.  These would
  175.      all cease working if their libraries were moved from under them.
  176.      Thus, libc.so* and libm.so* must stay where they are in /lib, and
  177.      the ELF versions have had their major numbers upgraded so that they
  178.      do not overwrite the a.out ones.  Old X libraries (prior to version
  179.      6) are best left where they are also, although newer ones
  180.      (libX*so.6) must be moved.  Moving the old ones will apparently
  181.      break xview programs, and not moving the new ones will cause them
  182.      to be overwritten when you install ELF X libraries.
  183.  
  184.      If you have non-ld.so programs that require libraries other than
  185.      the above (if you know which programs they are, you can run ldd on
  186.      them to find out which libraries they need before breaking them)
  187.      you have essentially two options.  One, you can extract the ELF
  188.      library tar files into a temporary directory, check whether your
  189.      precious library would be overwritten, and if so, move the ELF
  190.      version of the library into, say, /usr/i486-linux/lib instead of
  191.      /lib.  Make sure your ld.so.conf has /usr/i486-linux/lib in it,
  192.      then run ldconfig and think no more on't.  Two, you can recompile
  193.      or acquire a newer copy of the offending program.  This might not
  194.      be a bad idea, if possible.
  195.  
  196.   ╖  If you have /usr and / on different partitions, you'll need to move
  197.      at least some of the libraries in /lib to somewhere on the root
  198.      disk, not on /usr.  Either you can go through the programs that you
  199.      need to run at system startup or when in single-user mode, and
  200.      identify the libraries they use, or you can depend on your
  201.      system/distribution integrator to have done this for you and just
  202.      move all (er ... some.  See above for the exceptions) of the
  203.      libraries in /lib to /lib-aout.
  204.  
  205.   2.2.  Before you start --- Notes and Caveats
  206.  
  207.   ╖  You will need to be running a post-1.1.52 kernel with ELF binary
  208.      format support.
  209.  
  210.   ╖  You are recommended to prepare or acquire a linux boot/root disk,
  211.      such as a Slackware rescue disk.  You probably won't need it, but
  212.      if you do and you don't have one, you'll kick yourself.  In a
  213.      similar `prevention is better than cure' vein, statically linked
  214.      copies of mv, ln, and maybe other file manipulation commands
  215.      (though in fact I think you can do everything else you actually
  216.      need to with shell builtins) may help you out of any awkward
  217.      situations you could end up in.
  218.  
  219.   ╖  If you have been following the ELF development, you may have ELF
  220.      libraries in /lib/elf (usually libc.so.4 and co).  Applications
  221.      that you built using these should be rebuilt, then the directory
  222.      removed.  There is no need for a /lib/elf directory!
  223.  
  224.   ╖  Most Linux installations these days have converged on the `FSSTND'
  225.      standard file system, but doubtless there are still installed
  226.      systems that haven't.  If you see references to /sbin/something and
  227.      you don't have a /sbin directory, you'll probably find the program
  228.      referred to in /bin or /etc/.
  229.  
  230.   2.3.  You will need ...
  231.  
  232.   The following packages are available from
  233.   <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/> and
  234.   <ftp://sunsite.unc.edu/pub/Linux/GCC/>.  Both sites are widely
  235.   mirrored; please take the time to look up your nearest mirror site and
  236.   use that instead of the master sites where possible.  It's faster for
  237.   both you and everyone else.
  238.  
  239.   These packages (either the listed version or a later one) are
  240.   required.  Also download and read through the release notes for each
  241.   of them: these are the files named release.packagename.  This applies
  242.   especially if you get newer versions than are listed here, as
  243.   procedures may have changed.
  244.  
  245.   ╖  ld.so-1.7.3.tar.gz --- the new dynamic linker
  246.  
  247.   ╖  libc-5.0.9.bin.tar.gz --- the ELF shared images for the C library
  248.      and its friends (m (maths), termcap, gdbm, and so on), plus the
  249.      corresponding static libraries and the include files needed to
  250.      compile programs with them.  libc 5.2.something is expected to be
  251.      released during the lifetime of this HOWTO, and is considerably
  252.      different from 5.0.9; if you want to install it, you're on your
  253.      own, but I'd recommend installing 5.0.9 first and then installing
  254.      it over the top.  There are several parts to libc 5.0.9 which are
  255.      not included in 5.2.x and for which the distribution channels are
  256.      not entirely set up yet.
  257.  
  258.   ╖  gcc-2.7.0.bin.tar.gz --- the ELF C compiler.  Also includes an
  259.      a.out C compiler which understands the new directory layout.
  260.  
  261.   ╖  binutils-2.5.2l.17.bin.tar.gz --- the GNU binary utilities patched
  262.      for Linux.  These are programs such as gas, ld, strings and so on,
  263.      most of which are required to make the C compiler go.
  264.  
  265.   2.4.  Rearranging your filesystem
  266.  
  267.   Sooo...  Note that in all that follows, when I say `remove' I
  268.   naturally mean `backup then remove' :-).  Also, these instructions
  269.   directly apply only to people who haven't yet messed with ELF ---
  270.   those who have are expected to have the necessary nous to adapt as
  271.   appropriate.  Let's go!
  272.  
  273.   1. Make the new directories that you will move a.out things to
  274.  
  275.        ______________________________________________________________________
  276.        mkdir -p /usr/i486-linuxaout/bin
  277.        mkdir -p /usr/i486-linuxaout/include
  278.        mkdir -p /usr/i486-linuxaout/lib
  279.        mkdir /lib-aout
  280.        ______________________________________________________________________
  281.  
  282.   2. Untar the dynamic linker package ld.so-1.7.3 in the directory you
  283.      usually put source code, then read through the
  284.      ld.so-1.7.3/instldso.sh script just unpacked.  If you have a really
  285.      standard system, run it by doing sh instldso.sh, but if you have
  286.      anything at all unusual then do the install by hand instead.
  287.      `Anything at all unusual' includes
  288.  
  289.   ╖  using zsh as a shell (some versions of zsh define $VERSION, which
  290.      seems to confuse instldso.sh)
  291.  
  292.   ╖  having symlinks from /lib/elf to /lib (which you shouldn't need,
  293.      but you may have valid reasons for if you have been following the
  294.      ELF development)
  295.  
  296.   3. Edit /etc/ld.so.conf to add the new directory
  297.      /usr/i486-linuxaout/lib (and /lib-aout if you're going to need
  298.      one).  Then rerun /sbin/ldconfig -v to check that it is picking up
  299.      the new directories.
  300.  
  301.   4. Move all the a.out libraries in /usr/*/lib to
  302.      /usr/i486-linuxaout/lib.  Note, I said `libraries' not
  303.      `everything'.  That's files matching the specification lib*.so* ,
  304.      lib*.sa*, or lib*.a.  Don't start moving /usr/lib/gcc-lib or
  305.      anything silly like that around.
  306.  
  307.   5. Now look at /lib.  Leave intact libc.so*, libm.so*, and libdl.so*.
  308.      If you have symlinks to X libraries (libX*.so.3*) leave them there
  309.      too --- XView and some other packages may require them.  Leave
  310.      ld.so*, ld-linux.so* and any other files starting with ld.  As for
  311.      the remaining libraries (if you have any left): if you have /usr on
  312.      the root partition, put them in /usr/i486-linuxaout/lib.  If you
  313.      have /usr mounted separately, put them in /lib-aout.  Now run
  314.      ldconfig -v
  315.  
  316.   6. Remove the directory /usr/lib/ldscripts if it's there, in
  317.      preparation for installing the binutils (which will recreate it)
  318.  
  319.   7. Remove any copies of ld and as (except for ld86 and as86) that you
  320.      can find in /usr/bin.
  321.  
  322.   8. Some versions of GNU tar appear to have problems dealing with
  323.      symbolic links in the destination directory.  You have two options
  324.      here:
  325.  
  326.      a. (preferred) Use cpio instead of tar, it doesn't have this
  327.         problem.  zcat /wherever/you/put/it/libc-5.0.9.tar.gz | cpio -iv
  328.         is the magic incantation here, to be executed from the root
  329.         directory.
  330.  
  331.      b. (if you don't have cpio installed) Before installing the libc
  332.         images you might want to go through /usr/include and remove some
  333.         parts.
  334.  
  335.         This is icky.  Many packages (such as ncurses) are installed
  336.         into /usr/include by distribution maintainers and are not
  337.         supplied with the C library.  Backup the /usr/include tree, use
  338.         tar tzf to see what's in the archive before untarring it, then
  339.         delete the bits of /usr/include that it actually fills.  Then
  340.         untar the libc-5.0.9.bin.tar.gz  package from root.
  341.  
  342.   9. Install the binutils package.  tar -xvzf
  343.      binutils-2.5.2.l17.bin.tar.gz -C /  is one perfectly good way to do
  344.      this.
  345.  
  346.   10.
  347.      You have now installed everything you need to run ELF executables.
  348.      Medical experts recommend that VDU workers take regular breaks away
  349.      from the screen; this would be an opportune moment.  Don't forget
  350.      what you were doing, though; depending on the version of gcc you
  351.      were previously using, you may have left yourself unable to compile
  352.      programs in a.out until you unpack the new gcc.
  353.  
  354.   11.
  355.      Backup and remove everything in /usr/lib/gcc-lib/{i486-linux,
  356.      i486-linuxelf, i486-linuxaout}/  If you use a non-standard gcc
  357.      driver (eg if you use Gnu ADA), copy that somewhere safe also.
  358.      Then install the gcc package, again by untarring from root.
  359.  
  360.   12.
  361.      Some programs (notably various X programs) use /lib/cpp, which
  362.      under Linux is generally a link to /usr/lib/gcc-
  363.      lib/i486-linux/version/cpp.  As the preceding step wiped out
  364.      whatever version of cpp it was pointing to, you'll need to recreate
  365.      the link:
  366.  
  367.        $ cd /lib
  368.        $ ln -s /usr/lib/gcc-lib/i486-linux/2.7.0/cpp .
  369.  
  370.   13.
  371.      The FSSTND people have once again justified their keep by moving
  372.      the utmp and wtmp files from /var/adm to /var/run and /var/log
  373.      respectively.  You'll need to add some links dependent on where
  374.      they currently live, and you may need to make the /var/log and
  375.      /var/adm directories too.  I reproduce below the ls -l output of
  376.      appropriate bits on my system:
  377.  
  378.        $ ls -ld /var/adm /var/log /var/run /var/log/*tmp /var/run/*tmp
  379.        lrwxrwxrwx   1 root     root            3 May 24 05:53 /var/adm -> log/
  380.        drwxr-xr-x   9 root     root         1024 Aug 13 23:17 /var/log/
  381.        lrwxrwxrwx   1 root     root           11 Aug 13 23:17 /var/log/utmp -> ../run/utmp
  382.        -rw-r--r--   1 root     root       451472 Aug 13 23:00 /var/log/wtmp
  383.        drwxr-xr-x   2 root     root         1024 Aug 13 23:17 /var/run/
  384.        -rw-r--r--   1 root     root          448 Aug 13 23:00 /var/run/utmp
  385.  
  386.   Check the FSSTND (from LDP archives such as
  387.   <ftp://sunsite.unc.edu/pub/Linux/docs/fsstnd/>) for the full story.
  388.  
  389.   14.
  390.      This step is optional.  If you're intending to continue compiling
  391.      programs in a.out, this is the appropriate time to install libc.so
  392.      4.7.x.  Untar it from root, as you are now no doubt fully capable
  393.      of doing without further explanation.
  394.  
  395.    Done!  Simple tests that you can try are
  396.  
  397.        ______________________________________________________________________
  398.        $ gcc -v
  399.        Reading specs from /usr/lib/gcc-lib/i486-linux/2.7.0/specs
  400.        gcc version 2.7.0
  401.        $ gcc -v -b i486-linuxaout
  402.        Reading specs from /usr/lib/gcc-lib/i486-linuxaout/2.7.0/specs
  403.        gcc version 2.7.0
  404.        $ ld -V
  405.        ld version cygnus/linux-2.5.2l.14 (with BFD cygnus/linux-2.5.2l.11)
  406.          Supported emulations:
  407.           elf_i386
  408.           i386linux
  409.           i386coff
  410.        ______________________________________________________________________
  411.  
  412.   followed of course by the traditional ``Hello, world'' program.  Try
  413.   it with gcc and with gcc -b i486-linuxaout to check that both the
  414.   a.out and ELF compilers are set up corectly.
  415.  
  416.   2.5.  What it should look like (outline directory structure)
  417.  
  418.   This is a deliberately vague guide to what the files you have just
  419.   installed are.  It may be useful for troubleshooting or deciding what
  420.   to delete.
  421.  
  422.   2.5.1.
  423.    /lib
  424.  
  425.   ╖  Dynamic linkers ld.so (a.out) and ld-linux.so.1 (ELF).  Either of
  426.      these may be symlinks, but make sure that the files they point to
  427.      do exist.
  428.  
  429.   ╖  Basic shared libraries libc.so.4, libm.so.4 (a.out) These are
  430.      symlinks, but check that they point to real files.
  431.  
  432.   ╖  Basic shared libraries libc.so.5, libm.so.5,
  433.      libdl.so.1,libcurses.so.1,libtermcap.so.2, (ELF).  Again, these are
  434.      symlinks.
  435.  
  436.   ╖  Lots of symlinks.  For each library, there should be an actual file
  437.      (for example libc.so.5.0.9), a symlink to it with only the major
  438.      version number in its name (libc.so.5) and a symlink pointing to
  439.      that with no version number (libc.so).  That's
  440.  
  441.        ______________________________________________________________________
  442.        lrwxrwxrwx   1 root  root      9 May 24 05:52 libc.so -> libc.so.5
  443.        lrwxrwxrwx   1 root  root     13 Aug 25 12:48 libc.so.5 -> libc.so.5.0.9
  444.        -rwxr-xr-x   1 bin   bin  562683 May 19 04:47 libc.so.5.0.9
  445.        ______________________________________________________________________
  446.  
  447.   2.5.2.  /usr/lib
  448.  
  449.   ╖  All the non-library files and directories that were there
  450.      previously.
  451.  
  452.   ╖  libbfd.so*,libdb.so*, libgdbm.so*, ELF shared libraries.  All to
  453.      consist of three files as explained above in the /lib section.
  454.  
  455.   ╖  libbsd.a, libgmon.a, libldso.a, libmcheck.a, libieee.a, libmcheck.a
  456.      and one lib*.a file for every ELF shared library in /lib and
  457.      /usr/lib .  ELF static libraries.  The ones duplicating the shared
  458.      libraries may not be tremendously useful for most people --- when
  459.      using ELF, you can use the gcc -g switch with shared libraries, so
  460.      there's not much reason to compile static any longer.
  461.  
  462.   ╖  crt0.o, gcrt0.o.  a.out `start of program' files; one of these is
  463.      linked as the first file in every a.out program you compile, unless
  464.      you take steps to avoid it.
  465.  
  466.   ╖  crt1.o, crtbegin.o, crtbeginS.o, crtend.o, crtendS.o, crti.o,
  467.      crtn.o, gcrt1.o.  ELF startup files.  These do similar things to
  468.      *crt0.o above for ELF programs.
  469.  
  470.   2.5.3.
  471.    /usr/lib/ldscripts
  472.  
  473.   ╖  This is where the driver scripts for ld live, as the name suggests.
  474.      It should look like
  475.  
  476.        ______________________________________________________________________
  477.        $ ls /usr/lib/ldscripts/
  478.        elf_i386.x      elf_i386.xs     i386coff.xn     i386linux.xbn
  479.        elf_i386.xbn    elf_i386.xu     i386coff.xr     i386linux.xn
  480.        elf_i386.xn     i386coff.x      i386coff.xu     i386linux.xr
  481.        elf_i386.xr     i386coff.xbn    i386linux.x     i386linux.xu
  482.        ______________________________________________________________________
  483.  
  484.   2.5.4.  /usr/i486-linux/bin
  485.  
  486.   ╖  ar, as, gasp, ld, nm, ranlib, strip.  These are all actually
  487.      symlinks to the real binutils in /usr/bin
  488.  
  489.   2.5.5.  /usr/i486-linuxaout/bin
  490.  
  491.   ╖  as --- the a.out assembler, and gasp, its macro preprocessor
  492.  
  493.   ╖  ar, ld, nm, ranlib, strip --- symlinks to the real binutils in
  494.      /usr/bin
  495.  
  496.   2.5.6.  /usr/i486-linux/lib
  497.  
  498.   ╖  ldscripts is a symlink to /usr/lib/ldscripts.
  499.  
  500.   2.5.7.  /usr/i486-linuxaout/lib
  501.  
  502.   ╖  lib*.so*. a.out shared library images.  Needed to run a.out
  503.      programs
  504.  
  505.   ╖  lib*.sa. a.out shared library stubs.  Needed to compile a.out
  506.      programs that use shared libraries.  If you don't intend to, you
  507.      can safely remove these.
  508.  
  509.   ╖  lib*.a. a.out static libraries.  Needed to compile static a.out
  510.      programs (eg when compiling with -g).  Again, you can delete them
  511.      if you don't intend to.
  512.  
  513.   ╖  ldscripts is a symbolic link to /usr/lib/ldscripts
  514.  
  515.   2.5.8.  /usr/lib/gcc-lib/i486-linux/2.7.0
  516.  
  517.   ╖  This directory contains a version of gcc 2.7.0 set up to compile
  518.      ELF programs.
  519.  
  520.   2.5.9.  /usr/lib/gcc-lib/i486-linuxaout/2.7.0
  521.  
  522.   ╖  This directory contains a version of gcc 2.7.0 set up to compile
  523.      a.out programs, which knows about the new directory structure.  If
  524.      you're not going to compile anything in a.out, deleting this may
  525.      free up around 4Mb.
  526.  
  527.   2.6.  Common errors (Don't Panic!)
  528.  
  529.       You moved the wrong thing and now nothing runs
  530.         You still have a shell running, though, and with a little
  531.         ingenuity you can do an awful lot with shell builtins.  Remember
  532.         that echo * is an acceptable substitute for ls, and echo
  533.         >>filename can be used to add lines to a file.  Also, don't
  534.         forget that ldconfig is linked static.  If you moved, say,
  535.         libc.so.4 to /lib-aout mistakenly, you can do echo "lib-aout"
  536.         >>/etc/ld.so.conf ; ldconfig -v/ and be back up again.  If you
  537.         moved /lib/ld.so you may be able to do sln /silly/place/ld.so
  538.         /lib/ld.so, if you have a statically linked ln, and probably be
  539.         back up again.
  540.  
  541.       no such file or directory: /usr/bin/gcc
  542.         that the ELF dynamic loader /lib/ld-linux.so.1 is not installed,
  543.         or is unreadable for some reason.  You should have installed it
  544.         at around step 2 previously.
  545.  
  546.       not a ZMAGIC file, skipping
  547.         from ldconfig.  You have an old version of the ld.so package, so
  548.         get a recent one.  Again, see step 2 of the installation.
  549.  
  550.       bad address
  551.         on attempting to run anything ELF.  You're using kernel 1.3.x,
  552.         where x<3.  Upgrade to 1.3.3 or downgrade to 1.2.something
  553.  
  554.       _setutent: Can't open utmp file
  555.         This message is often seen in multiples of three when you start
  556.         an xterm.  Go and read the FSSTND tirade near the end of the
  557.         installation procedure.
  558.  
  559.       gcc: installation problem, cannot exec something: No such file or
  560.         directory
  561.         when attempting to do a.out compilations (something is usually
  562.         one of cpp or cc1).  Either it's right, or alternatively you
  563.         typed
  564.  
  565.           $ gcc -b -i486-linuxaout
  566.  
  567.      when you should have typed
  568.  
  569.      $ gcc -b i486-linuxaout
  570.  
  571.      Note that the `i486' does not start with a dash.
  572.  
  573.   3.  Building programs in ELF
  574.  
  575.   3.1.  Ordinary programs
  576.  
  577.   To build a program in ELF, use gcc as always.  To build in a.out, use
  578.   gcc -b i486-linuxaout .
  579.  
  580.        ______________________________________________________________________
  581.        $ cat >hello.c
  582.        main() { printf("hello, world\n"); }
  583.        ^D
  584.        $ gcc -o hello hello.c
  585.        $ file hello
  586.        hello: ELF 32-bit LSB executable i386 (386 and up) Version 1
  587.        $ ./hello
  588.        hello, world
  589.        ______________________________________________________________________
  590.  
  591.   This is perhaps an appropriate time to answer the question ``if a.out
  592.   compilers default to producing a program called a.out, what name does
  593.   an ELF compiler give its output?''.  Still a.out, is the answer.
  594.   Boring boring boring ...  :-)
  595.  
  596.   3.2.  Building libraries
  597.  
  598.   To build libfoo.so as a shared library, the basic steps look like
  599.   this:
  600.  
  601.        ______________________________________________________________________
  602.        $ gcc -fPIC -c *.c
  603.        $ gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 *.o
  604.        $ ln -s libfoo.so.1.0 libfoo.so.1
  605.        $ ln -s libfoo.so.1 libfoo.so
  606.        $ export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
  607.        ______________________________________________________________________
  608.  
  609.   This will generate a shared library called libfoo.so.1.0, and the
  610.   appropriate links for ld (libfoo.so) and the dynamic linker
  611.   (libfoo.so.1) to find it.  To test, we add the current directory to
  612.   LD_LIBRARY_PATH.
  613.  
  614.   When you're happpy that the library works, you'll have to move it to,
  615.   say, /usr/local/lib, and recreate the appropriate links.  Note that
  616.   the libfoo.so link should point to libfoo.so.1, so it doesn't need
  617.   updating on every minor version number change.  The link from
  618.   libfoo.so.1 to libfoo.so.1.0 is kept up to date by ldconfig, which on
  619.   most systems is run as part of the boot process.
  620.  
  621.        ______________________________________________________________________
  622.        $ su
  623.        # cp libfoo.so.1.0 /usr/local/lib
  624.        # /sbin/ldconfig
  625.        # ( cd /usr/local/lib ; ln -s libfoo.so.1 libfoo.so )
  626.        ______________________________________________________________________
  627.  
  628.   3.3.  Programs with dynamic loading
  629.  
  630.   These are covered extensively in H J Lu's ELF programming document,
  631.   and the dlopen(3) manual page, which can be found in the ld.so
  632.   package.  Here's a nice simple example though: link it with -ldl
  633.  
  634.        ______________________________________________________________________
  635.        #include <dlfcn.h>
  636.        #include <stdio.h>
  637.  
  638.        main()
  639.        {
  640.          void *libc;
  641.          void (*printf_call)();
  642.  
  643.          if(libc=dlopen("/lib/libc.so.5",RTLD_LAZY))
  644.          {
  645.            printf_call=dlsym(libc,"printf");
  646.            (*printf_call)("hello, world\n");
  647.          }
  648.  
  649.        }
  650.        ______________________________________________________________________
  651.  
  652.   3.4.  Debugging
  653.  
  654.   Your existing copy of gdb will most likely work unchanged with ELF
  655.   programs.  The new version in the GCC directory on tsx-11 is reported
  656.   to be better at debugging programs that use shared libraries and
  657.   dynamic loading, and to understand ELF core dumps.
  658.  
  659.   Note that 1.2 series kernels cannot generate core dumps from ELF
  660.   programs anyway.  1.3 can.
  661.  
  662.   4.  Patches and binaries
  663.  
  664.   At this point in the proceedings, you can, if you like, stop.  You
  665.   have installed everything necessary to compile and run ELF programs.
  666.  
  667.   You may wish to rebuild some programs in ELF, either for purposes of
  668.   `neatness' or to minimise memory usage.  For most end-user
  669.   applications, this is pretty simple; some packages however do assume
  670.   too much about the systems they run on, and may fail due to one or
  671.   more of:
  672.   ╖  Different underscore conventions in the assembler: in an a.out
  673.      executable, external labels get _ prefixed to them; in an ELF
  674.      executable, they don't.  This makes no difference until you start
  675.      integrating hand-written assembler: all the labels of the form _foo
  676.      must be translated to foo, or (if you want to be portable about it)
  677.      to EXTERNAL(foo) where EXTERNAL is some macro which returns either
  678.      its argument (if __ELF__ is defined) or _ concatenated with its
  679.      argument if not.
  680.  
  681.   ╖  Differences in libc 5 from libc 4.  The interface to the locale
  682.      support has changed, for one.
  683.  
  684.   ╖  The application or build process depending on knowledge of the
  685.      binary format used --- emacs, for example, dumps its memory image
  686.      to disk in executable format, so obviously needs to know what
  687.      format your executables are in.
  688.  
  689.   ╖  The application consists of or includes shared libraries (X11 is
  690.      the obvious example).  These will obviously need changes to
  691.      accomodate the different method of shared library creation in ELF.
  692.  
  693.   Anyway, here are two lists: the first is of programs that needed
  694.   changing for ELF where the changes have been made (ie that you will
  695.   need new versions of to compile as ELF), and the second is of programs
  696.   that still need third-party patches of some kind.
  697.  
  698.   4.1.  Upgrade:
  699.  
  700.   ╖  Dosemu.  Modulo the three or four cuurrent dosemu development trees
  701.      (don't ask, just join the linux-msdos mailing list), dosemu runs
  702.      with ELF.  You'll need to monkey with the Makefile.  Current
  703.      versions of dosemu are available from
  704.      <ftp://tsx-11.mit.edu/pub/linux/ALPHA/dosemu/>
  705.  
  706.   ╖  Emacs.  Emacs has a rather odd build procedure that involves
  707.      running a minimal version of itself, loading in all the useful bits
  708.      as lisp, then dumping its memory image back to disk as an
  709.      executable file.  (FSF) Emacs 19.29 and XEmacs 19.12 (formerly
  710.      Lucid Emacs) can both detect whether you are compiling as ELF and
  711.      Do The Right Thing automatically.
  712.  
  713.   ╖  MAKEDEV.  In some incarnations, this utility removes existing
  714.      entries for devices before recreating them.  This is Bad News if it
  715.      happens to touch /dev/zero, as said device is necessary to the
  716.      operation of all ELF programs.  See the util-linux package(q.v.)
  717.      for a fixed version.
  718.  
  719.   ╖  perl 5.001.  Perl 5.001 plus the ``official unofficial'' patches a-
  720.      e will compile unchanged on an ELF system, complete with dynamic
  721.      loading.  The patches are available from ftp.metronet.com or
  722.      ftp.wpi.edu
  723.  
  724.   ╖  The cal program in util-linux 2.2 doesn't work.  Upgrade to version
  725.      2.4 <ftp://tsx-11.mit.edu/pub/linux/packages/utils> or later.
  726.  
  727.   ╖  XFree86.  XFree86 3.1.2 comes in both a.out and ELF formats.  ftp
  728.      to ftp.xfree86.org, read the `too many users' message that you are
  729.      almost guaranteed to get, and pick the closest mirror site network-
  730.      wise to you.  Once you have the contents of the common and elf
  731.      directories, you must edit /usr/X11R6/lib/X11/config/linux.cf to
  732.      change the lines saying
  733.  
  734.   #define LinuxElfDefault         NO
  735.   #define UseElfFormat            NO
  736.  
  737.   to say YES instead.  Otherwise an xpm build will attempt to do odd
  738.   stuff with jumpas and its associated relics of the past.
  739.  
  740.   ╖  Mosaic.  I don't have the facilities to build this myself, but the
  741.      Mosaic 2.7b1 binary available from NCSA comes in ELF.  It has been
  742.      linked against an odd X setup though, with the result that on
  743.      normal systems it will complain about not finding libXpm.so.4.5.
  744.      The simple fix is to edit it carefully with emacs or another editor
  745.      that copes with binary files.  Find the occurence of the string
  746.      libXpm.so.4.5^@ (where ^@ is a NUL --- ASCII zero --- character),
  747.      delete the .5 and add two more characters after the NUL to aviod
  748.      changing the file length.
  749.  
  750.   4.2.  Patch
  751.  
  752.   ╖  e2fsutils.  The Utilities for the Second Extended File System need
  753.      a patch from
  754.      <ftp://ftp.ibp.fr/pub/linux/ELF/patches/e2fsprogs-0.5b.elf.diff.gz>
  755.      to compile correctly as a shared library.  Remy Card says ``This is
  756.      the ELF patch which will probably be included in the next release
  757.      of e2fsck and co''
  758.  
  759.   ╖  file.  This works anyway, but can be improved:
  760.      <http://sable.ox.ac.uk/~jo95004/patches/file.diff> adds support for
  761.      identifying stripped and mixed-endian ELF binaries.
  762.  
  763.   ╖  The Kernel.  As from at least 1.3.8, the development 1.3 series
  764.      have a make config option to build using ELF tools.  If you are
  765.      using the 1.2 series, you have two options:
  766.  
  767.      1. Patch the Makefile slightly to use the a.out compiler.  Just
  768.         change the CC and LD definitions to be
  769.  
  770.           ___________________________________________________________________
  771.           LD      =ld -m i386linux
  772.           CC      =gcc -b i486-linuxaout -D__KERNEL__ -I$(TOPDIR)/include
  773.           ___________________________________________________________________
  774.  
  775.      Alternatively,
  776.  
  777.      2. Apply H J Lu's patch which allows compiling the kernel in ELF
  778.         (and also adds the ability to do ELF core dumps).
  779.  
  780.      Let me reiterate that neither of these is necessary for the 1.3
  781.      series.
  782.  
  783.   ╖  ps (procps-0.97) The psupdate program needs a patch to work if you
  784.      have compiled the kernel as ELF.  It's available in
  785.      <linux.nrao.edu:/pub/people/juphoff/procps>, both as a patch to
  786.      vanilla 0.97 and as an entire tar-file.  A new version of procps is
  787.      expected to be released soon with this patch in place, so if you
  788.      can find procps 0.98 by the time you read this, this patch will
  789.      probably be obsolete.
  790.  
  791.   5.  Further information
  792.  
  793.   ╖  The linux-gcc mailing list is really the best place to see what's
  794.      happening, usually without even posting to it.  Remember, it's not
  795.      Usenet, so keep the questions down unless you're actually
  796.      developing.  For instructions on joining the mailing list, mail a
  797.      message containing the word help to majordomo@vger.rutgers.edu.
  798.      Archives of the list are at  <http://homer.ncm.com/>.
  799.  
  800.   ╖  There's a certain amount of information about what the linux-gcc
  801.      list is doing at my ELF web page
  802.      <http://sable.ox.ac.uk/~jo95004/elf.html>, when I remember to
  803.      update it.  This also has a link to the latest version of this
  804.      HOWTO, and the patches it refers to.  For US people and others with
  805.      poor links to UK academic sites (that's nearly everyone outside of
  806.      UK academia), this is all mirrored at
  807.      <http://www.blackdown.org/elf/elf.html>
  808.  
  809.   ╖  See also Bobby Shmit's ELF upgrade experience
  810.      <http://www.intac.com/~cully/elf.html> web page.
  811.  
  812.   ╖  The GCC-FAQ <ftp://sunsite.unc.edu/pub/Linux/docs/faqs/GCC-
  813.      FAQ.html> contains much general development information and some
  814.      more technical ELF details.
  815.  
  816.   ╖  There's also documentation for the file format on tsx-11
  817.      <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/ELF.doc.tar.gz>.  This
  818.      is probably of most use to people who want to understand, debug or
  819.      rewrite programs that deal directly with binary objects.
  820.  
  821.   ╖  H J Lu's document ELF: From The Programmer's Perspective
  822.      <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/elf.latex.tar.gz>
  823.      contains much useful and more detailed information on programming
  824.      with ELF.  If you aren't LaTeX-capable, it is also available as
  825.      PostScript.
  826.  
  827.   ╖  There is a manual page for dlopen(3) supplied with the ld.so
  828.      package.
  829.  
  830.   6.  Legalese
  831.  
  832.   All trademarks used in this document are acknowledged as being owned
  833.   by their respective owners.  (Spot the teeth-gritting irony there...)
  834.  
  835.   The right of Daniel Barlow to be identified as the author of this work
  836.   has been asserted in accordance with sections 77 and 78 of the
  837.   Copyright Designs and Patents Act 1988.  (Proof by assertion
  838.  
  839.   This document is copyright (C) 1995 Daniel Barlow
  840.   <daniel.barlow@sjc.ox.ac.uk> It may be reproduced and distributed in
  841.   whole or in part, in any medium physical or electronic, as long as
  842.   this copyright notice is retained on all copies. Commercial
  843.   redistribution is allowed and encouraged; however, the author would
  844.   like to be notified of any such distributions.
  845.  
  846.   All translations, derivative works, or aggregate works incorporating
  847.   any Linux HOWTO documents must be covered under this copyright notice.
  848.   That is, you may not produce a derivative work from a HOWTO and impose
  849.   additional restrictions on its distribution. Exceptions to these rules
  850.   may be granted under certain conditions; please contact the Linux
  851.   HOWTO coordinator at the address given below.
  852.  
  853.   In short, we wish to promote dissemination of this information through
  854.   as many channels as possible. However, we do wish to retain copyright
  855.   on the HOWTO documents, and would like to be notified of any plans to
  856.   redistribute the HOWTOs.
  857.  
  858.   If you have questions, please contact Greg Hankins, the Linux HOWTO
  859.   coordinator, at gregh@sunsite.unc.edu via email, or at +1 404 853
  860.   9989.
  861.  
  862.