home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / bfd / m68klinux.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  22KB  |  768 lines

  1. /* BFD back-end for linux flavored m68k a.out binaries.
  2.    Copyright (C) 1992, 93, 94, 95, 1996 Free Software Foundation, Inc.
  3.  
  4. This file is part of BFD, the Binary File Descriptor library.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  19.  
  20. #define    TARGET_PAGE_SIZE 4096
  21. #define ZMAGIC_DISK_BLOCK_SIZE 1024
  22. #define    SEGMENT_SIZE TARGET_PAGE_SIZE
  23. #define TEXT_START_ADDR    0x0
  24. #define N_SHARED_LIB(x) 0
  25. #define BYTES_IN_WORD 4
  26.  
  27. #include "bfd.h"
  28. #include "sysdep.h"
  29. #include "libbfd.h"
  30. #include "aout/aout64.h"
  31. #include "aout/stab_gnu.h"
  32. #include "aout/ar.h"
  33. #include "libaout.h"           /* BFD a.out internal data structures */
  34.  
  35. #define TARGET_IS_BIG_ENDIAN_P
  36. #define DEFAULT_ARCH bfd_arch_m68k
  37. #define MY(OP) CAT(m68klinux_,OP)
  38. #define TARGETNAME "a.out-m68k-linux"
  39.  
  40. extern const bfd_target MY(vec);
  41.  
  42. /* We always generate QMAGIC files in preference to ZMAGIC files.  It
  43.    would be possible to make this a linker option, if that ever
  44.    becomes important.  */
  45.  
  46. static void MY_final_link_callback
  47.   PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
  48.  
  49. static boolean
  50. m68klinux_bfd_final_link (abfd, info)
  51.      bfd *abfd;
  52.      struct bfd_link_info *info;
  53. {
  54.   obj_aout_subformat (abfd) = q_magic_format;
  55.   return NAME(aout,final_link) (abfd, info, MY_final_link_callback);
  56. }
  57.  
  58. #define MY_bfd_final_link m68klinux_bfd_final_link
  59.  
  60. /* Set the machine type correctly.  */
  61.  
  62. static boolean
  63. m68klinux_write_object_contents (abfd)
  64.      bfd *abfd;
  65. {
  66.   struct external_exec exec_bytes;
  67.   struct internal_exec *execp = exec_hdr (abfd);
  68.  
  69.   N_SET_MACHTYPE (*execp, M_68020);
  70.  
  71.   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
  72.  
  73.   WRITE_HEADERS(abfd, execp);
  74.  
  75.   return true;
  76. }
  77.  
  78. #define MY_write_object_contents m68klinux_write_object_contents
  79.  
  80. /* Code to link against Linux a.out shared libraries.  */
  81.  
  82. /* See if a symbol name is a reference to the global offset table.  */
  83.  
  84. #ifndef GOT_REF_PREFIX
  85. #define    GOT_REF_PREFIX    "__GOT_"
  86. #endif
  87.  
  88. #define IS_GOT_SYM(name) \
  89.   (strncmp (name, GOT_REF_PREFIX, sizeof GOT_REF_PREFIX - 1) == 0)
  90.  
  91. /* See if a symbol name is a reference to the procedure linkage table.  */
  92.  
  93. #ifndef PLT_REF_PREFIX
  94. #define    PLT_REF_PREFIX    "__PLT_"
  95. #endif
  96.  
  97. #define IS_PLT_SYM(name) \
  98.   (strncmp (name, PLT_REF_PREFIX, sizeof PLT_REF_PREFIX - 1) == 0)
  99.  
  100. /* This string is used to generate specialized error messages.  */
  101.  
  102. #ifndef NEEDS_SHRLIB
  103. #define NEEDS_SHRLIB "__NEEDS_SHRLIB_"
  104. #endif
  105.  
  106. /* This special symbol is a set vector that contains a list of
  107.    pointers to fixup tables.  It will be present in any dynamicly
  108.    linked file.  The linker generated fixup table should also be added
  109.    to the list, and it should always appear in the second slot (the
  110.    first one is a dummy with a magic number that is defined in
  111.    crt0.o).  */
  112.  
  113. #ifndef SHARABLE_CONFLICTS
  114. #define SHARABLE_CONFLICTS "__SHARABLE_CONFLICTS__"
  115. #endif
  116.  
  117. /* We keep a list of fixups.  The terminology is a bit strange, but
  118.    each fixup contains two 32 bit numbers.  A regular fixup contains
  119.    an address and a pointer, and at runtime we should store the
  120.    address at the location pointed to by the pointer.  A builtin fixup
  121.    contains two pointers, and we should read the address using one
  122.    pointer and store it at the location pointed to by the other
  123.    pointer.  Builtin fixups come into play when we have duplicate
  124.    __GOT__ symbols for the same variable.  The builtin fixup will copy
  125.    the GOT pointer from one over into the other.  */
  126.  
  127. struct fixup
  128. {
  129.   struct fixup *next;
  130.   struct linux_link_hash_entry *h;
  131.   bfd_vma value;
  132.  
  133.   /* Nonzero if this is a jump instruction that needs to be fixed,
  134.      zero if this is just a pointer */
  135.   char jump;
  136.  
  137.   char builtin;
  138. };
  139.  
  140. /* We don't need a special hash table entry structure, but we do need
  141.    to keep some information between linker passes, so we use a special
  142.    hash table.  */
  143.  
  144. struct linux_link_hash_entry
  145. {
  146.   struct aout_link_hash_entry root;
  147. };
  148.  
  149. struct linux_link_hash_table
  150. {
  151.   struct aout_link_hash_table root;
  152.  
  153.   /* First dynamic object found in link.  */
  154.   bfd *dynobj;
  155.  
  156.   /* Number of fixups.  */
  157.   size_t fixup_count;
  158.  
  159.   /* Number of builtin fixups.  */
  160.   size_t local_builtins;
  161.  
  162.   /* List of fixups.  */
  163.   struct fixup *fixup_list;
  164. };
  165.  
  166. static struct bfd_hash_entry *linux_link_hash_newfunc
  167.   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
  168. static struct bfd_link_hash_table *linux_link_hash_table_create
  169.   PARAMS ((bfd *));
  170. static struct fixup *new_fixup
  171.   PARAMS ((struct bfd_link_info *, struct linux_link_hash_entry *,
  172.        bfd_vma, int));
  173. static boolean linux_link_create_dynamic_sections
  174.   PARAMS ((bfd *, struct bfd_link_info *));
  175. static boolean linux_add_one_symbol
  176.   PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,
  177.        bfd_vma, const char *, boolean, boolean,
  178.        struct bfd_link_hash_entry **));
  179. static boolean linux_tally_symbols
  180.   PARAMS ((struct linux_link_hash_entry *, PTR));
  181. static boolean linux_finish_dynamic_link
  182.   PARAMS ((bfd *, struct bfd_link_info *));
  183.  
  184. /* Routine to create an entry in an Linux link hash table.  */
  185.  
  186. static struct bfd_hash_entry *
  187. linux_link_hash_newfunc (entry, table, string)
  188.      struct bfd_hash_entry *entry;
  189.      struct bfd_hash_table *table;
  190.      const char *string;
  191. {
  192.   struct linux_link_hash_entry *ret = (struct linux_link_hash_entry *) entry;
  193.  
  194.   /* Allocate the structure if it has not already been allocated by a
  195.      subclass.  */
  196.   if (ret == (struct linux_link_hash_entry *) NULL)
  197.     ret = ((struct linux_link_hash_entry *)
  198.        bfd_hash_allocate (table, sizeof (struct linux_link_hash_entry)));
  199.   if (ret == NULL)
  200.     return (struct bfd_hash_entry *) ret;
  201.  
  202.   /* Call the allocation method of the superclass.  */
  203.   ret = ((struct linux_link_hash_entry *)
  204.      NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret,
  205.                        table, string));
  206.   if (ret != NULL)
  207.     {
  208.       /* Set local fields; there aren't any.  */
  209.     }
  210.  
  211.   return (struct bfd_hash_entry *) ret;
  212. }
  213.  
  214. /* Create a Linux link hash table.  */
  215.  
  216. static struct bfd_link_hash_table *
  217. linux_link_hash_table_create (abfd)
  218.      bfd *abfd;
  219. {
  220.   struct linux_link_hash_table *ret;
  221.  
  222.   ret = ((struct linux_link_hash_table *)
  223.      bfd_alloc (abfd, sizeof (struct linux_link_hash_table)));
  224.   if (ret == (struct linux_link_hash_table *) NULL)
  225.     {
  226.       bfd_set_error (bfd_error_no_memory);
  227.       return (struct bfd_link_hash_table *) NULL;
  228.     }
  229.   if (! NAME(aout,link_hash_table_init) (&ret->root, abfd,
  230.                      linux_link_hash_newfunc))
  231.     {
  232.       free (ret);
  233.       return (struct bfd_link_hash_table *) NULL;
  234.     }
  235.  
  236.   ret->dynobj = NULL;
  237.   ret->fixup_count = 0;
  238.   ret->local_builtins = 0;
  239.   ret->fixup_list = NULL;
  240.  
  241.   return &ret->root.root;
  242. }
  243.  
  244. /* Look up an entry in a Linux link hash table.  */
  245.  
  246. #define linux_link_hash_lookup(table, string, create, copy, follow) \
  247.   ((struct linux_link_hash_entry *) \
  248.    aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
  249.               (follow)))
  250.  
  251. /* Traverse a Linux link hash table.  */
  252.  
  253. #define linux_link_hash_traverse(table, func, info)            \
  254.   (aout_link_hash_traverse                        \
  255.    (&(table)->root,                            \
  256.     (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func),    \
  257.     (info)))
  258.  
  259. /* Get the Linux link hash table from the info structure.  This is
  260.    just a cast.  */
  261.  
  262. #define linux_hash_table(p) ((struct linux_link_hash_table *) ((p)->hash))
  263.  
  264. /* Store the information for a new fixup.  */
  265.  
  266. static struct fixup *
  267. new_fixup (info, h, value, builtin)
  268.      struct bfd_link_info *info;
  269.      struct linux_link_hash_entry *h;
  270.      bfd_vma value;
  271.      int builtin;
  272. {
  273.   struct fixup *f;
  274.  
  275.   f = (struct fixup *) bfd_hash_allocate (&info->hash->table,
  276.                       sizeof (struct fixup));
  277.   if (f == NULL)
  278.     return f;
  279.   f->next = linux_hash_table (info)->fixup_list;
  280.   linux_hash_table (info)->fixup_list = f;
  281.   f->h = h;
  282.   f->value = value;
  283.   f->builtin = builtin;
  284.   f->jump = 0;
  285.   ++linux_hash_table (info)->fixup_count;
  286.   return f;
  287. }
  288.  
  289. /* We come here once we realize that we are going to link to a shared
  290.    library.  We need to create a special section that contains the
  291.    fixup table, and we ultimately need to add a pointer to this into
  292.    the set vector for SHARABLE_CONFLICTS.  At this point we do not
  293.    know the size of the section, but that's OK - we just need to
  294.    create it for now.  */
  295.  
  296. static boolean
  297. linux_link_create_dynamic_sections (abfd, info)
  298.      bfd *abfd;
  299.      struct bfd_link_info *info;
  300. {
  301.   flagword flags;
  302.   register asection *s;
  303.  
  304.   /* Note that we set the SEC_IN_MEMORY flag.  */
  305.   flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
  306.  
  307.   /* We choose to use the name ".linux-dynamic" for the fixup table.
  308.      Why not? */
  309.   s = bfd_make_section (abfd, ".linux-dynamic");
  310.   if (s == NULL
  311.       || ! bfd_set_section_flags (abfd, s, flags)
  312.       || ! bfd_set_section_alignment (abfd, s, 2))
  313.     return false;
  314.   s->_raw_size = 0;
  315.   s->contents = 0;
  316.  
  317.   return true;
  318. }
  319.  
  320. /* Function to add a single symbol to the linker hash table.  This is
  321.    a wrapper around _bfd_generic_link_add_one_symbol which handles the
  322.    tweaking needed for dynamic linking support.  */
  323.  
  324. static boolean
  325. linux_add_one_symbol (info, abfd, name, flags, section, value, string,
  326.               copy, collect, hashp)
  327.      struct bfd_link_info *info;
  328.      bfd *abfd;
  329.      const char *name;
  330.      flagword flags;
  331.      asection *section;
  332.      bfd_vma value;
  333.      const char *string;
  334.      boolean copy;
  335.      boolean collect;
  336.      struct bfd_link_hash_entry **hashp;
  337. {
  338.   struct linux_link_hash_entry *h;
  339.   boolean insert;
  340.  
  341.   /* Look up and see if we already have this symbol in the hash table.
  342.      If we do, and the defining entry is from a shared library, we
  343.      need to create the dynamic sections.
  344.  
  345.      FIXME: What if abfd->xvec != info->hash->creator?  We may want to
  346.      be able to link Linux a.out and ELF objects together, but serious
  347.      confusion is possible.  */
  348.  
  349.   insert = false;
  350.  
  351.   if (! info->relocateable
  352.       && linux_hash_table (info)->dynobj == NULL
  353.       && strcmp (name, SHARABLE_CONFLICTS) == 0
  354.       && (flags & BSF_CONSTRUCTOR) != 0
  355.       && abfd->xvec == info->hash->creator)
  356.     {
  357.       if (! linux_link_create_dynamic_sections (abfd, info))
  358.     return false;
  359.       linux_hash_table (info)->dynobj = abfd;
  360.       insert = true;
  361.     }
  362.  
  363.   if (bfd_is_abs_section (section)
  364.       && abfd->xvec == info->hash->creator)
  365.     {
  366.       h = linux_link_hash_lookup (linux_hash_table (info), name, false,
  367.                   false, false);
  368.       if (h != NULL
  369.       && (h->root.root.type == bfd_link_hash_defined
  370.           || h->root.root.type == bfd_link_hash_defweak))
  371.     {
  372.       struct fixup *f;
  373.  
  374.       if (hashp != NULL)
  375.         *hashp = (struct bfd_link_hash_entry *) h;
  376.  
  377.       f = new_fixup (info, h, value, ! IS_PLT_SYM (name));
  378.       if (f == NULL)
  379.         return false;
  380.       f->jump = IS_PLT_SYM (name);
  381.  
  382.       return true;
  383.     }
  384.     }
  385.  
  386.   /* Do the usual procedure for adding a symbol.  */
  387.   if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
  388.                       value, string, copy, collect,
  389.                       hashp))
  390.     return false;
  391.  
  392.   /* Insert a pointer to our table in the set vector.  The dynamic
  393.      linker requires this information */
  394.   if (insert)
  395.     {
  396.       asection *s;
  397.  
  398.       /* Here we do our special thing to add the pointer to the
  399.      dynamic section in the SHARABLE_CONFLICTS set vector.  */
  400.       s = bfd_get_section_by_name (linux_hash_table (info)->dynobj,
  401.                    ".linux-dynamic");
  402.       BFD_ASSERT (s != NULL);
  403.  
  404.       if (! (_bfd_generic_link_add_one_symbol
  405.          (info, linux_hash_table (info)->dynobj, SHARABLE_CONFLICTS,
  406.           BSF_GLOBAL | BSF_CONSTRUCTOR, s, 0, NULL, false, false, NULL)))
  407.     return false;
  408.     }
  409.  
  410.   return true;
  411. }
  412.  
  413. /* We will crawl the hash table and come here for every global symbol.
  414.    We will examine each entry and see if there are indications that we
  415.    need to add a fixup.  There are two possible cases - one is where
  416.    you have duplicate definitions of PLT or GOT symbols - these will
  417.    have already been caught and added as "builtin" fixups.  If we find
  418.    that the corresponding non PLT/GOT symbol is also present, we
  419.    convert it to a regular fixup instead.
  420.  
  421.    This function is called via linux_link_hash_traverse.  */
  422.  
  423. static boolean
  424. linux_tally_symbols (h, data)
  425.      struct linux_link_hash_entry *h;
  426.      PTR data;
  427. {
  428.   struct bfd_link_info *info = (struct bfd_link_info *) data;
  429.   struct fixup *f, *f1;
  430.   int is_plt;
  431.   struct linux_link_hash_entry *h1, *h2;
  432.   boolean exists;
  433.  
  434.   if (h->root.root.type == bfd_link_hash_undefined
  435.       && strncmp (h->root.root.root.string, NEEDS_SHRLIB,
  436.           sizeof NEEDS_SHRLIB - 1) == 0)
  437.     {
  438.       const char *name;
  439.       char *p;
  440.       char *alloc = NULL;
  441.  
  442.       name = h->root.root.root.string + sizeof NEEDS_SHRLIB - 1;
  443.       p = strrchr (name, '_');
  444.       if (p != NULL)
  445.     alloc = (char *) bfd_malloc (strlen (name) + 1);
  446.  
  447.       if (p == NULL || alloc == NULL)
  448.     (*_bfd_error_handler) ("Output file requires shared library `%s'\n",
  449.                    name);
  450.       else
  451.     {
  452.       strcpy (alloc, name);
  453.       p = strrchr (alloc, '_');
  454.       *p++ = '\0';
  455.       (*_bfd_error_handler)
  456.         ("Output file requires shared library `%s.so.%s'\n",
  457.          alloc, p);
  458.       free (alloc);
  459.     }
  460.  
  461.       abort ();
  462.     }
  463.  
  464.   /* If this symbol is not a PLT/GOT, we do not even need to look at it */
  465.   is_plt = IS_PLT_SYM (h->root.root.root.string);
  466.  
  467.   if (is_plt || IS_GOT_SYM (h->root.root.root.string))
  468.     {
  469.       /* Look up this symbol twice.  Once just as a regular lookup,
  470.      and then again following all of the indirect links until we
  471.      reach a real symbol.  */
  472.       h1 = linux_link_hash_lookup (linux_hash_table (info),
  473.                    (h->root.root.root.string
  474.                     + sizeof PLT_REF_PREFIX - 1),
  475.                    false, false, true);
  476.       /* h2 does not follow indirect symbols. */
  477.       h2 = linux_link_hash_lookup (linux_hash_table (info), 
  478.                    (h->root.root.root.string
  479.                     + sizeof PLT_REF_PREFIX - 1),
  480.                    false, false, false);
  481.  
  482.       /* The real symbol must exist but if it is also an ABS symbol,
  483.      there is no need to have a fixup.  This is because they both
  484.      came from the same library.  If on the other hand, we had to
  485.      use an indirect symbol to get to the real symbol, we add the
  486.      fixup anyway, since there are cases where these symbols come
  487.      from different shared libraries */
  488.       if (h1 != NULL
  489.       && (((h1->root.root.type == bfd_link_hash_defined
  490.         || h1->root.root.type == bfd_link_hash_defweak)
  491.            && ! bfd_is_abs_section (h1->root.root.u.def.section))
  492.           || h2->root.root.type == bfd_link_hash_indirect))
  493.     {
  494.       /* See if there is a "builtin" fixup already present
  495.          involving this symbol.  If so, convert it to a regular
  496.          fixup.  In the end, this relaxes some of the requirements
  497.          about the order of performing fixups.  */
  498.       exists = false;
  499.       for (f1 = linux_hash_table (info)->fixup_list;
  500.            f1 != NULL;
  501.            f1 = f1->next)
  502.         {
  503.           if ((f1->h != h && f1->h != h1)
  504.           || (! f1->builtin && ! f1->jump))
  505.         continue;
  506.           if (f1->h == h1)
  507.         exists = true;
  508.           if (! exists
  509.           && bfd_is_abs_section (h->root.root.u.def.section))
  510.         {
  511.           f = new_fixup (info, h1, f1->h->root.root.u.def.value, 0);
  512.           f->jump = is_plt;
  513.         }
  514.           f1->h = h1;
  515.           f1->jump = is_plt;
  516.           f1->builtin = 0;
  517.           exists = true;
  518.         }
  519.       if (! exists
  520.           && bfd_is_abs_section (h->root.root.u.def.section))
  521.         {
  522.           f = new_fixup (info, h1, h->root.root.u.def.value, 0);
  523.           if (f == NULL)
  524.         {
  525.           /* FIXME: No way to return error.  */
  526.           abort ();
  527.         }
  528.           f->jump = is_plt;
  529.         }
  530.     }
  531.  
  532.       /* Quick and dirty way of stripping these symbols from the
  533.      symtab. */
  534.       if (bfd_is_abs_section (h->root.root.u.def.section))
  535.     h->root.written = true;
  536.     }
  537.  
  538.   return true;
  539. }
  540.  
  541. /* This is called to set the size of the .linux-dynamic section is.
  542.    It is called by the Linux linker emulation before_allocation
  543.    routine.  We have finished reading all of the input files, and now
  544.    we just scan the hash tables to find out how many additional fixups
  545.    are required.  */
  546.  
  547. boolean
  548. bfd_m68klinux_size_dynamic_sections (output_bfd, info)
  549.      bfd *output_bfd;
  550.      struct bfd_link_info *info;
  551. {
  552.   struct fixup *f;
  553.   asection *s;
  554.  
  555.   if (output_bfd->xvec != &MY(vec))
  556.     return true;
  557.  
  558.   /* First find the fixups... */
  559.   linux_link_hash_traverse (linux_hash_table (info),
  560.                 linux_tally_symbols,
  561.                 (PTR) info);
  562.  
  563.   /* If there are builtin fixups, leave room for a marker.  This is
  564.      used by the dynamic linker so that it knows that all that follow
  565.      are builtin fixups instead of regular fixups.  */
  566.   for (f = linux_hash_table (info)->fixup_list; f != NULL; f = f->next)
  567.     {
  568.       if (f->builtin)
  569.     {
  570.       ++linux_hash_table (info)->fixup_count;
  571.       ++linux_hash_table (info)->local_builtins;
  572.       break;
  573.     }
  574.     }
  575.  
  576.   if (linux_hash_table (info)->dynobj == NULL)
  577.     {
  578.       if (linux_hash_table (info)->fixup_count > 0)
  579.     abort ();
  580.       return true;
  581.     }
  582.  
  583.   /* Allocate memory for our fixup table.  We will fill it in later.  */
  584.   s = bfd_get_section_by_name (linux_hash_table (info)->dynobj,
  585.                    ".linux-dynamic");
  586.   if (s != NULL)
  587.     {
  588.       s->_raw_size = 8 + linux_hash_table (info)->fixup_count * 8;
  589.       s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
  590.       if (s->contents == NULL)
  591.     {
  592.       bfd_set_error (bfd_error_no_memory);
  593.       return false;
  594.     }
  595.       memset (s->contents, 0, (size_t) s->_raw_size);
  596.     }
  597.  
  598.   return true;
  599. }
  600.  
  601. /* We come here once we are ready to actually write the fixup table to
  602.    the output file.  Scan the fixup tables and so forth and generate
  603.    the stuff we need.  */
  604.  
  605. static boolean
  606. linux_finish_dynamic_link (output_bfd, info)
  607.      bfd *output_bfd;
  608.      struct bfd_link_info *info;
  609. {
  610.   asection *s, *os, *is;
  611.   bfd_byte *fixup_table;
  612.   struct linux_link_hash_entry *h;
  613.   struct fixup *f;
  614.   unsigned int new_addr;
  615.   int section_offset;
  616.   unsigned int fixups_written;
  617.  
  618.   if (linux_hash_table (info)->dynobj == NULL)
  619.     return true;
  620.  
  621.   s = bfd_get_section_by_name (linux_hash_table (info)->dynobj,
  622.                    ".linux-dynamic");
  623.   BFD_ASSERT (s != NULL);
  624.   os = s->output_section;
  625.   fixups_written = 0;
  626.  
  627. #ifdef LINUX_LINK_DEBUG
  628.   printf ("Fixup table file offset: %x  VMA: %x\n", 
  629.       os->filepos + s->output_offset,
  630.       os->vma + s->output_offset);
  631. #endif
  632.  
  633.   fixup_table = s->contents;
  634.   bfd_put_32 (output_bfd, linux_hash_table (info)->fixup_count, fixup_table);
  635.   fixup_table += 4;
  636.  
  637.   /* Fill in fixup table.  */
  638.   for (f = linux_hash_table (info)->fixup_list; f != NULL; f = f->next)
  639.     {
  640.       if (f->builtin)
  641.     continue;
  642.  
  643.       if (f->h->root.root.type != bfd_link_hash_defined
  644.       && f->h->root.root.type != bfd_link_hash_defweak)
  645.     {
  646.       (*_bfd_error_handler)
  647.         ("Symbol %s not defined for fixups\n",
  648.          f->h->root.root.root.string);
  649.       continue;
  650.     }
  651.  
  652.       is = f->h->root.root.u.def.section;
  653.       section_offset = is->output_section->vma + is->output_offset;
  654.       new_addr = f->h->root.root.u.def.value + section_offset;
  655.  
  656. #ifdef LINUX_LINK_DEBUG
  657.       printf ("Fixup(%d) %s: %x %x\n",f->jump, f->h->root.root.string,
  658.           new_addr, f->value);
  659. #endif
  660.  
  661.       if (f->jump)
  662.     {
  663.       bfd_put_32 (output_bfd, new_addr, fixup_table);
  664.       fixup_table += 4;
  665.       bfd_put_32 (output_bfd, f->value + 2, fixup_table);
  666.       fixup_table += 4;
  667.     }
  668.       else
  669.     {
  670.       bfd_put_32 (output_bfd, new_addr, fixup_table);
  671.       fixup_table += 4;
  672.       bfd_put_32 (output_bfd, f->value, fixup_table);
  673.       fixup_table += 4;
  674.     }
  675.       ++fixups_written;
  676.     }
  677.  
  678.   if (linux_hash_table (info)->local_builtins != 0)
  679.     {
  680.       /* Special marker so we know to switch to the other type of fixup */
  681.       bfd_put_32 (output_bfd, 0, fixup_table);
  682.       fixup_table += 4;
  683.       bfd_put_32 (output_bfd, 0, fixup_table);
  684.       fixup_table += 4;
  685.       ++fixups_written;
  686.       for (f = linux_hash_table (info)->fixup_list; f != NULL; f = f->next)
  687.     {
  688.       if (! f->builtin)
  689.         continue;
  690.  
  691.       if (f->h->root.root.type != bfd_link_hash_defined
  692.           && f->h->root.root.type != bfd_link_hash_defweak)
  693.         {
  694.           (*_bfd_error_handler)
  695.         ("Symbol %s not defined for fixups\n",
  696.          f->h->root.root.root.string);
  697.           continue;
  698.         }
  699.  
  700.       is = f->h->root.root.u.def.section;
  701.       section_offset = is->output_section->vma + is->output_offset;
  702.       new_addr = f->h->root.root.u.def.value + section_offset;
  703.  
  704. #ifdef LINUX_LINK_DEBUG
  705.       printf ("Fixup(B) %s: %x %x\n", f->h->root.root.string,
  706.           new_addr, f->value);
  707. #endif
  708.  
  709.       bfd_put_32 (output_bfd, new_addr, fixup_table);
  710.       fixup_table += 4;
  711.       bfd_put_32 (output_bfd, f->value, fixup_table);
  712.       fixup_table += 4;
  713.       ++fixups_written;
  714.     }
  715.   }
  716.  
  717.   if (linux_hash_table (info)->fixup_count != fixups_written)
  718.     {
  719.       (*_bfd_error_handler) ("Warning: fixup count mismatch\n");
  720.       while (linux_hash_table (info)->fixup_count > fixups_written)
  721.     {
  722.       bfd_put_32 (output_bfd, 0, fixup_table);
  723.       fixup_table += 4;
  724.       bfd_put_32 (output_bfd, 0, fixup_table);
  725.       fixup_table += 4;
  726.       ++fixups_written;
  727.     }
  728.     }
  729.  
  730.   h = linux_link_hash_lookup (linux_hash_table (info), 
  731.                   "__BUILTIN_FIXUPS__",
  732.                   false, false, false);
  733.  
  734.   if (h != NULL
  735.       && (h->root.root.type == bfd_link_hash_defined
  736.       || h->root.root.type == bfd_link_hash_defweak))
  737.     {
  738.       is = h->root.root.u.def.section;
  739.       section_offset = is->output_section->vma + is->output_offset;
  740.       new_addr = h->root.root.u.def.value + section_offset;
  741.  
  742. #ifdef LINUX_LINK_DEBUG
  743.       printf ("Builtin fixup table at %x\n", new_addr);
  744. #endif
  745.  
  746.       bfd_put_32 (output_bfd, new_addr, fixup_table);
  747.     }
  748.   else
  749.     bfd_put_32 (output_bfd, 0, fixup_table);
  750.  
  751.   if (bfd_seek (output_bfd, os->filepos + s->output_offset, SEEK_SET) != 0)
  752.     return false;
  753.  
  754.   if (bfd_write ((PTR) s->contents, 1, s->_raw_size, output_bfd)
  755.       != s->_raw_size)
  756.     return false;
  757.  
  758.   return true;
  759. }
  760.  
  761. #define MY_bfd_link_hash_table_create linux_link_hash_table_create
  762. #define MY_add_one_symbol linux_add_one_symbol
  763. #define MY_finish_dynamic_link linux_finish_dynamic_link
  764.  
  765. #define MY_zmagic_contiguous 1
  766.  
  767. #include "aout-target.h"
  768.