* i386.cc (class Output_data_plt_i386): Add layout_ field.
authorIan Lance Taylor <ian@airs.com>
Fri, 15 Jul 2011 15:31:54 +0000 (15:31 +0000)
committerIan Lance Taylor <ian@airs.com>
Fri, 15 Jul 2011 15:31:54 +0000 (15:31 +0000)
(Output_data_plt_i386::Output_data_plt_i386): Initialize layout_.
(Output_data_plt_i386::do_write): Write address of .dynamic
section to first entry in .got.plt section.
* x86_64.cc (class Output_data_plt_x86_64): Add layout_ field.
(Output_data_plt_x86_64::Output_data_plt_x86_64) [both versions]:
Initialize layout_.
(Output_data_plt_x86_64::do_write): Write address of .dynamic
section to first entry in .got.plt section.
* layout.h (Layout::dynamic_section): New function.

gold/ChangeLog
gold/i386.cc
gold/layout.h
gold/x86_64.cc

index 69a4c59c522ed4a9a583c902fe991b086bd99a73..98346b64674534fab1590ee89ce5d7d1ab6dbdbe 100644 (file)
@@ -1,3 +1,16 @@
+2011-07-15  Ian Lance Taylor  <iant@google.com>
+
+       * i386.cc (class Output_data_plt_i386): Add layout_ field.
+       (Output_data_plt_i386::Output_data_plt_i386): Initialize layout_.
+       (Output_data_plt_i386::do_write): Write address of .dynamic
+       section to first entry in .got.plt section.
+       * x86_64.cc (class Output_data_plt_x86_64): Add layout_ field.
+       (Output_data_plt_x86_64::Output_data_plt_x86_64) [both versions]:
+       Initialize layout_.
+       (Output_data_plt_x86_64::do_write): Write address of .dynamic
+       section to first entry in .got.plt section.
+       * layout.h (Layout::dynamic_section): New function.
+
 2011-07-13  Sriraman Tallam  <tmsriram@google.com>
 
        * archive.cc (Archive::get_elf_object_for_member): Add extra parameter
index 7e982d549743225ded1c4d63acf94e8f4ed87e8b..445bc68a940127bb70fc1dc9084f6d73cca9bc75 100644 (file)
@@ -166,6 +166,9 @@ class Output_data_plt_i386 : public Output_section_data
     unsigned int got_offset;
   };
 
+  // A pointer to the Layout class, so that we can find the .dynamic
+  // section when we write out the GOT PLT section.
+  Layout* layout_;
   // The reloc section.
   Reloc_section* rel_;
   // The TLS_DESC relocations, if necessary.  These must follow the
@@ -822,9 +825,9 @@ Target_i386::rel_irelative_section(Layout* layout)
 Output_data_plt_i386::Output_data_plt_i386(Layout* layout,
                                           Output_data_space* got_plt,
                                           Output_data_space* got_irelative)
