From 3be08ea4728b56d35e136af4e6fd3086ade17764 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Thu, 3 May 2018 17:17:46 +0100 Subject: BFD: Prevent writing the MIPS _gp_disp symbol into symbol tables The _gp_disp is a magic symbol, always implicitly defined by the linker. It does not make a sense to write it into symbol tables for output files. Moreover, now if the linker gets a version script, the _gp_disp symbol gets zero version definition index. The zero index means[1]: "The symbol is local, not available outside the object." But the _gp_disp symbol has GLOBAL binding. That confuses some tools like for example the LLD linker when they get such files as inputs. This patch fixes the problem - it prevents writing the _gp_disp symbol in regular and dynamic symbol tables. This was tested by running LD test suite on a mipsel-linux board. References: [1] "Linux Standard Base Specification", Section "10.7.2 Symbol Version Table", p. 32 2018-05-03 Simon Atanasyan bfd/ * elf32-mips.c: (elf32_mips_fixup_symbol): New function. (elf_backend_fixup_symbol): New macro. * elfxx-mips.c: (mips_elf_output_extsym): Discard _gp_disp handling. (_bfd_mips_elf_finish_dynamic_symbol): Likewise. ld/ * testsuite/ld-mips-elf/gp-disp-sym.d: New test. * testsuite/ld-mips-elf/gp-disp-sym.s: New test source. * testsuite/ld-mips-elf/mips-elf.exp: Run the new test. * testsuite/ld-mips-elf/mips16-pic-2.ad: Update for _gp_disp symbol removal. * testsuite/ld-mips-elf/mips16-pic-2.nd: Likewise. * testsuite/ld-mips-elf/pic-and-nonpic-3a.dd: Likewise. * testsuite/ld-mips-elf/tlslib-o32-hidden.got: Likewise. * testsuite/ld-mips-elf/tlslib-o32-ver.got: Likewise. * testsuite/ld-mips-elf/tlslib-o32.got: Likewise. --- ld/ChangeLog | 13 +++++++++++++ ld/testsuite/ld-mips-elf/gp-disp-sym.d | 9 +++++++++ ld/testsuite/ld-mips-elf/gp-disp-sym.s | 5 +++++ ld/testsuite/ld-mips-elf/mips-elf.exp | 4 ++++ ld/testsuite/ld-mips-elf/mips16-pic-2.ad | 4 ++-- ld/testsuite/ld-mips-elf/mips16-pic-2.nd | 10 +++++----- ld/testsuite/ld-mips-elf/pic-and-nonpic-3a.dd | 2 +- ld/testsuite/ld-mips-elf/tlslib-o32-hidden.got | 10 +++++----- ld/testsuite/ld-mips-elf/tlslib-o32-ver.got | 12 ++++++------ ld/testsuite/ld-mips-elf/tlslib-o32.got | 12 ++++++------ 10 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 ld/testsuite/ld-mips-elf/gp-disp-sym.d create mode 100644 ld/testsuite/ld-mips-elf/gp-disp-sym.s (limited to 'ld') diff --git a/ld/ChangeLog b/ld/ChangeLog index d11cd06..55daa0d 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,16 @@ +2018-05-03 Simon Atanasyan + + * testsuite/ld-mips-elf/gp-disp-sym.d: New test. + * testsuite/ld-mips-elf/gp-disp-sym.s: New test source. + * testsuite/ld-mips-elf/mips-elf.exp: Run the new test. + * testsuite/ld-mips-elf/mips16-pic-2.ad: Update for _gp_disp + symbol removal. + * testsuite/ld-mips-elf/mips16-pic-2.nd: Likewise. + * testsuite/ld-mips-elf/pic-and-nonpic-3a.dd: Likewise. + * testsuite/ld-mips-elf/tlslib-o32-hidden.got: Likewise. + * testsuite/ld-mips-elf/tlslib-o32-ver.got: Likewise. + * testsuite/ld-mips-elf/tlslib-o32.got: Likewise. + 2018-04-27 Maciej W. Rozycki * testsuite/ld-mips-elf/bal-jalx-pic.d: Only run for diff --git a/ld/testsuite/ld-mips-elf/gp-disp-sym.d b/ld/testsuite/ld-mips-elf/gp-disp-sym.d new file mode 100644 index 0000000..00f19cc --- /dev/null +++ b/ld/testsuite/ld-mips-elf/gp-disp-sym.d @@ -0,0 +1,9 @@ +#name: MIPS _gp_disp removal from symbol tables +#ld: -shared +#objdump: -tT +#target: [check_shared_lib_support] + +#failif +#... +.*_gp_disp +#pass diff --git a/ld/testsuite/ld-mips-elf/gp-disp-sym.s b/ld/testsuite/ld-mips-elf/gp-disp-sym.s new file mode 100644 index 0000000..c6380ba --- /dev/null +++ b/ld/testsuite/ld-mips-elf/gp-disp-sym.s @@ -0,0 +1,5 @@ + .global foo + .text +foo: + lui $t0, %hi(_gp_disp) + addi $t0, $t0, %lo(_gp_disp) diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp index 95d677e..6668e22 100644 --- a/ld/testsuite/ld-mips-elf/mips-elf.exp +++ b/ld/testsuite/ld-mips-elf/mips-elf.exp @@ -1255,3 +1255,7 @@ run_dump_test "mips-abiflags-1" run_dump_test "mips-abiflags-1r" run_dump_test "mips-abiflags-2" run_dump_test "mips-abiflags-2r" + +# Test that _gp_disp symbol is not present in symbol tables. +run_dump_test "gp-disp-sym" [list [list as $abi_asflags(o32)] \ + [list ld $abi_ldflags(o32)]] diff --git a/ld/testsuite/ld-mips-elf/mips16-pic-2.ad b/ld/testsuite/ld-mips-elf/mips16-pic-2.ad index 52d3ea4..689f0c2 100644 --- a/ld/testsuite/ld-mips-elf/mips16-pic-2.ad +++ b/ld/testsuite/ld-mips-elf/mips16-pic-2.ad @@ -1,6 +1,6 @@ # [MIPS_GOTSYM, MIPS_SYMTABNO) covers used4...used7. #... - .* \(MIPS_SYMTABNO\) * 8 + .* \(MIPS_SYMTABNO\) * 7 #... - .* \(MIPS_GOTSYM\) * 0x4 + .* \(MIPS_GOTSYM\) * 0x3 #pass diff --git a/ld/testsuite/ld-mips-elf/mips16-pic-2.nd b/ld/testsuite/ld-mips-elf/mips16-pic-2.nd index bc2cd38..a2a5794 100644 --- a/ld/testsuite/ld-mips-elf/mips16-pic-2.nd +++ b/ld/testsuite/ld-mips-elf/mips16-pic-2.nd @@ -1,9 +1,9 @@ # used8 should come before MIPS_GOTSYM. #... - +3: 000405bc +36 +FUNC +GLOBAL +DEFAULT .* used8 - +4: 00040574 +36 +FUNC +GLOBAL +DEFAULT .* used6 - +5: 00040598 +36 +FUNC +GLOBAL +DEFAULT .* used7 - +6: 00040550 +36 +FUNC +GLOBAL +DEFAULT .* used5 - +7: 0004052c +36 +FUNC +GLOBAL +DEFAULT .* used4 + +2: 000405bc +36 +FUNC +GLOBAL +DEFAULT .* used8 + +3: 00040574 +36 +FUNC +GLOBAL +DEFAULT .* used6 + +4: 00040598 +36 +FUNC +GLOBAL +DEFAULT .* used7 + +5: 00040550 +36 +FUNC +GLOBAL +DEFAULT .* used5 + +6: 0004052c +36 +FUNC +GLOBAL +DEFAULT .* used4 #pass diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-3a.dd b/ld/testsuite/ld-mips-elf/pic-and-nonpic-3a.dd index 3dcfe12..b286f13 100644 --- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-3a.dd +++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-3a.dd @@ -35,5 +35,5 @@ Disassembly of section \.MIPS\.stubs: c00: 8f998010 lw t9,-32752\(gp\) c04: 03e07825 move t7,ra c08: 0320f809 jalr t9 - c0c: 24180005 li t8,5 + c0c: 24180004 li t8,4 \.\.\. diff --git a/ld/testsuite/ld-mips-elf/tlslib-o32-hidden.got b/ld/testsuite/ld-mips-elf/tlslib-o32-hidden.got index 563d8bb..a746031 100644 --- a/ld/testsuite/ld-mips-elf/tlslib-o32-hidden.got +++ b/ld/testsuite/ld-mips-elf/tlslib-o32-hidden.got @@ -4,11 +4,11 @@ DYNAMIC RELOCATION RECORDS OFFSET TYPE VALUE 00000000 R_MIPS_NONE \*ABS\* -000403bc R_MIPS_TLS_TPREL32 \*ABS\* -000403c0 R_MIPS_TLS_DTPMOD32 \*ABS\* -000403c8 R_MIPS_TLS_DTPMOD32 \*ABS\* +0004039c R_MIPS_TLS_TPREL32 \*ABS\* +000403a0 R_MIPS_TLS_DTPMOD32 \*ABS\* +000403a8 R_MIPS_TLS_DTPMOD32 \*ABS\* Contents of section .got: - 403b0 00000000 80000000 00000380 00000008 ................ - 403c0 00000000 ffff8004 00000000 00000000 ................ + 40390 00000000 80000000 00000360 00000008 ................ + 403a0 00000000 ffff8004 00000000 00000000 ................ diff --git a/ld/testsuite/ld-mips-elf/tlslib-o32-ver.got b/ld/testsuite/ld-mips-elf/tlslib-o32-ver.got index e675f9f..17a6385 100644 --- a/ld/testsuite/ld-mips-elf/tlslib-o32-ver.got +++ b/ld/testsuite/ld-mips-elf/tlslib-o32-ver.got @@ -4,12 +4,12 @@ DYNAMIC RELOCATION RECORDS OFFSET TYPE VALUE 00000000 R_MIPS_NONE \*ABS\* -000404d8 R_MIPS_TLS_DTPMOD32 \*ABS\* -000404d0 R_MIPS_TLS_DTPMOD32 tlsvar_gd@@VER_1 -000404d4 R_MIPS_TLS_DTPREL32 tlsvar_gd@@VER_1 -000404cc R_MIPS_TLS_TPREL32 tlsvar_ie@@VER_1 +000404b8 R_MIPS_TLS_DTPMOD32 \*ABS\* +000404b0 R_MIPS_TLS_DTPMOD32 tlsvar_gd@@VER_1 +000404b4 R_MIPS_TLS_DTPREL32 tlsvar_gd@@VER_1 +000404ac R_MIPS_TLS_TPREL32 tlsvar_ie@@VER_1 Contents of section .got: - 404c0 00000000 80000000 00000490 00000000 ................ - 404d0 00000000 00000000 00000000 00000000 ................ + 404a0 00000000 80000000 00000470 00000000 ................ + 404b0 00000000 00000000 00000000 00000000 ................ diff --git a/ld/testsuite/ld-mips-elf/tlslib-o32.got b/ld/testsuite/ld-mips-elf/tlslib-o32.got index ad90fb0..a389c30 100644 --- a/ld/testsuite/ld-mips-elf/tlslib-o32.got +++ b/ld/testsuite/ld-mips-elf/tlslib-o32.got @@ -4,12 +4,12 @@ tmpdir/tlslib-o32.so: file format elf32-tradbigmips DYNAMIC RELOCATION RECORDS OFFSET TYPE VALUE 00000000 R_MIPS_NONE \*ABS\* -00040448 R_MIPS_TLS_DTPMOD32 \*ABS\* -00040440 R_MIPS_TLS_DTPMOD32 tlsvar_gd -00040444 R_MIPS_TLS_DTPREL32 tlsvar_gd -0004043c R_MIPS_TLS_TPREL32 tlsvar_ie +00040428 R_MIPS_TLS_DTPMOD32 \*ABS\* +00040420 R_MIPS_TLS_DTPMOD32 tlsvar_gd +00040424 R_MIPS_TLS_DTPREL32 tlsvar_gd +0004041c R_MIPS_TLS_TPREL32 tlsvar_ie Contents of section .got: - 40430 00000000 80000000 00000400 00000000 ................ - 40440 00000000 00000000 00000000 00000000 ................ + 40410 00000000 80000000 000003e0 00000000 ................ + 40420 00000000 00000000 00000000 00000000 ................ -- cgit v1.1