~ubuntu-branches/debian/squeeze/binutils/squeeze

« back to all changes in this revision

Viewing changes to ld/ldlang.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-09-10 17:05:30 UTC
  • mfrom: (1.4.5 upstream) (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090910170530-wa6gpju9pq5c56on
Tags: 2.19.91.20090910-1
* Snapshot, taken from the 2.20 release branch 20090910, corresponding
  to the 2.19.90 upstream snapshot.
* Fix Thumb-2 shared libraries (Daniel Jacobowitz), patch taken
  from the trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#define obstack_chunk_alloc xmalloc
53
53
#define obstack_chunk_free free
54
54
static const char *startup_file;
 
55
static const char *entry_symbol_default = "start";
55
56
static bfd_boolean placed_commons = FALSE;
56
57
static bfd_boolean stripped_excluded_sections = FALSE;
57
58
static lang_output_section_statement_type *default_common_section;
59
60
static bfd_vma print_dot;
60
61
static lang_input_statement_type *first_file;
61
62
static const char *current_target;
62
 
static const char *output_target;
63
63
static lang_statement_list_type statement_list;
64
64
static struct bfd_hash_table lang_definedness_table;
65
65
static lang_statement_list_type *stat_save[10];
86
86
  (struct bfd_elf_version_expr_head *);
87
87
 
88
88
/* Exported variables.  */
 
89
const char *output_target;
89
90
lang_output_section_statement_type *abs_output_section;
90
91
lang_statement_list_type lang_output_section_statement;
91
92
lang_statement_list_type *stat_ptr = &statement_list;
92
93
lang_statement_list_type file_chain = { NULL, NULL };
93
94
lang_statement_list_type input_file_chain;
94
95
struct bfd_sym_chain entry_symbol = { NULL, NULL };
95
 
static const char *entry_symbol_default = "start";
96
96
const char *entry_section = ".text";
97
97
bfd_boolean entry_from_cmdline;
98
98
bfd_boolean lang_has_input_file = FALSE;
949
949
               size_t size,
950
950
               lang_statement_list_type *list)
951
951
{
952
 
  lang_statement_union_type *new;
 
952
  lang_statement_union_type *new_stmt;
953
953
 
954
 
  new = stat_alloc (size);
955
 
  new->header.type = type;
956
 
  new->header.next = NULL;
957
 
  lang_statement_append (list, new, &new->header.next);
958
 
  return new;
 
954
  new_stmt = (lang_statement_union_type *) stat_alloc (size);
 
955
  new_stmt->header.type = type;
 
956
  new_stmt->header.next = NULL;
 
957
  lang_statement_append (list, new_stmt, &new_stmt->header.next);
 
958
  return new_stmt;
959
959
}
960
960
 
961
961
/* Build a new input file node for the language.  There are several
976
976
  lang_input_statement_type *p;
977
977
 
978
978
  if (add_to_list)
979
 
    p = new_stat (lang_input_statement, stat_ptr);
 
979
    p = (lang_input_statement_type *) new_stat (lang_input_statement, stat_ptr);
980
980
  else
981
981
    {
982
 
      p = stat_alloc (sizeof (lang_input_statement_type));
 
982
      p = (lang_input_statement_type *)
 
983
          stat_alloc (sizeof (lang_input_statement_type));
983
984
      p->header.type = lang_input_statement_enum;
984
985
      p->header.next = NULL;
985
986
    }
1220
1221
{
1221
1222
  lang_memory_region_name *n;
1222
1223
  lang_memory_region_type *r;
1223
 
  lang_memory_region_type *new;
 
1224
  lang_memory_region_type *new_region;
1224
1225
 
1225
1226
  /* NAME is NULL for LMA memspecs if no region was specified.  */
1226
1227
  if (name == NULL)
1239
1240
  if (!create && strcmp (name, DEFAULT_MEMORY_REGION))
1240
1241
    einfo (_("%P:%S: warning: memory region `%s' not declared\n"), name);
1241
1242
 
1242
 
  new = stat_alloc (sizeof (lang_memory_region_type));
1243
 
 
1244
 
  new->name_list.name = xstrdup (name);
1245
 
  new->name_list.next = NULL;
1246
 
  new->next = NULL;
1247
 
  new->origin = 0;
1248
 
  new->length = ~(bfd_size_type) 0;
1249
 
  new->current = 0;
1250
 
  new->last_os = NULL;
1251
 
  new->flags = 0;
1252
 
  new->not_flags = 0;
1253
 
  new->had_full_message = FALSE;
