This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Use unaligned access on x86_64


> P.S.: I just tried it on gcc-112 (powerpc64le) and it looks like
> unaligned is also a win there
>
> from
>
> 2.354317085 seconds time elapsed
>    ( +-  1.35% )
>
> to
>
>  2.246461651 seconds time elapsed
>     ( +-  0.18% )

This got me thinking that it might be better to just use valid
unaligned access everywhere.

To make sure I didn't break architectures with strict alignment, I
started by building gold with -fsanitize=alignment.

This found that even current master doesn't always align correctly.
The backtrace of the first bug is attached.

The attached patch is a basic work in progress of what the final
version would look like. It is enough to build clang with no invalid
unaligned reads (relocation processing still has unaligned writes).

The net result is

* Architectures with fast unaligned access get faster.
* Architectures with strict alignment now at least work.
* Architectures with slow unaligned access might get slower, but not
sure if there is any.

Cheers,
Rafael

Attachment: bt
Description: Binary data

diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h
index 722984e..8060200 100644
--- a/elfcpp/elfcpp.h
+++ b/elfcpp/elfcpp.h
@@ -1027,6 +1027,16 @@ struct Elf_sizes
 
 // Accessor class for the ELF file header.
 
+#define FOO(RT, M)                                                             \
+  {                                                                            \
+    typedef RT R_type;                                                         \
+    const R_type *p = reinterpret_cast<const R_type *>(                        \
+        reinterpret_cast<const char *>(this->p_) + offsetof(P_type, M));       \
+    R_type t;                                                                  \
+    memcpy(&t, p, sizeof(t));                                                  \
+    return Convert<size, big_endian>::convert_host(t);                         \
+  }
+
 template<int size, bool big_endian>
 class Ehdr
 {
@@ -1043,15 +1053,19 @@ class Ehdr
 
   const unsigned char*
   get_e_ident() const
-  { return this->p_->e_ident; }
+  {
+    const unsigned char *p = reinterpret_cast<const unsigned char *>(this->p_) +
+                             offsetof(P_type, e_ident);
+    return p;
+  }
 
   Elf_Half
   get_e_type() const
-  { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
+  { FOO(Elf_Half, e_type); }
 
   Elf_Half
   get_e_machine() const
-  { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
+  { FOO(Elf_Half, e_machine); }
 
   Elf_Word
   get_e_version() const
@@ -1067,7 +1081,7 @@ class Ehdr
 
   typename Elf_types<size>::Elf_Off
   get_e_shoff() const
-  { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
+  { FOO(typename Elf_types<size>::Elf_Off, e_shoff); }
 
   Elf_Word
   get_e_flags() const
@@ -1075,7 +1089,7 @@ class Ehdr
 
   Elf_Half
   get_e_ehsize() const
-  { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
+  { FOO(Elf_Half, e_ehsize); }
 
   Elf_Half
   get_e_phentsize() const
@@ -1087,18 +1101,19 @@ class Ehdr
 
   Elf_Half
   get_e_shentsize() const
-  { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
+  { FOO(Elf_Half, e_shentsize); }
 
   Elf_Half
   get_e_shnum() const
-  { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
+  { FOO(Elf_Half, e_shnum); }
 
   Elf_Half
   get_e_shstrndx() const
-  { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
+  { FOO(Elf_Half, e_shstrndx); }
 
  private:
-  const internal::Ehdr_data<size>* p_;
+  typedef internal::Ehdr_data<size> P_type;
+  const P_type* p_;
 };
 
 // Write class for the ELF file header.
@@ -1189,15 +1204,15 @@ class Shdr
 
   Elf_Word
   get_sh_name() const
-  { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
+  { FOO(Elf_Word, sh_name); }
 
   Elf_Word
   get_sh_type() const
-  { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
+  { FOO(Elf_Word, sh_type); }
 
   typename Elf_types<size>::Elf_WXword
   get_sh_flags() const
-  { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
+  { FOO(typename Elf_types<size>::Elf_WXword, sh_flags); }
 
   typename Elf_types<size>::Elf_Addr
   get_sh_addr() const
@@ -1205,19 +1220,19 @@ class Shdr
 
   typename Elf_types<size>::Elf_Off
   get_sh_offset() const
-  { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
+  { FOO(typename Elf_types<size>::Elf_Off, sh_offset); }
 
   typename Elf_types<size>::Elf_WXword
   get_sh_size() const
-  { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
+  { FOO(typename Elf_types<size>::Elf_WXword, sh_size);  }
 
   Elf_Word
   get_sh_link() const
-  { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
+  { FOO(Elf_Word, sh_link); }
 
   Elf_Word
   get_sh_info() const
-  { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
+  { FOO(Elf_Word, sh_info); }
 
   typename Elf_types<size>::Elf_WXword
   get_sh_addralign() const
@@ -1226,10 +1241,11 @@ class Shdr
 
   typename Elf_types<size>::Elf_WXword
   get_sh_entsize() const
-  { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
+  { FOO(typename Elf_types<size>::Elf_WXword, sh_entsize); }
 
  private:
-  const internal::Shdr_data<size>* p_;
+  typedef internal::Shdr_data<size> P_type;
+  const P_type* p_;
 };
 
 // Write class for an ELF section header.
@@ -1461,19 +1477,23 @@ class Sym
 
   Elf_Word
   get_st_name() const
-  { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
+  { FOO(Elf_Word, st_name); }
 
   typename Elf_types<size>::Elf_Addr
   get_st_value() const
-  { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
+  { FOO(typename Elf_types<size>::Elf_Addr, st_value); }
 
   typename Elf_types<size>::Elf_WXword
   get_st_size() const
-  { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
+  { FOO(typename Elf_types<size>::Elf_WXword, st_size); }
 
   unsigned char
   get_st_info() const
-  { return this->p_->st_info; }
+  {
+    const unsigned char *p = reinterpret_cast<const unsigned char *>(this->p_) +
+                             offsetof(P_type, st_info);
+    return *p;
+  }
 
   STB
   get_st_bind() const
@@ -1485,7 +1505,11 @@ class Sym
 
   unsigned char
   get_st_other() const
-  { return this->p_->st_other; }
+  {
+    const unsigned char *p = reinterpret_cast<const unsigned char *>(this->p_) +
+                             offsetof(P_type, st_other);
+    return *p;
+  }
 
   STV
   get_st_visibility() const
@@ -1497,10 +1521,11 @@ class Sym
 
   Elf_Half
   get_st_shndx() const
-  { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
+  { FOO(Elf_Half, st_shndx); }
 
  private:
-  const internal::Sym_data<size>* p_;
+  typedef internal::Sym_data<size> P_type;
+  const P_type* p_;
 };
 
 // Writer class for an ELF symbol table entry.
@@ -1571,14 +1596,15 @@ class Rel
 
   typename Elf_types<size>::Elf_Addr
   get_r_offset() const
-  { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
+  { FOO(typename Elf_types<size>::Elf_Addr, r_offset); }
 
   typename Elf_types<size>::Elf_WXword
   get_r_info() const
-  { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
+  { FOO(typename Elf_types<size>::Elf_WXword, r_info); }
 
  private:
-  const internal::Rel_data<size>* p_;
+  typedef internal::Rel_data<size> P_type;
+  const P_type* p_;
 };
 
 // Writer class for an ELF Rel relocation.
@@ -1621,18 +1647,19 @@ class Rela
 
   typename Elf_types<size>::Elf_Addr
   get_r_offset() const
-  { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
+  { FOO(typename Elf_types<size>::Elf_Addr, r_offset); }
 
   typename Elf_types<size>::Elf_WXword
   get_r_info() const
-  { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
+  { FOO(typename Elf_types<size>::Elf_WXword, r_info); }
 
   typename Elf_types<size>::Elf_Swxword
   get_r_addend() const
-  { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
+  { FOO(typename Elf_types<size>::Elf_Swxword, r_addend); }
 
  private:
-  const internal::Rela_data<size>* p_;
+  typedef internal::Rela_data<size> P_type;
+  const P_type* p_;
 };
 
 // Writer class for an ELF Rela relocation.
diff --git a/elfcpp/elfcpp_swap.h b/elfcpp/elfcpp_swap.h
index 5b9a915..c885e6b 100644
--- a/elfcpp/elfcpp_swap.h
+++ b/elfcpp/elfcpp_swap.h
@@ -230,7 +230,11 @@ struct Swap
 
   static inline Valtype
   readval(const Valtype* wv)
-  { return Convert<size, big_endian>::convert_host(*wv); }
+  {
+    Valtype t;
+    memcpy(&t, wv, sizeof(t));
+    return Convert<size, big_endian>::convert_host(t);
+  }
 
   static inline void
   writeval(Valtype* wv, Valtype v)
diff --git a/gold/aarch64.cc b/gold/aarch64.cc
index 2745776..f5e9487 100644
--- a/gold/aarch64.cc
+++ b/gold/aarch64.cc
@@ -1300,7 +1300,7 @@ AArch64_relobj<size, big_endian>::do_count_local_symbols(
   gold_assert(loccount == symtabshdr.get_sh_info());
   off_t locsize = loccount * sym_size;
   const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
-					      locsize, true, true);
+					      locsize, true);
 
   // For mapping symbol processing, we need to read the symbol names.
   unsigned int strtab_shndx = this->adjust_shndx(symtabshdr.get_sh_link());
@@ -1322,7 +1322,7 @@ AArch64_relobj<size, big_endian>::do_count_local_symbols(
   const char* pnames =
     reinterpret_cast<const char*>(this->get_view(strtabshdr.get_sh_offset(),
 						 strtabshdr.get_sh_size(),
-						 false, false));
+						 false));
 
   // Skip the first dummy symbol.
   psyms += sym_size;
@@ -1571,8 +1571,7 @@ AArch64_relobj<size, big_endian>::scan_sections_for_stubs(
 
   // Read the section headers.
   const unsigned char* pshdrs = this->get_view(this->elf_file()->shoff(),
-					       shnum * shdr_size,
-					       true, true);
+					       shnum * shdr_size,  true);
 
   // To speed up processing, we set up hash tables for fast lookup of
   // input offsets to output addresses.
@@ -1615,7 +1614,7 @@ AArch64_relobj<size, big_endian>::scan_sections_for_stubs(
 	  // Get the relocations.
 	  const unsigned char* prelocs = this->get_view(shdr.get_sh_offset(),
 							shdr.get_sh_size(),
-							true, false);
+							false);
 
 	  // Get the section contents.
 	  section_size_type input_view_size = 0;
diff --git a/gold/archive.cc b/gold/archive.cc
index 6d25980..12a58d4 100644
--- a/gold/archive.cc
+++ b/gold/archive.cc
@@ -242,7 +242,7 @@ Archive::setup()
   if (xname == "/")
     {
       const unsigned char* p = this->get_view(off + sizeof(Archive_header),
-                                              extended_size, false, true);
+                                              extended_size, true);
       const char* px = reinterpret_cast<const char*>(p);
       this->extended_names_.assign(px, extended_size);
     }
@@ -283,7 +283,7 @@ Archive::read_armap(off_t start, section_size_type size)
   off_t last_seen_offset = -1;
 
   // Read in the entire armap.
-  const unsigned char* p = this->get_view(start, size, true, false);
+  const unsigned char* p = this->get_view(start, size, false);
 
   // Numbers in the armap are always big-endian.
   const elfcpp::Elf_Word* pword = reinterpret_cast<const elfcpp::Elf_Word*>(p);
@@ -329,8 +329,7 @@ off_t
 Archive::read_header(off_t off, bool cache, std::string* pname,
                      off_t* nested_off)
 {
-  const unsigned char* p = this->get_view(off, sizeof(Archive_header), true,
-					  cache);
+  const unsigned char* p = this->get_view(off, sizeof(Archive_header), cache);
   const Archive_header* hdr = reinterpret_cast<const Archive_header*>(p);
   return this->interpret_header(hdr, off,  pname, nested_off);
 }
diff --git a/gold/archive.h b/gold/archive.h
index 18cd899..77a2e71 100644
--- a/gold/archive.h
+++ b/gold/archive.h
@@ -286,8 +286,8 @@ class Archive : public Library_base
 
   // Get a view into the underlying file.
   const unsigned char*
-  get_view(off_t start, section_size_type size, bool aligned, bool cache)
-  { return this->input_file_->file().get_view(0, start, size, aligned, cache); }
+  get_view(off_t start, section_size_type size, bool cache)
+  { return this->input_file_->file().get_view(0, start, size, cache); }
 
   // Read the archive symbol map.
   void
diff --git a/gold/arm.cc b/gold/arm.cc
index 9812c88..7d996ea 100644
--- a/gold/arm.cc
+++ b/gold/arm.cc
@@ -6327,7 +6327,7 @@ Arm_relobj<big_endian>::scan_sections_for_stubs(
   // Read the section headers.
   const unsigned char* pshdrs = this->get_view(this->elf_file()->shoff(),
 					       shnum * shdr_size,
-					       true, true);
+					       true);
 
   // To speed up processing, we set up hash tables for fast lookup of
   // input offsets to output addresses.
@@ -6365,7 +6365,7 @@ Arm_relobj<big_endian>::scan_sections_for_stubs(
 	  // Get the relocations.
 	  const unsigned char* prelocs = this->get_view(shdr.get_sh_offset(),
 							shdr.get_sh_size(),
-							true, false);
+							false);
 
 	  // Get the section contents.  This does work for the case in which
 	  // we modify the contents of an input section.  We need to pass the
@@ -6456,7 +6456,7 @@ Arm_relobj<big_endian>::do_count_local_symbols(
   gold_assert(loccount == symtabshdr.get_sh_info());
   off_t locsize = loccount * sym_size;
   const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
-					      locsize, true, true);
+					      locsize, true);
 
   // For mapping symbol processing, we need to read the symbol names.
   unsigned int strtab_shndx = this->adjust_shndx(symtabshdr.get_sh_link());
@@ -6477,7 +6477,7 @@ Arm_relobj<big_endian>::do_count_local_symbols(
   const char* pnames =
     reinterpret_cast<const char*>(this->get_view(strtabshdr.get_sh_offset(),
 						 strtabshdr.get_sh_size(),
-						 false, false));
+						 false));
 
   // Loop over the local symbols and mark any local symbols pointing
   // to THUMB functions.
@@ -6648,7 +6648,7 @@ Arm_relobj<big_endian>::find_linked_text_section(
 
   // Get the relocations.
   const unsigned char* prelocs =
-      this->get_view(shdr.get_sh_offset(), shdr.get_sh_size(), true, false);
+      this->get_view(shdr.get_sh_offset(), shdr.get_sh_size(), false);
 
   // Find the REL31 relocation for the first word of the first EXIDX entry.
   for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
@@ -6782,7 +6782,7 @@ Arm_relobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
   // Read processor-specific flags in ELF file header.
   const unsigned char* pehdr = this->get_view(elfcpp::file_header_offset,
 					      elfcpp::Elf_sizes<32>::ehdr_size,
-					      true, false);
+					      false);
   elfcpp::Ehdr<32, big_endian> ehdr(pehdr);
   this->processor_specific_flags_ = ehdr.get_e_flags();
 
@@ -6820,7 +6820,7 @@ Arm_relobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
 	  section_size_type section_size =
 	    convert_to_section_size_type(shdr.get_sh_size());
 	  const unsigned char* view =
-	     this->get_view(section_offset, section_size, true, false);
+	     this->get_view(section_offset, section_size, false);
 	  this->attributes_section_data_ =
 	    new Attributes_section_data(view, section_size);
 	}
@@ -6894,7 +6894,7 @@ Arm_relobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
       gold_assert(loccount == symtabshdr.get_sh_info());
       off_t locsize = loccount * sym_size;
       const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
-						  locsize, true, true);
+						  locsize, true);
 
       // Process the deferred EXIDX sections.
       for (unsigned int i = 0; i < deferred_exidx_sections.size(); ++i)
@@ -6938,7 +6938,7 @@ Arm_relobj<big_endian>::do_gc_process_relocs(Symbol_table* symtab,
   const unsigned int shdr_size = elfcpp::Elf_sizes<32>::shdr_size;
   const unsigned char* pshdrs = this->get_view(this->elf_file()->shoff(),
 					       shnum * shdr_size,
-					       true, true);
+					       true);
 
   // Scan section headers for sections of type SHT_ARM_EXIDX.  Add references
   // to these from the linked text sections.
@@ -6988,7 +6988,7 @@ Arm_relobj<big_endian>::update_output_local_symbol_count()
   gold_assert(loccount == symtabshdr.get_sh_info());
   off_t locsize = loccount * sym_size;
   const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
-					      locsize, true, true);
+					      locsize, true);
 
   // Loop over the local symbols.
 
@@ -7063,7 +7063,7 @@ Arm_dynobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
   // Read processor-specific flags in ELF file header.
   const unsigned char* pehdr = this->get_view(elfcpp::file_header_offset,
 					      elfcpp::Elf_sizes<32>::ehdr_size,
-					      true, false);
+					      false);
   elfcpp::Ehdr<32, big_endian> ehdr(pehdr);
   this->processor_specific_flags_ = ehdr.get_e_flags();
 
@@ -7082,7 +7082,7 @@ Arm_dynobj<big_endian>::do_read_symbols(Read_symbols_data* sd)
 	  section_size_type section_size =
 	    convert_to_section_size_type(shdr.get_sh_size());
 	  const unsigned char* view =
-	    this->get_view(section_offset, section_size, true, false);
+	    this->get_view(section_offset, section_size,false);
 	  this->attributes_section_data_ =
 	    new Attributes_section_data(view, section_size);
 	  break;
diff --git a/gold/binary.cc b/gold/binary.cc
index 12ca296..18afc67 100644
--- a/gold/binary.cc
+++ b/gold/binary.cc
@@ -136,7 +136,7 @@ Binary_to_elf::sized_convert(const Task* task)
   if (filesize == 0)
     fileview = NULL;
   else
-    fileview = f.get_view(0, 0, filesize, false, false);
+    fileview = f.get_view(0, 0, filesize, false);
 
   unsigned int align;
   if (size == 32)
diff --git a/gold/dwp.cc b/gold/dwp.cc
index 16d471c..b1b79f5 100644
--- a/gold/dwp.cc
+++ b/gold/dwp.cc
@@ -782,7 +782,7 @@ Sized_relobj_dwo<size, big_endian>::setup()
 
   // Read the section headers.
   const unsigned char* const pshdrs = this->get_view(shoff, shnum * shdr_size,
-						     true, false);
+						     false);
 
   // Read the section names.
   const unsigned char* pshdrnames =
@@ -794,8 +794,7 @@ Sized_relobj_dwo<size, big_endian>::setup()
   section_size_type section_names_size =
       convert_to_section_size_type(shdrnames.get_sh_size());
   const unsigned char* namesu = this->get_view(shdrnames.get_sh_offset(),
-					       section_names_size, false,
-					       false);
+					       section_names_size, false);
   const char* names = reinterpret_cast<const char*>(namesu);
 
   Compressed_section_map* compressed_sections =
@@ -821,7 +820,7 @@ Sized_relobj_dwo<size, big_endian>::do_section_contents(
       static const unsigned char empty[1] = { '\0' };
       return empty;
     }
-  return this->get_view(loc.file_offset, *plen, true, cache);
+  return this->get_view(loc.file_offset, *plen, cache);
 }
 
 // Class Dwo_file.
@@ -1040,7 +1039,7 @@ Dwo_file::make_object(Dwp_output_file* output_file)
   if (filesize < hdrsize)
     hdrsize = filesize;
   const unsigned char* elf_header =
-      input_file->file().get_view(0, 0, hdrsize, true, false);
+      input_file->file().get_view(0, 0, hdrsize, false);
   if (!elfcpp::Elf_recognizer::is_elf_file(elf_header, hdrsize))
     gold_fatal(_("%s: not an ELF object file"), this->name_);
   
diff --git a/gold/dynobj.cc b/gold/dynobj.cc
index 13e3f61..66f3ebc 100644
--- a/gold/dynobj.cc
+++ b/gold/dynobj.cc
@@ -232,7 +232,7 @@ Sized_dynobj<size, big_endian>::read_dynsym_section(
 	        shndx, this->adjust_shndx(shdr.get_sh_link()), link);
 
   *view = this->get_lasting_view(shdr.get_sh_offset(), shdr.get_sh_size(),
-				 true, false);
+				 false);
   *view_size = convert_to_section_size_type(shdr.get_sh_size());
   *view_info = shdr.get_sh_info();
 }
@@ -257,7 +257,7 @@ Sized_dynobj<size, big_endian>::read_dynamic(const unsigned char* pshdrs,
 
   const off_t dynamic_size = dynamicshdr.get_sh_size();
   const unsigned char* pdynamic = this->get_view(dynamicshdr.get_sh_offset(),
-						 dynamic_size, true, false);
+						 dynamic_size, false);
 
   const unsigned int link = this->adjust_shndx(dynamicshdr.get_sh_link());
   if (link != strtab_shndx)
@@ -278,8 +278,7 @@ Sized_dynobj<size, big_endian>::read_dynamic(const unsigned char* pshdrs,
 	}
 
       strtab_size = strtabshdr.get_sh_size();
-      strtabu = this->get_view(strtabshdr.get_sh_offset(), strtab_size, false,
-			       false);
+      strtabu = this->get_view(strtabshdr.get_sh_offset(), strtab_size, false);
     }
 
   const char* const strtab = reinterpret_cast<const char*>(strtabu);
@@ -392,8 +391,7 @@ Sized_dynobj<size, big_endian>::base_read_symbols(Read_symbols_data* sd)
 				     + this->dynsym_shndx_ * This::shdr_size);
 
       sd->symbols = this->get_lasting_view(dynsymshdr.get_sh_offset(),
-					   dynsymshdr.get_sh_size(), true,
-					   false);
+					   dynsymshdr.get_sh_size(), false);
       sd->symbols_size =
 	convert_to_section_size_type(dynsymshdr.get_sh_size());
 
@@ -416,7 +414,7 @@ Sized_dynobj<size, big_endian>::base_read_symbols(Read_symbols_data* sd)
 
       sd->symbol_names = this->get_lasting_view(strtabshdr.get_sh_offset(),
 						strtabshdr.get_sh_size(),
-						false, false);
+                                                false);
       sd->symbol_names_size =
 	convert_to_section_size_type(strtabshdr.get_sh_size());
 
