gas: ensure sections contents is zero for BFD_RELOC_PPC*_TLSM on XCOFF.
authorClément Chigot <clement.chigot@atos.net>
Mon, 14 Jun 2021 11:25:42 +0000 (13:25 +0200)
committerAlan Modra <amodra@gmail.com>
Thu, 17 Jun 2021 06:08:09 +0000 (15:38 +0930)
AIX ld expects the section contents for relocations BFD_RELOC_PPC_TLSM
or BFD_RELOC_PPC64_TLSM to be zero.
Actually, it seems to be the case for all the TLS relocations
generated by AIX assembly but only these two are mandatory.

* config/tc-ppc.c (md_apply_fix): Adjust addend to nullify
section contents for BFD_RELOC_PPC_TLSM or
BFD_RELOC_PPC64_TLSM.
* testsuite/gas/ppc/xcoff-tlsm-32.d: New test.
* testsuite/gas/ppc/xcoff-tlsm-64.d: New test.
* testsuite/gas/ppc/xcoff-tlsm.s: New test.
* testsuite/gas/ppc/aix.exp: Run new tests.

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

index 8fa1be88e816a686016d48b5b1e962d3bae09f4d..ad2013708c46ffb0c67f56e48331dbf890682212 100644 (file)
@@ -1,3 +1,13 @@
+2021-06-17  Clément Chigot  <clement.chigot@atos.net>
+
+       * config/tc-ppc.c (md_apply_fix): Adjust addend to nullify
+       section contents for BFD_RELOC_PPC_TLSM or
+       BFD_RELOC_PPC64_TLSM.
+       * testsuite/gas/ppc/xcoff-tlsm-32.d: New test.
+       * testsuite/gas/ppc/xcoff-tlsm-64.d: New test.
+       * testsuite/gas/ppc/xcoff-tlsm.s: New test.
+       * testsuite/gas/ppc/aix.exp: Run new tests.
+
 2021-06-16  Jan Beulich  <jbeulich@suse.com>
 
        * read.c (parse_one_float): New.
index fce2b15f17afa224c631f47134377609b8966bb1..72bf5ce75d424db0508b7e5a1fcd33b428c8d074 100644 (file)
@@ -7411,11 +7411,9 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg)
        symbol_get_bfdsym (fixP->fx_addsy)->flags |= BSF_KEEP;
     }
 #else
-  if (fixP->fx_r_type != BFD_RELOC_PPC_TOC16
-      && fixP->fx_r_type != BFD_RELOC_PPC_TOC16_HI
-      && fixP->fx_r_type != BFD_RELOC_PPC_TOC16_LO)
-    fixP->fx_addnumber = 0;
-  else
+  if (fixP->fx_r_type == BFD_RELOC_PPC_TOC16
+      || fixP->fx_r_type == BFD_RELOC_PPC_TOC16_HI
+      || fixP->fx_r_type == BFD_RELOC_PPC_TOC16_LO)
     {
       /* We want to use the offset within the toc, not the actual VMA
         of the symbol.  */
@@ -7430,6 +7428,15 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg)
       /* Set *valP to avoid errors.  */
       *valP = value;
     }
+  else if (fixP->fx_r_type == BFD_RELOC_PPC_TLSM
+          || fixP->fx_r_type == BFD_RELOC_PPC64_TLSM)
+    /* AIX ld expects the section contents for these relocations
+       to be zero.  Arrange for that to occur when
+       bfd_install_relocation is called.  */
+    fixP->fx_addnumber = (- bfd_section_vma (S_GET_SEGMENT (fixP->fx_addsy))
+                         - S_GET_VALUE (fixP->fx_addsy));
+  else
+    fixP->fx_addnumber = 0;
 #endif
 }
 
index efe27e4edb03ab86db2c40b6835efd0e6de602fe..38b781969eb7f1791578253dc95b31ebdae58e2d 100644 (file)
@@ -78,4 +78,7 @@ if { [istarget "powerpc*-*-aix*"] || [istarget "rs6000-*-aix*"] } then {
 
     run_dump_test "xcoff-function-1-32"
     run_dump_test "xcoff-function-1-64"
+
+    run_dump_test "xcoff-tlsm-32"
+    run_dump_test "xcoff-tlsm-64"
 }
diff --git a/gas/testsuite/gas/ppc/xcoff-tlsm-32.d b/gas/testsuite/gas/ppc/xcoff-tlsm-32.d
new file mode 100644 (file)
index 0000000..a09dd1a
--- /dev/null
@@ -0,0 +1,34 @@
+#as: -a32
+#source: xcoff-tlsm.s
+#objdump: -Dr
+#name: XCOFF TLSM relocation (32 bit)
+
+.*
+Disassembly of section .data:
+
+00000000 <TOC>:
+   0:  00 00 00 10.*
+                       0: R_TLS        foo_tdata-0x10
+
+00000004 <.foo_tdata>:
+   4:  00 00 00 00.*
+                       4: R_TLSM       foo_tdata-0x10
+
+00000008 <foo_tbss>:
+   8:  00 00 00 20.*
+                       8: R_TLS        foo_tbss-0x20
+
+0000000c <.foo_tbss>:
+   c:  00 00 00 00.*
+                       c: R_TLSM       foo_tbss-0x20
+
+Disassembly of section .tdata:
+
+00000010 <foo_tdata>:
+  10:  00 00 00 01.*
+       ...
+
+Disassembly of section .tbss:
+
+00000020 <foo_tbss>:
+       ...
diff --git a/gas/testsuite/gas/ppc/xcoff-tlsm-64.d b/gas/testsuite/gas/ppc/xcoff-tlsm-64.d
new file mode 100644 (file)
index 0000000..f447a51
--- /dev/null
@@ -0,0 +1,36 @@
+#as: -a64
+#source: xcoff-tlsm.s
+#objdump: -Dr
+#name: XCOFF TLSM relocation (64 bit)
+
+.*
+Disassembly of section .data:
+
+0000000000000000 <TOC>:
+   0:  00 00 00 00.*
+                       0: R_TLS        foo_tdata-0x20
+   4:  00 00 00 20.*
+
+0000000000000008 <.foo_tdata>:
+       ...
+                       8: R_TLSM       foo_tdata-0x20
+
+0000000000000010 <foo_tbss>:
+  10:  00 00 00 00.*
+                       10: R_TLS       foo_tbss-0x30
+  14:  00 00 00 30.*
+
+0000000000000018 <.foo_tbss>:
+       ...
+                       18: R_TLSM      foo_tbss-0x30
+
+Disassembly of section .tdata:
+
+0000000000000020 <foo_tdata>:
+  20:  00 00 00 01.*
+       ...
+
+Disassembly of section .tbss:
+
+0000000000000030 <foo_tbss>:
+       ...
diff --git a/gas/testsuite/gas/ppc/xcoff-tlsm.s b/gas/testsuite/gas/ppc/xcoff-tlsm.s
new file mode 100644 (file)
index 0000000..0c857bf
--- /dev/null
@@ -0,0 +1,12 @@
+  .csect foo_tdata[TL],4
+  .align 2
+foo_tdata:
+  .long        1
+
+  .comm foo_tbss[UL],8
+
+  .toc
+  .tc foo_tdata[TC],foo_tdata[TL]
+  .tc .foo_tdata[TC],foo_tdata[TL]@m
+  .tc foo_tbss[TC],foo_tbss[UL]
+  .tc .foo_tbss[TC],foo_tbss[UL]@m
This page took 0.033544 seconds and 4 git commands to generate.