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/ld/ldlang.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* Linker command language support.
    22   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
    3    2001
     3   2001, 2002, 2003
    44   Free Software Foundation, Inc.
    55
    6 This file is part of GLD, the Gnu Linker.
    7 
    8 GLD is free software; you can redistribute it and/or modify
    9 it under the terms of the GNU General Public License as published by
    10 the Free Software Foundation; either version 2, or (at your option)
    11 any later version.
    12 
    13 GLD is distributed in the hope that it will be useful,
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16 GNU General Public License for more details.
    17 
    18 You should have received a copy of the GNU General Public License
    19 along with GLD; see the file COPYING.  If not, write to the Free
    20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    21 02111-1307, USA.  */
     6   This file is part of GLD, the Gnu Linker.
     7
     8   GLD is free software; you can redistribute it and/or modify
     9   it under the terms of the GNU General Public License as published by
     10   the Free Software Foundation; either version 2, or (at your option)
     11   any later version.
     12
     13   GLD is distributed in the hope that it will be useful,
     14   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16   GNU General Public License for more details.
     17
     18   You should have received a copy of the GNU General Public License
     19   along with GLD; see the file COPYING.  If not, write to the Free
     20   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
     21   02111-1307, USA.  */
    2222
    2323#include "bfd.h"
    2424#include "sysdep.h"
    2525#include "libiberty.h"
     26#include "safe-ctype.h"
    2627#include "obstack.h"
    2728#include "bfdlink.h"
     
    2930#include "ld.h"
    3031#include "ldmain.h"
    31 #include "ldgram.h"
    3232#include "ldexp.h"
    3333#include "ldlang.h"
     34#include <ldgram.h>
    3435#include "ldlex.h"
    3536#include "ldmisc.h"
     
    4041#include "demangle.h"
    4142
    42 #include <ctype.h>
    43 
    44 /* FORWARDS */
    45 static lang_statement_union_type *new_statement
    46   PARAMS ((enum statement_enum, size_t, lang_statement_list_type *));
    47 
    48 /* LOCALS */
     43#ifndef offsetof
     44#define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER))
     45#endif
     46
     47/* Locals variables.  */
    4948static struct obstack stat_obstack;
    5049
     
    5352static const char *startup_file;
    5453static lang_statement_list_type input_file_chain;
    55 static boolean placed_commons = false;
     54static bfd_boolean placed_commons = FALSE;
    5655static lang_output_section_statement_type *default_common_section;
    57 static boolean map_option_f;
     56static bfd_boolean map_option_f;
    5857static bfd_vma print_dot;
    5958static lang_input_statement_type *first_file;
     
    6362static struct lang_phdr *lang_phdr_list;
    6463
     64/* Forward declarations.  */
     65static lang_statement_union_type *new_statement
     66  PARAMS ((enum statement_enum, size_t, lang_statement_list_type *));
    6567static void lang_for_each_statement_worker
    6668  PARAMS ((void (*) (lang_statement_union_type *),
    6769           lang_statement_union_type *));
    6870static lang_input_statement_type *new_afile
    69   PARAMS ((const char *, lang_input_file_enum_type, const char *, boolean));
    70 static lang_memory_region_type *lang_memory_default PARAMS ((asection *));
    71 static void lang_map_flags PARAMS ((flagword));
    72 static void init_os PARAMS ((lang_output_section_statement_type *));
    73 static void exp_init_os PARAMS ((etree_type *));
    74 static void section_already_linked PARAMS ((bfd *, asection *, PTR));
     71  PARAMS ((const char *, lang_input_file_enum_type, const char *,
     72           bfd_boolean));
     73static lang_memory_region_type *lang_memory_default
     74  PARAMS ((asection *));
     75static void lang_map_flags
     76  PARAMS ((flagword));
     77static void init_os
     78  PARAMS ((lang_output_section_statement_type *));
     79static void exp_init_os
     80  PARAMS ((etree_type *));
     81static void section_already_linked
     82  PARAMS ((bfd *, asection *, PTR));
    7583static struct bfd_hash_entry *already_linked_newfunc
    7684  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
    77 static void already_linked_table_init PARAMS ((void));
    78 static void already_linked_table_free PARAMS ((void));
    79 static boolean wildcardp PARAMS ((const char *));
     85static void already_linked_table_init
     86  PARAMS ((void));
     87static void already_linked_table_free
     88  PARAMS ((void));
     89static bfd_boolean wildcardp
     90  PARAMS ((const char *));
    8091static lang_statement_union_type *wild_sort
    81   PARAMS ((lang_wild_statement_type *, lang_input_statement_type *,
    82            asection *));
     92  PARAMS ((lang_wild_statement_type *, struct wildcard_list *,
     93           lang_input_statement_type *, asection *));
    8394static void output_section_callback
    84   PARAMS ((lang_wild_statement_type *, asection *,
     95  PARAMS ((lang_wild_statement_type *, struct wildcard_list *, asection *,
    8596           lang_input_statement_type *, PTR));
    86 static lang_input_statement_type *lookup_name PARAMS ((const char *));
    87 static void load_symbols
     97static lang_input_statement_type *lookup_name
     98  PARAMS ((const char *));
     99static bfd_boolean load_symbols
    88100  PARAMS ((lang_input_statement_type *, lang_statement_list_type *));
    89101static void wild
    90   PARAMS ((lang_wild_statement_type *, const char *, const char *,
     102  PARAMS ((lang_wild_statement_type *,
    91103           const char *, lang_output_section_statement_type *));
    92 static bfd *open_output PARAMS ((const char *));
    93 static void ldlang_open_output PARAMS ((lang_statement_union_type *));
    94 static void open_input_bfds PARAMS ((lang_statement_union_type *, boolean));
    95 static void lang_reasonable_defaults PARAMS ((void));
    96 static void lang_place_undefineds PARAMS ((void));
     104static bfd *open_output
     105  PARAMS ((const char *));
     106static void ldlang_open_output
     107  PARAMS ((lang_statement_union_type *));
     108static void open_input_bfds
     109  PARAMS ((lang_statement_union_type *, bfd_boolean));
     110static void lang_reasonable_defaults
     111  PARAMS ((void));
     112static void insert_undefined
     113  PARAMS ((const char *));
     114static void lang_place_undefineds
     115  PARAMS ((void));
    97116static void map_input_to_output_sections
    98117  PARAMS ((lang_statement_union_type *, const char *,
    99118           lang_output_section_statement_type *));
     119static void strip_excluded_output_sections
     120  PARAMS ((void));
    100121static void print_output_section_statement
    101122  PARAMS ((lang_output_section_statement_type *));
     
    103124  PARAMS ((lang_assignment_statement_type *,
    104125           lang_output_section_statement_type *));
    105 static void print_input_statement PARAMS ((lang_input_statement_type *));
    106 static boolean print_one_symbol PARAMS ((struct bfd_link_hash_entry *, PTR));
    107 static void print_input_section PARAMS ((lang_input_section_type *));
    108 static void print_fill_statement PARAMS ((lang_fill_statement_type *));
    109 static void print_data_statement PARAMS ((lang_data_statement_type *));
    110 static void print_address_statement PARAMS ((lang_address_statement_type *));
    111 static void print_reloc_statement PARAMS ((lang_reloc_statement_type *));
    112 static void print_padding_statement PARAMS ((lang_padding_statement_type *));
     126static void print_input_statement
     127  PARAMS ((lang_input_statement_type *));
     128static bfd_boolean print_one_symbol
     129  PARAMS ((struct bfd_link_hash_entry *, PTR));
     130static void print_input_section
     131  PARAMS ((lang_input_section_type *));
     132static void print_fill_statement
     133  PARAMS ((lang_fill_statement_type *));
     134static void print_data_statement
     135  PARAMS ((lang_data_statement_type *));
     136static void print_address_statement
     137  PARAMS ((lang_address_statement_type *));
     138static void print_reloc_statement
     139  PARAMS ((lang_reloc_statement_type *));
     140static void print_padding_statement
     141  PARAMS ((lang_padding_statement_type *));
    113142static void print_wild_statement
    114143  PARAMS ((lang_wild_statement_type *, lang_output_section_statement_type *));
     
    119148static void print_statement_list
    120149  PARAMS ((lang_statement_union_type *, lang_output_section_statement_type *));
    121 static void print_statements PARAMS ((void));
    122 static bfd_vma insert_pad
    123   PARAMS ((lang_statement_union_type **, fill_type,
     150static void print_statements
     151  PARAMS ((void));
     152static void insert_pad
     153  PARAMS ((lang_statement_union_type **, fill_type *,
    124154           unsigned int, asection *, bfd_vma));
    125155static bfd_vma size_input_section
    126156  PARAMS ((lang_statement_union_type **, lang_output_section_statement_type *,
    127            fill_type, bfd_vma, boolean));
    128 static void lang_finish PARAMS ((void));
    129 static void ignore_bfd_errors PARAMS ((const char *, ...));
    130 static void lang_check PARAMS ((void));
    131 static void lang_common PARAMS ((void));
    132 static boolean lang_one_common PARAMS ((struct bfd_link_hash_entry *, PTR));
    133 static void lang_place_orphans PARAMS ((void));
    134 static int topower PARAMS ((int));
    135 static void lang_set_startof PARAMS ((void));
    136 static void reset_memory_regions PARAMS ((void));
     157           fill_type *, bfd_vma));
     158static void lang_finish
     159  PARAMS ((void));
     160static void ignore_bfd_errors
     161  PARAMS ((const char *, ...));
     162static void lang_check
     163  PARAMS ((void));
     164static void lang_common
     165  PARAMS ((void));
     166static bfd_boolean lang_one_common
     167  PARAMS ((struct bfd_link_hash_entry *, PTR));
     168static void lang_place_orphans
     169  PARAMS ((void));
     170static int topower
     171  PARAMS ((int));
     172static void lang_set_startof
     173  PARAMS ((void));
    137174static void gc_section_callback
    138   PARAMS ((lang_wild_statement_type *, asection *,
     175  PARAMS ((lang_wild_statement_type *, struct wildcard_list *, asection *,
    139176           lang_input_statement_type *, PTR));
    140 static void lang_record_phdrs PARAMS ((void));
     177static void lang_get_regions
     178  PARAMS ((struct memory_region_struct **, struct memory_region_struct **,
     179           const char *, const char *, int));
     180static void lang_record_phdrs
     181  PARAMS ((void));
    141182static void lang_gc_wild
    142   PARAMS ((lang_wild_statement_type *, const char *, const char *));
    143 static void lang_gc_sections_1 PARAMS ((lang_statement_union_type *));
    144 static void lang_gc_sections PARAMS ((void));
     183  PARAMS ((lang_wild_statement_type *));
     184static void lang_gc_sections_1
     185  PARAMS ((lang_statement_union_type *));
     186static void lang_gc_sections
     187  PARAMS ((void));
    145188static int lang_vers_match_lang_c
    146189  PARAMS ((struct bfd_elf_version_expr *, const char *));
     
    149192static int lang_vers_match_lang_java
    150193  PARAMS ((struct bfd_elf_version_expr *, const char *));
    151 static void lang_do_version_exports_section PARAMS ((void));
    152 static void lang_check_section_addresses PARAMS ((void));
     194static void lang_do_version_exports_section
     195  PARAMS ((void));
     196static void lang_check_section_addresses
     197  PARAMS ((void));
    153198static void os_region_check
    154199  PARAMS ((lang_output_section_statement_type *,
    155200           struct memory_region_struct *, etree_type *, bfd_vma));
    156 
    157 typedef void (*callback_t) PARAMS ((lang_wild_statement_type *,
    158                                     asection *, lang_input_statement_type *,
    159                                     PTR));
     201static bfd_vma lang_size_sections_1
     202  PARAMS ((lang_statement_union_type *, lang_output_section_statement_type *,
     203           lang_statement_union_type **, fill_type *, bfd_vma, bfd_boolean *,
     204           bfd_boolean));
     205typedef void (*callback_t)
     206  PARAMS ((lang_wild_statement_type *, struct wildcard_list *, asection *,
     207           lang_input_statement_type *, PTR));
    160208static void walk_wild
    161   PARAMS ((lang_wild_statement_type *, const char *, const char *,
    162          callback_t, PTR));
     209  PARAMS ((lang_wild_statement_type *, callback_t, PTR));
    163210static void walk_wild_section
    164   PARAMS ((lang_wild_statement_type *, const char *,
    165            lang_input_statement_type *, callback_t, PTR));
     211  PARAMS ((lang_wild_statement_type *, lang_input_statement_type *,
     212           callback_t, PTR));
    166213static void walk_wild_file
    167   PARAMS ((lang_wild_statement_type *, const char *,
    168            lang_input_statement_type *, callback_t, PTR));
    169 
    170 static int    get_target PARAMS ((const bfd_target *, PTR));
    171 static void   stricpy PARAMS ((char *, char *));
    172 static void   strcut PARAMS ((char *, char *));
    173 static int    name_compare PARAMS ((char *, char *));
    174 static int    closest_target_match PARAMS ((const bfd_target *, PTR));
    175 static char * get_first_input_target PARAMS ((void));
    176 
    177 /* EXPORTS */
     214  PARAMS ((lang_wild_statement_type *, lang_input_statement_type *,
     215           callback_t, PTR));
     216static int get_target
     217  PARAMS ((const bfd_target *, PTR));
     218static void stricpy
     219  PARAMS ((char *, char *));
     220static void strcut
     221  PARAMS ((char *, char *));
     222static int name_compare
     223  PARAMS ((char *, char *));
     224static int closest_target_match
     225  PARAMS ((const bfd_target *, PTR));
     226static char * get_first_input_target
     227  PARAMS ((void));
     228
     229/* Exported variables.  */
    178230lang_output_section_statement_type *abs_output_section;
    179231lang_statement_list_type lang_output_section_statement;
    180232lang_statement_list_type *stat_ptr = &statement_list;
    181233lang_statement_list_type file_chain = { NULL, NULL };
    182 const char *entry_symbol = NULL;
    183 boolean entry_from_cmdline;
    184 boolean lang_has_input_file = false;
    185 boolean had_output_filename = false;
    186 boolean lang_float_flag = false;
    187 boolean delete_output_file_on_failure = false;
     234struct bfd_sym_chain entry_symbol = { NULL, NULL };
     235const char *entry_section = ".text";
     236bfd_boolean entry_from_cmdline;
     237bfd_boolean lang_has_input_file = FALSE;
     238bfd_boolean had_output_filename = FALSE;
     239bfd_boolean lang_float_flag = FALSE;
     240bfd_boolean delete_output_file_on_failure = FALSE;
    188241struct lang_nocrossrefs *nocrossref_list;
    189242struct unique_sections *unique_section_list;
     243static bfd_boolean ldlang_sysrooted_script = FALSE;
    190244
    191245etree_type *base; /* Relocation base - or null */
     
    217271}
    218272
    219 boolean
     273bfd_boolean
    220274unique_section_p (secnam)
    221275     const char *secnam;
     
    228282        : strcmp (unam->name, secnam) == 0)
    229283      {
    230         return true;
     284        return TRUE;
    231285      }
    232286
    233   return false;
     287  return FALSE;
    234288}
    235289
     
    237291
    238292static void
    239 walk_wild_section (ptr, section, file, callback, data)
     293walk_wild_section (ptr, file, callback, data)
    240294     lang_wild_statement_type *ptr;
    241      const char *section;
    242295     lang_input_statement_type *file;
    243296     callback_t callback;
    244297     PTR data;
    245298{
    246   /* Don't process sections from files which were excluded.  */
    247   if (ptr->exclude_filename_list != NULL)
    248     {
    249       struct name_list *list_tmp;
    250       for (list_tmp = ptr->exclude_filename_list;
    251            list_tmp;
    252            list_tmp = list_tmp->next)
    253         {
    254           boolean match;
    255 
    256           if (wildcardp (list_tmp->name))
    257             match = fnmatch (list_tmp->name, file->filename, 0) == 0;
    258           else
    259             match = strcmp (list_tmp->name, file->filename) == 0;
    260 
    261           if (match)
    262             return;
    263         }
    264     }
    265 
    266   if (file->just_syms_flag == false)
    267     {
    268       register asection *s;
    269       boolean wildcard = false;
    270 
    271       if (section != NULL)
    272         wildcard = wildcardp (section);
    273 
    274       for (s = file->the_bfd->sections; s != NULL; s = s->next)
    275         {
    276           boolean match;
    277           const char *sname = bfd_get_section_name (file->the_bfd, s);
    278 
    279           if (section == NULL)
    280             match = true;
    281           else if (wildcard)
    282             match = fnmatch (section, sname, 0) == 0;
    283           else
    284             match = strcmp (section, sname) == 0;
    285 
    286           /* If this is a wild-card output section statement, exclude
    287              sections that match UNIQUE_SECTION_LIST.  */
    288           if (match && (data == NULL || !unique_section_p (sname)))
    289             (*callback) (ptr, s, file, data);
     299  asection *s;
     300
     301  if (file->just_syms_flag)
     302    return;
     303
     304  for (s = file->the_bfd->sections; s != NULL; s = s->next)
     305    {
     306      struct wildcard_list *sec;
     307
     308      sec = ptr->section_list;
     309      if (sec == NULL)
     310        (*callback) (ptr, sec, s, file, data);
     311
     312      while (sec != NULL)
     313        {
     314          bfd_boolean skip = FALSE;
     315          struct name_list *list_tmp;
     316
     317          /* Don't process sections from files which were
     318             excluded.  */
     319          for (list_tmp = sec->spec.exclude_name_list;
     320               list_tmp;
     321               list_tmp = list_tmp->next)
     322            {
     323              if (wildcardp (list_tmp->name))
     324                skip = fnmatch (list_tmp->name, file->filename, 0) == 0;
     325              else
     326                skip = strcmp (list_tmp->name, file->filename) == 0;
     327
     328              /* If this file is part of an archive, and the archive is
     329                 excluded, exclude this file.  */
     330              if (! skip && file->the_bfd != NULL
     331                  && file->the_bfd->my_archive != NULL
     332                  && file->the_bfd->my_archive->filename != NULL)
     333                {
     334                  if (wildcardp (list_tmp->name))
     335                    skip = fnmatch (list_tmp->name,
     336                                    file->the_bfd->my_archive->filename,
     337                                    0) == 0;
     338                  else
     339                    skip = strcmp (list_tmp->name,
     340                                   file->the_bfd->my_archive->filename) == 0;
     341                }
     342
     343              if (skip)
     344                break;
     345            }
     346
     347          if (!skip && sec->spec.name != NULL)
     348            {
     349              const char *sname = bfd_get_section_name (file->the_bfd, s);
     350
     351              if (wildcardp (sec->spec.name))
     352                skip = fnmatch (sec->spec.name, sname, 0) != 0;
     353              else
     354                skip = strcmp (sec->spec.name, sname) != 0;
     355            }
     356
     357          if (!skip)
     358            (*callback) (ptr, sec, s, file, data);
     359
     360          sec = sec->next;
    290361        }
    291362    }
     
    295366
    296367static void
    297 walk_wild_file (s, section, f, callback, data)
     368walk_wild_file (s, f, callback, data)
    298369     lang_wild_statement_type *s;
    299      const char *section;
    300370     lang_input_statement_type *f;
    301371     callback_t callback;
     
    304374  if (f->the_bfd == NULL
    305375      || ! bfd_check_format (f->the_bfd, bfd_archive))
    306     walk_wild_section (s, section, f, callback, data);
     376    walk_wild_section (s, f, callback, data);
    307377  else
    308378    {
     
    321391          if (member->usrdata != NULL)
    322392            {
    323               walk_wild_section (s, section,
     393              walk_wild_section (s,
    324394                                 (lang_input_statement_type *) member->usrdata,
    325395                                 callback, data);
     
    332402
    333403static void
    334 walk_wild (s, section, file, callback, data)
     404walk_wild (s, callback, data)
    335405     lang_wild_statement_type *s;
    336      const char *section;
    337      const char *file;
    338406     callback_t callback;
    339407     PTR data;
    340408{
    341   if (file == (char *) NULL)
     409  const char *file_spec = s->filename;
     410
     411  if (file_spec == NULL)
    342412    {
    343413      /* Perform the iteration over all files in the list.  */
    344414      LANG_FOR_EACH_INPUT_STATEMENT (f)
    345415        {
    346           walk_wild_file (s, section, f, callback, data);
    347         }
    348     }
    349   else if (wildcardp (file))
     416          walk_wild_file (s, f, callback, data);
     417        }
     418    }
     419  else if (wildcardp (file_spec))
    350420    {
    351421      LANG_FOR_EACH_INPUT_STATEMENT (f)
    352422        {
    353           if (fnmatch (file, f->filename, FNM_FILE_NAME) == 0)
    354             walk_wild_file (s, section, f, callback, data);
     423          if (fnmatch (file_spec, f->filename, FNM_FILE_NAME) == 0)
     424            walk_wild_file (s, f, callback, data);
    355425        }
    356426    }
     
    360430
    361431      /* Perform the iteration over a single file.  */
    362       f = lookup_name (file);
    363       walk_wild_file (s, section, f, callback, data);
     432      f = lookup_name (file_spec);
     433      if (f)
     434        walk_wild_file (s, f, callback, data);
    364435    }
    365436}
     
    373444     lang_statement_union_type *s;
    374445{
    375   for (; s != (lang_statement_union_type *) NULL; s = s->next)
     446  for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
    376447    {
    377448      func (s);
     
    454525
    455526   We can be supplied with requests for input files more than once;
    456    they may, for example be split over serveral lines like foo.o(.text)
     527   they may, for example be split over several lines like foo.o(.text)
    457528   foo.o(.data) etc, so when asked for a file we check that we haven't
    458529   got it already so we don't duplicate the bfd.  */
     
    463534     lang_input_file_enum_type file_type;
    464535     const char *target;
    465      boolean add_to_list;
     536     bfd_boolean add_to_list;
    466537{
    467538  lang_input_statement_type *p;
     
    476547    }
    477548
    478   lang_has_input_file = true;
     549  lang_has_input_file = TRUE;
    479550  p->target = target;
     551  p->sysrooted = FALSE;
    480552  switch (file_type)
    481553    {
    482554    case lang_input_file_is_symbols_only_enum:
    483555      p->filename = name;
    484       p->is_archive = false;
    485       p->real = true;
     556      p->is_archive = FALSE;
     557      p->real = TRUE;
    486558      p->local_sym_name = name;
    487       p->just_syms_flag = true;
    488       p->search_dirs_flag = false;
     559      p->just_syms_flag = TRUE;
     560      p->search_dirs_flag = FALSE;
    489561      break;
    490562    case lang_input_file_is_fake_enum:
    491563      p->filename = name;
    492       p->is_archive = false;
    493       p->real = false;
     564      p->is_archive = FALSE;
     565      p->real = FALSE;
    494566      p->local_sym_name = name;
    495       p->just_syms_flag = false;
    496       p->search_dirs_flag = false;
     567      p->just_syms_flag = FALSE;
     568      p->search_dirs_flag = FALSE;
    497569      break;
    498570    case lang_input_file_is_l_enum:
    499       p->is_archive = true;
     571      p->is_archive = TRUE;
    500572      p->filename = name;
    501       p->real = true;
     573      p->real = TRUE;
    502574      p->local_sym_name = concat ("-l", name, (const char *) NULL);
    503       p->just_syms_flag = false;
    504       p->search_dirs_flag = true;
     575      p->just_syms_flag = FALSE;
     576      p->search_dirs_flag = TRUE;
    505577      break;
    506578    case lang_input_file_is_marker_enum:
    507579      p->filename = name;
    508       p->is_archive = false;
    509       p->real = false;
     580      p->is_archive = FALSE;
     581      p->real = FALSE;
    510582      p->local_sym_name = name;
    511       p->just_syms_flag = false;
    512       p->search_dirs_flag = true;
     583      p->just_syms_flag = FALSE;
     584      p->search_dirs_flag = TRUE;
    513585      break;
    514586    case lang_input_file_is_search_file_enum:
     587      p->sysrooted = ldlang_sysrooted_script;
    515588      p->filename = name;
    516       p->is_archive = false;
    517       p->real = true;
     589      p->is_archive = FALSE;
     590      p->real = TRUE;
    518591      p->local_sym_name = name;
    519       p->just_syms_flag = false;
    520       p->search_dirs_flag = true;
     592      p->just_syms_flag = FALSE;
     593      p->search_dirs_flag = TRUE;
    521594      break;
    522595    case lang_input_file_is_file_enum:
    523596      p->filename = name;
    524       p->is_archive = false;
    525       p->real = true;
     597      p->is_archive = FALSE;
     598      p->real = TRUE;
    526599      p->local_sym_name = name;
    527       p->just_syms_flag = false;
    528       p->search_dirs_flag = false;
     600      p->just_syms_flag = FALSE;
     601      p->search_dirs_flag = FALSE;
    529602      break;
    530603    default:
     
    538611  p->dynamic = config.dynamic_link;
    539612  p->whole_archive = whole_archive;
    540   p->loaded = false;
     613  p->loaded = FALSE;
    541614  lang_statement_append (&input_file_chain,
    542615                         (lang_statement_union_type *) p,
     
    551624     const char *target;
    552625{
    553   lang_has_input_file = true;
    554   return new_afile (name, file_type, target, true);
     626  lang_has_input_file = TRUE;
     627  return new_afile (name, file_type, target, TRUE);
    555628}
    556629
     
    598671  lang_memory_region_type *p;
    599672
     673  /* NAME is NULL for LMA memspecs if no region was specified.  */
     674  if (name == NULL)
     675    return NULL;
     676
    600677  for (p = lang_memory_region_list;
    601678       p != (lang_memory_region_type *) NULL;
     
    638715    new->length = ~(bfd_size_type) 0;
    639716    new->current = 0;
    640     new->had_full_message = false;
     717    new->had_full_message = FALSE;
    641718
    642719    return new;
     
    703780      lookup->region = (lang_memory_region_type *) NULL;
    704781      lookup->lma_region = (lang_memory_region_type *) NULL;
    705       lookup->fill = 0;
     782      lookup->fill = (fill_type *) 0;
    706783      lookup->block_value = 1;
    707784      lookup->name = name;
     
    709786      lookup->next = (lang_statement_union_type *) NULL;
    710787      lookup->bfd_section = (asection *) NULL;
    711       lookup->processed = false;
     788      lookup->processed = FALSE;
    712789      lookup->sectype = normal_section;
    713790      lookup->addr_tree = (etree_type *) NULL;
     
    719796      lookup->section_alignment = -1;
    720797      lookup->load_base = (union etree_union *) NULL;
     798      lookup->update_dot_tree = NULL;
    721799      lookup->phdrs = NULL;
    722800
     
    814892
    815893  if (strcmp (s->name, DISCARD_SECTION_NAME) == 0)
    816     einfo (_("%P%F: Illegal use of `%s' section"), DISCARD_SECTION_NAME);
     894    einfo (_("%P%F: Illegal use of `%s' section\n"), DISCARD_SECTION_NAME);
    817895
    818896  new = ((section_userdata_type *)
     
    838916  if (s->addr_tree != NULL)
    839917    exp_init_os (s->addr_tree);
     918
     919  if (s->load_base != NULL)
     920    exp_init_os (s->load_base);
    840921}
    841922
     
    9361017  if (entry->just_syms_flag)
    9371018    {
    938       sec->output_section = bfd_abs_section_ptr;
    939       sec->output_offset = sec->vma;
     1019      bfd_link_just_syms (sec, &link_info);
    9401020      return;
    9411021    }
     
    9601040
    9611041     Also, not merging link once sections in a relocatable link
    962      causes trouble for MIPS ELF, which relies in link once semantics
     1042     causes trouble for MIPS ELF, which relies on link once semantics
    9631043     to handle the .reginfo section correctly.  */
    9641044
     
    9671047  already_linked_list =
    9681048    ((struct already_linked_hash_entry *)
    969      bfd_hash_lookup (&already_linked_table, name, true, false));
     1049     bfd_hash_lookup (&already_linked_table, name, TRUE, FALSE));
    9701050
    9711051  for (l = already_linked_list->entry; l != NULL; l = l->next)
     
    10091089            }
    10101090
    1011           /* Set the output_section field so that wild_doit does not
    1012              create a lang_input_section structure for this section.
    1013              Since there might be a symbol in the section being
    1014              discarded, we must retain a pointer to the section which
    1015              we are really going to use.  */
     1091          /* Set the output_section field so that lang_add_section
     1092             does not create a lang_input_section structure for this
     1093             section.  */
    10161094          sec->output_section = bfd_abs_section_ptr;
    1017           sec->kept_section = l->sec;
     1095
     1096          if (flags & SEC_GROUP)
     1097            bfd_discard_group (abfd, sec);
    10181098
    10191099          return;
     
    10711151   foo.o(.text, .data).  */
    10721152
    1073 /* Return true if the PATTERN argument is a wildcard pattern.
     1153/* Return TRUE if the PATTERN argument is a wildcard pattern.
    10741154   Although backslashes are treated specially if a pattern contains
    10751155   wildcards, we do not consider the mere presence of a backslash to
    1076    be enough to cause the the pattern to be treated as a wildcard.
     1156   be enough to cause the pattern to be treated as a wildcard.
    10771157   That lets us handle DOS filenames more naturally.  */
    10781158
    1079 static boolean
     1159static bfd_boolean
    10801160wildcardp (pattern)
    10811161     const char *pattern;
     
    10871167        || *s == '*'
    10881168        || *s == '[')
    1089       return true;
    1090   return false;
     1169      return TRUE;
     1170  return FALSE;
    10911171}
    10921172
     
    10961176
    10971177void
    1098 wild_doit (ptr, section, output, file)
     1178lang_add_section (ptr, section, output, file)
    10991179     lang_statement_list_type *ptr;
    11001180     asection *section;
     
    11031183{
    11041184  flagword flags;
    1105   boolean discard;
     1185  bfd_boolean discard;
    11061186
    11071187  flags = bfd_get_section_flags (section->owner, section);
    11081188
    1109   discard = false;
    1110 
    1111   /* If we are doing a final link, discard sections marked with
    1112      SEC_EXCLUDE.  */
    1113   if (! link_info.relocateable
    1114       && (flags & SEC_EXCLUDE) != 0)
    1115     discard = true;
     1189  discard = FALSE;
     1190
     1191  /* Discard sections marked with SEC_EXCLUDE if we are doing a final
     1192     link.  Discard debugging sections marked with SEC_EXCLUDE on a
     1193     relocatable link too.  */
     1194  if ((flags & SEC_EXCLUDE) != 0
     1195      && ((flags & SEC_DEBUGGING) != 0 || !link_info.relocateable))
     1196    discard = TRUE;
    11161197
    11171198  /* Discard input sections which are assigned to a section named
    11181199     DISCARD_SECTION_NAME.  */
    11191200  if (strcmp (output->name, DISCARD_SECTION_NAME) == 0)
    1120     discard = true;
     1201    discard = TRUE;
    11211202
    11221203  /* Discard debugging sections if we are stripping debugging
     
    11241205  if ((link_info.strip == strip_debugger || link_info.strip == strip_all)
    11251206      && (flags & SEC_DEBUGGING) != 0)
    1126     discard = true;
     1207    discard = TRUE;
    11271208
    11281209  if (discard)
     
    11381219  if (section->output_section == NULL)
    11391220    {
    1140       boolean first;
     1221      bfd_boolean first;
    11411222      lang_input_section_type *new;
    11421223      flagword flags;
     
    11811262        flags &= ~ SEC_READONLY;
    11821263
     1264      /* Keep SEC_MERGE and SEC_STRINGS only if they are the same.  */
     1265      if (! first
     1266          && ((section->output_section->flags & (SEC_MERGE | SEC_STRINGS))
     1267              != (flags & (SEC_MERGE | SEC_STRINGS))
     1268              || ((flags & SEC_MERGE)
     1269                  && section->output_section->entsize != section->entsize)))
     1270        {
     1271          section->output_section->flags &= ~ (SEC_MERGE | SEC_STRINGS);
     1272          flags &= ~ (SEC_MERGE | SEC_STRINGS);
     1273        }
     1274
     1275      /* For now make .tbss normal section.  */
     1276      if ((flags & SEC_THREAD_LOCAL) && ! link_info.relocateable)
     1277        flags |= SEC_LOAD;
     1278
    11831279      section->output_section->flags |= flags;
     1280
     1281      if (flags & SEC_MERGE)
     1282        section->output_section->entsize = section->entsize;
    11841283
    11851284      /* If SEC_READONLY is not set in the input section, then clear
     
    12111310        output->bfd_section->alignment_power = section->alignment_power;
    12121311
    1213       /* If supplied an aligment, then force it.  */
     1312      /* If supplied an alignment, then force it.  */
    12141313      if (output->section_alignment != -1)
    12151314        output->bfd_section->alignment_power = output->section_alignment;
     
    12301329
    12311330static lang_statement_union_type *
    1232 wild_sort (wild, file, section)
     1331wild_sort (wild, sec, file, section)
    12331332     lang_wild_statement_type *wild;
     1333     struct wildcard_list *sec;
    12341334     lang_input_statement_type *file;
    12351335     asection *section;
     
    12381338  lang_statement_union_type *l;
    12391339
    1240   if (! wild->filenames_sorted && ! wild->sections_sorted)
     1340  if (!wild->filenames_sorted && (sec == NULL || !sec->spec.sorted))
    12411341    return NULL;
    12421342
    12431343  section_name = bfd_get_section_name (file->the_bfd, section);
    1244   for (l = wild->children.head; l != NULL; l = l->next)
     1344  for (l = wild->children.head; l != NULL; l = l->header.next)
    12451345    {
    12461346      lang_input_section_type *ls;
     
    12561356        {
    12571357          const char *fn, *ln;
    1258           boolean fa, la;
     1358          bfd_boolean fa, la;
    12591359          int i;
    12601360
     
    12681368            {
    12691369              fn = bfd_get_filename (bfd_my_archive (file->the_bfd));
    1270               fa = true;
     1370              fa = TRUE;
    12711371            }
    12721372          else
    12731373            {
    12741374              fn = file->filename;
    1275               fa = false;
     1375              fa = FALSE;
    12761376            }
    12771377
     
    12801380            {
    12811381              ln = bfd_get_filename (bfd_my_archive (ls->ifile->the_bfd));
    1282               la = true;
     1382              la = TRUE;
    12831383            }
    12841384          else
    12851385            {
    12861386              ln = ls->ifile->filename;
    1287               la = false;
     1387              la = FALSE;
    12881388            }
    12891389
     
    13121412         looking at the sections for this file.  */
    13131413
    1314       if (wild->sections_sorted)
     1414      if (sec != NULL && sec->spec.sorted)
    13151415        {
    13161416          if (strcmp (section_name,
     
    13291429
    13301430static void
    1331 output_section_callback (ptr, section, file, output)
     1431output_section_callback (ptr, sec, section, file, output)
    13321432     lang_wild_statement_type *ptr;
     1433     struct wildcard_list *sec;
    13331434     asection *section;
    13341435     lang_input_statement_type *file;
     
    13361437{
    13371438  lang_statement_union_type *before;
     1439
     1440  /* Exclude sections that match UNIQUE_SECTION_LIST.  */
     1441  if (unique_section_p (bfd_get_section_name (file->the_bfd, section)))
     1442    return;
    13381443
    13391444  /* If the wild pattern was marked KEEP, the member sections
     
    13421447    section->flags |= SEC_KEEP;
    13431448
    1344   before = wild_sort (ptr, file, section);
     1449  before = wild_sort (ptr, sec, file, section);
    13451450
    13461451  /* Here BEFORE points to the lang_input_section which
     
    13501455
    13511456  if (before == NULL)
    1352     wild_doit (&ptr->children, section,
    1353                (lang_output_section_statement_type *) output,
    1354                file);
     1457    lang_add_section (&ptr->children, section,
     1458                      (lang_output_section_statement_type *) output,
     1459                      file);
    13551460  else
    13561461    {
     
    13591464
    13601465      lang_list_init (&list);
    1361       wild_doit (&list, section,
    1362                  (lang_output_section_statement_type *) output,
    1363                  file);
     1466      lang_add_section (&list, section,
     1467                        (lang_output_section_statement_type *) output,
     1468                        file);
    13641469
    13651470      /* If we are discarding the section, LIST.HEAD will
     
    13671472      if (list.head != NULL)
    13681473        {
    1369           ASSERT (list.head->next == NULL);
     1474          ASSERT (list.head->header.next == NULL);
    13701475
    13711476          for (pp = &ptr->children.head;
    13721477               *pp != before;
    1373                pp = &(*pp)->next)
     1478               pp = &(*pp)->header.next)
    13741479            ASSERT (*pp != NULL);
    13751480
    1376           list.head->next = *pp;
     1481          list.head->header.next = *pp;
    13771482          *pp = list.head;
    13781483        }
     
    14041509  if (search == (lang_input_statement_type *) NULL)
    14051510    search = new_afile (name, lang_input_file_is_file_enum, default_target,
    1406                         false);
     1511                        FALSE);
    14071512
    14081513  /* If we have already added this file, or this file is not real
     
    14141519    return search;
    14151520
    1416   load_symbols (search, (lang_statement_list_type *) NULL);
     1521  if (! load_symbols (search, (lang_statement_list_type *) NULL))
     1522    return NULL;
    14171523
    14181524  return search;
     
    14211527/* Get the symbols for an input file.  */
    14221528
    1423 static void
     1529static bfd_boolean
    14241530load_symbols (entry, place)
    14251531     lang_input_statement_type *entry;
     
    14291535
    14301536  if (entry->loaded)
    1431     return;
     1537    return TRUE;
    14321538
    14331539  ldfile_open_file (entry);
     
    14381544      bfd_error_type err;
    14391545      lang_statement_list_type *hold;
     1546      bfd_boolean bad_load = TRUE;
     1547      bfd_boolean save_ldlang_sysrooted_script;
    14401548
    14411549      err = bfd_get_error ();
     
    14431551      /* See if the emulation has some special knowledge.  */
    14441552      if (ldemul_unrecognized_file (entry))
    1445         return;
     1553        return TRUE;
    14461554
    14471555      if (err == bfd_error_file_ambiguously_recognized)
     
    14571565      else if (err != bfd_error_file_not_recognized
    14581566               || place == NULL)
    1459         einfo (_("%F%B: file not recognized: %E\n"), entry->the_bfd);
     1567          einfo (_("%F%B: file not recognized: %E\n"), entry->the_bfd);
     1568      else
     1569        bad_load = FALSE;
    14601570
    14611571      bfd_close (entry->the_bfd);
     
    14671577      hold = stat_ptr;
    14681578      stat_ptr = place;
    1469 
    1470       ldfile_assumed_script = true;
     1579      save_ldlang_sysrooted_script = ldlang_sysrooted_script;
     1580      ldlang_sysrooted_script = entry->sysrooted;
     1581
     1582      ldfile_assumed_script = TRUE;
    14711583      parser_input = input_script;
    14721584      yyparse ();
    1473       ldfile_assumed_script = false;
    1474 
     1585      ldfile_assumed_script = FALSE;
     1586
     1587      ldlang_sysrooted_script = save_ldlang_sysrooted_script;
    14751588      stat_ptr = hold;
    14761589
    1477       return;
     1590      return ! bad_load;
    14781591    }
    14791592
    14801593  if (ldemul_recognized_file (entry))
    1481     return;
     1594    return TRUE;
    14821595
    14831596  /* We don't call ldlang_add_file for an archive.  Instead, the
     
    14991612      if (entry->whole_archive)
    15001613        {
    1501           bfd *member = bfd_openr_next_archived_file (entry->the_bfd,
    1502                                                       (bfd *) NULL);
    1503           while (member != NULL)
     1614          bfd *member = NULL;
     1615          bfd_boolean loaded = TRUE;
     1616
     1617          for (;;)
    15041618            {
     1619              member = bfd_openr_next_archived_file (entry->the_bfd, member);
     1620
     1621              if (member == NULL)
     1622                break;
     1623
    15051624              if (! bfd_check_format (member, bfd_object))
    1506                 einfo (_("%F%B: object %B in archive is not object\n"),
    1507                        entry->the_bfd, member);
     1625                {
     1626                  einfo (_("%F%B: member %B in archive is not an object\n"),
     1627                         entry->the_bfd, member);
     1628                  loaded = FALSE;
     1629                }
     1630
    15081631              if (! ((*link_info.callbacks->add_archive_element)
    15091632                     (&link_info, member, "--whole-archive")))
    15101633                abort ();
     1634
    15111635              if (! bfd_link_add_symbols (member, &link_info))
    1512                 einfo (_("%F%B: could not read symbols: %E\n"), member);
    1513               member = bfd_openr_next_archived_file (entry->the_bfd,
    1514                                                      member);
     1636                {
     1637                  einfo (_("%F%B: could not read symbols: %E\n"), member);
     1638                  loaded = FALSE;
     1639                }
    15151640            }
    15161641
    1517           entry->loaded = true;
    1518 
    1519           return;
    1520         }
    1521     }
    1522 
    1523   if (! bfd_link_add_symbols (entry->the_bfd, &link_info))
     1642          entry->loaded = loaded;
     1643          return loaded;
     1644        }
     1645      break;
     1646    }
     1647
     1648  if (bfd_link_add_symbols (entry->the_bfd, &link_info))
     1649    entry->loaded = TRUE;
     1650  else
    15241651    einfo (_("%F%B: could not read symbols: %E\n"), entry->the_bfd);
    15251652
    1526   entry->loaded = true;
    1527 }
    1528 
    1529 /* Handle a wild statement.  SECTION or FILE or both may be NULL,
    1530    indicating that it is a wildcard.  Separate lang_input_section
    1531    statements are created for each part of the expansion; they are
    1532    added after the wild statement S.  OUTPUT is the output section.  */
     1653  return entry->loaded;
     1654}
     1655
     1656/* Handle a wild statement.  S->FILENAME or S->SECTION_LIST or both
     1657   may be NULL, indicating that it is a wildcard.  Separate
     1658   lang_input_section statements are created for each part of the
     1659   expansion; they are added after the wild statement S.  OUTPUT is
     1660   the output section.  */
    15331661
    15341662static void
    1535 wild (s, section, file, target, output)
     1663wild (s, target, output)
    15361664     lang_wild_statement_type *s;
    1537      const char *section;
    1538      const char *file;
    15391665     const char *target ATTRIBUTE_UNUSED;
    15401666     lang_output_section_statement_type *output;
    15411667{
    1542   walk_wild (s, section, file, output_section_callback, (PTR) output);
    1543 
    1544   if (section != (char *) NULL
    1545       && strcmp (section, "COMMON") == 0
    1546       && default_common_section == NULL)
    1547     {
    1548       /* Remember the section that common is going to in case we later
    1549          get something which doesn't know where to put it.  */
    1550       default_common_section = output;
    1551     }
    1552 }
    1553 
    1554 /* Return true iff target is the sought target.  */
     1668  struct wildcard_list *sec;
     1669
     1670  walk_wild (s, output_section_callback, (PTR) output);
     1671
     1672  for (sec = s->section_list; sec != NULL; sec = sec->next)
     1673    {
     1674      if (default_common_section != NULL)
     1675        break;
     1676      if (sec->spec.name != NULL && strcmp (sec->spec.name, "COMMON") == 0)
     1677        {
     1678          /* Remember the section that common is going to in case we
     1679             later get something which doesn't know where to put it.  */
     1680          default_common_section = output;
     1681        }
     1682    }
     1683}
     1684
     1685/* Return TRUE iff target is the sought target.  */
    15551686
    15561687static int
     
    15741705
    15751706  while ((c = *src++) != 0)
    1576     {
    1577       if (isupper ((unsigned char) c))
    1578         c = tolower (c);
    1579 
    1580       *dest++ = c;
    1581     }
     1707    *dest++ = TOLOWER (c);
    15821708
    15831709  *dest = 0;
    15841710}
    15851711
    1586 /* Remove the first occurance of needle (if any) in haystack
     1712/* Remove the first occurrence of needle (if any) in haystack
    15871713   from haystack.  */
    15881714
     
    17171843}
    17181844
     1845const char *
     1846lang_get_output_target ()
     1847{
     1848  const char *target;
     1849
     1850  /* Has the user told us which output format to use?  */
     1851  if (output_target != (char *) NULL)
     1852    return output_target;
     1853
     1854  /* No - has the current target been set to something other than
     1855     the default?  */
     1856  if (current_target != default_target)
     1857    return current_target;
     1858
     1859  /* No - can we determine the format of the first input file?  */
     1860  target = get_first_input_target ();
     1861  if (target != NULL)
     1862    return target;
     1863
     1864  /* Failed - use the default output target.  */
     1865  return default_target;
     1866}
     1867
    17191868/* Open the output file.  */
    17201869
     
    17251874  bfd *output;
    17261875
    1727   /* Has the user told us which output format to use?  */
    1728   if (output_target == (char *) NULL)
    1729     {
    1730       /* No - has the current target been set to something other than
    1731          the default?  */
    1732       if (current_target != default_target)
    1733         output_target = current_target;
    1734 
    1735       /* No - can we determine the format of the first input file?  */
    1736       else
    1737         {
    1738           output_target = get_first_input_target ();
    1739 
    1740           /* Failed - use the default output target.  */
    1741           if (output_target == NULL)
    1742             output_target = default_target;
    1743         }
    1744     }
     1876  output_target = lang_get_output_target ();
    17451877
    17461878  /* Has the user requested a particular endianness on the command
     
    18021934    }
    18031935
    1804   delete_output_file_on_failure = true;
     1936  delete_output_file_on_failure = TRUE;
    18051937
    18061938#if 0
     
    18601992open_input_bfds (s, force)
    18611993     lang_statement_union_type *s;
    1862      boolean force;
    1863 {
    1864   for (; s != (lang_statement_union_type *) NULL; s = s->next)
     1994     bfd_boolean force;
     1995{
     1996  for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
    18651997    {
    18661998      switch (s->header.type)
     
    18902022              {
    18912023                undefs = link_info.hash->undefs_tail;
    1892                 open_input_bfds (s->group_statement.children.head, true);
     2024                open_input_bfds (s->group_statement.children.head, TRUE);
    18932025              }
    18942026            while (undefs != link_info.hash->undefs_tail);
     
    19142046                  && bfd_check_format (s->input_statement.the_bfd,
    19152047                                       bfd_archive))
    1916                 s->input_statement.loaded = false;
     2048                s->input_statement.loaded = FALSE;
    19172049
    19182050              lang_list_init (&add);
    19192051
    1920               load_symbols (&s->input_statement, &add);
     2052              if (! load_symbols (&s->input_statement, &add))
     2053                config.make_executable = FALSE;
    19212054
    19222055              if (add.head != NULL)
    19232056                {
    1924                   *add.tail = s->next;
    1925                   s->next = add.head;
     2057                  *add.tail = s->header.next;
     2058                  s->header.next = add.head;
    19262059                }
    19272060            }
     
    19452078  default_common_section = lang_output_section_statement_lookup (".bss");
    19462079
    1947   if (placed_commons == false)
     2080  if (!placed_commons)
    19482081    {
    19492082      lang_wild_statement_type *new =
     
    19592092
    19602093/* Add the supplied name to the symbol table as an undefined reference.
    1961    Remove items from the chain as we open input bfds.  */
    1962 typedef struct ldlang_undef_chain_list
    1963 {
    1964   struct ldlang_undef_chain_list *next;
    1965   char *name;
    1966 }                      ldlang_undef_chain_list_type;
    1967 
    1968 static ldlang_undef_chain_list_type *ldlang_undef_chain_list_head;
     2094   This is a two step process as the symbol table doesn't even exist at
     2095   the time the ld command line is processed.  First we put the name
     2096   on a list, then, once the output file has been opened, transfer the
     2097   name to the symbol table.  */
     2098
     2099typedef struct bfd_sym_chain ldlang_undef_chain_list_type;
     2100
     2101#define ldlang_undef_chain_list_head entry_symbol.next
    19692102
    19702103void
     
    19802113
    19812114  new->name = xstrdup (name);
     2115
     2116  if (output_bfd != NULL)
     2117    insert_undefined (new->name);
     2118}
     2119
     2120/* Insert NAME as undefined in the symbol table.  */
     2121
     2122static void
     2123insert_undefined (name)
     2124     const char *name;
     2125{
     2126  struct bfd_link_hash_entry *h;
     2127
     2128  h = bfd_link_hash_lookup (link_info.hash, name, TRUE, FALSE, TRUE);
     2129  if (h == (struct bfd_link_hash_entry *) NULL)
     2130    einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
     2131  if (h->type == bfd_link_hash_new)
     2132    {
     2133      h->type = bfd_link_hash_undefined;
     2134      h->u.undef.abfd = NULL;
     2135      bfd_link_add_undef (link_info.hash, h);
     2136    }
    19822137}
    19832138
     
    19952150       ptr = ptr->next)
    19962151    {
    1997       struct bfd_link_hash_entry *h;
    1998 
    1999       h = bfd_link_hash_lookup (link_info.hash, ptr->name, true, false, true);
    2000       if (h == (struct bfd_link_hash_entry *) NULL)
    2001         einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
    2002       if (h->type == bfd_link_hash_new)
    2003         {
    2004           h->type = bfd_link_hash_undefined;
    2005           h->u.undef.abfd = NULL;
    2006           bfd_link_add_undef (link_info.hash, h);
    2007         }
    2008     }
    2009 }
    2010 
    2011 /* Open input files and attatch to output sections.  */
     2152      insert_undefined (ptr->name);
     2153    }
     2154}
     2155
     2156/* Open input files and attach to output sections.  */
    20122157
    20132158static void
     
    20172162     lang_output_section_statement_type *output_section_statement;
    20182163{
    2019   for (; s != (lang_statement_union_type *) NULL; s = s->next)
     2164  for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
    20202165    {
    20212166      switch (s->header.type)
    20222167        {
    2023 
    20242168        case lang_wild_statement_enum:
    2025           wild (&s->wild_statement, s->wild_statement.section_name,
    2026                 s->wild_statement.filename, target,
    2027                 output_section_statement);
    2028 
     2169          wild (&s->wild_statement, target, output_section_statement);
    20292170          break;
    20302171        case lang_constructors_statement_enum:
     
    20832224          }
    20842225          break;
     2226        }
     2227    }
     2228}
     2229
     2230/* An output section might have been removed after its statement was
     2231   added.  For example, ldemul_before_allocation can remove dynamic
     2232   sections if they turn out to be not needed.  Clean them up here.  */
     2233
     2234static void
     2235strip_excluded_output_sections ()
     2236{
     2237  lang_statement_union_type *u;
     2238
     2239  for (u = lang_output_section_statement.head;
     2240       u != NULL;
     2241       u = u->output_section_statement.next)
     2242    {
     2243      lang_output_section_statement_type *os;
     2244      asection *s;
     2245
     2246      os = &u->output_section_statement;
     2247      s = os->bfd_section;
     2248      if (s != NULL && (s->flags & SEC_EXCLUDE) != 0)
     2249        {
     2250          asection **p;
     2251
     2252          os->bfd_section = NULL;
     2253
     2254          for (p = &output_bfd->sections; *p; p = &(*p)->next)
     2255            if (*p == s)
     2256              {
     2257                bfd_section_list_remove (output_bfd, p);
     2258                output_bfd->section_count--;
     2259                break;
     2260              }
    20852261        }
    20862262    }
     
    21472323                          lang_final_phase_enum, print_dot, &print_dot);
    21482324  if (result.valid_p)
    2149     minfo ("0x%V", result.value + result.section->bfd_section->vma);
     2325    {
     2326      const char *dst;
     2327      bfd_vma value;
     2328
     2329      value = result.value + result.section->bfd_section->vma;
     2330      dst = assignment->exp->assign.dst;
     2331
     2332      minfo ("0x%V", value);
     2333      if (dst[0] == '.' && dst[1] == 0)
     2334        print_dot = value;
     2335    }
    21502336  else
    21512337    {
     
    21762362   via bfd_link_hash_traverse.  */
    21772363
    2178 static boolean
     2364static bfd_boolean
    21792365print_one_symbol (hash_entry, ptr)
    21802366     struct bfd_link_hash_entry *hash_entry;
     
    21992385    }
    22002386
    2201   return true;
     2387  return TRUE;
    22022388}
    22032389
     
    22662452     lang_fill_statement_type *fill;
    22672453{
    2268   fprintf (config.map_file, " FILL mask 0x%x\n", fill->fill);
     2454  size_t size;
     2455  unsigned char *p;
     2456  fputs (" FILL mask 0x", config.map_file);
     2457  for (p = fill->fill->data, size = fill->fill->size; size != 0; p++, size--)
     2458    fprintf (config.map_file, "%02x", *p);
     2459  fputs ("\n", config.map_file);
    22692460}
    22702461
     
    23952586  if (s->output_section != NULL)
    23962587    addr += s->output_section->vma;
    2397   minfo ("0x%V %W", addr, s->size);
    2398 
    2399   if (s->fill != 0)
    2400     minfo (" %u", s->fill);
     2588  minfo ("0x%V %W ", addr, s->size);
     2589
     2590  if (s->fill->size != 0)
     2591    {
     2592      size_t size;
     2593      unsigned char *p;
     2594      for (p = s->fill->data, size = s->fill->size; size != 0; p++, size--)
     2595        fprintf (config.map_file, "%02x", *p);
     2596    }
    24012597
    24022598  print_nl ();
     
    24102606     lang_output_section_statement_type *os;
    24112607{
     2608  struct wildcard_list *sec;
     2609
    24122610  print_space ();
    24132611
    24142612  if (w->filenames_sorted)
    24152613    minfo ("SORT(");
    2416   if (w->exclude_filename_list != NULL)
    2417     {
    2418       name_list *tmp;
    2419       minfo ("EXCLUDE_FILE ( %s", w->exclude_filename_list->name);
    2420       for (tmp = w->exclude_filename_list->next; tmp; tmp = tmp->next)
    2421         minfo (", %s", tmp->name);
    2422       minfo (")");
    2423     }
    24242614  if (w->filename != NULL)
    24252615    minfo ("%s", w->filename);
     
    24302620
    24312621  minfo ("(");
    2432   if (w->sections_sorted)
    2433     minfo ("SORT(");
    2434   if (w->section_name != NULL)
    2435     minfo ("%s", w->section_name);
    2436   else
    2437     minfo ("*");
    2438   if (w->sections_sorted)
    2439     minfo (")");
     2622  for (sec = w->section_list; sec; sec = sec->next)
     2623    {
     2624      if (sec->spec.sorted)
     2625        minfo ("SORT(");
     2626      if (sec->spec.exclude_name_list != NULL)
     2627        {
     2628          name_list *tmp;
     2629          minfo ("EXCLUDE_FILE(%s", sec->spec.exclude_name_list->name);
     2630          for (tmp = sec->spec.exclude_name_list->next; tmp; tmp = tmp->next)
     2631            minfo (" %s", tmp->name);
     2632          minfo (") ");
     2633        }
     2634      if (sec->spec.name != NULL)
     2635        minfo ("%s", sec->spec.name);
     2636      else
     2637        minfo ("*");
     2638      if (sec->spec.sorted)
     2639        minfo (")");
     2640      if (sec->next)
     2641        minfo (" ");
     2642    }
    24402643  minfo (")");
    24412644
     
    24682671    {
    24692672      print_statement (s, os);
    2470       s = s->next;
     2673      s = s->header.next;
    24712674    }
    24722675}
     
    25742777        {
    25752778          print_statement (s, abs_output_section);
    2576           s = s->next;
     2779          s = s->header.next;
    25772780        }
    25782781    }
     
    25812784}
    25822785
     2786static void
     2787insert_pad (ptr, fill, alignment_needed, output_section, dot)
     2788     lang_statement_union_type **ptr;
     2789     fill_type *fill;
     2790     unsigned int alignment_needed;
     2791     asection *output_section;
     2792     bfd_vma dot;
     2793{
     2794  static fill_type zero_fill = { 1, { 0 } };
     2795  lang_statement_union_type *pad;
     2796
     2797  pad = ((lang_statement_union_type *)
     2798         ((char *) ptr - offsetof (lang_statement_union_type, header.next)));
     2799  if (ptr != &statement_list.head
     2800      && pad->header.type == lang_padding_statement_enum
     2801      && pad->padding_statement.output_section == output_section)
     2802    {
     2803      /* Use the existing pad statement.  The above test on output
     2804         section is probably redundant, but it doesn't hurt to check.  */
     2805    }
     2806  else
     2807    {
     2808      /* Make a new padding statement, linked into existing chain.  */
     2809      pad = ((lang_statement_union_type *)
     2810             stat_alloc (sizeof (lang_padding_statement_type)));
     2811      pad->header.next = *ptr;
     2812      *ptr = pad;
     2813      pad->header.type = lang_padding_statement_enum;
     2814      pad->padding_statement.output_section = output_section;
     2815      if (fill == (fill_type *) 0)
     2816        fill = &zero_fill;
     2817      pad->padding_statement.fill = fill;
     2818    }
     2819  pad->padding_statement.output_offset = dot - output_section->vma;
     2820  pad->padding_statement.size = alignment_needed;
     2821  output_section->_raw_size += alignment_needed;
     2822}
     2823
     2824/* Work out how much this section will move the dot point.  */
     2825
    25832826static bfd_vma
    2584 insert_pad (this_ptr, fill, power, output_section_statement, dot)
    2585      lang_statement_union_type **this_ptr;
    2586      fill_type fill;
    2587      unsigned int power;
    2588      asection *output_section_statement;
    2589      bfd_vma dot;
    2590 {
    2591   /* Align this section first to the
    2592      input sections requirement, then
    2593      to the output section's requirement.
    2594      If this alignment is > than any seen before,
    2595      then record it too. Perform the alignment by
    2596      inserting a magic 'padding' statement.  */
    2597 
    2598   unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
    2599                                                 ldfile_output_machine);
    2600   unsigned int alignment_needed = align_power (dot, power) - dot;
    2601 
    2602   if (alignment_needed != 0)
    2603     {
    2604       lang_statement_union_type *new =
    2605         ((lang_statement_union_type *)
    2606          stat_alloc (sizeof (lang_padding_statement_type)));
    2607 
    2608       /* Link into existing chain.  */
    2609       new->header.next = *this_ptr;
    2610       *this_ptr = new;
    2611       new->header.type = lang_padding_statement_enum;
    2612       new->padding_statement.output_section = output_section_statement;
    2613       new->padding_statement.output_offset =
    2614         dot - output_section_statement->vma;
    2615       new->padding_statement.fill = fill;
    2616       new->padding_statement.size = alignment_needed * opb;
    2617     }
    2618 
    2619   /* Remember the most restrictive alignment.  */
    2620   if (power > output_section_statement->alignment_power)
    2621     {
    2622       output_section_statement->alignment_power = power;
    2623     }
    2624   output_section_statement->_raw_size += alignment_needed * opb;
    2625 
    2626   return dot + alignment_needed;
    2627 }
    2628 
    2629 /* Work out how much this section will move the dot point.  */
    2630 
    2631 static bfd_vma
    2632 size_input_section (this_ptr, output_section_statement, fill, dot, relax)
     2827size_input_section (this_ptr, output_section_statement, fill, dot)
    26332828     lang_statement_union_type **this_ptr;
    26342829     lang_output_section_statement_type *output_section_statement;
    2635      fill_type fill;
     2830     fill_type *fill;
    26362831     bfd_vma dot;
    2637      boolean relax ATTRIBUTE_UNUSED;
    26382832{
    26392833  lang_input_section_type *is = &((*this_ptr)->input_section);
    26402834  asection *i = is->section;
    2641   unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
    2642                                                 ldfile_output_machine);
    2643 
    2644   if (is->ifile->just_syms_flag == false)
    2645     {
     2835
     2836  if (!is->ifile->just_syms_flag)
     2837    {
     2838      unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
     2839                                                    ldfile_output_machine);
     2840      unsigned int alignment_needed;
     2841      asection *o;
     2842
     2843      /* Align this section first to the input sections requirement,
     2844         then to the output section's requirement.  If this alignment
     2845         is greater than any seen before, then record it too.  Perform
     2846         the alignment by inserting a magic 'padding' statement.  */
     2847
    26462848      if (output_section_statement->subsection_alignment != -1)
    2647        i->alignment_power =
    2648         output_section_statement->subsection_alignment;
    2649 
    2650       dot = insert_pad (this_ptr, fill, i->alignment_power,
    2651                         output_section_statement->bfd_section, dot);
     2849        i->alignment_power = output_section_statement->subsection_alignment;
     2850
     2851      o = output_section_statement->bfd_section;
     2852      if (o->alignment_power < i->alignment_power)
     2853        o->alignment_power = i->alignment_power;
     2854
     2855      alignment_needed = align_power (dot, i->alignment_power) - dot;
     2856
     2857      if (alignment_needed != 0)
     2858        {
     2859          insert_pad (this_ptr, fill, alignment_needed * opb, o, dot);
     2860          dot += alignment_needed;
     2861        }
    26522862
    26532863      /* Remember where in the output section this input section goes.  */
    26542864
    2655       i->output_offset = dot - output_section_statement->bfd_section->vma;
     2865      i->output_offset = dot - o->vma;
    26562866
    26572867      /* Mark how big the output section must be to contain this now.  */
     
    26602870      else
    26612871        dot += i->_raw_size / opb;
    2662       output_section_statement->bfd_section->_raw_size =
    2663         (dot - output_section_statement->bfd_section->vma) * opb;
     2872      o->_raw_size = (dot - o->vma) * opb;
    26642873    }
    26652874  else
     
    27322941}
    27332942
    2734 /* This variable indicates whether bfd_relax_section should be called
    2735    again.  */
    2736 
    2737 static boolean relax_again;
    2738 
    27392943/* Make sure the new address is within the region.  We explicitly permit the
    27402944   current address to be at the exact end of the region when the address is
     
    27522956       || (region->current - region->origin > region->length))
    27532957      && ((region->current != region->origin + region->length)
    2754            || base == 0))
     2958          || base == 0))
    27552959    {
    27562960      if (tree != (etree_type *) NULL)
    2757         {
    2758           einfo (_("%X%P: address 0x%v of %B section %s is not within region %s\n"),
    2759                 region->current,
    2760                 os->bfd_section->owner,
    2761                 os->bfd_section->name,
    2762                 region->name);
    2763         }
     2961        {
     2962          einfo (_("%X%P: address 0x%v of %B section %s is not within region %s\n"),
     2963                region->current,
     2964                os->bfd_section->owner,
     2965                os->bfd_section->name,
     2966                region->name);
     2967        }
    27642968      else
    2765         {
    2766           einfo (_("%X%P: region %s is full (%B section %s)\n"),
    2767                 region->name,
    2768                 os->bfd_section->owner,
    2769                 os->bfd_section->name);
    2770         }
     2969        {
     2970          einfo (_("%X%P: region %s is full (%B section %s)\n"),
     2971                region->name,
     2972                os->bfd_section->owner,
     2973                os->bfd_section->name);
     2974        }
    27712975      /* Reset the region pointer.  */
    27722976      region->current = region->origin;
     
    27762980/* Set the sizes for all the output sections.  */
    27772981
    2778 bfd_vma
    2779 lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
     2982static bfd_vma
     2983lang_size_sections_1 (s, output_section_statement, prev, fill, dot, relax,
     2984                      check_regions)
    27802985     lang_statement_union_type *s;
    27812986     lang_output_section_statement_type *output_section_statement;
    27822987     lang_statement_union_type **prev;
    2783      fill_type fill;
     2988     fill_type *fill;
    27842989     bfd_vma dot;
    2785      boolean relax;
     2990     bfd_boolean *relax;
     2991     bfd_boolean check_regions;
    27862992{
    27872993  unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
     
    27892995
    27902996  /* Size up the sections from their constituent parts.  */
    2791   for (; s != (lang_statement_union_type *) NULL; s = s->next)
     2997  for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
    27922998    {
    27932999      switch (s->header.type)
     
    28123018
    28133019                if (os->children.head == NULL
    2814                     || os->children.head->next != NULL
     3020                    || os->children.head->header.next != NULL
    28153021                    || os->children.head->header.type != lang_input_section_enum)
    28163022                  einfo (_("%P%X: Internal error on COFF shared library section %s\n"),
     
    28503056                    if ((bfd_get_section_flags (output_bfd, os->bfd_section)
    28513057                         & (SEC_ALLOC | SEC_LOAD)) != 0
     3058                        && (bfd_get_section_flags (output_bfd, os->bfd_section)
     3059                            & SEC_NEVER_LOAD) == 0
    28523060                        && ! link_info.relocateable
     3061                        && check_regions
    28533062                        && strcmp (os->region->name, "*default*") == 0
    28543063                        && lang_memory_region_list != NULL
     
    28833092                                       lang_allocating_phase_enum,
    28843093                                       dot, &dot);
    2885                     if (r.valid_p == false)
    2886                       {
    2887                         einfo (_("%F%S: non constant address expression for section %s\n"),
    2888                                os->name);
    2889                       }
     3094                    if (!r.valid_p)
     3095                      einfo (_("%F%S: non constant address expression for section %s\n"),
     3096                             os->name);
     3097
    28903098                    dot = r.value + r.section->bfd_section->vma;
    28913099                  }
     
    29023110              }
    29033111
    2904             (void) lang_size_sections (os->children.head, os,
    2905                                        &os->children.head,
    2906                                        os->fill, dot, relax);
     3112            lang_size_sections_1 (os->children.head, os, &os->children.head,
     3113                                  os->fill, dot, relax, check_regions);
    29073114
    29083115            /* Put the section within the requested block size, or
    29093116               align at the block boundary.  */
    2910             after = ALIGN_N (os->bfd_section->vma
     3117            after = align_n (os->bfd_section->vma
    29113118                             + os->bfd_section->_raw_size / opb,
    2912                              /* The coercion here is important, see ld.h.  */
    29133119                             (bfd_vma) os->block_value);
    29143120
    29153121            if (bfd_is_abs_section (os->bfd_section))
    29163122              ASSERT (after == os->bfd_section->vma);
     3123            else if ((os->bfd_section->flags & SEC_HAS_CONTENTS) == 0
     3124                     && (os->bfd_section->flags & SEC_THREAD_LOCAL)
     3125                     && ! link_info.relocateable)
     3126              os->bfd_section->_raw_size = 0;
    29173127            else
    29183128              os->bfd_section->_raw_size =
    29193129                (after - os->bfd_section->vma) * opb;
     3130
    29203131            dot = os->bfd_section->vma + os->bfd_section->_raw_size / opb;
    2921             os->processed = true;
     3132            os->processed = TRUE;
     3133
     3134            if (os->update_dot_tree != 0)
     3135              exp_fold_tree (os->update_dot_tree, abs_output_section,
     3136                             lang_allocating_phase_enum, dot, &dot);
    29223137
    29233138            /* Update dot in the region ?
     
    29373152                os->region->current = dot;
    29383153
    2939                 /* Make sure the new address is within the region.  */
    2940                 os_region_check (os, os->region, os->addr_tree,
    2941                                  os->bfd_section->vma);
     3154                if (check_regions)
     3155                  /* Make sure the new address is within the region.  */
     3156                  os_region_check (os, os->region, os->addr_tree,
     3157                                   os->bfd_section->vma);
    29423158
    29433159                /* If there's no load address specified, use the run
     
    29463162                  os->lma_region = os->region;
    29473163
    2948                 if (os->lma_region != NULL)
     3164                if (os->lma_region != NULL && os->lma_region != os->region)
    29493165                  {
    2950                     if (os->load_base != NULL)
    2951                       {
    2952                         einfo (_("%X%P: use an absolute load address or a load memory region, not both\n"));
    2953                       }
    2954                     else
    2955                       {
    2956                         /* Don't allocate twice.  */
    2957                         if (os->lma_region != os->region)
    2958                           {
    2959                             /* Set load_base, which will be handled later.  */
    2960                             os->load_base =
    2961                               exp_intop (os->lma_region->current);
    2962                             os->lma_region->current +=
    2963                               os->bfd_section->_raw_size / opb;
    2964                             os_region_check (os, os->lma_region, NULL,
    2965                                              os->bfd_section->lma);
    2966                           }
    2967                       }
     3166                    /* Set load_base, which will be handled later.  */
     3167                    os->load_base = exp_intop (os->lma_region->current);
     3168                    os->lma_region->current +=
     3169                      os->bfd_section->_raw_size / opb;
     3170                    if (check_regions)
     3171                      os_region_check (os, os->lma_region, NULL,
     3172                                       os->bfd_section->lma);
    29683173                  }
    29693174              }
     
    29723177
    29733178        case lang_constructors_statement_enum:
    2974           dot = lang_size_sections (constructor_list.head,
    2975                                     output_section_statement,
    2976                                     &s->wild_statement.children.head,
    2977                                     fill,
    2978                                     dot, relax);
     3179          dot = lang_size_sections_1 (constructor_list.head,
     3180                                      output_section_statement,
     3181                                      &s->wild_statement.children.head,
     3182                                      fill, dot, relax, check_regions);
    29793183          break;
    29803184
     
    30373241        case lang_wild_statement_enum:
    30383242
    3039           dot = lang_size_sections (s->wild_statement.children.head,
    3040                                     output_section_statement,
    3041                                     &s->wild_statement.children.head,
    3042                                     fill, dot, relax);
     3243          dot = lang_size_sections_1 (s->wild_statement.children.head,
     3244                                      output_section_statement,
     3245                                      &s->wild_statement.children.head,
     3246                                      fill, dot, relax, check_regions);
    30433247
    30443248          break;
     
    30633267            else
    30643268              {
    3065                 boolean again;
     3269                bfd_boolean again;
    30663270
    30673271                if (! bfd_relax_section (i->owner, i, &link_info, &again))
    30683272                  einfo (_("%P%F: can't relax section: %E\n"));
    30693273                if (again)
    3070                   relax_again = true;
     3274                  *relax = TRUE;
    30713275              }
    3072             dot = size_input_section (prev,
    3073                                       output_section_statement,
    3074                                       output_section_statement->fill,
    3075                                       dot, relax);
     3276            dot = size_input_section (prev, output_section_statement,
     3277                                      output_section_statement->fill, dot);
    30763278          }
    30773279          break;
     
    30963298            if (newdot != dot)
    30973299              {
    3098                 /* The assignment changed dot.  Insert a pad.  */
    30993300                if (output_section_statement == abs_output_section)
    31003301                  {
     
    31033304                    lang_memory_region_lookup ("*default*")->current = newdot;
    31043305                  }
    3105                 else if (!relax)
     3306                else
    31063307                  {
    3107                     lang_statement_union_type *new =
    3108                       ((lang_statement_union_type *)
    3109                        stat_alloc (sizeof (lang_padding_statement_type)));
    3110 
    3111                     /* Link into existing chain.  */
    3112                     new->header.next = *prev;
    3113                     *prev = new;
    3114                     new->header.type = lang_padding_statement_enum;
    3115                     new->padding_statement.output_section =
    3116                       output_section_statement->bfd_section;
    3117                     new->padding_statement.output_offset =
    3118                       dot - output_section_statement->bfd_section->vma;
    3119                     new->padding_statement.fill = fill;
    3120                     new->padding_statement.size = (newdot - dot) * opb;
    3121                     output_section_statement->bfd_section->_raw_size +=
    3122                       new->padding_statement.size;
     3308                    /* Insert a pad after this statement.  We can't
     3309                       put the pad before when relaxing, in case the
     3310                       assignment references dot.  */
     3311                    insert_pad (&s->header.next, fill, (newdot - dot) * opb,
     3312                                output_section_statement->bfd_section, dot);
     3313
     3314                    /* Don't neuter the pad below when relaxing.  */
     3315                    s = s->header.next;
    31233316                  }
    31243317
     
    31293322
    31303323        case lang_padding_statement_enum:
    3131           /* If we are relaxing, and this is not the first pass, some
    3132              padding statements may have been inserted during previous
    3133              passes.  We may have to move the padding statement to a new
    3134              location if dot has a different value at this point in this
    3135              pass than it did at this point in the previous pass.  */
    3136           s->padding_statement.output_offset =
    3137             dot - output_section_statement->bfd_section->vma;
    3138           dot += s->padding_statement.size / opb;
    3139           output_section_statement->bfd_section->_raw_size +=
    3140             s->padding_statement.size;
     3324          /* If this is the first time lang_size_sections is called,
     3325             we won't have any padding statements.  If this is the
     3326             second or later passes when relaxing, we should allow
     3327             padding to shrink.  If padding is needed on this pass, it
     3328             will be added back in.  */
     3329          s->padding_statement.size = 0;
     3330
     3331          /* Make sure output_offset is valid.  If relaxation shrinks
     3332             the section and this pad isn't needed, it's possible to
     3333             have output_offset larger than the final size of the
     3334             section.  bfd_set_section_contents will complain even for
     3335             a pad size of zero.  */
     3336          s->padding_statement.output_offset
     3337            = dot - output_section_statement->bfd_section->vma;
    31413338          break;
    31423339
    31433340        case lang_group_statement_enum:
    3144           dot = lang_size_sections (s->group_statement.children.head,
    3145                                     output_section_statement,
    3146                                     &s->group_statement.children.head,
    3147                                     fill, dot, relax);
     3341          dot = lang_size_sections_1 (s->group_statement.children.head,
     3342                                      output_section_statement,
     3343                                      &s->group_statement.children.head,
     3344                                      fill, dot, relax, check_regions);
    31483345          break;
    31493346
     
    31523349          break;
    31533350
    3154           /* This can only get here when relaxing is turned on.  */
    3155 
     3351          /* We can only get here when relaxing is turned on.  */
    31563352        case lang_address_statement_enum:
    31573353          break;
     
    31603356    }
    31613357  return dot;
     3358}
     3359
     3360bfd_vma
     3361lang_size_sections (s, output_section_statement, prev, fill, dot, relax,
     3362                    check_regions)
     3363     lang_statement_union_type *s;
     3364     lang_output_section_statement_type *output_section_statement;
     3365     lang_statement_union_type **prev;
     3366     fill_type *fill;
     3367     bfd_vma dot;
     3368     bfd_boolean *relax;
     3369     bfd_boolean check_regions;
     3370{
     3371  bfd_vma result;
     3372
     3373  exp_data_seg.phase = exp_dataseg_none;
     3374  result = lang_size_sections_1 (s, output_section_statement, prev, fill,
     3375                                 dot, relax, check_regions);
     3376  if (exp_data_seg.phase == exp_dataseg_end_seen)
     3377    {
     3378      /* If DATA_SEGMENT_ALIGN DATA_SEGMENT_END pair was seen, check whether
     3379         a page could be saved in the data segment.  */
     3380      bfd_vma first, last;
     3381
     3382      first = -exp_data_seg.base & (exp_data_seg.pagesize - 1);
     3383      last = exp_data_seg.end & (exp_data_seg.pagesize - 1);
     3384      if (first && last
     3385          && ((exp_data_seg.base & ~(exp_data_seg.pagesize - 1))
     3386              != (exp_data_seg.end & ~(exp_data_seg.pagesize - 1)))
     3387          && first + last <= exp_data_seg.pagesize)
     3388        {
     3389          exp_data_seg.phase = exp_dataseg_adjust;
     3390          result = lang_size_sections_1 (s, output_section_statement, prev,
     3391                                         fill, dot, relax, check_regions);
     3392        }
     3393    }
     3394
     3395  return result;
    31623396}
    31633397
     
    31663400     lang_statement_union_type *s;
    31673401     lang_output_section_statement_type *output_section_statement;
    3168      fill_type fill;
     3402     fill_type *fill;
    31693403     bfd_vma dot;
    31703404{
     
    31723406                                                ldfile_output_machine);
    31733407
    3174   for (; s != (lang_statement_union_type *) NULL; s = s->next)
     3408  for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
    31753409    {
    31763410      switch (s->header.type)
     
    32323466                                   lang_final_phase_enum, dot, &dot);
    32333467            s->data_statement.value = value.value;
    3234             if (value.valid_p == false)
     3468            if (!value.valid_p)
    32353469              einfo (_("%F%P: invalid data statement\n"));
    32363470          }
    3237           {
    3238             unsigned int size;
     3471          {
     3472            unsigned int size;
    32393473            switch (s->data_statement.type)
    32403474              {
     
    32693503                                   lang_final_phase_enum, dot, &dot);
    32703504            s->reloc_statement.addend_value = value.value;
    3271             if (value.valid_p == false)
     3505            if (!value.valid_p)
    32723506              einfo (_("%F%P: invalid reloc statement\n"));
    32733507          }
     
    33483582
    33493583      sprintf (buf, ".startof.%s", secname);
    3350       h = bfd_link_hash_lookup (link_info.hash, buf, false, false, true);
     3584      h = bfd_link_hash_lookup (link_info.hash, buf, FALSE, FALSE, TRUE);
    33513585      if (h != NULL && h->type == bfd_link_hash_undefined)
    33523586        {
     
    33573591
    33583592      sprintf (buf, ".sizeof.%s", secname);
    3359       h = bfd_link_hash_lookup (link_info.hash, buf, false, false, true);
     3593      h = bfd_link_hash_lookup (link_info.hash, buf, FALSE, FALSE, TRUE);
    33603594      if (h != NULL && h->type == bfd_link_hash_undefined)
    33613595        {
    3362           unsigned opb;
    3363 
    3364           opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
     3596          unsigned opb;
     3597
     3598          opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
    33653599                                               ldfile_output_machine);
    33663600          h->type = bfd_link_hash_defined;
     
    33803614{
    33813615  struct bfd_link_hash_entry *h;
    3382   boolean warn;
     3616  bfd_boolean warn;
    33833617
    33843618  if (link_info.relocateable || link_info.shared)
    3385     warn = false;
     3619    warn = FALSE;
    33863620  else
    3387     warn = true;
    3388 
    3389   if (entry_symbol == (char *) NULL)
     3621    warn = TRUE;
     3622
     3623  if (entry_symbol.name == (const char *) NULL)
    33903624    {
    33913625      /* No entry has been specified.  Look for start, but don't warn
    33923626         if we don't find it.  */
    3393       entry_symbol = "start";
    3394       warn = false;
    3395     }
    3396 
    3397   h = bfd_link_hash_lookup (link_info.hash, entry_symbol, false, false, true);
     3627      entry_symbol.name = "start";
     3628      warn = FALSE;
     3629    }
     3630
     3631  h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name,
     3632                            FALSE, FALSE, TRUE);
    33983633  if (h != (struct bfd_link_hash_entry *) NULL
    33993634      && (h->type == bfd_link_hash_defined
     
    34083643             + h->u.def.section->output_offset);
    34093644      if (! bfd_set_start_address (output_bfd, val))
    3410         einfo (_("%P%F:%s: can't set start address\n"), entry_symbol);
     3645        einfo (_("%P%F:%s: can't set start address\n"), entry_symbol.name);
    34113646    }
    34123647  else
     
    34173652      /* We couldn't find the entry symbol.  Try parsing it as a
    34183653         number.  */
    3419       val = bfd_scan_vma (entry_symbol, &send, 0);
     3654      val = bfd_scan_vma (entry_symbol.name, &send, 0);
    34203655      if (*send == '\0')
    34213656        {
     
    34293664          /* Can't find the entry symbol, and it's not a number.  Use
    34303665             the first address in the text section.  */
    3431           ts = bfd_get_section_by_name (output_bfd, ".text");
     3666          ts = bfd_get_section_by_name (output_bfd, entry_section);
    34323667          if (ts != (asection *) NULL)
    34333668            {
    34343669              if (warn)
    34353670                einfo (_("%P: warning: cannot find entry symbol %s; defaulting to %V\n"),
    3436                        entry_symbol, bfd_get_section_vma (output_bfd, ts));
     3671                       entry_symbol.name,
     3672                       bfd_get_section_vma (output_bfd, ts));
    34373673              if (! bfd_set_start_address (output_bfd,
    34383674                                           bfd_get_section_vma (output_bfd,
     
    34443680              if (warn)
    34453681                einfo (_("%P: warning: cannot find entry symbol %s; not setting start address\n"),
    3446                        entry_symbol);
     3682                       entry_symbol.name);
    34473683            }
    34483684        }
     
    34803716    {
    34813717      input_bfd = file->input_statement.the_bfd;
    3482       compatible = bfd_arch_get_compatible (input_bfd,
    3483                                             output_bfd);
     3718      compatible = bfd_arch_get_compatible (input_bfd, output_bfd,
     3719                                            command_line.accept_unknown_input_arch);
     3720
     3721      /* In general it is not possible to perform a relocatable
     3722         link between differing object formats when the input
     3723         file has relocations, because the relocations in the
     3724         input format may not have equivalent representations in
     3725         the output format (and besides BFD does not translate
     3726         relocs for other link purposes than a final link).  */
     3727      if ((link_info.relocateable || link_info.emitrelocations)
     3728          && (compatible == NULL
     3729              || bfd_get_flavour (input_bfd) != bfd_get_flavour (output_bfd))
     3730          && (bfd_get_file_flags (input_bfd) & HAS_RELOC) != 0)
     3731        {
     3732          einfo (_("%P%F: Relocatable linking with relocations from format %s (%B) to format %s (%B) is not supported\n"),
     3733                 bfd_get_target (input_bfd), input_bfd,
     3734                 bfd_get_target (output_bfd), output_bfd);
     3735          /* einfo with %F exits.  */
     3736        }
     3737
    34843738      if (compatible == NULL)
    34853739        {
     
    34923746        {
    34933747          /* If the input bfd has no contents, it shouldn't set the
    3494              private data of the output bfd. */
     3748             private data of the output bfd.  */
    34953749
    34963750          bfd_error_handler_type pfn = NULL;
     
    35223776lang_common ()
    35233777{
     3778  if (command_line.inhibit_common_definition)
     3779    return;
    35243780  if (link_info.relocateable
    35253781      && ! command_line.force_common_definition)
     
    35403796/* Place one common symbol in the correct section.  */
    35413797
    3542 static boolean
     3798static bfd_boolean
    35433799lang_one_common (h, info)
    35443800     struct bfd_link_hash_entry *h;
     
    35523808
    35533809  if (h->type != bfd_link_hash_common)
    3554     return true;
     3810    return TRUE;
    35553811
    35563812  size = h->u.c.size;
     
    35593815  if (config.sort_common
    35603816      && power_of_two < (unsigned int) *(int *) info)
    3561     return true;
     3817    return TRUE;
    35623818
    35633819  section = h->u.c.p->section;
    35643820
    35653821  /* Increase the size of the section.  */
    3566   section->_cooked_size = ALIGN_N ((section->_cooked_size + opb - 1) / opb,
    3567                                    (bfd_size_type) (1 << power_of_two)) * opb;
     3822  section->_cooked_size = align_n ((section->_cooked_size + opb - 1) / opb,
     3823                                   (bfd_vma) 1 << power_of_two) * opb;
    35683824
    35693825  /* Adjust the alignment if necessary.  */
     
    35863842  if (config.map_file != NULL)
    35873843    {
    3588       static boolean header_printed;
     3844      static bfd_boolean header_printed;
    35893845      int len;
    35903846      char *name;
     
    35953851          minfo (_("\nAllocating common symbols\n"));
    35963852          minfo (_("Common symbol       size              file\n\n"));
    3597           header_printed = true;
     3853          header_printed = TRUE;
    35983854        }
    35993855
     
    36313887    }
    36323888
    3633   return true;
     3889  return TRUE;
    36343890}
    36353891
     
    36513907          if (s->output_section == (asection *) NULL)
    36523908            {
    3653               /* This section of the file is not attatched, root
     3909              /* This section of the file is not attached, root
    36543910                 around for a sensible place for it to go.  */
    36553911
    36563912              if (file->just_syms_flag)
    36573913                {
    3658                   /* We are only retrieving symbol values from this
    3659                      file.  We want the symbols to act as though the
    3660                      values in the file are absolute.  */
    3661                   s->output_section = bfd_abs_section_ptr;
    3662                   s->output_offset = s->vma;
     3914                  abort ();
    36633915                }
    36643916              else if (strcmp (s->name, "COMMON") == 0)
     
    36823934
    36833935                        }
    3684                       wild_doit (&default_common_section->children, s,
    3685                                  default_common_section, file);
     3936                      lang_add_section (&default_common_section->children, s,
     3937                                        default_common_section, file);
    36863938                    }
    36873939                }
     
    36903942              else
    36913943                {
    3692                   lang_output_section_statement_type *os =
    3693                   lang_output_section_statement_lookup (s->name);
    3694 
    3695                   wild_doit (&os->children, s, os, file);
     3944                  lang_output_section_statement_type *os;
     3945
     3946                  os = lang_output_section_statement_lookup (s->name);
     3947                  lang_add_section (&os->children, s, os, file);
    36963948                }
    36973949            }
     
    38354087{
    38364088  /* Make -o on command line override OUTPUT in script.  */
    3837   if (had_output_filename == false || !from_script)
     4089  if (!had_output_filename || !from_script)
    38384090    {
    38394091      output_filename = name;
    3840       had_output_filename = true;
     4092      had_output_filename = TRUE;
    38414093    }
    38424094}
     
    39214173/* Reset the current counters in the regions.  */
    39224174
    3923 static void
    3924 reset_memory_regions ()
     4175void
     4176lang_reset_memory_regions ()
    39254177{
    39264178  lang_memory_region_type *p = lang_memory_region_list;
     4179  asection *o;
    39274180
    39284181  for (p = lang_memory_region_list;
     
    39334186      p->current = p->origin;
    39344187    }
    3935 }
    3936 
    3937 /* Expand a wild statement for a particular FILE, marking its sections KEEP
    3938    as needed.  SECTION may be NULL, in which case it is a wild card.  */
     4188
     4189  for (o = output_bfd->sections; o != NULL; o = o->next)
     4190    o->_raw_size = 0;
     4191}
     4192
     4193/* If the wild pattern was marked KEEP, the member sections
     4194   should be as well.  */
    39394195
    39404196static void
    3941 gc_section_callback (ptr, section, file, data)
     4197gc_section_callback (ptr, sec, section, file, data)
    39424198     lang_wild_statement_type *ptr;
     4199     struct wildcard_list *sec ATTRIBUTE_UNUSED;
    39434200     asection *section;
    39444201     lang_input_statement_type *file ATTRIBUTE_UNUSED;
    39454202     PTR data ATTRIBUTE_UNUSED;
    39464203{
    3947   /* If the wild pattern was marked KEEP, the member sections
    3948      should be as well.  */
    39494204  if (ptr->keep_sections)
    39504205    section->flags |= SEC_KEEP;
    39514206}
    39524207
    3953 /* Handle a wild statement, marking it against GC.  SECTION or FILE or both
    3954    may be NULL, indicating that it is a wildcard.  */
     4208/* Handle a wild statement, marking it against GC.  */
    39554209
    39564210static void
    3957 lang_gc_wild (s, section, file)
     4211lang_gc_wild (s)
    39584212     lang_wild_statement_type *s;
    3959      const char *section;
    3960      const char *file;
    3961 {
    3962   walk_wild (s, section, file, gc_section_callback, NULL);
     4213{
     4214  walk_wild (s, gc_section_callback, NULL);
    39634215}
    39644216
     
    39694221     lang_statement_union_type *s;
    39704222{
    3971   for (; s != (lang_statement_union_type *) NULL; s = s->next)
     4223  for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
    39724224    {
    39734225      switch (s->header.type)
    39744226        {
    39754227        case lang_wild_statement_enum:
    3976           lang_gc_wild (&s->wild_statement,
    3977                         s->wild_statement.section_name,
    3978                         s->wild_statement.filename);
     4228          lang_gc_wild (&s->wild_statement);
    39794229          break;
    39804230        case lang_constructors_statement_enum:
     
    39974247{
    39984248  struct bfd_link_hash_entry *h;
    3999   ldlang_undef_chain_list_type *ulist, fake_list_start;
     4249  ldlang_undef_chain_list_type *ulist;
    40004250
    40014251  /* Keep all sections so marked in the link script.  */
     
    40034253  lang_gc_sections_1 (statement_list.head);
    40044254
    4005   /* Keep all sections containing symbols undefined on the command-line.
    4006      Handle the entry symbol at the same time.  */
    4007 
    4008   if (entry_symbol != NULL)
    4009     {
    4010       fake_list_start.next = ldlang_undef_chain_list_head;
    4011       fake_list_start.name = (char *) entry_symbol;
    4012       ulist = &fake_list_start;
    4013     }
    4014   else
    4015     ulist = ldlang_undef_chain_list_head;
    4016 
    4017   for (; ulist; ulist = ulist->next)
     4255  /* Keep all sections containing symbols undefined on the command-line,
     4256     and the section containing the entry symbol.  */
     4257
     4258  for (ulist = link_info.gc_sym_list; ulist; ulist = ulist->next)
    40184259    {
    40194260      h = bfd_link_hash_lookup (link_info.hash, ulist->name,
    4020                                 false, false, false);
     4261                                FALSE, FALSE, FALSE);
    40214262
    40224263      if (h != (struct bfd_link_hash_entry *) NULL
     
    40504291  /* Create a bfd for each input file.  */
    40514292  current_target = default_target;
    4052   open_input_bfds (statement_list.head, false);
     4293  open_input_bfds (statement_list.head, FALSE);
     4294
     4295  link_info.gc_sym_list = &entry_symbol;
     4296  if (entry_symbol.name == NULL)
     4297    link_info.gc_sym_list = ldlang_undef_chain_list_head;
    40534298
    40544299  ldemul_after_open ();
     
    40754320    lang_gc_sections ();
    40764321
     4322  /* If there were any SEC_MERGE sections, finish their merging, so that
     4323     section sizes can be computed.  This has to be done after GC of sections,
     4324     so that GCed sections are not merged, but before assigning output
     4325     sections, since removing whole input sections is hard then.  */
     4326  bfd_merge_sections (output_bfd, &link_info);
     4327
    40774328  /* Size up the common data.  */
    40784329  lang_common ();
     
    40864337  lang_place_orphans ();
    40874338
     4339  if (! link_info.relocateable)
     4340    {
     4341      /* Look for a text section and set the readonly attribute in it.  */
     4342      asection *found = bfd_get_section_by_name (output_bfd, ".text");
     4343
     4344      if (found != (asection *) NULL)
     4345        {
     4346          if (config.text_read_only)
     4347            found->flags |= SEC_READONLY;
     4348          else
     4349            found->flags &= ~SEC_READONLY;
     4350        }
     4351    }
     4352
     4353  /* Do anything special before sizing sections.  This is where ELF
     4354     and other back-ends size dynamic sections.  */
    40884355  ldemul_before_allocation ();
     4356
     4357  if (!link_info.relocateable)
     4358    strip_excluded_output_sections ();
    40894359
    40904360  /* We must record the program headers before we try to fix the
     
    40924362  lang_record_phdrs ();
    40934363
     4364  /* Size up the sections.  */
     4365  lang_size_sections (statement_list.head,
     4366                      abs_output_section,
     4367                      &statement_list.head, 0, (bfd_vma) 0, NULL,
     4368                      command_line.relax ? FALSE : TRUE);
     4369
    40944370  /* Now run around and relax if we can.  */
    40954371  if (command_line.relax)
    40964372    {
    4097       /* First time round is a trial run to get the 'worst case'
    4098          addresses of the objects if there was no relaxing.  */
    4099       lang_size_sections (statement_list.head,
    4100                           abs_output_section,
    4101                           &(statement_list.head), 0, (bfd_vma) 0, false);
    4102 
    41034373      /* Keep relaxing until bfd_relax_section gives up.  */
     4374      bfd_boolean relax_again;
     4375
    41044376      do
    41054377        {
    4106           reset_memory_regions ();
    4107 
    4108           relax_again = false;
     4378          lang_reset_memory_regions ();
     4379
     4380          relax_again = FALSE;
    41094381
    41104382          /* Note: pe-dll.c does something like this also.  If you find
     
    41164388          lang_do_assignments (statement_list.head,
    41174389                               abs_output_section,
    4118                                (fill_type) 0, (bfd_vma) 0);
     4390                               (fill_type *) 0, (bfd_vma) 0);
    41194391
    41204392          /* Perform another relax pass - this time we know where the
    4121              globals are, so can make better guess.  */
     4393             globals are, so can make a better guess.  */
    41224394          lang_size_sections (statement_list.head,
    41234395                              abs_output_section,
    4124                               &(statement_list.head), 0, (bfd_vma) 0, true);
     4396                              &statement_list.head, 0, (bfd_vma) 0,
     4397                              &relax_again, FALSE);
     4398
     4399          /* If the normal relax is done and the relax finalize pass
     4400             is not performed yet, we perform another relax pass.  */
     4401          if (!relax_again && !link_info.relax_finalizing)
     4402            {
     4403              link_info.relax_finalizing = TRUE;
     4404              relax_again = TRUE;
     4405            }
    41254406        }
    41264407      while (relax_again);
    4127     }
    4128   else
    4129     {
    4130       /* Size up the sections.  */
     4408
     4409      /* Final extra sizing to report errors.  */
     4410      lang_reset_memory_regions ();
     4411      lang_do_assignments (statement_list.head,
     4412                           abs_output_section,
     4413                           (fill_type *) 0, (bfd_vma) 0);
    41314414      lang_size_sections (statement_list.head,
    41324415                          abs_output_section,
    4133                           &(statement_list.head), 0, (bfd_vma) 0, false);
     4416                          & statement_list.head, 0, (bfd_vma) 0,
     4417                          NULL, TRUE);
    41344418    }
    41354419
     
    41464430  lang_do_assignments (statement_list.head,
    41474431                       abs_output_section,
    4148                        (fill_type) 0, (bfd_vma) 0);
     4432                       (fill_type *) 0, (bfd_vma) 0);
    41494433
    41504434  /* Make sure that the section addresses make sense.  */
     
    41624446
    41634447void
    4164 lang_add_wild (section_name, sections_sorted, filename, filenames_sorted,
    4165                keep_sections, exclude_filename_list)
    4166      const char *const section_name;
    4167      boolean sections_sorted;
    4168      const char *const filename;
    4169      boolean filenames_sorted;
    4170      boolean keep_sections;
    4171      struct name_list *exclude_filename_list;
    4172 {
    4173   lang_wild_statement_type *new = new_stat (lang_wild_statement,
    4174                                             stat_ptr);
    4175 
    4176   if (section_name != (char *) NULL && strcmp (section_name, "COMMON") == 0)
    4177     {
    4178       placed_commons = true;
    4179     }
    4180   if (filename != NULL && ! wildcardp (filename))
    4181     {
    4182       lang_has_input_file = true;
    4183     }
    4184   new->section_name = section_name;
    4185   new->sections_sorted = sections_sorted;
    4186   new->filename = filename;
    4187   new->filenames_sorted = filenames_sorted;
     4448lang_add_wild (filespec, section_list, keep_sections)
     4449     struct wildcard_spec *filespec;
     4450     struct wildcard_list *section_list;
     4451     bfd_boolean keep_sections;
     4452{
     4453  struct wildcard_list *curr, *next;
     4454  lang_wild_statement_type *new;
     4455
     4456  /* Reverse the list as the parser puts it back to front.  */
     4457  for (curr = section_list, section_list = NULL;
     4458       curr != NULL;
     4459       section_list = curr, curr = next)
     4460    {
     4461      if (curr->spec.name != NULL && strcmp (curr->spec.name, "COMMON") == 0)
     4462        placed_commons = TRUE;
     4463
     4464      next = curr->next;
     4465      curr->next = section_list;
     4466    }
     4467
     4468  if (filespec != NULL && filespec->name != NULL)
     4469    {
     4470      if (strcmp (filespec->name, "*") == 0)
     4471        filespec->name = NULL;
     4472      else if (! wildcardp (filespec->name))
     4473        lang_has_input_file = TRUE;
     4474    }
     4475
     4476  new = new_stat (lang_wild_statement, stat_ptr);
     4477  new->filename = NULL;
     4478  new->filenames_sorted = FALSE;
     4479  if (filespec != NULL)
     4480    {
     4481      new->filename = filespec->name;
     4482      new->filenames_sorted = filespec->sorted;
     4483    }
     4484  new->section_list = section_list;
    41884485  new->keep_sections = keep_sections;
    4189   new->exclude_filename_list = exclude_filename_list;
    41904486  lang_list_init (&new->children);
    41914487}
     
    42114507lang_add_entry (name, cmdline)
    42124508     const char *name;
    4213      boolean cmdline;
    4214 {
    4215   if (entry_symbol == NULL
     4509     bfd_boolean cmdline;
     4510{
     4511  if (entry_symbol.name == NULL
    42164512      || cmdline
    42174513      || ! entry_from_cmdline)
    42184514    {
    4219       entry_symbol = name;
     4515      entry_symbol.name = name;
    42204516      entry_from_cmdline = cmdline;
    42214517    }
     
    42424538        {
    42434539        case 'F':
    4244           map_option_f = true;
     4540          map_option_f = TRUE;
    42454541          break;
    42464542        }
     
    42504546
    42514547void
    4252 lang_add_fill (exp)
    4253      int exp;
     4548lang_add_fill (fill)
     4549     fill_type *fill;
    42544550{
    42554551  lang_fill_statement_type *new = new_stat (lang_fill_statement,
    42564552                                            stat_ptr);
    42574553
    4258   new->fill = exp;
     4554  new->fill = fill;
    42594555}
    42604556
     
    43294625  first_file->filename = name;
    43304626  first_file->local_sym_name = name;
    4331   first_file->real = true;
     4627  first_file->real = TRUE;
    43324628
    43334629  startup_file = name;
     
    43364632void
    43374633lang_float (maybe)
    4338      boolean maybe;
     4634     bfd_boolean maybe;
    43394635{
    43404636  lang_float_flag = maybe;
     4637}
     4638
     4639
     4640/* Work out the load- and run-time regions from a script statement, and
     4641   store them in *LMA_REGION and *REGION respectively.
     4642
     4643   MEMSPEC is the name of the run-time region, or "*default*" if the
     4644   statement didn't specify one.  LMA_MEMSPEC is the name of the
     4645   load-time region, or null if the statement didn't specify one.
     4646   HAVE_LMA_P is TRUE if the statement had an explicit load address.
     4647
     4648   It is an error to specify both a load region and a load address.  */
     4649
     4650static void
     4651lang_get_regions (region, lma_region, memspec, lma_memspec, have_lma_p)
     4652     struct memory_region_struct **region, **lma_region;
     4653     const char *memspec, *lma_memspec;
     4654     int have_lma_p;
     4655{
     4656  *lma_region = lang_memory_region_lookup (lma_memspec);
     4657
     4658  /* If no runtime region has been given, but the load region has
     4659     been, use the load region.  */
     4660  if (lma_memspec != 0 && strcmp (memspec, "*default*") == 0)
     4661    *region = *lma_region;
     4662  else
     4663    *region = lang_memory_region_lookup (memspec);
     4664
     4665  if (have_lma_p && lma_memspec != 0)
     4666    einfo (_("%X%P:%S: section has both a load address and a load region\n"));
    43414667}
    43424668
    43434669void
    43444670lang_leave_output_section_statement (fill, memspec, phdrs, lma_memspec)
    4345      bfd_vma fill;
     4671     fill_type *fill;
    43464672     const char *memspec;
    43474673     struct lang_output_section_phdr_list *phdrs;
    43484674     const char *lma_memspec;
    43494675{
     4676  lang_get_regions (&current_section->region,
     4677                    &current_section->lma_region,
     4678                    memspec, lma_memspec,
     4679                    current_section->load_base != 0);
    43504680  current_section->fill = fill;
    4351   current_section->region = lang_memory_region_lookup (memspec);
    4352   if (strcmp (lma_memspec, "*default*") != 0)
    4353     {
    4354       current_section->lma_region = lang_memory_region_lookup (lma_memspec);
    4355       /* If no runtime region has been given, but the load region has
    4356          been, use the load region.  */
    4357       if (strcmp (memspec, "*default*") == 0)
    4358         current_section->region = lang_memory_region_lookup (lma_memspec);
    4359     }
    43604681  current_section->phdrs = phdrs;
    43614682  stat_ptr = &statement_list;
     
    43744695  struct bfd_link_hash_entry *h;
    43754696
    4376   h = bfd_link_hash_lookup (link_info.hash, name, true, true, true);
     4697  h = bfd_link_hash_lookup (link_info.hash, name, TRUE, TRUE, TRUE);
    43774698  if (h == (struct bfd_link_hash_entry *) NULL)
    43784699    einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
     
    44074728  struct bfd_link_hash_entry *h;
    44084729
    4409   h = bfd_link_hash_lookup (link_info.hash, name, true, true, true);
     4730  h = bfd_link_hash_lookup (link_info.hash, name, TRUE, TRUE, TRUE);
    44104731  if (h == (struct bfd_link_hash_entry *) NULL)
    44114732    einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
     
    44934814     const char *name;
    44944815     etree_type *type;
    4495      boolean filehdr;
    4496      boolean phdrs;
     4816     bfd_boolean filehdr;
     4817     bfd_boolean phdrs;
    44974818     etree_type *at;
    44984819     etree_type *flags;
     
    45734894                  secs[c] = os->bfd_section;
    45744895                  ++c;
    4575                   pl->used = true;
     4896                  pl->used = TRUE;
    45764897                }
    45774898            }
     
    46314952
    46324953  /* Set notice_all so that we get informed about all symbols.  */
    4633   link_info.notice_all = true;
     4954  link_info.notice_all = TRUE;
    46344955}
    46354956
     
    46394960/* The overlay virtual address.  */
    46404961static etree_type *overlay_vma;
    4641 
    4642 /* The overlay load address.  */
    4643 static etree_type *overlay_lma;
    4644 
    4645 /* Whether nocrossrefs is set for this overlay.  */
    4646 static int overlay_nocrossrefs;
    46474962
    46484963/* An expression for the maximum section size seen so far.  */
     
    46614976
    46624977void
    4663 lang_enter_overlay (vma_expr, lma_expr, nocrossrefs)
     4978lang_enter_overlay (vma_expr)
    46644979     etree_type *vma_expr;
    4665      etree_type *lma_expr;
    4666      int nocrossrefs;
    46674980{
    46684981  /* The grammar should prevent nested overlays from occurring.  */
    4669   ASSERT (overlay_vma == NULL
    4670           && overlay_lma == NULL
    4671           && overlay_list == NULL
    4672           && overlay_max == NULL);
     4982  ASSERT (overlay_vma == NULL && overlay_max == NULL);
    46734983
    46744984  overlay_vma = vma_expr;
    4675   overlay_lma = lma_expr;
    4676   overlay_nocrossrefs = nocrossrefs;
    46774985}
    46784986
    46794987/* Start a section in an overlay.  We handle this by calling
    4680    lang_enter_output_section_statement with the correct VMA and LMA.  */
     4988   lang_enter_output_section_statement with the correct VMA.
     4989   lang_leave_overlay sets up the LMA and memory regions.  */
    46814990
    46824991void
     
    46884997
    46894998  lang_enter_output_section_statement (name, overlay_vma, normal_section,
    4690                                        0, 0, 0, overlay_lma);
    4691 
    4692   /* If this is the first section, then base the VMA and LMA of future
     4999                                       0, 0, 0, 0);
     5000
     5001  /* If this is the first section, then base the VMA of future
    46935002     sections on this one.  This will work correctly even if `.' is
    46945003     used in the addresses.  */
    46955004  if (overlay_list == NULL)
    4696     {
    4697       overlay_vma = exp_nameop (ADDR, name);
    4698       overlay_lma = exp_nameop (LOADADDR, name);
    4699     }
     5005    overlay_vma = exp_nameop (ADDR, name);
    47005006
    47015007  /* Remember the section.  */
     
    47075013  size = exp_nameop (SIZEOF, name);
    47085014
    4709   /* Adjust the LMA for the next section.  */
    4710   overlay_lma = exp_binop ('+', overlay_lma, size);
    4711 
    47125015  /* Arrange to work out the maximum section end address.  */
    47135016  if (overlay_max == NULL)
     
    47225025void
    47235026lang_leave_overlay_section (fill, phdrs)
    4724      bfd_vma fill;
     5027     fill_type *fill;
    47255028     struct lang_output_section_phdr_list *phdrs;
    47265029{
     
    47325035  name = current_section->name;
    47335036
    4734   lang_leave_output_section_statement (fill, "*default*",
    4735                                        phdrs, "*default*");
     5037  /* For now, assume that "*default*" is the run-time memory region and
     5038     that no load-time region has been specified.  It doesn't really
     5039     matter what we say here, since lang_leave_overlay will override it.  */
     5040  lang_leave_output_section_statement (fill, "*default*", phdrs, 0);
    47365041
    47375042  /* Define the magic symbols.  */
     
    47405045  s2 = clean;
    47415046  for (s1 = name; *s1 != '\0'; s1++)
    4742     if (isalnum ((unsigned char) *s1) || *s1 == '_')
     5047    if (ISALNUM (*s1) || *s1 == '_')
    47435048      *s2++ = *s1;
    47445049  *s2 = '\0';
     
    47635068
    47645069void
    4765 lang_leave_overlay (fill, memspec, phdrs, lma_memspec)
    4766      bfd_vma fill;
     5070lang_leave_overlay (lma_expr, nocrossrefs, fill, memspec, phdrs, lma_memspec)
     5071     etree_type *lma_expr;
     5072     int nocrossrefs;
     5073     fill_type *fill;
    47675074     const char *memspec;
    47685075     struct lang_output_section_phdr_list *phdrs;
     
    47745081  struct lang_nocrossref *nocrossref;
    47755082
    4776   if (memspec == NULL)
    4777     region = NULL;
    4778   else
    4779     region = lang_memory_region_lookup (memspec);
    4780 
    4781   if (lma_memspec == NULL)
    4782     lma_region = NULL;
    4783   else
    4784     lma_region = lang_memory_region_lookup (lma_memspec);
     5083  lang_get_regions (&region, &lma_region,
     5084                    memspec, lma_memspec,
     5085                    lma_expr != 0);
    47855086
    47865087  nocrossref = NULL;
     5088
     5089  /* After setting the size of the last section, set '.' to end of the
     5090     overlay region.  */
     5091  if (overlay_list != NULL)
     5092    overlay_list->os->update_dot_tree
     5093      = exp_assop ('=', ".", exp_binop ('+', overlay_vma, overlay_max));
    47875094
    47885095  l = overlay_list;
     
    47915098      struct overlay_list *next;
    47925099
    4793       if (fill != 0 && l->os->fill == 0)
     5100      if (fill != (fill_type *) 0 && l->os->fill == (fill_type *) 0)
    47945101        l->os->fill = fill;
    4795       if (region != NULL && l->os->region == NULL)
    4796         l->os->region = region;
    4797       /* We only set lma_region for the first overlay section, as
    4798          subsequent overlay sections will have load_base set relative
    4799          to the first section.  Also, don't set lma_region if
    4800          load_base is specified.  FIXME:  There should really be a test
    4801          that `AT ( LDADDR )' doesn't conflict with `AT >LMA_REGION'
    4802          rather than letting LDADDR simply override LMA_REGION.  */
    4803       if (lma_region != NULL && l->os->lma_region == NULL
    4804           && l->next == NULL && l->os->load_base == NULL)
    4805         l->os->lma_region = lma_region;
     5102
     5103      l->os->region = region;
     5104      l->os->lma_region = lma_region;
     5105
     5106      /* The first section has the load address specified in the
     5107         OVERLAY statement.  The rest are worked out from that.
     5108         The base address is not needed (and should be null) if
     5109         an LMA region was specified.  */
     5110      if (l->next == 0)
     5111        l->os->load_base = lma_expr;
     5112      else if (lma_region == 0)
     5113        l->os->load_base = exp_binop ('+',
     5114                                      exp_nameop (LOADADDR, l->next->os->name),
     5115                                      exp_nameop (SIZEOF, l->next->os->name));
     5116
    48065117      if (phdrs != NULL && l->os->phdrs == NULL)
    48075118        l->os->phdrs = phdrs;
    48085119
    4809       if (overlay_nocrossrefs)
     5120      if (nocrossrefs)
    48105121        {
    48115122          struct lang_nocrossref *nc;
     
    48255136    lang_add_nocrossref (nocrossref);
    48265137
    4827   /* Update . for the end of the overlay.  */
    4828   lang_add_assignment (exp_assop ('=', ".",
    4829                                   exp_binop ('+', overlay_vma, overlay_max)));
    4830 
    48315138  overlay_vma = NULL;
    4832   overlay_lma = NULL;
    4833   overlay_nocrossrefs = 0;
    48345139  overlay_list = NULL;
    48355140  overlay_max = NULL;
     
    48685173    {
    48695174      /* cplus_demangle (also) returns NULL when it is not a C++ symbol.
    4870          Should we early out false in this case?  */
     5175         Should we early out FALSE in this case?  */
    48715176      result = fnmatch (expr->pattern, sym, 0) == 0;
    48725177    }
     
    48955200    {
    48965201      /* cplus_demangle (also) returns NULL when it is not a Java symbol.
    4897          Should we early out false in this case?  */
     5202         Should we early out FALSE in this case?  */
    48985203      result = fnmatch (expr->pattern, sym, 0) == 0;
    48995204    }
     
    49105215
    49115216struct bfd_elf_version_expr *
    4912 lang_new_vers_regex (orig, new, lang)
     5217lang_new_vers_pattern (orig, new, lang)
    49135218     struct bfd_elf_version_expr *orig;
    49145219     const char *new;
     
    49205225  ret->next = orig;
    49215226  ret->pattern = new;
     5227  ret->symver = 0;
     5228  ret->script = 0;
    49225229
    49235230  if (lang == NULL || strcasecmp (lang, "C") == 0)
     
    49345241    }
    49355242
    4936   return ret;
     5243  return ldemul_new_vers_pattern (ret);
    49375244}
    49385245
     
    49755282  struct bfd_elf_version_expr *e1;
    49765283
     5284  if (name == NULL)
     5285    name = "";
     5286
     5287  if ((name[0] == '\0' && lang_elf_version_info != NULL)
     5288      || (lang_elf_version_info && lang_elf_version_info->name[0] == '\0'))
     5289    {
     5290      einfo (_("%X%P: anonymous version tag cannot be combined with other version tags\n"));
     5291      free (version);
     5292      return;
     5293    }
     5294
    49775295  /* Make sure this node has a unique name.  */
    49785296  for (t = lang_elf_version_info; t != NULL; t = t->next)
     
    50115329  version->deps = deps;
    50125330  version->name = name;
    5013   ++version_index;
    5014   version->vernum = version_index;
     5331  if (name[0] != '\0')
     5332    {
     5333      ++version_index;
     5334      version->vernum = version_index;
     5335    }
     5336  else
     5337    version->vernum = 0;
    50155338
    50165339  for (pp = &lang_elf_version_info; *pp != NULL; pp = &(*pp)->next)
     
    50585381
    50595382      if (sec == NULL)
    5060         continue;
     5383        continue;
    50615384
    50625385      len = bfd_section_size (is->the_bfd, sec);
    50635386      contents = xmalloc (len);
    50645387      if (!bfd_get_section_contents (is->the_bfd, sec, contents, 0, len))
    5065         einfo (_("%X%P: unable to read .exports section contents"), sec);
     5388        einfo (_("%X%P: unable to read .exports section contents\n"), sec);
    50665389
    50675390      p = contents;
    50685391      while (p < contents + len)
    50695392        {
    5070           greg = lang_new_vers_regex (greg, p, NULL);
     5393          greg = lang_new_vers_pattern (greg, p, NULL);
    50715394          p = strchr (p, '\0') + 1;
    50725395        }
     
    50795402    }
    50805403
    5081   lreg = lang_new_vers_regex (NULL, "*", NULL);
     5404  lreg = lang_new_vers_pattern (NULL, "*", NULL);
    50825405  lang_register_vers_node (command_line.version_exports_section,
    50835406                           lang_new_vers_node (greg, lreg), NULL);
Note: See TracChangeset for help on using the changeset viewer.