home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / HOWTOs / ELF-HOWT < prev    next >
Text File  |  1999-11-04  |  54KB  |  1,453 lines

  1.   The Linux ELF HOWTO
  2.   Daniel Barlow <daniel.barlow@linux.org>
  3.   v1.29, 14 July 1996
  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 you should upgrade, (2) How to
  8.   upgrade to ELF-capability, and (3) what you can do then.  After a
  9.   fairly long fallow period in which I have been pretending to do aca-
  10.   demic work, it has recently been overhauled to give current informa-
  11.   tion for Linux 2.0.
  12.  
  13.   1.  What is ELF?  An introduction
  14.  
  15.  
  16.  
  17.   ELF (Executable and Linking Format) is a binary format originally
  18.   developed by USL (UNIX System Laboratories) and currently used in
  19.   Solaris and System V Release 4.  Because of its increased flexibility
  20.   over the older a.out format that Linux previously used, the GCC and C
  21.   library developers decided last year to move to using ELF as the Linux
  22.   standard binary format also.
  23.  
  24.   This `increased flexibility' manifests as essentially two benefits to
  25.   the average applications progammer:
  26.  
  27.  
  28.   o  It is much simpler to make shared libraries with ELF.  Typically,
  29.      just compile all the object files with -fPIC, then link with a
  30.      command like
  31.  
  32.  
  33.  
  34.         gcc -shared -Wl,-soname,libfoo.so.y -o libfoo.so.y.x *.o
  35.  
  36.  
  37.  
  38.  
  39.  
  40.   If that looks complex, you obviously haven't ever read up on the
  41.   equivalent procedure for a.out shared libraries, which involves com-
  42.   piling the library twice, reserving space for all the data you think
  43.   that the library is likely to require in future, and registering that
  44.   address space with a third party (it's described in a document over 20
  45.   pages long --- look at <ftp://tsx-11.mit.edu/pub/linux/pack-
  46.   ages/GCC/src/tools-2.17.tar.gz> for details).
  47.  
  48.   o  It makes dynamic loading (ie programs which can load modules at
  49.      runtime) much simpler.  This is used by Perl 5, Python, and Java,
  50.      among other things (it's a kicker for many kinds of interpreters).
  51.      Other suggestions for dynamic loading have included super-fast
  52.      MUDs, where extra code could be compiled and linked into the
  53.      running executable without having to stop and restart the program.
  54.  
  55.  
  56.   Against this it must be weighed that ELF is possibly a bit slower.
  57.   The figures that get bandied around are between 1% and 5%, though all
  58.   the actual tests that have been conducted so far indicate that the
  59.   difference is small enough to get lost in the noise of other events
  60.   happening at the same time.  If you have TeX or a Postscript
  61.   viewer/printer, you can read speed.comp-1.0.tar.gz, which is available
  62.   from SunSite somewhere.
  63.  
  64.   The slowdown comes from the fact that ELF library code must be
  65.   position independent (this is what the -fPIC above stands for) and so
  66.   a register must be devoted to holding offsets.  That's one less for
  67.   holding variables in, and the 80x86 has a paucity of general-purpose
  68.   registers anyway.  Note that the speed difference only applies to code
  69.   that is part of shared libraries.  For applications or kernels there
  70.   is no speed difference between a.out and ELF.
  71.  
  72.  
  73.   1.1.  What ELF isn't
  74.  
  75.   There are a number of common misconceptions about what ELF will do for
  76.   your system:
  77.  
  78.  
  79.      It's not a way to run SVR4 or Solaris programs
  80.         Although it's the same binary `container' as SVR4 systems use,
  81.         that doesn't mean that SVR4 programs suddenly become runnable on
  82.         Linux.  It's analogous to a disk format --- you can keep Linux
  83.         programs on MSDOS or Minix-format disks, and vice versa, but
  84.         that doesn't mean that these systems become able to run each
  85.         others' programs.
  86.  
  87.         It may be possible to run an application for another x86 Unix
  88.         under Linux (it depends on the application), but following the
  89.         instructions in this HOWTO will not have that effect.  Start by
  90.         looking at the iBCS kernel module (somewhere on tsx-11.mit.edu)
  91.         and see if it fits your needs.
  92.  
  93.  
  94.      It's not intrinsically smaller or faster
  95.         You may well end up with smaller binaries anyway, though, as you
  96.         can more easily create shared libraries of common code between
  97.         many programs.  In general, if you use the same compiler options
  98.         and your binaries come out smaller than they did with a.out,
  99.         it's more likely to be fluke or a different compiler version.
  100.         As for `faster', I'd be surprised.  Speed increases could turn
  101.         up if your binaries are smaller, due to less swapping or larger
  102.         functional areas fitting in cache.
  103.  
  104.  
  105.      It doesn't require that you replace every binary on your system
  106.         At the end of this procedure you have a system capable of
  107.         compiling and running both ELF and a.out programs.  New programs
  108.         will by default be compiled in ELF, though this can be
  109.         overridden with a command-line switch.  There is admittedly a
  110.         memory penalty for running a mixed ELF/a.out system --- if you
  111.         have both breeds of program running at once you also have two
  112.         copies of the C library in core, and so on.  I've had reports
  113.         that the speed difference from this is undetectable in normal
  114.         use on a 6Mb system though (I certainly haven't noticed much in
  115.         8Mb), so it's hardly pressing.  You lose far more memory every
  116.         day by running bloated programs like Emacs and static
  117.         Mosaic/Netscape binaries :-)
  118.  
  119.  
  120.      It's nothing to do with Tolkien.
  121.         Or at least, not in this context.
  122.  
  123.  
  124.  
  125.   1.2.  Why you should convert to ELF
  126.  
  127.   There are essentially two reasons to upgrade your system to compile
  128.   and run ELF programs: the first is the increased flexibility in
  129.   programming referred to above, and the second is that, due to the
  130.   first, everyone else will (or has already).  Current releases of the C
  131.   library and GCC are compiled only for ELF, and other developers are
  132.   moving ELFwards too.
  133.   Many people are concerned about stability (justifiably so, even if
  134.   it's not so much fun).  ELF on Linux has existed since August 1994 and
  135.   has been publically available since May or June 1995; the teething
  136.   troubles are probably out of the way by now.  You should allow for the
  137.   possibility of breaking things --- as you would with any major upgrade
  138.   --- but the technology that you're upgrading to is no longer bleeding
  139.   edge.  For a system on which any development is done, or on which you
  140.   want to run other people's precompiled binaries, ELF is pretty much a
  141.   necessity these days.  Plan to switch to it when you upgrade to
  142.   version 2.0 of the kernel.
  143.  
  144.  
  145.   1.3.  How to convert to ELF
  146.  
  147.   When this HOWTO was first written, there was only one way, and it was
  148.   the way described here.  These days there are high-quality upgradable
  149.   distributions available --- unless you have invested significant time
  150.   in setting up your machine exactly how you like it, you might find
  151.   that a backup of all your own data and a reinstall from a recent Red
  152.   Hat or Debian release is more convenient than messing about with the
  153.   assorted libraries and compilers described here.
  154.  
  155.   I must stress this.  The installation described here is a fairly small
  156.   job in itself (it can be completed in well under an hour, excepting
  157.   the time taken to download the new software), but there are a
  158.   multitude of errors that you can make which will probably leave you
  159.   with an unbootable system.  If you are not comfortable with upgrading
  160.   shared libraries, if the commands ldconfig and  ldd mean nothing to
  161.   you, or if you're unhappy about building packages from source code,
  162.   you should consider the `easy option'.  Even if this description isn't
  163.   you, think about it anyway --- if you want a `fully ELF' system,
  164.   somebody is going to have to recompile all the binaries on it.
  165.  
  166.   Still with us?
  167.  
  168.  
  169.   2.  Installation
  170.  
  171.   2.1.  Background
  172.  
  173.   The aim of this conversion is to leave you with a system which can
  174.   build and run both a.out and ELF programs, with each type of program
  175.   being able to find its appropriate breed of shared libraries.  This
  176.   obviously requires a bit more intelligence in the library search
  177.   routines than the simple `look in /lib, /usr/lib and anywhere else
  178.   that the program was compiled to search' strategy that some other
  179.   systems can get away with.
  180.  
  181.   This intelligence is centralised in a dynamic loader, which exists in
  182.   only one --- or two --- places on the system.  For a.out programs,
  183.   it's called /lib/ld.so, and for ELF programs it's /lib/ld-linux.so.1.
  184.   The compiler and linker do not encode absolute library pathnames into
  185.   the programs they output; instead they put the library name and the
  186.   absolute path to the appropriate dynamic loader in, and leave that to
  187.   match the library name to the appropriate place at runtime.  This has
  188.   one very important effect --- it means that the libraries that a
  189.   program uses can be moved to other directories  without recompiling
  190.   the program, provided that ld.so (ld-linux.so.1; whatever) is told to
  191.   search the new directory.  This is essential functionality for the
  192.   directory swapping operation that follows.
  193.  
  194.   The corollary of the above, of course, is that any attempt to delete
  195.   or move ld.so or ld-linux.so.1 may cause every dynamically linked
  196.   program on the system to stop working.  This is generally regarded as
  197.   a Bad Thing.
  198.  
  199.   The basic plan, then, is that ELF development things (compilers,
  200.   include files and libraries) go into /usr/{bin,lib,include} where your
  201.   a.out ones currently are, and the a.out things will be moved into
  202.   /usr/i486-linuxaout/{bin, lib, include}.  /etc/ld.so.conf lists all
  203.   the places on the system where libraries are expected to be found, and
  204.   ldconfig is intelligent enough to distinguish between ELF and a.out
  205.   variants.
  206.  
  207.   There are a couple of exceptions to the library placement:
  208.  
  209.   o  Some old programs were built without the use of ld.so.  These would
  210.      all cease working if their libraries were moved from under them.
  211.      Thus, libc.so* and libm.so* must stay where they are in /lib, and
  212.      the ELF versions have had their major numbers upgraded so that they
  213.      do not overwrite the a.out ones.  Old X libraries (prior to version
  214.      6) are best left where they are also, although newer ones
  215.      (libX*so.6) must be moved.  Moving the old ones will apparently
  216.      break xview programs, and not moving the new ones will cause them
  217.      to be overwritten when you install ELF X libraries.
  218.  
  219.      If you have non-ld.so programs that require libraries other than
  220.      the above (if you know which programs they are, you can run ldd on
  221.      them to find out which libraries they need before breaking them)
  222.      you have essentially two options.  One, you can extract the ELF
  223.      library tar files into a temporary directory, check whether your
  224.      precious library would be overwritten, and if so, move the ELF
  225.      version of the library into, say, /usr/i486-linux/lib instead of
  226.      /lib.  Make sure your ld.so.conf has /usr/i486-linux/lib in it,
  227.      then run ldconfig and think no more on't.  Two, you can recompile
  228.      or acquire a newer copy of the offending program.  This might not
  229.      be a bad idea, if possible.
  230.  
  231.   o  If you have /usr and / on different partitions, any libraries that
  232.      you move from /lib must end up somewhere else on the root disk, not
  233.      on /usr.  I used /lib-aout in the instructions that follow.
  234.  
  235.  
  236.   2.2.  Before you start --- Notes and Caveats
  237.  
  238.  
  239.   o  You will need to be running a post-1.1.52 kernel with ELF binary
  240.      format support.  1.2.13 works.  2.0.0 (the most recent at the time
  241.      of writing) also works, as do most of the 1.3 series, though the
  242.      point of running old `experimental' kernels is anyway questionable
  243.      now that 2.0 is here.
  244.  
  245.   o  You are recommended to prepare or acquire a linux boot/root disk,
  246.      such as a Slackware rescue disk.  You probably won't need it, but
  247.      if you do and you don't have one, you'll kick yourself.  In a
  248.      similar `prevention is better than cure' vein, statically linked
  249.      copies of mv, ln, and maybe other file manipulation commands
  250.      (though in fact I think you can do everything else you actually
  251.      need to with shell builtins) may help you out of any awkward
  252.      situations you could end up in.
  253.  
  254.   o  If you were following the early ELF development, or you installed
  255.      certain versions of Slackware (none of the current ones,
  256.      admittedly) you may have ELF libraries in /lib/elf (usually
  257.      libc.so.4 and co).  Applications that you built using these should
  258.      be rebuilt, then the directory removed.  There is no need for a
  259.      /lib/elf directory!
  260.  
  261.   o  Most Linux installations these days have converged on the `FSSTND'
  262.      standard file system, but doubtless there are still installed
  263.      systems that haven't.  If you see references to /sbin/something and
  264.      you don't have a /sbin directory, you'll probably find the program
  265.      referred to in /bin or /etc/.  It is especially important to check
  266.      this when you install new programs; if you have /etc nearer the
  267.      front of the search path than /sbin you'll get odd failures due to
  268.      running the old versions when you weren't expecting to.
  269.  
  270.   o  It's a good idea to pick a time when nobody else is using the
  271.      computer, or to take it single-user.  It might be a good idea to
  272.      reboot it off a floppy so that a mistake doesn't leave you stuck,
  273.      but personally I like to leave a small element of fun ...
  274.  
  275.  
  276.   2.3.  Ingredients
  277.  
  278.   Anything in the following list that I describe as being ``on tsx-11''
  279.   can be found in  <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/>,
  280.   <ftp://sunsite.unc.edu/pub/Linux/GCC/>, and at many mirrors.  Please
  281.   take the time to look up your nearest mirror site and use that instead
  282.   of the master sites where possible.  It's faster for both you and
  283.   everyone else.
  284.  
  285.   These packages (either the listed version or a later one) are
  286.   required.  Also download and read through the release notes for each
  287.   of them: these are the files named release.packagename.  This applies
  288.   especially if you get newer versions than are listed here, as
  289.   procedures may have changed.
  290.  
  291.   Even if you habitually compile things from source, I'd advise you to
  292.   go for the binary versions where I've indicated, unless you really
  293.   have no use for your hair.  Most of them are not set up for
  294.   `crosscompiling' on an a.out-based system, and you are probably lining
  295.   yourself up for major grief if you try.
  296.  
  297.  
  298.   2.3.1.  Absolute essentials
  299.  
  300.  
  301.   o  ld.so-1.7.14.tar.gz --- the new dynamic linker.  Contains both
  302.      source and binaries.  Note that forthcoming versions of this will
  303.      require kernel ELF support even for a.out binaries; if you get
  304.      1.8.1 or later instead of the version listed, make sure that the
  305.      kernel you're running was compiled with ELF support before you
  306.      install this.
  307.  
  308.   o  libc-5.3.12.bin.tar.gz --- the ELF shared images for the C and
  309.      maths libraries, plus the corresponding static libraries and the
  310.      include files needed to compile programs with them.  Source is also
  311.      available if you like it, but it takes ages to compile, and
  312.      probably won't at all unless you already have an ELF system.
  313.  
  314.   o  gcc-2.7.2.bin.tar.gz --- the ELF C compiler package, which also
  315.      includes an a.out C compiler which understands the new directory
  316.      layout.  If you want to build gcc yourself (which you'll probably
  317.      find is simpler when you're already running ELF), you're
  318.      recommended to apply gcc-2.7.2-linux.diff.gz to the GNU sources
  319.      first.
  320.  
  321.   o  binutils-2.6.0.12.bin.tar.gz --- the GNU binary utilities patched
  322.      for Linux.  These are programs such as gas, ld, strings and so on,
  323.      most of which are required to make the C compiler go.  Note that
  324.      the vanilla GNU binutils (e.g. from prep.ai.mit.edu) are not an
  325.      acceptable substitute; if you really want to compile this yourself
  326.      you'll need to use the patched-for-Linux binutils-2.6.0.12.tar.gz
  327.      package instead of the GNU one.
  328.  
  329.   o  ncurses-1.9.9e.tar.gz --- this is an SVR4-compatible curses
  330.      library, which is henceforward deemed to be the `standard curses
  331.      library' for Linux.  The source is available from GNU sites such as
  332.      <ftp://prep.ai.mit.edu/gnu/> and also from
  333.      <ftp://ftp.netcom.com/pub/zm/zmbenhal>, and there is a binary
  334.      package on tsx-11.  By the time you get to install this you will
  335.      have a fully functional ELF development system, so I recommend the
  336.      source package if you have any kind of compilation horsepower.
  337.      That may just be me, though.
  338.  
  339.   o  gdbm-1.7.3.tar.gz is a set of database routines that use extensible
  340.      hashing and work similarly to the standard UNIX dbm and ndbm
  341.      routines.  The source is available from GNU sites such as
  342.      <ftp://prep.ai.mit.edu/gnu/>; you also need a patch
  343.      <ftp://ftp.uk.linux.org/pub/Linux/libc/non-core/gdbm.patch> to make
  344.      shared libraries out of it.  That patch also fixes a couple of
  345.      other things (a one-character typo in the Makefile and a
  346.      predisposition to use the wrong kind of file locking).
  347.  
  348.  
  349.   2.3.2.  Others
  350.  
  351.   These are other libraries and files which aren't strictly essential,
  352.   but that you might want to get anyway.  This list contains only
  353.   packages that need to be upgraded to work in an ELF-useful fashion.
  354.   Later in this document is another list of programs which will continue
  355.   to work but which you'll have to tweak/upgrade if you want to
  356.   recompile them in ELF.  If your net access involves high-latency links
  357.   (like, say, a five-minute walk with a box of floppy disks), skip
  358.   forwards and check that one too before you set out :-)
  359.  
  360.  
  361.   o  The a.out compatibility library package, libc.so-4.7.6.  This is
  362.      listed as `optional' because your existing a.out libraries of
  363.      whatever vintage will continue to work fine with your existing
  364.      binaries.  You might find that you need this if you plan to
  365.      continue developing in a.out for whatever reason.
  366.  
  367.   o  BSD curses.  If you find binaries which require libcurses.so.1,
  368.      this is the old BSD curses library.  They're probably quite rare,
  369.      which is fortunate as I can't presently find a (source code) copy
  370.      of the library.  It's probably best to recompile programs like this
  371.      to use ncurses; if this is not an option, there is a binary
  372.      libcurses.so in the libc-5.0.9.bin.tar.gz on tsx-11 mirrors.
  373.  
  374.   o  Berkeley db: the new 4.4BSD libdb database routines.  The source
  375.      can be had from
  376.      <ftp://ftp.cs.berkeley.edu/ucb/4bsd/db.1.85.tar.gz/>, and the patch
  377.      for Linux shared libraries is
  378.      <ftp://ftp.uk.linux.org/pub/Linux/libc/non-core/db.patch>
  379.  
  380.   o  C++ stuff. The gcc package comes with g++, but you'll also need
  381.      libg++-2.7.1.4.bin.tar.gz to compile any useful C++ software.  I
  382.      don't use C++ myself, but I understand that it is nontrivial to
  383.      build this from source, hence the binary recommendation.
  384.  
  385.   o  GNU-compatible termcap.  The conversion to ncurses din't happen
  386.      simultaneously with the move to ELF --- you might find that you
  387.      want to run other people's programs that were built using this
  388.      library, and for some applications you might wish to continue using
  389.      it.  gdb is a legitimate example.  If you intend to debug shared
  390.      libraries and you think that gdb is getting confused about the ones
  391.      that it's linked with itself, you probably want a statically linked
  392.      copy of it; in this case, you'll find that a real termcap is a lot
  393.      smaller than the termcap-compatible routines in ncurses.
  394.  
  395.      termcap-2.0.8.tar.gz is available from tsx-11.  This is not GNU
  396.      Termcap, but it is completely compatible (the differences are in
  397.      the error checking, apparently).  This is a source code package.
  398.  
  399.   o  MAKEDEV.  In some incarnations, this utility removes existing
  400.      entries for devices before recreating them.  This is Bad News if it
  401.      removes /dev/zero, which causes some versions of ld-linux.so.1 to
  402.      break.  Find a new version at
  403.      <ftp://sunsite.unc.edu/pub/Linux/system/Admin/MAKEDEV-C-1.5.tar.gz>
  404.      or
  405.      <ftp://sunsite.unc.edu/pub/Linux/system/Admin/MAKEDEV-2.2.tar.gz>.
  406.  
  407.   o  modules-2.0.0.  If you use modules, the upgrade to binutils which
  408.      you're shortly about to perform will break all versions of the
  409.      modules utilities older than 1.3.69.  New modules utilities can be
  410.      had from  <http://www.pi.se/blox/>.
  411.  
  412.   o  The X window system includes a lot of shared libraries.  As your
  413.      new programs will be ELF, and ELF programs cannot use a.out
  414.      libraries, you'll need a new X installation if you want to do any X
  415.      development.  XFree86 3.1.2 comes in both a.out and ELF formats.
  416.      ftp to ftp.xfree86.org, read the `too many users' message that you
  417.      are almost guaranteed to get, and pick the closest mirror site
  418.      network-wise to you.  Once you have the contents of the common and
  419.      elf directories, you must edit /usr/X11R6/lib/X11/config/linux.cf
  420.      to change the lines saying
  421.  
  422.  
  423.  
  424.        #define LinuxElfDefault         NO
  425.        #define UseElfFormat            NO
  426.  
  427.  
  428.  
  429.  
  430.  
  431.   to say YES instead.  Otherwise an xpm build will attempt to do odd
  432.   stuff with jumpas and its associated relics of the past.  Note that
  433.   XFree86 binaries currently require an ELF shared termcap library
  434.   (libtermcap.so.2) to be installed.
  435.  
  436.   If you use Motif, you may also need to contact your vendor, to inves-
  437.   tigate whether they will supply ELF Motif libraries.  I don't use it;
  438.   I can't help here.
  439.  
  440.   o  If you're upgrading to Linux 2.0 at the same time as going ELF,
  441.      don't forget also to check the Documentation/Changes file that
  442.      comes in the kernel source, to find out what else you'll need.
  443.  
  444.  
  445.   2.4.  Rearranging your filesystem
  446.  
  447.   Sooo...  Note that in all that follows, when I say `remove' I
  448.   naturally mean `backup then remove' :-).  Take a deep breath ...
  449.  
  450.  
  451.   1.
  452.  
  453.       The essentials --- binary installation
  454.  
  455.  
  456.   2. Make the new directories that you will move a.out things to
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.   mkdir -p /usr/i486-linuxaout/bin
  464.   mkdir -p /usr/i486-linuxaout/include
  465.   mkdir -p /usr/i486-linuxaout/lib
  466.   mkdir /lib-aout
  467.  
  468.  
  469.  
  470.  
  471.  
  472.   3. Untar the dynamic linker package ld.so-1.7.14 in the directory you
  473.      usually put source code, then read through the
  474.      ld.so-1.7.14/instldso.sh script just unpacked.  If you have a
  475.      really standard system, run it by doing sh instldso.sh, but if you
  476.      have anything at all unusual then do the install by hand instead.
  477.      `Anything at all unusual' includes
  478.  
  479.   o  using zsh as a shell (some versions of zsh define $VERSION, which
  480.      seems to confuse instldso.sh)
  481.  
  482.   o  having symlinks from /lib/elf to /lib (which you shouldn't need,
  483.      but that's scant consolation when you're looking for the rescue
  484.      disk)
  485.  
  486.  
  487.   4. Edit /etc/ld.so.conf to add the new directory
  488.      /usr/i486-linuxaout/lib (and /lib-aout if you're going to need
  489.      one).  Then rerun /sbin/ldconfig -v to check that it is picking up
  490.      the new directories.
  491.  
  492.   5. Move all the a.out libraries in /usr/lib and /usr/*/lib to
  493.      /usr/i486-linuxaout/lib.  Note, I said `libraries' not
  494.      `everything'.  That's files matching the specification lib*.so* ,
  495.      lib*.sa*, or lib*.a.  Don't start moving /usr/lib/gcc-lib or
  496.      anything silly like that around.
  497.  
  498.   6. Now look at /lib.  Leave intact libc.so*, libm.so*, and libdl.so*.
  499.      If you have symlinks to X libraries (libX*.so.3*) leave them there
  500.      too --- XView and some other packages may require them.  Leave
  501.      ld.so*, ld-linux.so* and any other files starting with ld.  As for
  502.      the remaining libraries (if there are any others): if you have /usr
  503.      on the root partition, put them in /usr/i486-linuxaout/lib.  If you
  504.      have /usr mounted separately, put them in /lib-aout.  Now run
  505.      ldconfig -v
  506.  
  507.   7. Remove the directory /usr/lib/ldscripts if it's there, in
  508.      preparation for installing the binutils (which will recreate it)
  509.  
  510.   8. Remove any copies of ld and as (except for ld86 and as86) that you
  511.      can find in /usr/bin.
  512.  
  513.   9. You need to clean up your /usr/include hierarchy.  On an average
  514.      system, some of the files in here are `core' functionality and come
  515.      with libc, while others are from other packages that you or your
  516.      distribution builder have installed.  Given this mess, I suggest
  517.      you remake it from scratch; rename it to /usr/include.old, then
  518.      unpack libc-5.2.18.bin.tar.gz by untarring it from the root
  519.      directory.
  520.  
  521.   10.
  522.      Install the binutils package.  tar -xvzf
  523.      binutils-2.6.0.12.bin.tar.gz -C /  is one perfectly good way to do
  524.      this.
  525.  
  526.   11.
  527.      The gcc package expects to be untarred from root.  It installs some
  528.      files in /usr/bin and lots more in /usr/lib/gcc-
  529.      lib/i486-linux/2.7.2 and /usr/lib/gcc-lib/i486-linuxaout/2.7.2.
  530.      Use
  531.  
  532.  
  533.  
  534.        $ tar ztf gcc-2.7.2.bin.tar.gz
  535.  
  536.  
  537.  
  538.  
  539.  
  540.   to see what's in it, backup anything that it overwrites that you feel
  541.   you may want to keep (for example, if you have Gnu ADA installed you
  542.   will probably want to keep /usr/bin/gcc), then just do
  543.  
  544.  
  545.  
  546.        # tar -zxf gcc-2.7.2.bin.tar.gz -C /
  547.  
  548.  
  549.  
  550.  
  551.  
  552.   At this point, you should be able to run gcc -v and compile test pro-
  553.   grams.  Try
  554.  
  555.  
  556.  
  557.        $ gcc -v
  558.        Reading specs from /usr/lib/gcc-lib/i486-linux/2.7.2/specs
  559.        gcc version 2.7.2
  560.        $ gcc -v -b i486-linuxaout
  561.        Reading specs from /usr/lib/gcc-lib/i486-linuxaout/2.7.2/specs
  562.        gcc version 2.7.2
  563.        $ ld -V
  564.        ld version 2.6 (with BFD 2.6.0.2)
  565.          Supported emulations:
  566.           elf_i386
  567.           i386linux
  568.           i386coff
  569.  
  570.  
  571.  
  572.  
  573.  
  574.   followed of course by the traditional ``Hello, world'' program.  Try
  575.   it with gcc and with gcc -b i486-linuxaout to check that both the
  576.   a.out and ELF compilers are set up correctly.
  577.  
  578.   Finished?  Not quite.  You still have all the `non-core' libraries to
  579.   install, and a fair amount of mucking about with symlinks.  Onwards...
  580.  
  581.  
  582.    Symlinks
  583.  
  584.  
  585.   12.
  586.      Some programs (notably various X programs) use /lib/cpp, which
  587.      under Linux is generally a link to /usr/lib/gcc-
  588.      lib/i486-linux/version/cpp.  As the preceding step probably wiped
  589.      out whatever version of cpp it was pointing to, you'll need to
  590.      recreate the link:
  591.  
  592.  
  593.  
  594.  
  595.   # cd /lib
  596.   # ln -s /usr/lib/gcc-lib/i486-linux/2.7.2/cpp .
  597.  
  598.  
  599.  
  600.  
  601.  
  602.   13.
  603.      When you moved /usr/include to /usr/include.old, you lost the
  604.      symlinks into the kernel sources.  Run
  605.  
  606.  
  607.  
  608.        # cd /usr/include
  609.        # ln -s ../src/linux/include/linux .
  610.        # ln -s ../src/linux/include/asm .
  611.  
  612.  
  613.  
  614.  
  615.  
  616.   (assuming you have kernel source in /usr/src/linux; if not, season to
  617.   taste)
  618.  
  619.   14.
  620.      The FSSTND people have once again justified their keep by moving
  621.      the utmp and wtmp files from /var/adm to /var/run and /var/log
  622.      respectively.  You'll need to add some links dependent on where
  623.      they currently live, and you may need to make the /var/log and
  624.      /var/adm directories too.  I reproduce below the ls -l output of
  625.      appropriate bits on my system:
  626.  
  627.  
  628.  
  629.        $ ls -ld /var/adm /var/log /var/run /var/log/*tmp /var/run/*tmp
  630.        lrwxrwxrwx   1 root     root            3 May 24 05:53 /var/adm -> log/
  631.        drwxr-xr-x   9 root     root         1024 Aug 13 23:17 /var/log/
  632.        lrwxrwxrwx   1 root     root           11 Aug 13 23:17 /var/log/utmp -> ../run/utmp
  633.        -rw-r--r--   1 root     root       451472 Aug 13 23:00 /var/log/wtmp
  634.        drwxr-xr-x   2 root     root         1024 Aug 13 23:17 /var/run/
  635.        -rw-r--r--   1 root     root          448 Aug 13 23:00 /var/run/utmp
  636.  
  637.  
  638.  
  639.  
  640.  
  641.   Check the FSSTND (from LDP archives such as  <ftp://sun-
  642.   site.unc.edu/pub/Linux/docs/fsstnd/>) for the full story.
  643.  
  644.  
  645.   Rejoice!
  646.  
  647.   By this time you should have a (more or less) fully functioning ELF
  648.   development system.  Stand back and celebrate quietly for a few
  649.   minutes.
  650.  
  651.  
  652.   Essential source code packages
  653.  
  654.  
  655.   15.
  656.      ncurses installation is a fairly long job, though most of of the
  657.      time can be spent reading Usenet while it builds.  After unpacking
  658.      the tar file, read the INSTALL file pretending that you are `a
  659.      Linux ...] distribution integrator or packager'; that is, you
  660.      probably want to be configuring it with a command like
  661.        $ ./configure --with-normal --with-shared --disable-termcap --enable-overwrite --prefix=/usr
  662.  
  663.  
  664.  
  665.  
  666.   Take heed also of the comments about the default terminal type; in 1.3
  667.   and 2.0 kernels this is set to linux at boot time, but you may find
  668.   that you need to edit /etc/inittab to avoid having it set back to con-
  669.   sole by getty.  If you do not have /usr/lib/terminfo on the root disk
  670.   you will have to fiddle with the `fallback' support in ncurses.  This
  671.   is documented in the INSTALL file mentioned above, and is simple but
  672.   tedious (due to the necessity of building the library twice).  If
  673.   you're happy with having linux and vt100 as fallbacks, there is a
  674.   ready-prepared fallback.c at
  675.   <ftp://ftp.uk.linux.org/pub/Linux/libc/non-core/fallback.c> which you
  676.   can copy over the existing one.  After you have installed ncurses,
  677.   you'll have to get messy in /usr/lib --- it does some non-optimal
  678.   things that are simplest to clear up by hand.  Note the weird discrep-
  679.   ancy between the version numbers; this is ugly but not actually detri-
  680.   mental to human health.
  681.  
  682.      a. /usr/lib/libncurses.so.1.9.9e should be moved to /lib so that
  683.         curses programs which run in single-user mode will continue to
  684.         do so.  If you have /usr/lib on the root partition, this is
  685.         unnecessary but will do no harm.
  686.  
  687.      b. In /lib, make a link to libncurses.so.1.9.9e called
  688.         libncurses.so.3.0.
  689.  
  690.      c. You also need links /usr/lib/libncurses.so,
  691.         /usr/lib/libcurses.so and /usr/lib/libtermcap.so which should
  692.         all point to /lib/libncurses.so.3.0.
  693.  
  694.   In brief for the hard of thinking, that little lot was
  695.  
  696.  
  697.        # cd /lib
  698.        # mv /usr/lib/libncurses.so.1.9.9e .
  699.        # ln -s libncurses.so.1.9.9e libncurses.so.3.0
  700.        # cd /usr/lib
  701.        # ln -s /lib/libncurses.so.3.0 libncurses.so
  702.        # ln -s /lib/libncurses.so.3.0 libcurses.so
  703.        # ln -s /lib/libncurses.so.3.0 libtermcap.so
  704.  
  705.  
  706.  
  707.  
  708.  
  709.   16.
  710.      gdbm installation.  Unpack the source code in a source code
  711.      directory, apply gdbm.patch, and look over the README and INSTALL
  712.      files.  The build process should go something like:
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.   $ tar zxf gdbm-1.7.3.tar.gz
  728.   $ patch -p0 < gdbm.patch
  729.   $ cd gdbm-1.7.3
  730.   $ ./configure --prefix=/usr
  731.   $ make
  732.   $ make progs
  733.   $ su
  734.   # make install
  735.   # make install-compat
  736.   # cd /usr/lib
  737.   # ln -s libgdbm.so.1 libgdbm.so
  738.   # ln -s libgdbm.so.1 libgdbm.so.2
  739.   # ldconfig
  740.  
  741.  
  742.  
  743.  
  744.   The last step is for backward-compatibility; some current distribu-
  745.   tions use libgdbm.so.2 which is exactly the same code as libgdbm.so.1,
  746.   but misnumbered for historical reasons.
  747.  
  748.   Optional source code packages.  In general, you can just install these
  749.   according to their instructions, so I won't repeat them.  There are
  750.   two exceptions, though:
  751.  
  752.  
  753.   17.
  754.      If you want the GNU-ish termcap (strictly speaking, optional; in
  755.      practice, necessary to use XFree86 binaries) it also needs to be
  756.      built from source, but shouldn't require anything more complex than
  757.  
  758.  
  759.  
  760.        $ tar zxf termcap-2.0.8.tar.gz
  761.        $ cd termcap-2.0.8
  762.        $ make
  763.        $ su
  764.        # cp libtermcap.so.2.0.8 /usr/lib
  765.        # ldconfig
  766.  
  767.  
  768.  
  769.  
  770.   I recommend that you don't make install, as this would overwrite bits
  771.   of the ncurses installation.  If you need to actually compile things
  772.   against this library, as opposed to just running binaries that were
  773.   made with it, think about putting the header files and static
  774.   libraries somewhere nonstandard, and using -I and -L flags when you
  775.   compile the said things.  The vagueness of this description should
  776.   make it plain that continued use of termcap is `discouraged' unless
  777.   you have a good reason.
  778.  
  779.  
  780.   18.
  781.      For libdb, it goes something like:
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.   $ tar zxf db.1.85.tar.gz
  794.   $ patch -p0 <db.patch
  795.   $ cd db.1.85/PORT/linux
  796.   $ make
  797.   $ su
  798.   # mkdir /usr/include/db
  799.   # ldconfig
  800.   # cp libdb.so.1.85.3 /usr/lib ; ( cd /usr/lib && ln -s libdb.so.1 libdb.so )
  801.   # cp ../../include/*.h /usr/include/db
  802.  
  803.  
  804.  
  805.  
  806.   Note that
  807.  
  808.   o  you're not applying PORT/linux/OTHER_PATCHES, because it's subsumed
  809.      by this patch
  810.  
  811.   o  you're installing the header files somewhere other than
  812.      /usr/include --- they conflict with the ones that gdbm uses.  To
  813.      compile programs that want libdb you must add -I/usr/include/db to
  814.      the C compiler's command line.
  815.  
  816.  
  817.  
  818.   2.5.  What it should look like (outline directory structure)
  819.  
  820.   This is a deliberately vague guide to what the files you have just
  821.   installed are.  It may be useful for troubleshooting or deciding what
  822.   to delete.
  823.  
  824.  
  825.   2.5.1.  /lib
  826.  
  827.  
  828.   o  Dynamic linkers ld.so (a.out) and ld-linux.so.1 (ELF).  Either of
  829.      these may be symlinks, but make sure that the files they point to
  830.      do exist.
  831.  
  832.   o  Basic shared libraries libc.so.4, libm.so.4 (a.out) These are
  833.      symlinks, but check that they point to real files.
  834.  
  835.   o  Basic shared libraries libc.so.5, libm.so.5,
  836.      libdl.so.1,libncurses.so.1,libtermcap.so.2, (ELF).  Again, these
  837.      are symlinks.  Check the files that they point to.
  838.  
  839.  
  840.   2.5.2.  /usr/lib
  841.  
  842.  
  843.   o  All the non-library files and directories that were there
  844.      previously.
  845.  
  846.   o  libbfd.so*,libdb.so*, libgdbm.so*, ELF shared libraries.
  847.  
  848.   o  More symlinks.  For each library in /lib or /usr/lib, there should
  849.      be a symlink in here.  The link's name should be the real filename,
  850.      minus the version number.  For example, for libc,
  851.  
  852.  
  853.  
  854.        lrwxrwxrwx   1 root     root           14 May  2 20:09 /lib/libc.so.5 -> libc.so.5.3.12
  855.        -rwxr-xr-x   1 bin      bin        583795 Apr 25 06:15 /lib/libc.so.5.3.12
  856.        lrwxrwxrwx   1 root     root           12 Oct 27  1995 /usr/lib/libc.so -> /lib/libc.so.5
  857.  
  858.  
  859.   These links are used by ld at link time.
  860.  
  861.   o  libbsd.a, libgmon.a, libmcheck.a, libmcheck.a and one lib*.a file
  862.      for every ELF shared library in /lib and /usr/lib.  ELF static
  863.      libraries.  The ones that duplicate shared libraries may not be
  864.      tremendously useful for most people --- when using ELF, you can use
  865.      the gcc -g switch with shared libraries, so there's not much reason
  866.      to compile static any longer.  You will need to keep them if you
  867.      actually want to debug the libraries themselves.
  868.  
  869.   o  crt0.o, gcrt0.o.  a.out `start of program' files; one of these is
  870.      linked as the first file in every a.out program you compile, unless
  871.      you take steps to avoid it.
  872.  
  873.   o  crt1.o, crtbegin.o, crtbeginS.o, crtend.o, crtendS.o, crti.o,
  874.      crtn.o, gcrt1.o.  ELF startup files.  These do similar things to
  875.      *crt0.o above for ELF programs.
  876.  
  877.  
  878.   2.5.3.  /usr/lib/ldscripts
  879.  
  880.  
  881.   o  This is where the driver scripts for ld live, as the name suggests.
  882.      It should look like
  883.  
  884.  
  885.        $ ls /usr/lib/ldscripts/
  886.        elf_i386.x      elf_i386.xs     i386coff.xn     i386linux.xbn
  887.        elf_i386.xbn    elf_i386.xu     i386coff.xr     i386linux.xn
  888.        elf_i386.xn     i386coff.x      i386coff.xu     i386linux.xr
  889.        elf_i386.xr     i386coff.xbn    i386linux.x     i386linux.xu
  890.  
  891.  
  892.  
  893.  
  894.  
  895.   2.5.4.  /usr/i486-linux/bin
  896.  
  897.  
  898.   o  ar, as, gasp, ld, nm, ranlib, strip.  These are all actually
  899.      symlinks to the real binutils in /usr/bin
  900.  
  901.  
  902.   2.5.5.  /usr/i486-linuxaout/bin
  903.  
  904.  
  905.   o  as --- the a.out assembler, and gasp, its macro preprocessor
  906.  
  907.   o  ar, ld, nm, ranlib, strip --- symlinks to the real binutils in
  908.      /usr/bin
  909.  
  910.  
  911.   2.5.6.  /usr/i486-linux/lib
  912.  
  913.  
  914.   o  ldscripts is a symlink to /usr/lib/ldscripts.
  915.  
  916.  
  917.   2.5.7.  /usr/i486-linuxaout/lib
  918.  
  919.  
  920.   o  lib*.so*. a.out shared library images.  Needed to run a.out
  921.      programs
  922.  
  923.   o  lib*.sa. a.out shared library stubs.  Needed to compile a.out
  924.      programs that use shared libraries.  If you don't intend to, you
  925.      can safely remove these.
  926.  
  927.   o  lib*.a. a.out static libraries.  Needed to compile static a.out
  928.      programs (eg when compiling with -g).  Again, you can delete them
  929.      if you don't intend to do this.
  930.  
  931.   o  ldscripts is a symbolic link to /usr/lib/ldscripts
  932.  
  933.  
  934.   2.5.8.  /usr/lib/gcc-lib/i486-linux/2.7.2
  935.  
  936.  
  937.   o  This directory contains a version of gcc 2.7.2 set up to compile
  938.      ELF programs.
  939.  
  940.  
  941.   2.5.9.  /usr/lib/gcc-lib/i486-linuxaout/2.7.2
  942.  
  943.  
  944.   o  This directory contains a version of gcc 2.7.2 set up to compile
  945.      a.out programs, which knows about the new directory structure.  If
  946.      you're not going to compile anything in a.out, deleting this may
  947.      free up around 4Mb.  Note that you need to keep it if you want to
  948.      build unpatched 1.2 series kernels.
  949.  
  950.  
  951.   2.6.  Common errors --- Don't Panic!
  952.  
  953.   (in large friendly letters)
  954.  
  955.  
  956.  
  957.  
  958.       You moved the wrong thing and now nothing runs
  959.         You still have a shell running, though, and with a little
  960.         ingenuity you can do an awful lot with shell builtins.  Remember
  961.         that echo * is an acceptable substitute for ls, and echo
  962.         >>filename can be used to add lines to a file.  Also, don't
  963.         forget that ldconfig is linked static.  If you moved, say,
  964.         libc.so.4 to /lib-aout mistakenly, you can do echo "lib-aout"
  965.         >>/etc/ld.so.conf ; ldconfig -v/ and be back up again.  If you
  966.         moved /lib/ld.so you may be able to do sln /silly/place/ld.so
  967.         /lib/ld.so, if you have a statically linked ln, and probably be
  968.         back up again.
  969.  
  970.  
  971.       bad address
  972.         on attempting to run anything ELF.  You're using kernel 1.3.x,
  973.         where x<3.  Don't.  They're probably the buggiest Linux kernels
  974.         on the planet anyway.  Upgrade to 2.0 or downgrade to 1.2.13.
  975.         Some people also report kernel panics in similar circumstances;
  976.         I haven't investigated, chiefly as I can think of no reason for
  977.         wanting or needing to run development kernels and not keeping up
  978.         with the releases.
  979.  
  980.  
  981.       gcc: installation problem, cannot exec something: No such file or
  982.         directory
  983.         when attempting to do a.out compilations (something is usually
  984.         one of cpp or cc1).  Either it's right, or alternatively you
  985.         typed
  986.  
  987.  
  988.  
  989.           $ gcc -b -i486-linuxaout
  990.  
  991.      when you should have typed
  992.  
  993.  
  994.  
  995.           $ gcc -b i486-linuxaout
  996.  
  997.  
  998.  
  999.  
  1000.      Note that the `i486' does not start with a dash.
  1001.  
  1002.  
  1003.      make: *** No targets specified and no makefile found.  Stop.
  1004.         indicates that you haven't patched and recompiled make, or that
  1005.         you still have an old version of it elsewhere on the system.
  1006.  
  1007.  
  1008.       no such file or directory: /usr/bin/gcc
  1009.         (or any other file that you try to run) when you know there is
  1010.         such a file.  This usually means that the ELF dynamic loader
  1011.         /lib/ld-linux.so.1 is not installed, or is unreadable for some
  1012.         reason.  You should have installed it at around step 2
  1013.         previously.
  1014.  
  1015.  
  1016.       not a ZMAGIC file, skipping
  1017.         from ldconfig.  You have an old version of the ld.so package, so
  1018.         get a recent one.  Again, see step 2 of the installation.
  1019.  
  1020.  
  1021.       _setutent: Can't open utmp file
  1022.         This message is often seen in multiples of three when you start
  1023.         an xterm.  Go and read the FSSTND tirade near the end of the
  1024.         installation procedure.
  1025.  
  1026.  
  1027.  
  1028.   3.  Building programs
  1029.  
  1030.   3.1.  Ordinary programs
  1031.  
  1032.   To build a program in ELF, use gcc as always.  To build in a.out, use
  1033.   gcc -b i486-linuxaout .
  1034.  
  1035.  
  1036.  
  1037.        $ cat >hello.c
  1038.        main() { printf("hello, world\n"); }
  1039.        ^D
  1040.        $ gcc -o hello hello.c
  1041.        $ file hello
  1042.        hello: ELF 32-bit LSB executable i386 (386 and up) Version 1
  1043.        $ ./hello
  1044.        hello, world
  1045.  
  1046.  
  1047.  
  1048.  
  1049.   This is perhaps an appropriate time to answer the question ``if a.out
  1050.   compilers default to producing a program called a.out, what name does
  1051.   an ELF compiler give its output?''.  Still a.out, is the answer.
  1052.   Boring boring boring ...  :-)
  1053.  
  1054.  
  1055.  
  1056.  
  1057.   3.2.  Building libraries
  1058.  
  1059.   To build libfoo.so as a shared library, the basic steps look like
  1060.   this:
  1061.  
  1062.  
  1063.  
  1064.        $ gcc -fPIC -c *.c
  1065.        $ gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 *.o
  1066.        $ ln -s libfoo.so.1.0 libfoo.so.1
  1067.        $ ln -s libfoo.so.1 libfoo.so
  1068.        $ export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
  1069.  
  1070.  
  1071.  
  1072.  
  1073.   This will generate a shared library called libfoo.so.1.0, and the
  1074.   appropriate links for ld (libfoo.so) and the dynamic linker
  1075.   (libfoo.so.1) to find it.  To test, we add the current directory to
  1076.   LD_LIBRARY_PATH.
  1077.  
  1078.   When you're happpy that the library works, you'll have to move it to,
  1079.   say, /usr/local/lib, and recreate the appropriate links.  Note that
  1080.   the libfoo.so link should point to libfoo.so.1, so it doesn't need
  1081.   updating on every minor version number change.  The link from
  1082.   libfoo.so.1 to libfoo.so.1.0 is kept up to date by ldconfig, which on
  1083.   most systems is run as part of the boot process.
  1084.  
  1085.  
  1086.  
  1087.        $ su
  1088.        # cp libfoo.so.1.0 /usr/local/lib
  1089.        # /sbin/ldconfig
  1090.        # ( cd /usr/local/lib ; ln -s libfoo.so.1 libfoo.so )
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.   3.3.  Building in a.out
  1097.  
  1098.   You may have a need to continue to build programs in the old a.out
  1099.   format.  For `normal' programs all you need to do to use the a.out
  1100.   compiler is specify the flag -b i486-linuxaout when you call gcc, and
  1101.   -m i386linux when (if) you call ld.  If you need to build a.out DLL
  1102.   shared libraries still, you have my sympathy.  To the best of my
  1103.   knowledge, the short answer is that it doesn't work.  Please mail me
  1104.   if you know different.
  1105.  
  1106.  
  1107.   4.  Patches and binaries
  1108.  
  1109.   At this point in the proceedings, you can, if you like, stop.  You
  1110.   have installed everything necessary to compile and run ELF programs.
  1111.  
  1112.   You may wish to rebuild programs in ELF, either for purposes of
  1113.   `neatness' or to minimise memory usage.  For most end-user
  1114.   applications, this is pretty simple; some packages however do assume
  1115.   too much about the systems they run on, and may fail due to one or
  1116.   more of:
  1117.  
  1118.   o  Different underscore conventions in the assembler: in an a.out
  1119.      executable, external labels get _ prefixed to them; in an ELF
  1120.      executable, they don't.  This makes no difference until you start
  1121.      integrating hand-written assembler: all the labels of the form _foo
  1122.      must be translated to foo, or (if you want to be portable about it)
  1123.      to EXTERNAL(foo) where EXTERNAL is some macro which returns either
  1124.      its argument (if __ELF__ is defined) or _ concatenated with its
  1125.      argument if not.
  1126.  
  1127.   o  Differences in libc 5 from libc 4.  The interface to the locale
  1128.      support has changed, for one.
  1129.  
  1130.   o  The application or build process depending on knowledge of the
  1131.      binary format used --- emacs, for example, dumps its memory image
  1132.      to disk in executable format, so obviously needs to know what
  1133.      format your executables are in.
  1134.  
  1135.   o  The application consists of or includes shared libraries (X11 is
  1136.      the obvious example).  These will obviously need changes to
  1137.      accomodate the different method of shared library creation in ELF.
  1138.  
  1139.   Anyway, here are two lists: the first is of programs that needed
  1140.   changing for ELF where the changes have been made (i.e. that you will
  1141.   need new versions of to compile as ELF), and the second is of programs
  1142.   that still need third-party patches of some kind.
  1143.  
  1144.  
  1145.   4.1.  Upgrade:
  1146.  
  1147.  
  1148.   o  Dosemu.  Nowadays, dosemu runs with ELF.  You'll need to monkey
  1149.      with the Makefile.  Current versions of dosemu are available from
  1150.      <ftp://tsx-11.mit.edu/pub/linux/ALPHA/dosemu/>
  1151.  
  1152.   o  e2fsutils.  The Utilities for the Second Extended File System
  1153.      versions 0.5c and later compile unchanged in ELF.
  1154.  
  1155.   o  Emacs.  There are two potential problems here.  (i) Emacs has a
  1156.      rather odd build procedure that involves running a minimal version
  1157.      of itself, loading in all the useful bits as lisp, then dumping its
  1158.      memory image back to disk as an executable file.  (FSF) Emacs 19.29
  1159.      and XEmacs 19.12 (formerly Lucid Emacs) can both detect whether you
  1160.      are compiling as ELF and Do The Right Thing automatically.  (ii) If
  1161.      you build some versions of emacs against ncurses, it will fail
  1162.      unless you first edit src/s/linux.h in the emacs distribution to
  1163.      add the line #define TERMINFO somewhere near the top.  This is not
  1164.      necessary for 19.31, but is for XEmacs 19.13.  Apparently it will
  1165.      be fixed in 19.14.
  1166.  
  1167.   o  gdb 4.16.  Your existing copy of gdb will continue to work just as
  1168.      well as it always has done in the past, but the shared library
  1169.      support in 4.16 is a lot better, so if you want to debug programs
  1170.      that do weird things in that area, this is a good upgrade.
  1171.  
  1172.   o  The Kernel.  Kernel versions 2.0 and greater work fine with ELF;
  1173.      you have to say `yes' to both of
  1174.  
  1175.  
  1176.  
  1177.        Kernel support for ELF binaries (CONFIG_BINFMT_ELF) [Y/m/n/?]
  1178.        Compile kernel as ELF - if your GCC is ELF-GCC (CONFIG_KERNEL_ELF) [Y/n/?]
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.   when you run make config (this is also the case for most of the 1.3
  1185.   series).  If you are using 1.2 still, see the `patch' list below.
  1186.  
  1187.   o  perl 5.  Perl 5.001m and later will compile unchanged on an ELF
  1188.      system, complete with dynamic loading.  Current versions of Perl
  1189.      are available from CPAN (Comprehensive Perl Archive Network) sites:
  1190.      see  <ftp://ftp.funet.fi/pub/mirrors/perl/CPAN> for the closest one
  1191.      to you.
  1192.  
  1193.   o  ps and top.  Procps 0.98 and greater will work with ELF (earlier
  1194.      versions also work, but can't read the kernel to find WCHAN names,
  1195.      if you care about them).  Note that 2.0 series kernels require
  1196.      procps 0.99a or greater anyway.
  1197.  
  1198.   o  The cal program in util-linux 2.2 doesn't work.  Upgrade to version
  1199.      2.5 <ftp://tsx-11.mit.edu/pub/linux/packages/utils> or later.
  1200.  
  1201.   o  Mosaic.  I don't have the facilities to build this myself, but the
  1202.      Mosaic 2.7b1 binary available from NCSA comes in ELF.  It has been
  1203.      linked against an odd X setup though, with the result that on
  1204.      normal systems it will complain about not finding libXpm.so.4.5.
  1205.      The simple fix is to edit it carefully with emacs or another editor
  1206.      that copes with binary files.  Find the occurence of the string
  1207.      libXpm.so.4.5^@ (where ^@ is a NUL --- ASCII zero --- character),
  1208.      delete the .5 and add two more characters after the NUL to aviod
  1209.      changing the file length.
  1210.  
  1211.  
  1212.   4.2.  Patch
  1213.  
  1214.  
  1215.   o  file.  This works anyway, but can be improved:
  1216.      <ftp://ftp.uk.linux.org/pub/Linux/libc/non-core/file.patch> adds
  1217.      support for identifying stripped and mixed-endian ELF binaries.
  1218.  
  1219.   o  make-3.74 --- either get the source code from a GNU site and apply
  1220.      the patch that comes with the libc-5.3.12 release notes, or get the
  1221.      binary make-3.74.gz from tsx-11.  There is a bug in GNU make which
  1222.      only manifests with new ELF libc versions --- it's actually a
  1223.      dependency on a bug in old versions of the GNU libc, which was also
  1224.      present in Linux libc until recently.  If you keep your old a.out
  1225.      make program it will continue to work, but if you want an ELF one
  1226.      you need the patch.
  1227.  
  1228.      The GNU Make developers know about the bug, and one day will
  1229.      release a fixed version.
  1230.  
  1231.   o  The 1.2.x Kernel.  You have three options:
  1232.  
  1233.  
  1234.      1. Patch the Makefile slightly to use the a.out compiler.  cd
  1235.         /usr/src/linux/, cut the following patch out, and feed it into
  1236.         patch -p1.  Or just edit the Makefile manually using this as a
  1237.         guide; it's clear enough (delete the lines marked with a - and
  1238.         add the ones with a +.
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.      diff -u linux-1.2.13/Makefile.orig linux/Makefile
  1256.      --- linux-1.2.13/Makefile.orig  Wed Aug 16 20:53:26 1995
  1257.      +++ linux/Makefile      Fri Dec  8 16:19:49 1995
  1258.      @@ -12,9 +12,9 @@
  1259.       TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
  1260.  
  1261.      -AS     =as
  1262.      -LD     =ld
  1263.      -HOSTCC =gcc -I$(TOPDIR)/include
  1264.      -CC     =gcc -D__KERNEL__ -I$(TOPDIR)/include
  1265.      +AS     =/usr/i486-linuxaout/bin/as
  1266.      +LD     =ld  -m i386linux
  1267.      +HOSTCC =gcc -b i486-linuxaout -I$(TOPDIR)/include
  1268.      +CC     =gcc -b i486-linuxaout -D__KERNEL__ -I$(TOPDIR)/include
  1269.       MAKE   =make
  1270.       CPP    =$(CC) -E
  1271.       AR     =ar
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.      Alternatively,
  1278.  
  1279.      2. Apply H J Lu's patch which allows compiling the kernel in ELF
  1280.         (and also adds the ability to do ELF core dumps).  This can be
  1281.         had from
  1282.         <ftp://ftp.cdrom.com/pub/linux/slackware_source/kernel-
  1283.         source/v1.2/linuxelf-1.2.13.diff.gz>.
  1284.  
  1285.         If you are using an ELF distribution (RedHat 2.1, Slackware 3)
  1286.         which comes with a 1.2 series kernel, you will probably find
  1287.         that this patch or one similar has been applied already.
  1288.  
  1289.         The best idea, hoever, is probably
  1290.  
  1291.      3. Upgrade to 2.0!  1.2 was never really intended for ELF anyway.
  1292.  
  1293.  
  1294.      You will have other problems compiling 1.2.13 with gcc 2.7.2 and
  1295.      above; there was a bug in asm/io.h which is only detected by gcc
  1296.      2.7.2.  You will need the patch
  1297.      <ftp://ftp.uk.linux.org/pub/Linux/libc/misc/io.h>.
  1298.  
  1299.  
  1300.   5.  Further information
  1301.  
  1302.  
  1303.  
  1304.   o  The GCC-HOWTO <GCC-HOWTO.html> contains much useful information
  1305.      about development on Linux (at least, I think it does; I maintain
  1306.      it).  It should be available from the same place as you found this,
  1307.      which is why the link above is relative.
  1308.  
  1309.   o  The linux-gcc mailing list (which is also the linux.dev.gcc
  1310.      newsgroup, if you have a linux.* news feed) is really the best
  1311.      place to see what's happening, usually without even posting to it.
  1312.      Remember, it's not Usenet, so keep the questions down unless you're
  1313.      actually developing.  For instructions on joining the mailing list,
  1314.      mail a message containing the word help to
  1315.      majordomo@vger.rutgers.edu.  Archives of the list are at
  1316.      <http://www.linux.ncm.com/linux-gcc/>.
  1317.  
  1318.   o  There's a certain amount of information about what the linux-gcc
  1319.      list is doing at my linux-gcc web page
  1320.      <http://ftp.uk.linux.org/~barlow/linux/gcc-list.html>, when I
  1321.      remember to update it.  This also has a link to the latest version
  1322.      of this HOWTO, and the patches it refers to.  For US people and
  1323.      others with poor links to UK academic sites (that's nearly everyone
  1324.      outside of UK academia), this is all mirrored at
  1325.      <http://www.blackdown.org/elf/elf.html>
  1326.  
  1327.   o  There's also documentation for the file format on tsx-11
  1328.      <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/ELF.doc.tar.gz>.  This
  1329.      is probably of most use to people who want to understand, debug or
  1330.      rewrite programs that deal directly with binary objects.
  1331.  
  1332.   o  H J Lu's document ELF: From The Programmer's Perspective
  1333.      <ftp://tsx-11.mit.edu/pub/linux/packages/GCC/elf.latex.tar.gz>
  1334.      contains much useful and more detailed information on programming
  1335.      with ELF.  If you aren't LaTeX-capable, it is also available as
  1336.      PostScript.
  1337.  
  1338.   o  Information about the ncurses library and the terminfo database is
  1339.      available from Eric Raymond's ncurses resource page
  1340.      <http://www.ccil.org/~esr/ncurses.html>.
  1341.  
  1342.   o  There is a manual page covering dlopen(3) and related functions,
  1343.      which is supplied with the ld.so package.
  1344.  
  1345.  
  1346.   6.  Miscellanities
  1347.  
  1348.   6.1.  Feedback
  1349.  
  1350.   is welcomed.  Mail me at daniel.barlow@linux.org.  My PGP public key
  1351.   (ID 5F263625) is available from my web pages
  1352.   <http://ftp.uk.linux.org/~barlow/>, if you feel the need to be
  1353.   secretive about things.
  1354.  
  1355.   If you have a question that you feel this document should have
  1356.   answered and doesn't, mail me.  If you have a question which probably
  1357.   shouldn't be answered here but you think I might know the answer
  1358.   anyway, you might want to try posting to an appropriate
  1359.   comp.os.linux.* newsgroup first; I usually answer mail eventually, but
  1360.   I have been known to lose it on occasion.
  1361.  
  1362.   Anyone found adding my name to junk email lists will pay dearly for
  1363.   it.
  1364.  
  1365.  
  1366.   6.2.  Translations
  1367.  
  1368.   If you wish to translate this document, please go right ahead, but do
  1369.   tell me about it!  The chances are (sadly) several hundred to one
  1370.   against that I speak the language you wish to translate to, but that
  1371.   aside I am happy to help in whatever way I can.
  1372.  
  1373.  
  1374.   Translations that I know of are:
  1375.  
  1376.  
  1377.   o  Italian <http://www.psico.unipd.it/ildp/docs/HOWTO/ELF-HOWTO.html>,
  1378.      by Favro Renata.  (Other HOWTOs are also available in Italian from
  1379.      <http://www.psico.unipd.it/ildp/docs/HOWTO/INDEX.html>.
  1380.  
  1381.   o  Kojima Mitsuhiro has produced a Japanese translation, available
  1382.      from  <http://jf.gee.kyoto-u.ac.jp/JF/index.html>.
  1383.  
  1384.  
  1385.  
  1386.  
  1387.   6.3.  Legal bits
  1388.  
  1389.   All trademarks used in this document are acknowledged as being owned
  1390.   by their respective owners.  Yow!
  1391.  
  1392.  
  1393.   The right of Daniel Barlow to be identified as the author of this work
  1394.   has been asserted in accordance with sections 77 and 78 of the
  1395.   Copyright Designs and Patents Act 1988.
  1396.  
  1397.   This document is copyright (C) 1996 Daniel Barlow
  1398.   <daniel.barlow@linux.org> It may be reproduced and distributed in
  1399.   whole or in part, in any medium physical or electronic, as long as
  1400.   this copyright notice is retained on all copies. Commercial
  1401.   redistribution is allowed and encouraged; however, the author would
  1402.   like to be notified of any such distributions.
  1403.  
  1404.   All translations, derivative works, or aggregate works incorporating
  1405.   any Linux HOWTO documents must be covered under this copyright notice.
  1406.   That is, you may not produce a derivative work from a HOWTO and impose
  1407.   additional restrictions on its distribution. Exceptions to these rules
  1408.   may be granted under certain conditions; please contact the Linux
  1409.   HOWTO coordinator at the address given below.
  1410.  
  1411.   In short, we wish to promote dissemination of this information through
  1412.   as many channels as possible. However, we do wish to retain copyright
  1413.   on the HOWTO documents, and would like to be notified of any plans to
  1414.   redistribute the HOWTOs.
  1415.  
  1416.   If you have questions, please contact Tim Bynum, the Linux HOWTO
  1417.   coordinator, at linux-howto@sunsite.unc.edu.
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.