~ubuntu-branches/ubuntu/hoary/binutils/hoary

« back to all changes in this revision

Viewing changes to ld/ldlang.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-03-18 13:07:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050318130752-j4i37zgqclj53b94
Tags: 2.15-5ubuntu2
debian/rules: Call pkgstriptranslations if present (the package does not
use debhelper, thus it does not happen automatically).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Linker command language support.
2
2
   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3
 
   2001, 2002, 2003
 
3
   2001, 2002, 2003, 2004
4
4
   Free Software Foundation, Inc.
5
5
 
6
6
   This file is part of GLD, the Gnu Linker.
445
445
  p->next = NULL;
446
446
  p->symbol_count = 0;
447
447
  p->dynamic = config.dynamic_link;
 
448
  p->as_needed = as_needed;
448
449
  p->whole_archive = whole_archive;
449
450
  p->loaded = FALSE;
450
451
  lang_statement_append (&input_file_chain,
622
623
 
623
624
      lookup->next = NULL;
624
625
      lookup->bfd_section = NULL;
625
 
      lookup->processed = FALSE;
 
626
      lookup->processed = 0;
626
627
      lookup->sectype = normal_section;
627
628
      lookup->addr_tree = NULL;
628
629
      lang_list_init (&lookup->children);
775
776
      exp_init_os (exp->trinary.rhs);
776
777
      break;
777
778
 
 
779
    case etree_assert:
 
780
      exp_init_os (exp->assert_s.child);
 
781
      break;
 
782
      
778
783
    case etree_unary:
779
784
      exp_init_os (exp->unary.child);
780
785
      break;
1097
1102
          flags &= ~ (SEC_MERGE | SEC_STRINGS);
1098
1103
        }
1099
1104
 
1100
 
      /* For now make .tbss normal section.  */
1101
 
      if ((flags & SEC_THREAD_LOCAL) && ! link_info.relocatable)
1102
 
        flags |= SEC_LOAD;
1103
 
 
1104
1105
      section->output_section->flags |= flags;
1105
1106
 
1106
1107
      if (flags & SEC_MERGE)
1320
1321
       search != NULL;
1321
1322
       search = (lang_input_statement_type *) search->next_real_file)
1322
1323
    {
1323
 
      if (search->filename == NULL && name == NULL)
 
1324
      /* Use the local_sym_name as the name of the file that has
 
1325
         already been loaded as filename might have been transformed
 
1326
         via the search directory lookup mechanism.  */
 
1327
      const char * filename = search->local_sym_name;
 
1328
 
 
1329
      if (filename == NULL && name == NULL)
1324
1330
        return search;
1325
 
      if (search->filename != NULL
 
1331
      if (filename != NULL
1326
1332
          && name != NULL
1327
 
          && strcmp (search->filename, name) == 0)
 
1333
          && strcmp (filename, name) == 0)
1328
1334
        break;
1329
1335
    }
1330
1336
 
1331
1337
  if (search == NULL)
1332
 
    search = new_afile (name, lang_input_file_is_file_enum, default_target,
 
1338
    search = new_afile (name, lang_input_file_is_search_file_enum, default_target,
1333
1339
                        FALSE);
1334
1340
 
1335
1341
  /* If we have already added this file, or this file is not real
1794
1800
    }
1795
1801
}
1796
1802
 
 
1803
/* Convert between addresses in bytes and sizes in octets.
 
1804
   For currently supported targets, octets_per_byte is always a power
 
1805
   of two, so we can use shifts.  */
 
1806
#define TO_ADDR(X) ((X) >> opb_shift)
 
1807
#define TO_SIZE(X) ((X) << opb_shift)
 
1808
 
 
1809
/* Support the above.  */
 
1810
static unsigned int opb_shift = 0;
 
1811
 
 
1812
static void
 
1813
init_opb (void)
 
1814
{
 
1815
  unsigned x = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
 
1816
                                              ldfile_output_machine);
 
1817
  opb_shift = 0;
 
1818
  if (x > 1)
 
1819
    while ((x & 1) == 0)
 
1820
      {
 
1821
        x >>= 1;
 
1822
        ++opb_shift;
 
1823
      }
 
1824
  ASSERT (x == 1);
 
1825
}
 
1826
 
1797
1827
/* Open all the input files.  */
1798
1828
 
1799
1829
static void
1813
1843
          /* Maybe we should load the file's symbols.  */
1814
1844
          if (s->wild_statement.filename
1815
1845
              && ! wildcardp (s->wild_statement.filename))