diff --git a/gold/dynobj.h b/gold/dynobj.h
index b7c60f8..4beff81 100644
--- a/gold/dynobj.h
+++ b/gold/dynobj.h
@@ -219,7 +219,7 @@ class Sized_dynobj : public Dynobj
 	static const unsigned char empty[1] = { '\0' };
 	return empty;
       }
-    return this->get_view(loc.file_offset, *plen, true, cache);
+    return this->get_view(loc.file_offset, *plen, cache);
   }
 
   // Return section flags.
diff --git a/gold/fileread.cc b/gold/fileread.cc
index 0bd8320..dadb5e1 100644
--- a/gold/fileread.cc
+++ b/gold/fileread.cc
@@ -328,21 +328,16 @@ File_read::is_locked() const
 // not for the requested BYTESHIFT.
 
 inline File_read::View*
-File_read::find_view(off_t start, section_size_type size,
-		     unsigned int byteshift, File_read::View** vshifted) const
+File_read::find_view(off_t start, section_size_type size) const
 {
   gold_assert(start <= this->size_
 	      && (static_cast<unsigned long long>(size)
 		  <= static_cast<unsigned long long>(this->size_ - start)));
 
-  if (vshifted != NULL)
-    *vshifted = NULL;
-
   // If we have the whole file mmapped, and the alignment is right,
   // we can return it.
   if (this->whole_file_view_)
-    if (byteshift == -1U || byteshift == 0)
-      return this->whole_file_view_;
+    return this->whole_file_view_;
 
   off_t page = File_read::page_offset(start);
 
@@ -356,14 +351,8 @@ File_read::find_view(off_t start, section_size_type size,
 	  && (p->second->start() + static_cast<off_t>(p->second->size())
 	      >= start + static_cast<off_t>(size)))
 	{
-	  if (byteshift == -1U || byteshift == p->second->byteshift())
-	    {
-	      p->second->set_accessed();
-	      return p->second;
-	    }
-
-	  if (vshifted != NULL && *vshifted == NULL)
-	    *vshifted = p->second;
+          p->second->set_accessed();
+          return p->second;
 	}
 
       ++p;
@@ -425,7 +414,7 @@ File_read::do_read(off_t start, section_size_type size, void* p)
 void
 File_read::read(off_t start, section_size_type size, void* p)
 {
-  const File_read::View* pv = this->find_view(start, size, -1U, NULL);
+  const File_read::View* pv = this->find_view(start, size);
   if (pv != NULL)
     {
       memcpy(p, pv->data() + (start - pv->start() + pv->byteshift()), size);
@@ -530,7 +519,7 @@ File_read::make_view(off_t start, section_size_type size,
 
 File_read::View*
 File_read::find_or_make_view(off_t offset, off_t start,
-			     section_size_type size, bool aligned, bool cache)
+			     section_size_type size, bool cache)
 {
   // Check that start and end of the view are within the file.
   if (start > this->size_
@@ -569,10 +558,7 @@ File_read::find_or_make_view(off_t offset, off_t start,
     this->whole_file_view_ = this->make_view(0, this->size_, 0, cache);
 
   // Try to find a View with the required BYTESHIFT.
-  File_read::View* vshifted;
-  File_read::View* v = this->find_view(offset + start, size,
-				       aligned ? byteshift : -1U,
-				       &vshifted);
+  File_read::View* v = this->find_view(offset + start, size);
   if (v != NULL)
     {
       if (cache)
@@ -580,52 +566,26 @@ File_read::find_or_make_view(off_t offset, off_t start,
       return v;
     }
 
-  // If VSHIFTED is not NULL, then it has the data we need, but with
-  // the wrong byteshift.
-  v = vshifted;
-  if (v != NULL)
-    {
-      gold_assert(aligned);
-
-      unsigned char* pbytes;
-      pbytes = static_cast<unsigned char*>(malloc(v->size() + byteshift));
-      if (pbytes == NULL)
-	gold_nomem();
-      memset(pbytes, 0, byteshift);
-      memcpy(pbytes + byteshift, v->data() + v->byteshift(), v->size());
-
-      File_read::View* shifted_view =
-	  new File_read::View(v->start(), v->size(), pbytes, byteshift,
-			      cache, View::DATA_ALLOCATED_ARRAY);
-
-      this->add_view(shifted_view);
-      return shifted_view;
-    }
-
-  // Make a new view.  If we don't need an aligned view, use a
-  // byteshift of 0, so that we can use mmap.
-  return this->make_view(offset + start, size,
-			 aligned ? byteshift : 0,
-			 cache);
+  // Make a new view.
+  return this->make_view(offset + start, size, 0, cache);
 }
 
 // Get a view into the file.
 
 const unsigned char*
 File_read::get_view(off_t offset, off_t start, section_size_type size,
-		    bool aligned, bool cache)
+                    bool cache)
 {
   File_read::View* pv = this->find_or_make_view(offset, start, size,
-						aligned, cache);
+						cache);
   return pv->data() + (offset + start - pv->start() + pv->byteshift());
 }
 
 File_view*
 File_read::get_lasting_view(off_t offset, off_t start, section_size_type size,
-			    bool aligned, bool cache)
+			    bool cache)
 {
-  File_read::View* pv = this->find_or_make_view(offset, start, size,
-						aligned, cache);
+  File_read::View *pv = this->find_or_make_view(offset, start, size, cache);
   pv->lock();
   return new File_view(*this, pv,
 		       (pv->data()
@@ -734,8 +694,7 @@ File_read::read_multiple(off_t base, const Read_multiple& rm)
       else
 	{
 	  File_read::View* view = this->find_view(base + i_off,
-						  end_off - i_off,
-						  -1U, NULL);
+						  end_off - i_off);
 	  if (view == NULL)
 	    this->do_readv(base, rm, i, j - i);
 	  else
diff --git a/gold/fileread.h b/gold/fileread.h
index 601e7b0..b0c3d19 100644
--- a/gold/fileread.h
+++ b/gold/fileread.h
@@ -150,8 +150,7 @@ class File_read
   // get_view, read, or get_lasting_view which retrieve the same
   // data.
   const unsigned char*
-  get_view(off_t offset, off_t start, section_size_type size, bool aligned,
-	   bool cache);
+  get_view(off_t offset, off_t start, section_size_type size,  bool cache);
 
   // Read data from the file into the buffer P starting at file offset
   // START for SIZE bytes.
@@ -166,7 +165,7 @@ class File_read
   // ALIGNED and CACHE parameters are as in get_view.
   File_view*
   get_lasting_view(off_t offset, off_t start, section_size_type size,
-		   bool aligned, bool cache);
+		   bool cache);
 
   // Mark all views as no longer cached.
   void
@@ -367,8 +366,7 @@ class File_read
 
   // Find a view into the file.
   View*
-  find_view(off_t start, section_size_type size, unsigned int byteshift,
-	    View** vshifted) const;
+  find_view(off_t start, section_size_type size) const;
 
   // Read data from the file into a buffer.
   void
@@ -386,7 +384,7 @@ class File_read
   // Find or make a view into the file.
   View*
   find_or_make_view(off_t offset, off_t start, section_size_type size,
-		    bool aligned, bool cache);
+                    bool cache);
 
   // Clear the file views.
   void
diff --git a/gold/merge.cc b/gold/merge.cc
index 50d13af..d3a452a 100644
--- a/gold/merge.cc
+++ b/gold/merge.cc
@@ -457,7 +457,8 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
       return false;
     }
 
-  if (pend[-1] != 0)
+  Char_type zero = 0;
+  if (memcmp(&zero, &pend[-1], sizeof(zero)) != 0)
     {
       gold_warning(_("%s: last entry in mergeable string section '%s' "
 		     "not null terminated"),
diff --git a/gold/mips.cc b/gold/mips.cc
index acf76cf..5050880 100644
--- a/gold/mips.cc
+++ b/gold/mips.cc
@@ -5839,7 +5839,7 @@ Mips_relobj<size, big_endian>::do_count_local_symbols(
   gold_assert(loccount == symtabshdr.get_sh_info());
   off_t locsize = loccount * sym_size;
   const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
-                                              locsize, true, true);
+                                              locsize, true);
 
   // Loop over the local symbols and mark any MIPS16 or microMIPS local symbols.
 
@@ -5867,7 +5867,7 @@ Mips_relobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
   // Read processor-specific flags in ELF file header.
   const unsigned char* pehdr = this->get_view(elfcpp::file_header_offset,
                                             elfcpp::Elf_sizes<size>::ehdr_size,
-                                            true, false);
+                                            false);
   elfcpp::Ehdr<size, big_endian> ehdr(pehdr);
   this->processor_specific_flags_ = ehdr.get_e_flags();
 
@@ -5896,7 +5896,7 @@ Mips_relobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
           section_size_type section_size =
             convert_to_section_size_type(shdr.get_sh_size());
           const unsigned char* view =
-             this->get_view(section_offset, section_size, true, false);
+             this->get_view(section_offset, section_size, false);
 
           this->gp_ = elfcpp::Swap<size, big_endian>::readval(view + 20);
 
@@ -8004,7 +8004,7 @@ Target_mips<size, big_endian>::do_finalize_sections(Layout* layout,
           const unsigned char* pehdr = relobj->get_view(
                                             elfcpp::file_header_offset,
                                             elfcpp::Elf_sizes<size>::ehdr_size,
-                                            true, false);
+                                            false);
 
           elfcpp::Ehdr<size, big_endian> ehdr(pehdr);
           elfcpp::Elf_Word in_flags = ehdr.get_e_flags();
@@ -8025,7 +8025,7 @@ Target_mips<size, big_endian>::do_finalize_sections(Layout* layout,
       // Read processor-specific flags.
       const unsigned char* pehdr = dynobj->get_view(elfcpp::file_header_offset,
                                            elfcpp::Elf_sizes<size>::ehdr_size,
-                                           true, false);
+                                           false);
 
       elfcpp::Ehdr<size, big_endian> ehdr(pehdr);
       elfcpp::Elf_Word in_flags = ehdr.get_e_flags();
diff --git a/gold/nacl.h b/gold/nacl.h
index 5b6f5a4..8b1e720 100644
--- a/gold/nacl.h
+++ b/gold/nacl.h
@@ -60,7 +60,7 @@ class Sniff_file
   {
    public:
     View(File_read& file, off_t file_offset, off_t data_size)
-      : data_(file.get_view(0, file_offset, data_size, true, false))
+      : data_(file.get_view(0, file_offset, data_size, false))
     { }
 
     const unsigned char* data()
diff --git a/gold/object.cc b/gold/object.cc
index 18c6670..d19b7d0 100644
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -121,7 +121,7 @@ Xindex::read_symtab_xindex(Object* object, unsigned int xindex_shndx,
 				   * elfcpp::Elf_sizes<size>::shdr_size));
       typename elfcpp::Shdr<size, big_endian> shdr(p);
       bytecount = convert_to_section_size_type(shdr.get_sh_size());
-      contents = object->get_view(shdr.get_sh_offset(), bytecount, true, false);
+      contents = object->get_view(shdr.get_sh_offset(), bytecount, false);
     }
 
   gold_assert(this->symtab_xindex_.empty());
@@ -196,7 +196,7 @@ Object::read_section_data(elfcpp::Elf_file<size, big_endian, Object>* elf_file,
   const off_t shoff = elf_file->shoff();
   const unsigned int shnum = this->shnum();
   sd->section_headers = this->get_lasting_view(shoff, shnum * shdr_size,
-					       true, true);
+					       true);
 
   // Read the section names.
   const unsigned char* pshdrs = sd->section_headers->data();
@@ -210,8 +210,7 @@ Object::read_section_data(elfcpp::Elf_file<size, big_endian, Object>* elf_file,
   sd->section_names_size =
     convert_to_section_size_type(shdrnames.get_sh_size());
   sd->section_names = this->get_lasting_view(shdrnames.get_sh_offset(),
-					     sd->section_names_size, false,
-					     false);
+					     sd->section_names_size, false);
 }
 
 // If NAME is the name of a special .gnu.warning section, arrange for
@@ -872,7 +871,7 @@ Sized_relobj_file<size, big_endian>::base_read_symbols(Read_symbols_data* sd)
       return;
     }
 
