From d923cae027fb7f86d6b684c9084c5521fef0ed56 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 23 Jan 2014 08:15:17 -0800 Subject: [PATCH] Issue a linker error if TLS sections are not adjacent 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. PR ld/16498 * elf.c (_bfd_elf_map_sections_to_segments): Issue a linker error if TLS sections are not adjacent. --- bfd/ChangeLog | 6 ++++++ bfd/elf.c | 26 +++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 3996dfcb2d..78aa794ddf 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2014-01-23 H.J. Lu + + 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 * elflink.c (elf_link_add_object_symbols): Call minfo for --as-needed. diff --git a/bfd/elf.c b/bfd/elf.c index 3815e32103..c0303fc21a 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -4117,11 +4117,31 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info) /* Mandated PF_R. */ m->p_flags = PF_R; m->p_flags_valid = 1; + s = first_tls; for (i = 0; i < (unsigned int) tls_count; ++i) { - BFD_ASSERT (first_tls->flags & SEC_THREAD_LOCAL); - m->sections[i] = first_tls; - first_tls = first_tls->next; + if ((s->flags & SEC_THREAD_LOCAL) == 0) + { + _bfd_error_handler + (_("%B: TLS sections are not adjacent:"), abfd); + s = first_tls; + i = 0; + while (i < (unsigned int) tls_count) + { + if ((s->flags & SEC_THREAD_LOCAL) != 0) + { + _bfd_error_handler (_(" TLS: %A"), s); + i++; + } + else + _bfd_error_handler (_(" non-TLS: %A"), s); + s = s->next; + } + bfd_set_error (bfd_error_bad_value); + goto error_return; + } + m->sections[i] = s; + s = s->next; } *pm = m; -- 2.34.1