1254
 
 
1255
 
  *lang_memory_region_list_tail = new;
1256
 
  lang_memory_region_list_tail = &new->next;
1257
 
 
1258
 
  return new;
 
1243
  new_region = (lang_memory_region_type *)
 
1244
      stat_alloc (sizeof (lang_memory_region_type));
 
1245
 
 
1246
  new_region->name_list.name = xstrdup (name);
 
1247
  new_region->name_list.next = NULL;
 
1248
  new_region->next = NULL;
 
1249
  new_region->origin = 0;
 
1250
  new_region->length = ~(bfd_size_type) 0;
 
1251
  new_region->current = 0;
 
1252
  new_region->last_os = NULL;
 
1253
  new_region->flags = 0;
 
1254
  new_region->not_flags = 0;
 
1255
  new_region->had_full_message = FALSE;
 
1256
 
 
1257
  *lang_memory_region_list_tail = new_region;
 
1258
  lang_memory_region_list_tail = &new_region->next;
 
1259
 
 
1260
  return new_region;
1259
1261
}
1260
1262
 
1261
1263
void
1997
1999
  ASSERT (get_userdata (sec) == NULL);
1998
2000
  get_userdata (sec) = new_data;
1999
2001
  new_data->map_symbol_def_tail = &new_data->map_symbol_def_head;
 
2002
  new_data->map_symbol_def_count = 0;
2000
2003
}
2001
2004
 
2002
2005
static bfd_boolean
2024
2027
      def->entry = hash_entry;
2025
2028
      *(ud->map_symbol_def_tail) = def;
2026
2029
      ud->map_symbol_def_tail = &def->next;
 
2030
      ud->map_symbol_def_count++;
2027
2031
    }
2028
2032
  return TRUE;
2029
2033
}
2055
2059
 
2056
2060
  if (!link_info.reduce_memory_overheads)
2057
2061
    {
2058
 
      fat_section_userdata_type *new
2059
 
        = stat_alloc (sizeof (fat_section_userdata_type));
2060
 
      memset (new, 0, sizeof (fat_section_userdata_type));
2061
 
      get_userdata (s->bfd_section) = new;
 
2062
      fat_section_userdata_type *new_userdata = (fat_section_userdata_type *)
 
2063
        stat_alloc (sizeof (fat_section_userdata_type));
 
2064
      memset (new_userdata, 0, sizeof (fat_section_userdata_type));
 
2065
      get_userdata (s->bfd_section) = new_userdata;
2062
2066
    }
2063
2067
 
2064
2068
  /* If there is a base address, make sure that any sections it might
2194
2198
  if (section->output_section == NULL)
2195
2199
    {
2196
2200
      bfd_boolean first;
2197
 
      lang_input_section_type *new;
 
2201
      lang_input_section_type *new_section;
2198
2202
      flagword flags;
2199
2203
 
2200
2204
      flags = section->flags;
2242
2246
        }
2243
2247
 
2244
2248
      /* Add a section reference to the list.  */
2245
 
      new = new_stat (lang_input_section, ptr);
 
2249
      new_section = new_stat (lang_input_section, ptr);
2246
2250
 
2247
 
      new->section = section;
 
2251
      new_section->section = section;
2248
2252
      section->output_section = output->bfd_section;
2249
2253
 
2250
2254
      /* If final link, don't copy the SEC_LINK_ONCE flags, they've
3248
3252
void
3249
3253
ldlang_add_undef (const char *const name)
3250
3254
{
3251
 
  ldlang_undef_chain_list_type *new =
3252
 
    stat_alloc (sizeof (ldlang_undef_chain_list_type));
3253
 
 
3254
 
  new->next = ldlang_undef_chain_list_head;
3255
 
  ldlang_undef_chain_list_head = new;
3256
 
 
3257
 
  new->name = xstrdup (name);
 
3255
  ldlang_undef_chain_list_type *new_undef = (ldlang_undef_chain_list_type *)
 
3256
      stat_alloc (sizeof (ldlang_undef_chain_list_type));
 
3257
 
 
3258
  new_undef->next = ldlang_undef_chain_list_head;
 
3259
  ldlang_undef_chain_list_head = new_undef;
 
3260
 
 
3261
  new_undef->name = xstrdup (name);
3258
3262
 
3259
3263
  if (link_info.output_bfd != NULL)
3260
 
    insert_undefined (new->name);
 
3264
    insert_undefined (new_undef->name);
3261
3265
}
3262
3266
 
3263
3267
/* Insert NAME as undefined in the symbol table.  */
3949
3953
  return TRUE;
