From 15f6e0dac34a243341fba80f8ebdaeec78d766fe Mon Sep 17 00:00:00 2001 From: Ramana Radhakrishnan Date: Mon, 4 Jul 2016 09:06:02 +0000 Subject: [PATCH] [AArch64] Fix PR target/63874 In this PR we have a situation where we aren't really detecting weak references vs weak definitions. If one has a weak definition that binds locally there's no reason not to put out PC relative relocations. However if you have a genuine weak reference that is known not to bind locally it makes very little sense to put out an entry into the literal pool which doesn't always work with DSOs and shared objects. Tested aarch64-none-linux-gnu bootstrap and regression test with no regressions 2016-07-04 Ramana Radhakrishnan PR target/63874 * config/aarch64/aarch64.c (aarch64_classify_symbol): Fix typo in comment. Only force to memory if it is a weak external reference. 2016-07-04 Ramana Radhakrishnan PR target/63874 * gcc.target/aarch64/pr63874.c: New test. From-SVN: r237957 --- gcc/ChangeLog | 7 +++++++ gcc/config/aarch64/aarch64.c | 12 ++++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/aarch64/pr63874.c | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/pr63874.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d5abcd15a58..c021b34409b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-07-04 Ramana Radhakrishnan + + PR target/63874 + * config/aarch64/aarch64.c (aarch64_classify_symbol): Fix + typo in comment. Only force to memory if it is a weak + external reference. + 2016-07-04 Matthew Wahab Jiong Wang diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 062899fbcc8..512ef10d158 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -9423,15 +9423,18 @@ aarch64_classify_symbol (rtx x, rtx offset) switch (aarch64_cmodel) { case AARCH64_CMODEL_TINY: - /* When we retreive symbol + offset address, we have to make sure + /* When we retrieve symbol + offset address, we have to make sure the offset does not cause overflow of the final address. But we have no way of knowing the address of symbol at compile time so we can't accurately say if the distance between the PC and symbol + offset is outside the addressible range of +/-1M in the TINY code model. So we rely on images not being greater than 1M and cap the offset at 1M and anything beyond 1M will have to - be loaded using an alternative mechanism. */ - if (SYMBOL_REF_WEAK (x) + be loaded using an alternative mechanism. Furthermore if the + symbol is a weak reference to something that isn't known to + resolve to a symbol in this module, then force to memory. */ + if ((SYMBOL_REF_WEAK (x) + && !aarch64_symbol_binds_local_p (x)) || INTVAL (offset) < -1048575 || INTVAL (offset) > 1048575) return SYMBOL_FORCE_TO_MEM; return SYMBOL_TINY_ABSOLUTE; @@ -9439,7 +9442,8 @@ aarch64_classify_symbol (rtx x, rtx offset) case AARCH64_CMODEL_SMALL: /* Same reasoning as the tiny code model, but the offset cap here is 4G. */ - if (SYMBOL_REF_WEAK (x) + if ((SYMBOL_REF_WEAK (x) + && !aarch64_symbol_binds_local_p (x)) || !IN_RANGE (INTVAL (offset), HOST_WIDE_INT_C (-4294967263), HOST_WIDE_INT_C (4294967264))) return SYMBOL_FORCE_TO_MEM; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 86c1b5d373b..23e010ed834 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-07-04 Ramana Radhakrishnan + + PR target/63874 + * gcc.target/aarch64/pr63874.c: New test. + 2016-07-04 Jan Beulich * g++.dg/header.c: New. diff --git a/gcc/testsuite/gcc.target/aarch64/pr63874.c b/gcc/testsuite/gcc.target/aarch64/pr63874.c new file mode 100644 index 00000000000..1a745a038a2 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr63874.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-skip-if "Not applicable for mcmodel=large" { aarch64*-*-* } { "-mcmodel=large" } { "" } } */ + +extern void __attribute__((weak)) foo_weakref (void); +void __attribute__((weak, noinline)) bar (void) +{ + return; +} +void (*f) (void); +void (*g) (void); + +int +main (void) +{ + f = &foo_weakref; + g = &bar; + return 0; +} + +/* { dg-final { scan-assembler-not "adr*foo_weakref" } } */ +/* { dg-final { scan-assembler-not "\\.(word|xword)\tbar" } } */ -- 2.30.2