* x86_64.cc (Target_x86_64::saw_tls_block_reloc_): Remove member.
[binutils-gdb.git] / gold / arm.cc
index aadac32dec937720a419171f5c5db290a8025037..79a96633d4868bd589caa4b4841942738eff4bdf 100644 (file)
@@ -126,7 +126,7 @@ const size_t ARM_TCB_SIZE = 8;
 // compilation time and generate a representation of it in PODs only.  That
 // way we can avoid initialization when the linker starts.
 
-Arm_reloc_property_table *arm_reloc_property_table = NULL;
+Arm_reloc_property_tablearm_reloc_property_table = NULL;
 
 // Instruction template class.  This class is similar to the insn_sequence
 // struct in bfd/elf32-arm.c.
@@ -1064,6 +1064,11 @@ class Arm_exidx_cantunwind : public Output_section_data
       this->do_fixed_endian_write<false>(of);
   }
 
+  // Write to a map file.
+  void
+  do_print_to_mapfile(Mapfile* mapfile) const
+  { mapfile->print_output_data(this, _("** ARM cantunwind")); }
+
  private:
   // Implement do_write for a given endianness.
   template<bool big_endian>
@@ -1636,7 +1641,7 @@ class Arm_relobj : public Sized_relobj<32, big_endian>
 
   void
   do_relocate_sections(const Symbol_table* symtab, const Layout* layout,
-                      const unsigned char* pshdrs,
+                      const unsigned char* pshdrs, Output_file* of,
                       typename Sized_relobj<32, big_endian>::Views* pivews);
 
   // Read the symbol information.
@@ -1653,18 +1658,18 @@ class Arm_relobj : public Sized_relobj<32, big_endian>
   bool
   section_needs_reloc_stub_scanning(const elfcpp::Shdr<32, big_endian>&,
                                    const Relobj::Output_sections&,
-                                   const Symbol_table *, const unsigned char*);
+                                   const Symbol_table*, const unsigned char*);
 
   // Whether a section is a scannable text section.
   bool
   section_is_scannable(const elfcpp::Shdr<32, big_endian>&, unsigned int,
-                      const Output_section*, const Symbol_table *);
+                      const Output_section*, const Symbol_table*);
 
   // Whether a section needs to be scanned for the Cortex-A8 erratum.
   bool
   section_needs_cortex_a8_stub_scanning(const elfcpp::Shdr<32, big_endian>&,
                                        unsigned int, Output_section*,
-                                       const Symbol_table *);
+                                       const Symbol_table*);
 
   // Scan a section for the Cortex-A8 erratum.
   void
@@ -2342,15 +2347,36 @@ class Target_arm : public Sized_target<32, big_endian>
 
   // Return the size of the GOT section.
   section_size_type
-  got_size()
+  got_size() const
   {
     gold_assert(this->got_ != NULL);
     return this->got_->data_size();
   }
 
+  // Return the number of entries in the GOT.
+  unsigned int
+  got_entry_count() const
+  {
+    if (!this->has_got_section())
+      return 0;
+    return this->got_size() / 4;
+  }
+
+  // Return the number of entries in the PLT.
+  unsigned int
+  plt_entry_count() const;
+
+  // Return the offset of the first non-reserved PLT entry.
+  unsigned int
+  first_plt_entry_offset() const;
+
+  // Return the size of each PLT entry.
+  unsigned int
+  plt_entry_size() const;
+
   // Map platform-specific reloc types
   static unsigned int
-  get_real_reloc_type (unsigned int r_type);
+  get_real_reloc_type(unsigned int r_type);
 
   //
   // Methods to support stub-generations.
@@ -2605,7 +2631,7 @@ class Target_arm : public Sized_target<32, big_endian>
     // reloc.  This means the relocation type accesses a symbol not via
     // GOT or PLT.
     static inline bool