3950
3954
}
3951
3955
 
 
3956
static int
 
3957
hash_entry_addr_cmp (const void *a, const void *b)
 
3958
{
 
3959
  const struct bfd_link_hash_entry *l = *(const struct bfd_link_hash_entry **)a;
 
3960
  const struct bfd_link_hash_entry *r = *(const struct bfd_link_hash_entry **)b;
 
3961
 
 
3962
  if (l->u.def.value < r->u.def.value)
 
3963
    return -1;
 
3964
  else if (l->u.def.value > r->u.def.value)
 
3965
    return 1;
 
3966
  else
 
3967
    return 0;
 
3968
}
 
3969
 
3952
3970
static void
3953
3971
print_all_symbols (asection *sec)
3954
3972
{
3955
3973
  struct fat_user_section_struct *ud = get_userdata (sec);
3956
3974
  struct map_symbol_def *def;
 
3975
  struct bfd_link_hash_entry **entries;
 
3976
  unsigned int i;
3957
3977
 
3958
3978
  if (!ud)
3959
3979
    return;
3960
3980
 
3961
3981
  *ud->map_symbol_def_tail = 0;
3962
 
  for (def = ud->map_symbol_def_head; def; def = def->next)
3963
 
    print_one_symbol (def->entry, sec);
 
3982
  
 
3983
  /* Sort the symbols by address.  */
 
3984
  entries = obstack_alloc (&map_obstack,
 
3985
                           ud->map_symbol_def_count * sizeof (*entries));
 
3986
 
 
3987
  for (i = 0, def = ud->map_symbol_def_head; def; def = def->next, i++)
 
3988
    entries[i] = def->entry;
 
3989
 
 
3990
  qsort (entries, ud->map_symbol_def_count, sizeof (*entries),
 
3991
         hash_entry_addr_cmp);
 
3992
 
 
3993
  /* Print the symbols.  */
 
3994
  for (i = 0; i < ud->map_symbol_def_count; i++)
 
3995
    print_one_symbol (entries[i], sec);
 
3996
 
 
3997
  obstack_free (&map_obstack, entries);
3964
3998
}
3965
3999
 
3966
4000
/* Print information about an input section to the map file.  */
5978
6012
void
5979
6013
lang_final (void)
5980
6014
{
5981
 
  lang_output_statement_type *new;
5982
 
 
5983
 
  new = new_stat (lang_output_statement, stat_ptr);
5984
 
  new->name = output_filename;
 
6015
  lang_output_statement_type *new_stmt;
 
6016
 
 
6017
  new_stmt = new_stat (lang_output_statement, stat_ptr);
 
6018
  new_stmt->name = output_filename;
 
6019
 
5985
6020
}
5986
6021
 
5987
6022
/* Reset the current counters in the regions.  */
6159
6194
 
6160
6195
/* Relax all sections until bfd_relax_section gives up.  */
6161
6196
 
6162
 
static void
6163
 
relax_sections (void)
 
6197
void
 
