This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gold patch] Mark .tdata sections as RELRO


Gold does not put .tdata sections in the RELRO segment. As a result,
if a binary contains TLS, the RELRO segment will not begin at the same
offset as the LOAD segment, and strip will remove the RELRO segment
when rewriting the file. This patch fixes gold to put .tdata in the
RELRO segment.

Tested on x86_64. OK?

-cary


2012-05-11  Cary Coutant  <ccoutant@google.com>

	* layout.cc (Layout::make_output_section): Mark .tdata section
	as RELRO.
	* testsuite/relro_test.cc: Add a TLS variable.


Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.226
diff -u -p -r1.226 layout.cc
--- layout.cc	8 May 2012 18:00:02 -0000	1.226
+++ layout.cc	11 May 2012 22:49:39 -0000
@@ -1430,7 +1430,9 @@ Layout::make_output_section(const char*
     {
       if (type == elfcpp::SHT_PROGBITS)
 	{
-	  if (strcmp(name, ".data.rel.ro") == 0)
+	  if ((flags & elfcpp::SHF_TLS) != 0)
+	    is_relro = true;
+	  else if (strcmp(name, ".data.rel.ro") == 0)
 	    is_relro = true;
 	  else if (strcmp(name, ".data.rel.ro.local") == 0)
 	    {
Index: testsuite/relro_test.cc
===================================================================
RCS file: /cvs/src/src/gold/testsuite/relro_test.cc,v
retrieving revision 1.4
diff -u -p -r1.4 relro_test.cc
--- testsuite/relro_test.cc	16 Oct 2010 00:37:25 -0000	1.4
+++ testsuite/relro_test.cc	11 May 2012 22:49:39 -0000
@@ -45,6 +45,9 @@ int* const p1 __attribute__ ((aligned(64
 // P2 is a local relro variable.
 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
@@ -76,6 +79,7 @@ t1()
   assert(i1page != p2page);
   assert(i2page != p1page);
   assert(i2page != p2page);
+  assert(i3 == 1);

   return true;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]