PowerPC gold, fix 32-bit branch address arithmetic
[platform/upstream/binutils.git] / gold / binary.cc
index 9909ff4..4dab52c 100644 (file)
@@ -1,6 +1,6 @@
 // binary.cc -- binary input files for gold
 
-// Copyright 2008 Free Software Foundation, Inc.
+// Copyright (C) 2008-2014 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -35,7 +35,7 @@
 // Support for reading binary files as input.  These become blobs in
 // the final output.  These files are treated as though they have a
 // single .data section and define three symbols:
-// _binary_FILENAME_start, _binary_FILENAME_end, _binary_FILENAME_end.
+// _binary_FILENAME_start, _binary_FILENAME_end, _binary_FILENAME_size.
 // The FILENAME is the name of the input file, with any
 // non-alphanumeric character changed to an underscore.
 
@@ -132,7 +132,11 @@ Binary_to_elf::sized_convert(const Task* task)
     }
 
   section_size_type filesize = convert_to_section_size_type(f.filesize());
-  const unsigned char* fileview = f.get_view(0, filesize, false);
+  const unsigned char* fileview;
+  if (filesize == 0)
+    fileview = NULL;
+  else
+    fileview = f.get_view(0, 0, filesize, false, false);
 
   unsigned int align;
   if (size == 32)
@@ -198,16 +202,16 @@ Binary_to_elf::sized_convert(const Task* task)
   this->write_section_header<size, big_endian>("", &shstrtab, elfcpp::SHT_NULL,
                                               0, 0, 0, 0, 0,
                                               0, 0, &pout);
-  // Having the section be named ".data" and having it be writable is
-  // because th GNU linker does it that way, and existing linker
-  // script expect it.
+  // Having the section be named ".data", having it be writable, and
+  // giving it an alignment of 1 is because the GNU linker does it
+  // that way, and existing linker script expect it.
   this->write_section_header<size, big_endian>(".data", &shstrtab,
                                               elfcpp::SHT_PROGBITS,
                                               (elfcpp::SHF_ALLOC
                                                | elfcpp::SHF_WRITE),
                                               data_offset,
                                               filesize, 0, 0,
-                                              align, 0, &pout);
+                                              1, 0, &pout);
   this->write_section_header<size, big_endian>(".symtab", &shstrtab,
                                               elfcpp::SHT_SYMTAB,
                                               0, symtab_offset, 4 * sym_size,
@@ -223,10 +227,13 @@ Binary_to_elf::sized_convert(const Task* task)
                                               shstrtab.get_strtab_size(),
                                               0, 0, 1, 0, &pout);
 
-  memcpy(pout, fileview, filesize);
-  pout += filesize;
-  memset(pout, 0, aligned_filesize - filesize);
-  pout += aligned_filesize - filesize;
+  if (filesize > 0)
+    {
+      memcpy(pout, fileview, filesize);
+      pout += filesize;
+      memset(pout, 0, aligned_filesize - filesize);
+      pout += aligned_filesize - filesize;
+    }
 
   this->write_symbol<size, big_endian>("", &strtab, 0, 0, &pout);
   this->write_symbol<size, big_endian>(start_symbol_name, &strtab, 0, 1,