Fix an internal error in the constructor of Target_arm.
authorIgor Kudrin <ikudrin@accesssoftek.com>
Mon, 19 Dec 2016 23:23:59 +0000 (15:23 -0800)
committerCary Coutant <ccoutant@gmail.com>
Mon, 19 Dec 2016 23:28:28 +0000 (15:28 -0800)
gold/
* arm.cc (Target_arm::Target_arm): Move initialization code ...
(Target_arm::do_select_as_default_target): ... to here.
* testsuite/Makefile.am (arm_target_lazy_init): New test case.
* testsuite/Makefile.in: Regenerate.
* testsuite/arm_target_lazy_init.s: New source file.
* testsuite/arm_target_lazy_init.t: New linker script.

gold/ChangeLog
gold/arm.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/arm_target_lazy_init.s [new file with mode: 0644]
gold/testsuite/arm_target_lazy_init.t [new file with mode: 0644]

index a9ead08170dbced87bfdc75d661f9df643f03f6f..faccdfb3685e639a84689a8d0b47a88a249edc28 100644 (file)
@@ -1,3 +1,12 @@
+2016-12-19  Igor Kudrin  <ikudrin@accesssoftek.com>
+
+       * arm.cc (Target_arm::Target_arm): Move initialization code ...
+       (Target_arm::do_select_as_default_target): ... to here.
+       * testsuite/Makefile.am (arm_target_lazy_init): New test case.
+       * testsuite/Makefile.in: Regenerate.
+       * testsuite/arm_target_lazy_init.s: New source file.
+       * testsuite/arm_target_lazy_init.t: New linker script.
+
 2016-12-19  Cary Coutant  <ccoutant@gmail.com>
 
        PR gold/20976
index ea20c3762605ae13cdf5651af41f9f7a819a6b5c..d1361aa683e17609631db3550fffb078a7abe5a6 100644 (file)
@@ -2132,32 +2132,7 @@ class Target_arm : public Sized_target<32, big_endian>
       target1_reloc_(elfcpp::R_ARM_ABS32),
       // This can be any reloc type but usually is R_ARM_GOT_PREL.
       target2_reloc_(elfcpp::R_ARM_GOT_PREL)
-  {
-    if (parameters->options().user_set_target1_rel())
-      {
-       // FIXME: This is not strictly compatible with ld, which allows both
-       // --target1-abs and --target-rel to be given.
-       if (parameters->options().user_set_target1_abs())
-         gold_error(_("Cannot use both --target1-abs and --target1-rel."));
-       else
-         this->target1_reloc_ = elfcpp::R_ARM_REL32;
-      }
-    // We don't need to handle --target1-abs because target1_reloc_ is set
-    // to elfcpp::R_ARM_ABS32 in the member initializer list.
-
-    if (parameters->options().user_set_target2())
-      {
-       const char* target2 = parameters->options().target2();
-       if (strcmp(target2, "rel") == 0)
-         this->target2_reloc_ = elfcpp::R_ARM_REL32;
-       else if (strcmp(target2, "abs") == 0)
-         this->target2_reloc_ = elfcpp::R_ARM_ABS32;
-       else if (strcmp(target2, "got-rel") == 0)
-         this->target2_reloc_ = elfcpp::R_ARM_GOT_PREL;
-       else
-         gold_unreachable();
-      }
-  }
+  { }
 
   // Whether we force PCI branch veneers.
   bool
@@ -2571,6 +2546,30 @@ class Target_arm : public Sized_target<32, big_endian>
     // as the default.
     gold_assert(arm_reloc_property_table == NULL);
     arm_reloc_property_table = new Arm_reloc_property_table();
