Bug 22263 - -fpie -pie generates dynamic relocations in text section
Summary: -fpie -pie generates dynamic relocations in text section
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.30
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 20179 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-10-05 10:27 UTC by H.J. Lu
Modified: 2019-10-10 11:29 UTC (History)
3 users (show)

See Also:
Host:
Target: tilegx,tilepro,sparc,alpha
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2017-10-05 10:27:07 UTC
[hjl@gnu-efi-2 build-tilepro-linux]$ cat x.c
__thread int * foo;

void
bar (void)
{
  *foo = 1;
}
[hjl@gnu-efi-2 build-tilepro-linux]$ cat y.c
extern __thread int *foo;
 
static int x;

extern void bar (void);

int
main ()
{
  foo = &x;
  return 0;
}
[hjl@gnu-efi-2 build-tilepro-linux]$ /export/gnu/import/git/toolchain/install/compilers/tilepro-linux-gnu/bin/tilepro-glibc-linux-gnu-gcc -pie -fpie x.c y.c -O2 -Wl,-z,text
/export/gnu/import/git/toolchain/install/compilers/tilepro-linux-gnu/lib/gcc/tilepro-glibc-linux-gnu/7.2.1/../../../../tilepro-glibc-linux-gnu/bin/ld: read-only segment has dynamic relocations.
collect2: error: ld returned 1 exit status
[hjl@gnu-efi-2 build-tilepro-linux]$
Comment 1 H.J. Lu 2017-10-08 00:28:44 UTC
The same thing happens on sparc:

[hjl@gnu-efi-2 pr22263]$ make
/export/gnu/import/git/toolchain/install/compilers/sparc64-linux-gnu/bin/sparc64-glibc-linux-gnu-gcc -fPIE -O2   -c -o x.o x.c
/export/gnu/import/git/toolchain/install/compilers/sparc64-linux-gnu/bin/sparc64-glibc-linux-gnu-gcc -fPIE -O2   -c -o y.o y.c
/export/gnu/import/git/toolchain/install/compilers/sparc64-linux-gnu/bin/sparc64-glibc-linux-gnu-gcc -pie -Wl,-z,text -o x x.o y.o
/export/gnu/import/git/toolchain/install/compilers/sparc64-linux-gnu/lib/gcc/sparc64-glibc-linux-gnu/7.2.1/../../../../sparc64-glibc-linux-gnu/bin/ld: read-only segment has dynamic relocations.
collect2: error: ld returned 1 exit status
make: *** [Makefile:16: x] Error 1
[hjl@gnu-efi-2 pr22263]$
Comment 2 H.J. Lu 2017-10-08 21:15:51 UTC
This is caused by incorrectly checking bfd_link_pic, which should check
bfd_link_executable instead.
Comment 3 H.J. Lu 2017-10-08 21:36:26 UTC
tilegx has the same issue:

[hjl@gnu-efi-2 pr22263]$ make
/export/gnu/import/git/toolchain/install/compilers/tilegx-linux-gnu/bin/tilegx-glibc-linux-gnu-gcc -fPIE -O2   -c -o x.o x.c
/export/gnu/import/git/toolchain/install/compilers/tilegx-linux-gnu/bin/tilegx-glibc-linux-gnu-gcc -fPIE -O2   -c -o y.o y.c
./ld -pie -z text -o x x.o y.o
./ld: read-only segment has dynamic relocations.
make: *** [Makefile:23: x] Error 1
[hjl@gnu-efi-2 pr22263]$
Comment 4 H.J. Lu 2017-10-08 22:06:44 UTC
*** Bug 20179 has been marked as a duplicate of this bug. ***
Comment 5 H.J. Lu 2017-10-12 21:07:54 UTC
alpha has the same issue.
Comment 6 cvs-commit@gcc.gnu.org 2017-10-12 21:56:07 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=74ffa566739c7e98568a9aa8b5ab8d8f3730d30d

