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