Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/i386linux.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for linux flavored i386 a.out binaries.
    2    Copyright 1992, 1993, 1994, 1995, 1996, 1997
     2   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003
    33   Free Software Foundation, Inc.
    44
     
    2424#define TEXT_START_ADDR 0x0
    2525#define N_SHARED_LIB(x) 0
    26 #define BYTES_IN_WORD 4
    2726
    2827#define MACHTYPE_OK(mtype) ((mtype) == M_386 || (mtype) == M_UNKNOWN)
     
    3736
    3837#define DEFAULT_ARCH bfd_arch_i386
    39 #define MY(OP) CAT(i386linux_,OP)
     38
     39/* Do not "beautify" the CONCAT* macro args.  Traditional C will not
     40   remove whitespace added here, and thus will fail to concatenate
     41   the tokens.  */
     42#define MY(OP) CONCAT2 (i386linux_,OP)
    4043#define TARGETNAME "a.out-i386-linux"
    4144
     
    4851static void MY_final_link_callback
    4952  PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
    50 static boolean i386linux_bfd_final_link
     53static bfd_boolean i386linux_bfd_final_link
    5154  PARAMS ((bfd *, struct bfd_link_info *));
    52 static boolean i386linux_write_object_contents PARAMS ((bfd *));
    53 
    54 static boolean
     55static bfd_boolean i386linux_write_object_contents PARAMS ((bfd *));
     56
     57static bfd_boolean
    5558i386linux_bfd_final_link (abfd, info)
    5659     bfd *abfd;
     
    6568/* Set the machine type correctly.  */
    6669
    67 static boolean
     70static bfd_boolean
    6871i386linux_write_object_contents (abfd)
    6972     bfd *abfd;
     
    7881  WRITE_HEADERS(abfd, execp);
    7982
    80   return true;
     83  return TRUE;
    8184}
    8285
     
    177180  PARAMS ((struct bfd_link_info *, struct linux_link_hash_entry *,
    178181           bfd_vma, int));
    179 static boolean linux_link_create_dynamic_sections
     182static bfd_boolean linux_link_create_dynamic_sections
    180183  PARAMS ((bfd *, struct bfd_link_info *));
    181 static boolean linux_add_one_symbol
     184static bfd_boolean linux_add_one_symbol
    182185  PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,
    183            bfd_vma, const char *, boolean, boolean,
     186           bfd_vma, const char *, bfd_boolean, bfd_boolean,
    184187           struct bfd_link_hash_entry **));
    185 static boolean linux_tally_symbols
     188static bfd_boolean linux_tally_symbols
    186189  PARAMS ((struct linux_link_hash_entry *, PTR));
    187 static boolean linux_finish_dynamic_link
     190static bfd_boolean linux_finish_dynamic_link
    188191  PARAMS ((bfd *, struct bfd_link_info *));
    189192
     
    225228{
    226229  struct linux_link_hash_table *ret;
    227 
    228   ret = ((struct linux_link_hash_table *)
    229          bfd_alloc (abfd, sizeof (struct linux_link_hash_table)));
     230  bfd_size_type amt = sizeof (struct linux_link_hash_table);
     231
     232  ret = (struct linux_link_hash_table *) bfd_alloc (abfd, amt);
    230233  if (ret == (struct linux_link_hash_table *) NULL)
    231234    return (struct bfd_link_hash_table *) NULL;
     
    257260  (aout_link_hash_traverse                                              \
    258261   (&(table)->root,                                                     \
    259     (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \
     262    (bfd_boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \
    260263    (info)))
    261264
     
    297300   create it for now.  */
    298301
    299 static boolean
     302static bfd_boolean
    300303linux_link_create_dynamic_sections (abfd, info)
    301304     bfd *abfd;
     
    314317      || ! bfd_set_section_flags (abfd, s, flags)
    315318      || ! bfd_set_section_alignment (abfd, s, 2))
    316     return false;
     319    return FALSE;
    317320  s->_raw_size = 0;
    318321  s->contents = 0;
    319322
    320   return true;
     323  return TRUE;
    321324}
    322325
     
    325328   tweaking needed for dynamic linking support.  */
    326329
    327 static boolean
     330static bfd_boolean
    328331linux_add_one_symbol (info, abfd, name, flags, section, value, string,
    329332                      copy, collect, hashp)
     
    335338     bfd_vma value;
    336339     const char *string;
    337      boolean copy;
    338      boolean collect;
     340     bfd_boolean copy;
     341     bfd_boolean collect;
    339342     struct bfd_link_hash_entry **hashp;
    340343{
    341344  struct linux_link_hash_entry *h;
    342   boolean insert;
     345  bfd_boolean insert;
    343346
    344347  /* Look up and see if we already have this symbol in the hash table.
     
    350353     confusion is possible.  */
    351354
    352   insert = false;
     355  insert = FALSE;
    353356
    354357  if (! info->relocateable
     
    359362    {
    360363      if (! linux_link_create_dynamic_sections (abfd, info))
    361         return false;
     364        return FALSE;
    362365      linux_hash_table (info)->dynobj = abfd;
    363       insert = true;
     366      insert = TRUE;
    364367    }
    365368
     
    367370      && abfd->xvec == info->hash->creator)
    368371    {
    369       h = linux_link_hash_lookup (linux_hash_table (info), name, false,
    370                                   false, false);
     372      h = linux_link_hash_lookup (linux_hash_table (info), name, FALSE,
     373                                  FALSE, FALSE);
    371374      if (h != NULL
    372375          && (h->root.root.type == bfd_link_hash_defined
     
    380383          f = new_fixup (info, h, value, ! IS_PLT_SYM (name));
    381384          if (f == NULL)
    382             return false;
     385            return FALSE;
    383386          f->jump = IS_PLT_SYM (name);
    384387
    385           return true;
     388          return TRUE;
    386389        }
    387390    }
     
    391394                                          value, string, copy, collect,
    392395                                          hashp))
    393     return false;
     396    return FALSE;
    394397
    395398  /* Insert a pointer to our table in the set vector.  The dynamic
     
    407410      if (! (_bfd_generic_link_add_one_symbol
    408411             (info, linux_hash_table (info)->dynobj, SHARABLE_CONFLICTS,
    409               BSF_GLOBAL | BSF_CONSTRUCTOR, s, 0, NULL, false, false, NULL)))
    410         return false;
    411     }
    412 
    413   return true;
     412              BSF_GLOBAL | BSF_CONSTRUCTOR, s, (bfd_vma) 0, NULL,
     413              FALSE, FALSE, NULL)))
     414        return FALSE;
     415    }
     416
     417  return TRUE;
    414418}
    415419
     
    424428   This function is called via linux_link_hash_traverse.  */
    425429
    426 static boolean
     430static bfd_boolean
    427431linux_tally_symbols (h, data)
    428432     struct linux_link_hash_entry *h;
     
    433437  int is_plt;
    434438  struct linux_link_hash_entry *h1, *h2;
    435   boolean exists;
     439  bfd_boolean exists;
     440
     441  if (h->root.root.type == bfd_link_hash_warning)
     442    h = (struct linux_link_hash_entry *) h->root.root.u.i.link;
    436443
    437444  if (h->root.root.type == bfd_link_hash_undefined
     
    446453      p = strrchr (name, '_');
    447454      if (p != NULL)
    448         alloc = (char *) bfd_malloc (strlen (name) + 1);
     455        alloc = (char *) bfd_malloc ((bfd_size_type) strlen (name) + 1);
    449456
    450457      if (p == NULL || alloc == NULL)
     
    476483                                   (h->root.root.root.string
    477484                                    + sizeof PLT_REF_PREFIX - 1),
    478                                    false, false, true);
     485                                   FALSE, FALSE, TRUE);
    479486      /* h2 does not follow indirect symbols. */
    480       h2 = linux_link_hash_lookup (linux_hash_table (info), 
     487      h2 = linux_link_hash_lookup (linux_hash_table (info),
    481488                                   (h->root.root.root.string
    482489                                    + sizeof PLT_REF_PREFIX - 1),
    483                                    false, false, false);
     490                                   FALSE, FALSE, FALSE);
    484491
    485492      /* The real symbol must exist but if it is also an ABS symbol,
     
    499506             fixup.  In the end, this relaxes some of the requirements
    500507             about the order of performing fixups.  */
    501           exists = false;
     508          exists = FALSE;
    502509          for (f1 = linux_hash_table (info)->fixup_list;
    503510               f1 != NULL;
     
    508515                continue;
    509516              if (f1->h == h1)
    510                 exists = true;
     517                exists = TRUE;
    511518              if (! exists
    512519                  && bfd_is_abs_section (h->root.root.u.def.section))
     
    518525              f1->jump = is_plt;
    519526              f1->builtin = 0;
    520               exists = true;
     527              exists = TRUE;
    521528            }
    522529          if (! exists
     
    536543         symtab. */
    537544      if (bfd_is_abs_section (h->root.root.u.def.section))
    538         h->root.written = true;
    539     }
    540 
    541   return true;
     545        h->root.written = TRUE;
     546    }
     547
     548  return TRUE;
    542549}
    543550
     
    548555   are required.  */
    549556
    550 boolean
     557bfd_boolean
    551558bfd_i386linux_size_dynamic_sections (output_bfd, info)
    552559     bfd *output_bfd;
     
    557564
    558565  if (output_bfd->xvec != &MY(vec))
    559     return true;
     566    return TRUE;
    560567
    561568  /* First find the fixups... */
     
    581588      if (linux_hash_table (info)->fixup_count > 0)
    582589        abort ();
    583       return true;
     590      return TRUE;
    584591    }
    585592
     
    589596  if (s != NULL)
    590597    {
    591       s->_raw_size = 8 + linux_hash_table (info)->fixup_count * 8;
    592       s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
     598      s->_raw_size = linux_hash_table (info)->fixup_count + 1;
     599      s->_raw_size *= 8;
     600      s->contents = (bfd_byte *) bfd_zalloc (output_bfd, s->_raw_size);
    593601      if (s->contents == NULL)
    594         return false;
    595       memset (s->contents, 0, (size_t) s->_raw_size);
    596     }
    597 
    598   return true;
     602        return FALSE;
     603    }
     604
     605  return TRUE;
    599606}
    600607
     
    603610   the stuff we need.  */
    604611
    605 static boolean
     612static bfd_boolean
    606613linux_finish_dynamic_link (output_bfd, info)
    607614     bfd *output_bfd;
     
    617624
    618625  if (linux_hash_table (info)->dynobj == NULL)
    619     return true;
     626    return TRUE;
    620627
    621628  s = bfd_get_section_by_name (linux_hash_table (info)->dynobj,
     
    626633
    627634#ifdef LINUX_LINK_DEBUG
    628   printf ("Fixup table file offset: %x  VMA: %x\n", 
     635  printf ("Fixup table file offset: %x  VMA: %x\n",
    629636          os->filepos + s->output_offset,
    630637          os->vma + s->output_offset);
     
    632639
    633640  fixup_table = s->contents;
    634   bfd_put_32 (output_bfd, linux_hash_table (info)->fixup_count, fixup_table);
     641  bfd_put_32 (output_bfd,
     642              (bfd_vma) linux_hash_table (info)->fixup_count, fixup_table);
    635643  fixup_table += 4;
    636644
     
    662670        {
    663671          /* Relative address */
    664           new_addr = new_addr - (f->value + 5); 
    665           bfd_put_32 (output_bfd, new_addr, fixup_table);
     672          new_addr = new_addr - (f->value + 5);
     673          bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table);
    666674          fixup_table += 4;
    667675          bfd_put_32 (output_bfd, f->value + 1, fixup_table);
     
    670678      else
    671679        {
    672           bfd_put_32 (output_bfd, new_addr, fixup_table);
     680          bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table);
    673681          fixup_table += 4;
    674682          bfd_put_32 (output_bfd, f->value, fixup_table);
     
    681689    {
    682690      /* Special marker so we know to switch to the other type of fixup */
    683       bfd_put_32 (output_bfd, 0, fixup_table);
     691      bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
    684692      fixup_table += 4;
    685       bfd_put_32 (output_bfd, 0, fixup_table);
     693      bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
    686694      fixup_table += 4;
    687695      ++fixups_written;
     
    709717#endif
    710718
    711           bfd_put_32 (output_bfd, new_addr, fixup_table);
     719          bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table);
    712720          fixup_table += 4;
    713721          bfd_put_32 (output_bfd, f->value, fixup_table);
     
    722730      while (linux_hash_table (info)->fixup_count > fixups_written)
    723731        {
    724           bfd_put_32 (output_bfd, 0, fixup_table);
     732          bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
    725733          fixup_table += 4;
    726           bfd_put_32 (output_bfd, 0, fixup_table);
     734          bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
    727735          fixup_table += 4;
    728736          ++fixups_written;
     
    730738    }
    731739
    732   h = linux_link_hash_lookup (linux_hash_table (info), 
     740  h = linux_link_hash_lookup (linux_hash_table (info),
    733741                              "__BUILTIN_FIXUPS__",
    734                               false, false, false);
     742                              FALSE, FALSE, FALSE);
    735743
    736744  if (h != NULL
     
    746754#endif
    747755
    748       bfd_put_32 (output_bfd, new_addr, fixup_table);
     756      bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table);
    749757    }
    750758  else
    751     bfd_put_32 (output_bfd, 0, fixup_table);
    752 
    753   if (bfd_seek (output_bfd, os->filepos + s->output_offset, SEEK_SET) != 0)
    754     return false;
    755 
    756   if (bfd_write ((PTR) s->contents, 1, s->_raw_size, output_bfd)
    757       != s->_raw_size)
    758     return false;
    759 
    760   return true;
     759    bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
     760
     761  if (bfd_seek (output_bfd, (file_ptr) (os->filepos + s->output_offset),
     762                SEEK_SET) != 0)
     763    return FALSE;
     764
     765  if (bfd_bwrite ((PTR) s->contents, s->_raw_size, output_bfd) != s->_raw_size)
     766    return FALSE;
     767
     768  return TRUE;
    761769}
    762770
Note: See TracChangeset for help on using the changeset viewer.