Don't allow mov-to-lea optimization for __ehdr_start.
authorCary Coutant <ccoutant@gmail.com>
Wed, 1 Feb 2017 00:32:59 +0000 (16:32 -0800)
committerCary Coutant <ccoutant@gmail.com>
Wed, 1 Feb 2017 00:33:58 +0000 (16:33 -0800)
gold/
PR gold/21090
* x86_64.cc (Target_x86_64::can_convert_mov_to_lea): Add check
for predefined symbol.
(Target_x86_64::Relocate::relocate): Fix formatting.

gold/ChangeLog
gold/x86_64.cc

index 7357c08a03a756b07e7dfadcdc211d612aa1ebe0..c50e1f8933281ac5964524658724ee94b6f53708 100644 (file)
@@ -1,3 +1,10 @@
+2017-01-31  Cary Coutant  <ccoutant@gmail.com>
+
+       PR gold/21090
+       * x86_64.cc (Target_x86_64::can_convert_mov_to_lea): Add check
+       for predefined symbol.
+       (Target_x86_64::Relocate::relocate): Fix formatting.
+
 2017-01-23  Rahul Chaudhry  <rahulchaudhry@google.com>
 
         * testsuite/icf_safe_so_test.sh: Use "set -e".
index ffa876116a142ea12d57f800580a50c036d23391..d21c26813c977be3bbb135a4995460709e85a170 100644 (file)
@@ -1046,8 +1046,11 @@ class Target_x86_64 : public Sized_target<size, false>
       return false;
     // We cannot convert references to IFUNC symbols, or to symbols that
     // are not local to the current module.
+    // We can't do predefined symbols because they may become undefined
+    // (e.g., __ehdr_start when the headers aren't mapped to a segment).
     if (gsym->type() == elfcpp::STT_GNU_IFUNC
-        || gsym->is_undefined ()
+        || gsym->is_undefined()
+        || gsym->is_predefined()
         || gsym->is_from_dynobj()
         || gsym->is_preemptible())
       return false;
@@ -4244,12 +4247,14 @@ Target_x86_64<size>::Relocate::relocate(
          if (gsym != NULL)
            {
              gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
-             got_offset = gsym->got_offset(GOT_TYPE_STANDARD) - target->got_size();
+             got_offset = (gsym->got_offset(GOT_TYPE_STANDARD)
+                           - target->got_size());
            }
          else
            {
              unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
-             gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
+             gold_assert(object->local_has_got_offset(r_sym,
+                                                      GOT_TYPE_STANDARD));
              got_offset = (object->local_got_offset(r_sym, GOT_TYPE_STANDARD)
                            - target->got_size());
            }