1816
 
            (void) lookup_name (s->wild_statement.filename);
 
1846
            lookup_name (s->wild_statement.filename);
1817
1847
          open_input_bfds (s->wild_statement.children.head, force);
1818
1848
          break;
1819
1849
        case lang_group_statement_enum:
2065
2095
                                        target,
2066
2096
                                        output_section_statement);
2067
2097
          break;
 
2098
        case lang_data_statement_enum:
 
2099
          /* Make sure that any sections mentioned in the expression
 
2100
             are initialized.  */
 
2101
          exp_init_os (s->data_statement.exp);
 
2102
          /* FALLTHROUGH */
2068
2103
        case lang_fill_statement_enum:
2069
2104
        case lang_input_section_enum:
2070
2105
        case lang_object_symbols_statement_enum:
2071
 
        case lang_data_statement_enum:
2072
2106
        case lang_reloc_statement_enum:
2073
2107
        case lang_padding_statement_enum:
2074
2108
        case lang_input_statement_enum:
2267
2301
{
2268
2302
  asection *i = in->section;
2269
2303
  bfd_size_type size = i->_cooked_size != 0 ? i->_cooked_size : i->_raw_size;
2270
 
  unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
2271
 
                                                ldfile_output_machine);
 
2304
 
 
2305
  init_opb ();
2272
2306
  if (size != 0)
2273
2307
    {
2274
2308
      print_space ();
2292
2326
            }
2293
2327
 
2294
2328
          minfo ("0x%V %W %B\n",
2295
 
                 i->output_section->vma + i->output_offset, size / opb,
 
2329
                 i->output_section->vma + i->output_offset, TO_ADDR (size),
2296
2330
                 i->owner);
2297
2331
 
2298
2332
          if (i->_cooked_size != 0 && i->_cooked_size != i->_raw_size)
2314
2348
 
2315
2349
          bfd_link_hash_traverse (link_info.hash, print_one_symbol, i);
2316
2350
 
2317
 
          print_dot = i->output_section->vma + i->output_offset + size / opb;
 
2351
          print_dot = (i->output_section->vma + i->output_offset
 
2352
                       + TO_ADDR (size));
2318
2353
        }
2319
2354
    }
2320
2355
}
2337
2372
  bfd_vma addr;
2338
2373
  bfd_size_type size;
2339
2374
  const char *name;
2340
 
  unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
2341
 
                                                ldfile_output_machine);
2342
2375
 
 
2376
  init_opb ();
2343
2377
  for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
2344
2378
    print_space ();
2345
2379
 
2383
2417
 
2384
2418
  print_nl ();
2385
2419
 
2386
 
  print_dot = addr + size / opb;
2387
 
 
 
2420
  print_dot = addr + TO_ADDR (size);
2388
2421
}
2389
2422
 
2390
2423
/* Print an address statement.  These are generated by options like
2406
2439
  int i;
2407
2440
  bfd_vma addr;
2408
2441
  bfd_size_type size;
2409
 
  unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
2410
 
                                                ldfile_output_machine);
2411
2442
 
 
2443
  init_opb ();
2412
2444
  for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
2413
2445
    print_space ();
2414
2446
 
2429
2461
 
2430
2462
  print_nl ();
2431
2463
 
2432
 
  print_dot = addr + size / opb;
 
2464
  print_dot = addr + TO_ADDR (size);
2433
2465
}
2434
2466
 
2435
2467
static void
2437
2469
{
2438
2470
  int len;
2439
2471
  bfd_vma addr;
2440
 
  unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
2441
 
                                                ldfile_output_machine);
2442
2472
 
 
2473
  init_opb ();
2443
2474
  minfo (" *fill*");
2444
2475
 
2445
2476
  len = sizeof " *fill*" - 1;
2464
2495
 
2465
2496
  print_nl ();
2466
2497
 
2467
 
  print_dot = addr + s->size / opb;
 
2498
  print_dot = addr + TO_ADDR (s->size);
2468
2499
}
2469
2500
 
2470
2501
static void
2693
2724
 
2694
2725
  if (!is->ifile->just_syms_flag)
2695
2726
    {
2696
 
      unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
2697
 
                                                    ldfile_output_machine);
2698
2727
      unsigned int alignment_needed;
2699
2728
      asection *o;
2700
2729
 
2714
2743
 
2715
2744
      if (alignment_needed != 0)
2716
2745
        {
2717
 
          insert_pad (this_ptr, fill, alignment_needed * opb, o, dot);
 
2746
          insert_pad (this_ptr, fill, TO_SIZE (alignment_needed), o, dot);
2718
2747
          dot += alignment_needed;
2719
2748
        }
2720
2749
 
2724
2753
 
2725
2754
      /* Mark how big the output section must be to contain this now.  */