commit 74ffa566739c7e98568a9aa8b5ab8d8f3730d30d
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Oct 12 14:41:22 2017 -0700

    Add a compile-time test for PR ld/22263
    
    This compile-time test requires a target C compiler to run.  It fails
    on many targets where ELF backend linkers incorrectly check bfd_link_pic
    for TLS relocations, which should check bfd_link_executable instead.
    
    	PR ld/22263
    	* testsuite/ld-elf/pr22263-1.rd: New file.
    	* testsuite/ld-elf/pr22263-1a.c: Likewise.
    	* testsuite/ld-elf/pr22263-1b.c: Likewise.
    	* testsuite/ld-elf/tls.exp: Likewise.
Comment 7 cvs-commit@gcc.gnu.org 2017-10-13 13:46:43 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=354bac403e9a19bbbfb676d854db5f11f0e84c27

commit 354bac403e9a19bbbfb676d854db5f11f0e84c27
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Oct 13 15:23:35 2017 +1030

    PR22263 testcase
    
    A number of targets need dynamic relocs in PIEs for reasons other than
    relocating thread variables.  The PR is about text relocations, and,
    reading between the lines, unnecessary dynamic tprel relocations.
    Change the test to check for those conditions rather than no dynamic
    relocations
    
    	PR ld/22263
    	* testsuite/ld-elf/tls.exp: Link with -z text.
    	* testsuite/ld-elf/pr22263-1.rd: Test for tprel relocs.
Comment 8 cvs-commit@gcc.gnu.org 2017-10-19 12:19:11 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0fb7012e88683b8bd67a4fb8f782359fa0e11724

commit 0fb7012e88683b8bd67a4fb8f782359fa0e11724
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Oct 19 05:18:07 2017 -0700

    sparc: Check bfd_link_executable for TLS check
    
    Copied from x86, check bfd_link_executable, instead of bfd_link_pic,
    for TLS transition check.  Not sure if it works correctly.  All usages
    of bfd_link_pic should be audited.
    
    	PR ld/22263
    	* elfxx-sparc.c (sparc_elf_tls_transition): Replace
    	bfd_link_pic with !bfd_link_executable, !bfd_link_pic with
    	bfd_link_executable for TLS check.
    	(_bfd_sparc_elf_check_relocs): Likewise.
    	(allocate_dynrelocs): Likewise.
    	(_bfd_sparc_elf_relocate_section): Likewise.
Comment 9 cvs-commit@gcc.gnu.org 2017-10-19 12:21:50 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1ba1f393faac96f6ad80499d7133df23d6187b8c

commit 1ba1f393faac96f6ad80499d7133df23d6187b8c
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Oct 19 05:20:44 2017 -0700

    tilepro: Check bfd_link_executable for TLS check
    
    Copied from x86, check bfd_link_executable, instead of bfd_link_pic,
    for TLS transition check.  Not sure if it works correctly.  All usages
    of bfd_link_pic should be audited.
    
    	PR ld/22263
    	* elf32-tilepro.c (tilepro_elf_tls_transition): Replace
    	bfd_link_pic with !bfd_link_executable, !bfd_link_pic with
    	bfd_link_executable for TLS check.
    	(tilepro_elf_check_relocs): Likewise.
    	(allocate_dynrelocs): Likewise.
    	(tilepro_elf_relocate_section): Likewise.
Comment 10 cvs-commit@gcc.gnu.org 2017-10-19 12:24:27 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=280958942b74f3164708700f195188c4d3446f58

commit 280958942b74f3164708700f195188c4d3446f58
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Oct 19 05:22:23 2017 -0700

    tilegx: Check bfd_link_executable for TLS check
    
    Copied from x86, check bfd_link_executable, instead of bfd_link_pic,
    for TLS transition check.  Not sure if it works correctly.  All usages
    of bfd_link_pic should be audited.
    
    	PR ld/22263
    	* elfxx-tilegx.c (tilegx_elf_tls_transition): Replace
    	bfd_link_pic with !bfd_link_executable, !bfd_link_pic with
    	bfd_link_executable for TLS check.
    	(tilegx_elf_check_relocs): Likewise.
    	(allocate_dynrelocs): Likewise.
    	(tilegx_elf_relocate_section): Likewise.
