Support --hash-style=gnu.
authorIan Lance Taylor <iant@google.com>
Thu, 6 Mar 2008 00:15:04 +0000 (00:15 +0000)
committerIan Lance Taylor <iant@google.com>
Thu, 6 Mar 2008 00:15:04 +0000 (00:15 +0000)
elfcpp/elfcpp.h
gold/layout.cc
gold/options.h

index 64f7c6c2d11351184620f4274c1a7a8014174ec0..dae043469992351b1b4599e00ed166b51b61c617 100644 (file)
@@ -346,6 +346,10 @@ enum SHT
   SHT_LOUSER = 0x80000000,
   SHT_HIUSER = 0xffffffff,
   // The remaining values are not in the standard.
+  // Object attributes.
+  SHT_GNU_ATTRIBUTES = 0x6ffffff5,
+  // GNU style dynamic hash table.
+  SHT_GNU_HASH = 0x6ffffff6,
   // List of prelink dependencies.
   SHT_GNU_LIBLIST = 0x6ffffff7,
   // Versions defined by file.
index 1591cfb5c9a5bdf0e20699ef4a0f862c97ae5b1f..124d3bcafefa41a50000b7f115d91977ce4add67 100644 (file)
@@ -1924,27 +1924,53 @@ Layout::create_dynamic_symtab(const Input_objects* input_objects,
 
   // Create the hash tables.
 
-  // FIXME: We need an option to create a GNU hash table.
+  if (strcmp(parameters->options().hash_style(), "sysv") == 0
+      || strcmp(parameters->options().hash_style(), "both") == 0)
+    {
+      unsigned char* phash;
+      unsigned int hashlen;
+      Dynobj::create_elf_hash_table(*pdynamic_symbols, local_symcount,
+                                   &phash, &hashlen);
+
+      Output_section* hashsec = this->choose_output_section(NULL, ".hash",
+                                                           elfcpp::SHT_HASH,
+                                                           elfcpp::SHF_ALLOC,
+                                                           false);
+
+      Output_section_data* hashdata = new Output_data_const_buffer(phash,
+                                                                  hashlen,
+                                                                  align);
+      hashsec->add_output_section_data(hashdata);
+
+      hashsec->set_link_section(dynsym);
+      hashsec->set_entsize(4);
 
-  unsigned char* phash;
-  unsigned int hashlen;
-  Dynobj::create_elf_hash_table(*pdynamic_symbols, local_symcount,
-                               &phash, &hashlen);
+      odyn->add_section_address(elfcpp::DT_HASH, hashsec);
+    }
+
+  if (strcmp(parameters->options().hash_style(), "gnu") == 0
+      || strcmp(parameters->options().hash_style(), "both") == 0)
+    {
+      unsigned char* phash;
+      unsigned int hashlen;
+      Dynobj::create_gnu_hash_table(*pdynamic_symbols, local_symcount,
+                                   &phash, &hashlen);
 
-  Output_section* hashsec = this->choose_output_section(NULL, ".hash",
-                                                       elfcpp::SHT_HASH,
-                                                       elfcpp::SHF_ALLOC,
-                                                       false);
+      Output_section* hashsec = this->choose_output_section(NULL, ".gnu.hash",
+                                                           elfcpp::SHT_GNU_HASH,
+                                                           elfcpp::SHF_ALLOC,
+                                                           false);
 
-  Output_section_data* hashdata = new Output_data_const_buffer(phash,
-                                                              hashlen,
-                                                              align);
-  hashsec->add_output_section_data(hashdata);
+      Output_section_data* hashdata = new Output_data_const_buffer(phash,
+                                                                  hashlen,
+                                                                  align);
+      hashsec->add_output_section_data(hashdata);
 
-  hashsec->set_link_section(dynsym);
-  hashsec->set_entsize(4);
+      hashsec->set_link_section(dynsym);
+      hashsec->set_entsize(4);
 
-  odyn->add_section_address(elfcpp::DT_HASH, hashsec);
+      odyn->add_section_address(elfcpp::DT_GNU_HASH, hashsec);
+    }
 }
 
 // Assign offsets to each local portion of the dynamic symbol table.
index 30ffb8c5468703d89e16abd248c0b84a2588d4db..7f5a561130240b537365b32ec83bc0379706f7c3 100644 (file)
@@ -465,6 +465,10 @@ class General_options
   DEFINE_string(soname, options::ONE_DASH, 'h', NULL,
                 _("Set shared library name"), _("FILENAME"));
 
+  DEFINE_enum(hash_style, options::TWO_DASHES, '\0', "sysv",
+             _("Dynamic hash style"), _("[sysv,gnu,both]"),
+             {"sysv", "gnu", "both"});
+
   DEFINE_string(dynamic_linker, options::TWO_DASHES, 'I', NULL,
                 _("Set dynamic linker path"), _("PROGRAM"));