-  File_view* fvsymtab = this->get_lasting_view(readoff, readsize, true, false);
+  File_view* fvsymtab = this->get_lasting_view(readoff, readsize, false);
 
   // Read the section header for the symbol names.
   unsigned int strtab_shndx = this->adjust_shndx(symtabshdr.get_sh_link());
@@ -892,7 +891,7 @@ Sized_relobj_file<size, big_endian>::base_read_symbols(Read_symbols_data* sd)
   // Read the symbol names.
   File_view* fvstrtab = this->get_lasting_view(strtabshdr.get_sh_offset(),
 					       strtabshdr.get_sh_size(),
-					       false, true);
+					       true);
 
   sd->symbols = fvsymtab;
   sd->symbols_size = readsize;
@@ -950,7 +949,7 @@ Sized_relobj_file<size, big_endian>::include_section_group(
   // Read the section contents.
   typename This::Shdr shdr(shdrs + index * This::shdr_size);
   const unsigned char* pcon = this->get_view(shdr.get_sh_offset(),
-					     shdr.get_sh_size(), true, false);
+					     shdr.get_sh_size(), false);
   const elfcpp::Elf_Word* pword =
     reinterpret_cast<const elfcpp::Elf_Word*>(pcon);
 
@@ -979,8 +978,7 @@ Sized_relobj_file<size, big_endian>::include_section_group(
       return false;
     }
   off_t symoff = symshdr.get_sh_offset() + symndx * This::sym_size;
