Fix default_binds_local_p_2 for extern protected data
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Tue, 20 Oct 2015 09:37:27 +0000 (09:37 +0000)
committerSzabolcs Nagy <nsz@gcc.gnu.org>
Tue, 20 Oct 2015 09:37:27 +0000 (09:37 +0000)
gcc:

PR target/66912
* varasm.c (default_binds_local_p_2): Turn on extern_protected_data.

gcc/testsuite:

PR target/66912
* gcc.target/aarch64/pr66912.c: New.
* gcc.target/arm/pr66912.c: New.

From-SVN: r229024

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/pr66912.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/pr66912.c [new file with mode: 0644]
gcc/varasm.c

index 7f5cbf0c5a215ac02a3231fd67b925588e8a012d..e3206f43b6cb9c295b943fd994cc150bc193f7e0 100644 (file)
@@ -1,3 +1,8 @@
+2015-10-20  Szabolcs Nagy  <szabolcs.nagy@arm.com>
+
+       PR target/66912
+       * varasm.c (default_binds_local_p_2): Turn on extern_protected_data.
+
 2015-10-20  Arkadiusz Drabczyk  <arkadiusz@drabczyk.org>
 
        * doc/extend.texi: Update documentation WRT inline functions.
index 51fb89574d788e86b6ad90243a72e55ff2e7a453..4415ac38fe02e80337cc4c6db88046417d587a7b 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-20  Szabolcs Nagy  <szabolcs.nagy@arm.com>
+
+       PR target/66912
+       * gcc.target/aarch64/pr66912.c: New.
+       * gcc.target/arm/pr66912.c: New.
+
 2015-10-19  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        * gfortran.dg/pr67900.f90: New tests.
diff --git a/gcc/testsuite/gcc.target/aarch64/pr66912.c b/gcc/testsuite/gcc.target/aarch64/pr66912.c
new file mode 100644 (file)
index 0000000..b8aabcd
--- /dev/null
@@ -0,0 +1,42 @@
+/* { dg-do compile { target *-*-linux* } } */
+/* { dg-options "-O2 -fpic" } */
+
+__attribute__((visibility("protected")))
+int n_common;
+
+__attribute__((weak, visibility("protected")))
+int n_weak_common;
+
+__attribute__((visibility("protected")))
+int n_init = -1;
+
+__attribute__((weak, visibility("protected")))
+int n_weak_init = -1;
+
+int
+f1 ()
+{
+  /* { dg-final { scan-assembler ":got(page_lo15)?:n_common" } } */
+  return n_common;
+}
+
+int
+f2 ()
+{
+  /* { dg-final { scan-assembler ":got(page_lo15)?:n_weak_common" } } */
+  return n_weak_common;
+}
+
+int
+f3 ()
+{
+  /* { dg-final { scan-assembler ":got(page_lo15)?:n_init" } } */
+  return n_init;
+}
+
+int
+f4 ()
+{
+  /* { dg-final { scan-assembler ":got(page_lo15)?:n_weak_init" } } */
+  return n_weak_init;
+}
diff --git a/gcc/testsuite/gcc.target/arm/pr66912.c b/gcc/testsuite/gcc.target/arm/pr66912.c
new file mode 100644 (file)
index 0000000..27e4c45
--- /dev/null
@@ -0,0 +1,42 @@
+/* { dg-do compile { target *-*-linux* } } */
+/* { dg-options "-O2 -fpic" } */
+
+__attribute__((visibility("protected")))
+int n_common;
+
+__attribute__((weak, visibility("protected")))
+int n_weak_common;
+
+__attribute__((visibility("protected")))
+int n_init = -1;
+
+__attribute__((weak, visibility("protected")))
+int n_weak_init = -1;
+
+int
+f1 ()
+{
+  /* { dg-final { scan-assembler "\\.word\\tn_common\\(GOT\\)" } } */
+  return n_common;
+}
+
+int
+f2 ()
+{
+  /* { dg-final { scan-assembler "\\.word\\tn_weak_common\\(GOT\\)" } } */
+  return n_weak_common;
+}
+
+int
+f3 ()
+{
+  /* { dg-final { scan-assembler "\\.word\\tn_init\\(GOT\\)" } } */
+  return n_init;
+}
+
+int
+f4 ()
+{
+  /* { dg-final { scan-assembler "\\.word\\tn_weak_init\\(GOT\\)" } } */
+  return n_weak_init;
+}
index f1564bc4955f63cdfee160508fdfd02b4fdcf179..ff9d271d424a6269381576902bb4b6f6d0f6d71d 100644 (file)
@@ -6898,12 +6898,13 @@ default_binds_local_p (const_tree exp)
   return default_binds_local_p_3 (exp, flag_shlib != 0, true, false, false);
 }
 
-/* Similar to default_binds_local_p, but common symbol may be local.  */
+/* Similar to default_binds_local_p, but common symbol may be local and
+   extern protected data is non-local.  */
 
 bool
 default_binds_local_p_2 (const_tree exp)
 {
-  return default_binds_local_p_3 (exp, flag_shlib != 0, true, false,
+  return default_binds_local_p_3 (exp, flag_shlib != 0, true, true,
                                  !flag_pic);
 }