6198
lang_relax_sections (bfd_boolean need_layout)
6164
6199
{
6165
 
  /* Keep relaxing until bfd_relax_section gives up.  */
6166
 
  bfd_boolean relax_again;
6167
 
 
6168
 
  link_info.relax_trip = -1;
6169
 
  do
6170
 
    {
6171
 
      relax_again = FALSE;
6172
 
      link_info.relax_trip++;
6173
 
 
6174
 
      /* Note: pe-dll.c does something like this also.  If you find
6175
 
         you need to change this code, you probably need to change
6176
 
         pe-dll.c also.  DJ  */
6177
 
 
6178
 
      /* Do all the assignments with our current guesses as to
6179
 
         section sizes.  */
 
6200
  if (command_line.relax)
 
6201
    {
 
6202
      /* We may need more than one relaxation pass.  */
 
6203
      int i = link_info.relax_pass;
 
6204
 
 
6205
      /* The backend can use it to determine the current pass.  */
 
6206
      link_info.relax_pass = 0;
 
6207
 
 
6208
      while (i--)
 
6209
        {
 
6210
          /* Keep relaxing until bfd_relax_section gives up.  */
 
6211
          bfd_boolean relax_again;
 
6212
 
 
6213
          link_info.relax_trip = -1;
 
6214
          do
 
6215
            {
 
6216
              link_info.relax_trip++;
 
6217
 
 
6218
              /* Note: pe-dll.c does something like this also.  If you find
 
6219
                 you need to change this code, you probably need to change
 
6220
                 pe-dll.c also.  DJ  */
 
6221
 
 
6222
              /* Do all the assignments with our current guesses as to
 
6223
                 section sizes.  */
 
6224
              lang_do_assignments ();
 
6225
 
 
6226
              /* We must do this after lang_do_assignments, because it uses
 
6227
                 size.  */
 
6228
              lang_reset_memory_regions ();
 
6229
 
 
6230
              /* Perform another relax pass - this time we know where the
 
6231
                 globals are, so can make a better guess.  */
 
6232
              relax_again = FALSE;
 
6233
              lang_size_sections (&relax_again, FALSE);
 
6234
            }
 
6235
          while (relax_again);
 
6236
 
 
6237
          link_info.relax_pass++;
 
6238
        }
 
6239
      need_layout = TRUE;
 
6240
    }
 
6241
 
 
6242
  if (need_layout)
 
6243
    {
 
6244
      /* Final extra sizing to report errors.  */
6180
6245
      lang_do_assignments ();
6181
 
 
6182
 
      /* We must do this after lang_do_assignments, because it uses
6183
 
         size.  */
6184
6246
      lang_reset_memory_regions ();
6185
 
 
6186
 
      /* Perform another relax pass - this time we know where the
6187
 
         globals are, so can make a better guess.  */
6188
 
      lang_size_sections (&relax_again, FALSE);
 
6247
      lang_size_sections (NULL, TRUE);
6189
6248
    }
6190
 
  while (relax_again);
6191
6249
}
6192
6250
 
6193
6251
void
6293
6351
  /* Size up the sections.  */
6294
6352
  lang_size_sections (NULL, !command_line.relax);
6295
6353
 
6296
 
  /* Now run around and relax if we can.  */
6297
 
  if (command_line.relax)
6298
 
    {
6299
 
      /* We may need more than one relaxation pass.  */
6300
 
      int i = link_info.relax_pass;
6301
 
 
6302
 
      /* The backend can use it to determine the current pass.  */
6303
 
      link_info.relax_pass = 0;
6304
 
 
6305
 
      while (i--)
6306
 
        {
6307
 
          relax_sections ();
6308
 
          link_info.relax_pass++;
6309
 
        }
6310
 
 
6311
 
      /* Final extra sizing to report errors.  */
6312
 
      lang_do_assignments ();
6313
 
      lang_reset_memory_regions ();
6314
 
      lang_size_sections (NULL, TRUE);
6315
 
    }
6316
 
 
6317
6354
  /* See if anything special should be done now we know how big
6318
 
     everything is.  */
 
6355
     everything is.  This is where relaxation is done.  */
6319
6356
  ldemul_after_allocation ();
6320
6357
 
6321
6358
  /* Fix any .startof. or .sizeof. symbols.  */
6343
6380
               bfd_boolean keep_sections)
6344
6381
{
6345
6382
  struct wildcard_list *curr, *next;
6346
 
  lang_wild_statement_type *new;
 
6383
  lang_wild_statement_type *new_stmt;
6347
6384
 
6348
6385
  /* Reverse the list as the parser puts it back to front.  */
6349
6386
  for (curr = section_list, section_list = NULL;
6365
6402
        lang_has_input_file = TRUE;
6366
6403
    }
6367
6404
 
6368
 
  new = new_stat (lang_wild_statement, stat_ptr);
6369
 
  new->filename = NULL;
6370
 
  new->filenames_sorted = FALSE;
 
6405
  new_stmt = new_stat (lang_wild_statement, stat_ptr);
 
6406
  new_stmt->filename = NULL;
 
6407
  new_stmt->filenames_sorted = FALSE;
6371
6408
  if (filespec != NULL)
6372
6409
    {
6373
 
      new->filename = filespec->name;
6374
 
      new->filenames_sorted = filespec->sorted == by_name;
 
6410
      new_stmt->filename = filespec->name;
 
6411
      new_stmt->filenames_sorted = filespec->sorted == by_name;
6375
6412
    }
6376
 
  new->section_list = section_list;
6377
 
  new->keep_sections = keep_sections;
6378
 
  lang_list_init (&new->children);
6379
 
  analyze_walk_wild_section_handler (new);
 
6413
  new_stmt->section_list = section_list;
 
6414
  new_stmt->keep_sections = keep_sections;
 
6415
  lang_list_init (&new_stmt->children);
 
6416
  analyze_walk_wild_section_handler (new_stmt);
6380
6417
}
6381
6418
 
