libiberty: documentation markup and order fixes.
[binutils-gdb.git] / gold / arm.cc
index c304d2acfc92bb6448f92120c44ee5f00d2ce491..6c81d3071b94b93982cf3a0afbcb744fc4a98cf0 100644 (file)
@@ -116,7 +116,7 @@ const size_t ARM_TCB_SIZE = 8;
 
 // Ideally we would like to avoid using global variables but this is used
 // very in many places and sometimes in loops.  If we use a function
-// returning a static instance of Arm_reloc_property_table, it will very
+// returning a static instance of Arm_reloc_property_table, it will be very
 // slow in an threaded environment since the static instance needs to be
 // locked.  The pointer is below initialized in the
 // Target::do_select_as_default_target() hook so that we do not spend time
@@ -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.
@@ -598,10 +598,10 @@ class Reloc_stub : public Stub
     // If this is a local symbol, this is the index in the defining object.
     // Otherwise, it is invalid_index for a global symbol.
     unsigned int r_sym_;
-    // If r_sym_ is invalid index.  This points to a global symbol.
-    // Otherwise, this points a relobj.  We used the unsized and target
+    // If r_sym_ is an invalid index, this points to a global symbol.
+    // Otherwise, it points to a relobj.  We used the unsized and target
     // independent Symbol and Relobj classes instead of Sized_symbol<32> and  
-    // Arm_relobj.  This is done to avoid making the stub class a template
+    // Arm_relobj, in order to avoid making the stub class a template
     // as most of the stub machinery is endianness-neutral.  However, it
     // may require a bit of casting done by users of this class.
     union
@@ -895,8 +895,8 @@ class Stub_table : public Output_data
   current_data_size() const
   { return this->current_data_size_for_child(); }
 
-  // Add a STUB with using KEY.  Caller is reponsible for avoid adding
-  // if already a STUB with the same key has been added. 
+  // Add a STUB using KEY.  The caller is responsible for avoiding addition
+  // if a STUB with the same key has already been added.
   void
   add_reloc_stub(Reloc_stub* stub, const Reloc_stub::Key& key)
   {
@@ -915,8 +915,8 @@ class Stub_table : public Output_data
   }
 
   // Add a Cortex-A8 STUB that fixes up a THUMB branch at ADDRESS.
-  // Caller is reponsible for avoid adding if already a STUB with the same
-  // address has been added. 
+  // The caller is responsible for avoiding addition if a STUB with the same
+  // address has already been added.
   void
   add_cortex_a8_stub(Arm_address address, Cortex_a8_stub* stub)
   {
@@ -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>
@@ -1099,6 +1104,10 @@ class Arm_exidx_merged_section : public Output_relaxed_input_section
       const Arm_exidx_section_offset_map& section_offset_map,
       uint32_t deleted_bytes);
 
+  // Build output contents.
+  void
+  build_contents(const unsigned char*, section_size_type);
+
   // Return the original EXIDX input section.
   const Arm_exidx_input_section&
   exidx_input_section() const
@@ -1123,6 +1132,10 @@ class Arm_exidx_merged_section : public Output_relaxed_input_section
   const Arm_exidx_input_section& exidx_input_section_;
   // Section offset map.
   const Arm_exidx_section_offset_map& section_offset_map_;
+  // Merged section contents.  We need to keep build the merged section 
+  // and save it here to avoid accessing the original EXIDX section when
+  // we cannot lock the sections' object.
+  unsigned char* section_contents_;
 };
 
 // A class to wrap an ordinary input section containing executable code.
@@ -1133,11 +1146,12 @@ class Arm_input_section : public Output_relaxed_input_section
  public:
   Arm_input_section(Relobj* relobj, unsigned int shndx)
     : Output_relaxed_input_section(relobj, shndx, 1),
-      original_addralign_(1), original_size_(0), stub_table_(NULL)
+      original_addralign_(1), original_size_(0), stub_table_(NULL),
+      original_contents_(NULL)
   { }
 
   ~Arm_input_section()
-  { }
+  { delete[] this->original_contents_; }
 
   // Initialize.
   void
@@ -1164,6 +1178,11 @@ class Arm_input_section : public Output_relaxed_input_section
   as_arm_input_section(Output_relaxed_input_section* poris)
   { return static_cast<Arm_input_section<big_endian>*>(poris); }
 
+  // Return the original size of the section.
+  uint32_t
+  original_size() const
+  { return this->original_size_; }
+
  protected:
   // Write data to output file.
   void
@@ -1175,7 +1194,7 @@ class Arm_input_section : public Output_relaxed_input_section
   {
     if (this->is_stub_table_owner())
       return std::max(this->stub_table_->addralign(),
-                     this->original_addralign_);
+                     static_cast<uint64_t>(this->original_addralign_));
     else
       return this->original_addralign_;
   }
@@ -1197,8 +1216,8 @@ class Arm_input_section : public Output_relaxed_input_section
     if ((object == this->relobj())
        && (shndx == this->shndx())
        && (offset >= 0)
-       && (convert_types<uint64_t, section_offset_type>(offset)
-           <= this->original_size_))
+       && (offset <=
+           convert_types<section_offset_type, uint32_t>(this->original_size_)))
       {
        *poutput = offset;
        return true;
@@ -1213,11 +1232,15 @@ class Arm_input_section : public Output_relaxed_input_section
   Arm_input_section& operator=(const Arm_input_section&);
 
   // Address alignment of the original input section.
-  uint64_t original_addralign_;
+  uint32_t original_addralign_;
   // Section size of the original input section.
-  uint64_t original_size_;
+  uint32_t original_size_;
   // Stub table.
   Stub_table<big_endian>* stub_table_;
+  // Original section contents.  We have to make a copy here since the file
+  // containing the original section may not be locked when we need to access
+  // the contents.
+  unsigned char* original_contents_;
 };
 
 // Arm_exidx_fixup class.  This is used to define a number of methods
@@ -1237,14 +1260,17 @@ class Arm_exidx_fixup
   ~Arm_exidx_fixup()
   { delete this->section_offset_map_; }
 
-  // Process an EXIDX section for entry merging.  Return  number of bytes to
-  // be deleted in output.  If parts of the input EXIDX section are merged
-  // a heap allocated Arm_exidx_section_offset_map is store in the located
-  // PSECTION_OFFSET_MAP.  The caller owns the map and is reponsible for
-  // releasing it.
+  // Process an EXIDX section for entry merging.  SECTION_CONTENTS points
+  // to the EXIDX contents and SECTION_SIZE is the size of the contents. Return
+  // number of bytes to be deleted in output.  If parts of the input EXIDX
+  // section are merged a heap allocated Arm_exidx_section_offset_map is store
+  // in the located PSECTION_OFFSET_MAP.   The caller owns the map and is
+  // responsible for releasing it.
   template<bool big_endian>
   uint32_t
   process_exidx_section(const Arm_exidx_input_section* exidx_input_section,
+                       const unsigned char* section_contents,
+                       section_size_type section_size,
                        Arm_exidx_section_offset_map** psection_offset_map);
   
   // Append an EXIDX_CANTUNWIND entry pointing at the end of the last
@@ -1319,14 +1345,17 @@ class Arm_output_section : public Output_section
   Arm_output_section(const char* name, elfcpp::Elf_Word type,
                     elfcpp::Elf_Xword flags)
     : Output_section(name, type, flags)
-  { }
+  {
+    if (type == elfcpp::SHT_ARM_EXIDX)
+      this->set_always_keeps_input_sections();
+  }
 
   ~Arm_output_section()
   { }
   
   // Group input sections for stub generation.
   void
-  group_sections(section_size_type, bool, Target_arm<big_endian>*);
+  group_sections(section_size_type, bool, Target_arm<big_endian>*, const Task*);
 
   // Downcast a base pointer to an Arm_output_section pointer.  This is
   // not type-safe but we only use Arm_output_section not the base class.
@@ -1345,7 +1374,12 @@ class Arm_output_section : public Output_section
   fix_exidx_coverage(Layout* layout,
                     const Text_section_list& sorted_text_section,
                     Symbol_table* symtab,
-                    bool merge_exidx_entries);
+                    bool merge_exidx_entries,
+                    const Task* task);
+
+  // Link an EXIDX section into its corresponding text section.
+  void
+  set_exidx_section_link();
 
  private:
   // For convenience.
@@ -1357,7 +1391,8 @@ class Arm_output_section : public Output_section
                         Input_section_list::const_iterator,
                         Input_section_list::const_iterator,
                         Target_arm<big_endian>*,
-                        std::vector<Output_relaxed_input_section*>*);
+                        std::vector<Output_relaxed_input_section*>*,
+                        const Task* task);
 };
 
 // Arm_exidx_input_section class.  This represents an EXIDX input section.
@@ -1369,9 +1404,10 @@ class Arm_exidx_input_section
     static_cast<section_offset_type>(-1);
 
   Arm_exidx_input_section(Relobj* relobj, unsigned int shndx,
-                         unsigned int link, uint32_t size, uint32_t addralign)
+                         unsigned int link, uint32_t size,
+                         uint32_t addralign, uint32_t text_size)
     : relobj_(relobj), shndx_(shndx), link_(link), size_(size),
-      addralign_(addralign)
+      addralign_(addralign), text_size_(text_size), has_errors_(false)
   { }
 
   ~Arm_exidx_input_section()
@@ -1399,11 +1435,26 @@ class Arm_exidx_input_section
   size() const
   { return this->size_; }
 
-  // Reutnr address alignment of EXIDX input section.
+  // Return address alignment of EXIDX input section.
   uint32_t
   addralign() const
   { return this->addralign_; }
 
+  // Return size of the associated text input section.
+  uint32_t
+  text_size() const
+  { return this->text_size_; }
+
+  // Whether there are any errors in the EXIDX input section.
+  bool
+  has_errors() const
+  { return this->has_errors_; }
+
+  // Set has-errors flag.
+  void
+  set_has_errors()
+  { this->has_errors_ = true; }
+
  private:
   // Object containing this.
   Relobj* relobj_;
@@ -1415,6 +1466,10 @@ class Arm_exidx_input_section
   uint32_t size_;
   // Address alignment of this.  For ARM 32-bit is sufficient.
   uint32_t addralign_;
+  // Size of associated text section.
+  uint32_t text_size_;
+  // Whether this has any errors.
+  bool has_errors_;
 };
 
 // Arm_relobj class.
@@ -1576,6 +1631,22 @@ class Arm_relobj : public Sized_relobj<32, big_endian>
   merge_flags_and_attributes() const
   { return this->merge_flags_and_attributes_; }
   
+  // Export list of EXIDX section indices.
+  void
+  get_exidx_shndx_list(std::vector<unsigned int>* list) const
+  {
+    list->clear();
+    for (Exidx_section_map::const_iterator p = this->exidx_section_map_.begin();
+        p != this->exidx_section_map_.end();
+        ++p)
+      {
+       if (p->second->shndx() == p->first)
+         list->push_back(p->first);
+      }
+    // Sort list to make result independent of implementation of map. 
+    std::sort(list->begin(), list->end());
+  }
+
  protected:
   // Post constructor setup.
   void
@@ -1596,7 +1667,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.
@@ -1613,18 +1684,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
@@ -1633,7 +1704,7 @@ class Arm_relobj : public Sized_relobj<32, big_endian>
                                     Target_arm<big_endian>*);
 
   // Find the linked text section of an EXIDX section by looking at the
-  // first reloction of the EXIDX section.  PSHDR points to the section
+  // first relocation of the EXIDX section.  PSHDR points to the section
   // headers of a relocation section and PSYMS points to the local symbols.
   // PSHNDX points to a location storing the text section index if found.
   // Return whether we can find the linked section.
@@ -1648,7 +1719,8 @@ class Arm_relobj : public Sized_relobj<32, big_endian>
   void
   make_exidx_input_section(unsigned int shndx,
                           const elfcpp::Shdr<32, big_endian>& shdr,
-                          unsigned int text_shndx);
+                          unsigned int text_shndx,
+                          const elfcpp::Shdr<32, big_endian>& text_shdr);
 
   // Return the output address of either a plain input section or a
   // relaxed input section.  SHNDX is the section index.
@@ -1951,6 +2023,79 @@ class Arm_output_data_got : public Output_data_got<32, big_endian>
   std::vector<Static_reloc> static_relocs_;
 };
 