-    reloc_is_non_pic (unsigned int r_type)
+    reloc_is_non_pic(unsigned int r_type)
     {
       switch (r_type)
        {
@@ -2816,6 +2842,9 @@ class Target_arm : public Sized_target<32, big_endian>
   static const Target::Target_info arm_info;
 
   // The types of GOT entries needed for this platform.
+  // These values are exposed to the ABI in an incremental link.
+  // Do not renumber existing values without changing the version
+  // number of the .gnu_incremental_inputs section.
   enum Got_type
   {
     GOT_TYPE_STANDARD = 0,      // GOT entry for a regular symbol
@@ -3049,14 +3078,14 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
   // Handle ARM long branches.
   static typename This::Status
   arm_branch_common(unsigned int, const Relocate_info<32, big_endian>*,
-                   unsigned char *, const Sized_symbol<32>*,
+                   unsigned char*, const Sized_symbol<32>*,
                    const Arm_relobj<big_endian>*, unsigned int,
                    const Symbol_value<32>*, Arm_address, Arm_address, bool);
 
   // Handle THUMB long branches.
   static typename This::Status
   thumb_branch_common(unsigned int, const Relocate_info<32, big_endian>*,
-                     unsigned char *, const Sized_symbol<32>*,
+                     unsigned char*, const Sized_symbol<32>*,
                      const Arm_relobj<big_endian>*, unsigned int,
                      const Symbol_value<32>*, Arm_address, Arm_address, bool);
 
@@ -3144,7 +3173,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_ABS8: S + A
   static inline typename This::Status
-  abs8(unsigned char *view,
+  abs8(unsigned charview,
        const Sized_relobj<32, big_endian>* object,
        const Symbol_value<32>* psymval)
   {
@@ -3166,7 +3195,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_THM_ABS5: S + A
   static inline typename This::Status
-  thm_abs5(unsigned char *view,
+  thm_abs5(unsigned charview,
        const Sized_relobj<32, big_endian>* object,
        const Symbol_value<32>* psymval)
   {
@@ -3188,7 +3217,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_ABS12: S + A
   static inline typename This::Status
-  abs12(unsigned char *view,
+  abs12(unsigned charview,
        const Sized_relobj<32, big_endian>* object,
        const Symbol_value<32>* psymval)
   {
@@ -3207,7 +3236,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_ABS16: S + A
   static inline typename This::Status
-  abs16(unsigned char *view,
+  abs16(unsigned charview,
        const Sized_relobj<32, big_endian>* object,
        const Symbol_value<32>* psymval)
   {
@@ -3226,7 +3255,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_ABS32: (S + A) | T
   static inline typename This::Status
-  abs32(unsigned char *view,
+  abs32(unsigned charview,
        const Sized_relobj<32, big_endian>* object,
        const Symbol_value<32>* psymval,
        Arm_address thumb_bit)
@@ -3241,7 +3270,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_REL32: (S + A) | T - P
   static inline typename This::Status
-  rel32(unsigned char *view,
+  rel32(unsigned charview,
        const Sized_relobj<32, big_endian>* object,
        const Symbol_value<32>* psymval,
        Arm_address address,
@@ -3257,13 +3286,13 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_THM_JUMP24: (S + A) | T - P
   static typename This::Status
-  thm_jump19(unsigned char *view, const Arm_relobj<big_endian>* object,
+  thm_jump19(unsigned charview, const Arm_relobj<big_endian>* object,
             const Symbol_value<32>* psymval, Arm_address address,
             Arm_address thumb_bit);
 
   // R_ARM_THM_JUMP6: S + A – P
   static inline typename This::Status
-  thm_jump6(unsigned char *view,
+  thm_jump6(unsigned charview,
            const Sized_relobj<32, big_endian>* object,
            const Symbol_value<32>* psymval,
            Arm_address address)
@@ -3285,7 +3314,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_THM_JUMP8: S + A – P
   static inline typename This::Status
-  thm_jump8(unsigned char *view,
+  thm_jump8(unsigned charview,
            const Sized_relobj<32, big_endian>* object,
            const Symbol_value<32>* psymval,
            Arm_address address)
@@ -3304,7 +3333,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_THM_JUMP11: S + A – P
   static inline typename This::Status
-  thm_jump11(unsigned char *view,
+  thm_jump11(unsigned charview,
            const Sized_relobj<32, big_endian>* object,
            const Symbol_value<32>* psymval,
            Arm_address address)
@@ -3351,7 +3380,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_GOT_PREL: GOT(S) + A - P
   static inline typename This::Status
-  got_prel(unsigned char *view,
+  got_prel(unsigned charview,
           Arm_address got_entry,
           Arm_address address)
   {
@@ -3361,7 +3390,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // R_ARM_PREL: (S + A) | T - P
   static inline typename This::Status
-  prel31(unsigned char *view,
+  prel31(unsigned charview,
         const Sized_relobj<32, big_endian>* object,
         const Symbol_value<32>* psymval,
         Arm_address address,
@@ -3428,7 +3457,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
   // R_ARM_THM_MOVW_BREL_NC: ((S + A) | T) - B(S)
   // R_ARM_THM_MOVW_BREL: ((S + A) | T) - B(S)
   static inline typename This::Status
-  thm_movw(unsigned char *view,
+  thm_movw(unsigned charview,
           const Sized_relobj<32, big_endian>* object,
           const Symbol_value<32>* psymval,
           Arm_address relative_address_base,
@@ -3585,7 +3614,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
   // R_ARM_V4BX
   static inline typename This::Status
   v4bx(const Relocate_info<32, big_endian>* relinfo,
-       unsigned char *view,
+       unsigned charview,
        const Arm_relobj<big_endian>* object,
        const Arm_address address,
        const bool is_interworking)
@@ -3812,7 +3841,7 @@ typename Arm_relocate_functions<big_endian>::Status
 Arm_relocate_functions<big_endian>::arm_branch_common(
     unsigned int r_type,
     const Relocate_info<32, big_endian>* relinfo,
-    unsigned char *view,
+    unsigned charview,
     const Sized_symbol<32>* gsym,
     const Arm_relobj<big_endian>* object,
     unsigned int r_sym,
@@ -3940,7 +3969,7 @@ typename Arm_relocate_functions<big_endian>::Status
 Arm_relocate_functions<big_endian>::thumb_branch_common(
     unsigned int r_type,
     const Relocate_info<32, big_endian>* relinfo,
-    unsigned char *view,
+    unsigned charview,
     const Sized_symbol<32>* gsym,
     const Arm_relobj<big_endian>* object,
     unsigned int r_sym,
@@ -4104,7 +4133,7 @@ Arm_relocate_functions<big_endian>::thumb_branch_common(
 template<bool big_endian>
 typename Arm_relocate_functions<big_endian>::Status
 Arm_relocate_functions<big_endian>::thm_jump19(
-    unsigned char *view,
+    unsigned charview,
     const Arm_relobj<big_endian>* object,
     const Symbol_value<32>* psymval,
     Arm_address address,
@@ -4156,7 +4185,8 @@ Target_arm<big_endian>::got_section(Symbol_table* symtab, Layout* layout)
       layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
                                      (elfcpp::SHF_ALLOC
                                       | elfcpp::SHF_WRITE),
-                                     this->got_, false, false, false, true);
+                                     this->got_, ORDER_RELRO, true);
+
       // The old GNU linker creates a .got.plt section.  We just
       // create another set of data in the .got section.  Note that we
       // always create a PLT if we create a GOT, although the PLT
@@ -4165,8 +4195,7 @@ Target_arm<big_endian>::got_section(Symbol_table* symtab, Layout* layout)
       layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
                                      (elfcpp::SHF_ALLOC
                                       | elfcpp::SHF_WRITE),
-                                     this->got_plt_, false, false, false,
-                                     false);
+                                     this->got_plt_, ORDER_DATA, false);
 
       // The first three entries are reserved.
       this->got_plt_->set_current_data_size(3 * 4);
@@ -4194,8 +4223,8 @@ Target_arm<big_endian>::rel_dyn_section(Layout* layout)
       gold_assert(layout != NULL);
       this->rel_dyn_ = new Reloc_section(parameters->options().combreloc());
       layout->add_output_section_data(".rel.dyn", elfcpp::SHT_REL,
-                                     elfcpp::SHF_ALLOC, this->rel_dyn_, true,
-                                     false, false, false);
+                                     elfcpp::SHF_ALLOC, this->rel_dyn_,
+                                     ORDER_DYNAMIC_RELOCS, false);
     }
   return this->rel_dyn_;
 }
@@ -5918,7 +5947,7 @@ Arm_relobj<big_endian>::section_is_scannable(
     const elfcpp::Shdr<32, big_endian>& shdr,
     unsigned int shndx,
     const Output_section* os,
-    const Symbol_table *symtab)
+    const Symbol_tablesymtab)
 {
   // Skip any empty sections, unallocated sections or sections whose
   // type are not SHT_PROGBITS.
@@ -5953,7 +5982,7 @@ bool
 Arm_relobj<big_endian>::section_needs_reloc_stub_scanning(
     const elfcpp::Shdr<32, big_endian>& shdr,
     const Relobj::Output_sections& out_sections,
-    const Symbol_table *symtab,
+    const Symbol_tablesymtab,
     const unsigned char* pshdrs)
 {
   unsigned int sh_type = shdr.get_sh_type();
@@ -6327,11 +6356,12 @@ Arm_relobj<big_endian>::do_relocate_sections(
     const Symbol_table* symtab,
     const Layout* layout,
     const unsigned char* pshdrs,
+    Output_file* of,
     typename Sized_relobj<32, big_endian>::Views* pviews)
 {
   // Call parent to relocate sections.
   Sized_relobj<32, big_endian>::do_relocate_sections(symtab, layout, pshdrs,
-                                                    pviews); 
+                                                    of, pviews); 
 
   // We do not generate stubs if doing a relocatable link.
   if (parameters->options().relocatable())
@@ -6590,7 +6620,7 @@ Arm_relobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
   std::vector<unsigned int> deferred_exidx_sections;
   const size_t shdr_size = elfcpp::Elf_sizes<32>::shdr_size;
   const unsigned char* pshdrs = sd->section_headers->data();
-  const unsigned char *ps = pshdrs + shdr_size;
+  const unsigned charps = pshdrs + shdr_size;
   bool must_merge_flags_and_attributes = false;
   for (unsigned int i = 1; i < this->shnum(); ++i, ps += shdr_size)
     {
@@ -6866,7 +6896,7 @@ Arm_dynobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
   // We read from the end because gas seems to put it near the end of
   // the section headers.
   const size_t shdr_size = elfcpp::Elf_sizes<32>::shdr_size;
-  const unsigned char *ps =
+  const unsigned charps =
     sd->section_headers->data() + shdr_size * (this->shnum() - 1);
   for (unsigned int i = this->shnum(); i > 0; --i, ps -= shdr_size)
     {
@@ -7111,6 +7141,21 @@ class Output_data_plt_arm : public Output_section_data
   rel_plt() const
   { return this->rel_; }
 
+  // Return the number of PLT entries.
+  unsigned int
+  entry_count() const
+  { return this->count_; }
+
+  // Return the offset of the first non-reserved PLT entry.
+  static unsigned int
+  first_plt_entry_offset()
+  { return sizeof(first_plt_entry); }
+
+  // Return the size of a PLT entry.
+  static unsigned int
+  get_plt_entry_size()
+  { return sizeof(plt_entry); }
+
  protected:
   void
   do_adjust_output_section(Output_section* os);
@@ -7158,8 +7203,8 @@ Output_data_plt_arm<big_endian>::Output_data_plt_arm(Layout* layout,
 {
   this->rel_ = new Reloc_section(false);
   layout->add_output_section_data(".rel.plt", elfcpp::SHT_REL,
-                                 elfcpp::SHF_ALLOC, this->rel_, true, false,
-                                 false, false);
+                                 elfcpp::SHF_ALLOC, this->rel_,
+                                 ORDER_DYNAMIC_PLT_RELOCS, false);
 }
 
 template<bool big_endian>
@@ -7321,11 +7366,40 @@ Target_arm<big_endian>::make_plt_entry(Symbol_table* symtab, Layout* layout,
       layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
                                      (elfcpp::SHF_ALLOC
                                       | elfcpp::SHF_EXECINSTR),
-                                     this->plt_, false, false, false, false);
+                                     this->plt_, ORDER_PLT, false);
     }
   this->plt_->add_entry(gsym);
 }
 
+// Return the number of entries in the PLT.
+
+template<bool big_endian>
+unsigned int
+Target_arm<big_endian>::plt_entry_count() const
+{
+  if (this->plt_ == NULL)
+    return 0;
+  return this->plt_->entry_count();
+}
+
+// Return the offset of the first non-reserved PLT entry.
+
+template<bool big_endian>
+unsigned int
+Target_arm<big_endian>::first_plt_entry_offset() const
+{
+  return Output_data_plt_arm<big_endian>::first_plt_entry_offset();
+}
+
+// Return the size of each PLT entry.
+
+template<bool big_endian>
+unsigned int
+Target_arm<big_endian>::plt_entry_size() const
+{
+  return Output_data_plt_arm<big_endian>::get_plt_entry_size();
+}
+
 // Get the section to use for TLS_DESC relocations.
 
 template<bool big_endian>
@@ -8213,7 +8287,8 @@ Target_arm<big_endian>::gc_process_relocs(Symbol_table* symtab,
   typedef Target_arm<big_endian> Arm;
   typedef typename Target_arm<big_endian>::Scan Scan;
 
-  gold::gc_process_relocs<32, big_endian, Arm, elfcpp::SHT_REL, Scan>(
+  gold::gc_process_relocs<32, big_endian, Arm, elfcpp::SHT_REL, Scan,
+                         typename Target_arm::Relocatable_size_for_reloc>(
     symtab,
     layout,
     this,
@@ -8357,33 +8432,50 @@ Target_arm<big_endian>::do_finalize_sections(
 
   // Handle the .ARM.exidx section.
   Output_section* exidx_section = layout->find_output_section(".ARM.exidx");
-  if (exidx_section != NULL
-      && exidx_section->type() == elfcpp::SHT_ARM_EXIDX
-      && !parameters->options().relocatable())
-    {
-      // Create __exidx_start and __exdix_end symbols.
-      symtab->define_in_output_data("__exidx_start", NULL,
-                                   Symbol_table::PREDEFINED,
-                                   exidx_section, 0, 0, elfcpp::STT_OBJECT,
-                                   elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN, 0,
-                                   false, true);
-      symtab->define_in_output_data("__exidx_end", NULL,
-                                   Symbol_table::PREDEFINED,
-                                   exidx_section, 0, 0, elfcpp::STT_OBJECT,
-                                   elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN, 0,
-                                   true, true);
 
-      // For the ARM target, we need to add a PT_ARM_EXIDX segment for
-      // the .ARM.exidx section.
-      if (!layout->script_options()->saw_phdrs_clause())
-       {
-         gold_assert(layout->find_output_segment(elfcpp::PT_ARM_EXIDX, 0, 0)
-                     == NULL);
-         Output_segment*  exidx_segment =
-           layout->make_output_segment(elfcpp::PT_ARM_EXIDX, elfcpp::PF_R);
-         exidx_segment->add_output_section(exidx_section, elfcpp::PF_R,
-                                           false);
-       }
+  if (!parameters->options().relocatable())
+    {
+      if (exidx_section != NULL
+          && exidx_section->type() == elfcpp::SHT_ARM_EXIDX)
+        {
+          // Create __exidx_start and __exdix_end symbols.
+          symtab->define_in_output_data("__exidx_start", NULL,
+                                        Symbol_table::PREDEFINED,
+                                        exidx_section, 0, 0, elfcpp::STT_OBJECT,
+                                        elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN,
+                                        0, false, true);
+          symtab->define_in_output_data("__exidx_end", NULL,
+                                        Symbol_table::PREDEFINED,
+                                        exidx_section, 0, 0, elfcpp::STT_OBJECT,
+                                        elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN,
+                                        0, true, true);
+
+          // For the ARM target, we need to add a PT_ARM_EXIDX segment for
+          // the .ARM.exidx section.
+          if (!layout->script_options()->saw_phdrs_clause())
+            {
+              gold_assert(layout->find_output_segment(elfcpp::PT_ARM_EXIDX, 0,
+                                                      0)
+                          == NULL);
+              Output_segment*  exidx_segment =
+                layout->make_output_segment(elfcpp::PT_ARM_EXIDX, elfcpp::PF_R);
+              exidx_segment->add_output_section_to_nonload(exidx_section,
+                                                           elfcpp::PF_R);
+            }
+        }
+      else
+        {
+          symtab->define_as_constant("__exidx_start", NULL,
+                                     Symbol_table::PREDEFINED,
+                                     0, 0, elfcpp::STT_OBJECT,
+                                     elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN, 0,
+                                     true, false);
+          symtab->define_as_constant("__exidx_end", NULL,
+                                     Symbol_table::PREDEFINED,
+                                     0, 0, elfcpp::STT_OBJECT,
+                                     elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN, 0,
+                                     true, false);
+        }
     }
 
   // Create an .ARM.attributes section if we have merged any attributes
@@ -8394,7 +8486,7 @@ Target_arm<big_endian>::do_finalize_sections(
       new Output_attributes_section_data(*this->attributes_section_data_);
       layout->add_output_section_data(".ARM.attributes",
                                      elfcpp::SHT_ARM_ATTRIBUTES, 0,
-                                     attributes_section, false, false, false,
+                                     attributes_section, ORDER_INVALID,
                                      false);
     }
 
@@ -8457,7 +8549,7 @@ inline bool
 Target_arm<big_endian>::Relocate::relocate(
     const Relocate_info<32, big_endian>* relinfo,
     Target_arm* target,
-    Output_section *output_section,
+    Output_sectionoutput_section,
     size_t relnum,
     const elfcpp::Rel<32, big_endian>& rel,
     unsigned int r_type,
@@ -9561,7 +9653,7 @@ Target_arm<big_endian>::do_dynsym_value(const Symbol* gsym) const
 //
 template<bool big_endian>
 unsigned int
-Target_arm<big_endian>::get_real_reloc_type (unsigned int r_type)
+Target_arm<big_endian>::get_real_reloc_type(unsigned int r_type)
 {
   switch (r_type)
     {
@@ -9713,7 +9805,7 @@ int
 Target_arm<big_endian>::get_secondary_compatible_arch(
     const Attributes_section_data* pasd)
 {
-  const Object_attribute *known_attributes =
+  const Object_attributeknown_attributes =
     pasd->known_attributes(Object_attribute::OBJ_ATTR_PROC);
 
   // Note: the tag and its argument below are uleb128 values, though
@@ -9739,7 +9831,7 @@ Target_arm<big_endian>::set_secondary_compatible_arch(
     Attributes_section_data* pasd,
     int arch)
 {
-  Object_attribute *known_attributes =
+  Object_attributeknown_attributes =
     pasd->known_attributes(Object_attribute::OBJ_ATTR_PROC);
 
   if (arch == -1)
@@ -9878,7 +9970,7 @@ Target_arm<big_endian>::tag_cpu_arch_combine(
       T(V7E_M),                // V7E_M.
       T(V4T_PLUS_V6_M) // V4T plus V6_M.
     };
-  static const int *comb[] =
+  static const intcomb[] =
     {
       v6t2,
       v6k,
@@ -9946,7 +10038,7 @@ template<bool big_endian>
 std::string
 Target_arm<big_endian>::aeabi_enum_name(unsigned int value)
 {
-  static const char *aeabi_enum_names[] =
+  static const charaeabi_enum_names[] =
     { "", "variable-size", "32-bit", "" };
   const size_t aeabi_enum_names_size =
     sizeof(aeabi_enum_names) / sizeof(aeabi_enum_names[0]);
@@ -9967,7 +10059,7 @@ template<bool big_endian>
 std::string
 Target_arm<big_endian>::tag_cpu_name_value(unsigned int value)
 {
-  static const char *name_table[] = {
+  static const charname_table[] = {
     // These aren't real CPU names, but we can't guess
     // that from the architecture version alone.
    "Pre v4",
@@ -10289,11 +10381,11 @@ Target_arm<big_endian>::merge_object_attributes(
            out_attr[i].set_int_value(in_attr[i].int_value());
          break;
        case elfcpp::Tag_ABI_PCS_wchar_t:
-         // FIXME: Make it possible to turn off this warning.
          if (out_attr[i].int_value()
              && in_attr[i].int_value()
              && out_attr[i].int_value() != in_attr[i].int_value()
-             && parameters->options().warn_mismatch())
+             && parameters->options().warn_mismatch()
+             && parameters->options().wchar_size_warning())
            {
              gold_warning(_("%s uses %u-byte wchar_t yet the output is to "
                             "use %u-byte wchar_t; use of wchar_t values "
@@ -10314,10 +10406,10 @@ Target_arm<big_endian>::merge_object_attributes(
                  // Use whatever requirements the new object has.
                  out_attr[i].set_int_value(in_attr[i].int_value());
                }
-             // FIXME: Make it possible to turn off this warning.
              else if (in_attr[i].int_value() != elfcpp::AEABI_enum_forced_wide
                       && out_attr[i].int_value() != in_attr[i].int_value()
-                      && parameters->options().warn_mismatch())
+                      && parameters->options().warn_mismatch()
+                      && parameters->options().enum_size_warning())
                {
                  unsigned int in_value = in_attr[i].int_value();
                  unsigned int out_value = out_attr[i].int_value();
@@ -10858,6 +10950,8 @@ Target_arm<big_endian>::scan_reloc_section_for_stubs(
 
       Symbol_value<32> symval;
       const Symbol_value<32> *psymval;
+      bool is_defined_in_discarded_section;
+      unsigned int shndx;
       if (r_sym < local_count)
        {
          sym = NULL;
@@ -10869,45 +10963,53 @@ Target_arm<big_endian>::scan_reloc_section_for_stubs(
           // counterpart in the kept section.  The symbol must not 
           // correspond to a section we are folding.
          bool is_ordinary;
-         unsigned int shndx = psymval->input_shndx(&is_ordinary);
-         if (is_ordinary
-             && shndx != elfcpp::SHN_UNDEF
-             && !arm_object->is_section_included(shndx) 
-              && !(relinfo->symtab->is_section_folded(arm_object, shndx)))
+         shndx = psymval->input_shndx(&is_ordinary);
+         is_defined_in_discarded_section =
+           (is_ordinary
+            && shndx != elfcpp::SHN_UNDEF
+            && !arm_object->is_section_included(shndx)
+            && !relinfo->symtab->is_section_folded(arm_object, shndx));
+
+         // We need to compute the would-be final value of this local
+         // symbol.
+         if (!is_defined_in_discarded_section)
            {
-             if (comdat_behavior == CB_UNDETERMINED)
-               {
-                 std::string name =
-                   arm_object->section_name(relinfo->data_shndx);
-                 comdat_behavior = get_comdat_behavior(name.c_str());
-               }
-             if (comdat_behavior == CB_PRETEND)
-               {
-                  bool found;
-                 typename elfcpp::Elf_types<32>::Elf_Addr value =
-                   arm_object->map_to_kept_section(shndx, &found);
-                 if (found)
-                   symval.set_output_value(value + psymval->input_value());
-                  else
-                    symval.set_output_value(0);
-               }
+             typedef Sized_relobj<32, big_endian> ObjType;
+             typename ObjType::Compute_final_local_value_status status =
+               arm_object->compute_final_local_value(r_sym, psymval, &symval,
+                                                     relinfo->symtab); 
+             if (status == ObjType::CFLV_OK)
+               {
+                 // Currently we cannot handle a branch to a target in
+                 // a merged section.  If this is the case, issue an error
+                 // and also free the merge symbol value.
+                 if (!symval.has_output_value())
+                   {
+                     const std::string& section_name =
+                       arm_object->section_name(shndx);
+                     arm_object->error(_("cannot handle branch to local %u "
+                                         "in a merged section %s"),
+                                       r_sym, section_name.c_str());
+                   }
+                 psymval = &symval;
+               }
              else
-               {
-                  symval.set_output_value(0);
-               }
-             symval.set_no_output_symtab_entry();
-             psymval = &symval;
+               {
+                 // We cannot determine the final value.
+                 continue;  
+               }
            }
        }
       else
        {
-         const Symbol* gsym = arm_object->global_symbol(r_sym);
+         const Symbol* gsym;
+         gsym = arm_object->global_symbol(r_sym);
          gold_assert(gsym != NULL);
          if (gsym->is_forwarder())
            gsym = relinfo->symtab->resolve_forwards(gsym);
 
          sym = static_cast<const Sized_symbol<32>*>(gsym);
-         if (sym->has_symtab_index())
+         if (sym->has_symtab_index() && sym->symtab_index() != -1U)
            symval.set_output_symtab_index(sym->symtab_index());
          else
            symval.set_no_output_symtab_entry();
@@ -10924,9 +11026,53 @@ Target_arm<big_endian>::scan_reloc_section_for_stubs(
          // Skip this if the symbol has not output section.
          if (status == Symbol_table::CFVS_NO_OUTPUT_SECTION)
            continue;
-
          symval.set_output_value(value);
+
+         if (gsym->type() == elfcpp::STT_TLS)
+           symval.set_is_tls_symbol();
+         else if (gsym->type() == elfcpp::STT_GNU_IFUNC)
+           symval.set_is_ifunc_symbol();
          psymval = &symval;
+
+         is_defined_in_discarded_section =
+           (gsym->is_defined_in_discarded_section()
+            && gsym->is_undefined());
+         shndx = 0;
+       }
+
+      Symbol_value<32> symval2;
+      if (is_defined_in_discarded_section)
+       {
+         if (comdat_behavior == CB_UNDETERMINED)
+           {
+             std::string name = arm_object->section_name(relinfo->data_shndx);
+             comdat_behavior = get_comdat_behavior(name.c_str());
+           }
+         if (comdat_behavior == CB_PRETEND)
+           {
+             // FIXME: This case does not work for global symbols.
+             // We have no place to store the original section index.
+             // Fortunately this does not matter for comdat sections,
+             // only for sections explicitly discarded by a linker
+             // script.
+             bool found;
+             typename elfcpp::Elf_types<32>::Elf_Addr value =
+               arm_object->map_to_kept_section(shndx, &found);
+             if (found)
+               symval2.set_output_value(value + psymval->input_value());
+             else
+               symval2.set_output_value(0);
+           }
+         else
+           {
+             if (comdat_behavior == CB_WARNING)
+               gold_warning_at_location(relinfo, i, offset,
+                                        _("relocation refers to discarded "
+                                          "section"));
+             symval2.set_output_value(0);
+           }
+         symval2.set_no_output_symtab_entry();
+         psymval = &symval2;
        }
 
       // If symbol is a section symbol, we don't know the actual type of
@@ -11575,7 +11721,7 @@ Target_arm<big_endian>::fix_exidx_coverage(
          if (!exidx_input_section->has_errors())
            {
              unsigned int text_shndx = exidx_input_section->link();
-             Output_section *os = arm_relobj->output_section(text_shndx);
+             Output_sectionos = arm_relobj->output_section(text_shndx);
              if (os != NULL && (os->flags() & elfcpp::SHF_ALLOC) != 0)
                sorted_output_sections.insert(os);
            }