aboutsummaryrefslogtreecommitdiff
path: root/gas
diff options
context:
space:
mode:
authorClément Chigot <clement.chigot@atos.net>2021-12-17 14:46:01 +0100
committerClément Chigot <clement.chigot@atos.net>2022-01-10 09:14:57 +0100
commit3c5038247c8a5fcff18fd81249b0801a95569939 (patch)
tree2705a789bb9771f4d0f6f8709e390bc5666b9070 /gas
parent4cfa9e3f28c8c5156b9773cc94192233947d351c (diff)
downloadgdb-3c5038247c8a5fcff18fd81249b0801a95569939.zip
gdb-3c5038247c8a5fcff18fd81249b0801a95569939.tar.gz
gdb-3c5038247c8a5fcff18fd81249b0801a95569939.tar.bz2
XCOFF: add support for TLS relocations on hidden symbols
This patch adds support for TLS relocation targeting C_HIDEXT symbols. In gas, TLS relocations, except R_TLSM and R_TLMSL, must keep the value of their target symbol. In ld, it simply ensures that internal TLS symbols are added to the linker hash table for xcoff_reloc_type_tls. It also improves the tests made by both. bfd/ChangeLog: * coff-rs6000.c (xcoff_howto_table): Fix name of R_TLSML. (xcoff_reloc_type_tls): Replace the error when h is NULL by an assert. (xcoff_complain_overflow_unsigned_func): Adjust comments. * coff64-rs6000.c (xcoff64_howto_table): Fix name of R_TLSML. * xcofflink.c (xcoff_link_add_symbols_to_hash_table): New function. (xcoff_link_add_symbols): Add C_HIDEXT TLS symbols to the linker hash table. gas/ChangeLog: * config/tc-ppc.c (md_apply_fix): Enable support for TLS relocation over internal symbols. * testsuite/gas/ppc/aix.exp: Replace xcoff-tlms by xcoff-tls. * testsuite/gas/ppc/xcoff-tlsm-32.d: Removed. * testsuite/gas/ppc/xcoff-tlsm-64.d: Removed. * testsuite/gas/ppc/xcoff-tlsm.s: Removed. * testsuite/gas/ppc/xcoff-tls-32.d: New test. * testsuite/gas/ppc/xcoff-tls-64.d: New test. * testsuite/gas/ppc/xcoff-tls.s: New test. ld/ChangeLog: * testsuite/ld-powerpc/aix52.exp: Improve aix-tls-reloc test. * testsuite/ld-powerpc/aix-tls-reloc.s: Likewise. * testsuite/ld-powerpc/aix-tls-reloc-32.d: Removed. * testsuite/ld-powerpc/aix-tls-reloc-64.d: Removed. * testsuite/ld-powerpc/aix-tls-reloc-32.dd: New test. * testsuite/ld-powerpc/aix-tls-reloc-32.dt: New test. * testsuite/ld-powerpc/aix-tls-reloc-64.dd: New test. * testsuite/ld-powerpc/aix-tls-reloc-64.dt: New test.
Diffstat (limited to 'gas')
-rw-r--r--gas/config/tc-ppc.c32
-rw-r--r--gas/testsuite/gas/ppc/aix.exp4
-rw-r--r--gas/testsuite/gas/ppc/xcoff-tls-32.d106
-rw-r--r--gas/testsuite/gas/ppc/xcoff-tls-64.d124
-rw-r--r--gas/testsuite/gas/ppc/xcoff-tls.s57
-rw-r--r--gas/testsuite/gas/ppc/xcoff-tlsm-32.d34
-rw-r--r--gas/testsuite/gas/ppc/xcoff-tlsm-64.d36
-rw-r--r--gas/testsuite/gas/ppc/xcoff-tlsm.s12
8 files changed, 308 insertions, 97 deletions
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index c7af7b7..159d315 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -7426,22 +7426,25 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg)
case BFD_RELOC_PPC64_TLSM:
gas_assert (fixP->fx_addsy != NULL);
S_SET_THREAD_LOCAL (fixP->fx_addsy);
- fieldval = 0;
break;
- /* TLSML relocations are targeting a XMC_TC symbol named
- "_$TLSML". We can't check earlier because the relocation
- can target any symbol name which will be latter .rename
- to "_$TLSML". */
+ /* Officially, R_TLSML relocations must be from a TOC entry
+ targeting itself. In practice, this TOC entry is always
+ named (or .rename) "_$TLSML".
+ Thus, as it doesn't seem possible to retrieve the symbol
+ being relocated here, we simply check that the symbol
+ targeted by R_TLSML is indeed a TOC entry named "_$TLSML".
+ FIXME: Find a way to correctly check R_TLSML relocations
+ as described above. */
case BFD_RELOC_PPC_TLSML:
case BFD_RELOC_PPC64_TLSML:
gas_assert (fixP->fx_addsy != NULL);
- if (strcmp (symbol_get_tc (fixP->fx_addsy)->real_name, "_$TLSML") != 0)
- {
- as_bad_where (fixP->fx_file, fixP->fx_line,
- _("R_TLSML relocation doesn't target a "
- "symbol named \"_$TLSML\". %s"), S_GET_NAME(fixP->fx_addsy));
- }
+ if ((symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TC
+ || symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TE)
+ && strcmp (symbol_get_tc (fixP->fx_addsy)->real_name, "_$TLSML") != 0)
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("R_TLSML relocation doesn't target a "
+ "TOC entry named \"_$TLSML\": %s"), S_GET_NAME(fixP->fx_addsy));
fieldval = 0;
break;
@@ -7519,12 +7522,15 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg)
*valP = value;
}
else if (fixP->fx_r_type == BFD_RELOC_PPC_TLSM
- || fixP->fx_r_type == BFD_RELOC_PPC64_TLSM)
+ || fixP->fx_r_type == BFD_RELOC_PPC64_TLSM
+ || fixP->fx_r_type == BFD_RELOC_PPC_TLSML
+ || fixP->fx_r_type == BFD_RELOC_PPC64_TLSML)
/* 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));
+ - S_GET_VALUE (fixP->fx_addsy)
+ - fieldval);
else
fixP->fx_addnumber = 0;
#endif
diff --git a/gas/testsuite/gas/ppc/aix.exp b/gas/testsuite/gas/ppc/aix.exp
index 85ed06e..78f29f0 100644
--- a/gas/testsuite/gas/ppc/aix.exp
+++ b/gas/testsuite/gas/ppc/aix.exp
@@ -79,8 +79,8 @@ 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"
+ run_dump_test "xcoff-tls-32"
+ run_dump_test "xcoff-tls-64"
run_dump_test "xcoff-stsym-32"
run_dump_test "xcoff-stsym-64"
diff --git a/gas/testsuite/gas/ppc/xcoff-tls-32.d b/gas/testsuite/gas/ppc/xcoff-tls-32.d
new file mode 100644
index 0000000..eb71df0
--- /dev/null
+++ b/gas/testsuite/gas/ppc/xcoff-tls-32.d
@@ -0,0 +1,106 @@
+#as: -a32
+#source: xcoff-tls.s
+#objdump: -Dr
+#name: XCOFF TLS relocation (32 bit)
+
+.*
+Disassembly of section .data:
+
+00000000 <TOC>:
+ 0: 00 00 00 58.*
+ 0: R_TLS tdata_ext.*
+
+00000004 <.tdata_ext_gd>:
+ 4: 00 00 00 00.*
+ 4: R_TLSM tdata_ext.*
+
+00000008 <tdata_ext_ld>:
+ 8: 00 00 00 58.*
+ 8: R_TLS_LD tdata_ext.*
+
+0000000c <tdata_ext_ie>:
+ c: 00 00 00 58.*
+ c: R_TLS_IE tdata_ext.*
+
+00000010 <tdata_ext_le>:
+ 10: 00 00 00 58.*
+ 10: R_TLS_LE tdata_ext.*
+
+00000014 <tdata_int1_gd>:
+ 14: 00 00 00 5c.*
+ 14: R_TLS tdata_int_csect.*
+
+00000018 <.tdata_int1_gd>:
+ 18: 00 00 00 00.*
+ 18: R_TLSM tdata_int_csect.*
+
+0000001c <tdata_int1_ld>:
+ 1c: 00 00 00 5c.*
+ 1c: R_TLS_LD tdata_int_csect.*
+
+00000020 <tdata_int1_ie>:
+ 20: 00 00 00 5c.*
+ 20: R_TLS_IE tdata_int_csect.*
+
+00000024 <tdata_int1_le>:
+ 24: 00 00 00 5c.*
+ 24: R_TLS_LE tdata_int_csect.*
+
+00000028 <tdata_int2_gd>:
+ 28: 00 00 00 60.*
+ 28: R_TLS tdata_int_csect.*
+
+0000002c <.tdata_int2_gd>:
+ 2c: 00 00 00 00.*
+ 2c: R_TLSM tdata_int_csect.*
+
+00000030 <tdata_int2_ld>:
+ 30: 00 00 00 60.*
+ 30: R_TLS_LD tdata_int_csect.*
+
+00000034 <tdata_int2_ie>:
+ 34: 00 00 00 60.*
+ 34: R_TLS_IE tdata_int_csect.*
+
+00000038 <tdata_int2_le>:
+ 38: 00 00 00 60.*
+ 38: R_TLS_LE tdata_int_csect.*
+
+0000003c <tbss_ext_gd>:
+ 3c: 00 00 00 68.*
+ 3c: R_TLS tbss_ext.*
+
+00000040 <.tbss_ext_gd>:
+ 40: 00 00 00 00.*
+ 40: R_TLSM tbss_ext.*
+
+00000044 <tbss_ext_ld>:
+ 44: 00 00 00 68.*
+ 44: R_TLS_LD tbss_ext.*
+
+00000048 <tbss_ext_ie>:
+ 48: 00 00 00 68.*
+ 48: R_TLS_IE tbss_ext.*
+
+0000004c <tbss_ext_le>:
+ 4c: 00 00 00 68.*
+ 4c: R_TLS_LE tbss_ext.*
+
+00000050 <_\$TLSML>:
+ ...
+ 50: R_TLSML _\$TLSML.*
+
+Disassembly of section .tdata:
+
+00000058 <tdata_ext>:
+ 58: 00 00 00 01 .long 0x1
+
+0000005c <tdata_int_csect>:
+ 5c: 00 00 00 02 .long 0x2
+ 60: 00 00 00 03 .long 0x3
+ 64:.*
+
+Disassembly of section .tbss:
+
+00000068 <tbss_ext>:
+ ...
diff --git a/gas/testsuite/gas/ppc/xcoff-tls-64.d b/gas/testsuite/gas/ppc/xcoff-tls-64.d
new file mode 100644
index 0000000..7f3b6eb
--- /dev/null
+++ b/gas/testsuite/gas/ppc/xcoff-tls-64.d
@@ -0,0 +1,124 @@
+#as: -a64
+#source: xcoff-tls.s
+#objdump: -Dr
+#name: XCOFF TLS relocation (64 bit)
+
+.*
+
+
+Disassembly of section .data:
+
+0000000000000000 <TOC>:
+ 0: 00 00 00 00.*
+ 0: R_TLS tdata_ext.*
+ 4: 00 00 00 a8.*
+
+0000000000000008 <.tdata_ext_gd>:
+ ...
+ 8: R_TLSM tdata_ext.*
+
+0000000000000010 <tdata_ext_ld>:
+ 10: 00 00 00 00.*
+ 10: R_TLS_LD tdata_ext.*
+ 14: 00 00 00 a8.*
+
+0000000000000018 <tdata_ext_ie>:
+ 18: 00 00 00 00.*
+ 18: R_TLS_IE tdata_ext.*
+ 1c: 00 00 00 a8.*
+
+0000000000000020 <tdata_ext_le>:
+ 20: 00 00 00 00.*
+ 20: R_TLS_LE tdata_ext.*
+ 24: 00 00 00 a8.*
+
+0000000000000028 <tdata_int1_gd>:
+ 28: 00 00 00 00.*
+ 28: R_TLS tdata_int_csect.*
+ 2c: 00 00 00 ac.*
+
+0000000000000030 <.tdata_int1_gd>:
+ ...
+ 30: R_TLSM tdata_int_csect.*
+
+0000000000000038 <tdata_int1_ld>:
+ 38: 00 00 00 00.*
+ 38: R_TLS_LD tdata_int_csect.*
+ 3c: 00 00 00 ac.*
+
+0000000000000040 <tdata_int1_ie>:
+ 40: 00 00 00 00.*
+ 40: R_TLS_IE tdata_int_csect.*
+ 44: 00 00 00 ac.*
+
+0000000000000048 <tdata_int1_le>:
+ 48: 00 00 00 00.*
+ 48: R_TLS_LE tdata_int_csect.*
+ 4c: 00 00 00 ac.*
+
+0000000000000050 <tdata_int2_gd>:
+ 50: 00 00 00 00.*
+ 50: R_TLS tdata_int_csect.*
+ 54: 00 00 00 b0.*
+
+0000000000000058 <.tdata_int2_gd>:
+ ...
+ 58: R_TLSM tdata_int_csect.*
+
+0000000000000060 <tdata_int2_ld>:
+ 60: 00 00 00 00.*
+ 60: R_TLS_LD tdata_int_csect.*
+ 64: 00 00 00 b0.*
+
+0000000000000068 <tdata_int2_ie>:
+ 68: 00 00 00 00.*
+ 68: R_TLS_IE tdata_int_csect.*
+ 6c: 00 00 00 b0.*
+
+0000000000000070 <tdata_int2_le>:
+ 70: 00 00 00 00.*
+ 70: R_TLS_LE tdata_int_csect.*
+ 74: 00 00 00 b0.*
+
+0000000000000078 <tbss_ext_gd>:
+ 78: 00 00 00 00.*
+ 78: R_TLS tbss_ext.*
+ 7c: 00 00 00 b8.*
+
+0000000000000080 <.tbss_ext_gd>:
+ ...
+ 80: R_TLSM tbss_ext.*
+
+0000000000000088 <tbss_ext_ld>:
+ 88: 00 00 00 00.*
+ 88: R_TLS_LD tbss_ext.*
+ 8c: 00 00 00 b8.*
+
+0000000000000090 <tbss_ext_ie>:
+ 90: 00 00 00 00.*
+ 90: R_TLS_IE tbss_ext.*
+ 94: 00 00 00 b8.*
+
+0000000000000098 <tbss_ext_le>:
+ 98: 00 00 00 00.*
+ 98: R_TLS_LE tbss_ext.*
+ 9c: 00 00 00 b8.*
+
+00000000000000a0 <_\$TLSML>:
+ ...
+ a0: R_TLSML _\$TLSML-0xa0
+
+Disassembly of section .tdata:
+
+00000000000000a8 <tdata_ext>:
+ a8: 00 00 00 01 .long 0x1
+
+00000000000000ac <tdata_int_csect>:
+ ac: 00 00 00 02 .long 0x2
+ b0: 00 00 00 03 .long 0x3
+ b4:.*
+
+Disassembly of section .tbss:
+
+00000000000000b8 <tbss_ext>:
+ ...
diff --git a/gas/testsuite/gas/ppc/xcoff-tls.s b/gas/testsuite/gas/ppc/xcoff-tls.s
new file mode 100644
index 0000000..83e77f1
--- /dev/null
+++ b/gas/testsuite/gas/ppc/xcoff-tls.s
@@ -0,0 +1,57 @@
+# An external tdata symbol
+ .globl tdata_ext[TL]
+ .csect tdata_ext[TL]
+ .long 1
+
+ .csect tdata_int_csect[TL]
+# A first internal tdata symbol
+tdata_int1:
+ .long 2
+# A second internal tdata symbol
+tdata_int2:
+ .long 3
+
+# Two external tbss symbols.
+# XCOFF doesn't seem to allow internal tbss
+# (or bss) symbols.
+ .comm tbss_ext[UL],8
+
+ .toc
+# TC entries targeting the external tdata symbol
+# Their value should be "tdata_ext" address,
+# except TLSM value which must be 0.
+# Their relocations should target it.
+ .tc tdata_ext_gd[TC],tdata_ext[TL]
+ .tc .tdata_ext_gd[TC],tdata_ext[TL]@m
+ .tc tdata_ext_ld[TC],tdata_ext[TL]@ld
+ .tc tdata_ext_ie[TC],tdata_ext[TL]@ie
+ .tc tdata_ext_le[TC],tdata_ext[TL]@le
+
+# TC entries targeting internal tdata symbols.
+# Their value should be "tdata_int1" or "tdata_int2"
+# addresses, except TLSM value which must be 0.
+# Their relocations should target "tdata_int_csect".
+ .tc tdata_int1_gd[TC],tdata_int1
+ .tc .tdata_int1_gd[TC],tdata_int1@m
+ .tc tdata_int1_ld[TC],tdata_int1@ld
+ .tc tdata_int1_ie[TC],tdata_int1@ie
+ .tc tdata_int1_le[TC],tdata_int1@le
+ .tc tdata_int2_gd[TC],tdata_int2
+ .tc .tdata_int2_gd[TC],tdata_int2@m
+ .tc tdata_int2_ld[TC],tdata_int2@ld
+ .tc tdata_int2_ie[TC],tdata_int2@ie
+ .tc tdata_int2_le[TC],tdata_int2@le
+
+# TC entries targeting the external tdata symbol
+# Their value should be "tbss_ext" address,
+# except TLSM value which must be 0.
+# Their relocations should target "tbss_ext".
+ .tc tbss_ext_gd[TC],tbss_ext[UL]
+ .tc .tbss_ext_gd[TC],tbss_ext[UL]@m
+ .tc tbss_ext_ld[TC],tbss_ext[UL]@ld
+ .tc tbss_ext_ie[TC],tbss_ext[UL]@ie
+ .tc tbss_ext_le[TC],tbss_ext[UL]@le
+
+# Module entry
+ .tc mh[TC],mh[TC]@ml
+.rename mh[TC], "_$TLSML" # Symbol for the module handle
diff --git a/gas/testsuite/gas/ppc/xcoff-tlsm-32.d b/gas/testsuite/gas/ppc/xcoff-tlsm-32.d
deleted file mode 100644
index a09dd1a..0000000
--- a/gas/testsuite/gas/ppc/xcoff-tlsm-32.d
+++ /dev/null
@@ -1,34 +0,0 @@
-#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
deleted file mode 100644
index f447a51..0000000
--- a/gas/testsuite/gas/ppc/xcoff-tlsm-64.d
+++ /dev/null
@@ -1,36 +0,0 @@
-#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
deleted file mode 100644
index 0c857bf..0000000
--- a/gas/testsuite/gas/ppc/xcoff-tlsm.s
+++ /dev/null
@@ -1,12 +0,0 @@
- .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