+// The ARM target has many relocation types with odd-sizes or noncontiguous
+// bits.  The default handling of relocatable relocation cannot process these
+// relocations.  So we have to extend the default code.
+
+template<bool big_endian, int sh_type, typename Classify_reloc>
+class Arm_scan_relocatable_relocs :
+  public Default_scan_relocatable_relocs<sh_type, Classify_reloc>
+{
+ public:
+  // Return the strategy to use for a local symbol which is a section
+  // symbol, given the relocation type.
+  inline Relocatable_relocs::Reloc_strategy
+  local_section_strategy(unsigned int r_type, Relobj*)
+  {
+    if (sh_type == elfcpp::SHT_RELA)
+      return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA;
+    else
+      {
+       if (r_type == elfcpp::R_ARM_TARGET1
+           || r_type == elfcpp::R_ARM_TARGET2)
+         {
+           const Target_arm<big_endian>* arm_target =
+             Target_arm<big_endian>::default_target();
+           r_type = arm_target->get_real_reloc_type(r_type);
+         }
+
+       switch(r_type)
+         {
+         // Relocations that write nothing.  These exclude R_ARM_TARGET1
+         // and R_ARM_TARGET2.
+         case elfcpp::R_ARM_NONE:
+         case elfcpp::R_ARM_V4BX:
+         case elfcpp::R_ARM_TLS_GOTDESC:
+         case elfcpp::R_ARM_TLS_CALL:
+         case elfcpp::R_ARM_TLS_DESCSEQ:
+         case elfcpp::R_ARM_THM_TLS_CALL:
+         case elfcpp::R_ARM_GOTRELAX:
+         case elfcpp::R_ARM_GNU_VTENTRY:
+         case elfcpp::R_ARM_GNU_VTINHERIT:
+         case elfcpp::R_ARM_THM_TLS_DESCSEQ16:
+         case elfcpp::R_ARM_THM_TLS_DESCSEQ32:
+           return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_0;
+         // These should have been converted to something else above.
+         case elfcpp::R_ARM_TARGET1:
+         case elfcpp::R_ARM_TARGET2:
+           gold_unreachable();
+         // Relocations that write full 32 bits.
+         case elfcpp::R_ARM_ABS32:
+         case elfcpp::R_ARM_REL32:
+         case elfcpp::R_ARM_SBREL32:
+         case elfcpp::R_ARM_GOTOFF32:
+         case elfcpp::R_ARM_BASE_PREL:
+         case elfcpp::R_ARM_GOT_BREL:
+         case elfcpp::R_ARM_BASE_ABS:
+         case elfcpp::R_ARM_ABS32_NOI:
+         case elfcpp::R_ARM_REL32_NOI:
+         case elfcpp::R_ARM_PLT32_ABS:
+         case elfcpp::R_ARM_GOT_ABS:
+         case elfcpp::R_ARM_GOT_PREL:
+         case elfcpp::R_ARM_TLS_GD32:
+         case elfcpp::R_ARM_TLS_LDM32:
+         case elfcpp::R_ARM_TLS_LDO32:
+         case elfcpp::R_ARM_TLS_IE32:
+         case elfcpp::R_ARM_TLS_LE32:
+           return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_4;
+         default:
+           // For all other static relocations, return RELOC_SPECIAL.
+           return Relocatable_relocs::RELOC_SPECIAL;
+         }
+      }
+  }
+};
+
 // Utilities for manipulating integers of up to 32-bits
 
 namespace utils
@@ -2031,6 +2176,23 @@ class Target_arm : public Sized_target<32, big_endian>
       fix_cortex_a8_(false), cortex_a8_relocs_info_()
   { }
 
+  // Virtual function which is set to return true by a target if
+  // it can use relocation types to determine if a function's
+  // pointer is taken.
+  virtual bool
+  can_check_for_function_pointers() const
+  { return true; }
+
+  // Whether a section called SECTION_NAME may have function pointers to
+  // sections not eligible for safe ICF folding.
+  virtual bool
+  section_may_have_icf_unsafe_pointers(const char* section_name) const
+  {
+    return (!is_prefix_of(".ARM.exidx", section_name)
+           && !is_prefix_of(".ARM.extab", section_name)
+           && Target::section_may_have_icf_unsafe_pointers(section_name));
+  }
+  
   // Whether we can use BLX.
   bool
   may_use_blx() const
@@ -2184,6 +2346,21 @@ class Target_arm : public Sized_target<32, big_endian>
                           unsigned char* reloc_view,
                           section_size_type reloc_view_size);
 
+  // Perform target-specific processing in a relocatable link.  This is
+  // only used if we use the relocation strategy RELOC_SPECIAL.
+  void
+  relocate_special_relocatable(const Relocate_info<32, big_endian>* relinfo,
+                              unsigned int sh_type,
+                              const unsigned char* preloc_in,
+                              size_t relnum,
+                              Output_section* output_section,
+                              off_t offset_in_output_section,
+                              unsigned char* view,
+                              typename elfcpp::Elf_types<32>::Elf_Addr
+                                view_address,
+                              section_size_type view_size,
+                              unsigned char* preloc_out);
   // Return whether SYM is defined by the ABI.
   bool
   do_is_defined_by_abi(Symbol* sym) const
@@ -2196,15 +2373,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.
@@ -2327,7 +2525,7 @@ class Target_arm : public Sized_target<32, big_endian>
   { return !parameters->options().relocatable(); }
 
   bool
-  do_relax(int, const Input_objects*, Symbol_table*, Layout*);
+  do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*);
 
   // Determine whether an object attribute tag takes an integer, a
   // string or both.
@@ -2358,6 +2556,9 @@ class Target_arm : public Sized_target<32, big_endian>
       : issued_non_pic_error_(false)
     { }
 
+    static inline int
+    get_reference_flags(unsigned int r_type);
+
     inline void
     local(Symbol_table* symtab, Layout* layout, Target_arm* target,
          Sized_relobj<32, big_endian>* object,
@@ -2381,8 +2582,7 @@ class Target_arm : public Sized_target<32, big_endian>
                                        Output_section* ,
                                        const elfcpp::Rel<32, big_endian>& ,
                                        unsigned int ,
-                                       const elfcpp::Sym<32, big_endian>&)
-    { return false; }
+                                       const elfcpp::Sym<32, big_endian>&);
 
     inline bool
     global_reloc_may_be_function_pointer(Symbol_table* , Layout* , Target_arm* ,
@@ -2390,8 +2590,7 @@ class Target_arm : public Sized_target<32, big_endian>
                                         unsigned int ,
                                         Output_section* ,
                                         const elfcpp::Rel<32, big_endian>& ,
-                                        unsigned int , Symbol*)
-    { return false; }
+                                        unsigned int , Symbol*);
 
    private:
     static void
@@ -2422,6 +2621,9 @@ class Target_arm : public Sized_target<32, big_endian>
                  || sym->is_preemptible()));
     }
 
+    inline bool
+    possible_function_pointer_reloc(unsigned int r_type);
+
     // Whether we have issued an error about a non-PIC compilation.
     bool issued_non_pic_error_;
   };
@@ -2439,7 +2641,7 @@ class Target_arm : public Sized_target<32, big_endian>
     // Return whether the static relocation needs to be applied.
     inline bool
     should_apply_static_reloc(const Sized_symbol<32>* gsym,
-                             int ref_flags,
+                             unsigned int r_type,
                              bool is_32bit,
                              Output_section* output_section);
 
@@ -2458,7 +2660,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)
        {
@@ -2629,7 +2831,7 @@ class Target_arm : public Sized_target<32, big_endian>
 
   // Group input sections for stub generation.
   void
-  group_sections(Layout*, section_size_type, bool);
+  group_sections(Layout*, section_size_type, bool, const Task*);
 
   // Scan a relocation for stub generation.
   void
@@ -2653,7 +2855,9 @@ class Target_arm : public Sized_target<32, big_endian>
 
   // Fix .ARM.exidx section coverage.
   void
-  fix_exidx_coverage(Layout*, Arm_output_section<big_endian>*, Symbol_table*);
+  fix_exidx_coverage(Layout*, const Input_objects*,
+                    Arm_output_section<big_endian>*, Symbol_table*,
+                    const Task*);
 
   // Functors for STL set.
   struct output_section_address_less_than
@@ -2668,6 +2872,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
@@ -2756,7 +2963,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
   typedef enum
   {
     STATUS_OKAY,       // No error during relocation.
-    STATUS_OVERFLOW,   // Relocation oveflow.
+    STATUS_OVERFLOW,   // Relocation overflow.
     STATUS_BAD_RELOC   // Relocation cannot be applied.
   } Status;
 
@@ -2901,14 +3108,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);
 
@@ -2982,7 +3189,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
 
   // Insert OFFSET to a 32-bit THUMB conditional branch and return the lower
   // instruction.  LOWER_INSN is the original lower instruction of the branch.
