]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Adjust TLS relaxation condition
authorMatthew Malcomson <matthew.malcomson@arm.com>
Fri, 5 Aug 2022 16:19:31 +0000 (17:19 +0100)
committerMatthew Malcomson <matthew.malcomson@arm.com>
Fri, 5 Aug 2022 16:50:11 +0000 (17:50 +0100)
commit8a4f850747b18a37417799831f9e477a1d367c7b
tree5e8f9af31d2694042ece3b56ef873d7d80ec94de
parentaeba84b166fb5f19eba1cf6a3efbc22661bba966
Adjust TLS relaxation condition

In aarch64_tls_transition_without_check and elfNN_aarch64_tls_relax we
choose whether to perform a relaxation to an IE access model or an LE
access model based on whether the symbol itself is marked as local (i.e.
`h == NULL`).

This is problematic in two ways.  The first is that sometimes a global
dynamic access can be relaxed to an initial exec access when creating a
shared library, and if that happens on a local symbol then we currently
relax it to a local exec access instead.  This usually does not happen
since we only relax an access if aarch64_can_relax_tls returns true and
aarch64_can_relax_tls does not have the same problem.  However, it can
happen when we have seen both an IE and GD access on the same symbol.
This case is exercised in the newly added testcase tls-relax-gd-ie-2.

The second problem is that deciding based on whether the symbol is local
misses the case when the symbol is global but is still non-interposable
and known to be located in the executable.  This happens on all global
symbols in executables.
This case is exercised in the newly added testcase tls-relax-ie-le-4.

Here we adjust the condition we base our relaxation on so that we relax
to local-exec if we are creating an executable and the relevant symbol
we're accessing is stored inside that executable.

Alongside that general fix, we adjust the existing exclusion parameters
for Morello relaxations.  Patches are in-flight to replace the existing
Morello TLS relocation handling with the more recent TLS ABI.  This
patch simply adjusts the existing handling to use a more robust method
to determine the case when a GD -> LE relaxation can be performed.

-- Updating tests for new relaxation criteria

Many of the tests added to check our relaxation to IE were implemented
by taking advantage of the fact that we did not relax a global symbol
defined in an executable.

Since a global symbol defined in an executable is still not
interposable, we know that a TLS version of such a symbol will be in the
main TLS block.  This means that we can perform a stronger relaxation on
such symbols and relax their accesses to a local-exec access.

Hence we have to update all tests that relied on the older suboptimal
decision making.

The two cases when we still would want to relax a general dynamic access
to an initial exec one are:
1) When in a shared library and accessing a symbol which we have already
   seen accessed with an initial exec access sequence.
2) When in an executable and accessing a symbol defined in a shared
   library.

Both of these require shared library support, which means that these
tests are now only available on targets with that.

I have chosen to switch the existing testcases from a plain executable
to one dynamically linked to a shared object as that doesn't require
changing the testcases quite so much (just requires accessing a
different variable rather than requiring adding another code sequence).

The tls-relax-all testcase was an outlier to the above approach, since
it included a general dynamic access to both a local and global symbol
and inspected for the difference accordingly.

This is the same logical change as
https://sourceware.org/pipermail/binutils/2022-July/121660.html
28 files changed:
bfd/elfnn-aarch64.c
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/relocs-ilp32.ld
ld/testsuite/ld-aarch64/relocs.ld
ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d
ld/testsuite/ld-aarch64/tls-relax-all.d
ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d
ld/testsuite/ld-aarch64/tls-relax-gd-ie.d
ld/testsuite/ld-aarch64/tls-relax-gd-ie.s
ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d
ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s
ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d
ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s
ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d
ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s
ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d
ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s
ld/testsuite/ld-aarch64/tls-sharedlib.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d
ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d
ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s
ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d
ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d
ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s