gas/
authorTristan Gingold <gingold@adacore.com>
Wed, 4 Sep 2013 12:28:11 +0000 (12:28 +0000)
committerTristan Gingold <gingold@adacore.com>
Wed, 4 Sep 2013 12:28:11 +0000 (12:28 +0000)
* config/tc-ppc.c (md_apply_fix): Handle defined after use toc
symbols.

gas/testsuite/
* gas/ppc/aix.exp: Run xcoff-toc-1 test.
* gas/ppc/xcoff-toc-1.s, gas/ppc/xcoff-toc-1.d: New test.

gas/ChangeLog
gas/config/tc-ppc.c
gas/testsuite/ChangeLog
gas/testsuite/gas/ppc/aix.exp
gas/testsuite/gas/ppc/xcoff-toc-1.d [new file with mode: 0644]
gas/testsuite/gas/ppc/xcoff-toc-1.s [new file with mode: 0644]

index d614224217af76e3eb0c421ce9863e1d2a3be98f..89c9cc9b556e2af16a259138ed0ec961239dfe34 100644 (file)
@@ -1,3 +1,8 @@
+2013-09-04  Tristan Gingold  <gingold@adacore.com>
+
+       * config/tc-ppc.c (md_apply_fix): Handle defined after use toc
+       symbols.
+
 2013-09-04  Roland McGrath  <mcgrathr@google.com>
 
        PR gas/15914
index 1631fb7fa4bc8fc7ba9744c6958609f6cb8bf0e9..6b54f5ad8ebcb979abe24e9428d65246a6631c8e 100644 (file)
@@ -3146,6 +3146,7 @@ md_assemble (char *str)
                   && (operand->bitm & 0xfff0) == 0xfff0
                   && operand->shift == 0)
            {
+             /* Note: the symbol may be not yet defined.  */
              if (ppc_is_toc_sym (ex.X_add_symbol))
                {
                  reloc = BFD_RELOC_PPC_TOC16;
@@ -6363,6 +6364,15 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
          value = fixP->fx_offset;
          fixP->fx_done = 1;
        }
+
+       /* During parsing of instructions, a TOC16 reloc is generated for
+          instructions such as 'lwz RT,SYM(RB)' if SYM is a symbol defined
+          in the toc.  But at parse time, SYM may be not yet defined, so
+          check again here.  */
+       if (fixP->fx_r_type == BFD_RELOC_16
+           && fixP->fx_addsy != NULL
+           && ppc_is_toc_sym (fixP->fx_addsy))
+         fixP->fx_r_type = BFD_RELOC_PPC_TOC16;
 #endif
     }
 
@@ -6873,6 +6883,8 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
       fixP->fx_addnumber =
        - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixP->fx_addsy))
        - S_GET_VALUE (ppc_toc_csect);
+      /* Set *valP to avoid errors.  */
+      *valP = value;
 #endif
     }
 #endif
index 15e00f3e74c4d708e9828aadafd87bc175581163..2110cd94de90634943f6fd1c0637f542d2b25938 100644 (file)
@@ -1,3 +1,8 @@
+2013-09-04  Tristan Gingold  <gingold@adacore.com>
+
+       * gas/ppc/aix.exp: Run xcoff-toc-1 test.
+       * gas/ppc/xcoff-toc-1.s, gas/ppc/xcoff-toc-1.d: New test.
+
 2013-09-04  Roland McGrath  <mcgrathr@google.com>
 
        PR gas/15914
index 27898376c368e5057e14d0fef44d7e464c2d1c61..9612f27d199a380287bf83c2d7d6aeeb96fa40fc 100644 (file)
@@ -67,6 +67,7 @@ if [istarget powerpc-ibm-aix*] then {
     run_dump_test "xcoff-branch-1-64"
     run_dump_test "xcoff-br16-1"
     run_dump_test "xcoff-br16-2"
+    run_dump_test "xcoff-toc-1"
 
     run_list_test "xcoff-ref-1"
 
diff --git a/gas/testsuite/gas/ppc/xcoff-toc-1.d b/gas/testsuite/gas/ppc/xcoff-toc-1.d
new file mode 100644 (file)
index 0000000..bb85694
--- /dev/null
@@ -0,0 +1,12 @@
+#as: -a32
+#source: xcoff-toc-1.s
+#objdump: -dr
+#name: XCOFF TOC reloc test 1
+
+.*
+Disassembly of section \.text:
+
+00000000 <\.foo>:
+   0:  80 22 00 00     l       r1,0\(r2\)
+                       2: R_TOC        data-0x10010
+   4:  4e 80 00 20     br
diff --git a/gas/testsuite/gas/ppc/xcoff-toc-1.s b/gas/testsuite/gas/ppc/xcoff-toc-1.s
new file mode 100644 (file)
index 0000000..ac491ae
--- /dev/null
@@ -0,0 +1,21 @@
+       .csect _rw_[RW],4
+       .toc
+
+       .csect .text[PR]
+       .align 2
+       .lglobl .foo
+       .csect foo[DS]
+foo:
+       .long .foo, TOC[tc0], 0
+       .csect .text[PR]
+.foo:
+       lwz 1,LC..72(2)
+       blr
+       .align 2
+       .toc
+LC..72:
+       .tc data[TC],data
+       .csect _rw_[RW],4
+       .align 2
+data:
+       .space 0x10000