Comment 11 cvs-commit@gcc.gnu.org 2017-11-27 11:54:27 UTC
The master branch has been updated by Szabolcs Nagy <nsz@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6dda7875a8021787f11bd95a69d81a079e408a57

commit 6dda7875a8021787f11bd95a69d81a079e408a57
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Nov 15 17:40:04 2017 +0000

    [PR ld/22263] aarch64: Avoid dynamic TLS relocs in PIE
    
    No dynamic relocs are needed for TLS defined in an executable, the
    TP relative offset is known at link time.
    
    Fixes
    FAIL: Build pr22263-1
    
    bfd/
    	PR ld/22263
    	* elfnn-aarch64.c (elfNN_aarch64_relocate_section): Use
    	bfd_link_executable instead of bfd_link_pic for TLS.
    	(elfNN_aarch64_allocate_dynrelocs): Likewise.
    	(aarch64_can_relax_tls): Likewise.
Comment 12 cvs-commit@gcc.gnu.org 2018-01-25 11:21:17 UTC
The master branch has been updated by Eric Botcazou <ebotcazou@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bb363086e7743506d78bc6b1e56face0fb1fc93f

commit bb363086e7743506d78bc6b1e56face0fb1fc93f
Author: Eric Botcazou <ebotcazou@gcc.gnu.org>
Date:   Thu Jan 25 12:16:06 2018 +0100

    Fix PR ld/22727 (TLS breakage in PIC/PIE mode on SPARC).
    
    There are actually 2 different bugs:
     1. TLS transition is broken in PIE mode.
     2. TLS is broken in PIC/PIE mode when the __tls_get_addr symbol
        is versioned  (as is the case on Linux and Solaris at least).
    
    The 1st bug is fixed by reverting the problematic change for now
    (note that the associated test doesn't pass on SPARC because of another
    issue so there is  no formal regression in the testsuite). The 2nd bug
    is fixed by changing the  call to _bfd_generic_link_add_one_symbol
    on __tls_get_addr into a mere lookup in _bfd_sparc_elf_check_relocs.
    
    bfd/
    	* elfxx-sparc.c (_bfd_sparc_elf_check_relocs) <R_SPARC_TLS_GD_CALL>:
    	Do a mere lookup of the __tls_get_addr symbol instead of adding it.
    
    	Revert
    	2017-10-19  H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR ld/22263
    	* elfxx-sparc.c (sparc_elf_tls_transition): Replace
    	bfd_link_pic with !bfd_link_executable, !bfd_link_pic with
    	bfd_link_executable for TLS check.
    	(_bfd_sparc_elf_check_relocs): Likewise.
    	(allocate_dynrelocs): Likewise.
    	(_bfd_sparc_elf_relocate_section): Likewise.
    ld/
    	* testsuite/ld-sparc/sparc.exp (32-bit: Helper shared library):
    	Link with a version script.
    	(32-bit: TLS -fpie): New test.
    	(64-bit: Helper shared library): Link with a version script.
    	(64-bit: TLS -fpie): New test.
    	(64-bit: GOTDATA relocations): Pass -Av9 to the assembler.
    	* testsuite/ld-sparc/tlslib.ver: New file.
    	* testsuite/ld-sparc/tlspie32.dd: Likewise.
    	* testsuite/ld-sparc/tlspie32.s: Likewise.
    	* testsuite/ld-sparc/tlspie64.dd: Likewise.
    	* testsuite/ld-sparc/tlspie64.s: Likewise.
    	* testsuite/ld-sparc/tlssunbin32.dd: Adjust for versioned symbol.
    	* testsuite/ld-sparc/tlssunbin32.rd: Likewise.
    	* testsuite/ld-sparc/tlssunbin32.sd: Likewise.
    	* testsuite/ld-sparc/tlssunbin64.dd: Likewise.
    	* testsuite/ld-sparc/tlssunbin64.rd: Likewise.
    	* testsuite/ld-sparc/tlssunbin64.sd: Likewise.
