Add new plugin hooks to support querying section alignment and size.
[binutils-gdb.git] / gold / testsuite / relro_test.cc
index 1fc1b43887c2e77b43d8e5095ea6e16662dfaf37..f38a2674ab493f005fa71cc05ea894917ff4b9de 100644 (file)
@@ -1,6 +1,6 @@
 // relro_test.cc -- test -z relro for gold
 
-// Copyright 2008 Free Software Foundation, Inc.
+// Copyright (C) 2008-2016 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
 #include <stdint.h>
 #include <unistd.h>
 
+// This tests we were linked with a script.  If we were linked with a
+// script, relro currently does not work.
+
+extern char using_script[] __attribute__ ((weak));
+
 // This code is put into a shared library linked with -z relro.
 
 // i1 and i2 are not relro variables.
@@ -35,16 +40,22 @@ int i1 = 1;
 static int i2 = 2;
 
 // P1 is a global relro variable.
-int* const p1 = &i1;
+int* const p1 __attribute__ ((aligned(64))) = &i1;
 
 // P2 is a local relro variable.
-int* const p2 = &i2;
+int* const p2 __attribute__ ((aligned(64))) = &i2;
+
+// Add a TLS variable to make sure -z relro works correctly with TLS.
+__thread int i3 = 1;
 
 // Test symbol addresses.
 
 bool
 t1()
 {
+  if (using_script)
+    return true;
+
   void* i1addr = static_cast<void*>(&i1);
   void* i2addr = static_cast<void*>(&i2);
   const void* p1addr = static_cast<const void*>(&p1);
@@ -68,6 +79,7 @@ t1()
   assert(i1page != p2page);
   assert(i2page != p1page);
   assert(i2page != p2page);
+  assert(i3 == 1);
 
   return true;
 }
@@ -129,6 +141,9 @@ f2()
 bool
 t2()
 {
+  if (using_script)
+    return true;
+
   signal(SIGSEGV, sigsegv_handler);
   orig_terminate = std::set_terminate(terminate_handler);