-  const unsigned char* psym = this->get_view(symoff, This::sym_size, true,
-					     false);
+  const unsigned char* psym = this->get_view(symoff, This::sym_size,  false);
   elfcpp::Sym<size, big_endian> sym(psym);
 
   // Read the symbol table names.
@@ -2160,7 +2158,7 @@ Sized_relobj_file<size, big_endian>::do_count_local_symbols(Stringpool* pool,
   gold_assert(loccount == symtabshdr.get_sh_info());
   off_t locsize = loccount * sym_size;
   const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
-					      locsize, true, true);
+					      locsize, true);
 
   // Read the symbol names.
   const unsigned int strtab_shndx =
@@ -2615,7 +2613,7 @@ Sized_relobj_file<size, big_endian>::write_local_symbols(
   const int sym_size = This::sym_size;
   off_t locsize = loccount * sym_size;
   const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
-					      locsize, true, false);
+					      locsize, false);
 
   // Read the symbol names.
   const unsigned int strtab_shndx =
@@ -3154,8 +3152,7 @@ is_elf_object(Input_file* input_file, off_t offset,
   if (filesize - offset < want)
     want = filesize - offset;
 
-  const unsigned char* p = input_file->file().get_view(offset, 0, want,
-						       true, false);
+  const unsigned char *p = input_file->file().get_view(offset, 0, want, false);
   *start = p;
   *read_size = want;
 
diff --git a/gold/object.h b/gold/object.h
index a3d5d0e..5bdf60f 100644
--- a/gold/object.h
+++ b/gold/object.h
@@ -640,7 +640,7 @@ class Object
   // Return a View.
   View
   view(off_t file_offset, section_size_type data_size)
-  { return View(this->get_view(file_offset, data_size, true, true)); }
+  { return View(this->get_view(file_offset, data_size, true)); }
 
   // Report an error.
   void
@@ -659,23 +659,22 @@ class Object
 
   // Get a View given a Location.
   View view(Location loc)
-  { return View(this->get_view(loc.file_offset, loc.data_size, true, true)); }
+  { return View(this->get_view(loc.file_offset, loc.data_size, true)); }
 
   // Get a view into the underlying file.
   const unsigned char*
-  get_view(off_t start, section_size_type size, bool aligned, bool cache)
+  get_view(off_t start, section_size_type size, bool cache)
   {
     return this->input_file()->file().get_view(this->offset_, start, size,
-					       aligned, cache);
+                                               cache);
   }
 
   // Get a lasting view into the underlying file.
   File_view*