-  // Caller is reponsible for overflow checking.
+  // The caller is responsible for overflow checking.
   static inline uint16_t
   thumb32_cond_branch_lower(uint16_t lower_insn, int32_t offset)
   {
@@ -2996,7 +3203,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)
   {
@@ -3018,7 +3225,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)
   {
@@ -3040,7 +3247,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)
   {
@@ -3059,7 +3266,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)
   {
@@ -3078,7 +3285,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)
@@ -3093,7 +3300,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,
@@ -3109,13 +3316,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)
@@ -3137,7 +3344,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)
@@ -3156,7 +3363,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)
@@ -3203,7 +3410,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)
   {
@@ -3213,7 +3420,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,
@@ -3280,7 +3487,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,
@@ -3437,7 +3644,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)
@@ -3664,7 +3871,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,
@@ -3720,6 +3927,7 @@ Arm_relocate_functions<big_endian>::arm_branch_common(
     Target_arm<big_endian>::default_target();
   if (is_weakly_undefined_without_plt)
     {
+      gold_assert(!parameters->options().relocatable());
       Valtype cond = val & 0xf0000000U;
       if (arm_target->may_use_arm_nop())
        val = cond | 0x0320f000;
@@ -3737,8 +3945,11 @@ Arm_relocate_functions<big_endian>::arm_branch_common(
   // to switch mode.
   bool may_use_blx = arm_target->may_use_blx();
   Reloc_stub* stub = NULL;
-  if (utils::has_overflow<26>(branch_offset)
-      || ((thumb_bit != 0) && !(may_use_blx && r_type == elfcpp::R_ARM_CALL)))
+
+  if (!parameters->options().relocatable()
+      && (utils::has_overflow<26>(branch_offset)
+         || ((thumb_bit != 0)
+             && !(may_use_blx && r_type == elfcpp::R_ARM_CALL))))
     {
       Valtype unadjusted_branch_target = psymval->value(object, 0);
 
@@ -3788,7 +3999,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,
@@ -3845,6 +4056,7 @@ Arm_relocate_functions<big_endian>::thumb_branch_common(
     Target_arm<big_endian>::default_target();
   if (is_weakly_undefined_without_plt)
     {
+      gold_assert(!parameters->options().relocatable());
       if (arm_target->may_use_thumb2_nop())
        {
          elfcpp::Swap<16, big_endian>::writeval(wv, 0xf3af);
@@ -3871,11 +4083,12 @@ Arm_relocate_functions<big_endian>::thumb_branch_common(
   // We need a stub if the branch offset is too large or if we need
   // to switch mode.
   bool thumb2 = arm_target->using_thumb2();
-  if ((!thumb2 && utils::has_overflow<23>(branch_offset))
-      || (thumb2 && utils::has_overflow<25>(branch_offset))
-      || ((thumb_bit == 0)
-          && (((r_type == elfcpp::R_ARM_THM_CALL) && !may_use_blx)
-             || r_type == elfcpp::R_ARM_THM_JUMP24)))
+  if (!parameters->options().relocatable()
+      && ((!thumb2 && utils::has_overflow<23>(branch_offset))
+         || (thumb2 && utils::has_overflow<25>(branch_offset))
+         || ((thumb_bit == 0)
+             && (((r_type == elfcpp::R_ARM_THM_CALL) && !may_use_blx)
+                 || r_type == elfcpp::R_ARM_THM_JUMP24))))
     {
       Arm_address unadjusted_branch_target = psymval->value(object, 0);
 
@@ -3950,7 +4163,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,
@@ -3999,22 +4212,18 @@ Target_arm<big_endian>::got_section(Symbol_table* symtab, Layout* layout)
 
       this->got_ = new Arm_output_data_got<big_endian>(symtab, layout);
 
-      Output_section* os;
-      os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
-                                          (elfcpp::SHF_ALLOC
-                                           | elfcpp::SHF_WRITE),
-                                          this->got_, false, false, false,
-                                          true);
+      layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
+                                     (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE),
+                                     this->got_, ORDER_DATA, false);
+
       // 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
       // might be empty.
       this->got_plt_ = new Output_data_space(4, "** GOT PLT");
-      os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
-                                          (elfcpp::SHF_ALLOC
-                                           | elfcpp::SHF_WRITE),
-                                          this->got_plt_, false, false,
-                                          false, false);
+      layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
+                                     (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE),
+                                     this->got_plt_, ORDER_DATA, false);
 
       // The first three entries are reserved.
       this->got_plt_->set_current_data_size(3 * 4);
@@ -4042,8 +4251,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_;
 }
@@ -4226,7 +4435,7 @@ Reloc_stub::Key::name() const
 // Determine the type of stub needed, if any, for a relocation of R_TYPE at
 // LOCATION to DESTINATION.
 // This code is based on the arm_type_of_stub function in
-// bfd/elf32-arm.c.  We have changed the interface a liitle to keep the Stub
+// bfd/elf32-arm.c.  We have changed the interface a little to keep the Stub
 // class simple.
 
 Stub_type
@@ -4630,7 +4839,7 @@ Stub_factory::Stub_factory()
 
 // Stub_table methods.
 
-// Removel all Cortex-A8 stub.
+// Remove all Cortex-A8 stub.
 
 template<bool big_endian>
 void
@@ -4907,10 +5116,22 @@ Arm_input_section<big_endian>::init()
   Relobj* relobj = this->relobj();
   unsigned int shndx = this->shndx();
 
-  // Cache these to speed up size and alignment queries.  It is too slow
-  // to call section_addraglin and section_size every time.
-  this->original_addralign_ = relobj->section_addralign(shndx);
-  this->original_size_ = relobj->section_size(shndx);
+  // We have to cache original size, alignment and contents to avoid locking
+  // the original file.
+  this->original_addralign_ =
+    convert_types<uint32_t, uint64_t>(relobj->section_addralign(shndx));
+
+  // This is not efficient but we expect only a small number of relaxed
+  // input sections for stubs.
+  section_size_type section_size;
+  const unsigned char* section_contents =
+    relobj->section_contents(shndx, &section_size, false);
+  this->original_size_ =
+    convert_types<uint32_t, uint64_t>(relobj->section_size(shndx));
+
+  gold_assert(this->original_contents_ == NULL);
+  this->original_contents_ = new unsigned char[section_size];
+  memcpy(this->original_contents_, section_contents, section_size);
 
   // We want to make this look like the original input section after
   // output sections are finalized.
@@ -4929,10 +5150,9 @@ void
 Arm_input_section<big_endian>::do_write(Output_file* of)
 {
   // We have to write out the original section content.
-  section_size_type section_size;
-  const unsigned char* section_contents =
-    this->relobj()->section_contents(this->shndx(), &section_size, false); 
-  of->write(this->offset(), section_contents, section_size); 
+  gold_assert(this->original_contents_ != NULL);
+  of->write(this->offset(), this->original_contents_,
+           this->original_size_); 
 
   // If this owns a stub table and it is not empty, write it.
   if (this->is_stub_table_owner() && !this->stub_table_->empty())
@@ -4949,10 +5169,8 @@ Arm_input_section<big_endian>::set_final_data_size()
 
   if (this->is_stub_table_owner())
     {
-      // The stub table comes after the original section contents.
+      this->stub_table_->finalize_data_size();
       off = align_address(off, this->stub_table_->addralign());
-      this->stub_table_->set_address_and_file_offset(this->address() + off,
-                                                    this->offset() + off);
       off += this->stub_table_->data_size();
     }
   this->set_data_size(off);
@@ -5005,8 +5223,18 @@ Arm_exidx_cantunwind::do_fixed_endian_write(Output_file* of)
   Arm_address output_offset =
     arm_relobj->get_output_section_offset(this->shndx_);
   Arm_address section_start;
+  section_size_type section_size;
+
+  // Find out the end of the text section referred by this.
   if (output_offset != Arm_relobj<big_endian>::invalid_address)
-    section_start = os->address() + output_offset;
+    {
+      section_start = os->address() + output_offset;
+      const Arm_exidx_input_section* exidx_input_section =
+        arm_relobj->exidx_input_section_by_link(this->shndx_);
+      gold_assert(exidx_input_section != NULL);
+      section_size =
+       convert_to_section_size_type(exidx_input_section->text_size());
+    }
   else
     {
       // Currently this only happens for a relaxed section.
@@ -5014,11 +5242,11 @@ Arm_exidx_cantunwind::do_fixed_endian_write(Output_file* of)
        os->find_relaxed_input_section(this->relobj_, this->shndx_);
       gold_assert(poris != NULL);
       section_start = poris->address();
+      section_size = convert_to_section_size_type(poris->data_size());
     }
 
   // We always append this to the end of an EXIDX section.
-  Arm_address output_address =
-    section_start + this->relobj_->section_size(this->shndx_);
+  Arm_address output_address = section_start + section_size;
 
   // Write out the entry.  The first word either points to the beginning
   // or after the end of a text section.  The second word is the special
@@ -5050,9 +5278,59 @@ Arm_exidx_merged_section::Arm_exidx_merged_section(
     exidx_input_section_(exidx_input_section),
     section_offset_map_(section_offset_map)
 {
+  // If we retain or discard the whole EXIDX input section,  we would
+  // not be here.
+  gold_assert(deleted_bytes != 0
+             && deleted_bytes != this->exidx_input_section_.size());
+
   // Fix size here so that we do not need to implement set_final_data_size.
-  this->set_data_size(exidx_input_section.size() - deleted_bytes);
+  uint32_t size = exidx_input_section.size() - deleted_bytes;
+  this->set_data_size(size);
   this->fix_data_size();
+
+  // Allocate buffer for section contents and build contents.
+  this->section_contents_ = new unsigned char[size];
+}
+
+// Build the contents of a merged EXIDX output section.
+
+void
+Arm_exidx_merged_section::build_contents(
+    const unsigned char* original_contents,
+    section_size_type original_size)
+{
+  // Go over spans of input offsets and write only those that are not
+  // discarded.
+  section_offset_type in_start = 0;
+  section_offset_type out_start = 0;
+  section_offset_type in_max =
+    convert_types<section_offset_type>(original_size);
+  section_offset_type out_max =
+    convert_types<section_offset_type>(this->data_size());
+  for (Arm_exidx_section_offset_map::const_iterator p =
+        this->section_offset_map_.begin();
+      p != this->section_offset_map_.end();
+      ++p)
+    {
+      section_offset_type in_end = p->first;
+      gold_assert(in_end >= in_start);
+      section_offset_type out_end = p->second;
+      size_t in_chunk_size = convert_types<size_t>(in_end - in_start + 1);
+      if (out_end != -1)
+       {
+         size_t out_chunk_size =
+           convert_types<size_t>(out_end - out_start + 1);
+
+         gold_assert(out_chunk_size == in_chunk_size
+                     && in_end < in_max && out_end < out_max);
+
+         memcpy(this->section_contents_ + out_start,
+                original_contents + in_start,
+                out_chunk_size);
+         out_start += out_chunk_size;
+       }
+      in_start += in_chunk_size;
+    }
 }
 
 // Given an input OBJECT, an input section index SHNDX within that
@@ -5111,11 +5389,6 @@ Arm_exidx_merged_section::do_output_offset(
 void
 Arm_exidx_merged_section::do_write(Output_file* of)
 {
-  // If we retain or discard the whole EXIDX input section,  we would
-  // not be here.
-  gold_assert(this->data_size() != this->exidx_input_section_.size()
-             && this->data_size() != 0);
-
   off_t offset = this->offset();
   const section_size_type oview_size = this->data_size();
   unsigned char* const oview = of->get_output_view(offset, oview_size);
@@ -5123,38 +5396,7 @@ Arm_exidx_merged_section::do_write(Output_file* of)
   Output_section* os = this->relobj()->output_section(this->shndx());
   gold_assert(os != NULL);
 
-  // Get contents of EXIDX input section.
-  section_size_type section_size;
-  const unsigned char* section_contents =
-    this->relobj()->section_contents(this->shndx(), &section_size, false); 
-  gold_assert(section_size == this->exidx_input_section_.size());
-
-  // Go over spans of input offsets and write only those that are not
-  // discarded.
-  section_offset_type in_start = 0;
-  section_offset_type out_start = 0;
-  for(Arm_exidx_section_offset_map::const_iterator p =
-        this->section_offset_map_.begin();
-      p != this->section_offset_map_.end();
-      ++p)
-    {
-      section_offset_type in_end = p->first;
-      gold_assert(in_end >= in_start);
-      section_offset_type out_end = p->second;
-      size_t in_chunk_size = convert_types<size_t>(in_end - in_start + 1);
-      if (out_end != -1)
-       {
-         size_t out_chunk_size =
-           convert_types<size_t>(out_end - out_start + 1);
-         gold_assert(out_chunk_size == in_chunk_size);
-         memcpy(oview + out_start, section_contents + in_start,
-                out_chunk_size);
-         out_start += out_chunk_size;
-       }
-      in_start += in_chunk_size;
-    }
-
-  gold_assert(convert_to_section_size_type(out_start) == oview_size);
+  memcpy(oview, this->section_contents_, oview_size);
   of->write_output_view(this->offset(), oview_size, oview);
 }
 
@@ -5235,21 +5477,22 @@ Arm_exidx_fixup::update_offset_map(
 }
 
 // Process EXIDX_INPUT_SECTION for EXIDX entry merging.  Return the number of
-// bytes deleted.  If some entries are merged, also store a pointer to a newly
-// created Arm_exidx_section_offset_map object in *PSECTION_OFFSET_MAP.  The
-// caller owns the map and is responsible for releasing it after use.
+// bytes deleted.  SECTION_CONTENTS points to the contents of the EXIDX
+// section and SECTION_SIZE is the number of bytes pointed by SECTION_CONTENTS.
+// If some entries are merged, also store a pointer to a newly created
+// Arm_exidx_section_offset_map object in *PSECTION_OFFSET_MAP.  The caller
+// owns the map and is responsible for releasing it after use.
 
 template<bool big_endian>
 uint32_t
 Arm_exidx_fixup::process_exidx_section(
     const Arm_exidx_input_section* exidx_input_section,
+    const unsigned char* section_contents,
+    section_size_type section_size,
     Arm_exidx_section_offset_map** psection_offset_map)
 {
   Relobj* relobj = exidx_input_section->relobj();
   unsigned shndx = exidx_input_section->shndx();
-  section_size_type section_size;
-  const unsigned char* section_contents =
-    relobj->section_contents(shndx, &section_size, false);
 
   if ((section_size % 8) != 0)
     {
@@ -5282,7 +5525,7 @@ Arm_exidx_fixup::process_exidx_section(
       // dropping.  If there is no entry (x0, y0) for an input offset x0,
       // the output offset y0 of it is determined by the output offset y1 of
       // the smallest input offset x1 > x0 that there is an (x1, y1) entry
-      // in the map.  If y1 is not -1, then y0 = y1 + x0 - x1.  Othewise, y1
+      // in the map.  If y1 is not -1, then y0 = y1 + x0 - x1.  Otherwise, y1
       // y0 is also -1.
       if (delete_entry != prev_delete_entry && i != 0)
        this->update_offset_map(i - 1, deleted_bytes, prev_delete_entry);
@@ -5329,7 +5572,8 @@ Arm_output_section<big_endian>::create_stub_group(
   Input_section_list::const_iterator end,
   Input_section_list::const_iterator owner,
   Target_arm<big_endian>* target,
-  std::vector<Output_relaxed_input_section*>* new_relaxed_sections)
+  std::vector<Output_relaxed_input_section*>* new_relaxed_sections,
+  const Task* task)
 {
   // We use a different kind of relaxed section in an EXIDX section.
   // The static casting from Output_relaxed_input_section to
@@ -5352,7 +5596,9 @@ Arm_output_section<big_endian>::create_stub_group(
   else
     {
       gold_assert(owner->is_input_section());
-      // Create a new relaxed input section.
+      // Create a new relaxed input section.  We need to lock the original
+      // file.
+      Task_lock_obj<Object> tl(task, owner->relobj());
       arm_input_section =
        target->new_arm_input_section(owner->relobj(), owner->shndx());
       new_relaxed_sections->push_back(arm_input_section);
@@ -5397,7 +5643,8 @@ void
 Arm_output_section<big_endian>::group_sections(
     section_size_type group_size,
     bool stubs_always_after_branch,
-    Target_arm<big_endian>* target)
+    Target_arm<big_endian>* target,
+    const Task* task)
 {
   // We only care about sections containing code.
   if ((this->flags() & elfcpp::SHF_EXECINSTR) == 0)
@@ -5440,7 +5687,7 @@ Arm_output_section<big_endian>::group_sections(
       section_size_type section_end_offset =
        section_begin_offset + p->data_size(); 
       
-      // Check to see if we should group the previously seens sections.
+      // Check to see if we should group the previously seen sections.
       switch (state)
        {
        case NO_GROUP:
@@ -5454,7 +5701,8 @@ Arm_output_section<big_endian>::group_sections(
                {       
                  gold_assert(group_end != this->input_sections().end());
                  this->create_stub_group(group_begin, group_end, group_end,
-                                         target, &new_relaxed_sections);
+                                         target, &new_relaxed_sections,
+                                         task);
                  state = NO_GROUP;
                }
              else
@@ -5476,7 +5724,7 @@ Arm_output_section<big_endian>::group_sections(
           {
             gold_assert(group_end != this->input_sections().end());
             this->create_stub_group(group_begin, group_end, stub_table,
-                                    target, &new_relaxed_sections);
+                                    target, &new_relaxed_sections, task);
             state = NO_GROUP;
           }
           break;
@@ -5486,9 +5734,10 @@ Arm_output_section<big_endian>::group_sections(
        }       
 
       // If we see an input section and currently there is no group, start
-      // a new one.  Skip any empty sections.
+      // a new one.  Skip any empty sections.  We look at the data size
+      // instead of calling p->relobj()->section_size() to avoid locking.
       if ((p->is_input_section() || p->is_relaxed_input_section())
-         && (p->relobj()->section_size(p->shndx()) != 0))
+         && (p->data_size() != 0))
        {
          if (state == NO_GROUP)
            {
@@ -5513,7 +5762,7 @@ Arm_output_section<big_endian>::group_sections(
                              (state == FINDING_STUB_SECTION
                               ? group_end
                               : stub_table),
-                              target, &new_relaxed_sections);
+                              target, &new_relaxed_sections, task);
     }
 
   // Convert input section into relaxed input section in a batch.
@@ -5540,10 +5789,6 @@ void
 Arm_output_section<big_endian>::append_text_sections_to_list(
     Text_section_list* list)
 {
-  // We only care about text sections.
-  if ((this->flags() & elfcpp::SHF_EXECINSTR) == 0)
-    return;
-
   gold_assert((this->flags() & elfcpp::SHF_ALLOC) != 0);
 
   for (Input_section_list::const_iterator p = this->input_sections().begin();
@@ -5565,7 +5810,8 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
     Layout* layout,
     const Text_section_list& sorted_text_sections,
     Symbol_table* symtab,
-    bool merge_exidx_entries)
+    bool merge_exidx_entries,
+    const Task* task)
 {
   // We should only do this for the EXIDX output section.
   gold_assert(this->type() == elfcpp::SHT_ARM_EXIDX);
@@ -5576,8 +5822,8 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
 
   // Remove all input sections.
   uint64_t address = this->address();
-  typedef std::list<Simple_input_section> Simple_input_section_list;
-  Simple_input_section_list input_sections;
+  typedef std::list<Output_section::Input_section> Input_section_list;
+  Input_section_list input_sections;
   this->reset_address_and_file_offset();
   this->get_input_sections(address, std::string(""), &input_sections);
 
@@ -5586,20 +5832,23 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
   
   // Go through all the known input sections and record them.
   typedef Unordered_set<Section_id, Section_id_hash> Section_id_set;
-  Section_id_set known_input_sections;
-  for (Simple_input_section_list::const_iterator p = input_sections.begin();
+  typedef Unordered_map<Section_id, const Output_section::Input_section*,
+                       Section_id_hash> Text_to_exidx_map;
+  Text_to_exidx_map text_to_exidx_map;
+  for (Input_section_list::const_iterator p = input_sections.begin();
        p != input_sections.end();
        ++p)
     {
       // This should never happen.  At this point, we should only see
       // plain EXIDX input sections.
       gold_assert(!p->is_relaxed_input_section());
-      known_input_sections.insert(Section_id(p->relobj(), p->shndx()));
+      text_to_exidx_map[Section_id(p->relobj(), p->shndx())] = &(*p);
     }
 
   Arm_exidx_fixup exidx_fixup(this, merge_exidx_entries);
 
   // Go over the sorted text sections.
+  typedef Unordered_set<Section_id, Section_id_hash> Section_id_set;
   Section_id_set processed_input_sections;
   for (Text_section_list::const_iterator p = sorted_text_sections.begin();
        p != sorted_text_sections.end();
@@ -5613,9 +5862,10 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
       const Arm_exidx_input_section* exidx_input_section =
         arm_relobj->exidx_input_section_by_link(shndx);
 
-      // If this text section has no EXIDX section, force an EXIDX_CANTUNWIND
-      // entry pointing to the end of the last seen EXIDX section.
-      if (exidx_input_section == NULL)
+      // If this text section has no EXIDX section or if the EXIDX section
+      // has errors, force an EXIDX_CANTUNWIND entry pointing to the end
+      // of the last seen EXIDX section.
+      if (exidx_input_section == NULL || exidx_input_section->has_errors())
        {
          exidx_fixup.add_exidx_cantunwind_as_needed();
          continue;
@@ -5624,7 +5874,8 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
       Relobj* exidx_relobj = exidx_input_section->relobj();
       unsigned int exidx_shndx = exidx_input_section->shndx();
       Section_id sid(exidx_relobj, exidx_shndx);
-      if (known_input_sections.find(sid) == known_input_sections.end())
+      Text_to_exidx_map::const_iterator iter = text_to_exidx_map.find(sid);
+      if (iter == text_to_exidx_map.end())
        {
          // This is odd.  We have not seen this EXIDX input section before.
          // We cannot do fix-up.  If we saw a SECTIONS clause in a script,
@@ -5643,10 +5894,19 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
          continue;
        }
 
+      // We need to access the contents of the EXIDX section, lock the
+      // object here.
+      Task_lock_obj<Object> tl(task, exidx_relobj);
+      section_size_type exidx_size;
+      const unsigned char* exidx_contents =
+       exidx_relobj->section_contents(exidx_shndx, &exidx_size, false); 
+
       // Fix up coverage and append input section to output data list.
       Arm_exidx_section_offset_map* section_offset_map = NULL;
       uint32_t deleted_bytes =
         exidx_fixup.process_exidx_section<big_endian>(exidx_input_section,
+                                                     exidx_contents,
+                                                     exidx_size,
                                                      &section_offset_map);
 
       if (deleted_bytes == exidx_input_section->size())
@@ -5664,10 +5924,14 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
          // Some entries are merged.  We need to convert this EXIDX input
          // section into a relaxed section.
          gold_assert(section_offset_map != NULL);
+
          Arm_exidx_merged_section* merged_section =
            new Arm_exidx_merged_section(*exidx_input_section,
                                         *section_offset_map, deleted_bytes);
-         this->add_relaxed_input_section(merged_section);
+         merged_section->build_contents(exidx_contents, exidx_size);
+
+         const std::string secname = exidx_relobj->section_name(exidx_shndx);
+         this->add_relaxed_input_section(layout, merged_section, secname);
          arm_relobj->convert_input_section_to_relaxed_section(exidx_shndx);
 
          // All local symbols defined in discarded portions of this input
@@ -5679,9 +5943,9 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
        {
          // Just add back the EXIDX input section.
          gold_assert(section_offset_map == NULL);
-         Output_section::Simple_input_section sis(exidx_relobj, exidx_shndx);
-         this->add_simple_input_section(sis, exidx_input_section->size(),
-                                        exidx_input_section->addralign());
+         const Output_section::Input_section* pis = iter->second;
+         gold_assert(pis->is_input_section());
+         this->add_script_input_section(*pis);
        }
 
       processed_input_sections.insert(Section_id(exidx_relobj, exidx_shndx)); 
@@ -5691,22 +5955,27 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
   exidx_fixup.add_exidx_cantunwind_as_needed();
 
   // Remove any known EXIDX input sections that are not processed.
-  for (Simple_input_section_list::const_iterator p = input_sections.begin();
+  for (Input_section_list::const_iterator p = input_sections.begin();
        p != input_sections.end();
        ++p)
     {
       if (processed_input_sections.find(Section_id(p->relobj(), p->shndx()))
          == processed_input_sections.end())
        {
-         // We only discard a known EXIDX section because its linked
-         // text section has been folded by ICF.
+         // We discard a known EXIDX section because its linked
+         // text section has been folded by ICF.  We also discard an
+         // EXIDX section with error, the output does not matter in this
+         // case.  We do this to avoid triggering asserts.
          Arm_relobj<big_endian>* arm_relobj =
            Arm_relobj<big_endian>::as_arm_relobj(p->relobj());
          const Arm_exidx_input_section* exidx_input_section =
            arm_relobj->exidx_input_section_by_shndx(p->shndx());
          gold_assert(exidx_input_section != NULL);
-         unsigned int text_shndx = exidx_input_section->link();
-         gold_assert(symtab->is_section_folded(p->relobj(), text_shndx));
+         if (!exidx_input_section->has_errors())
+           {
+             unsigned int text_shndx = exidx_input_section->link();
+             gold_assert(symtab->is_section_folded(p->relobj(), text_shndx));
+           }
 
          // Remove this from link.  We also need to recount the
          // local symbols.
@@ -5725,6 +5994,28 @@ Arm_output_section<big_endian>::fix_exidx_coverage(
   this->set_section_offsets_need_adjustment();
 }
 
+// Link EXIDX output sections to text output sections.
+
+template<bool big_endian>
+void
+Arm_output_section<big_endian>::set_exidx_section_link()
+{
+  gold_assert(this->type() == elfcpp::SHT_ARM_EXIDX);
+  if (!this->input_sections().empty())
+    {
+      Input_section_list::const_iterator p = this->input_sections().begin();
+      Arm_relobj<big_endian>* arm_relobj =
+       Arm_relobj<big_endian>::as_arm_relobj(p->relobj());
+      unsigned exidx_shndx = p->shndx();
+      const Arm_exidx_input_section* exidx_input_section =
+       arm_relobj->exidx_input_section_by_shndx(exidx_shndx);
+      gold_assert(exidx_input_section != NULL);
+      unsigned int text_shndx = exidx_input_section->link();
+      Output_section* os = arm_relobj->output_section(text_shndx);
+      this->set_link_section(os);
+    }
+}
+
 // Arm_relobj methods.
 
 // Determine if an input section is scannable for stub processing.  SHDR is
@@ -5738,7 +6029,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.
@@ -5773,7 +6064,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();
@@ -6044,7 +6335,7 @@ Arm_relobj<big_endian>::scan_sections_for_stubs(
 // harder because we cannot access this information.   So we override the
 // do_count_local_symbol in parent and scan local symbols to mark
 // THUMB functions.  This is not the most efficient way but I do not want to
-// slow down other ports by calling a per symbol targer hook inside
+// slow down other ports by calling a per symbol target hook inside
 // Sized_relobj<size, big_endian>::do_count_local_symbols. 
 
 template<bool big_endian>
@@ -6062,7 +6353,7 @@ Arm_relobj<big_endian>::do_count_local_symbols(
   if (loccount == 0)
     return;
 
-  // Intialize the thumb function bit-vector.
+  // Initialize the thumb function bit-vector.
   std::vector<bool> empty_vector(loccount, false);
   this->local_symbol_is_thumb_function_.swap(empty_vector);
 
@@ -6147,11 +6438,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())
@@ -6236,9 +6528,9 @@ Arm_relobj<big_endian>::do_relocate_sections(
     }
 }
 
-// Find the linked text section of an EXIDX section by looking the the first
+// Find the linked text section of an EXIDX section by looking at the first
 // relocation.  4.4.1 of the EHABI specifications says that an EXIDX section
-// must be linked to to its associated code section via the sh_link field of
+// must be linked to its associated code section via the sh_link field of
 // its section header.  However, some tools are broken and the link is not
 // always set.  LD just drops such an EXIDX section silently, causing the
 // associated code not unwindabled.   Here we try a little bit harder to
@@ -6326,28 +6618,58 @@ void
 Arm_relobj<big_endian>::make_exidx_input_section(
     unsigned int shndx,
     const elfcpp::Shdr<32, big_endian>& shdr,
-    unsigned int text_shndx)
+    unsigned int text_shndx,
+    const elfcpp::Shdr<32, big_endian>& text_shdr)
 {
-  // Issue an error and ignore this EXIDX section if it points to a text
-  // section already has an EXIDX section.
-  if (this->exidx_section_map_[text_shndx] != NULL)
-    {
-      gold_error(_("EXIDX sections %u and %u both link to text section %u "
-                  "in %s"),
-                shndx, this->exidx_section_map_[text_shndx]->shndx(),
-                text_shndx, this->name().c_str());
-      return;
-    }
-
   // Create an Arm_exidx_input_section object for this EXIDX section.
   Arm_exidx_input_section* exidx_input_section =
     new Arm_exidx_input_section(this, shndx, text_shndx, shdr.get_sh_size(),
-                               shdr.get_sh_addralign());
-  this->exidx_section_map_[text_shndx] = exidx_input_section;
+                               shdr.get_sh_addralign(),
+                               text_shdr.get_sh_size());
 
-  // Also map the EXIDX section index to this.
   gold_assert(this->exidx_section_map_[shndx] == NULL);
   this->exidx_section_map_[shndx] = exidx_input_section;
+
+  if (text_shndx == elfcpp::SHN_UNDEF || text_shndx >= this->shnum())
+    {
+      gold_error(_("EXIDX section %s(%u) links to invalid section %u in %s"),
+                this->section_name(shndx).c_str(), shndx, text_shndx,
+                this->name().c_str());
+      exidx_input_section->set_has_errors();
+    } 
+  else if (this->exidx_section_map_[text_shndx] != NULL)
+    {
+      unsigned other_exidx_shndx =
+       this->exidx_section_map_[text_shndx]->shndx();
+      gold_error(_("EXIDX sections %s(%u) and %s(%u) both link to text section"
+                  "%s(%u) in %s"),
+                this->section_name(shndx).c_str(), shndx,
+                this->section_name(other_exidx_shndx).c_str(),
+                other_exidx_shndx, this->section_name(text_shndx).c_str(),
+                text_shndx, this->name().c_str());
+      exidx_input_section->set_has_errors();
+    }
+  else
+     this->exidx_section_map_[text_shndx] = exidx_input_section;
+
+  // Check section flags of text section.
+  if ((text_shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0)
+    {
+      gold_error(_("EXIDX section %s(%u) links to non-allocated section %s(%u) "
+                  " in %s"),
+                this->section_name(shndx).c_str(), shndx,
+                this->section_name(text_shndx).c_str(), text_shndx,
+                this->name().c_str());
+      exidx_input_section->set_has_errors();
+    }
+  else if ((text_shdr.get_sh_flags() & elfcpp::SHF_EXECINSTR) == 0)
+    // I would like to make this an error but currently ld just ignores
+    // this.
+    gold_warning(_("EXIDX section %s(%u) links to non-executable section "
+                  "%s(%u) in %s"),
+                this->section_name(shndx).c_str(), shndx,
+                this->section_name(text_shndx).c_str(), text_shndx,
+                this->name().c_str());
 }
 
 // Read the symbol information.
@@ -6381,7 +6703,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)
     {
@@ -6409,27 +6731,33 @@ Arm_relobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
          section_offset_type section_offset = shdr.get_sh_offset();
          section_size_type section_size =
            convert_to_section_size_type(shdr.get_sh_size());
-         File_view* view = this->get_lasting_view(section_offset,
-                                                  section_size, true, false);
+         const unsigned char* view =
+            this->get_view(section_offset, section_size, true, false);
          this->attributes_section_data_ =
-           new Attributes_section_data(view->data(), section_size);
+           new Attributes_section_data(view, section_size);
        }
       else if (shdr.get_sh_type() == elfcpp::SHT_ARM_EXIDX)
        {
          unsigned int text_shndx = this->adjust_shndx(shdr.get_sh_link());
-         if (text_shndx >= this->shnum())
-           gold_error(_("EXIDX section %u linked to invalid section %u"),
-                      i, text_shndx);
-         else if (text_shndx == elfcpp::SHN_UNDEF)
+         if (text_shndx == elfcpp::SHN_UNDEF)
            deferred_exidx_sections.push_back(i);
          else
-           this->make_exidx_input_section(i, shdr, text_shndx);
+           {
+             elfcpp::Shdr<32, big_endian> text_shdr(pshdrs
+                                                    + text_shndx * shdr_size);
+             this->make_exidx_input_section(i, shdr, text_shndx, text_shdr);
+           }
+         // EHABI 4.4.1 requires that SHF_LINK_ORDER flag to be set.
+         if ((shdr.get_sh_flags() & elfcpp::SHF_LINK_ORDER) == 0)
+           gold_warning(_("SHF_LINK_ORDER not set in EXIDX section %s of %s"),
+                        this->section_name(i).c_str(), this->name().c_str());
        }
     }
 
   // This is rare.
   if (!must_merge_flags_and_attributes)
     {
+      gold_assert(deferred_exidx_sections.empty());
       this->merge_flags_and_attributes_ = false;
       return;
     }
@@ -6481,26 +6809,25 @@ Arm_relobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
                                                  locsize, true, true);
 
       // Process the deferred EXIDX sections. 
-      for(unsigned int i = 0; i < deferred_exidx_sections.size(); ++i)
+      for (unsigned int i = 0; i < deferred_exidx_sections.size(); ++i)
        {
          unsigned int shndx = deferred_exidx_sections[i];
          elfcpp::Shdr<32, big_endian> shdr(pshdrs + shndx * shdr_size);
-         unsigned int text_shndx;
+         unsigned int text_shndx = elfcpp::SHN_UNDEF;
          Reloc_map::const_iterator it = reloc_map.find(shndx);
-         if (it != reloc_map.end()
-             && find_linked_text_section(pshdrs + it->second * shdr_size,
-                                         psyms, &text_shndx))
-           this->make_exidx_input_section(shndx, shdr, text_shndx);
-         else
-           gold_error(_("EXIDX section %u has no linked text section."),
-                      shndx);
+         if (it != reloc_map.end())
+           find_linked_text_section(pshdrs + it->second * shdr_size,
+                                    psyms, &text_shndx);
+         elfcpp::Shdr<32, big_endian> text_shdr(pshdrs
+                                                + text_shndx * shdr_size);
+         this->make_exidx_input_section(shndx, shdr, text_shndx, text_shdr);
        }
     }
 }
 
 // Process relocations for garbage collection.  The ARM target uses .ARM.exidx
 // sections for unwinding.  These sections are referenced implicitly by 
-// text sections linked in the section headers.  If we ignore these implict
+// text sections linked in the section headers.  If we ignore these implicit
 // references, the .ARM.exidx sections and any .ARM.extab sections they use
 // will be garbage-collected incorrectly.  Hence we override the same function
 // in the base class to handle these implicit references.
@@ -6656,7 +6983,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)
     {
@@ -6666,10 +6993,10 @@ Arm_dynobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
          section_offset_type section_offset = shdr.get_sh_offset();
          section_size_type section_size =
            convert_to_section_size_type(shdr.get_sh_size());
-         File_view* view = this->get_lasting_view(section_offset,
-                                                  section_size, true, false);
+         const unsigned char* view =
+           this->get_view(section_offset, section_size, true, false);
          this->attributes_section_data_ =
-           new Attributes_section_data(view->data(), section_size);
+           new Attributes_section_data(view, section_size);
          break;
        }
     }
@@ -6901,6 +7228,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);
@@ -6948,8 +7290,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>
@@ -7111,11 +7453,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>
@@ -7200,45 +7571,167 @@ Target_arm<big_endian>::optimize_tls_reloc(bool, int)
   return tls::TLSOPT_NONE;
 }
 
-// Report an unsupported relocation against a local symbol.
-
-template<bool big_endian>
-void
-Target_arm<big_endian>::Scan::unsupported_reloc_local(
-    Sized_relobj<32, big_endian>* object,
-    unsigned int r_type)
-{
-  gold_error(_("%s: unsupported reloc %u against local symbol"),
-            object->name().c_str(), r_type);
-}
-
-// We are about to emit a dynamic relocation of type R_TYPE.  If the
-// dynamic linker does not support it, issue an error.  The GNU linker
-// only issues a non-PIC error for an allocated read-only section.
-// Here we know the section is allocated, but we don't know that it is
-// read-only.  But we check for all the relocation types which the
-// glibc dynamic linker supports, so it seems appropriate to issue an
-// error even if the section is not read-only.
+// Get the Reference_flags for a particular relocation.
 
 template<bool big_endian>
-void
-Target_arm<big_endian>::Scan::check_non_pic(Relobj* object,
-                                           unsigned int r_type)
+int
+Target_arm<big_endian>::Scan::get_reference_flags(unsigned int r_type)
 {
   switch (r_type)
     {
-    // These are the relocation types supported by glibc for ARM.
-    case elfcpp::R_ARM_RELATIVE:
-    case elfcpp::R_ARM_COPY:
-    case elfcpp::R_ARM_GLOB_DAT:
-    case elfcpp::R_ARM_JUMP_SLOT:
+    case elfcpp::R_ARM_NONE:
+    case elfcpp::R_ARM_V4BX:
+    case elfcpp::R_ARM_GNU_VTENTRY:
+    case elfcpp::R_ARM_GNU_VTINHERIT:
+      // No symbol reference.
+      return 0;
+
     case elfcpp::R_ARM_ABS32:
+    case elfcpp::R_ARM_ABS16:
+    case elfcpp::R_ARM_ABS12:
+    case elfcpp::R_ARM_THM_ABS5:
+    case elfcpp::R_ARM_ABS8:
+    case elfcpp::R_ARM_BASE_ABS:
+    case elfcpp::R_ARM_MOVW_ABS_NC:
+    case elfcpp::R_ARM_MOVT_ABS:
+    case elfcpp::R_ARM_THM_MOVW_ABS_NC:
+    case elfcpp::R_ARM_THM_MOVT_ABS:
     case elfcpp::R_ARM_ABS32_NOI:
-    case elfcpp::R_ARM_PC24:
-    // FIXME: The following 3 types are not supported by Android's dynamic
-    // linker.
-    case elfcpp::R_ARM_TLS_DTPMOD32:
-    case elfcpp::R_ARM_TLS_DTPOFF32:
+      return Symbol::ABSOLUTE_REF;
+
+    case elfcpp::R_ARM_REL32:
+    case elfcpp::R_ARM_LDR_PC_G0:
+    case elfcpp::R_ARM_SBREL32:
+    case elfcpp::R_ARM_THM_PC8:
+    case elfcpp::R_ARM_BASE_PREL:
+    case elfcpp::R_ARM_MOVW_PREL_NC:
+    case elfcpp::R_ARM_MOVT_PREL:
+    case elfcpp::R_ARM_THM_MOVW_PREL_NC:
+    case elfcpp::R_ARM_THM_MOVT_PREL:
+    case elfcpp::R_ARM_THM_ALU_PREL_11_0:
+    case elfcpp::R_ARM_THM_PC12:
+    case elfcpp::R_ARM_REL32_NOI:
+    case elfcpp::R_ARM_ALU_PC_G0_NC:
+    case elfcpp::R_ARM_ALU_PC_G0:
+    case elfcpp::R_ARM_ALU_PC_G1_NC:
+    case elfcpp::R_ARM_ALU_PC_G1:
+    case elfcpp::R_ARM_ALU_PC_G2:
+    case elfcpp::R_ARM_LDR_PC_G1:
+    case elfcpp::R_ARM_LDR_PC_G2:
+    case elfcpp::R_ARM_LDRS_PC_G0:
+    case elfcpp::R_ARM_LDRS_PC_G1:
+    case elfcpp::R_ARM_LDRS_PC_G2:
+    case elfcpp::R_ARM_LDC_PC_G0:
+    case elfcpp::R_ARM_LDC_PC_G1:
+    case elfcpp::R_ARM_LDC_PC_G2:
+    case elfcpp::R_ARM_ALU_SB_G0_NC:
+    case elfcpp::R_ARM_ALU_SB_G0:
+    case elfcpp::R_ARM_ALU_SB_G1_NC:
+    case elfcpp::R_ARM_ALU_SB_G1:
+    case elfcpp::R_ARM_ALU_SB_G2:
+    case elfcpp::R_ARM_LDR_SB_G0:
+    case elfcpp::R_ARM_LDR_SB_G1:
+    case elfcpp::R_ARM_LDR_SB_G2:
+    case elfcpp::R_ARM_LDRS_SB_G0:
+    case elfcpp::R_ARM_LDRS_SB_G1:
+    case elfcpp::R_ARM_LDRS_SB_G2:
+    case elfcpp::R_ARM_LDC_SB_G0:
+    case elfcpp::R_ARM_LDC_SB_G1:
+    case elfcpp::R_ARM_LDC_SB_G2:
+    case elfcpp::R_ARM_MOVW_BREL_NC:
+    case elfcpp::R_ARM_MOVT_BREL:
+    case elfcpp::R_ARM_MOVW_BREL:
+    case elfcpp::R_ARM_THM_MOVW_BREL_NC:
+    case elfcpp::R_ARM_THM_MOVT_BREL:
+    case elfcpp::R_ARM_THM_MOVW_BREL:
+    case elfcpp::R_ARM_GOTOFF32:
+    case elfcpp::R_ARM_GOTOFF12:
+    case elfcpp::R_ARM_SBREL31:
+      return Symbol::RELATIVE_REF;
+
+    case elfcpp::R_ARM_PLT32:
+    case elfcpp::R_ARM_CALL:
+    case elfcpp::R_ARM_JUMP24:
+    case elfcpp::R_ARM_THM_CALL:
+    case elfcpp::R_ARM_THM_JUMP24:
+    case elfcpp::R_ARM_THM_JUMP19:
+    case elfcpp::R_ARM_THM_JUMP6:
+    case elfcpp::R_ARM_THM_JUMP11:
+    case elfcpp::R_ARM_THM_JUMP8:
+    // R_ARM_PREL31 is not used to relocate call/jump instructions but
+    // in unwind tables. It may point to functions via PLTs.
+    // So we treat it like call/jump relocations above.
+    case elfcpp::R_ARM_PREL31:
+      return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
+
+    case elfcpp::R_ARM_GOT_BREL:
+    case elfcpp::R_ARM_GOT_ABS:
+    case elfcpp::R_ARM_GOT_PREL:
+      // Absolute in GOT.
+      return Symbol::ABSOLUTE_REF;
+
+    case elfcpp::R_ARM_TLS_GD32:       // Global-dynamic
+    case elfcpp::R_ARM_TLS_LDM32:      // Local-dynamic
+    case elfcpp::R_ARM_TLS_LDO32:      // Alternate local-dynamic
+    case elfcpp::R_ARM_TLS_IE32:       // Initial-exec
+    case elfcpp::R_ARM_TLS_LE32:       // Local-exec
+      return Symbol::TLS_REF;
+
+    case elfcpp::R_ARM_TARGET1:
+    case elfcpp::R_ARM_TARGET2:
+    case elfcpp::R_ARM_COPY:
+    case elfcpp::R_ARM_GLOB_DAT:
+    case elfcpp::R_ARM_JUMP_SLOT:
+    case elfcpp::R_ARM_RELATIVE:
+    case elfcpp::R_ARM_PC24:
+    case elfcpp::R_ARM_LDR_SBREL_11_0_NC:
+    case elfcpp::R_ARM_ALU_SBREL_19_12_NC:
+    case elfcpp::R_ARM_ALU_SBREL_27_20_CK:
+    default:
+      // Not expected.  We will give an error later.
+      return 0;
+    }
+}
+
+// Report an unsupported relocation against a local symbol.
+
+template<bool big_endian>
+void
+Target_arm<big_endian>::Scan::unsupported_reloc_local(
+    Sized_relobj<32, big_endian>* object,
+    unsigned int r_type)
+{
+  gold_error(_("%s: unsupported reloc %u against local symbol"),
+            object->name().c_str(), r_type);
+}
+
+// We are about to emit a dynamic relocation of type R_TYPE.  If the
+// dynamic linker does not support it, issue an error.  The GNU linker
+// only issues a non-PIC error for an allocated read-only section.
+// Here we know the section is allocated, but we don't know that it is
+// read-only.  But we check for all the relocation types which the
+// glibc dynamic linker supports, so it seems appropriate to issue an
+// error even if the section is not read-only.
+
+template<bool big_endian>
+void
+Target_arm<big_endian>::Scan::check_non_pic(Relobj* object,
+                                           unsigned int r_type)
+{
+  switch (r_type)
+    {
+    // These are the relocation types supported by glibc for ARM.
+    case elfcpp::R_ARM_RELATIVE:
+    case elfcpp::R_ARM_COPY:
+    case elfcpp::R_ARM_GLOB_DAT:
+    case elfcpp::R_ARM_JUMP_SLOT:
+    case elfcpp::R_ARM_ABS32:
+    case elfcpp::R_ARM_ABS32_NOI:
+    case elfcpp::R_ARM_PC24:
+    // FIXME: The following 3 types are not supported by Android's dynamic
+    // linker.
+    case elfcpp::R_ARM_TLS_DTPMOD32:
+    case elfcpp::R_ARM_TLS_DTPOFF32:
     case elfcpp::R_ARM_TLS_TPOFF32:
       return;
 
@@ -7349,7 +7842,6 @@ Target_arm<big_endian>::Scan::local(Symbol_table* symtab,
         }
       break;
 
-    case elfcpp::R_ARM_PC24:
     case elfcpp::R_ARM_REL32:
     case elfcpp::R_ARM_LDR_PC_G0:
     case elfcpp::R_ARM_SBREL32:
@@ -7360,9 +7852,6 @@ Target_arm<big_endian>::Scan::local(Symbol_table* symtab,
     case elfcpp::R_ARM_CALL:
     case elfcpp::R_ARM_JUMP24:
     case elfcpp::R_ARM_THM_JUMP24:
-    case elfcpp::R_ARM_LDR_SBREL_11_0_NC:
-    case elfcpp::R_ARM_ALU_SBREL_19_12_NC:
-    case elfcpp::R_ARM_ALU_SBREL_27_20_CK:
     case elfcpp::R_ARM_SBREL31:
     case elfcpp::R_ARM_PREL31:
     case elfcpp::R_ARM_MOVW_PREL_NC:
@@ -7566,6 +8055,10 @@ Target_arm<big_endian>::Scan::local(Symbol_table* symtab,
       }
       break;
 
+    case elfcpp::R_ARM_PC24:
+    case elfcpp::R_ARM_LDR_SBREL_11_0_NC:
+    case elfcpp::R_ARM_ALU_SBREL_19_12_NC:
+    case elfcpp::R_ARM_ALU_SBREL_27_20_CK:
     default:
       unsupported_reloc_local(object, r_type);
       break;
@@ -7585,6 +8078,72 @@ Target_arm<big_endian>::Scan::unsupported_reloc_global(
             object->name().c_str(), r_type, gsym->demangled_name().c_str());
 }
 
+template<bool big_endian>
+inline bool
+Target_arm<big_endian>::Scan::possible_function_pointer_reloc(
+    unsigned int r_type)
+{
+  switch (r_type)
+    {
+    case elfcpp::R_ARM_PC24:
+    case elfcpp::R_ARM_THM_CALL:
+    case elfcpp::R_ARM_PLT32:
+    case elfcpp::R_ARM_CALL:
+    case elfcpp::R_ARM_JUMP24:
+    case elfcpp::R_ARM_THM_JUMP24:
+    case elfcpp::R_ARM_SBREL31:
+    case elfcpp::R_ARM_PREL31:
+    case elfcpp::R_ARM_THM_JUMP19:
+    case elfcpp::R_ARM_THM_JUMP6:
+    case elfcpp::R_ARM_THM_JUMP11:
+    case elfcpp::R_ARM_THM_JUMP8:
+      // All the relocations above are branches except SBREL31 and PREL31.
+      return false;
+
+    default:
+      // Be conservative and assume this is a function pointer.
+      return true;
+    }
+}
+
+template<bool big_endian>
+inline bool
+Target_arm<big_endian>::Scan::local_reloc_may_be_function_pointer(
+  Symbol_table*,
+  Layout*,
+  Target_arm<big_endian>* target,
+  Sized_relobj<32, big_endian>*,
+  unsigned int,
+  Output_section*,
+  const elfcpp::Rel<32, big_endian>&,
+  unsigned int r_type,
+  const elfcpp::Sym<32, big_endian>&)
+{
+  r_type = target->get_real_reloc_type(r_type);
+  return possible_function_pointer_reloc(r_type);
+}
+
+template<bool big_endian>
+inline bool
+Target_arm<big_endian>::Scan::global_reloc_may_be_function_pointer(
+  Symbol_table*,
+  Layout*,
+  Target_arm<big_endian>* target,
+  Sized_relobj<32, big_endian>*,
+  unsigned int,
+  Output_section*,
+  const elfcpp::Rel<32, big_endian>&,
+  unsigned int r_type,
+  Symbol* gsym)
+{
+  // GOT is not a function.
+  if (strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
+    return false;
+
+  r_type = target->get_real_reloc_type(r_type);
+  return possible_function_pointer_reloc(r_type);
+}
+
 // Scan a relocation for a global symbol.
 
 template<bool big_endian>
@@ -7640,7 +8199,7 @@ Target_arm<big_endian>::Scan::global(Symbol_table* symtab,
               gsym->set_needs_dynsym_value();
           }
         // Make a dynamic relocation if necessary.
-        if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
+        if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
           {
             if (gsym->may_need_copy_reloc())
               {
@@ -7678,9 +8237,6 @@ Target_arm<big_endian>::Scan::global(Symbol_table* symtab,
     case elfcpp::R_ARM_SBREL32:
     case elfcpp::R_ARM_THM_PC8:
     case elfcpp::R_ARM_BASE_PREL:
-    case elfcpp::R_ARM_LDR_SBREL_11_0_NC:
-    case elfcpp::R_ARM_ALU_SBREL_19_12_NC:
-    case elfcpp::R_ARM_ALU_SBREL_27_20_CK:
     case elfcpp::R_ARM_MOVW_PREL_NC:
     case elfcpp::R_ARM_MOVT_PREL:
     case elfcpp::R_ARM_THM_MOVW_PREL_NC:
@@ -7724,8 +8280,7 @@ Target_arm<big_endian>::Scan::global(Symbol_table* symtab,
       // Relative addressing relocations.
       {
        // Make a dynamic relocation if necessary.
-       int flags = Symbol::NON_PIC_REF;
-       if (gsym->needs_dynamic_reloc(flags))
+       if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
          {
            if (target->may_need_copy_reloc(gsym))
              {
@@ -7743,7 +8298,6 @@ Target_arm<big_endian>::Scan::global(Symbol_table* symtab,
       }
       break;
 
-    case elfcpp::R_ARM_PC24:
     case elfcpp::R_ARM_THM_CALL:
     case elfcpp::R_ARM_PLT32:
     case elfcpp::R_ARM_CALL:
@@ -7758,7 +8312,7 @@ Target_arm<big_endian>::Scan::global(Symbol_table* symtab,
       // All the relocation above are branches except for the PREL31 ones.
       // A PREL31 relocation can point to a personality function in a shared
       // library.  In that case we want to use a PLT because we want to
-      // call the personality routine and the dyanmic linkers we care about
+      // call the personality routine and the dynamic linkers we care about
       // do not support dynamic PREL31 relocations. An REL31 relocation may
       // point to a function whose unwinding behaviour is being described but
       // we will not mistakenly generate a PLT for that because we should use
@@ -7912,6 +8466,10 @@ Target_arm<big_endian>::Scan::global(Symbol_table* symtab,
       }
       break;
 
+    case elfcpp::R_ARM_PC24:
+    case elfcpp::R_ARM_LDR_SBREL_11_0_NC:
+    case elfcpp::R_ARM_ALU_SBREL_19_12_NC:
+    case elfcpp::R_ARM_ALU_SBREL_27_20_CK:
     default:
       unsupported_reloc_global(object, r_type, gsym);
       break;
@@ -7937,7 +8495,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,
@@ -7998,6 +8557,7 @@ Target_arm<big_endian>::do_finalize_sections(
     const Input_objects* input_objects,
     Symbol_table* symtab)
 {
+  bool merged_any_attributes = false;
   // Merge processor-specific flags.
   for (Input_objects::Relobj_iterator p = input_objects->relobj_begin();
        p != input_objects->relobj_end();
@@ -8012,6 +8572,7 @@ Target_arm<big_endian>::do_finalize_sections(
              arm_relobj->processor_specific_flags());
          this->merge_object_attributes(arm_relobj->name().c_str(),
                                        arm_relobj->attributes_section_data());
+         merged_any_attributes = true;
        }
     } 
 
@@ -8026,6 +8587,7 @@ Target_arm<big_endian>::do_finalize_sections(
          arm_dynobj->processor_specific_flags());
       this->merge_object_attributes(arm_dynobj->name().c_str(),
                                    arm_dynobj->attributes_section_data());
+      merged_any_attributes = true;
     }
 
   // Create an empty uninitialized attribute section if we still don't have it
@@ -8078,46 +8640,74 @@ 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 __exidx_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 unless we have no regular input
-  // object.  In that case the output will be empty.
-  if (input_objects->number_of_relobjs() != 0)
+  // Create an .ARM.attributes section if we have merged any attributes
+  // from inputs.
+  if (merged_any_attributes)
     {
       Output_attributes_section_data* attributes_section =
       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);
     }
+
+  // Fix up links in section EXIDX headers.
+  for (Layout::Section_list::const_iterator p = layout->section_list().begin();
+       p != layout->section_list().end();
+       ++p)
+    if ((*p)->type() == elfcpp::SHT_ARM_EXIDX)
+      {
+       Arm_output_section<big_endian>* os =
+         Arm_output_section<big_endian>::as_arm_output_section(*p);
+       os->set_exidx_section_link();
+      }
 }
 
 // Return whether a direct absolute static relocation needs to be applied.
@@ -8130,7 +8720,7 @@ template<bool big_endian>
 inline bool
 Target_arm<big_endian>::Relocate::should_apply_static_reloc(
     const Sized_symbol<32>* gsym,
-    int ref_flags,
+    unsigned int r_type,
     bool is_32bit,
     Output_section* output_section)
 {
@@ -8140,6 +8730,8 @@ Target_arm<big_endian>::Relocate::should_apply_static_reloc(
   if ((output_section->flags() & elfcpp::SHF_ALLOC) == 0)
       return true;
 
+  int ref_flags = Scan::get_reference_flags(r_type);
+
   // For local symbols, we will have created a non-RELATIVE dynamic
   // relocation only if (a) the output is position independent,
   // (b) the relocation is absolute (not pc- or segment-relative), and
@@ -8167,7 +8759,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,
@@ -8200,13 +8792,52 @@ Target_arm<big_endian>::Relocate::relocate(
   Arm_address thumb_bit = 0;
   Symbol_value<32> symval;
   bool is_weakly_undefined_without_plt = false;
-  if (relnum != Target_arm<big_endian>::fake_relnum_for_stubs)
+  bool have_got_offset = false;
+  unsigned int got_offset = 0;
+
+  // If the relocation uses the GOT entry of a symbol instead of the symbol
+  // itself, we don't care about whether the symbol is defined or what kind
+  // of symbol it is.
+  if (reloc_property->uses_got_entry())
+    {
+      // Get the GOT offset.
+      // The GOT pointer points to the end of the GOT section.
+      // We need to subtract the size of the GOT section to get
+      // the actual offset to use in the relocation.
+      // TODO: We should move GOT offset computing code in TLS relocations
+      // to here.
+      switch (r_type)
+       {
+       case elfcpp::R_ARM_GOT_BREL:
+       case elfcpp::R_ARM_GOT_PREL:
+         if (gsym != NULL)
+           {
+             gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
+             got_offset = (gsym->got_offset(GOT_TYPE_STANDARD)
+                           - target->got_size());
+           }
+         else
+           {
+             unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
+             gold_assert(object->local_has_got_offset(r_sym,
+                                                      GOT_TYPE_STANDARD));
+             got_offset = (object->local_got_offset(r_sym, GOT_TYPE_STANDARD)
+                           - target->got_size());
+           }
+         have_got_offset = true;
+         break;
+
+       default:
+         break;
+       }
+    }
+  else if (relnum != Target_arm<big_endian>::fake_relnum_for_stubs)
     {
       if (gsym != NULL)
        {
          // This is a global symbol.  Determine if we use PLT and if the
          // final target is THUMB.
-         if (gsym->use_plt_offset(reloc_is_non_pic(r_type)))
+         if (gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
            {
              // This uses a PLT, change the symbol value.
              symval.set_output_value(target->plt_section()->address()
@@ -8220,6 +8851,13 @@ Target_arm<big_endian>::Relocate::relocate(
              // be converted into an NOP.
              is_weakly_undefined_without_plt = true;
            }
+         else if (gsym->is_undefined() && reloc_property->uses_symbol())
+           {
+             // This relocation uses the symbol value but the symbol is
+             // undefined.  Exit early and have the caller reporting an
+             // error.
+             return true;
+           }
          else
            {
              // Set thumb bit if symbol:
@@ -8262,36 +8900,6 @@ Target_arm<big_endian>::Relocate::relocate(
       psymval = &symval;
     } 
 
-  // Get the GOT offset if needed.
-  // The GOT pointer points to the end of the GOT section.
-  // We need to subtract the size of the GOT section to get
-  // the actual offset to use in the relocation.
-  bool have_got_offset = false;
-  unsigned int got_offset = 0;
-  switch (r_type)
-    {
-    case elfcpp::R_ARM_GOT_BREL:
-    case elfcpp::R_ARM_GOT_PREL:
-      if (gsym != NULL)
-       {
-         gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
-         got_offset = (gsym->got_offset(GOT_TYPE_STANDARD)
-                       - target->got_size());
-       }
-      else
-       {
-         unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
-         gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
-         got_offset = (object->local_got_offset(r_sym, GOT_TYPE_STANDARD)
-                       - target->got_size());
-       }
-      have_got_offset = true;
-      break;
-
-    default:
-      break;
-    }
-
   // To look up relocation stubs, we need to pass the symbol table index of
   // a local symbol.
   unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
@@ -8353,62 +8961,53 @@ Target_arm<big_endian>::Relocate::relocate(
       break;
 
     case elfcpp::R_ARM_ABS8:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, false, output_section))
        reloc_status = Arm_relocate_functions::abs8(view, object, psymval);
       break;
 
     case elfcpp::R_ARM_ABS12:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, false, output_section))
        reloc_status = Arm_relocate_functions::abs12(view, object, psymval);
       break;
 
     case elfcpp::R_ARM_ABS16:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, false, output_section))
        reloc_status = Arm_relocate_functions::abs16(view, object, psymval);
       break;
 
     case elfcpp::R_ARM_ABS32:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, true, output_section))
        reloc_status = Arm_relocate_functions::abs32(view, object, psymval,
                                                     thumb_bit);
       break;
 
     case elfcpp::R_ARM_ABS32_NOI:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, true,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, true, output_section))
        // No thumb bit for this relocation: (S + A)
        reloc_status = Arm_relocate_functions::abs32(view, object, psymval,
                                                     0);
       break;
 
     case elfcpp::R_ARM_MOVW_ABS_NC:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, false, output_section))
        reloc_status = Arm_relocate_functions::movw(view, object, psymval,
                                                    0, thumb_bit,
                                                    check_overflow);
       break;
 
     case elfcpp::R_ARM_MOVT_ABS:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, false, output_section))
        reloc_status = Arm_relocate_functions::movt(view, object, psymval, 0);
       break;
 
     case elfcpp::R_ARM_THM_MOVW_ABS_NC:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, false, output_section))
        reloc_status = Arm_relocate_functions::thm_movw(view, object, psymval,
                                                                0, thumb_bit, false);
       break;
 
     case elfcpp::R_ARM_THM_MOVT_ABS:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, false, output_section))
        reloc_status = Arm_relocate_functions::thm_movt(view, object,
                                                        psymval, 0);
       break;
@@ -8451,8 +9050,7 @@ Target_arm<big_endian>::Relocate::relocate(
       break;
 
     case elfcpp::R_ARM_THM_ABS5:
-      if (should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
-                                   output_section))
+      if (should_apply_static_reloc(gsym, r_type, false, output_section))
        reloc_status = Arm_relocate_functions::thm_abs5(view, object, psymval);
       break;
 
@@ -8482,13 +9080,8 @@ Target_arm<big_endian>::Relocate::relocate(
       break;
 
     case elfcpp::R_ARM_BASE_ABS:
-      {
-       if (!should_apply_static_reloc(gsym, Symbol::ABSOLUTE_REF, false,
-                                     output_section))
-         break;
-
+      if (should_apply_static_reloc(gsym, r_type, false, output_section))
        reloc_status = Arm_relocate_functions::base_abs(view, sym_origin);
-      }
       break;
 
     case elfcpp::R_ARM_GOT_BREL:
@@ -8642,8 +9235,15 @@ Target_arm<big_endian>::Relocate::relocate(
                           view, address, view_size);
       break;
 
+    // The known and unknown unsupported and/or deprecated relocations.
+    case elfcpp::R_ARM_PC24:
+    case elfcpp::R_ARM_LDR_SBREL_11_0_NC:
+    case elfcpp::R_ARM_ALU_SBREL_19_12_NC:
+    case elfcpp::R_ARM_ALU_SBREL_27_20_CK:
     default:
-      gold_unreachable();
+      // Just silently leave the method. We should get an appropriate error
+      // message in the scan methods.
+      break;
     }
 
   // Report any errors.
@@ -8910,7 +9510,7 @@ Target_arm<big_endian>::scan_relocatable_relocs(
 {
   gold_assert(sh_type == elfcpp::SHT_REL);
 
-  typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_REL,
+  typedef Arm_scan_relocatable_relocs<big_endian, elfcpp::SHT_REL,
     Relocatable_size_for_reloc> Scan_relocatable_relocs;
 
   gold::scan_relocatable_relocs<32, big_endian, elfcpp::SHT_REL,
@@ -8962,6 +9562,291 @@ Target_arm<big_endian>::relocate_for_relocatable(
     reloc_view_size);
 }
 
+// Perform target-specific processing in a relocatable link.  This is
+// only used if we use the relocation strategy RELOC_SPECIAL.
+
+template<bool big_endian>
+void
+Target_arm<big_endian>::relocate_special_relocatable(
+    const Relocate_info<32, big_endian>* relinfo,
+    unsigned int sh_type,
+    const unsigned char* preloc_in,
+    size_t relnum,
+    Output_section* output_section,
+    off_t offset_in_output_section,
+    unsigned char* view,
+    elfcpp::Elf_types<32>::Elf_Addr view_address,
+    section_size_type,
+    unsigned char* preloc_out)
+{
+  // We can only handle REL type relocation sections.
+  gold_assert(sh_type == elfcpp::SHT_REL);
+
+  typedef typename Reloc_types<elfcpp::SHT_REL, 32, big_endian>::Reloc Reltype;
+  typedef typename Reloc_types<elfcpp::SHT_REL, 32, big_endian>::Reloc_write
+    Reltype_write;
+  const Arm_address invalid_address = static_cast<Arm_address>(0) - 1;
+
+  const Arm_relobj<big_endian>* object =
+    Arm_relobj<big_endian>::as_arm_relobj(relinfo->object);
+  const unsigned int local_count = object->local_symbol_count();
+
+  Reltype reloc(preloc_in);
+  Reltype_write reloc_write(preloc_out);
+
+  elfcpp::Elf_types<32>::Elf_WXword r_info = reloc.get_r_info();
+  const unsigned int r_sym = elfcpp::elf_r_sym<32>(r_info);
+  const unsigned int r_type = elfcpp::elf_r_type<32>(r_info);
+
+  const Arm_reloc_property* arp =
+    arm_reloc_property_table->get_implemented_static_reloc_property(r_type);
+  gold_assert(arp != NULL);
+
+  // Get the new symbol index.
+  // We only use RELOC_SPECIAL strategy in local relocations.
+  gold_assert(r_sym < local_count);
+
+  // We are adjusting a section symbol.  We need to find
+  // the symbol table index of the section symbol for
+  // the output section corresponding to input section
+  // in which this symbol is defined.
+  bool is_ordinary;
+  unsigned int shndx = object->local_symbol_input_shndx(r_sym, &is_ordinary);
+  gold_assert(is_ordinary);
+  Output_section* os = object->output_section(shndx);
+  gold_assert(os != NULL);
+  gold_assert(os->needs_symtab_index());
+  unsigned int new_symndx = os->symtab_index();
+
+  // Get the new offset--the location in the output section where
+  // this relocation should be applied.
+
+  Arm_address offset = reloc.get_r_offset();
+  Arm_address new_offset;
+  if (offset_in_output_section != invalid_address)
+    new_offset = offset + offset_in_output_section;
+  else
+    {
+      section_offset_type sot_offset =
+          convert_types<section_offset_type, Arm_address>(offset);
+      section_offset_type new_sot_offset =
+          output_section->output_offset(object, relinfo->data_shndx,
+                                        sot_offset);
+      gold_assert(new_sot_offset != -1);
+      new_offset = new_sot_offset;
+    }
+
+  // In an object file, r_offset is an offset within the section.
+  // In an executable or dynamic object, generated by
+  // --emit-relocs, r_offset is an absolute address.
+  if (!parameters->options().relocatable())
+    {
+      new_offset += view_address;
+      if (offset_in_output_section != invalid_address)
+        new_offset -= offset_in_output_section;
+    }
+
+  reloc_write.put_r_offset(new_offset);
+  reloc_write.put_r_info(elfcpp::elf_r_info<32>(new_symndx, r_type));
+
+  // Handle the reloc addend.
+  // The relocation uses a section symbol in the input file.
+  // We are adjusting it to use a section symbol in the output
+  // file.  The input section symbol refers to some address in
+  // the input section.  We need the relocation in the output
+  // file to refer to that same address.  This adjustment to
+  // the addend is the same calculation we use for a simple
+  // absolute relocation for the input section symbol.
+
+  const Symbol_value<32>* psymval = object->local_symbol(r_sym);
+
+  // Handle THUMB bit.
+  Symbol_value<32> symval;
+  Arm_address thumb_bit =
+     object->local_symbol_is_thumb_function(r_sym) ? 1 : 0;
+  if (thumb_bit != 0
+      && arp->uses_thumb_bit() 
+      && ((psymval->value(object, 0) & 1) != 0))
+    {
+      Arm_address stripped_value =
+       psymval->value(object, 0) & ~static_cast<Arm_address>(1);
+      symval.set_output_value(stripped_value);
+      psymval = &symval;
+    } 
+
+  unsigned char* paddend = view + offset;
+  typename Arm_relocate_functions<big_endian>::Status reloc_status =
+       Arm_relocate_functions<big_endian>::STATUS_OKAY;
+  switch (r_type)
+    {
+    case elfcpp::R_ARM_ABS8:
+      reloc_status = Arm_relocate_functions<big_endian>::abs8(paddend, object,
+                                                             psymval);
+      break;
+
+    case elfcpp::R_ARM_ABS12:
+      reloc_status = Arm_relocate_functions<big_endian>::abs12(paddend, object,
+                                                              psymval);
+      break;
+
+    case elfcpp::R_ARM_ABS16:
+      reloc_status = Arm_relocate_functions<big_endian>::abs16(paddend, object,
+                                                              psymval);
+      break;
+
+    case elfcpp::R_ARM_THM_ABS5:
+      reloc_status = Arm_relocate_functions<big_endian>::thm_abs5(paddend,
+                                                                 object,
+                                                                 psymval);
+      break;
+
+    case elfcpp::R_ARM_MOVW_ABS_NC:
+    case elfcpp::R_ARM_MOVW_PREL_NC:
+    case elfcpp::R_ARM_MOVW_BREL_NC:
+    case elfcpp::R_ARM_MOVW_BREL:
+      reloc_status = Arm_relocate_functions<big_endian>::movw(
+         paddend, object, psymval, 0, thumb_bit, arp->checks_overflow());
+      break;
+
+    case elfcpp::R_ARM_THM_MOVW_ABS_NC:
+    case elfcpp::R_ARM_THM_MOVW_PREL_NC:
+    case elfcpp::R_ARM_THM_MOVW_BREL_NC:
+    case elfcpp::R_ARM_THM_MOVW_BREL:
+      reloc_status = Arm_relocate_functions<big_endian>::thm_movw(
+         paddend, object, psymval, 0, thumb_bit, arp->checks_overflow());
+      break;
+
+    case elfcpp::R_ARM_THM_CALL:
+    case elfcpp::R_ARM_THM_XPC22:
+    case elfcpp::R_ARM_THM_JUMP24:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::thumb_branch_common(
+           r_type, relinfo, paddend, NULL, object, 0, psymval, 0, thumb_bit,
+           false);
+      break;
+
+    case elfcpp::R_ARM_PLT32:
+    case elfcpp::R_ARM_CALL:
+    case elfcpp::R_ARM_JUMP24:
+    case elfcpp::R_ARM_XPC25:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::arm_branch_common(
+           r_type, relinfo, paddend, NULL, object, 0, psymval, 0, thumb_bit,
+           false);
+      break;
+
+    case elfcpp::R_ARM_THM_JUMP19:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::thm_jump19(paddend, object,
+                                                      psymval, 0, thumb_bit);
+      break;
+
+    case elfcpp::R_ARM_THM_JUMP6:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::thm_jump6(paddend, object, psymval,
+                                                     0);
+      break;
+
+    case elfcpp::R_ARM_THM_JUMP8:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::thm_jump8(paddend, object, psymval,
+                                                     0);
+      break;
+
+    case elfcpp::R_ARM_THM_JUMP11:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::thm_jump11(paddend, object, psymval,
+                                                      0);
+      break;
+
+    case elfcpp::R_ARM_PREL31:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::prel31(paddend, object, psymval, 0,
+                                                  thumb_bit);
+      break;
+
+    case elfcpp::R_ARM_THM_PC8:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::thm_pc8(paddend, object, psymval,
+                                                   0);
+      break;
+
+    case elfcpp::R_ARM_THM_PC12:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::thm_pc12(paddend, object, psymval,
+                                                    0);
+      break;
+
+    case elfcpp::R_ARM_THM_ALU_PREL_11_0:
+      reloc_status =
+       Arm_relocate_functions<big_endian>::thm_alu11(paddend, object, psymval,
+                                                     0, thumb_bit);
+      break;
+
+    // These relocation truncate relocation results so we cannot handle them
+    // in a relocatable link.
+    case elfcpp::R_ARM_MOVT_ABS:
+    case elfcpp::R_ARM_THM_MOVT_ABS:
+    case elfcpp::R_ARM_MOVT_PREL:
+    case elfcpp::R_ARM_MOVT_BREL:
+    case elfcpp::R_ARM_THM_MOVT_PREL:
+    case elfcpp::R_ARM_THM_MOVT_BREL:
+    case elfcpp::R_ARM_ALU_PC_G0_NC:
+    case elfcpp::R_ARM_ALU_PC_G0:
+    case elfcpp::R_ARM_ALU_PC_G1_NC:
+    case elfcpp::R_ARM_ALU_PC_G1:
+    case elfcpp::R_ARM_ALU_PC_G2:
+    case elfcpp::R_ARM_ALU_SB_G0_NC:
+    case elfcpp::R_ARM_ALU_SB_G0:
+    case elfcpp::R_ARM_ALU_SB_G1_NC:
+    case elfcpp::R_ARM_ALU_SB_G1:
+    case elfcpp::R_ARM_ALU_SB_G2:
+    case elfcpp::R_ARM_LDR_PC_G0:
+    case elfcpp::R_ARM_LDR_PC_G1:
+    case elfcpp::R_ARM_LDR_PC_G2:
+    case elfcpp::R_ARM_LDR_SB_G0:
+    case elfcpp::R_ARM_LDR_SB_G1:
+    case elfcpp::R_ARM_LDR_SB_G2:
+    case elfcpp::R_ARM_LDRS_PC_G0:
+    case elfcpp::R_ARM_LDRS_PC_G1:
+    case elfcpp::R_ARM_LDRS_PC_G2:
+    case elfcpp::R_ARM_LDRS_SB_G0:
+    case elfcpp::R_ARM_LDRS_SB_G1:
+    case elfcpp::R_ARM_LDRS_SB_G2:
+    case elfcpp::R_ARM_LDC_PC_G0:
+    case elfcpp::R_ARM_LDC_PC_G1:
+    case elfcpp::R_ARM_LDC_PC_G2:
+    case elfcpp::R_ARM_LDC_SB_G0:
+    case elfcpp::R_ARM_LDC_SB_G1:
+    case elfcpp::R_ARM_LDC_SB_G2:
+      gold_error(_("cannot handle %s in a relocatable link"),
+                arp->name().c_str());
+      break;
+
+    default:
+      gold_unreachable();
+    }
+
+  // Report any errors.
+  switch (reloc_status)
+    {
+    case Arm_relocate_functions<big_endian>::STATUS_OKAY:
+      break;
+    case Arm_relocate_functions<big_endian>::STATUS_OVERFLOW:
+      gold_error_at_location(relinfo, relnum, reloc.get_r_offset(),
+                            _("relocation overflow in %s"),
+                            arp->name().c_str());
+      break;
+    case Arm_relocate_functions<big_endian>::STATUS_BAD_RELOC:
+      gold_error_at_location(relinfo, relnum, reloc.get_r_offset(),
+       _("unexpected opcode while processing relocation %s"),
+       arp->name().c_str());
+      break;
+    default:
+      gold_unreachable();
+    }
+}
+
 // Return the value to use for a dynamic symbol which requires special
 // treatment.  This is how we support equality comparisons of function
 // pointers across shared library boundaries, as described in the
@@ -8979,7 +9864,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)
     {
@@ -8988,7 +9873,7 @@ Target_arm<big_endian>::get_real_reloc_type (unsigned int r_type)
       return elfcpp::R_ARM_ABS32;
 
     case elfcpp::R_ARM_TARGET2:
-      // This can be any reloc type but ususally is R_ARM_GOT_PREL
+      // This can be any reloc type but usually is R_ARM_GOT_PREL
       return elfcpp::R_ARM_GOT_PREL;
 
     default:
@@ -9006,7 +9891,8 @@ Target_arm<big_endian>::are_eabi_versions_compatible(
 {
   // v4 and v5 are the same spec before and after it was released,
   // so allow mixing them.
-  if ((v1 == elfcpp::EF_ARM_EABI_VER4 && v2 == elfcpp::EF_ARM_EABI_VER5)
+  if ((v1 == elfcpp::EF_ARM_EABI_UNKNOWN || v2 == elfcpp::EF_ARM_EABI_UNKNOWN)
+      || (v1 == elfcpp::EF_ARM_EABI_VER4 && v2 == elfcpp::EF_ARM_EABI_VER5)
       || (v1 == elfcpp::EF_ARM_EABI_VER5 && v2 == elfcpp::EF_ARM_EABI_VER4))
     return true;
 
@@ -9130,7 +10016,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
@@ -9156,7 +10042,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)
@@ -9295,7 +10181,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,
@@ -9363,7 +10249,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]);
@@ -9384,7 +10270,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",
@@ -9571,7 +10457,7 @@ Target_arm<big_endian>::merge_object_attributes(
                  || (out_attr[elfcpp::Tag_ABI_align8_preserved].int_value()
                      == 0)))
            {
-             // This error message should be enabled once all non-conformant
+             // This error message should be enabled once all non-conforming
              // binaries in the toolchain have had the attributes set
              // properly.
              // gold_error(_("output 8-byte data alignment conflicts with %s"),
@@ -9706,11 +10592,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 "
@@ -9731,10 +10617,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();
@@ -9748,7 +10634,7 @@ Target_arm<big_endian>::merge_object_attributes(
            }
          break;
        case elfcpp::Tag_ABI_VFP_args:
-         // Aready done.
+         // Already done.
          break;
        case elfcpp::Tag_ABI_WMMX_args:
          if (in_attr[i].int_value() != out_attr[i].int_value()
@@ -10049,7 +10935,7 @@ Target_arm<big_endian>::scan_reloc_for_stub(
     {
       // This is a global symbol.  Determine if we use PLT and if the
       // final target is THUMB.
-      if (gsym->use_plt_offset(Relocate::reloc_is_non_pic(r_type)))
+      if (gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
        {
          // This uses a PLT, change the symbol value.
          symval.set_output_value(this->plt_section()->address()
@@ -10275,6 +11161,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;
@@ -10286,45 +11174,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();
@@ -10341,9 +11237,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
@@ -10399,12 +11339,12 @@ Target_arm<big_endian>::scan_section_for_stubs(
 
 // Group input sections for stub generation.
 //
-// We goup input sections in an output sections so that the total size,
+// We group input sections in an output section so that the total size,
 // including any padding space due to alignment is smaller than GROUP_SIZE
 // unless the only input section in group is bigger than GROUP_SIZE already.
 // Then an ARM stub table is created to follow the last input section
 // in group.  For each group an ARM stub table is created an is placed
-// after the last group.  If STUB_ALWATS_AFTER_BRANCH is false, we further
+// after the last group.  If STUB_ALWAYS_AFTER_BRANCH is false, we further
 // extend the group after the stub table.
 
 template<bool big_endian>
@@ -10412,7 +11352,8 @@ void
 Target_arm<big_endian>::group_sections(
     Layout* layout,
     section_size_type group_size,
-    bool stubs_always_after_branch)
+    bool stubs_always_after_branch,
+    const Task* task)
 {
   // Group input sections and insert stub table
   Layout::Section_list section_list;
@@ -10424,7 +11365,7 @@ Target_arm<big_endian>::group_sections(
       Arm_output_section<big_endian>* output_section =
        Arm_output_section<big_endian>::as_arm_output_section(*p);
       output_section->group_sections(group_size, stubs_always_after_branch,
-                                    this);
+                                    this, task);
     }
 }
 
@@ -10436,7 +11377,8 @@ Target_arm<big_endian>::do_relax(
     int pass,
     const Input_objects* input_objects,
     Symbol_table* symtab,
-    Layout* layout)
+    Layout* layout,
+    const Task* task)
 {
   // No need to generate stubs if this is a relocatable link.
   gold_assert(!parameters->options().relocatable());
@@ -10444,23 +11386,18 @@ Target_arm<big_endian>::do_relax(
   // If this is the first pass, we need to group input sections into
   // stub groups.
   bool done_exidx_fixup = false;
+  typedef typename Stub_table_list::iterator Stub_table_iterator;
   if (pass == 1)
     {
       // Determine the stub group size.  The group size is the absolute
       // value of the parameter --stub-group-size.  If --stub-group-size
-      // is passed a negative value, we restict stubs to be always after
+      // is passed a negative value, we restrict stubs to be always after
       // the stubbed branches.
       int32_t stub_group_size_param =
        parameters->options().stub_group_size();
       bool stubs_always_after_branch = stub_group_size_param < 0;
       section_size_type stub_group_size = abs(stub_group_size_param);
 
-      // The Cortex-A8 erratum fix depends on stubs not being in the same 4K
-      // page as the first half of a 32-bit branch straddling two 4K pages.
-      // This is a crude way of enforcing that.
-      if (this->fix_cortex_a8_)
-       stubs_always_after_branch = true;
-
       if (stub_group_size == 1)
        {
          // Default value.
@@ -10470,35 +11407,75 @@ Target_arm<big_endian>::do_relax(
          // fixing cortex-a8 errata, the branch range has to be even smaller,
          // since wide conditional branch has a range of +-1MB only.
          //
-         // This value is 24K less than that, which allows for 2025
+         // This value is 48K less than that, which allows for 4096
          // 12-byte stubs.  If we exceed that, then we will fail to link.
          // The user will have to relink with an explicit group size
          // option.
-         if (this->fix_cortex_a8_)
-           stub_group_size = 1024276;
-         else
-           stub_group_size = 4170000;
+           stub_group_size = 4145152;
+       }
+
+      // The Cortex-A8 erratum fix depends on stubs not being in the same 4K
+      // page as the first half of a 32-bit branch straddling two 4K pages.
+      // This is a crude way of enforcing that.  In addition, long conditional
+      // branches of THUMB-2 have a range of +-1M.  If we are fixing cortex-A8
+      // erratum, limit the group size to  (1M - 12k) to avoid unreachable
+      // cortex-A8 stubs from long conditional branches.
+      if (this->fix_cortex_a8_)
+       {
+         stubs_always_after_branch = true;
+         const section_size_type cortex_a8_group_size = 1024 * (1024 - 12);
+         stub_group_size = std::max(stub_group_size, cortex_a8_group_size);
        }
 
-      group_sections(layout, stub_group_size, stubs_always_after_branch);
+      group_sections(layout, stub_group_size, stubs_always_after_branch, task);
      
       // Also fix .ARM.exidx section coverage.
-      Output_section* os = layout->find_output_section(".ARM.exidx");
-      if (os != NULL && os->type() == elfcpp::SHT_ARM_EXIDX)
+      Arm_output_section<big_endian>* exidx_output_section = NULL;
+      for (Layout::Section_list::const_iterator p =
+            layout->section_list().begin();
+          p != layout->section_list().end();
+          ++p)
+       if ((*p)->type() == elfcpp::SHT_ARM_EXIDX)
+         {
+           if (exidx_output_section == NULL)
+             exidx_output_section =
+               Arm_output_section<big_endian>::as_arm_output_section(*p);
+           else
+             // We cannot handle this now.
+             gold_error(_("multiple SHT_ARM_EXIDX sections %s and %s in a "
+                          "non-relocatable link"),
+                         exidx_output_section->name(),
+                         (*p)->name());
+         }
+
+      if (exidx_output_section != NULL)
        {
-         Arm_output_section<big_endian>* exidx_output_section =
-           Arm_output_section<big_endian>::as_arm_output_section(os);
-         this->fix_exidx_coverage(layout, exidx_output_section, symtab);
+         this->fix_exidx_coverage(layout, input_objects, exidx_output_section,
+                                  symtab, task);
          done_exidx_fixup = true;
        }
     }
+  else
+    {
+      // If this is not the first pass, addresses and file offsets have
+      // been reset at this point, set them here.
+      for (Stub_table_iterator sp = this->stub_tables_.begin();
+          sp != this->stub_tables_.end();
+          ++sp)
+       {
+         Arm_input_section<big_endian>* owner = (*sp)->owner();
+         off_t off = align_address(owner->original_size(),
+                                   (*sp)->addralign());
+         (*sp)->set_address_and_file_offset(owner->address() + off,
+                                            owner->offset() + off);
+       }
+    }
 
   // The Cortex-A8 stubs are sensitive to layout of code sections.  At the
   // beginning of each relaxation pass, just blow away all the stubs.
   // Alternatively, we could selectively remove only the stubs and reloc
   // information for code sections that have moved since the last pass.
   // That would require more book-keeping.
-  typedef typename Stub_table_list::iterator Stub_table_iterator;
   if (this->fix_cortex_a8_)
     {
       // Clear all Cortex-A8 reloc information.
@@ -10523,6 +11500,9 @@ Target_arm<big_endian>::do_relax(
     {
       Arm_relobj<big_endian>* arm_relobj =
        Arm_relobj<big_endian>::as_arm_relobj(*op);
+      // Lock the object so we can read from it.  This is only called
+      // single-threaded from Layout::finalize, so it is OK to lock.
+      Task_lock_obj<Object> tl(task, arm_relobj);
       arm_relobj->scan_sections_for_stubs(this, symtab, layout);
     }
 
@@ -10553,7 +11533,7 @@ Target_arm<big_endian>::do_relax(
   // need to update output sections, so we record all output sections needing
   // update above and scan the sections here to find out what sections need
   // to be updated.
-  for(Layout::Section_list::const_iterator p = layout->section_list().begin();
+  for (Layout::Section_list::const_iterator p = layout->section_list().begin();
       p != layout->section_list().end();
       ++p)
     {
@@ -10585,7 +11565,11 @@ Target_arm<big_endian>::do_relax(
          // symbols defined in parts of input sections that are discarded by
          // relaxation.
          if (arm_relobj->output_local_symbol_count_needs_update())
-           arm_relobj->update_output_local_symbol_count();
+           {
+             // We need to lock the object's file to update it.
+             Task_lock_obj<Object> tl(task, arm_relobj);
+             arm_relobj->update_output_local_symbol_count();
+           }
        }
     }
 
@@ -10673,7 +11657,7 @@ Target_arm<big_endian>::do_attributes_order(int num) const
 {
   // Reorder the known object attributes in output.  We want to move
   // Tag_conformance to position 4 and Tag_conformance to position 5
-  // and shift eveything between 4 .. Tag_conformance - 1 to make room.
+  // and shift everything between 4 .. Tag_conformance - 1 to make room.
   if (num == 4)
     return elfcpp::Tag_conformance;
   if (num == 5)
@@ -10875,13 +11859,11 @@ Target_arm<big_endian>::apply_cortex_a8_workaround(
   switch (stub->stub_template()->type())
     {
     case arm_stub_a8_veneer_b_cond:
-      gold_assert(!utils::has_overflow<21>(branch_offset));
-      upper_insn = RelocFuncs::thumb32_cond_branch_upper(upper_insn,
-                                                        branch_offset);
-      lower_insn = RelocFuncs::thumb32_cond_branch_lower(lower_insn,
-                                                        branch_offset);
-      break;
-
+      // For a conditional branch, we re-write it to be an unconditional
+      // branch to the stub.  We use the THUMB-2 encoding here.
+      upper_insn = 0xf000U;
+      lower_insn = 0xb800U;
+      // Fall through
     case arm_stub_a8_veneer_b:
     case arm_stub_a8_veneer_bl:
     case arm_stub_a8_veneer_blx:
@@ -10927,8 +11909,10 @@ template<bool big_endian>
 void
 Target_arm<big_endian>::fix_exidx_coverage(
     Layout* layout,
+    const Input_objects* input_objects,
     Arm_output_section<big_endian>* exidx_section,
-    Symbol_table* symtab)
+    Symbol_table* symtab,
+    const Task* task)
 {
   // We need to look at all the input sections in output in ascending
   // order of of output address.  We do that by building a sorted list
@@ -10939,22 +11923,37 @@ Target_arm<big_endian>::fix_exidx_coverage(
   typedef std::set<Output_section*, output_section_address_less_than>
       Sorted_output_section_list;
   Sorted_output_section_list sorted_output_sections;
-  Layout::Section_list section_list;
-  layout->get_allocated_sections(&section_list);
-  for (Layout::Section_list::const_iterator p = section_list.begin();
-       p != section_list.end();
+
+  // Find out all the output sections of input sections pointed by
+  // EXIDX input sections.
+  for (Input_objects::Relobj_iterator p = input_objects->relobj_begin();
+       p != input_objects->relobj_end();
        ++p)
     {
-      // We only care about output sections that contain executable code.
-      if (((*p)->flags() & elfcpp::SHF_EXECINSTR) != 0)
-       sorted_output_sections.insert(*p);
+      Arm_relobj<big_endian>* arm_relobj =
+       Arm_relobj<big_endian>::as_arm_relobj(*p);
+      std::vector<unsigned int> shndx_list;
+      arm_relobj->get_exidx_shndx_list(&shndx_list);
+      for (size_t i = 0; i < shndx_list.size(); ++i)
+       {
+         const Arm_exidx_input_section* exidx_input_section =
+           arm_relobj->exidx_input_section_by_shndx(shndx_list[i]);
+         gold_assert(exidx_input_section != NULL);
+         if (!exidx_input_section->has_errors())
+           {
+             unsigned int text_shndx = exidx_input_section->link();
+             Output_section* os = arm_relobj->output_section(text_shndx);
+             if (os != NULL && (os->flags() & elfcpp::SHF_ALLOC) != 0)
+               sorted_output_sections.insert(os);
+           }
+       }
     }
 
   // Go over the output sections in ascending order of output addresses.
   typedef typename Arm_output_section<big_endian>::Text_section_list
       Text_section_list;
   Text_section_list sorted_text_sections;
-  for(typename Sorted_output_section_list::iterator p =
+  for (typename Sorted_output_section_list::iterator p =
        sorted_output_sections.begin();
       p != sorted_output_sections.end();
       ++p)
@@ -10965,7 +11964,7 @@ Target_arm<big_endian>::fix_exidx_coverage(
     } 
 
   exidx_section->fix_exidx_coverage(layout, sorted_text_sections, symtab,
-                                   merge_exidx_entries());
+                                   merge_exidx_entries(), task);
 }
 
 Target_selector_arm<false> target_selector_arm;