/[gcl]/gcl/binutils/bfd/m68klinux.c
ViewVC logotype

Diff of /gcl/binutils/bfd/m68klinux.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by camm, Fri Aug 9 05:35:37 2002 UTC revision 1.2 by camm, Fri Sep 9 23:32:14 2005 UTC
# Line 1  Line 1 
1  /* BFD back-end for linux flavored m68k a.out binaries.  /* BFD back-end for linux flavored m68k a.out binaries.
2     Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002     Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
3     Free Software Foundation, Inc.     2003, 2004 Free Software Foundation, Inc.
4    
5  This file is part of BFD, the Binary File Descriptor library.  This file is part of BFD, the Binary File Descriptor library.
6    
# Line 23  Foundation, Inc., 59 Temple Place - Suit Line 23  Foundation, Inc., 59 Temple Place - Suit
23  #define SEGMENT_SIZE TARGET_PAGE_SIZE  #define SEGMENT_SIZE TARGET_PAGE_SIZE
24  #define TEXT_START_ADDR 0x0  #define TEXT_START_ADDR 0x0
25  #define N_SHARED_LIB(x) 0  #define N_SHARED_LIB(x) 0
 #define BYTES_IN_WORD 4  
26    
27  #define MACHTYPE_OK(mtype) ((mtype) == M_68020 || (mtype) == M_UNKNOWN)  #define MACHTYPE_OK(mtype) ((mtype) == M_68020 || (mtype) == M_UNKNOWN)
28    
# Line 52  extern const bfd_target MY(vec); Line 51  extern const bfd_target MY(vec);
51    
52  static void MY_final_link_callback  static void MY_final_link_callback
53    PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));    PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
54  static boolean m68klinux_bfd_final_link  static bfd_boolean m68klinux_bfd_final_link
55    PARAMS ((bfd *, struct bfd_link_info *));    PARAMS ((bfd *, struct bfd_link_info *));
56  static boolean m68klinux_write_object_contents PARAMS ((bfd *));  static bfd_boolean m68klinux_write_object_contents PARAMS ((bfd *));
57    
58  static boolean  static bfd_boolean
59  m68klinux_bfd_final_link (abfd, info)  m68klinux_bfd_final_link (abfd, info)
60       bfd *abfd;       bfd *abfd;
61       struct bfd_link_info *info;       struct bfd_link_info *info;
# Line 69  m68klinux_bfd_final_link (abfd, info) Line 68  m68klinux_bfd_final_link (abfd, info)
68    
69  /* Set the machine type correctly.  */  /* Set the machine type correctly.  */
70    
71  static boolean  static bfd_boolean
72  m68klinux_write_object_contents (abfd)  m68klinux_write_object_contents (abfd)
73       bfd *abfd;       bfd *abfd;
74  {  {
# Line 82  m68klinux_write_object_contents (abfd) Line 81  m68klinux_write_object_contents (abfd)
81    
82    WRITE_HEADERS(abfd, execp);    WRITE_HEADERS(abfd, execp);
83    
84    return true;    return TRUE;
85  }  }
86    
87  #define MY_write_object_contents m68klinux_write_object_contents  #define MY_write_object_contents m68klinux_write_object_contents
# Line 114  m68klinux_write_object_contents (abfd) Line 113  m68klinux_write_object_contents (abfd)
113  #endif  #endif
114    
115  /* This special symbol is a set vector that contains a list of  /* This special symbol is a set vector that contains a list of
116     pointers to fixup tables.  It will be present in any dynamicly     pointers to fixup tables.  It will be present in any dynamically
117     linked file.  The linker generated fixup table should also be added     linked file.  The linker generated fixup table should also be added
118     to the list, and it should always appear in the second slot (the     to the list, and it should always appear in the second slot (the
119     first one is a dummy with a magic number that is defined in     first one is a dummy with a magic number that is defined in
# Line 180  static struct bfd_link_hash_table *linux Line 179  static struct bfd_link_hash_table *linux
179  static struct fixup *new_fixup  static struct fixup *new_fixup
180    PARAMS ((struct bfd_link_info *, struct linux_link_hash_entry *,    PARAMS ((struct bfd_link_info *, struct linux_link_hash_entry *,
181             bfd_vma, int));             bfd_vma, int));
182  static boolean linux_link_create_dynamic_sections  static bfd_boolean linux_link_create_dynamic_sections
183    PARAMS ((bfd *, struct bfd_link_info *));    PARAMS ((bfd *, struct bfd_link_info *));
184  static boolean linux_add_one_symbol  static bfd_boolean linux_add_one_symbol
185    PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,    PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,
186             bfd_vma, const char *, boolean, boolean,             bfd_vma, const char *, bfd_boolean, bfd_boolean,
187             struct bfd_link_hash_entry **));             struct bfd_link_hash_entry **));
188  static boolean linux_tally_symbols  static bfd_boolean linux_tally_symbols
189    PARAMS ((struct linux_link_hash_entry *, PTR));    PARAMS ((struct linux_link_hash_entry *, PTR));
190  static boolean linux_finish_dynamic_link  static bfd_boolean linux_finish_dynamic_link
191    PARAMS ((bfd *, struct bfd_link_info *));    PARAMS ((bfd *, struct bfd_link_info *));
192    
193  /* Routine to create an entry in an Linux link hash table.  */  /* Routine to create an entry in an Linux link hash table.  */
# Line 263  linux_link_hash_table_create (abfd) Line 262  linux_link_hash_table_create (abfd)
262  #define linux_link_hash_traverse(table, func, info)                     \  #define linux_link_hash_traverse(table, func, info)                     \
263    (aout_link_hash_traverse                                              \    (aout_link_hash_traverse                                              \
264     (&(table)->root,                                                     \     (&(table)->root,                                                     \
265      (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \      (bfd_boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func),     \
266      (info)))      (info)))
267    
268  /* Get the Linux link hash table from the info structure.  This is  /* Get the Linux link hash table from the info structure.  This is
# Line 303  new_fixup (info, h, value, builtin) Line 302  new_fixup (info, h, value, builtin)
302     know the size of the section, but that's OK - we just need to     know the size of the section, but that's OK - we just need to
303     create it for now.  */     create it for now.  */
304    
305  static boolean  static bfd_boolean
306  linux_link_create_dynamic_sections (abfd, info)  linux_link_create_dynamic_sections (abfd, info)
307       bfd *abfd;       bfd *abfd;
308       struct bfd_link_info *info ATTRIBUTE_UNUSED;       struct bfd_link_info *info ATTRIBUTE_UNUSED;
# Line 320  linux_link_create_dynamic_sections (abfd Line 319  linux_link_create_dynamic_sections (abfd
319    if (s == NULL    if (s == NULL
320        || ! bfd_set_section_flags (abfd, s, flags)        || ! bfd_set_section_flags (abfd, s, flags)
321        || ! bfd_set_section_alignment (abfd, s, 2))        || ! bfd_set_section_alignment (abfd, s, 2))
322      return false;      return FALSE;
323    s->_raw_size = 0;    s->size = 0;
324    s->contents = 0;    s->contents = 0;
325    
326    return true;    return TRUE;
327  }  }
328    
329  /* Function to add a single symbol to the linker hash table.  This is  /* Function to add a single symbol to the linker hash table.  This is
330     a wrapper around _bfd_generic_link_add_one_symbol which handles the     a wrapper around _bfd_generic_link_add_one_symbol which handles the
331     tweaking needed for dynamic linking support.  */     tweaking needed for dynamic linking support.  */
332    
333  static boolean  static bfd_boolean
334  linux_add_one_symbol (info, abfd, name, flags, section, value, string,  linux_add_one_symbol (info, abfd, name, flags, section, value, string,
335                        copy, collect, hashp)                        copy, collect, hashp)
336       struct bfd_link_info *info;       struct bfd_link_info *info;
# Line 341  linux_add_one_symbol (info, abfd, name, Line 340  linux_add_one_symbol (info, abfd, name,
340       asection *section;       asection *section;
341       bfd_vma value;       bfd_vma value;
342       const char *string;       const char *string;
343       boolean copy;       bfd_boolean copy;
344       boolean collect;       bfd_boolean collect;
345       struct bfd_link_hash_entry **hashp;       struct bfd_link_hash_entry **hashp;
346  {  {
347    struct linux_link_hash_entry *h;    struct linux_link_hash_entry *h;
348    boolean insert;    bfd_boolean insert;
349    
350    /* Look up and see if we already have this symbol in the hash table.    /* Look up and see if we already have this symbol in the hash table.
351       If we do, and the defining entry is from a shared library, we       If we do, and the defining entry is from a shared library, we
# Line 356  linux_add_one_symbol (info, abfd, name, Line 355  linux_add_one_symbol (info, abfd, name,
355       be able to link Linux a.out and ELF objects together, but serious       be able to link Linux a.out and ELF objects together, but serious
356       confusion is possible.  */       confusion is possible.  */
357    
358    insert = false;    insert = FALSE;
359    
360    if (! info->relocateable    if (! info->relocatable
361        && linux_hash_table (info)->dynobj == NULL        && linux_hash_table (info)->dynobj == NULL
362        && strcmp (name, SHARABLE_CONFLICTS) == 0        && strcmp (name, SHARABLE_CONFLICTS) == 0
363        && (flags & BSF_CONSTRUCTOR) != 0        && (flags & BSF_CONSTRUCTOR) != 0
364        && abfd->xvec == info->hash->creator)        && abfd->xvec == info->hash->creator)
365      {      {
366        if (! linux_link_create_dynamic_sections (abfd, info))        if (! linux_link_create_dynamic_sections (abfd, info))
367          return false;          return FALSE;
368        linux_hash_table (info)->dynobj = abfd;        linux_hash_table (info)->dynobj = abfd;
369        insert = true;        insert = TRUE;
370      }      }
371    
372    if (bfd_is_abs_section (section)    if (bfd_is_abs_section (section)
373        && abfd->xvec == info->hash->creator)        && abfd->xvec == info->hash->creator)
374      {      {
375        h = linux_link_hash_lookup (linux_hash_table (info), name, false,        h = linux_link_hash_lookup (linux_hash_table (info), name, FALSE,
376                                    false, false);                                    FALSE, FALSE);
377        if (h != NULL        if (h != NULL
378            && (h->root.root.type == bfd_link_hash_defined            && (h->root.root.type == bfd_link_hash_defined
379                || h->root.root.type == bfd_link_hash_defweak))                || h->root.root.type == bfd_link_hash_defweak))
# Line 386  linux_add_one_symbol (info, abfd, name, Line 385  linux_add_one_symbol (info, abfd, name,
385    
386            f = new_fixup (info, h, value, ! IS_PLT_SYM (name));            f = new_fixup (info, h, value, ! IS_PLT_SYM (name));
387            if (f == NULL)            if (f == NULL)
388              return false;              return FALSE;
389            f->jump = IS_PLT_SYM (name);            f->jump = IS_PLT_SYM (name);
390    
391            return true;            return TRUE;
392          }          }
393      }      }
394    
# Line 397  linux_add_one_symbol (info, abfd, name, Line 396  linux_add_one_symbol (info, abfd, name,
396    if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,    if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
397                                            value, string, copy, collect,                                            value, string, copy, collect,
398                                            hashp))                                            hashp))
399      return false;      return FALSE;
400    
401    /* Insert a pointer to our table in the set vector.  The dynamic    /* Insert a pointer to our table in the set vector.  The dynamic
402       linker requires this information */       linker requires this information */
# Line 414  linux_add_one_symbol (info, abfd, name, Line 413  linux_add_one_symbol (info, abfd, name,
413        if (! (_bfd_generic_link_add_one_symbol        if (! (_bfd_generic_link_add_one_symbol
414               (info, linux_hash_table (info)->dynobj, SHARABLE_CONFLICTS,               (info, linux_hash_table (info)->dynobj, SHARABLE_CONFLICTS,
415                BSF_GLOBAL | BSF_CONSTRUCTOR, s, (bfd_vma) 0, NULL,                BSF_GLOBAL | BSF_CONSTRUCTOR, s, (bfd_vma) 0, NULL,
416                false, false, NULL)))                FALSE, FALSE, NULL)))
417          return false;          return FALSE;
418      }      }
419    
420    return true;    return TRUE;
421  }  }
422    
423  /* We will crawl the hash table and come here for every global symbol.  /* We will crawl the hash table and come here for every global symbol.
# Line 431  linux_add_one_symbol (info, abfd, name, Line 430  linux_add_one_symbol (info, abfd, name,
430    
431     This function is called via linux_link_hash_traverse.  */     This function is called via linux_link_hash_traverse.  */
432    
433  static boolean  static bfd_boolean
434  linux_tally_symbols (h, data)  linux_tally_symbols (h, data)
435       struct linux_link_hash_entry *h;       struct linux_link_hash_entry *h;
436       PTR data;       PTR data;
# Line 440  linux_tally_symbols (h, data) Line 439  linux_tally_symbols (h, data)
439    struct fixup *f, *f1;    struct fixup *f, *f1;
440    int is_plt;    int is_plt;
441    struct linux_link_hash_entry *h1, *h2;    struct linux_link_hash_entry *h1, *h2;
442    boolean exists;    bfd_boolean exists;
443    
444    if (h->root.root.type == bfd_link_hash_warning)    if (h->root.root.type == bfd_link_hash_warning)
445      h = (struct linux_link_hash_entry *) h->root.root.u.i.link;      h = (struct linux_link_hash_entry *) h->root.root.u.i.link;
# Line 486  linux_tally_symbols (h, data) Line 485  linux_tally_symbols (h, data)
485        h1 = linux_link_hash_lookup (linux_hash_table (info),        h1 = linux_link_hash_lookup (linux_hash_table (info),
486                                     (h->root.root.root.string                                     (h->root.root.root.string
487                                      + sizeof PLT_REF_PREFIX - 1),                                      + sizeof PLT_REF_PREFIX - 1),
488                                     false, false, true);                                     FALSE, FALSE, TRUE);
489        /* h2 does not follow indirect symbols.  */        /* h2 does not follow indirect symbols.  */
490        h2 = linux_link_hash_lookup (linux_hash_table (info),        h2 = linux_link_hash_lookup (linux_hash_table (info),
491                                     (h->root.root.root.string                                     (h->root.root.root.string
492                                      + sizeof PLT_REF_PREFIX - 1),                                      + sizeof PLT_REF_PREFIX - 1),
493                                     false, false, false);                                     FALSE, FALSE, FALSE);
494    
495        /* The real symbol must exist but if it is also an ABS symbol,        /* The real symbol must exist but if it is also an ABS symbol,
496           there is no need to have a fixup.  This is because they both           there is no need to have a fixup.  This is because they both
# Line 509  linux_tally_symbols (h, data) Line 508  linux_tally_symbols (h, data)
508               involving this symbol.  If so, convert it to a regular               involving this symbol.  If so, convert it to a regular
509               fixup.  In the end, this relaxes some of the requirements               fixup.  In the end, this relaxes some of the requirements
510               about the order of performing fixups.  */               about the order of performing fixups.  */
511            exists = false;            exists = FALSE;
512            for (f1 = linux_hash_table (info)->fixup_list;            for (f1 = linux_hash_table (info)->fixup_list;
513                 f1 != NULL;                 f1 != NULL;
514                 f1 = f1->next)                 f1 = f1->next)
# Line 518  linux_tally_symbols (h, data) Line 517  linux_tally_symbols (h, data)
517                    || (! f1->builtin && ! f1->jump))                    || (! f1->builtin && ! f1->jump))
518                  continue;                  continue;
519                if (f1->h == h1)                if (f1->h == h1)
520                  exists = true;                  exists = TRUE;
521                if (! exists                if (! exists
522                    && bfd_is_abs_section (h->root.root.u.def.section))                    && bfd_is_abs_section (h->root.root.u.def.section))
523                  {                  {
# Line 528  linux_tally_symbols (h, data) Line 527  linux_tally_symbols (h, data)
527                f1->h = h1;                f1->h = h1;
528                f1->jump = is_plt;                f1->jump = is_plt;
529                f1->builtin = 0;                f1->builtin = 0;
530                exists = true;                exists = TRUE;
531              }              }
532            if (! exists            if (! exists
533                && bfd_is_abs_section (h->root.root.u.def.section))                && bfd_is_abs_section (h->root.root.u.def.section))
# Line 546  linux_tally_symbols (h, data) Line 545  linux_tally_symbols (h, data)
545        /* Quick and dirty way of stripping these symbols from the        /* Quick and dirty way of stripping these symbols from the
546           symtab.  */           symtab.  */
547        if (bfd_is_abs_section (h->root.root.u.def.section))        if (bfd_is_abs_section (h->root.root.u.def.section))
548          h->root.written = true;          h->root.written = TRUE;
549      }      }
550    
551    return true;    return TRUE;
552  }  }
553    
554  /* This is called to set the size of the .linux-dynamic section is.  /* This is called to set the size of the .linux-dynamic section is.
# Line 558  linux_tally_symbols (h, data) Line 557  linux_tally_symbols (h, data)
557     we just scan the hash tables to find out how many additional fixups     we just scan the hash tables to find out how many additional fixups
558     are required.  */     are required.  */
559    
560  boolean  bfd_boolean
561  bfd_m68klinux_size_dynamic_sections (output_bfd, info)  bfd_m68klinux_size_dynamic_sections (output_bfd, info)
562       bfd *output_bfd;       bfd *output_bfd;
563       struct bfd_link_info *info;       struct bfd_link_info *info;
# Line 567  bfd_m68klinux_size_dynamic_sections (out Line 566  bfd_m68klinux_size_dynamic_sections (out
566    asection *s;    asection *s;
567    
568    if (output_bfd->xvec != &MY(vec))    if (output_bfd->xvec != &MY(vec))
569      return true;      return TRUE;
570    
571    /* First find the fixups...  */    /* First find the fixups...  */
572    linux_link_hash_traverse (linux_hash_table (info),    linux_link_hash_traverse (linux_hash_table (info),
# Line 591  bfd_m68klinux_size_dynamic_sections (out Line 590  bfd_m68klinux_size_dynamic_sections (out
590      {      {
591        if (linux_hash_table (info)->fixup_count > 0)        if (linux_hash_table (info)->fixup_count > 0)
592          abort ();          abort ();
593        return true;        return TRUE;
594      }      }
595    
596    /* Allocate memory for our fixup table.  We will fill it in later.  */    /* Allocate memory for our fixup table.  We will fill it in later.  */
# Line 599  bfd_m68klinux_size_dynamic_sections (out Line 598  bfd_m68klinux_size_dynamic_sections (out
598                                 ".linux-dynamic");                                 ".linux-dynamic");
599    if (s != NULL)    if (s != NULL)
600      {      {
601        s->_raw_size = linux_hash_table (info)->fixup_count + 1;        s->size = linux_hash_table (info)->fixup_count + 1;
602        s->_raw_size *= 8;        s->size *= 8;
603        s->contents = (bfd_byte *) bfd_zalloc (output_bfd, s->_raw_size);        s->contents = (bfd_byte *) bfd_zalloc (output_bfd, s->size);
604        if (s->contents == NULL)        if (s->contents == NULL)
605          {          {
606            bfd_set_error (bfd_error_no_memory);            bfd_set_error (bfd_error_no_memory);
607            return false;            return FALSE;
608          }          }
609      }      }
610    
611    return true;    return TRUE;
612  }  }
613    
614  /* We come here once we are ready to actually write the fixup table to  /* We come here once we are ready to actually write the fixup table to
615     the output file.  Scan the fixup tables and so forth and generate     the output file.  Scan the fixup tables and so forth and generate
616     the stuff we need.  */     the stuff we need.  */
617    
618  static boolean  static bfd_boolean
619  linux_finish_dynamic_link (output_bfd, info)  linux_finish_dynamic_link (output_bfd, info)
620       bfd *output_bfd;       bfd *output_bfd;
621       struct bfd_link_info *info;       struct bfd_link_info *info;
# Line 630  linux_finish_dynamic_link (output_bfd, i Line 629  linux_finish_dynamic_link (output_bfd, i
629    unsigned int fixups_written;    unsigned int fixups_written;
630    
631    if (linux_hash_table (info)->dynobj == NULL)    if (linux_hash_table (info)->dynobj == NULL)
632      return true;      return TRUE;
633    
634    s = bfd_get_section_by_name (linux_hash_table (info)->dynobj,    s = bfd_get_section_by_name (linux_hash_table (info)->dynobj,
635                                 ".linux-dynamic");                                 ".linux-dynamic");
# Line 744  linux_finish_dynamic_link (output_bfd, i Line 743  linux_finish_dynamic_link (output_bfd, i
743    
744    h = linux_link_hash_lookup (linux_hash_table (info),    h = linux_link_hash_lookup (linux_hash_table (info),
745                                "__BUILTIN_FIXUPS__",                                "__BUILTIN_FIXUPS__",
746                                false, false, false);                                FALSE, FALSE, FALSE);
747    
748    if (h != NULL    if (h != NULL
749        && (h->root.root.type == bfd_link_hash_defined        && (h->root.root.type == bfd_link_hash_defined
# Line 765  linux_finish_dynamic_link (output_bfd, i Line 764  linux_finish_dynamic_link (output_bfd, i
764    
765    if (bfd_seek (output_bfd, (file_ptr) (os->filepos + s->output_offset),    if (bfd_seek (output_bfd, (file_ptr) (os->filepos + s->output_offset),
766                  SEEK_SET) != 0)                  SEEK_SET) != 0)
767      return false;      return FALSE;
768    
769    if (bfd_bwrite ((PTR) s->contents, s->_raw_size, output_bfd) != s->_raw_size)    if (bfd_bwrite ((PTR) s->contents, s->size, output_bfd) != s->size)
770      return false;      return FALSE;
771    
772    return true;    return TRUE;
773  }  }
774    
775  #define MY_bfd_link_hash_table_create linux_link_hash_table_create  #define MY_bfd_link_hash_table_create linux_link_hash_table_create

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26