Comment 13 cvs-commit@gcc.gnu.org 2018-01-25 11:31:58 UTC
The binutils-2_30-branch branch has been updated by Eric Botcazou <ebotcazou@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=220cf7e75d1e554d0a003e1c505a335ed663725e

commit 220cf7e75d1e554d0a003e1c505a335ed663725e
Author: Eric Botcazou <ebotcazou@gcc.gnu.org>
Date:   Thu Jan 25 12:16:06 2018 +0100

    Fix PR ld/22727 (TLS breakage in PIC/PIE mode on SPARC).
    
    There are actually 2 different bugs:
     1. TLS transition is broken in PIE mode.
     2. TLS is broken in PIC/PIE mode when the __tls_get_addr symbol
        is versioned  (as is the case on Linux and Solaris at least).
    
    The 1st bug is fixed by reverting the problematic change for now
    (note that the associated test doesn't pass on SPARC because of another
    issue so there is  no formal regression in the testsuite). The 2nd bug
    is fixed by changing the  call to _bfd_generic_link_add_one_symbol
    on __tls_get_addr into a mere lookup in _bfd_sparc_elf_check_relocs.
    
    bfd/
    	* elfxx-sparc.c (_bfd_sparc_elf_check_relocs) <R_SPARC_TLS_GD_CALL>:
    	Do a mere lookup of the __tls_get_addr symbol instead of adding it.
    
    	Revert
    	2017-10-19  H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR ld/22263
    	* elfxx-sparc.c (sparc_elf_tls_transition): Replace
    	bfd_link_pic with !bfd_link_executable, !bfd_link_pic with
    	bfd_link_executable for TLS check.
    	(_bfd_sparc_elf_check_relocs): Likewise.
    	(allocate_dynrelocs): Likewise.
    	(_bfd_sparc_elf_relocate_section): Likewise.
    ld/
    	* testsuite/ld-sparc/sparc.exp (32-bit: Helper shared library):
    	Link with a version script.
    	(32-bit: TLS -fpie): New test.
    	(64-bit: Helper shared library): Link with a version script.
    	(64-bit: TLS -fpie): New test.
    	(64-bit: GOTDATA relocations): Pass -Av9 to the assembler.
    	* testsuite/ld-sparc/tlslib.ver: New file.
    	* testsuite/ld-sparc/tlspie32.dd: Likewise.
    	* testsuite/ld-sparc/tlspie32.s: Likewise.
    	* testsuite/ld-sparc/tlspie64.dd: Likewise.
    	* testsuite/ld-sparc/tlspie64.s: Likewise.
    	* testsuite/ld-sparc/tlssunbin32.dd: Adjust for versioned symbol.
    	* testsuite/ld-sparc/tlssunbin32.rd: Likewise.
    	* testsuite/ld-sparc/tlssunbin32.sd: Likewise.
    	* testsuite/ld-sparc/tlssunbin64.dd: Likewise.
    	* testsuite/ld-sparc/tlssunbin64.rd: Likewise.
    	* testsuite/ld-sparc/tlssunbin64.sd: Likewise.
Comment 14 H.J. Lu 2018-01-31 21:20:19 UTC
*** Bug 22570 has been marked as a duplicate of this bug. ***
Comment 15 cvs-commit@gcc.gnu.org 2018-02-06 17:18:33 UTC
The master branch has been updated by Eric Botcazou <ebotcazou@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c20c30f615756ddfccc4bb75c65ccfc1a399466e