-  : Output_section_data(16), tls_desc_rel_(NULL), irelative_rel_(NULL),
-    got_plt_(got_plt), got_irelative_(got_irelative), count_(0),
-    irelative_count_(0), global_ifuncs_(), local_ifuncs_()
+  : Output_section_data(16), layout_(layout), tls_desc_rel_(NULL),
+    irelative_rel_(NULL), got_plt_(got_plt), got_irelative_(got_irelative),
+    count_(0), irelative_count_(0), global_ifuncs_(), local_ifuncs_()
 {
   this->rel_ = new Reloc_section(false);
   layout->add_output_section_data(".rel.plt", elfcpp::SHT_REL,
@@ -1138,8 +1141,16 @@ Output_data_plt_i386::do_write(Output_file* of)
 
   unsigned char* got_pov = got_view;
 
-  memset(got_pov, 0, 12);
-  got_pov += 12;
+  // The first entry in the GOT is the address of the .dynamic section
+  // aka the PT_DYNAMIC segment.  The next two entries are reserved.
+  // We saved space for them when we created the section in
+  // Target_i386::got_section.
+  Output_section* dynamic = this->layout_->dynamic_section();
+  uint32_t dynamic_addr = dynamic == NULL ? 0 : dynamic->address();
+  elfcpp::Swap<32, false>::writeval(got_pov, dynamic_addr);
+  got_pov += 4;
+  memset(got_pov, 0, 8);
+  got_pov += 8;
 
   const int rel_size = elfcpp::Elf_sizes<32>::rel_size;
 
index f2c170b988aad5906587d6907648aadb42e44a7b..1497f12d77381495a8f2ad7b874dc17a9cf720c4 100644 (file)
@@ -627,6 +627,12 @@ class Layout
   dynpool() const
   { return &this->dynpool_; }
 
+  // Return the .dynamic output section.  This is only valid after the
+  // layout has been finalized.
+  Output_section*
+  dynamic_section() const
+  { return this->dynamic_section_; }
+
   // Return the symtab_xindex section used to hold large section
   // indexes for the normal symbol table.
   Output_symtab_xindex*
index 4025527b40353516d0ea59d69c396059a1c296f3..e6b00210762f3effb40adda27e070c9326daa448 100644 (file)
@@ -57,9 +57,10 @@ class Output_data_plt_x86_64 : public Output_section_data
   Output_data_plt_x86_64(Layout* layout, Output_data_got<64, false>* got,
                         Output_data_space* got_plt,
                         Output_data_space* got_irelative)
-    : Output_section_data(16), tlsdesc_rel_(NULL), irelative_rel_(NULL),
-      got_(got), got_plt_(got_plt), got_irelative_(got_irelative), count_(0),
-      irelative_count_(0), tlsdesc_got_offset_(-1U), free_list_()
+    : Output_section_data(16), layout_(layout), tlsdesc_rel_(NULL),
+      irelative_rel_(NULL), got_(got), got_plt_(got_plt),
+      got_irelative_(got_irelative), count_(0), irelative_count_(0),
+      tlsdesc_got_offset_(-1U), free_list_()
   { this->init(layout); }
 
   Output_data_plt_x86_64(Layout* layout, Output_data_got<64, false>* got,
@@ -67,9 +68,9 @@ class Output_data_plt_x86_64 : public Output_section_data
                         Output_data_space* got_irelative,
                         unsigned int plt_count)
     : Output_section_data((plt_count + 1) * plt_entry_size, 16, false),
-      tlsdesc_rel_(NULL), irelative_rel_(NULL), got_(got), got_plt_(got_plt),
-      got_irelative_(got_irelative), count_(plt_count), irelative_count_(0),
-      tlsdesc_got_offset_(-1U), free_list_()
+      layout_(layout), tlsdesc_rel_(NULL), irelative_rel_(NULL), got_(got),
+      got_plt_(got_plt), got_irelative_(got_irelative), count_(plt_count),
+      irelative_count_(0), tlsdesc_got_offset_(-1U), free_list_()
   {
     this->init(layout);
 
@@ -205,6 +206,9 @@ class Output_data_plt_x86_64 : public Output_section_data
   void
   do_write(Output_file*);
 
+  // A pointer to the Layout class, so that we can find the .dynamic
+  // section when we write out the GOT PLT section.
+  Layout* layout_;
   // The reloc section.
   Reloc_section* rel_;
   // The TLSDESC relocs, if necessary.  These must follow the regular
@@ -1306,8 +1310,16 @@ Output_data_plt_x86_64::do_write(Output_file* of)
 
   unsigned char* got_pov = got_view;
 
-  memset(got_pov, 0, 24);
-  got_pov += 24;
+  // The first entry in the GOT is the address of the .dynamic section
+  // aka the PT_DYNAMIC segment.  The next two entries are reserved.
+  // We saved space for them when we created the section in
+  // Target_x86_64::got_section.
+  Output_section* dynamic = this->layout_->dynamic_section();
+  uint32_t dynamic_addr = dynamic == NULL ? 0 : dynamic->address();
+  elfcpp::Swap<64, false>::writeval(got_pov, dynamic_addr);
+  got_pov += 8;
+  memset(got_pov, 0, 16);
+  got_pov += 16;
 
   unsigned int plt_offset = plt_entry_size;
   unsigned int got_offset = 24;