-  get_lasting_view(off_t start, section_size_type size, bool aligned,
-		   bool cache)
+  get_lasting_view(off_t start, section_size_type size, bool cache)
   {
     return this->input_file()->file().get_lasting_view(this->offset_, start,
-						       size, aligned, cache);
+						       size, cache);
   }
 
   // Read data from the underlying file.
@@ -2350,7 +2349,7 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
 	static const unsigned char empty[1] = { '\0' };
 	return empty;
       }
-    return this->get_view(loc.file_offset, *plen, true, cache);
+    return this->get_view(loc.file_offset, *plen, cache);
   }
 
   // Return section flags.
diff --git a/gold/plugin.cc b/gold/plugin.cc
index 1588f34..c8e8f8a 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -822,8 +822,7 @@ Plugin_manager::get_view(unsigned int handle, const void **viewp)
       filesize = obj->filesize();
       input_file = obj->input_file();
     }
-  *viewp = (void*) input_file->file().get_view(offset, 0, filesize, false,
-                                               false);
+  *viewp = (void*) input_file->file().get_view(offset, 0, filesize,  false);
   return LDPS_OK;
 }
 
diff --git a/gold/powerpc.cc b/gold/powerpc.cc
index 540e197..9276680 100644
--- a/gold/powerpc.cc
+++ b/gold/powerpc.cc
@@ -1886,7 +1886,7 @@ Powerpc_relobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
 	  const unsigned char *psymtab = pshdrs + symtab_shndx * shdr_size;
 	  typename elfcpp::Shdr<size, big_endian> shdr(psymtab);
 	  const unsigned char* psyms = this->get_view(shdr.get_sh_offset(),
-						      locsize, true, false);
+						      locsize, false);
 	  psyms += sym_size;
 	  for (unsigned int i = 1; i < loccount; ++i, psyms += sym_size)
 	    {
@@ -1969,7 +1969,7 @@ Powerpc_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
 	      this->opd_address_ = shdr.get_sh_addr();
 	      opd_size = convert_to_section_size_type(shdr.get_sh_size());
 	      opd = this->get_view(shdr.get_sh_offset(), opd_size,
-				   true, false);
+                                   false);
 	      break;
 	    }
 	}
