Update copyright in comments to 2011.
[deliverable/binutils-gdb.git] / gold / copy-relocs.cc
index 3df50c8c67de3d45a0452bac67b5d828b6ef066c..4931aa06b659c1694d929a21433a951b2240322e 100644 (file)
@@ -1,6 +1,6 @@
 // copy-relocs.cc -- handle COPY relocations for gold.
 
-// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -58,9 +58,9 @@ Copy_relocs<sh_type, size, big_endian>::copy_reloc(
     Symbol_table* symtab,
     Layout* layout,
     Sized_symbol<size>* sym,
-    Relobj* object,
+    Sized_relobj<size, big_endian>* object,
     unsigned int shndx,
-    Output_section *output_section,
+    Output_sectionoutput_section,
     const Reloc& rel,
     Output_data_reloc<sh_type, true, size, big_endian>* reloc_section)
 {
@@ -81,10 +81,11 @@ template<int sh_type, int size, bool big_endian>
 bool
 Copy_relocs<sh_type, size, big_endian>::need_copy_reloc(
     Sized_symbol<size>* sym,
-    Relobj* object,
+    Sized_relobj<size, big_endian>* object,
     unsigned int shndx) const
 {
-  // FIXME: Handle -z nocopyrelocs.
+  if (!parameters->options().copyreloc())
+    return false;
 
   if (sym->symsize() == 0)
     return false;
@@ -109,6 +110,9 @@ Copy_relocs<sh_type, size, big_endian>::emit_copy_reloc(
     Sized_symbol<size>* sym,
     Output_data_reloc<sh_type, true, size, big_endian>* reloc_section)
 {
+  // We should not be here if -z nocopyreloc is given.
+  gold_assert(parameters->options().copyreloc());
+
   typename elfcpp::Elf_types<size>::Elf_WXword symsize = sym->symsize();
 
   // There is no defined way to determine the required alignment of
@@ -121,20 +125,32 @@ Copy_relocs<sh_type, size, big_endian>::emit_copy_reloc(
   bool is_ordinary;
   unsigned int shndx = sym->shndx(&is_ordinary);
   gold_assert(is_ordinary);
-  typename elfcpp::Elf_types<size>::Elf_WXword addralign =
-    sym->object()->section_addralign(shndx);
+  typename elfcpp::Elf_types<size>::Elf_WXword addralign;
+
+  {
+    // Lock the object so we can read from it.  This is only called
+    // single-threaded from scan_relocs, so it is OK to lock.
+    // Unfortunately we have no way to pass in a Task token.
+    const Task* dummy_task = reinterpret_cast<const Task*>(-1);
+    Object* obj = sym->object();
+    Task_lock_obj<Object> tl(dummy_task, obj);
+    addralign = obj->section_addralign(shndx);
+  }
 
   typename Sized_symbol<size>::Value_type value = sym->value();
   while ((value & (addralign - 1)) != 0)
     addralign >>= 1;
 
+  // Mark the dynamic object as needed for the --as-needed option.
+  sym->object()->set_is_needed();
+
   if (this->dynbss_ == NULL)
     {
-      this->dynbss_ = new Output_data_space(addralign);
+      this->dynbss_ = new Output_data_space(addralign, "** dynbss");
       layout->add_output_section_data(".bss",
                                      elfcpp::SHT_NOBITS,
                                      elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
-                                     this->dynbss_);
+                                     this->dynbss_, ORDER_BSS, false);
     }
 
   Output_data_space* dynbss = this->dynbss_;
@@ -172,10 +188,12 @@ Copy_relocs<sh_type, size, big_endian>::add_copy_reloc(
 
 template<int sh_type, int size, bool big_endian>
 void
-Copy_relocs<sh_type, size, big_endian>::save(Symbol* sym, Relobj* object,
-                                            unsigned int shndx,
-                                            Output_section* output_section,
-                                            const Reloc& rel)
+Copy_relocs<sh_type, size, big_endian>::save(
+    Symbol* sym,
+    Sized_relobj<size, big_endian>* object,
+    unsigned int shndx,
+    Output_section* output_section,
+    const Reloc& rel)
 {
   unsigned int reloc_type = elfcpp::elf_r_type<size>(rel.get_r_info());
   typename elfcpp::Elf_types<size>::Elf_Addr addend =
This page took 0.031755 seconds and 4 git commands to generate.