commit c20c30f615756ddfccc4bb75c65ccfc1a399466e
Author: Eric Botcazou <ebotcazou@gcc.gnu.org>
Date:   Tue Feb 6 18:15:56 2018 +0100

    Fix PR ld/22263 on SPARC.
    
    This is -fpie -pie generating dynamic relocations in the text section,
    simply because no TLS transitions are applied in PIE mode.  The meat
    of the patch is to turn calls to bfd_link_pic (info) in TLS-related code
    into !bfd_link_executable (info) and there are quite a lot of them...
    
    bfd/
    	* elfxx-sparc.c (sparc_elf_tls_transition): Turn call to bfd_link_pic
    	into call to !bfd_link_executable and tidy up.
    	(_bfd_sparc_elf_check_relocs): Fix formatting and tidy up.
    	<R_SPARC_TLS_LE_HIX22>: Turn call to bfd_link_pic into call to
    	!bfd_link_executable.
    	<R_SPARC_TLS_IE_HI22>: Likewise.
    	<GOT relocations>: Remove useless code, tidy and merge blocks.
    	<R_SPARC_TLS_GD_CALL>: Turn call to bfd_link_pic into call to
    	!bfd_link_executable.
    	<R_SPARC_WPLT30>: Tidy up.
    	(_bfd_sparc_elf_gc_mark_hook): Turn call to bfd_link_pic into call
    	to !bfd_link_executable.
    	(allocate_dynrelocs): Likewise.
    	(_bfd_sparc_elf_relocate_section): Fix formatting and tidy up.
    	<R_SPARC_TLS_GD_HI22>: Merge into...
    	<R_SPARC_TLS_GD_LO10>: ...this.  Adjust 4th argument in call to
    	sparc_elf_tls_transition and remove redundant code.
    	<R_SPARC_TLS_LDM_HI22>: Turn call to bfd_link_pic into call to
    	!bfd_link_executable.
    	<R_SPARC_TLS_LDO_HIX22>: Likewise.
    	<R_SPARC_TLS_LE_HIX22>: Likewise.  Tidy up.
    	<R_SPARC_TLS_LDM_CALL>: Likewise.
    	<R_SPARC_TLS_GD_CALL>: Likewise.  Tidy up.
    	<R_SPARC_TLS_GD_ADD>: Likewise.
    	<R_SPARC_TLS_LDM_ADD>: Likewise.
    	<R_SPARC_TLS_LDO_ADD>: Likewise.
    	<R_SPARC_TLS_IE_LD>: Likewise.
    ld/
    	* testsuite/ld-elf/tls.exp (AFLAGS_PIC): Define on SPARC.
    	(pr22263-1): Pass AFLAGS_PIC to the assembler.
    	* testsuite/ld-sparc/tlspie32.s: Add test for other 3 transitions.
    	* testsuite/ld-sparc/tlspie32.dd: Adjust to above.
    	* testsuite/ld-sparc/tlspie64.s: Add test for other 3 transitions.
    	* testsuite/ld-sparc/tlspie64.dd: Adjust to above.
Comment 16 Khem Raj 2018-07-03 13:13:32 UTC
this bug is present in mips ld too
Comment 17 Rich Felker 2018-07-03 14:37:25 UTC
Yes, see #22570 in the list of duplicates, which includes a proposed patch for MIPS.
Comment 18 cvs-commit@gcc.gnu.org 2018-11-27 12:43:38 UTC
The master branch has been updated by Tamar Christina <tnfchris@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9fca35fc3486283562a7fcd9eb0ff845b0152d98