diff --git a/gold/reloc.cc b/gold/reloc.cc
index 3c9f7a9..291c1a0 100644
--- a/gold/reloc.cc
+++ b/gold/reloc.cc
@@ -273,7 +273,7 @@ Sized_relobj_file<size, big_endian>::do_read_relocs(Read_relocs_data* rd)
 
   const unsigned char* pshdrs = this->get_view(this->elf_file_.shoff(),
 					       shnum * This::shdr_size,
-					       true, true);
+					       true);
   // Skip the first, dummy, section.
   const unsigned char* ps = pshdrs + This::shdr_size;
   for (unsigned int i = 1; i < shnum; ++i, ps += This::shdr_size)
@@ -351,7 +351,7 @@ Sized_relobj_file<size, big_endian>::do_read_relocs(Read_relocs_data* rd)
       sr.reloc_shndx = i;
       sr.data_shndx = shndx;
       sr.contents = this->get_lasting_view(shdr.get_sh_offset(), sh_size,
-					   true, true);
+					   true);
       sr.sh_type = sh_type;
       sr.reloc_count = reloc_count;
       sr.output_section = os;
@@ -373,7 +373,7 @@ Sized_relobj_file<size, big_endian>::do_read_relocs(Read_relocs_data* rd)
       gold_assert(loccount == symtabshdr.get_sh_info());
       off_t locsize = loccount * sym_size;
       rd->local_symbols = this->get_lasting_view(symtabshdr.get_sh_offset(),
-						 locsize, true, true);
+						 locsize, true);
     }
 }
 
