From 3478a63d7ed68d666f842f5b8fb5bdade619c817 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20Chigot?= Date: Mon, 14 Jun 2021 13:25:42 +0200 Subject: [PATCH] gas: ensure sections contents is zero for BFD_RELOC_PPC*_TLSM on XCOFF. 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 | 10 ++++++++ gas/config/tc-ppc.c | 17 +++++++++---- gas/testsuite/gas/ppc/aix.exp | 3 +++ gas/testsuite/gas/ppc/xcoff-tlsm-32.d | 34 +++++++++++++++++++++++++ gas/testsuite/gas/ppc/xcoff-tlsm-64.d | 36 +++++++++++++++++++++++++++ gas/testsuite/gas/ppc/xcoff-tlsm.s | 12 +++++++++ 6 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 gas/testsuite/gas/ppc/xcoff-tlsm-32.d create mode 100644 gas/testsuite/gas/ppc/xcoff-tlsm-64.d create mode 100644 gas/testsuite/gas/ppc/xcoff-tlsm.s diff --git a/gas/ChangeLog b/gas/ChangeLog index 8fa1be88e81..ad2013708c4 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,13 @@ +2021-06-17 Clément Chigot + + * 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 * read.c (parse_one_float): New. diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c index fce2b15f17a..72bf5ce75d4 100644 --- a/gas/config/tc-ppc.c +++ b/gas/config/tc-ppc.c @@ -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 } diff --git a/gas/testsuite/gas/ppc/aix.exp b/gas/testsuite/gas/ppc/aix.exp index efe27e4edb0..38b781969eb 100644 --- a/gas/testsuite/gas/ppc/aix.exp +++ b/gas/testsuite/gas/ppc/aix.exp @@ -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 index 00000000000..a09dd1a2e4a --- /dev/null +++ b/gas/testsuite/gas/ppc/xcoff-tlsm-32.d @@ -0,0 +1,34 @@ +#as: -a32 +#source: xcoff-tlsm.s +#objdump: -Dr +#name: XCOFF TLSM relocation (32 bit) + +.* +Disassembly of section .data: + +00000000 : + 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 : + 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 : + 10: 00 00 00 01.* + ... + +Disassembly of section .tbss: + +00000020 : + ... diff --git a/gas/testsuite/gas/ppc/xcoff-tlsm-64.d b/gas/testsuite/gas/ppc/xcoff-tlsm-64.d new file mode 100644 index 00000000000..f447a517742 --- /dev/null +++ b/gas/testsuite/gas/ppc/xcoff-tlsm-64.d @@ -0,0 +1,36 @@ +#as: -a64 +#source: xcoff-tlsm.s +#objdump: -Dr +#name: XCOFF TLSM relocation (64 bit) + +.* +Disassembly of section .data: + +0000000000000000 : + 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 : + 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 : + 20: 00 00 00 01.* + ... + +Disassembly of section .tbss: + +0000000000000030 : + ... diff --git a/gas/testsuite/gas/ppc/xcoff-tlsm.s b/gas/testsuite/gas/ppc/xcoff-tlsm.s new file mode 100644 index 00000000000..0c857bf0aa9 --- /dev/null +++ b/gas/testsuite/gas/ppc/xcoff-tlsm.s @@ -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 -- 2.30.2