2726
2755
      if (i->_cooked_size != 0)
2727
 
        dot += i->_cooked_size / opb;
 
2756
        dot += TO_ADDR (i->_cooked_size);
2728
2757
      else
2729
 
        dot += i->_raw_size / opb;
2730
 
      o->_raw_size = (dot - o->vma) * opb;
 
2758
        dot += TO_ADDR (i->_raw_size);
 
2759
      o->_raw_size = TO_SIZE (dot - o->vma);
2731
2760
    }
2732
2761
  else
2733
2762
    {
2738
2767
}
2739
2768
 
2740
2769
#define IGNORE_SECTION(bfd, s) \
2741
 
  (((bfd_get_section_flags (bfd, s) & (SEC_ALLOC | SEC_LOAD))   \
2742
 
    != (SEC_ALLOC | SEC_LOAD))                                  \
 
2770
  (((bfd_get_section_flags (bfd, s) & SEC_THREAD_LOCAL)                 \
 
2771
    ? ((bfd_get_section_flags (bfd, s) & (SEC_LOAD | SEC_NEVER_LOAD))   \
 
2772
       != SEC_LOAD)                                                     \
 
2773
    :  ((bfd_get_section_flags (bfd, s) & (SEC_ALLOC | SEC_NEVER_LOAD)) \
 
2774
        != SEC_ALLOC))                                                  \
2743
2775
   || bfd_section_size (bfd, s) == 0)
2744
2776
 
2745
2777
/* Check to see if any allocated sections overlap with other allocated
2750
2782
lang_check_section_addresses (void)
2751
2783
{
2752
2784
  asection *s;
2753
 
  unsigned opb = bfd_octets_per_byte (output_bfd);
2754
2785
 
2755
2786
  /* Scan all sections in the output list.  */
2756
2787
  for (s = output_bfd->sections; s != NULL; s = s->next)
2778
2809
          /* We must check the sections' LMA addresses not their
2779
2810
             VMA addresses because overlay sections can have
2780
2811
             overlapping VMAs but they must have distinct LMAs.  */
2781
 
          s_start  = bfd_section_lma (output_bfd, s);
 
2812
          s_start = bfd_section_lma (output_bfd, s);
2782
2813
          os_start = bfd_section_lma (output_bfd, os);
2783
 
          s_end    = s_start  + bfd_section_size (output_bfd, s) / opb - 1;
2784
 
          os_end   = os_start + bfd_section_size (output_bfd, os) / opb - 1;
 
2814
          s_end = s_start + TO_ADDR (bfd_section_size (output_bfd, s)) - 1;
 
2815
          os_end = os_start + TO_ADDR (bfd_section_size (output_bfd, os)) - 1;
2785
2816
 
2786
2817
          /* Look for an overlap.  */
2787
2818
          if ((s_end < os_start) || (s_start > os_end))
2805
2836
 
2806
2837
static void
2807
2838
os_region_check (lang_output_section_statement_type *os,
2808
 
                 struct memory_region_struct *region,
 
2839
                 lang_memory_region_type *region,
2809
2840
                 etree_type *tree,
2810
2841
                 bfd_vma base)
2811
2842
{
2846
2877
   bfd_boolean *relax,
2847
2878
   bfd_boolean check_regions)
2848
2879
{
2849
 
  unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
2850
 
                                                ldfile_output_machine);
2851
 
 
2852
2880
  /* Size up the sections from their constituent parts.  */
2853
2881
  for (; s != NULL; s = s->header.next)
2854
2882
    {
2910
2938
                       region, and some non default memory regions were
2911
2939
                       defined, issue an error message.  */
2912
2940
                    if (!IGNORE_SECTION (output_bfd, os->bfd_section)
2913
 
                        && (bfd_get_section_flags (output_bfd, os->bfd_section)
2914
 
                            & SEC_NEVER_LOAD) == 0
2915
2941
                        && ! link_info.relocatable
2916
2942
                        && check_regions
2917
2943
                        && strcmp (os->region->name, DEFAULT_MEMORY_REGION) == 0
2958
2984
                  {
2959
2985
                    etree_value_type r;
2960
2986
 
 
2987
                    os->processed = -1;
2961
2988
                    r = exp_fold_tree (os->addr_tree,
2962
2989
                                       abs_output_section,
2963
2990
                                       lang_allocating_phase_enum,
2964
2991
                                       dot, &dot);
 
2992
                    os->processed = 0;
 
2993
                    
2965
2994
                    if (!r.valid_p)
2966
 
                      einfo (_("%F%S: non constant address expression for section %s\n"),
 
2995
                      einfo (_("%F%S: non constant or forward reference address expression for section %s\n"),
2967
2996
                             os->name);
2968
2997
 
2969
2998
                    dot = r.value + r.section->bfd_section->vma;
2985
3014
 
2986
3015
            /* Put the section within the requested block size, or
2987
3016
               align at the block boundary.  */
2988
 
            after = align_n (os->bfd_section->vma
2989
 
                             + os->bfd_section->_raw_size / opb,
2990
 
                             (bfd_vma) os->block_value);
 
3017
            after = ((os->bfd_section->vma
 
3018
                      + TO_ADDR (os->bfd_section->_raw_size)
 
3019
                      + os->block_value - 1)
 
3020
                     & - (bfd_vma) os->block_value);
2991
3021
 
2992
3022
            if (bfd_is_abs_section (os->bfd_section))
2993
3023
              ASSERT (after == os->bfd_section->vma);
2994
 
            else if ((os->bfd_section->flags & SEC_HAS_CONTENTS) == 0
2995
 
                     && (os->bfd_section->flags & SEC_THREAD_LOCAL)
2996
 
                     && ! link_info.relocatable)
2997
 
              os->bfd_section->_raw_size = 0;
2998
3024
            else
2999
 
              os->bfd_section->_raw_size =
3000
 
                (after - os->bfd_section->vma) * opb;
3001
 
 
3002
 
            dot = os->bfd_section->vma + os->bfd_section->_raw_size / opb;
3003
 
            os->processed = TRUE;
 
3025
              os->bfd_section->_raw_size
 
3026
                = TO_SIZE (after - os->bfd_section->vma);
 
3027
 
 
3028
            dot = os->bfd_section->vma;
 
3029
            /* .tbss sections effectively have zero size.  */
 
3030
            if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0
 
3031
                || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0
 
3032
                || link_info.relocatable)
 
3033
              dot += TO_ADDR (os->bfd_section->_raw_size);
 
3034
 
 
3035
            os->processed = 1;
3004
3036
 
3005
3037
            if (os->update_dot_tree != 0)
3006
3038
              exp_fold_tree (os->update_dot_tree, abs_output_section,
3037
3069
                    /* Set load_base, which will be handled later.  */
3038
3070
                    os->load_base = exp_intop (os->lma_region->current);
3039
3071
                    os->lma_region->current +=
3040
 
                      os->bfd_section->_raw_size / opb;
 
3072
                      TO_ADDR (os->bfd_section->_raw_size);
3041
3073
                    if (check_regions)
3042
3074
                      os_region_check (os, os->lma_region, NULL,
3043
3075
                                       os->bfd_section->lma);
3062
3094
            s->data_statement.output_section =
3063
3095
              output_section_statement->bfd_section;
3064
3096
 
 
3097
            /* We might refer to provided symbols in the expression, and
 
3098
               need to mark them as needed.  */
 
3099
            exp_fold_tree (s->data_statement.exp, abs_output_section,
 
3100
                           lang_allocating_phase_enum, dot, &dot);
 
3101
 
3065
3102
            switch (s->data_statement.type)
3066
3103
              {
3067
3104
              default:
3080
3117
                size = BYTE_SIZE;
3081
3118
                break;
3082
3119
              }
3083
 
            if (size < opb)
3084
 
              size = opb;
3085
 
            dot += size / opb;
 
3120
            if (size < TO_SIZE ((unsigned) 1))
 
3121
              size = TO_SIZE ((unsigned) 1);
 
3122
            dot += TO_ADDR (size);
3086
3123
            output_section_statement->bfd_section->_raw_size += size;
3087
3124
            /* The output section gets contents, and then we inspect for
3088
3125
               any flags set in the input script which override any ALLOC.  */
3104
3141
            s->reloc_statement.output_section =
3105
3142
              output_section_statement->bfd_section;
3106
3143
            size = bfd_get_reloc_size (s->reloc_statement.howto);
3107
 
            dot += size / opb;
 
3144
            dot += TO_ADDR (size);
3108
3145
            output_section_statement->bfd_section->_raw_size += size;
3109
3146
          }
3110
3147
          break;
3179
3216
                    /* Insert a pad after this statement.  We can't
3180
3217
                       put the pad before when relaxing, in case the
3181
3218
                       assignment references dot.  */
3182
 
                    insert_pad (&s->header.next, fill, (newdot - dot) * opb,
 
3219
                    insert_pad (&s->header.next, fill, TO_SIZE (newdot - dot),
3183
3220
                                output_section_statement->bfd_section, dot);
3184
3221
 
3185
3222
                    /* Don't neuter the pad below when relaxing.  */
3186
3223
                    s = s->header.next;
3187
3224
                  }
3188
3225
 
 
3226
                /* If dot is advanced, this implies that the section should
 
3227
                   have space allocated to it, unless the user has explicitly
 
3228
                   stated that the section should never be loaded.  */
 
3229
                if (!(output_section_statement->flags & (SEC_NEVER_LOAD | SEC_ALLOC)))
 
3230
                  output_section_statement->bfd_section->flags |= SEC_ALLOC;
 
3231
 
3189
3232
                dot = newdot;
3190
3233
              }
3191
3234
          }
3261
3304
          && first + last <= exp_data_seg.pagesize)
3262
3305
        {
3263
3306
          exp_data_seg.phase = exp_dataseg_adjust;
 
3307
          lang_statement_iteration++;
3264
3308
          result = lang_size_sections_1 (s, output_section_statement, prev,
3265
3309
                                         fill, dot, relax, check_regions);
3266
3310
        }
3286
3330
   fill_type *fill,
3287
3331
   bfd_vma dot)
