home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / HOWTO / ELF-HOWT < prev    next >
Encoding:
Text File  |  1995-04-20  |  48.7 KB  |  1,711 lines

  1.         The Linux ELF HOWTO
  2.         version 0.99 - Tue Dec 27
  3.         by Riccardo Facchetti <riccardo@cdc8g5.cdc.polimi.it>
  4.  
  5. ** Note:    This file is provided 'as-is', see disclaimer
  6. ** Note1:   The Author is Riccardo Facchetti
  7. ** Note2:   Read CAREFULLY all the HOWTO if you want to do the things described!
  8.             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9. ** Note3:   GNU Make v. 3.72.1 seems to have a bug, I use GNU Make v. 3.70
  10. ** Note4:   If you will install g++, you may want to install libg++ too.
  11.             The installation of libg++ is NOT discussed here because it is out
  12.             of the scope of this HOWTO (may be it will be included in a
  13.             following release)
  14.         
  15.  
  16. INDEX
  17.     0.  Why ?
  18.     1.  Introduction
  19.     1.1 Copyright
  20.     1.2 Feedback
  21.     1.3 Disclaimer
  22.     2.  What do i need to start up ?
  23.     2.1 Where can i find all the things at 2. ?
  24.     2.2 Other requirements
  25.     3.  Theory of operation
  26.     3.1 Choose an alternate directory tree
  27.     4.  Building binutils-2.5.2.6
  28.     4.1 Preparing binutils-2.5.2.6 for compilation
  29.     4.2 Compiling binutils-2.5.2.6
  30.     4.3 Installing binutils-2.5.2.6
  31.     5.  Building gcc-2.6.2
  32.     5.1 Preparing gcc-2.6.2 for compilation
  33.     5.2 Compiling gcc-2.6.2
  34.     5.3 Installing gcc-2.6.2
  35.     5.4 Try it now!
  36.     6.  Building libc-4.6.27
  37.     6.1 Preparing libc-4.6.27 for compilation
  38.     6.2 Compiling libc-4.6.27
  39.     6.3 Installing libc-4.6.27
  40.     6.4 Try the Whole Thing!
  41.     7.  Recompiling the Whole Thing: Stage 2
  42.     7.1 Recompiling binutils-2.5.2.6
  43.     7.2 Recompiling gcc-2.6.2
  44.     7.3 Recompiling libc-4.6.27
  45.     8.  Patch: binutils-2.5.2 ==> binutils-2.5.2.6
  46.     
  47.  
  48. ==============================================================================
  49.  
  50. 0.  Why ?
  51.  
  52.     Hello,
  53.     in the last two weeks, i've faced the problem of jump-table -> ELF migration
  54.     This is a real problem because linux binary format is destined to migrate
  55.     to ELF and sooner or later we will be forced to re-install all the binaries
  56.     or re-compile it (unless we want have systems in an half-way with both
  57.     ELF and jump-table libraries for long time)
  58.  
  59.     I've started to ask around where can i find ELF gcc/gas/gld/libc ELF
  60.     binaries. Unfortunately noone have answered to me useful informations.
  61.  
  62.     After this first try, i've decided to bootstrap an ELF development package
  63.     on my onw.
  64.  
  65.     I have collected all the stages in an HOW TO: the ELF-HOWTO.
  66.  
  67. 1.  Introduction
  68.  
  69.     This is the Linux ELF HOWTO.
  70.     
  71.     This document describes the way I have started the migration of
  72.     my system to the ELF binary file format.
  73.  
  74.     This HOWTO is written during the Real Thing: all the things written here
  75.     are tested by me directly.
  76.  
  77. 1.1 Copyright
  78.  
  79.     The Linux ELF HOWTO is copyright (C) 1995 by Riccardo Facchetti.  Linux
  80.     HOWTO documents may be reproduced and distributed in whole or in part,
  81.     in any medium physical or electronic, as long as this copyright notice
  82.     is retained on all copies. Commercial redistribution is allowed and
  83.     encouraged; however, the author would like to be notified of any such
  84.     distributions.
  85.  
  86.     All translations, derivative works, or aggregate works incorporating
  87.     any Linux HOWTO documents must be covered under this copyright notice.
  88.     That is, you may not produce a derivative work from a HOWTO and impose
  89.     additional restrictions on its distribution. Exceptions to these rules
  90.     may be granted under certain conditions; please contact the Linux
  91.     HOWTO coordinator at the address given below.
  92.  
  93.     In short, we wish to promote dissemination of this information through
  94.     as many channels as possible. However, we do wish to retain copyright
  95.     on the HOWTO documents, and would like to be notified of any plans to
  96.     redistribute the HOWTOs.
  97.  
  98.     If you have questions, please contact Matt Welsh, the Linux HOWTO
  99.     coordinator, at
  100.     mdw@sunsite.unc.edu.  You may finger this address for phone number and
  101.     additional contact information.
  102.  
  103. 1.2 Feedback
  104.  
  105.     Since this HOWTO will be mantained in a relaxed way because of the little
  106.     time I can spend on it, please send me suggestions, bugs and
  107.     comments, but don't expect them to be included in a short-term update.
  108.  
  109.     You can reach me via e-mail at:
  110.  
  111.     riccardo@cdc8g5.cdc.polimi.it
  112.  
  113.     or via snail-mail at:
  114.  
  115.     Riccardo Facchetti
  116.     Via PAOLO VI, 29
  117.     22053 - Lecco (Lc)
  118.         ITALY
  119.  
  120. 1.3 Disclaimer
  121.  
  122.     This document is *not* bible.
  123.     The Author is not responsible
  124.     for any damages incurred due to actions taken based on the
  125.     information included in this document.
  126.  
  127. 2.  What do i need to start up ?
  128.  
  129.     To build ELF executables you need an ELF C compiler, an ELF assembler,
  130.     an ELF linker, and ELF C libraries (static/dynamic/debug/profile).
  131.  
  132.     These are the sources you need to build the ELF system: if you change
  133.                                                             ^^^^^^^^^^^^^
  134.     some source (e.g. you would like to use gcc-2.6.3 instead of gcc-2.6.2)
  135.     ^^^^^^^^^^^
  136.     you are on your own. I think you should follow this document anyway because
  137.     the things contained here are generalized enought.
  138.     If you use a binutils package newer that binutils-2.5.2 may be you do not
  139.     need to patch it with the patch 2.5.2 => 2.5.2.6
  140.     If you use a newer gcc may be you can follow this HOWTO step by step
  141.     If you use a newer libc, may be you do not need to edit all the files
  142.     I have edited.
  143.  
  144.     Do not do anything without think (be sure of what you are doing)!!!
  145.  
  146.     ELF C compiler:     gcc-2.6.2 as is
  147.     ELF assembler:      binutils-2.5.2 patched to 2.5.2.6
  148.     ELF linker:         binutils-2.5.2 patched to 2.5.2.6
  149.     ELF C libraries:    libc-4.6.27 as is
  150.     C libraries header
  151.     patch:              binutils-2.5.2 => binutils-2.5.2.6
  152.  
  153. 2.1 Where can i find all the things at 2. ?
  154.  
  155.     gcc-2.6.2:          standard GNU distribution
  156.     binutils-2.5.2:     standard GNU distribution
  157.     libc-4.6.27:        standard linux.site:/pub/linux/GCC/libc-4.6.27.tar.gz
  158.     patch binutils-2.5.2 => binutils-2.5.2.6:
  159.                         at the end of this document or in libc-4.6.27 announce
  160.  
  161. 2.2 Other requirements
  162.  
  163.     You need to have the libc-4.6.27 jump-table version and inc-2.6.27
  164.     installed on your system. You can find it in every major linux site
  165.     in /pub/linux/GCC/
  166.  
  167.     You need to know how to edit/change/save a text file
  168.  
  169.     You need at least 50 Mbytes of HD space
  170.     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  171.  
  172.     You need jump-table development system (gcc/gas/ld/make/includes/kernel/etc)
  173.  
  174.     You need to compile the BINFMT_ELF option into the kernel
  175.  
  176.     To build ELF development system you need the kernel 1.1.72 or above
  177.  
  178.     [excerpt from libc-4.6.27 announce]
  179.  
  180. You need <linux/elf.h> in the kernel 1.1.72 or above if you want to
  181. compile the ELF libraries yourself. Otherwise, please join the Linux
  182. gcc list.
  183.  
  184. You need to recompile the libraries with the kernel 1.1.65 or above
  185. to gain the support for 57600 and 115200 bps.
  186.  
  187.     [end of excerpt]
  188.  
  189. 3.  Theory of operation
  190.  
  191.     The problem of building the development system for ELF binaries
  192.     is that we need to bootstrap the system from jump-table system.
  193.     On the other hand, we NEED to mantain separate the jump-table
  194.     system from the ELF one because we may want to use all the two
  195.     development systems. We also need to have a /lib for jump-table and
  196.     one for ELF, a gcc/gas/ld for jump-table and one for ELF (this is our
  197.     goal of course :)
  198.     So we need to do the following operations:
  199.  
  200.     a)  Choose an alternate directory tree for ELF system
  201.  
  202.     b)  Build jump-table binaries of binutils-2.5.2.6, to have the ELF
  203.         assembler (gas) and linker (ld)
  204.  
  205.     c)  Install the b)
  206.  
  207.     d)  Build jump-table binaries of gcc-2.6.2 to have the ELF C compiler
  208.  
  209.     e)  Install the d)
  210.  
  211.     f)  Build ELF binaries of libc-4.6.27, to have ELF C libraries
  212.  
  213.     g)  Install the f)
  214.  
  215.     h)  b)-g) is the first stage. To have gcc/gas/ld ELF binaries you must
  216.         repeat the b)-g) stage (2nd stage).
  217.  
  218. 3.1 Choose an alternate directory tree
  219.  
  220.     You must choose an alternate directory tree for your ELF system.
  221.     I have chosen:
  222.  
  223.         /lib/elf                            for ELF shared libraries
  224.         /usr/i486-linuxelf/...              for all the ELF related files
  225.         /usr/i486-linuxelf/bin              for ELF binaries
  226.         /usr/i486-linuxelf/lib              for libraries
  227.         /usr/i486-linuxelf/lib/gcc-lib/...  for gcc and its files
  228.         ...
  229.  
  230.     so the installation prefix will ever be /usr/i486-linuxelf
  231.  
  232. 4.  Building binutils-2.5.2.6
  233.  
  234. 4.1 Preparing binutils-2.5.2.6 for compilation
  235.  
  236. * Unpacking the archive
  237.  
  238. cd /usr/src
  239. tar xfvz binutils-2.5.2.tar.gz
  240. cd binutils-2.5.2
  241.  
  242. * Patching binutils-2.5.2 to binutils-2.5.2.6
  243.  
  244. patch -p0 < ELF-HOWTO
  245.  
  246.     where ELF-HOWTO is this file. The patch, made by H.J. Lu, fixes some
  247.     binutils-2.5.2 bugs and allow the support for ELF.
  248.  
  249. * Search for rejected patches
  250.  
  251. find . -name *.rej -print
  252.  
  253.     should find nothing
  254.  
  255. * Search and erase the original files
  256.  
  257. find . -name *.orig -print -exec rm -f {} \;
  258.  
  259. * Edit bfd/elf32-i386.c
  260.  
  261. vi bfd/elf32-i386.c
  262.  
  263.     at line 194 you should find:
  264.  
  265. #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
  266.  
  267.     change it to:
  268.  
  269. #define ELF_DYNAMIC_INTERPRETER "/lib/elf/ld-linux.so.1"
  270.  
  271.     The libc-4.6.27 will put the dinamic linker in /lib/elf and ld-linux.so.1
  272.     will be a symlink to the real linker -> /lib/elf/ld-linux.so.1.0.14
  273.     This is needed because the ELF executables will use this run-time linker
  274.     to link the shared libraries.
  275.  
  276. * Configure the binutils-2.5.2.6
  277.  
  278.     If you have an i386:
  279.  
  280. ./configure i386-linuxelf
  281.  
  282.     for a 486:
  283.  
  284. ./configure i486-linuxelf
  285.  
  286.     have a little break during configuration, it take few minutes.
  287.  
  288. * Edit Makefile
  289.  
  290. vi Makefile
  291.  
  292.     at line 36 you should find:
  293.  
  294. prefix = /usr/local
  295.  
  296.     change it to:
  297.  
  298. prefix = /usr/i486-linuxelf
  299.  
  300.     to reflect the installation directory tree we have chosen.
  301.  
  302.     at line 82 you should find:
  303.  
  304. CFLAGS = -g
  305.  
  306.     change it to:
  307.  
  308. CFLAGS = -O2 -m486 -fomit-frame-pointer
  309.  
  310.     (use the -m486 only if you have an i486) for optimization.
  311.  
  312. * Edit ld/Makefile to change the defaule emulation mode:
  313.     
  314. vi ld/Makefile
  315.  
  316.     at line 189 you should find:
  317.  
  318. EMUL=i386linux
  319. EMUL_EXTRA1=elf_i386
  320.  
  321.     swap it to:
  322.  
  323. EMUL_EXTRA1=i386linux
  324. EMUL=elf_i386
  325.  
  326.     to set the default emulation to elf_i386 (this will be the ELF linker,
  327.     not the jump-table one).
  328.  
  329. 4.2 Compiling binutils-2.5.2.6
  330.  
  331.     do the
  332.  
  333. make
  334.  
  335.     and have a long coffee break.
  336.  
  337. 4.3 Installing binutils-2.5.2.6
  338.  
  339.     do the
  340.  
  341. make install
  342.  
  343.     and it is done.
  344.  
  345.     Now if you are short of disk space you may want to
  346.  
  347. cd /usr/src
  348. rm -rf binutils-2.5.2
  349.  
  350. 5.  Building gcc-2.6.2
  351.  
  352.     Now we have in /usr/i486-linuxelf/bin the as (gas) and ld (gld), both
  353.     compiled for ELF support.
  354.     Now we will compile gcc-2.6.2 to generate ELF code. We need ELF assembler
  355.     because in the final step, when make generate the libgcc using the xgcc,
  356.     the xgcc is an ELF compiler so he (it?) need the ELF assembler.
  357.  
  358.     Note: gcc-2.6.2 seems to have a bug in ELF generation code of the profiler
  359.           section. When you build code to be profiled (-p or -pg), gcc-2.6.2
  360.           generates a call to mcount() function. Unfortunately, this code
  361.           is generated in assembly stage and gcc fails to generate it.
  362.  
  363.           In fact generates:
  364.  
  365.           call _mcount
  366.  
  367.           instead of
  368.  
  369.           call mcount
  370.  
  371.           ELF binary format do not prepend the '_' (underscore)
  372.           when compiling C to asm functions (don't know for sure, but it
  373.           is likely to be true), so you will end up with a lot of
  374.  
  375.           undefined reference to `_mcount'
  376.  
  377.           messages.
  378.  
  379.           I do not use the profiler.
  380.           Anyway i think the best way to correct this bug is modify libgcc
  381.           because i have not the stomach to put my hands on the gcc :)
  382.           (see 6.1)
  383.  
  384. 5.1 Preparing gcc-2.6.2 for compilation
  385.  
  386. * Unpacking the archive
  387.  
  388. cd /usr/src
  389. tar xfvz gcc-2.6.2.tar.gz
  390. cd gcc-2.6.2
  391.  
  392. * If you are short of disk space (now you need 30 Mbytes to compile gcc)
  393.  
  394.     If you are running short of disk space, you may need to erase some
  395.     unneeded documentation:
  396.  
  397. rm -f ChangeLog*
  398. rm -f gcc.info*
  399. rm -f cpp.info*
  400. rm -f texinfo.tex gcc.ps
  401.  
  402. * Configure the gcc-2.6.2
  403.  
  404.     If you have an i386:
  405.  
  406. ./configure --with-elf i386-linux
  407.  
  408.     for a 486:
  409.  
  410. ./configure --with-elf i486-linux
  411.  
  412. * Edit Makefile
  413.     
  414. vi Makefile
  415.  
  416.     at line 154 you should find:
  417.  
  418. prefix = /usr/local
  419.  
  420.     change it to:
  421.  
  422. prefix = /usr/i486-linuxelf
  423.  
  424.     at line 159 you should find:
  425.  
  426. local_prefix = /usr/local
  427.  
  428.     change it to:
  429.  
  430. local_prefix = /usr/i486-linuxelf
  431.  
  432.     to reflect the installation path we have chosen.
  433.  
  434. * Configuring gcc package to use the ELF assembler/linker in libgcc2.a
  435.   compilation
  436.  
  437. ln -s /usr/i486-linuxelf/bin/as .
  438. ln -s /usr/i486-linuxelf/bin/ld .
  439.  
  440.     with this two links, we enable the xgcc (the gcc just compiled) to
  441.     make use of the ELF assembler/linker.
  442.  
  443. 5.2 Compiling gcc-2.6.2
  444.  
  445.     do
  446.  
  447. make LANGUAGES=c CC=gcc CFLAGS="-O2 -m486 -fomit-frame-pointer -N"
  448.  
  449.     Note: change the CFLAGS as needed (for example i have compiled gcc with
  450.           -O3 maximum optimization flag set).
  451.     Note1: enquire.c will not compile because we do not still have a C library.
  452.     Note3: it is not important the optimization flag because this is only the
  453.            first stage of compilation. In the near future we will re-compile
  454.            the gcc.
  455.            (see 7.)
  456.     Note4: you should read the INSTALL file of gcc
  457.  
  458.     Now have a long tea-time break with a friend (better if of the opposite sex)
  459.     talking about something of interesting ;)
  460.  
  461. 5.3 Installing gcc-2.6.2
  462.  
  463. * Install the binaries
  464.  
  465.     do
  466.  
  467. make install LANGUAGES=c
  468.  
  469. * Link the cpp to the ELF installation
  470.  
  471.     We need to link it because /usr/i486-linuxelf/bin is not in
  472.     our search PATH
  473.  
  474. ln -s /usr/i486-linuxelf/lib/gcc-lib/i486-linux/2.6.2/cpp /usr/i486-linuxelf/bin
  475.  
  476. * Copy float.h from your gcc jump-table installation to the ELF one
  477.  
  478.     enquire could not be compiled, so float.h is a zero lenght file, but we can
  479.     get it from the jump-table installation of gcc:
  480.  
  481. cp /usr/lib/gcc-lib/i486-linux/2.6.2/include/float.h /usr/i486-linuxelf/lib/gcc-lib/i486-linux/2.6.2/include/
  482.  
  483. * Build some shell scripts to use the gcc-elf in a smoother way
  484.  
  485. vi /usr/bin/gcc-elf
  486.  
  487. [start]
  488. #! /bin/sh
  489.  
  490. /usr/i486-linuxelf/bin/gcc -L/usr/i486-linuxelf/lib -B/usr/i486-linuxelf/bin/ $*
  491. [end]
  492.  
  493. vi /usr/bin/as-elf
  494.  
  495. [start]
  496. #! /bin/sh
  497.  
  498. /usr/i486-linuxelf/bin/as $*
  499. [end]
  500.  
  501. vi /usr/bin/ld-elf
  502.  
  503. [start]
  504. #!/bin/sh
  505.  
  506. /usr/i486-linuxelf/bin/ld $*
  507. [end]
  508.  
  509. chmod 755 /usr/bin/*-elf
  510.  
  511. * Set up the compiler specs to run with ELF enviroenment
  512.  
  513. cd /usr/i486-linuxelf/lib/gcc-lib/i486-linux/2.6.2
  514.  
  515. vi specs
  516.  
  517.     in the section *startfile (startup code), at line 26 you should find:
  518.  
  519. %{pg:gcrt0.o%s} %{!pg:%{p:gcrt0.o%s} %{!p:crt0.o%s}} %{static:-static}
  520.  
  521.     change it to:
  522.  
  523. %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}} %{!never:crti.o%s crtn.o%s} %{static:-static}
  524.  
  525.     Note: this change tells the compiler to link the crt1+crti+crtn that are the
  526.           startup code of ELF executables. When gcc-elf is invoked with -pg or
  527.           -p option, it links gcrt1.o instead of crt1.o
  528.  
  529.     The format of %{a:b} statements is:
  530.  
  531.     if (a is true) {
  532.         do b;
  533.     }
  534.  
  535.     Note1: b can be another %{a:b} statement
  536.  
  537.     in section *predefines (always 'defined' by gcc), at line 35 you should find
  538.  
  539. -Dunix -Di386 -Dlinux -Asystem(unix) -Asystem(posix) -Acpu(i386) -Amachine(i386)
  540.  
  541.     change it to:
  542.  
  543. -D__ELF__ -Dunix -Di386 -Dlinux -Asystem(unix) -Asystem(posix) -Acpu(i386) -Amachine(i386)
  544.  
  545.     Note2: you MUST define the -D__ELF__ because THIS gcc (gcc-elf) is an ELF
  546.            compiler so we need to use the ELF specific code contained in
  547.            /usr/include/... files
  548.  
  549.     and it is done.
  550.  
  551.     Now if you are short of disk space you may want to
  552.  
  553. cd /usr/src
  554. rm -rf gcc-2.6.2
  555.  
  556. 5.4 Try it now!
  557.  
  558.     Just to be sure all the things are okay until now:
  559.     
  560.     check your gcc installation with 'gcc-elf -v', then try to compile
  561.     something:
  562.  
  563. cd /tmp
  564.  
  565.     edit a file called p.c
  566.  
  567. vi p.c
  568.  
  569. [start]
  570. main()
  571. {
  572. printf("prova\n");
  573. }
  574. [end]
  575.     
  576.     'prova' means just 'test' in italian language :)
  577.     then compile it to the object file (only to object because we still have not
  578.     the C library)
  579.  
  580. gcc-elf -v -c p.c
  581.  
  582.     You should be able to see that gcc-elf invoke all the /usr/i486-linuxelf
  583.     stuff.
  584.  
  585.     Now to check the kind of file gcc-elf have built, do
  586.  
  587. file p.o
  588.  
  589.     and it should say that p.o is an
  590.  
  591. ELF 32-bit LSB relocatable i386 (386 and up) Version 1
  592.  
  593.     Of course you must have the ELF definition in /etc/magic file.
  594.     If gcc-elf builds ELF objects, we are on the right way!
  595.  
  596. 6.  Building libc-4.6.27
  597.  
  598.     Now we have the ELF compiler/assembler/linker. We need an ELF
  599.     C library. This step will build the libc-4.6.27 in
  600.     static/shared/debug/profile versions.
  601.  
  602.  
  603. 6.1 Preparing libc-4.6.27 for compilation
  604.  
  605. * Unpacking the archive
  606.  
  607. cd /usr/src
  608. tar xfvz libc-4.6.27.tar.gz
  609. cd libc-linux
  610.  
  611. * Configuring the libc-4.6.27
  612.  
  613. ./configure
  614.  
  615. Values correct (y/n) [y] ? n
  616. Build 386, 486 or m68k library code (486 default) 4/3/m [4] ?
  617. The target platform [i486-linux] ?
  618. The target OS [linux] ?
  619. Build targets (static/shared default) s/a [a] ?
  620. Root path to i486-linux related files [/usr] ?
  621. Bin path to gcc [/usr/bin] ? 
  622. The gcc version [2.6.2] ?
  623. Fast build/save space (fast default) f/s [f] ?
  624. GNU `make' executable [make] ?
  625. Root path to installation dirs [/] ?
  626. Build a NYS libc from nys* (y default)  y/n [n] ?
  627. Values correct (y/n) [y] ?
  628.  
  629.     Note: all the above configuration parameters are defaults but you
  630.           MUST do the ./configure to reset the config.in
  631.  
  632. * Edit Makeconfig
  633.  
  634. vi Makeconfig
  635.  
  636.     at line 368 you should find:
  637.  
  638. PIC_OPT_CFLAGS= -fPIC -O1 -funroll-loops -fomit-frame-pointer
  639.  
  640.     change it to:
  641.  
  642. PIC_OPT_CFLAGS= -fPIC -D__PIC__ -O1 -funroll-loops -fomit-frame-pointer
  643.  
  644.     we need to define __PIC__ because the syscall?() macros are different
  645.     for PIC and !PIC code.
  646.  
  647.     at line 327 you should find:
  648.  
  649. REALCC  =gcc-elf -V $(GCCVERSION) -b $(TARGET_MACHINE) \
  650.  
  651.     change it to:
  652.  
  653. REALCC  =gcc-elf \
  654.  
  655.     we do not need the -V -b switches because gcc-elf should use the right
  656.     binaries and -V -b confuses the compiler.
  657.  
  658. * Edit elf/Makefile
  659.  
  660. vi elf/Makefile
  661.  
  662.     at line 29 you can find:
  663.  
  664. if [ "1" = "1" ]; then \
  665.  
  666.     change it to:
  667.  
  668. if [ "0" = "1" ]; then \
  669.  
  670.     to make use of the linker directly and not through gcc-elf, because
  671.     sadly gcc-elf do not support the -shared switch.
  672.  
  673. * Edit elf/d-link/libdl/Makefile
  674.  
  675. vi elf/d-link/libdl/Makefile
  676.  
  677.     at line 29 you should find:
  678.  
  679. ELF_LDFLAGS=--shared -nostdlib # using GNU ld
  680.  
  681.     change it to:
  682.  
  683. ELF_LDFLAGS=-Wl,-shared -nostdlib # using GNU ld
  684.  
  685.     to pass the -shared switch directly to the linker, see above.
  686.  
  687. * Edit elf/d-link/readelflib1.c
  688.  
  689.     This is important because the ld-linux.so (ELF shlib loader)
  690.     must know that the standard ELF shlib path is /lib/elf/ and not /lib/
  691.  
  692.     At line 122 you should find:
  693.  
  694. pnt1 = "/lib/";
  695.  
  696.     change it to:
  697.  
  698. pnt1 = "/lib/elf/";
  699.  
  700. * Edit sysdeps/linux/i386/gmon/gmon.c
  701.  
  702.     This change is needed if you want to use the profile option with gcc-2.6.2
  703.     (see the Note at 5.)
  704.  
  705.     Note1: if you upgrade the gcc (say to gcc-2.6.3) you have to check if this
  706.            new gcc is able to handle ELF profiling code.
  707.            You can do it this way:
  708.            
  709. vi p.c
  710.  
  711. [start]
  712. main()
  713. {
  714. printf("Prova\n");
  715. }
  716. [end]
  717.  
  718.            Now compile it this way:
  719.  
  720. gcc-elf -p -S p.c
  721.  
  722.            gcc generate a p.s (assembly)
  723.  
  724.     * Edit p.s
  725.  
  726. vi p.s
  727.  
  728.            at some time in the assembly listing you should find:
  729.  
  730. call _mcount
  731.  
  732.            or
  733.  
  734. call mcount
  735.  
  736.            in the first case your gcc is buggy so you should apply the next
  737.            patch to gmon.c, in the second case, gcc is okay so don't apply
  738.            the next patch
  739.  
  740.     at line 50 you should find:
  741.  
  742. extern void mcount(); /* asm ("mcount"); */
  743.  
  744.     change it to:
  745.  
  746. extern void _mcount(); /* asm ("_mcount"); */
  747.  
  748.     at line 221 you should find:
  749.  
  750. mcount()
  751.  
  752.     change it to:
  753.  
  754. _mcount()
  755.  
  756. 6.2 Compiling libc-4.6.27
  757.  
  758.     Now it is time to compile the libc-4.6.27.
  759.     My suggestion is to launch the compilation and then go to sleep
  760.     or something like that because it takes LOT of time ( and if you have
  761.     better things to do other than sleep, your time is not lost doing such
  762.     nice things :)
  763.  
  764.     do
  765.  
  766. nohup make ELF=true &
  767.  
  768.     (for those who use the zsh now they should do a 'disown %1')
  769.  
  770.     now you can logout/exit/ctrl-d
  771.  
  772.     Note: the nohup is important because it log all the compilation in
  773.           a file called nohup.out
  774.           At the end of compilation, before going to the next step,
  775.           you must check the nohup.out (~ 1.5 Mbytes) for errors. Do
  776.  
  777. grep Error nohup.out
  778.  
  779.           it should print out nothing. If any error is encountered,
  780.           investigate and try to correct it.
  781.  
  782. 6.3 Installing libc-4.6.27
  783.  
  784.     To install the ELF libraries do
  785.  
  786. make install.elf
  787.  
  788.     and it is done!
  789.  
  790.     Now you can delete the libc-linux
  791.  
  792. cd /usr/src
  793. rm -rf libc-linux
  794.  
  795. 6.4 Try the Whole Thing!
  796.     
  797. cd /tmp
  798.  
  799.     edit a file called p.c
  800.  
  801. vi p.c
  802.  
  803. [start]
  804. main()
  805. {
  806. printf("prova\n");
  807. }
  808. [end]
  809.  
  810.     now try to compile the file to use the shared ELF library:
  811.  
  812. gcc-elf -O -v p.c -o p
  813.  
  814.     'file p' should say:
  815.  
  816. p: ELF 32-bit LSB executable i386 (386 and up) Version 1
  817.  
  818.     run './p' and you should see the output 'prova'
  819.  
  820.     repeat the above operations to check the static/debug/profile with
  821.     these command lines:
  822.  
  823. gcc-elf -static -O -v p.c -o p
  824. gcc-elf -g -v p.c -o p
  825. gcc-elf -p -v p.c -o p
  826. gcc-elf -pg -v p.c -o p
  827.  
  828.     launch the './p' for every compilation to check that p is right.
  829.  
  830.     If you cannot see the output 'prova', you have failed something:
  831.     make sure you have executed all the passes described in this HOWTO
  832.     and if you find some error, please let me know.
  833.  
  834.     If this last test is Passed, you have succeeded installing the
  835.     bootstrap ELF dev. sys.
  836.  
  837. 7.  Recompiling the Whole Thing: Stage 2
  838.  
  839.     Now you MUST go on recompiling the Whole Thing to be sure all is okay.
  840.     The recompilation is not only the way to have ELF binaries, it is a
  841.     way to test the reliability of the binaries we have just compiled.
  842.     Think this as the Stage 2 (a la gcc stage2). I do not think a stage3
  843.     will be useful, but if you like you can do the stage 3 too :)
  844.     (e.g. Stage 3 compiled files should be the same as Stage 2, given the
  845.     compilation flags)
  846.  
  847.     Mainly you have to repeat the 4.* 5.* 6.*, with a little difference:
  848.     in the Stage 2 you will use the gcc-elf!
  849.  
  850. 7.1 Recompiling binutils-2.5.2.6
  851.  
  852.     Follow the 4.1
  853.  
  854.     Now you must change the gcc with gcc-elf in Makefile
  855.  
  856. * Edit Makefile
  857.  
  858. vi Makefile
  859.  
  860.     at line 72 you should find:
  861.  
  862. CC = cc
  863.  
  864.     change it to:
  865.  
  866. CC = gcc-elf
  867.  
  868.     Now follow the 4.2 and 4.3
  869.  
  870.     You are done with binutils-2.5.2.6
  871.  
  872. 7.2 Recompiling gcc-2.6.2
  873.  
  874.     Follow the 5.1 for configuration.
  875.  
  876.     Now compile the compiler stage1, do:
  877.  
  878. make LANGUAGES=c CC=gcc-elf CFLAGS="-O2 -m486 -fomit-frame-pointer -N"
  879.  
  880.     Be warned: all the things related
  881.     to enquire.c and float.h are still valid!! We have now the ELF C lib
  882.     but enquire will compile and link the right way only if we copy the
  883.     installed gcc-elf specs file in gcc source directory (xgcc must know where
  884.     to find crt and libc), so you have wait until the gcc compilation is
  885.     finished, then you will cp the correct specs:
  886.  
  887. cp /usr/i486-linuxelf/lib/gcc-lib/i486-linux/2.6.2/specs .
  888.  
  889.     then remove enquire (an invalid file):
  890.  
  891. rm ./enquire
  892.  
  893.     then re-compile with the same command line as the first compilation, and
  894.     it will finish the compilation: do the above for all compilation stages,
  895.     after every build.
  896.  
  897.     now make stage2 and stage3 of the compiler to build g++ and obj-c.
  898.  
  899.     Here the commands:
  900.  
  901.         *** First compilation (stage1) ***
  902.  
  903. ln -s /usr/i486-linuxelf/bin/as .
  904. ln -s /usr/i486-linuxelf/bin/ld .
  905. make LANGUAGES=c CC=gcc-elf CFLAGS="-O2 -m486 -fomit-frame-pointer -N"
  906. cp /usr/i486-linuxelf/lib/gcc-lib/i486-linux/2.6.2/specs .
  907. rm ./enquire
  908. make LANGUAGES=c CC=gcc-elf CFLAGS="-O2 -m486 -fomit-frame-pointer -N"
  909.  
  910.         *** Second compilation (stage2) ***
  911.  
  912. make stage1
  913. ln -s /usr/i486-linuxelf/bin/as stage1/as
  914. ln -s /usr/i486-linuxelf/bin/ld stage1/ld
  915. make LANGUAGES=c CC="stage1/xgcc -Bstage1/" CFLAGS="-O2 -m486 -fomit-frame-pointer -N"
  916. cp /usr/i486-linuxelf/lib/gcc-lib/i486-linux/2.6.2/specs .
  917. rm ./enquire
  918. make LANGUAGES=c CC="stage1/xgcc -Bstage1/" CFLAGS="-O2 -m486 -fomit-frame-pointer -N"
  919.  
  920.         *** Third compilation (stage3) ***
  921.  
  922. make stage2
  923. ln -s /usr/i486-linuxelf/bin/as stage2/as
  924. ln -s /usr/i486-linuxelf/bin/ld stage2/ld
  925. make CC="stage2/xgcc -Bstage2/" CFLAGS="-O2 -m486 -fomit-frame-pointer -N"
  926. cp /usr/i486-linuxelf/lib/gcc-lib/i486-linux/2.6.2/specs .
  927. rm ./enquire
  928. make CC="stage2/xgcc -Bstage2/" CFLAGS="-O2 -m486 -fomit-frame-pointer -N"
  929.  
  930.     Now compare the objects of stage2 and stage3: they MUST be equal!!!!
  931.  
  932. for file in *.o
  933. do
  934. echo $file
  935. cmp $file stage2/$file
  936. done
  937.  
  938.     Now for installation do
  939.  
  940. make install
  941.  
  942.     Make sure /usr/i486-linuxelf/lib/gcc-lib/i486-linux/2.6.2/specs
  943.     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  944.     is correct.
  945.     ^^^^^^^^^^^
  946.  
  947. 7.3 Recompiling libc-4.6.27
  948.  
  949.     Follow 6.1, 6.2 and 6.3
  950.  
  951. 8.  Patch binutils-2.5.2 ==> binutils-2.5.2.6
  952.  
  953.     Note: you can apply this patch by simply 'patch -p0 < this-file'
  954.  
  955. H.J. Lu
  956. hjl@nynexst.com
  957. 12/16/94
  958.  
  959. This patch contains some necessary bug fixes for binutils 2.5.2 to
  960. support ELF. It is called 2.5.2.6 by me. The fixes may not be the same 
  961. as the ones in the next public release of binutils.
  962.  
  963. H.J.
  964. 12/14/94
  965. ---
  966. *** ./binutils/Makefile.in.orig    Tue Nov 29 11:03:51 1994
  967. --- ./binutils/Makefile.in    Wed Dec 14 11:42:03 1994
  968. ***************
  969. *** 70,76 ****
  970.   LEX = `if [ -f ../flex/flex ] ; then echo ../flex/flex ; else echo flex ; fi`
  971.   
  972.   # Distribution version
  973. ! VERSION=2.5.2
  974.   # Distribution name
  975.   DIST_NAME=binutils-${VERSION}
  976.   
  977. --- 70,76 ----
  978.   LEX = `if [ -f ../flex/flex ] ; then echo ../flex/flex ; else echo flex ; fi`
  979.   
  980.   # Distribution version
  981. ! VERSION=2.5.2.6
  982.   # Distribution name
  983.   DIST_NAME=binutils-${VERSION}
  984.   
  985. *** ./config/mh-linux.orig    Mon Nov 28 19:55:59 1994
  986. --- ./config/mh-linux    Mon Nov 28 19:56:07 1994
  987. ***************
  988. *** 2,8 ****
  989.   # FIXME: What is this used for?  It should go away (and even if it hasn't,
  990.   # it's not clear linux should define it).
  991.   SYSV = -DSYSV
  992. ! RANLIB = ranlib
  993.   
  994.   # What is this doing here?
  995.   #LDFLAGS = -static
  996. --- 2,8 ----
  997.   # FIXME: What is this used for?  It should go away (and even if it hasn't,
  998.   # it's not clear linux should define it).
  999.   SYSV = -DSYSV
  1000. ! #RANLIB = ranlib
  1001.   
  1002.   # What is this doing here?
  1003.   #LDFLAGS = -static
  1004. *** ./bfd/config/i386linux.mh.orig    Mon Nov 28 19:55:18 1994
  1005. --- ./bfd/config/i386linux.mh    Mon Nov 28 19:55:27 1994
  1006. ***************
  1007. *** 1,4 ****
  1008.   HDEFINES=-DTRAD_CORE
  1009.   HDEPFILES=trad-core.o
  1010.   # Apparently this is needed to build objdump in certain configurations.
  1011. ! EXTRALIBS=-lm
  1012. --- 1,4 ----
  1013.   HDEFINES=-DTRAD_CORE
  1014.   HDEPFILES=trad-core.o
  1015.   # Apparently this is needed to build objdump in certain configurations.
  1016. ! #EXTRALIBS=-lm
  1017. *** ./bfd/bfd-in.h.orig    Mon Sep 26 11:01:57 1994
  1018. --- ./bfd/bfd-in.h    Fri Nov 11 14:30:17 1994
  1019. ***************
  1020. *** 545,555 ****
  1021.   extern boolean bfd_elf64_record_link_assignment
  1022.     PARAMS ((bfd *, struct bfd_link_info *, const char *));
  1023.   extern boolean bfd_elf32_size_dynamic_sections
  1024. !   PARAMS ((bfd *, const char *, const char *, struct bfd_link_info *,
  1025. !        struct sec **));
  1026.   extern boolean bfd_elf64_size_dynamic_sections
  1027. !   PARAMS ((bfd *, const char *, const char *, struct bfd_link_info *,
  1028. !        struct sec **));
  1029.   extern void bfd_elf_set_dt_needed_name PARAMS ((bfd *, const char *));
  1030.   
  1031.   /* SunOS shared library support routines for the linker.  */
  1032. --- 545,555 ----
  1033.   extern boolean bfd_elf64_record_link_assignment
  1034.     PARAMS ((bfd *, struct bfd_link_info *, const char *));
  1035.   extern boolean bfd_elf32_size_dynamic_sections
  1036. !   PARAMS ((bfd *, const char *, const char *, boolean,
  1037. !        struct bfd_link_info *, struct sec **));
  1038.   extern boolean bfd_elf64_size_dynamic_sections
  1039. !   PARAMS ((bfd *, const char *, const char *, boolean,
  1040. !        struct bfd_link_info *, struct sec **));
  1041.   extern void bfd_elf_set_dt_needed_name PARAMS ((bfd *, const char *));
  1042.   
  1043.   /* SunOS shared library support routines for the linker.  */
  1044. *** ./bfd/bfd-in2.h.orig    Fri Oct 21 21:27:50 1994
  1045. --- ./bfd/bfd-in2.h    Fri Nov 11 14:30:17 1994
  1046. ***************
  1047. *** 545,555 ****
  1048.   extern boolean bfd_elf64_record_link_assignment
  1049.     PARAMS ((bfd *, struct bfd_link_info *, const char *));
  1050.   extern boolean bfd_elf32_size_dynamic_sections
  1051. !   PARAMS ((bfd *, const char *, const char *, struct bfd_link_info *,
  1052. !        struct sec **));
  1053.   extern boolean bfd_elf64_size_dynamic_sections
  1054. !   PARAMS ((bfd *, const char *, const char *, struct bfd_link_info *,
  1055. !        struct sec **));
  1056.   extern void bfd_elf_set_dt_needed_name PARAMS ((bfd *, const char *));
  1057.   
  1058.   /* SunOS shared library support routines for the linker.  */
  1059. --- 545,555 ----
  1060.   extern boolean bfd_elf64_record_link_assignment
  1061.     PARAMS ((bfd *, struct bfd_link_info *, const char *));
  1062.   extern boolean bfd_elf32_size_dynamic_sections
  1063. !   PARAMS ((bfd *, const char *, const char *, boolean,
  1064. !        struct bfd_link_info *, struct sec **));
  1065.   extern boolean bfd_elf64_size_dynamic_sections
  1066. !   PARAMS ((bfd *, const char *, const char *, boolean,
  1067. !        struct bfd_link_info *, struct sec **));
  1068.   extern void bfd_elf_set_dt_needed_name PARAMS ((bfd *, const char *));
  1069.   
  1070.   /* SunOS shared library support routines for the linker.  */
  1071. *** ./bfd/elfcode.h.orig    Tue Nov  1 17:59:53 1994
  1072. --- ./bfd/elfcode.h    Sat Dec 10 14:09:19 1994
  1073. ***************
  1074. *** 1845,1851 ****
  1075. --- 1845,1858 ----
  1076.         if (phdr->p_type != PT_NULL
  1077.         && (hdr->sh_offset - (phdr->p_offset + phdr->p_memsz)
  1078.             == hdr->sh_addr - (phdr->p_vaddr + phdr->p_memsz))
  1079. + #if 0
  1080. +       /* FIXME: ctors/dtors contain the code, but are r/w. */
  1081. +       && (last_type != SHT_NOBITS || hdr->sh_type == SHT_NOBITS)
  1082. +       && (((hdr->sh_flags & SHF_WRITE) == 0 && (phdr->p_flags & PF_W) == 0)
  1083. +           || ((hdr->sh_flags & SHF_WRITE) != 0 && (phdr->p_flags & PF_W) != 0)))
  1084. + #else
  1085.         && (last_type != SHT_NOBITS || hdr->sh_type == SHT_NOBITS))
  1086. + #endif
  1087.       {
  1088.         bfd_size_type adjust;
  1089.   
  1090. ***************
  1091. *** 3744,3749 ****
  1092. --- 3751,3758 ----
  1093.     PARAMS ((bfd *, struct bfd_link_info *));
  1094.   static Elf_Internal_Rela *elf_link_read_relocs
  1095.     PARAMS ((bfd *, asection *, PTR, Elf_Internal_Rela *, boolean));
  1096. + static boolean elf_export_symbol
  1097. +   PARAMS ((struct elf_link_hash_entry *, PTR));
  1098.   static boolean elf_adjust_dynamic_symbol
  1099.     PARAMS ((struct elf_link_hash_entry *, PTR));
  1100.   
  1101. ***************
  1102. *** 4863,4873 ****
  1103.      addresses of the various sections.  */
  1104.   
  1105.   boolean
  1106. ! NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath, info,
  1107. !                      sinterpptr)
  1108.        bfd *output_bfd;
  1109.        const char *soname;
  1110.        const char *rpath;
  1111.        struct bfd_link_info *info;
  1112.        asection **sinterpptr;
  1113.   {
  1114. --- 4872,4883 ----
  1115.      addresses of the various sections.  */
  1116.   
  1117.   boolean
  1118. ! NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
  1119. !                      export_dynamic, info, sinterpptr)
  1120.        bfd *output_bfd;
  1121.        const char *soname;
  1122.        const char *rpath;
  1123. +      boolean export_dynamic;
  1124.        struct bfd_link_info *info;
  1125.        asection **sinterpptr;
  1126.   {
  1127. ***************
  1128. *** 4887,4892 ****
  1129. --- 4897,4908 ----
  1130.     if (dynobj == NULL)
  1131.       return true;
  1132.   
  1133. +   /* If we are supposed to export all symbols into the dynamic symbol
  1134. +      table (this is not the normal case), then do so.  */
  1135. +   if (export_dynamic)
  1136. +     elf_link_hash_traverse (elf_hash_table (info), elf_export_symbol,
  1137. +                 (PTR) info);
  1138.     if (elf_hash_table (info)->dynamic_sections_created)
  1139.       {
  1140.         *sinterpptr = bfd_get_section_by_name (dynobj, ".interp");
  1141. ***************
  1142. *** 5019,5024 ****
  1143. --- 5035,5064 ----
  1144.     return true;
  1145.   }
  1146.   
  1147. + /* This routine is used to export all defined symbols into the dynamic
  1148. +    symbol table.  It is called via elf_link_hash_traverse.  */
  1149. + static boolean
  1150. + elf_export_symbol (h, data)
  1151. +      struct elf_link_hash_entry *h;
  1152. +      PTR data;
  1153. + {
  1154. +   struct bfd_link_info *info = (struct bfd_link_info *) data;
  1155. +   if (h->dynindx == -1
  1156. +       && (h->elf_link_hash_flags & (ELF_LINK_HASH_DEF_REGULAR
  1157. +     | ELF_LINK_HASH_REF_REGULAR)) != 0)
  1158. +     {
  1159. +       if (! elf_link_record_dynamic_symbol (info, h))
  1160. +     {
  1161. +       /* FIXME: No way to report error.  */
  1162. +       abort ();
  1163. +     }
  1164. +     }
  1165. +   return true;
  1166. + }
  1167.   /* Make the backend pick a good value for a dynamic symbol.  This is
  1168.      called via elf_link_hash_traverse, and also calls itself
  1169.      recursively.  */
  1170. ***************
  1171. *** 5202,5207 ****
  1172. --- 5242,5248 ----
  1173.   
  1174.     dynamic = elf_hash_table (info)->dynamic_sections_created;
  1175.     dynobj = elf_hash_table (info)->dynobj;
  1176. +   BFD_ASSERT (dynamic ? dynobj != 0 : dynobj == 0);    /* FIXME */
  1177.   
  1178.     finfo.info = info;
  1179.     finfo.output_bfd = abfd;
  1180. ***************
  1181. *** 5895,5900 ****
  1182. --- 5936,5955 ----
  1183.       strip = true;
  1184.     else
  1185.       strip = false;
  1186. +   /*
  1187. +    * If we are not creating a shared library, complain about any symbols which
  1188. +    * are undefined.  If we do not do this, the linker will not complain about
  1189. +    * unresolved references within shared libraries, and the application might
  1190. +    * die at runtime.  Only warn about symbols that are referenced in shared libraries
  1191. +    * and not in regular .o files - the rest have been warned about already.
  1192. +    */
  1193. +   if (!finfo->info->shared && 
  1194. +       !(h->elf_link_hash_flags & (ELF_LINK_HASH_DEF_REGULAR | ELF_LINK_HASH_DEF_DYNAMIC))
  1195. +       && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | ELF_LINK_HASH_REF_DYNAMIC)) 
  1196. +       ==  ELF_LINK_HASH_REF_DYNAMIC)
  1197. +     (*finfo->info->callbacks->undefined_symbol)
  1198. +       (finfo, h->root.root.string, h->root.u.undef.abfd, bfd_und_section_ptr, 0);
  1199.   
  1200.     /* If we're stripping it, and it's not a dynamic symbol, there's
  1201.        nothing else to do.  */
  1202. *** ./bfd/elf32-i386.c.orig    Fri Nov  4 10:35:44 1994
  1203. --- ./bfd/elf32-i386.c    Wed Dec 14 09:26:08 1994
  1204. ***************
  1205. *** 1035,1043 ****
  1206.         if (h->root.type == bfd_link_hash_defined)
  1207.           {
  1208.             sec = h->root.u.def.section;
  1209. !           relocation = (h->root.u.def.value
  1210. !                 + sec->output_section->vma
  1211. !                 + sec->output_offset);
  1212.           }
  1213.         else if (h->root.type == bfd_link_hash_weak)
  1214.           relocation = 0;
  1215. --- 1035,1059 ----
  1216.         if (h->root.type == bfd_link_hash_defined)
  1217.           {
  1218.             sec = h->root.u.def.section;
  1219. !           if (r_type == R_386_GOTPC
  1220. !           || (r_type == R_386_PLT32
  1221. !               && h->plt_offset != (bfd_vma) -1)
  1222. !           || (r_type == R_386_GOT32
  1223. !               && elf_hash_table (info)->dynamic_sections_created)
  1224. !           || (info->shared
  1225. !               && (r_type == R_386_32
  1226. !               || r_type == R_386_PC32)
  1227. !               && (input_section->flags & SEC_ALLOC) != 0))
  1228. !         {
  1229. !           /* In these cases, we don't need the relocation
  1230. !                      value.  We check specially because in some
  1231. !                      obscure cases sec->output_section will be NULL.  */
  1232. !           relocation = 0;
  1233. !         }
  1234. !           else
  1235. !         relocation = (h->root.u.def.value
  1236. !                   + sec->output_section->vma
  1237. !                   + sec->output_offset);
  1238.           }
  1239.         else if (h->root.type == bfd_link_hash_weak)
  1240.           relocation = 0;
  1241. *** ./bfd/i386linux.c.orig    Mon Aug 22 11:00:32 1994
  1242. --- ./bfd/i386linux.c    Tue Nov 29 02:12:59 1994
  1243. ***************
  1244. *** 91,96 ****
  1245. --- 91,102 ----
  1246.   #define    PLT_REF_PREFIX    "__PLT_"
  1247.   #endif
  1248.   
  1249. + /* Used to generate specialized error messages */
  1250. + #ifndef NEEDS_SHRLIB
  1251. + #define NEEDS_SHRLIB "__NEEDS_SHRLIB_"
  1252. + #endif
  1253.   #define IS_PLT_SYM(name) \
  1254.     (strncmp (name, PLT_REF_PREFIX, sizeof PLT_REF_PREFIX - 1) == 0)
  1255.   
  1256. ***************
  1257. *** 416,423 ****
  1258. --- 422,453 ----
  1259.     struct bfd_link_info *info = (struct bfd_link_info *) data;
  1260.     struct fixup *f, *f1;
  1261.     int is_plt;
  1262. +   char * missing_filename, *cpnt;
  1263.     struct linux_link_hash_entry *h1, *h2;
  1264.     boolean exists;
  1265. +   if (h->root.root.type == bfd_link_hash_undefined &&
  1266. +       strncmp(h->root.root.root.string, NEEDS_SHRLIB, strlen(NEEDS_SHRLIB)) == 0)
  1267. +     {
  1268. +       missing_filename = strdup(h->root.root.root.string + strlen(NEEDS_SHRLIB));
  1269. +       cpnt = strrchr(missing_filename, '_');
  1270. +       if (cpnt)
  1271. +     {
  1272. +       *cpnt = 0;
  1273. +       fprintf (stderr,
  1274. +         "ld: Output file requires shared library `%s.so.%s'\n",
  1275. +         missing_filename, cpnt + 1);
  1276. +         }
  1277. +       else
  1278. +     {
  1279. +       fprintf (stderr,
  1280. +         "ld: Output file requires shared library `%s'\n",
  1281. +         missing_filename);
  1282. +     }
  1283. +       free(missing_filename);
  1284. +       abort ();
  1285. +     } 
  1286.   
  1287.     /* If this symbol is not a PLT/GOT, we do not even need to look at it */
  1288.     is_plt = IS_PLT_SYM (h->root.root.root.string);
  1289. *** ./gas/config/tc-i386.c.orig    Fri Oct 21 21:42:53 1994
  1290. --- ./gas/config/tc-i386.c    Sun Dec  4 18:15:00 1994
  1291. ***************
  1292. *** 1691,1699 ****
  1293.               insn_size += size;
  1294.   #ifdef BFD_ASSEMBLER
  1295.               if (r_type == BFD_RELOC_32
  1296. -                 && i.imms[n]->X_op == O_symbol
  1297.                   && GOT_symbol
  1298. !                 && GOT_symbol == i.imms[n]->X_add_symbol)
  1299.                 {
  1300.                   r_type = BFD_RELOC_386_GOTPC;
  1301.                   i.imms[n]->X_add_number += 3;
  1302. --- 1691,1701 ----
  1303.               insn_size += size;
  1304.   #ifdef BFD_ASSEMBLER
  1305.               if (r_type == BFD_RELOC_32
  1306.                   && GOT_symbol
  1307. !                 && GOT_symbol == i.imms[n]->X_add_symbol
  1308. !                 && (i.imms[n]->X_op == O_symbol
  1309. !                 || (i.imms[n]->X_op == O_add
  1310. !                 && i.imms[n]->X_add_symbol -> sy_value.X_op == O_constant)))
  1311.                 {
  1312.                   r_type = BFD_RELOC_386_GOTPC;
  1313.                   i.imms[n]->X_add_number += 3;
  1314. ***************
  1315. *** 2420,2435 ****
  1316.     if (fixP->fx_r_type == BFD_RELOC_32_PCREL && fixP->fx_addsy)
  1317.       {
  1318.         value += fixP->fx_where + fixP->fx_frag->fr_address;
  1319. - #ifdef OBJ_ELF
  1320. -       if (S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
  1321. -     {
  1322. -       /* Yes, we add the values in twice.  This is because
  1323. -          bfd_perform_relocation subtracts them out again.  I think
  1324. -          bfd_perform_relocation is broken, but I don't dare change
  1325. -          it.  FIXME.  */
  1326. -       value += fixP->fx_where + fixP->fx_frag->fr_address;
  1327. -     }
  1328. - #endif
  1329.       }
  1330.   
  1331.     /* Fix a few things - the dynamic linker expects certain values here,
  1332. --- 2422,2427 ----
  1333. *** ./gas/Makefile.in.orig    Tue Nov 29 11:03:26 1994
  1334. --- ./gas/Makefile.in    Wed Dec 14 11:42:10 1994
  1335. ***************
  1336. *** 53,59 ****
  1337.   includedir = $(prefix)/include
  1338.   docdir = $(datadir)/doc
  1339.   
  1340. ! VERSION=2.5.2
  1341.   
  1342.   SHELL = /bin/sh
  1343.   
  1344. --- 53,59 ----
  1345.   includedir = $(prefix)/include
  1346.   docdir = $(datadir)/doc
  1347.   
  1348. ! VERSION=2.5.2.6
  1349.   
  1350.   SHELL = /bin/sh
  1351.   
  1352. *** ./gas/write.c.orig    Mon Oct 17 22:12:25 1994
  1353. --- ./gas/write.c    Fri Nov 11 14:22:41 1994
  1354. ***************
  1355. *** 2271,2276 ****
  1356. --- 2271,2290 ----
  1357.           }
  1358.       }
  1359.   
  1360. + #ifdef OBJ_ELF
  1361. +       if (fixP->fx_r_type == BFD_RELOC_32_PCREL && fixP->fx_addsy)
  1362. +     {
  1363. +       if (S_GET_SEGMENT (fixP->fx_addsy) == this_segment_type)
  1364. +         {
  1365. +           /* Yes, we add the values in twice.  This is because
  1366. +          bfd_perform_relocation subtracts them out again.  I think
  1367. +          bfd_perform_relocation is broken, but I don't dare change
  1368. +          it.  FIXME.  */
  1369. +           add_number += fixP->fx_where + fixP->fx_frag->fr_address;
  1370. +         }
  1371. +     }
  1372. + #endif
  1373.         if (!fixP->fx_bit_fixP && size > 0)
  1374.       {
  1375.         valueT mask = 0;
  1376. *** ./libiberty/basename.c.orig    Thu Dec  8 15:15:18 1994
  1377. --- ./libiberty/basename.c    Thu Dec  8 15:16:11 1994
  1378. ***************
  1379. *** 44,50 ****
  1380.   
  1381.   char *
  1382.   basename (name)
  1383. !   char *name;
  1384.   {
  1385.     char *base = name;
  1386.   
  1387. --- 44,50 ----
  1388.   
  1389.   char *
  1390.   basename (name)
  1391. !   const char *name;
  1392.   {
  1393.     char *base = name;
  1394.   
  1395. *** ./ld/ldver.c.orig    Tue Nov 29 15:37:17 1994
  1396. --- ./ld/ldver.c    Wed Dec 14 11:42:39 1994
  1397. ***************
  1398. *** 29,35 ****
  1399.   ldversion (noisy)
  1400.        int noisy;
  1401.   {
  1402. !   fprintf(stdout,"ld version 2.5.2 (with BFD %s)\n", BFD_VERSION);
  1403.   
  1404.     if (noisy) 
  1405.     {
  1406. --- 29,35 ----
  1407.   ldversion (noisy)
  1408.        int noisy;
  1409.   {
  1410. !   fprintf(stdout,"ld version 2.5.2.6 (with BFD %s)\n", BFD_VERSION);
  1411.   
  1412.     if (noisy) 
  1413.     {
  1414. *** ./ld/emultempl/elf32.em.orig    Tue Sep 27 20:07:51 1994
  1415. --- ./ld/emultempl/elf32.em    Sat Nov 12 16:53:49 1994
  1416. ***************
  1417. *** 125,130 ****
  1418. --- 125,131 ----
  1419.     if (! bfd_elf32_size_dynamic_sections (output_bfd,
  1420.                        command_line.soname,
  1421.                        command_line.rpath,
  1422. +                      command_line.export_dynamic,
  1423.                        &link_info,
  1424.                        &sinterp))
  1425.       einfo ("%P%F: failed to set dynamic section sizes: %E\n");
  1426. ***************
  1427. *** 206,215 ****
  1428.        asection *s;
  1429.   {
  1430.     lang_output_section_statement_type *place;
  1431. !   asection *snew, **pps;
  1432.     lang_statement_list_type *old;
  1433.     lang_statement_list_type add;
  1434.     etree_type *address;
  1435.     const char *secname, *ps;
  1436.     lang_output_section_statement_type *os;
  1437.   
  1438. --- 207,217 ----
  1439.        asection *s;
  1440.   {
  1441.     lang_output_section_statement_type *place;
  1442. !   asection *snew, **pps, *sec;
  1443.     lang_statement_list_type *old;
  1444.     lang_statement_list_type add;
  1445.     etree_type *address;
  1446. +   int has_dynamic;
  1447.     const char *secname, *ps;
  1448.     lang_output_section_statement_type *os;
  1449.   
  1450. ***************
  1451. *** 244,249 ****
  1452. --- 246,264 ----
  1453.       return false;
  1454.   
  1455.     secname = bfd_get_section_name (s->owner, s);
  1456. +   /* In dynamic images, we cannot have orphaned relocation sections.
  1457. +      The .dynamic section will be all wrong, so for now we simply assert
  1458. +      this to be the case. The fix is simple - you need to add the relevant
  1459. +      relocation sections to the linker script so that they get bunched
  1460. +      with the other relocation sections.  The .rel.plt must be the last
  1461. +      one always, or you get screwed up for other reasons. */
  1462. +   has_dynamic = 0;
  1463. +   for (sec = output_bfd->sections; sec ; sec = sec->next)
  1464. +     if(strcmp(sec->name,".dynamic") == 0) has_dynamic = 1;
  1465. +   ASSERT(strncmp(secname,".rel",4) || !has_dynamic);
  1466.   
  1467.     /* Create the section in the output file, and put it in the right
  1468.        place.  This shuffling to make the output file look neater, and
  1469. *** ./ld/scripttempl/elf.sc.orig    Fri Oct 14 19:15:55 1994
  1470. --- ./ld/scripttempl/elf.sc    Sat Dec 10 00:54:19 1994
  1471. ***************
  1472. *** 2,10 ****
  1473.   # Unusual variables checked by this code:
  1474.   #    NOP - two byte opcode for no-op (defaults to 0)
  1475.   #    DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
  1476. ! #    OTHER_READONLY_SECTIONS - other than .text .init .ctors .rodata ...
  1477.   #        (e.g., .PARISC.milli)
  1478. ! #    OTHER_READWRITE_SECTIONS - other than .data .bss .sdata ...
  1479.   #        (e.g., .PARISC.global)
  1480.   #    OTHER_SECTIONS - at the end
  1481.   #    EXECUTABLE_SYMBOLS - symbols that must be defined for an
  1482. --- 2,10 ----
  1483.   # Unusual variables checked by this code:
  1484.   #    NOP - two byte opcode for no-op (defaults to 0)
  1485.   #    DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
  1486. ! #    OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
  1487.   #        (e.g., .PARISC.milli)
  1488. ! #    OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
  1489.   #        (e.g., .PARISC.global)
  1490.   #    OTHER_SECTIONS - at the end
  1491.   #    EXECUTABLE_SYMBOLS - symbols that must be defined for an
  1492. ***************
  1493. *** 20,25 ****
  1494. --- 20,26 ----
  1495.   # When adding sections, do note that the names of some sections are used
  1496.   # when specifying the start address of the next.
  1497.   #
  1498. + test -z "$ENTRY" && ENTRY=_start
  1499.   test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  1500.   test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  1501.   test "$LD_FLAG" = "N" && DATA_ADDR=.
  1502. ***************
  1503. *** 29,34 ****
  1504. --- 30,36 ----
  1505.   OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
  1506.             "${LITTLE_OUTPUT_FORMAT}")
  1507.   OUTPUT_ARCH(${ARCH})
  1508. + ENTRY(${ENTRY})
  1509.   
  1510.   ${RELOCATING+${LIB_SEARCH_DIRS}}
  1511.   ${RELOCATING+/* Do we need any of these for elf?
  1512. ***************
  1513. *** 59,64 ****
  1514. --- 61,70 ----
  1515.     .rela.ctors  ${RELOCATING-0} : { *(.rela.ctors)    }
  1516.     .rel.dtors   ${RELOCATING-0} : { *(.rel.dtors)    }
  1517.     .rela.dtors  ${RELOCATING-0} : { *(.rela.dtors)    }
  1518. +   .rel.init    ${RELOCATING-0} : { *(.rel.init)    }
  1519. +   .rela.init   ${RELOCATING-0} : { *(.rela.init)    }
  1520. +   .rel.fini    ${RELOCATING-0} : { *(.rel.fini)    }
  1521. +   .rela.fini   ${RELOCATING-0} : { *(.rela.fini)    }
  1522.     .rel.bss     ${RELOCATING-0} : { *(.rel.bss)        }
  1523.     .rela.bss    ${RELOCATING-0} : { *(.rela.bss)        }
  1524.     .rel.plt     ${RELOCATING-0} : { *(.rel.plt)        }
  1525. ***************
  1526. *** 68,86 ****
  1527.     .text    ${RELOCATING-0} :
  1528.     {
  1529.       ${RELOCATING+${TEXT_START_SYMBOLS}}
  1530. !     *(.text)
  1531. !   }
  1532.     ${RELOCATING+_etext = .;}
  1533.     ${RELOCATING+PROVIDE (etext = .);}
  1534.     .fini    ${RELOCATING-0} : { *(.fini)    } =${NOP-0}
  1535. -   .ctors   ${RELOCATING-0} : { *(.ctors)   }
  1536. -   .dtors   ${RELOCATING-0} : { *(.dtors)   }
  1537.     .rodata  ${RELOCATING-0} : { *(.rodata)  }
  1538.     .rodata1 ${RELOCATING-0} : { *(.rodata1) }
  1539.     ${RELOCATING+${OTHER_READONLY_SECTIONS}}
  1540.   
  1541.     /* Read-write section, merged into data segment: */
  1542. -   ${RELOCATING+. = ${DATA_ADDR- ALIGN(8) + ${MAXPAGESIZE}};}
  1543.     .data  ${RELOCATING-0} :
  1544.     {
  1545.       ${RELOCATING+${DATA_START_SYMBOLS}}
  1546. --- 74,94 ----
  1547.     .text    ${RELOCATING-0} :
  1548.     {
  1549.       ${RELOCATING+${TEXT_START_SYMBOLS}}
  1550. !     *(.text) 
  1551. !   } = ${NOP-0}
  1552.     ${RELOCATING+_etext = .;}
  1553.     ${RELOCATING+PROVIDE (etext = .);}
  1554.     .fini    ${RELOCATING-0} : { *(.fini)    } =${NOP-0}
  1555.     .rodata  ${RELOCATING-0} : { *(.rodata)  }
  1556.     .rodata1 ${RELOCATING-0} : { *(.rodata1) }
  1557.     ${RELOCATING+${OTHER_READONLY_SECTIONS}}
  1558.   
  1559. +   /* The last page of text may contain the beginning of data
  1560. +    * and the first page of data may contain the end of text.
  1561. +    * We first align to the page boundary. We then add the shift
  1562. +    * due to the extra end of text, but only if necessary. */
  1563. +   ${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + ((ALIGN(8) + ${MAXPAGESIZE} - ALIGN(${MAXPAGESIZE})) & (${MAXPAGESIZE} - 1));}
  1564.     /* Read-write section, merged into data segment: */
  1565.     .data  ${RELOCATING-0} :
  1566.     {
  1567.       ${RELOCATING+${DATA_START_SYMBOLS}}
  1568. ***************
  1569. *** 88,93 ****
  1570. --- 96,103 ----
  1571.       ${CONSTRUCTING+CONSTRUCTORS}
  1572.     }
  1573.     .data1 ${RELOCATING-0} : { *(.data1) }
  1574. +   .ctors ${RELOCATING-0} : { *(.ctors) }
  1575. +   .dtors ${RELOCATING-0} : { *(.dtors) }
  1576.     ${RELOCATING+${OTHER_READWRITE_SECTIONS}}
  1577.     .got         ${RELOCATING-0} : { *(.got.plt) *(.got) }
  1578.     .dynamic     ${RELOCATING-0} : { *(.dynamic) }
  1579. *** ./ld/ld.h.orig    Tue Sep 20 17:15:53 1994
  1580. --- ./ld/ld.h    Fri Nov 11 14:30:37 1994
  1581. ***************
  1582. *** 61,66 ****
  1583. --- 61,70 ----
  1584.   
  1585.     /* Big or little endian as set on command line.  */
  1586.     enum { ENDIAN_UNSET = 0, ENDIAN_BIG, ENDIAN_LITTLE } endian;
  1587. +   /* If true, export all symbols in the dynamic symbol table of an ELF
  1588. +      executable.  */
  1589. +   boolean export_dynamic;
  1590.   } args_type;
  1591.   
  1592.   extern args_type command_line;
  1593. *** ./ld/lexsup.c.orig    Wed Oct 12 16:26:42 1994
  1594. --- ./ld/lexsup.c    Sat Dec  3 09:49:23 1994
  1595. ***************
  1596. *** 68,74 ****
  1597.   #define OPTION_DYNAMIC_LINKER        (OPTION_DEFSYM + 1)
  1598.   #define OPTION_EB            (OPTION_DYNAMIC_LINKER + 1)
  1599.   #define OPTION_EL            (OPTION_EB + 1)
  1600. ! #define OPTION_HELP            (OPTION_EL + 1)
  1601.   #define OPTION_IGNORE            (OPTION_HELP + 1)
  1602.   #define OPTION_MAP            (OPTION_IGNORE + 1)
  1603.   #define OPTION_NO_KEEP_MEMORY        (OPTION_MAP + 1)
  1604. --- 68,75 ----
  1605.   #define OPTION_DYNAMIC_LINKER        (OPTION_DEFSYM + 1)
  1606.   #define OPTION_EB            (OPTION_DYNAMIC_LINKER + 1)
  1607.   #define OPTION_EL            (OPTION_EB + 1)
  1608. ! #define OPTION_EXPORT_DYNAMIC        (OPTION_EL + 1)
  1609. ! #define OPTION_HELP            (OPTION_EXPORT_DYNAMIC + 1)
  1610.   #define OPTION_IGNORE            (OPTION_HELP + 1)
  1611.   #define OPTION_MAP            (OPTION_IGNORE + 1)
  1612.   #define OPTION_NO_KEEP_MEMORY        (OPTION_MAP + 1)
  1613. ***************
  1614. *** 106,111 ****
  1615. --- 107,113 ----
  1616.       {"EB", no_argument, NULL, OPTION_EB},
  1617.       {"EL", no_argument, NULL, OPTION_EL},
  1618.       {"end-group", no_argument, NULL, ')'},
  1619. +     {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
  1620.       {"format", required_argument, NULL, 'b'},
  1621.       {"help", no_argument, NULL, OPTION_HELP},
  1622.       {"Map", required_argument, NULL, OPTION_MAP},
  1623. ***************
  1624. *** 205,210 ****
  1625. --- 207,215 ----
  1626.       case OPTION_EL:
  1627.         command_line.endian = ENDIAN_LITTLE;
  1628.         break;
  1629. +     case OPTION_EXPORT_DYNAMIC:
  1630. +       command_line.export_dynamic = true;
  1631. +       break;
  1632.       case 'e':
  1633.         lang_add_entry (optarg, 1);
  1634.         break;
  1635. ***************
  1636. *** 373,380 ****
  1637.         trace_file_tries = true;
  1638.         break;
  1639.       case 'v':
  1640. -     case 'V':
  1641.         ldversion (0);
  1642.         version_printed = true;
  1643.         break;
  1644.       case OPTION_VERSION:
  1645. --- 378,388 ----
  1646.         trace_file_tries = true;
  1647.         break;
  1648.       case 'v':
  1649.         ldversion (0);
  1650. +       version_printed = true;
  1651. +       break;
  1652. +     case 'V':
  1653. +       ldversion (1);
  1654.         version_printed = true;
  1655.         break;
  1656.       case OPTION_VERSION:
  1657. *** ./ld/ldlang.c.orig    Tue Sep 20 17:15:58 1994
  1658. --- ./ld/ldlang.c    Sat Nov 12 12:15:38 1994
  1659. ***************
  1660. *** 2106,2112 ****
  1661.   lang_finish ()
  1662.   {
  1663.     struct bfd_link_hash_entry *h;
  1664. !   boolean warn = link_info.relocateable ? false : true;
  1665.   
  1666.     if (entry_symbol == (char *) NULL)
  1667.       {
  1668. --- 2106,2112 ----
  1669.   lang_finish ()
  1670.   {
  1671.     struct bfd_link_hash_entry *h;
  1672. !   boolean warn = (link_info.relocateable || link_info.shared) ? false : true;
  1673.   
  1674.     if (entry_symbol == (char *) NULL)
  1675.       {
  1676. *** ./include/libiberty.h.orig    Wed Aug 10 16:19:49 1994
  1677. --- ./include/libiberty.h    Thu Dec  8 15:18:00 1994
  1678. ***************
  1679. *** 23,29 ****
  1680.   
  1681.   /* Return the last component of a path name.  */
  1682.   
  1683. ! extern char *basename PARAMS ((char *));
  1684.   
  1685.   /* Concatenate an arbitrary number of strings, up to (char *) NULL.
  1686.      Allocates memory using xmalloc.  */
  1687. --- 23,29 ----
  1688.   
  1689.   /* Return the last component of a path name.  */
  1690.   
  1691. ! extern char *basename PARAMS ((const char *));
  1692.   
  1693.   /* Concatenate an arbitrary number of strings, up to (char *) NULL.
  1694.      Allocates memory using xmalloc.  */
  1695.  
  1696.