@@ -650,7 +650,7 @@ Sized_relobj_file<size, big_endian>::do_relocate(const Symbol_table* symtab,
   // Read the section headers.
   const unsigned char* pshdrs = this->get_view(this->elf_file_.shoff(),
 					       shnum * This::shdr_size,
-					       true, true);
+					       true);
 
   Views views;
   views.resize(shnum);
@@ -963,7 +963,7 @@ Sized_relobj_file<size, big_endian>::do_relocate_sections(
 	}
 
       const unsigned char* prelocs = this->get_view(shdr.get_sh_offset(),
-						    sh_size, true, false);
+						    sh_size, false);
 
       unsigned int reloc_size;
       if (sh_type == elfcpp::SHT_REL)
@@ -1400,7 +1400,7 @@ Sized_relobj_file<size, big_endian>::find_functions(
   typename elfcpp::Elf_types<size>::Elf_WXword sh_size =
     symtabshdr.get_sh_size();
   const unsigned char* psyms = this->get_view(symtabshdr.get_sh_offset(),
-					      sh_size, true, true);
+					      sh_size, true);
 
   const int sym_size = This::sym_size;
   const unsigned int symcount = sh_size / sym_size;
diff --git a/gold/stringpool.h b/gold/stringpool.h
index 2a3fb08..6950ade 100644
--- a/gold/stringpool.h
+++ b/gold/stringpool.h
@@ -38,8 +38,9 @@ template<typename Char_type>
 inline size_t
 string_length(const Char_type* p)
 {
+  Char_type zero = 0;
   size_t len = 0;
-  for (; *p != 0; ++p)
+  for (; memcmp(&zero, p, sizeof(zero)) != 0; ++p)
     ++len;
   return len;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]