3288
3332
{
3289
 
  unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
3290
 
                                                ldfile_output_machine);
3291
 
 
3292
3333
  for (; s != NULL; s = s->header.next)
3293
3334
    {
3294
3335
      switch (s->header.type)
3308
3349
            if (os->bfd_section != NULL)
3309
3350
              {
3310
3351
                dot = os->bfd_section->vma;
3311
 
                (void) lang_do_assignments_1 (os->children.head, os,
3312
 
                                              os->fill, dot);
3313
 
                dot = os->bfd_section->vma + os->bfd_section->_raw_size / opb;
 
3352
                lang_do_assignments_1 (os->children.head, os, os->fill, dot);
 
3353
                dot = (os->bfd_section->vma
 
3354
                       + TO_ADDR (os->bfd_section->_raw_size));
3314
3355
 
3315
3356
              }
3316
3357
            if (os->load_base)
3348
3389
            value = exp_fold_tree (s->data_statement.exp,
3349
3390
                                   abs_output_section,
3350
3391
                                   lang_final_phase_enum, dot, &dot);
3351
 
            s->data_statement.value = value.value;
3352
3392
            if (!value.valid_p)
3353
3393
              einfo (_("%F%P: invalid data statement\n"));
 
3394
            s->data_statement.value
 
3395
              = value.value + value.section->bfd_section->vma;
3354
3396
          }