commit 9fca35fc3486283562a7fcd9eb0ff845b0152d98
Author: Tamar Christina <tamar.christina@arm.com>
Date:   Tue Nov 27 12:33:21 2018 +0000

    AArch64: Fix regression in Cortex A53 erratum when PIE. (PR ld/23904)
    
    The fix for PR ld/22263 causes TLS relocations using ADRP to be relaxed
    into MOVZ, however this causes issues for the erratum code.
    
    The erratum code scans the input sections looking for ADRP instructions
    and notes their location in the stream.
    
    It then later tries to find them again in order to generate the linker
    stubs.  Due to the relaxation it instead finds a MOVZ and hard aborts.
    
    Since this relaxation is a valid one, and in which case the erratum no
    longer applies, it shouldn't abort but instead just continue.
    
    This changes the TLS relaxation code such that when it finds an ADRP and
    it relaxes it, it removes the erratum entry from the work list by changing
    the stub type into none so the stub is ignored.
    
    The entry is not actually removed as removal is a more expensive operation
    and we have already allocated the memory anyway.
    
    The clearing is done for IE->LE and GD->LE relaxations, and a testcase is
    added for the IE case. The GD case I believe to be impossible to get together
    with the erratum sequence due to the required BL which would break the sequence.
    However to cover all basis I have added the guard there as well.
    
    build on native hardware and regtested on
      aarch64-none-elf, aarch64-none-elf (32 bit host),
      aarch64-none-linux-gnu, aarch64-none-linux-gnu (32 bit host)
    
    Cross-compiled and regtested on
      aarch64-none-linux-gnu, aarch64_be-none-linux-gnu
    
    Testcase in PR23940 tested and works as expected now and benchmarks ran on A53
    showing no regressions and no issues.
    
    bfd/ChangeLog:
    
    	PR ld/23904
    	* elfnn-aarch64.c (_bfd_aarch64_adrp_p): Use existing constants.
    	(_bfd_aarch64_erratum_843419_branch_to_stub): Use _bfd_aarch64_adrp_p.
    	(struct erratum_835769_branch_to_stub_clear_data): New.
    	(_bfd_aarch64_erratum_843419_clear_stub): New.
    	(clear_erratum_843419_entry): New.
    	(elfNN_aarch64_tls_relax): Use it.
    	(elfNN_aarch64_relocate_section): Pass input_section.
    	(aarch64_map_one_stub): Handle branch type none as valid.
    
    ld/ChangeLog:
    
    	PR ld/23904
    	* testsuite/ld-aarch64/aarch64-elf.exp: Add erratum843419_tls_ie.
    	* testsuite/ld-aarch64/erratum843419_tls_ie.d: New test.
    	* testsuite/ld-aarch64/erratum843419_tls_ie.s: New test.
Comment 19 cvs-commit@gcc.gnu.org 2018-11-27 12:54:23 UTC
The binutils-2_31-branch branch has been updated by Tamar Christina <tnfchris@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=513092d696472fc06cf7812e14160e16b2da5286

commit 513092d696472fc06cf7812e14160e16b2da5286
Author: Tamar Christina <tamar.christina@arm.com>
Date:   Tue Nov 27 12:33:21 2018 +0000

    AArch64: Fix regression in Cortex A53 erratum when PIE. (PR ld/23904)
    
    The fix for PR ld/22263 causes TLS relocations using ADRP to be relaxed
    into MOVZ, however this causes issues for the erratum code.
    
    The erratum code scans the input sections looking for ADRP instructions
    and notes their location in the stream.
    
    It then later tries to find them again in order to generate the linker
    stubs.  Due to the relaxation it instead finds a MOVZ and hard aborts.
    
    Since this relaxation is a valid one, and in which case the erratum no
    longer applies, it shouldn't abort but instead just continue.
    
    This changes the TLS relaxation code such that when it finds an ADRP and
    it relaxes it, it removes the erratum entry from the work list by changing
    the stub type into none so the stub is ignored.
    
    The entry is not actually removed as removal is a more expensive operation
    and we have already allocated the memory anyway.
    
    The clearing is done for IE->LE and GD->LE relaxations, and a testcase is
    added for the IE case. The GD case I believe to be impossible to get together
    with the erratum sequence due to the required BL which would break the sequence.
    However to cover all basis I have added the guard there as well.
    
    build on native hardware and regtested on
      aarch64-none-elf, aarch64-none-elf (32 bit host),
      aarch64-none-linux-gnu, aarch64-none-linux-gnu (32 bit host)
    
    Cross-compiled and regtested on
      aarch64-none-linux-gnu, aarch64_be-none-linux-gnu
    
    Testcase in PR23940 tested and works as expected now and benchmarks ran on A53
    showing no regressions and no issues.
    
    bfd/ChangeLog:
    
    	PR ld/23904
    	* elfnn-aarch64.c (_bfd_aarch64_adrp_p): Use existing constants.
    	(_bfd_aarch64_erratum_843419_branch_to_stub): Use _bfd_aarch64_adrp_p.
    	(struct erratum_835769_branch_to_stub_clear_data): New.
    	(_bfd_aarch64_erratum_843419_clear_stub): New.
    	(clear_erratum_843419_entry): New.
    	(elfNN_aarch64_tls_relax): Use it.
    	(elfNN_aarch64_relocate_section): Pass input_section.
    	(aarch64_map_one_stub): Handle branch type none as valid.
    
    ld/ChangeLog:
    
    	PR ld/23904
    	* testsuite/ld-aarch64/aarch64-elf.exp: Add erratum843419_tls_ie.
    	* testsuite/ld-aarch64/erratum843419_tls_ie.d: New test.
    	* testsuite/ld-aarch64/erratum843419_tls_ie.s: New test.
    
    (cherry picked from commit 9fca35fc3486283562a7fcd9eb0ff845b0152d98)