6382
6419
void
6421
6458
void
6422
6459
lang_add_target (const char *name)
6423
6460
{
6424
 
  lang_target_statement_type *new;
 
6461
  lang_target_statement_type *new_stmt;
6425
6462
 
6426
 
  new = new_stat (lang_target_statement, stat_ptr);
6427
 
  new->target = name;
 
6463
  new_stmt = new_stat (lang_target_statement, stat_ptr);
 
6464
  new_stmt->target = name;
6428
6465
}
6429
6466
 
6430
6467
void
6445
6482
void
6446
6483
lang_add_fill (fill_type *fill)
6447
6484
{
6448
 
  lang_fill_statement_type *new;
 
6485
  lang_fill_statement_type *new_stmt;
6449
6486
 
6450
 
  new = new_stat (lang_fill_statement, stat_ptr);
6451
 
  new->fill = fill;
 
6487
  new_stmt = new_stat (lang_fill_statement, stat_ptr);
 
6488
  new_stmt->fill = fill;
6452
6489
}
6453
6490
 
6454
6491
void
6455
6492
lang_add_data (int type, union etree_union *exp)
6456
6493
{
6457
 
  lang_data_statement_type *new;
 
6494
  lang_data_statement_type *new_stmt;
6458
6495
 
6459
 
  new = new_stat (lang_data_statement, stat_ptr);
6460
 
  new->exp = exp;
6461
 
  new->type = type;
 
6496
  new_stmt = new_stat (lang_data_statement, stat_ptr);
 
6497
  new_stmt->exp = exp;
 
6498
  new_stmt->type = type;
6462
6499
}
6463
6500
 
6464
6501
/* Create a new reloc statement.  RELOC is the BFD relocation type to
6491
6528
lang_assignment_statement_type *
6492
6529
lang_add_assignment (etree_type *exp)
6493
6530
{
6494
 
  lang_assignment_statement_type *new;
 
6531
  lang_assignment_statement_type *new_stmt;
6495
6532
 
6496
 
  new = new_stat (lang_assignment_statement, stat_ptr);
6497
 
  new->exp = exp;
6498
 
  return new;
 
6533
  new_stmt = new_stat (lang_assignment_statement, stat_ptr);
 
6534
  new_stmt->exp = exp;
 
6535
  return new_stmt;
6499
6536
}
6500
6537
 
6501
6538
void
6680
6717
void
6681
6718
lang_add_insert (const char *where, int is_before)
6682
6719
{
6683
 
  lang_insert_statement_type *new;
 
6720
  lang_insert_statement_type *new_stmt;
6684
6721
 
6685
 
  new = new_stat (lang_insert_statement, stat_ptr);
6686
 
  new->where = where;
6687
 
  new->is_before = is_before;
 
6722
  new_stmt = new_stat (lang_insert_statement, stat_ptr);
 
6723
  new_stmt->where = where;
 
6724
  new_stmt->is_before = is_before;
6688
6725
  saved_script_handle = previous_script_handle;
6689
6726
}
6690
6727
 
7227
7264
    }
7228
7265
}
7229
7266
 
7230
 
/* This is called for each variable name or match expression.  NEW is
 
7267
/* This is called for each variable name or match expression.  NEW_NAME is
7231
7268
   the name of the symbol to match, or, if LITERAL_P is FALSE, a glob
7232
7269
   pattern to be matched against symbol names.  */
7233
7270
 
7234
7271
struct bfd_elf_version_expr *
7235
7272
lang_new_vers_pattern (struct bfd_elf_version_expr *orig,
7236
 
                       const char *new,
 
7273
                       const char *new_name,
7237
7274
                       const char *lang,
7238
7275
                       bfd_boolean literal_p)
7239
7276
{
7240
7277
  struct bfd_elf_version_expr *ret;
7241
7278
 
7242
 
  ret = xmalloc (sizeof *ret);
 
7279
  ret = (struct bfd_elf_version_expr *) xmalloc (sizeof *ret);
7243
7280
  ret->next = orig;
7244
7281
  ret->symver = 0;
7245
7282
  ret->script = 0;
7246
7283
  ret->literal = TRUE;
7247
 
  ret->pattern = literal_p ? new : realsymbol (new);
 
7284
  ret->pattern = literal_p ? new_name : realsymbol (new_name);
7248
7285
  if (ret->pattern == NULL)
7249
7286
    {
7250
 
      ret->pattern = new;
 
7287
      ret->pattern = new_name;
7251
7288
      ret->literal = FALSE;
7252
7289
    }
7253
7290