3355
3397
          {
3356
3398
            unsigned int size;
3372
3414
                size = BYTE_SIZE;
3373
3415
                break;
3374
3416
              }
3375
 
            if (size < opb)
3376
 
              size = opb;
3377
 
            dot += size / opb;
 
3417
            if (size < TO_SIZE ((unsigned) 1))
 
3418
              size = TO_SIZE ((unsigned) 1);
 
3419
            dot += TO_ADDR (size);
3378
3420
          }
3379
3421
          break;
3380
3422
 
3389
3431
            if (!value.valid_p)
3390
3432
              einfo (_("%F%P: invalid reloc statement\n"));
3391
3433
          }
3392
 
          dot += bfd_get_reloc_size (s->reloc_statement.howto) / opb;
 
3434
          dot += TO_ADDR (bfd_get_reloc_size (s->reloc_statement.howto));
3393
3435
          break;
3394
3436
 
3395
3437
        case lang_input_section_enum:
3397
3439
            asection *in = s->input_section.section;
3398
3440
 
3399
3441
            if (in->_cooked_size != 0)
3400
 
              dot += in->_cooked_size / opb;
 
3442
              dot += TO_ADDR (in->_cooked_size);
3401
3443
            else
3402
 
              dot += in->_raw_size / opb;
 
3444
              dot += TO_ADDR (in->_raw_size);
3403
3445
          }
3404
3446
          break;
3405
3447
 
3419
3461
 
3420
3462
          break;
3421
3463
        case lang_padding_statement_enum:
3422
 
          dot += s->padding_statement.size / opb;
 
3464
          dot += TO_ADDR (s->padding_statement.size);
3423
3465
          break;