Comment 20 cvs-commit@gcc.gnu.org 2019-10-04 09:58:42 UTC
The master branch has been updated by Szabolcs Nagy <nsz@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9cb09e33e04feb12df2aaa6e81d61b82ad609ce5

commit 9cb09e33e04feb12df2aaa6e81d61b82ad609ce5
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Oct 2 19:46:46 2019 +0100

    [PR ld/22263][PR ld/25056] arm: Avoid dynamic TLS relocs in PIE
    
    Dynamic relocs are only needed in an executable for TLS symbols if
    those are defined in an external module and even then TLS access
    can be relaxed to use IE model instead of GD.
    
    Several bfd_link_pic checks are turned into bfd_link_dll checks
    to fix TLS handling in PIE, for the same fix some other targets
    used !bfd_link_executable checks, but that includes relocatable
    objects so dll seems safer (in most cases either should work, since
    dynamic relocations are not applied in relocatable objects).
    
    On arm* fixes
    FAIL: Build pr22263-1
    
    bfd/
    
    	PR ld/22263
    	PR ld/25056
    	* elf32-arm.c (elf32_arm_tls_transition): Use bfd_link_dll instead of
    	bfd_link_pic for TLS checks.
    	(elf32_arm_final_link_relocate): Likewise.
    	(allocate_dynrelocs_for_symbol): Likewise.
Comment 21 cvs-commit@gcc.gnu.org 2019-10-10 11:29:10 UTC
The binutils-2_33-branch branch has been updated by Szabolcs Nagy <nsz@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b094948c0943c996460cbc9ab3c14207dc520445

commit b094948c0943c996460cbc9ab3c14207dc520445
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Oct 2 19:46:46 2019 +0100

    [PR ld/22263][PR ld/25056] arm: Avoid dynamic TLS relocs in PIE
    
    Dynamic relocs are only needed in an executable for TLS symbols if
    those are defined in an external module and even then TLS access
    can be relaxed to use IE model instead of GD.
    
    Several bfd_link_pic checks are turned into bfd_link_dll checks
    to fix TLS handling in PIE, for the same fix some other targets
    used !bfd_link_executable checks, but that includes relocatable
    objects so dll seems safer (in most cases either should work, since
    dynamic relocations are not applied in relocatable objects).
    
    On arm* fixes
    FAIL: Build pr22263-1
    
    bfd/
    
    	PR ld/22263
    	PR ld/25056
    	* elf32-arm.c (elf32_arm_tls_transition): Use bfd_link_dll instead of
    	bfd_link_pic for TLS checks.
    	(elf32_arm_final_link_relocate): Likewise.
    	(allocate_dynrelocs_for_symbol): Likewise.