+    if (parameters->options().user_set_target1_rel())
+      {
+       // FIXME: This is not strictly compatible with ld, which allows both
+       // --target1-abs and --target-rel to be given.
+       if (parameters->options().user_set_target1_abs())
+         gold_error(_("Cannot use both --target1-abs and --target1-rel."));
+       else
+         this->target1_reloc_ = elfcpp::R_ARM_REL32;
+      }
+    // We don't need to handle --target1-abs because target1_reloc_ is set
+    // to elfcpp::R_ARM_ABS32 in the member initializer list.
+
+    if (parameters->options().user_set_target2())
+      {
+       const char* target2 = parameters->options().target2();
+       if (strcmp(target2, "rel") == 0)
+         this->target2_reloc_ = elfcpp::R_ARM_REL32;
+       else if (strcmp(target2, "abs") == 0)
+         this->target2_reloc_ = elfcpp::R_ARM_ABS32;
+       else if (strcmp(target2, "got-rel") == 0)
+         this->target2_reloc_ = elfcpp::R_ARM_GOT_PREL;
+       else
+         gold_unreachable();
+      }
   }
 
   // Virtual function which is set to return true by a target if
index ab743c714712d2dd3096bb5d0c1fae348931dbde..0e6f5d1418799155aba209802e7c35107d1ac6ec 100644 (file)
@@ -3721,6 +3721,14 @@ arm_target2.o: arm_target2.s
 MOSTLYCLEANFILES += arm_target1_abs arm_target1_rel \
                    arm_target2_rel arm_target2_abs arm_target2_got_rel
 
+# The test demonstrates why the constructor of a target object should not access options.
+check_DATA += arm_target_lazy_init
+MOSTLYCLEANFILES += arm_target_lazy_init
+arm_target_lazy_init: arm_target_lazy_init.o arm_target_lazy_init.t ../ld-new
+       ../ld-new -T $(srcdir)/arm_target_lazy_init.t -o $@ $<
+arm_target_lazy_init.o: arm_target_lazy_init.s
+       $(TEST_AS) -EL -o $@ $<
+
 endif DEFAULT_TARGET_ARM
 
 if DEFAULT_TARGET_AARCH64
index 5de841adb9b0351a859fe9ed86e2f180cf3d9e94..fe9d41928522b47cd329af96048b0b07cf7ee065 100644 (file)
@@ -854,6 +854,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_rel.sh \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_abs.sh \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_got_rel.sh
+
+# The test demonstrates why the constructor of a target object should not access options.
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@am__append_93 = arm_abs_global.stdout \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_bl_in_range.stdout \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_bl_out_of_range.stdout \
@@ -903,7 +905,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target1_rel.stdout \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_rel.stdout \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_abs.stdout \
-@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_got_rel.stdout
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_got_rel.stdout \
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target_lazy_init
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@am__append_94 = arm_abs_global \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_bl_in_range \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_bl_out_of_range \
@@ -951,7 +954,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target1_rel \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_rel \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_abs \
-@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_got_rel
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target2_got_rel \
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_target_lazy_init
 @DEFAULT_TARGET_AARCH64_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@am__append_95 = aarch64_reloc_none.sh \
 @DEFAULT_TARGET_AARCH64_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@     aarch64_relocs.sh
 @DEFAULT_TARGET_AARCH64_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@am__append_96 = aarch64_reloc_none.stdout \
@@ -7763,6 +7767,10 @@ uninstall-am:
 
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_target2.o: arm_target2.s
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -o $@ $<
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_target_lazy_init: arm_target_lazy_init.o arm_target_lazy_init.t ../ld-new
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ ../ld-new -T $(srcdir)/arm_target_lazy_init.t -o $@ $<
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_target_lazy_init.o: arm_target_lazy_init.s
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -EL -o $@ $<
 @DEFAULT_TARGET_AARCH64_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@aarch64_reloc_none.o: aarch64_reloc_none.s
 @DEFAULT_TARGET_AARCH64_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@     $(TEST_AS) -o $@ $<
 @DEFAULT_TARGET_AARCH64_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@aarch64_reloc_none: aarch64_reloc_none.o ../ld-new
diff --git a/gold/testsuite/arm_target_lazy_init.s b/gold/testsuite/arm_target_lazy_init.s
new file mode 100644 (file)
index 0000000..d1836f2
--- /dev/null
@@ -0,0 +1,2 @@
+.text
+       nop
diff --git a/gold/testsuite/arm_target_lazy_init.t b/gold/testsuite/arm_target_lazy_init.t
new file mode 100644 (file)
index 0000000..afefae4
--- /dev/null
@@ -0,0 +1 @@
+OUTPUT_FORMAT("elf32-littlearm")