3424
3466
 
3425
3467
        case lang_group_statement_enum:
3440
3482
  return dot;
3441
3483
}
3442
3484
 
3443
 
bfd_vma
 
3485
void
3444
3486
lang_do_assignments (lang_statement_union_type *s,
3445
 
                     lang_output_section_statement_type
3446
 
                     *output_section_statement,
 
3487
                     lang_output_section_statement_type *output_section_statement,
3447
3488
                     fill_type *fill,
3448
3489
                     bfd_vma dot)
3449
3490
{
3489
3530
      h = bfd_link_hash_lookup (link_info.hash, buf, FALSE, FALSE, TRUE);
3490
3531
      if (h != NULL && h->type == bfd_link_hash_undefined)
3491
3532
        {
3492
 
          unsigned opb;
3493
 
 
3494
 
          opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
3495
 
                                               ldfile_output_machine);
3496
3533
          h->type = bfd_link_hash_defined;
3497
3534
          if (s->_cooked_size != 0)
3498
 
            h->u.def.value = s->_cooked_size / opb;
 
3535
            h->u.def.value = TO_ADDR (s->_cooked_size);
3499
3536
          else
3500
 
            h->u.def.value = s->_raw_size / opb;
 
3537
            h->u.def.value = TO_ADDR (s->_raw_size);
3501
3538
          h->u.def.section = bfd_abs_section_ptr;
3502
3539
        }
3503
3540
 
3650
3687
          if (! bfd_merge_private_bfd_data (input_bfd, output_bfd))
3651
3688
            {
3652
3689
              if (command_line.warn_mismatch)
3653
 
                einfo (_("%E%X: failed to merge target specific data of file %B\n"),
 
3690
                einfo (_("%P%X: failed to merge target specific data of file %B\n"),
3654
3691
                       input_bfd);
3655
3692
            }
3656
3693
          if (! command_line.warn_mismatch)
3691
3728
  unsigned int power_of_two;
3692
3729
  bfd_vma size;
3693
3730
  asection *section;
3694
 
  unsigned opb = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
3695
 
                                                ldfile_output_machine);
3696
3731
 
3697
3732
  if (h->type != bfd_link_hash_common)
3698
3733
    return TRUE;
3706
3741
 
3707
3742
  section = h->u.c.p->section;
3708
3743
 
3709
 
  /* Increase the size of the section.  */
3710
 
  section->_cooked_size = align_n ((section->_cooked_size + opb - 1) / opb,
3711
 
                                   (bfd_vma) 1 << power_of_two) * opb;
 
3744
  /* Increase the size of the section to align the common sym.  */
 
3745
  section->_cooked_size += ((bfd_vma) 1 << (power_of_two + opb_shift)) - 1;
 
3746
  section->_cooked_size &= (- (bfd_vma) 1 << (power_of_two + opb_shift));
3712
3747
 
3713
3748
  /* Adjust the alignment if necessary.  */
3714
3749
  if (power_of_two > section->alignment_power)
3903
3938
    }
3904
3939
}
3905
3940
 
3906
 
#if 0
3907
 
 
3908
 
/* Not used.  */
3909
 
 
3910
 
void
3911
 
lang_for_each_input_section (void (*func) (bfd *ab, asection *as))
3912
 
{
3913
 
  LANG_FOR_EACH_INPUT_STATEMENT (f)
3914
 
    {
3915
 
      asection *s;
3916
 
 
3917
 
      for (s = f->the_bfd->sections; s != NULL; s = s->next)
3918
 
        func (f->the_bfd, s);
3919
 
    }
3920
 
}
3921
 
 
3922
 
