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]

[PATCH] Issue a linker error if TLS sections are not adjacent


Hi,

Bad linker script may lead to TLS sections separated by non-TLS sections
in output.  This patch changes linker assert to a linker error to
provide better linker diagnosis.  OK for master?

Thanks.


H.J.
--
bfd/

	PR ld/16498
	* elf.c (_bfd_elf_map_sections_to_segments): Issue a linker error
	if TLS sections are not adjacent.

ld/testsuite/

	PR ld/16498
	* ld-elf/pr16498.d: New file.
	* ld-elf/pr16498.s: Likewise.
	* ld-elf/pr16498.d: Likewise.
---
 bfd/ChangeLog                 |  6 ++++++
 bfd/elf.c                     |  8 +++++++-
 ld/testsuite/ChangeLog        |  7 +++++++
 ld/testsuite/ld-elf/pr16498.d |  3 +++
 ld/testsuite/ld-elf/pr16498.s | 23 +++++++++++++++++++++++
 ld/testsuite/ld-elf/pr16498.t |  6 ++++++
 6 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-elf/pr16498.d
 create mode 100644 ld/testsuite/ld-elf/pr16498.s
 create mode 100644 ld/testsuite/ld-elf/pr16498.t

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 3996dfc..4f74e4b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2014-01-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/16498
+	* elf.c (_bfd_elf_map_sections_to_segments): Issue a linker error 
+	if TLS sections are not adjacent.
+
 2014-01-22  Alan Modra  <amodra@gmail.com>
 
 	* elflink.c (elf_link_add_object_symbols): Call minfo for --as-needed.
diff --git a/bfd/elf.c b/bfd/elf.c
index 3815e32..ece9038 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4119,7 +4119,13 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
 	  m->p_flags_valid = 1;
 	  for (i = 0; i < (unsigned int) tls_count; ++i)
 	    {
-	      BFD_ASSERT (first_tls->flags & SEC_THREAD_LOCAL);
+	      if ((first_tls->flags & SEC_THREAD_LOCAL) == 0)
+		{
+		  _bfd_error_handler
+		    (_("%B: TLS sections are not adjacent"), abfd);
+		  bfd_set_error (bfd_error_bad_value);
+		  goto error_return;
+		}
 	      m->sections[i] = first_tls;
 	      first_tls = first_tls->next;
 	    }
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index a269b07..c355dd5 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2014-01-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/16498
+	* ld-elf/pr16498.d: New file.
+	* ld-elf/pr16498.s: Likewise.
+	* ld-elf/pr16498.d: Likewise.
+
 2014-01-22  Alan Modra  <amodra@gmail.com>
 
 	* ld-scripts/pr14962-2.d: Correct target triple.
diff --git a/ld/testsuite/ld-elf/pr16498.d b/ld/testsuite/ld-elf/pr16498.d
new file mode 100644
index 0000000..f4ce024
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr16498.d
@@ -0,0 +1,3 @@
+#ld: -shared -T pr16498.t
+#error: .*: TLS sections are not adjacent
+#target: *-*-linux* *-*-gnu* *-*-nacl*
diff --git a/ld/testsuite/ld-elf/pr16498.s b/ld/testsuite/ld-elf/pr16498.s
new file mode 100644
index 0000000..77f80e6
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr16498.s
@@ -0,0 +1,23 @@
+	.globl	data
+	.data
+	.align 32
+	.type	data, %object
+	.size	data, 120
+data:
+	.long	1
+	.zero	116
+	.globl	foo
+	.section	.tbss,"awT",%nobits
+	.align 4
+	.type	foo, %object
+	.size	foo, 4
+foo:
+	.zero	4
+	.globl	bar
+	.section	.tdata,"awT",%progbits
+	.align 16
+	.type	bar, %object
+	.size	bar, 80
+bar:
+	.long	1
+	.zero	76
diff --git a/ld/testsuite/ld-elf/pr16498.t b/ld/testsuite/ld-elf/pr16498.t
new file mode 100644
index 0000000..928724f
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr16498.t
@@ -0,0 +1,6 @@
+SECTIONS
+{
+  .tdata  : { *(.tdata) }
+  .data	  : { *(.data)
+  }
+}
-- 
1.8.4.2


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