#endif
3923
 
 
3924
3941
void
3925
3942
ldlang_add_file (lang_input_statement_type *entry)
3926
3943
{
3989
4006
lang_enter_output_section_statement (const char *output_section_statement_name,
3990
4007
                                     etree_type *address_exp,
3991
4008
                                     enum section_type sectype,
3992
 
                                     bfd_vma block_value,
3993
4009
                                     etree_type *align,
3994
4010
                                     etree_type *subalign,
3995
4011
                                     etree_type *ebase)
4016
4032
    os->flags = SEC_NO_FLAGS;
4017
4033
  else
4018
4034
    os->flags = SEC_NEVER_LOAD;
4019
 
  os->block_value = block_value ? block_value : 1;
 
4035
  os->block_value = 1;
4020
4036
  stat_ptr = &os->children;
4021
4037
 
4022
4038
  os->subsection_alignment =
4142
4158
 
4143
4159
  /* Open the output file.  */
4144
4160
  lang_for_each_statement (ldlang_open_output);
 
4161
  init_opb ();
4145
4162
 
4146
4163
  ldemul_create_output_section_statements ();
4147
4164
 
4235
4252
 
4236
4253
      do
4237
4254
        {
4238
 
          lang_reset_memory_regions ();
4239
 
 
4240
4255
          relax_again = FALSE;
4241
4256
 
4242
4257
          /* Note: pe-dll.c does something like this also.  If you find
4248
4263
          lang_do_assignments (statement_list.head, abs_output_section,
4249
4264
                               NULL, 0);
4250
4265
 
 
4266
          /* We must do this after lang_do_assignments, because it uses
 
4267
             _raw_size.  */
 
4268
          lang_reset_memory_regions ();
 
4269
 
4251
4270
          /* Perform another relax pass - this time we know where the
4252
4271
             globals are, so can make a better guess.  */
4253
4272
          lang_size_sections (statement_list.head, abs_output_section,
4255
4274
 
4256
4275
          /* If the normal relax is done and the relax finalize pass
4257
4276
             is not performed yet, we perform another relax pass.  */
4258
 
          if (!relax_again && !link_info.relax_finalizing)
 
4277
          if (!relax_again && link_info.need_relax_finalize)
4259
4278
            {
4260
 
              link_info.relax_finalizing = TRUE;
 
4279
              link_info.need_relax_finalize = FALSE;
4261
4280
              relax_again = TRUE;
4262
4281
            }
4263
4282
        }
4264
4283
      while (relax_again);
4265
4284
 
4266
4285
      /* Final extra sizing to report errors.  */
 
4286
      lang_do_assignments (statement_list.head, abs_output_section, NULL, 0);
4267
4287
      lang_reset_memory_regions ();
4268
 
      lang_do_assignments (statement_list.head, abs_output_section, NULL, 0);
4269
4288
      lang_size_sections (statement_list.head, abs_output_section,
4270
4289
                          &statement_list.head, 0, 0, NULL, TRUE);
4271
4290
    }
4485
4504
   It is an error to specify both a load region and a load address.  */
4486
4505
 
4487
4506
static void
4488
 
lang_get_regions (struct memory_region_struct **region,
4489
 
                  struct memory_region_struct **lma_region,
 
4507
lang_get_regions (lang_memory_region_type **region,
 
4508
                  lang_memory_region_type **lma_region,
4490
4509
                  const char *memspec,
4491
4510
                  const char *lma_memspec,
4492
 
                  int have_lma_p)
 
4511
                  bfd_boolean have_lma,
 
4512
                  bfd_boolean have_vma)
4493
4513
{
4494
4514
  *lma_region = lang_memory_region_lookup (lma_memspec, FALSE);
4495
4515
 
4496
 
  /* If no runtime region has been given, but the load region has
4497
 
     been, use the load region.  */
4498
 
  if (lma_memspec != 0 && strcmp (memspec, DEFAULT_MEMORY_REGION) == 0)
 
4516
  /* If no runtime region or VMA has been specified, but the load region has
 
4517
     been specified, then use the load region for the runtime region as well.  */
 
4518
  if (lma_memspec != NULL
 
4519
      && ! have_vma
 
4520
      && strcmp (memspec, DEFAULT_MEMORY_REGION) == 0)
4499
4521
    *region = *lma_region;
4500
4522
  else
4501
4523
    *region = lang_memory_region_lookup (memspec, FALSE);
4502
4524
 
4503
 
  if (have_lma_p && lma_memspec != 0)
 
4525
  if (have_lma && lma_memspec != 0)
4504
4526
    einfo (_("%X%P:%S: section has both a load address and a load region\n"));
4505
4527
}
4506
4528
 
4507
4529
void
4508
 
lang_leave_output_section_statement
4509
 
  (fill_type *fill, const char *memspec,
4510
 
   struct lang_output_section_phdr_list *phdrs, const char *lma_memspec)
 
4530
lang_leave_output_section_statement (fill_type *fill, const char *memspec,
 
4531
                                     lang_output_section_phdr_list *phdrs,
 
4532
                                     const char *lma_memspec)
4511
4533
{
4512
4534
  lang_get_regions (&current_section->region,
4513
4535
                    &current_section->lma_region,
4514
4536
                    memspec, lma_memspec,
4515
 
                    current_section->load_base != 0);
 
4537
                    current_section->load_base != NULL,
 
4538
                    current_section->addr_tree != NULL);
4516
4539
  current_section->fill = fill;
4517
4540
  current_section->phdrs = phdrs;
4518
4541
  stat_ptr = &statement_list;
4575
4598
        h->u.def.value = 0;
4576
4599
      else
4577
4600
        h->u.def.value = (bfd_get_section_vma (output_bfd, sec)
4578
 
                          + bfd_section_size (output_bfd, sec) /
4579
 
                          bfd_octets_per_byte (output_bfd));
 
4601
                          + TO_ADDR (bfd_section_size (output_bfd, sec)));
4580
4602
 
4581
4603
      h->u.def.section = bfd_abs_section_ptr;
4582
4604
    }
4672
4694
{
4673
4695
  unsigned int alc;
4674
4696
  asection **secs;
4675
 
  struct lang_output_section_phdr_list *last;
 
4697
  lang_output_section_phdr_list *last;
4676
4698
  struct lang_phdr *l;
4677
4699
  lang_statement_union_type *u;
4678
4700
 
4691
4713
           u = u->output_section_statement.next)
4692
4714
        {
4693
4715
          lang_output_section_statement_type *os;
4694
 
          struct lang_output_section_phdr_list *pl;
 
4716
          lang_output_section_phdr_list *pl;
4695
4717
 
4696
4718
          os = &u->output_section_statement;
4697
4719
 
4751
4773
       u != NULL;
4752
4774
       u = u->output_section_statement.next)
4753
4775
    {
4754
 
      struct lang_output_section_phdr_list *pl;
 
4776
      lang_output_section_phdr_list *pl;
4755
4777
 
4756
4778
      if (u->output_section_statement.bfd_section == NULL)
4757
4779
        continue;
4768
4790
/* Record a list of sections which may not be cross referenced.  */
4769
4791
 
4770
4792
void
4771
 
lang_add_nocrossref (struct lang_nocrossref *l)
 
4793
lang_add_nocrossref (lang_nocrossref_type *l)
4772
4794
{
4773
4795
  struct lang_nocrossrefs *n;
4774
4796
 
4825
4847
  etree_type *size;
4826
4848
 
4827
4849
  lang_enter_output_section_statement (name, overlay_vma, normal_section,
4828
 
                                       0, 0, overlay_subalign, 0);
 
4850
                                       0, overlay_subalign, 0);
4829
4851
 
4830
4852
  /* If this is the first section, then base the VMA of future
4831
4853
     sections on this one.  This will work correctly even if `.' is
4853
4875
 
4854
4876
void
4855
4877
lang_leave_overlay_section (fill_type *fill,
4856
 
                            struct lang_output_section_phdr_list *phdrs)
 
4878
                            lang_output_section_phdr_list *phdrs)
4857
4879
{
4858
4880
  const char *name;
4859
4881
  char *clean, *s2;
4900
4922
                    int nocrossrefs,
4901
4923
                    fill_type *fill,
4902
4924
                    const char *memspec,
4903
 
                    struct lang_output_section_phdr_list *phdrs,
 
4925
                    lang_output_section_phdr_list *phdrs,
4904
4926
                    const char *lma_memspec)
4905
4927
{
4906
4928
  lang_memory_region_type *region;
4907
4929
  lang_memory_region_type *lma_region;
4908
4930
  struct overlay_list *l;
4909
 
  struct lang_nocrossref *nocrossref;
 
4931
  lang_nocrossref_type *nocrossref;
4910
4932
 
4911
4933
  lang_get_regions (&region, &lma_region,
4912
4934
                    memspec, lma_memspec,
4913
 
                    lma_expr != 0);
 
4935
                    lma_expr != NULL, FALSE);
4914
4936
 
4915
4937
  nocrossref = NULL;
4916
4938
 
4947
4969
 
4948
4970
      if (nocrossrefs)
4949
4971
        {
4950
 
          struct lang_nocrossref *nc;
 
4972
          lang_nocrossref_type *nc;
4951
4973
 
4952
4974
          nc = xmalloc (sizeof *nc);
4953
4975
          nc->name = l->os->name;
4989
5011
 
4990
5012
  if (head->mask & BFD_ELF_VERSION_CXX_TYPE)
4991
5013
    {
4992
 
      cxx_sym = cplus_demangle (sym, /* DMGL_NO_TPARAMS */ 0);
 
5014
      cxx_sym = cplus_demangle (sym, DMGL_PARAMS | DMGL_ANSI);
4993
5015
      if (!cxx_sym)
4994
5016
        cxx_sym = sym;
4995
5017
    }